diff --git a/CVSROOT/checkoutlist b/CVSROOT/checkoutlist deleted file mode 100644 index b04b350..0000000 --- a/CVSROOT/checkoutlist +++ /dev/null @@ -1,13 +0,0 @@ -# The "checkoutlist" file is used to support additional version controlled -# administrative files in $CVSROOT/CVSROOT, such as template files. -# -# The first entry on a line is a filename which will be checked out from -# the corresponding RCS file in the $CVSROOT/CVSROOT directory. -# The remainder of the line is an error message to use if the file cannot -# be checked out. -# -# File format: -# -# [] -# -# comment lines begin with '#' diff --git a/CVSROOT/commitinfo b/CVSROOT/commitinfo deleted file mode 100644 index b19e7b7..0000000 --- a/CVSROOT/commitinfo +++ /dev/null @@ -1,15 +0,0 @@ -# The "commitinfo" file is used to control pre-commit checks. -# The filter on the right is invoked with the repository and a list -# of files to check. A non-zero exit of the filter program will -# cause the commit to be aborted. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being committed to, relative -# to the $CVSROOT. For the first match that is found, then the remainder -# of the line is the name of the filter to run. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/config b/CVSROOT/config deleted file mode 100644 index 8069cad..0000000 --- a/CVSROOT/config +++ /dev/null @@ -1,11 +0,0 @@ -# Set this to "no" if pserver shouldn't check system users/passwords -#SystemAuth=no - -# Set `PreservePermissions' to `yes' to save file status information -# in the repository. -#PreservePermissions=no - -# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top -# level of the new working directory when using the `cvs checkout' -# command. -#TopLevelAdmin=no diff --git a/CVSROOT/cvswrappers b/CVSROOT/cvswrappers deleted file mode 100644 index 0accaf1..0000000 --- a/CVSROOT/cvswrappers +++ /dev/null @@ -1,23 +0,0 @@ -# This file affects handling of files based on their names. -# -# The -t/-f options allow one to treat directories of files -# as a single file, or to transform a file in other ways on -# its way in and out of CVS. -# -# The -m option specifies whether CVS attempts to merge files. -# -# The -k option specifies keyword expansion (e.g. -kb for binary). -# -# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers) -# -# wildcard [option value][option value]... -# -# where option is one of -# -f from cvs filter value: path to filter -# -t to cvs filter value: path to filter -# -m update methodology value: MERGE or COPY -# -k expansion mode value: b, o, kkv, &c -# -# and value is a single-quote delimited value. -# For example: -#*.gif -k 'b' diff --git a/CVSROOT/editinfo b/CVSROOT/editinfo deleted file mode 100644 index d78886c..0000000 --- a/CVSROOT/editinfo +++ /dev/null @@ -1,21 +0,0 @@ -# The "editinfo" file is used to allow verification of logging -# information. It works best when a template (as specified in the -# rcsinfo file) is provided for the logging procedure. Given a -# template with locations for, a bug-id number, a list of people who -# reviewed the code before it can be checked in, and an external -# process to catalog the differences that were code reviewed, the -# following test can be applied to the code: -# -# Making sure that the entered bug-id number is correct. -# Validating that the code that was reviewed is indeed the code being -# checked in (using the bug-id number or a seperate review -# number to identify this particular code set.). -# -# If any of the above test failed, then the commit would be aborted. -# -# Actions such as mailing a copy of the report to each reviewer are -# better handled by an entry in the loginfo file. -# -# One thing that should be noted is the the ALL keyword is not -# supported. There can be only one entry that matches a given -# repository. diff --git a/CVSROOT/loginfo b/CVSROOT/loginfo deleted file mode 100644 index 5a59f0a..0000000 --- a/CVSROOT/loginfo +++ /dev/null @@ -1,26 +0,0 @@ -# The "loginfo" file controls where "cvs commit" log information -# is sent. The first entry on a line is a regular expression which must match -# the directory that the change is being made to, relative to the -# $CVSROOT. If a match is found, then the remainder of the line is a filter -# program that should expect log information on its standard input. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name ALL appears as a regular expression it is always used -# in addition to the first matching regex or DEFAULT. -# -# You may specify a format string as part of the -# filter. The string is composed of a `%' followed -# by a single format character, or followed by a set of format -# characters surrounded by `{' and `}' as separators. The format -# characters are: -# -# s = file name -# V = old version number (pre-checkin) -# v = new version number (post-checkin) -# -# For example: -#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog -# or -#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog diff --git a/CVSROOT/modules b/CVSROOT/modules deleted file mode 100644 index 18bc3d7..0000000 --- a/CVSROOT/modules +++ /dev/null @@ -1,29 +0,0 @@ -# Three different line formats are valid: -# key -a aliases... -# key [options] directory -# key [options] directory files... -# -# Where "options" are composed of: -# -i prog Run "prog" on "cvs commit" from top-level of module. -# -o prog Run "prog" on "cvs checkout" of module. -# -e prog Run "prog" on "cvs export" of module. -# -t prog Run "prog" on "cvs rtag" of module. -# -u prog Run "prog" on "cvs update" of module. -# -d dir Place module in directory "dir" instead of module name. -# -l Top-level directory only -- do not recurse. -# -# NOTE: If you change any of the "Run" options above, you'll have to -# release and re-checkout any working directories of these modules. -# -# And "directory" is a path to a directory relative to $CVSROOT. -# -# The "-a" option specifies an alias. An alias is interpreted as if -# everything on the right of the "-a" had been typed on the command line. -# -# You can encode a module within a module by using the special '&' -# character to interpose another module into the current module. This -# can be useful for creating a module that consists of many directories -# spread out over the entire source repository. - -MacSSH -a macssh lsh zlib gmp GUSI - diff --git a/CVSROOT/notify b/CVSROOT/notify deleted file mode 100644 index 34f0bc2..0000000 --- a/CVSROOT/notify +++ /dev/null @@ -1,12 +0,0 @@ -# The "notify" file controls where notifications from watches set by -# "cvs watch add" or "cvs edit" are sent. The first entry on a line is -# a regular expression which is tested against the directory that the -# change is being made to, relative to the $CVSROOT. If it matches, -# then the remainder of the line is a filter program that should contain -# one occurrence of %s for the user to notify, and information on its -# standard input. -# -# "ALL" or "DEFAULT" can be used in place of the regular expression. -# -# For example: -#ALL mail %s -s "CVS notification" diff --git a/CVSROOT/rcsinfo b/CVSROOT/rcsinfo deleted file mode 100644 index 49e59f4..0000000 --- a/CVSROOT/rcsinfo +++ /dev/null @@ -1,13 +0,0 @@ -# The "rcsinfo" file is used to control templates with which the editor -# is invoked on commit and import. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being made to, relative to the -# $CVSROOT. For the first match that is found, then the remainder of the -# line is the name of the file that contains the template. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/taginfo b/CVSROOT/taginfo deleted file mode 100644 index 274a46d..0000000 --- a/CVSROOT/taginfo +++ /dev/null @@ -1,20 +0,0 @@ -# The "taginfo" file is used to control pre-tag checks. -# The filter on the right is invoked with the following arguments: -# -# $1 -- tagname -# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d -# $3 -- repository -# $4-> file revision [file revision ...] -# -# A non-zero exit of the filter program will cause the tag to be aborted. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being committed to, relative -# to the $CVSROOT. For the first match that is found, then the remainder -# of the line is the name of the filter to run. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/verifymsg b/CVSROOT/verifymsg deleted file mode 100644 index 86f747c..0000000 --- a/CVSROOT/verifymsg +++ /dev/null @@ -1,21 +0,0 @@ -# The "verifymsg" file is used to allow verification of logging -# information. It works best when a template (as specified in the -# rcsinfo file) is provided for the logging procedure. Given a -# template with locations for, a bug-id number, a list of people who -# reviewed the code before it can be checked in, and an external -# process to catalog the differences that were code reviewed, the -# following test can be applied to the code: -# -# Making sure that the entered bug-id number is correct. -# Validating that the code that was reviewed is indeed the code being -# checked in (using the bug-id number or a seperate review -# number to identify this particular code set.). -# -# If any of the above test failed, then the commit would be aborted. -# -# Actions such as mailing a copy of the report to each reviewer are -# better handled by an entry in the loginfo file. -# -# One thing that should be noted is the the ALL keyword is not -# supported. There can be only one entry that matches a given -# repository. diff --git a/GUSI/DCon/Headers/DCon.h b/GUSI/DCon/Headers/DCon.h deleted file mode 100755 index a15013d..0000000 --- a/GUSI/DCon/Headers/DCon.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _DCON_ -#define _DCON_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -void dopen(const char *log); -void dprintf(const char *format,...); -void vdprintf(const char *format,va_list arg); -void dprintmem(const void *data,size_t len); - -void dfprintf(const char *log,const char *format,...); -void vdfprintf(const char *log,const char *format,va_list arg); -void dfprintmem(const char *log,const void *data,size_t len); - - -#ifndef DCON - #define DCON 1 -#endif - -#if DCON - #define dAssertPrint(condition) dprintf(NULL,"Assert failed: " condition " %s:%d\n",__FILE__,__LINE__) - #define dAssertIfTrue(condition) ((condition) ? dAssertPrint(#condition) : ((void)0)) - #define dAssertIfFalse(condition) ((condition) ? ((void)0) : dAssertPrint(#condition)) - #define dAssert(condition) dAssertIfFalse(condition) -#else - #define dAssertPrint(condition) ((void)0) - #define dAssertIfTrue(condition) ((condition) ? ((void)0) : ((void)0)) - #define dAssertIfFalse(condition) ((condition) ? ((void)0) : ((void)0)) - #define dAssert(condition) dAssertIfFalse(condition) - #define dopen while(0) - #define dprintf while(0) - #define vdprintf while(0) - #define dprintmem while(0) - #define dfprintf while(0) - #define vfdprintf while(0) - #define dfprintmem while(0) -#endif - - -#ifdef __cplusplus -} -#endif - -#endif /* _DCON_ */ diff --git a/GUSI/Examples/GUSIFileTest.c b/GUSI/Examples/GUSIFileTest.c deleted file mode 100755 index 52e11c5..0000000 --- a/GUSI/Examples/GUSIFileTest.c +++ /dev/null @@ -1,481 +0,0 @@ -/********************************************************************* -File : GUSI - Grand Unified Socket Interface -File : GUSIFileTest - Test plain files -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:36 chombier -Initial import - -Revision 1.4 2000/05/23 06:38:53 neeri -Added descriptor tests - -Revision 1.3 2000/01/17 01:38:32 neeri -Fix rename() directory separator handling - -Revision 1.2 1999/04/10 04:24:53 neeri -Reimplement ls and ll in a more standard way - -Revision 1.1 1998/10/25 11:57:25 neeri -Ready to release 2.0a3 - -Revision 1.2 1994/12/31 01:10:41 neeri -ANSIfy. -Test FSSpec encoding. - -Revision 1.1 1994/02/25 02:46:54 neeri -Initial revision - -Revision 0.9 1993/07/29 00:00:00 neeri -scandir - -Revision 0.8 1993/07/18 00:00:00 neeri -dirent -> struct dirent - -Revision 0.7 1992/12/20 00:00:00 neeri -Allow defaults for choose() - -Revision 0.6 1992/12/08 00:00:00 neeri -Pwd() - -Revision 0.5 1992/10/27 00:00:00 neeri -Forgot to adapt it to dirent.h - -Revision 0.4 1992/09/07 00:00:00 neeri -RdLink() - -Revision 0.3 1992/07/25 00:00:00 neeri -Isolated testing gear in GUSITest - -Revision 0.2 1992/07/13 00:00:00 neeri -Test choose() - -Revision 0.1 1992/06/14 00:00:00 neeri -More tests - -*********************************************************************/ - -#include "GUSITest.h" -#include "GUSIFileSpec.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void Stat(char ch1, char ch2, const char * cmd) -{ - int res; - struct stat statbuf; - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else { - if (ch2 == 'l') { - cmd = "lstat"; - res = lstat(filename, &statbuf); - } else { - cmd = "stat"; - res = stat(filename, &statbuf); - } - - if (res) { - printf("# %s(\"%s\") returned error %s\n", cmd, filename, Explain()); - } else { - printf("# %s(\"%s\") =\n", cmd, filename); - DUMP(statbuf.st_dev,d); - DUMP(statbuf.st_ino,d); - DUMP(statbuf.st_mode,o); - DUMP(statbuf.st_nlink,d); - DUMP(statbuf.st_uid,d); - DUMP(statbuf.st_gid,d); - DUMP(statbuf.st_rdev,d); - DUMP(statbuf.st_size,d); - DUMP(statbuf.st_atime,u); - DUMP(statbuf.st_mtime,u); - DUMP(statbuf.st_ctime,u); - DUMP(statbuf.st_blksize,d); - DUMP(statbuf.st_blocks,d); - } - Where(); - } -} - -void ChDir(char ch1, char ch2, const char * cmd) -{ - char directory[80]; - - if (sscanf(cmd, "%s", directory) != 1) - Usage(ch1, ch2); - else if (chdir(directory)) { - printf("# chdir(\"%s\") returned error %s\n", directory, Explain()); - Where(); - } -} - -void MkDir(char ch1, char ch2, const char * cmd) -{ - char directory[80]; - - if (sscanf(cmd, "%s", directory) != 1) - Usage(ch1, ch2); - else if (mkdir(directory)) { - printf("# mkdir(\"%s\") returned error %s\n", directory, Explain()); - Where(); - } -} - -void RmDir(char ch1, char ch2, const char * cmd) -{ - char directory[80]; - - if (sscanf(cmd, "%s", directory) != 1) - Usage(ch1, ch2); - else if (rmdir(directory)) { - printf("# rmdir(\"%s\") returned error %s\n", directory, Explain()); - Where(); - } -} - -void List(char ch1, char ch2, const char * cmd) -{ - int count; - int i; - DIR * dir; - struct dirent * entry; - char * dirend; - char directory[80]; - struct stat statbuf; - - if (sscanf(cmd, "%s", directory) != 1) - strcpy(directory, ":"); - - if (ch2 == 'l' && !strchr(directory, ':')) { - directory[0] = ':'; - sscanf(cmd, "%s", directory+1); - } - - if (!(dir = opendir(directory))) { - printf("# opendir(\"%s\") returned error %s\n", directory, Explain()); - goto error; - } - - printf("# directory \"%s\" =\n", directory); - - dirend = directory + strlen(directory); - if (dirend[-1] != ':') - *dirend++ = ':'; - - while (entry = readdir(dir)) - if (ch2 == 's') - printf("# %s\n", entry->d_name); - else { - strcpy(dirend, entry->d_name); - - if (lstat(directory, &statbuf)) - printf("# lstat(\"%s\") returned error %s\n", entry->d_name, Explain()); - else - printf("# %c %7d %s\n", - (statbuf.st_mode & S_IFMT) == S_IFREG ? 'F' : - (statbuf.st_mode & S_IFMT) == S_IFDIR ? 'D' : - (statbuf.st_mode & S_IFMT) == S_IFLNK ? 'L' : '?', - statbuf.st_size, - entry->d_name); - } - closedir(dir); - -error: - Where(); -} - -void Type(char ch1, char ch2, const char * cmd) -{ - FILE * fl; - char line[500]; - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else { - fl = fopen(filename, "r"); - - if (!fl) - printf("# open(\"%s\") returned error %s\n", filename, Explain()); - else { - printf("# \"%s\" =\n", filename); - while (fgets(line, 500, fl)) - fputs(line, stdout); - - fclose(fl); - } - - - Where(); - } -} - -void Encode(char ch1, char ch2, const char * cmd) -{ -#if 0 - OSErr err; - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else { - FSSpec spec; - - if (err = Path2FSSpec(filename, &spec)) - fprintf(stderr, "Path2FSSpec(%s) returned error %d\n", filename, err); - else - fprintf(stderr, "%s -> %s\n", filename, FSp2Encoding(&spec)); - } -#endif -} - -void Glob(char ch1, char ch2, const char * cmd) -{ -#if 0 - OSErr err; - FileGlobRef glob; - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else if (!(glob = NewFileGlob(filename))) - fprintf(stderr, "NewFileGlob(%s) failed.\n", filename); - else { - FSSpec spec; - - fprintf(stderr, "Glob(%s) matched:\n", filename); - while (FileGlob2FSSpec(glob, &spec)) { - fprintf(stderr, " %s\n", FSp2FullPath(&spec)); - NextFileGlob(glob); - } - DisposeFileGlob(glob); - } -#endif -} - -void Edit(char ch1, char ch2, const char * cmd) -{ - FILE * fl; - char line[500]; - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else { - fl = fopen(filename, "w"); - - if (!fl) - printf("# open(\"%s\") returned error %s\n", filename, Explain()); - else { - printf("# Enter \"%s\", terminate with \".\"\n", filename); - while (fgets(line, 500, stdin)) - if (strcmp(line, ".\n")) - fputs(line, fl); - else - break; - - fclose(fl); - } - } -} - -void Rm(char ch1, char ch2, const char * cmd) -{ - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else if (remove(filename)) { - printf("# remove(\"%s\") returned error %s\n", filename, Explain()); - Where(); - } -} - -void Mv(char ch1, char ch2, const char * cmd) -{ - struct stat statbuf; - char oldfilename[80]; - char newfilename[80]; - - if (sscanf(cmd, "%s %s", oldfilename, newfilename) != 2) - Usage(ch1, ch2); - else { - if (!stat(newfilename, &statbuf) && (statbuf.st_mode & S_IFMT) == S_IFDIR) { - char * fn; - char * next; - int len = strlen(newfilename); - - /* Extract file name part from oldfilename */ - for (fn = oldfilename; (next = strchr(fn, ':')) && next[1]; fn = next+1); - - if (!strchr(newfilename, ':')) { /* Prepend ':' if necessary */ - newfilename[0] = ':'; - sscanf(cmd, "%s %s", oldfilename, newfilename+1); - ++len; - } - - if (newfilename[len-1] != ':') - newfilename[len++] = ':'; - - strcpy(newfilename+len, fn); - } - - if (rename(oldfilename, newfilename)) { - printf("# rename(\"%s\", \"%s\") returned error %s\n", oldfilename, newfilename, Explain()); - Where(); - } - } -} - -void Link(char ch1, char ch2, const char * cmd) -{ - char oldfilename[80]; - char newfilename[80]; - - if (sscanf(cmd, "%s %s", oldfilename, newfilename) != 2) - Usage(ch1, ch2); - else { - if (symlink(oldfilename, newfilename)) { - printf("# symlink(\"%s\", \"%s\") returned error %s\n", oldfilename, newfilename, Explain()); - Where(); - } - } -} - -void RdLink(char ch1, char ch2, const char * cmd) -{ - char path[200]; - char link[200]; - int len; - - if (sscanf(cmd, "%s", path) != 1) - Usage(ch1, ch2); - - len = readlink(path, link, 199); - - if (len < 0) - printf("# readlink(\"%s\") returned error %s\n", path, Explain()); - else { - link[len] = 0; - printf("# readlink(\"%s\") returned \"%s\"\n", path, link); - } - - Where(); -} - -void Pwd(char ch1, char ch2, const char * cmd) -{ - char * buf; - - buf = getcwd(NULL, 1024); - - if (!buf) - printf("# getcwd() returned error %s\n", Explain()); - else { - printf("# getcwd() returned \"%s\"\n", buf); - - free(buf); - } - - Where(); -} - -void Access(char ch1, char ch2, const char * cmd) -{ - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else { - if (access(filename, F_OK)) - printf("# access(\"%s\", F_OK) returned error %s\n", filename, Explain()); - else - printf("# access(\"%s\", F_OK) succeeded.\n", filename, Explain()); - if (access(filename, R_OK)) - printf("# access(\"%s\", R_OK) returned error %s\n", filename, Explain()); - else - printf("# access(\"%s\", R_OK) succeeded.\n", filename, Explain()); - if (access(filename, W_OK)) - printf("# access(\"%s\", W_OK) returned error %s\n", filename, Explain()); - else - printf("# access(\"%s\", W_OK) succeeded.\n", filename, Explain()); - if (access(filename, X_OK)) - printf("# access(\"%s\", X_OK) returned error %s\n", filename, Explain()); - else - printf("# access(\"%s\", X_OK) succeeded.\n", filename, Explain()); - Where(); - } -} - -void Open(char ch1, char ch2, const char * cmd) -{ - char filename[80]; - - if (sscanf(cmd, "%s", filename) != 1) - Usage(ch1, ch2); - else if ((sock = open(filename, O_RDONLY)) < 0) - printf("# open(\"%s\") returned error %s\n", filename, Explain()); -} - -void Seek(char ch1, char ch2, const char * cmd) -{ - int whence; - int offset; - int result; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (sscanf(cmd, "%d %d", &offset, &whence) != 2) { - Usage(ch1, ch2); - return; - } - - if ((result = lseek(sock, offset, whence)) < 0) - printf("# lseek(%d %d) returned error %s\n", offset, whence, Explain()); - else - printf("# lseek(%d %d) ended up at offset %d\n", offset, whence, result); -} - -main(int argc, char ** argv) -{ - printf("GUSIFileTest MN 21May00\n\n"); - - AddDescriptorCommands(); - - COMMAND('s', 't', Stat, "filename", "Call stat() on a file"); - COMMAND('s', 'l', Stat, "filename", "Call lstat() on a file"); - COMMAND('c', 'd', ChDir, "directory", "Call chdir()"); - COMMAND('l', 's', List, "[ directory ]", "List a directory"); - COMMAND('l', 'l', List, "[ directory ]", "List a directory with more info"); - COMMAND('m', 'd', MkDir, "directory", "Make a new directory"); - COMMAND('d', 'd', RmDir, "directory", "Delete an empty directory"); - COMMAND('t', 'y', Type, "filename", "Type out the contents of a file"); - COMMAND('e', 'd', Edit, "filename", "Enter the contents of a new file"); - COMMAND('m', 'v', Mv, "oldfile newfile", "Rename/Move a file"); - COMMAND('r', 'm', Rm, "filename", "Delete a file"); - COMMAND('r', 'l', RdLink,"filename", "Read symbolic link"); - COMMAND('l', 'n', Link, "oldfile newfile", "Create a symbolic link"); - COMMAND('p', 'w', Pwd, "", "Print current directory"); - COMMAND('e', 'n', Encode,"filename", "Translate filename to encoded FSSpec"); - COMMAND('g', 'l', Glob, "filename", "Expand wildcards"); - COMMAND('a', 'c', Access,"filename", "Test access rights"); - COMMAND('o', 'p', Open, "filename", "Open a file (to test commands on open files)"); - COMMAND('s', 'k', Seek, "offset whence", "Seek on open descriptor"); - RunTest(argc, argv); -} diff --git a/GUSI/Examples/GUSIINETTest.c b/GUSI/Examples/GUSIINETTest.c deleted file mode 100755 index 15ee33f..0000000 --- a/GUSI/Examples/GUSIINETTest.c +++ /dev/null @@ -1,601 +0,0 @@ -/********************************************************************* -Project : GUSI - Grand Unified Socket Interface -File : GUSIINETTest - Test unix domain sockets -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:39 chombier -Initial import - -Revision 1.4 2000/10/15 21:49:20 neeri -Add multiple connection test - -Revision 1.3 2000/05/23 06:40:03 neeri -Add Linger, Getsockname tests - -Revision 1.2 2000/03/06 08:28:32 neeri -Releasing 2.0.5 - -Revision 1.1 1998/10/25 11:57:26 neeri -Ready to release 2.0a3 - -Revision 1.1 1994/12/31 00:50:27 neeri -Initial revision - -Revision 0.6 1993/08/25 00:00:00 neeri -gethostbyaddr() - -Revision 0.5 1993/07/29 00:00:00 neeri -servent tests - -Revision 0.4 1993/03/03 00:00:00 neeri -Added performance test - -Revision 0.3 1992/09/14 00:00:00 neeri -Misinterpreted hostent structure - -Revision 0.2 1992/09/08 00:00:00 neeri -Factor out common socket routines - -Revision 0.1 1992/09/08 00:00:00 neeri -First attempt - -*********************************************************************/ - -#include "GUSITest.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Events.h" - -char addrstr[100]; - -void Socket(char ch1, char ch2, const char * line) -{ - sock = socket(AF_INET, (ch1 == 's') ? SOCK_STREAM : SOCK_DGRAM, 0); - - if (sock == -1) { - printf("# socket() returned error %d [%s]\n", errno, Explain()); - Where(); - } -} - -void Bind(char ch1, char ch2, const char * cmd) -{ - int len; - struct sockaddr_in addr; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (sscanf(cmd, "%s %hd", addrstr, &addr.sin_port) == 2) { - addr.sin_addr.s_addr = inet_addr(addrstr); - addr.sin_family = AF_INET; - len = sizeof(struct sockaddr_in); - } else { - Usage(ch1, ch2); - return; - } - - if (bind(sock, (struct sockaddr *) &addr, len)) { - printf( - "bind(%s:%d) returned error %d [%s]\n", - inet_ntoa(addr.sin_addr), - addr.sin_port, - errno, Explain()); - - Where(); - } -} - -void NoDelay(char , char , const char * cmd) -{ - int one = 1; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - return; - } - - if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof(int))) - printf( - "setsockopt(IPPROTO_TCP, TCP_NODELAY) returned error %d [%s]\n", - errno, Explain()); -} - -void Linger(char ch1, char ch2, const char * cmd) -{ - struct linger l; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (sscanf(cmd, "%d", &l.l_linger) == 1) { - l.l_onoff = l.l_linger > -1; - } else { - Usage(ch1, ch2); - return; - } - - if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof(struct linger))) - printf( - "setsockopt(SOL_SOCKET, SO_LINGER) returned error %d [%s]\n", - errno, Explain()); -} - -void Accept(char ch1, char ch2, const char * line) -{ - socklen_t len; - struct sockaddr_in addr; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - if (accsock != -1) { - printf("# can't accept more than one connection\n"); - Where(); - - return; - } - - len = sizeof(struct sockaddr_in); - sock = accept(accsock = sock, (struct sockaddr *) &addr, &len); - - if (sock < 0) { - printf("# accept() returned error %d [%s]\n", errno, Explain()); - sock = accsock; - accsock = -1; - } else { - printf( - "# accepted connection from %s port %d\n", - inet_ntoa(addr.sin_addr), - addr.sin_port); - } - - Where(); -} - -void Getsockname(char ch1, char ch2, const char * line) -{ - socklen_t len; - struct sockaddr_in addr; - int err; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - len = sizeof(struct sockaddr_in); - - if (ch2 == 's') - err = getsockname(accsock = sock, (struct sockaddr *) &addr, &len); - else - err = getpeername(accsock = sock, (struct sockaddr *) &addr, &len); - if (err < 0) { - printf("# get%sname() returned error %d [%s]\n", - (ch2 == 's' ? "sock" : "peer"), errno, Explain()); - } else { - printf( - "# %s are %s port %d\n", (ch2 == 's' ? "We" : "They"), - inet_ntoa(addr.sin_addr), - addr.sin_port); - } - - Where(); -} - -void Connect(char ch1, char ch2, const char * cmd) -{ - int len; - struct sockaddr_in addr; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (sscanf(cmd, "%s %hd", addrstr, &addr.sin_port) == 2) { - addr.sin_addr.s_addr = inet_addr(addrstr); - addr.sin_family = AF_INET; - len = sizeof(struct sockaddr_in); - } else { - Usage(ch1, ch2); - return; - } - - if (connect(sock, (struct sockaddr *) &addr, len)) { - printf( - "connect(%s:%d) returned error %s\n", - inet_ntoa(addr.sin_addr), - addr.sin_port, - Explain()); - Where(); - } -} - -static int sSock[1000]; -static int sSockUsed; - -void MultiConn(char ch1, char ch2, const char * cmd) -{ - int len; - int count; - int i; - struct sockaddr_in addr; - - if (sscanf(cmd, "%d %s %hd", &count, addrstr, &addr.sin_port) == 3) { - addr.sin_addr.s_addr = inet_addr(addrstr); - addr.sin_family = AF_INET; - len = sizeof(struct sockaddr_in); - } else { - Usage(ch1, ch2); - return; - } - - if (count > 1000-sSockUsed) - count = 1000-sSockUsed; - for (i=0; i 0) - close(sSock[--sSockUsed]); -} - -int ReadWhileUCan() -{ - int res; - char * outline; - fd_set rdfds; - fd_set exfds; - struct timeval delay; - char out[500]; - - for (;;) { - FD_ZERO(&rdfds); - FD_ZERO(&exfds); - - FD_SET(sock, &rdfds); - FD_SET(sock, &exfds); - - delay.tv_sec = 1; - delay.tv_usec = 0; - - res = select(sock+1, &rdfds, nil, &exfds, &delay); - - if (res < 0) { - printf("# select() returned error %d [%s]\n", errno, Explain()); - - return -1; - } else if (!res) - return 0; - else if (res && FD_ISSET(sock, &exfds)) { - printf("# select() returned an exception\n"); - - return -1; - } else if (res && FD_ISSET(sock, &rdfds)) { - res = read(sock, out, 500); - - if (res < 0) { - printf("# read() returned error %d [%s]\n", errno, Explain()); - - return -1; - } - - out[res] = 0; - - for (outline = strtok(out, "\n\r"); outline; outline = strtok(nil, "\n\r")) - printf("%s\n", outline); - } - } -} - -void Telnet(char ch1, char ch2, const char * cmd) -{ - int len; - int part; - int res; - char * line; - char * outline; - fd_set rdfds; - fd_set wrfds; - fd_set exfds; - struct timeval delay; - char in[100]; - char out[500]; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - printf("# Entering Poor Man's Telnet mode\n"); - - for (;;) { - if (ReadWhileUCan()) - break; - - Prompt(); - - if (!fgets(in, 100, input)) - break; - - ++inputline; - - if (!strcmp(in, ".\n")) - break; - - if (!strcmp(in, "?\n")) - continue; - - len = strlen(in); - in[len++] = '\r'; - in[len] = 0; - - for (line = in; len; len -= part, line += part) { - part = 0; - - FD_ZERO(&rdfds); - FD_ZERO(&wrfds); - FD_ZERO(&exfds); - - FD_SET(sock, &rdfds); - FD_SET(sock, &wrfds); - FD_SET(sock, &exfds); - - delay.tv_sec = 10; - delay.tv_usec = 0; - - res = select(sock+1, &rdfds, &wrfds, &exfds, &delay); - - if (res < 0) { - printf("# select() returned error %d [%s]\n", errno, Explain()); - - return; - } else if (!res) { - printf("# select() timed out\n"); - - return; - } else if (FD_ISSET(sock, &exfds)) { - printf("# select() returned an exception\n"); - - return; - } - - if (FD_ISSET(sock, &rdfds)) { - res = read(sock, out, 500); - - if (res < 0) { - printf("# read() returned error %d [%s]\n", errno, Explain()); - - return; - } - - out[res] = 0; - - for (outline = strtok(out, "\n\r"); outline; outline = strtok(nil, "\n\r")) - printf("%s\n", outline); - } else if (FD_ISSET(sock, &wrfds)) { - res = write(sock, line, len); - - if (res < 0) { - line[strlen(line) - 2] = 0; - printf("# write(\"%s\") returned error %s\n", line, Explain()); - - return; - } - - part = res; - } - } - } - - printf("# Leaving Poor Man's Telnet mode\n"); -} - -void N2Addr(char ch1, char ch2, const char * cmd) -{ - struct in_addr addr; - struct hostent * ent; - - if (sscanf(cmd, "%s", addrstr) == 1) - if (ent = gethostbyname(addrstr)) { - memcpy(&addr, ent->h_addr, sizeof(struct in_addr)); - printf("# gethostbyname(%s) returned %s\n", addrstr, inet_ntoa(addr)); - } else - printf("# gethostbyname(%s) failed.\n", addrstr); - else - Usage(ch1, ch2); -} - -void A2Name(char ch1, char ch2, const char * cmd) -{ - in_addr_t addr; - struct hostent * ent; - - if (sscanf(cmd, "%s", addrstr) == 1) { - addr = inet_addr(addrstr); - if (ent = gethostbyaddr((char *) &addr, 0, 0)) { - printf("# gethostbyaddr(%s) returned %s\n", addrstr, ent->h_name); - } else - printf("# gethostbyaddr(%s) failed.\n", addrstr); - } else - Usage(ch1, ch2); -} - -void PerfTest(char ch1, char ch2, const char * cmd) -{ - int count; - int i; - long ticks; - char buf[1024]; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (sscanf(cmd, "%d", &count) == 1) { - ticks = TickCount(); - for (i=0; is_port); - else - printf("# getservbyname(%s %s) failed.\n", addrstr, proto); - else if (sscanf(cmd, "%s", addrstr) == 1) - if (ent = getservbyname(addrstr, NULL)) - printf("# getservbyname(%s) returned %d\n", addrstr, ent->s_port); - else - printf("# getservbyname(%s) failed.\n", addrstr); - else - Usage(ch1, ch2); -} - -void PrintServEnt(struct servent * ent, Boolean full) -{ - char ** al; - - printf("%s", ent->s_name); - - if (full) - printf(" %d/%s", ent->s_port, ent->s_proto); - - for (al = ent->s_aliases; *al; ++al) - printf(" %s", *al); - - putchar('\n'); -} - -void ServByPort(char ch1, char ch2, const char * cmd) -{ - int port; - struct servent * ent; - char proto[6]; - - if (sscanf(cmd, "%d %s", &port, proto) == 2) - if (ent = getservbyport(port, proto)) { - printf("# getservbyport(%d %s) returned ", port, proto); - - PrintServEnt(ent, false); - } else - printf("# getservbyport(%d %s) failed.\n", addrstr, proto); - else if (sscanf(cmd, "%d %s", &port) == 1) - if (ent = getservbyport(port, NULL)) { - printf("# getservbyport(%d) returned ", port); - - PrintServEnt(ent, false); - } else - printf("# getservbyport(%d) failed.\n", addrstr); - else - Usage(ch1, ch2); -} - -void ServList(char ch1, char ch2, const char * line) -{ - struct servent * ent; - - setservent(0); - - while (ent = getservent()) { - printf("# "); - PrintServEnt(ent, true); - } -} - -main(int argc, char ** argv) -{ - printf("GUSIINETTest MN 14May00\n\n"); - - COMMAND('s', 's', Socket, "", "Create a stream socket"); - COMMAND('d', 's', Socket, "", "Create a datagram socket"); - COMMAND('b', 'd', Bind, "addr port", "Bind to address"); - COMMAND('c', 'o', Connect, "addr port", "Connect to address"); - COMMAND('m', 'c', MultiConn, "# addr port", "Connect multiple times to address"); - COMMAND('m', 'd', MultiDis, "", "Disconnect the connections"); - COMMAND('a', 'c', Accept, "", "Accept a connection"); - COMMAND('t', 'n', Telnet, "", "Play telnet"); - COMMAND('n', 'a', N2Addr, "name", "Convert name to address"); - COMMAND('a', 'n', A2Name, "addr", "Convert address to name"); - COMMAND('p', 't', PerfTest,"count", "Do a performance test"); - COMMAND('s', 'n', ServByName, "name", "Convert service name to port number"); - COMMAND('s', 'p', ServByPort, "port", "Convert port number to service name"); - COMMAND('s', 'l', ServList, "", "List services"); - COMMAND('n', 'd', NoDelay, "", "Turn on NODELAY TCP option"); - COMMAND('l', 'g', Linger, "", "Set LINGER socket option"); - COMMAND('g', 's', Getsockname, "", "Get socket name"); - COMMAND('g', 'p', Getsockname, "", "Get peer name"); - - AddSocketCommands(); - - RunTest(argc, argv); - CleanupSockets(); -} \ No newline at end of file diff --git a/GUSI/Examples/GUSIPPCTest.c b/GUSI/Examples/GUSIPPCTest.c deleted file mode 100755 index f37a9d4..0000000 --- a/GUSI/Examples/GUSIPPCTest.c +++ /dev/null @@ -1,198 +0,0 @@ -/********************************************************************* -File : GUSI - Grand Unified Socket Interface -File : GUSIPPCTest - Test PPC sockets -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:39 chombier -Initial import - -Revision 1.1 2000/10/29 20:31:53 neeri -Releasing 2.1.3 - -Revision 1.2 1994/12/31 01:05:05 neeri -ANSIfy (omitting parameter names was illegal). - -Revision 1.1 1994/02/25 02:47:36 neeri -Initial revision - -Revision 0.3 1993/06/20 00:00:00 neeri -New sa_constr - -Revision 0.2 1992/10/14 00:00:00 neeri -Fix NBP type, usage messages - -Revision 0.1 1992/09/08 00:00:00 neeri -Factor out common socket routines - -*********************************************************************/ - -#include "GUSITest.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -void Socket(char ch1, char ch2, const char * line) -{ - sock = socket(AF_PPC, SOCK_STREAM, 0); - - if (sock == -1) { - printf("# socket() returned error %s\n", Explain()); - Where(); - } -} - -void Bind(char ch1, char ch2, const char * cmd) -{ - struct sockaddr_ppc addr; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - addr.sppc_family = AF_PPC; - addr.sppc_port.nameScript = smRoman; - addr.sppc_port.portKindSelector = ppcByString; - addr.sppc_location.locationKindSelector = ppcNBPTypeLocation; - - if (sscanf(cmd, "%s %s", addr.sppc_port.name+1, addr.sppc_location.u.nbpType+1) != 2) { - Usage(ch1, ch2); - - return; - } - - addr.sppc_port.name[0] = strlen(((char *)addr.sppc_port.name)+1); - addr.sppc_location.u.nbpType[0] = strlen(((char *)&addr.sppc_location.u.nbpType)+1); - - PLstrcpy((StringPtr) &addr.sppc_port.u.portTypeStr, "\pGUSIPPCTest"); - - if (bind(sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_ppc))) { - printf("bind() returned error %s\n", Explain()); - Where(); - } -} - -void Accept(char ch1, char ch2, const char * line) -{ - socklen_t len; - struct sockaddr_ppc addr; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - if (accsock != -1) { - printf("# can't accept more than one connection\n"); - Where(); - - return; - } - - len = sizeof(struct sockaddr_ppc); - sock = accept(accsock = sock, (struct sockaddr *) &addr, &len); - - if (sock < 0) { - printf("# accept() returned error %s\n", Explain()); - sock = accsock; - accsock = -1; - } else { - addr.sppc_port.name[addr.sppc_port.name[0]+1] = 0; - addr.sppc_port.u.portTypeStr[addr.sppc_port.u.portTypeStr[0]+1] = 0; - printf( - "# accepted connection from %s[%s]", - ((char *)addr.sppc_port.name)+1, - ((char *)addr.sppc_port.u.portTypeStr)+1); - - switch (addr.sppc_location.locationKindSelector) { - case ppcNBPLocation: - addr.sppc_location.u.nbpEntity.objStr[addr.sppc_location.u.nbpEntity.objStr[0]+1] = 0; - addr.sppc_location.u.nbpEntity.typeStr[addr.sppc_location.u.nbpEntity.typeStr[0]+1] = 0; - addr.sppc_location.u.nbpEntity.zoneStr[addr.sppc_location.u.nbpEntity.zoneStr[0]+1] = 0; - printf( - "@%s:%s:%s\n", - ((char *)addr.sppc_location.u.nbpEntity.objStr)+1, - ((char *)addr.sppc_location.u.nbpEntity.typeStr)+1, - ((char *)addr.sppc_location.u.nbpEntity.zoneStr)+1); - break; - case ppcNBPTypeLocation: - addr.sppc_location.u.nbpType[addr.sppc_location.u.nbpType[0]+1] = 0; - printf("@%s\n", ((char *)addr.sppc_location.u.nbpType)+1); - break; - default: - printf("\n"); - break; - } - } - - Where(); -} - -Boolean BrowseForName(struct sockaddr_ppc * name) -{ - PortInfoRec info; - - if (PPCBrowser( - "\pConnect where?", - (StringPtr) "\p", - false, - &name->sppc_location, - &info, - (PPCFilterUPP)nil, - "\pGUSIPPCTest")) - return false; - - name->sppc_family = AF_PPC; - name->sppc_port = info.name; - - return true; -} - -void Connect(char ch1, char ch2, const char * cmd) -{ - socklen_t len; - struct sockaddr_ppc addr; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (!BrowseForName(&addr)) - return; - - if (connect(sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_ppc))) { - printf("# connect() returned error %s\n", Explain()); - Where(); - } -} - -main(int argc, char ** argv) -{ - printf("GUSIPPCTest MN 10Jan98\n\n"); - - COMMAND('s', 's', Socket, "", "Create a stream socket"); - COMMAND('b', 'd', Bind, "Name Type", "Bind to address"); - COMMAND('c', 'o', Connect, "", "Connect to address"); - COMMAND('a', 'c', Accept, "", "Accept a connection"); - - AddSocketCommands(); - - RunTest(argc, argv); - CleanupSockets(); -} \ No newline at end of file diff --git a/GUSI/Examples/GUSISocketTest.c b/GUSI/Examples/GUSISocketTest.c deleted file mode 100755 index b4a5975..0000000 --- a/GUSI/Examples/GUSISocketTest.c +++ /dev/null @@ -1,395 +0,0 @@ -/********************************************************************* -File : GUSI - Grand Unified Socket Interface -File : GUSISocketTest.c - Socket testing gear -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:39 chombier -Initial import - -Revision 1.6 2000/05/23 06:41:40 neeri -Separate out descriptor commands - -Revision 1.5 1999/12/13 03:07:24 neeri -Releasing 2.0.2 - -Revision 1.4 1999/11/15 07:52:30 neeri -Last Call for 2.0.1 - -Revision 1.3 1999/08/02 06:59:24 neeri -Added support for asynchronous errors - -Revision 1.2 1999/04/10 04:25:54 neeri -Change to more standard compliant headers - -Revision 1.1 1998/10/25 11:57:27 neeri -Ready to release 2.0a3 - -Revision 1.2 1994/12/31 01:12:21 neeri -ANSIfy. -Roundtrip benchmark. - -Revision 1.1 1994/02/25 02:47:47 neeri -Initial revision - -Revision 0.1 1992/09/08 00:00:00 neeri -Factor out more common code - -*********************************************************************/ - -#include "GUSITest.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int sock = -1; -int accsock = -1; - -void Close(char ch1, char ch2, const char * cmd) -{ - if (close(sock)) { - printf("# close() returned error %s\n", Explain()); - Where(); - } - - sock = accsock; - accsock = -1; -} - -void Listen(char ch1, char ch2, const char * cmd) -{ - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (listen(sock, 5)) { - printf("# listen() returned error %s\n", Explain()); - Where(); - } -} - -void Write(char ch1, char ch2, const char * line) -{ - int len = strlen(line); - int part; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - for (; len; len -= part, line += part) { - part = write(sock, line, len); - if (part < 0) { - printf("# write(\"%s\") returned error %s\n", line, Explain()); - Where(); - - break; - } - } -} - -void Read(char ch1, char ch2, const char * cmd) -{ - int len; - char buf[500]; - char * line; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - len = read(sock, buf, 500); - - if (len < 0) { - printf("# read() returned error %s\n", Explain()); - } else { - buf[len] = 0; - printf("# read() returned:\n"); - - for (line = strtok(buf, "\n\r"); line; line = strtok(nil, "\n\r")) - printf("# %s\n", line); - } - - Where(); -} - -void Select(char ch1, char ch2, const char * cmd) -{ - int res; - fd_set rdfds; - fd_set wrfds; - fd_set exfds; - struct timeval delay; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - FD_ZERO(&rdfds); - FD_ZERO(&wrfds); - FD_ZERO(&exfds); - - FD_SET(sock, &rdfds); - FD_SET(sock, &wrfds); - FD_SET(sock, &exfds); - - delay.tv_sec = 10; - delay.tv_usec = 0; - - res = select(sock+1, &rdfds, &wrfds, &exfds, &delay); - - if (res < 0) { - printf("# select() returned error %s\n", Explain()); - } else if (!res) { - printf("# select() timed out\n"); - } else { - printf( - "# select() returned %s%s%s\n", - FD_ISSET(sock, &rdfds) ? "canRead " : "", - FD_ISSET(sock, &wrfds) ? "canWrite " : "", - FD_ISSET(sock, &exfds) ? "exception " : ""); - } - - Where(); -} - -void TogBlk(char ch1, char ch2, const char * cmd) -{ - int block; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - switch (fcntl(sock, F_GETFL, 0)) { - case 0: - block = 1; - break; - default: - block = 0; - break; - case -1: - printf("# fcntl(F_GETFL) returned error %s\n", Explain()); - Where(); - - return; - } - - if (fcntl(sock, F_SETFL, block ? O_NONBLOCK : 0)) - printf( - "# ioctl(FIONBIO, %s) returned error %s\n", - block ? "true" : "false", - Explain()); - else - printf("# Socket is now %s\n", block ? "nonblocking" : "blocking"); - - Where(); -} - -void NRead(char ch1, char ch2, const char * cmd) -{ - int nread; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (ioctl(sock, FIONREAD, (long *) &nread)) - printf("# ioctl(FIONREAD) returned error %s\n", Explain()); - else - printf("# %d bytes waiting to be read\n", nread); - - Where(); -} - -void GetError(char ch1, char ch2, const char * cmd) -{ - int err; - socklen_t len = sizeof(int); - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len)) - printf("# getsockopt(SOL_SOCKET, SO_ERROR) returned error %s\n", Explain()); - else { - errno = err; - printf("# Asynchronous error was %d (%s)\n", err, Explain()); - } - - Where(); -} - -static char BenchBuf[8192]; - -void BenchSer(char ch1, char ch2, const char * cmd) -{ - char * at; - int requestSize; - int responseSize; - int packetSize; - int count; - int i; - - if (sock == -1) { - printf("# socket is not open\n"); - Where(); - - return; - } - - at = BenchBuf; - - do { - at += read(sock, at, 1024); - *at = 0; - } while (!strchr(BenchBuf, '\015')); - - sscanf(BenchBuf, "%d %d %d\015", &requestSize, &responseSize, &count); - - write(sock, BenchBuf, 1); - - for (i=0; i++ -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:54 chombier -Initial import - -Revision 1.4 2000/05/23 06:45:28 neeri -Add profiler support - -Revision 1.3 1999/06/28 05:43:30 neeri -Handle signals - -Revision 1.2 1999/04/10 04:26:22 neeri -Get rid of nonstandard error codes - -Revision 1.1 1998/10/25 11:57:28 neeri -Ready to release 2.0a3 - -Revision 1.2 1994/12/31 01:15:09 neeri -ANSIfy. -Benchmark support. - -Revision 1.1 1994/02/25 02:47:57 neeri -Initial revision - -Revision 0.2 1992/09/20 00:00:00 neeri -Allow empty lines & comments - -Revision 0.1 1992/09/08 00:00:00 neeri -Factor out more common code - -*********************************************************************/ - -#include -#include -#include "GUSITest.h" -#include -#include -#include -#include -#include -#include -#include - -#if __profile__ -#include -#endif - -#ifdef __MWERKS__ -#include -#endif - -Boolean HellHoundOnMyTrail = true; /* Gotta keep on moving */ -char infilename[200]; -char * inputfrom; -FILE * input; -int inputline; -CmdDef commands[NROFCMDS]; - -void Help(char ch1, char ch2, const char * cmd) -{ - printf("Commands are:\n\n"); - - for (ch1 = 'a'; ch1 <= 'z'; ++ch1) - for (ch2 = 0; ch2 <= 'z'; ch2 ? ++ch2 : (ch2 = 'a')) - if (HELPMSG(ch1,ch2)) - printf( - " %c%c %-25s -- %s\n", - ch1, - ch2 ? ch2 : ' ', - USAGE(ch1,ch2), - HELPMSG(ch1,ch2)); - - printf("\n"); -} - -void Where() -{ - if (inputfrom) - printf("File '%s'; Line %d\n", inputfrom, inputline); -} - -void Prompt() -{ - if (!inputfrom) - printf("[%d]%c", inputline, ' '); -} - -#define CASE(code) case code: return #code - -const char * Explain() -{ - switch (errno) { - CASE(EPERM); - CASE(ENOENT); - CASE(ESRCH); - CASE(EINTR); - CASE(EIO); - CASE(ENXIO); - CASE(E2BIG); - CASE(ENOEXEC); - CASE(EBADF); - CASE(ECHILD); - CASE(ENOMEM); - CASE(EACCES); - CASE(EFAULT); - CASE(EBUSY); - CASE(EEXIST); - CASE(EXDEV); - CASE(ENODEV); - CASE(ENOTDIR); - CASE(EISDIR); - CASE(EINVAL); - CASE(ENFILE); - CASE(EMFILE); - CASE(ENOTTY); - CASE(EFBIG); - CASE(ENOSPC); - CASE(ESPIPE); - CASE(EROFS); - CASE(EMLINK); - CASE(EPIPE); - CASE(EDOM); - CASE(ERANGE); - CASE(EWOULDBLOCK); - CASE(EINPROGRESS); - CASE(EALREADY); - CASE(ENOTSOCK); - CASE(EDESTADDRREQ); - CASE(EMSGSIZE); - CASE(EPROTOTYPE); - CASE(ENOPROTOOPT); - CASE(EPROTONOSUPPORT); - CASE(ESOCKTNOSUPPORT); - CASE(EOPNOTSUPP); - CASE(EPFNOSUPPORT); - CASE(EAFNOSUPPORT); - CASE(EADDRINUSE); - CASE(EADDRNOTAVAIL); - CASE(ENETDOWN); - CASE(ENETUNREACH); - CASE(ENETRESET); - CASE(ECONNABORTED); - CASE(ECONNRESET); - CASE(ENOBUFS); - CASE(EISCONN); - CASE(ENOTCONN); - CASE(ESHUTDOWN); - CASE(ETOOMANYREFS); - CASE(ETIMEDOUT); - CASE(ECONNREFUSED); - CASE(ELOOP); - CASE(ENAMETOOLONG); - CASE(EHOSTDOWN); - CASE(EHOSTUNREACH); - CASE(ENOTEMPTY); - CASE(ENOLCK); - CASE(ENOSYS); - default: - return "Unknown"; - } -} - -void Usage(char ch1, char ch2) -{ - printf("# Usage is: %c%c %s\n", ch1, ch2 ? ch2 : ' ', USAGE(ch1,ch2)); - Where(); -} - -void Dispatch(const char * command) -{ - char ch1 = command[0]; - char ch2 = command[1]; - TestCmd exec; - - /* We are guaranteed to have at least one valid character */ - - switch (ch1) { - case '\n': - case '#': - return; - } - - if (!ch2) - ++command; - else { - if (isspace(ch2)) { - command += 1; - ch2 = 0; - } else - command += 2; - - /* Skip rest of first word */ - for (; *command && !isspace(*command); ++command); - - /* Skip whitespace */ - while (isspace(*command)) - ++command; - } - - if (isalpha(ch1) && (!ch2 || isalpha(ch2)) && (exec = DISPATCH(ch1,ch2))) - exec(ch1, ch2, command); - else { - if (ch2) - printf("# Unknown command: '%c%c'\n", ch1, ch2); - else - printf("# Unknown command: '%c'\n", ch1); - - printf("# Type 'h' for a list of known commands.\n"); - - Where(); - } -} - -void Quit(char ch1, char ch2, const char * cmd) -{ - HellHoundOnMyTrail = false; -} - -void signal_handler(int sig) -{ - /* Don't do anything, just interrupt system calls */ -} - -void Alarm(char ch1, char ch2, const char * cmd) -{ - signal(SIGALRM, signal_handler); - alarm(atoi(cmd)); -} - -void InitSampler(Sampler * samp) -{ - samp->count = 0; - samp->min = 0x7FFFFFFF; - samp->max = -samp->min; - samp->sum = 0; -} - -void Sample(Sampler * samp, long sample) -{ - ++samp->count; - if (sample < samp->min) - samp->min = sample; - if (sample > samp->max) - samp->max = sample; - samp->sum += sample; -} - -void RunTest(int argc, char ** argv) -{ - struct sigaction act; - char cmd[80]; - -#if __profile__ - ProfilerInit(collectDetailed, bestTimeBase, 100, 20); - ProfilerSetStatus(0); -#endif - - COMMAND('h', 0, Help, "", "Print this list"); - COMMAND('a', 'l', Alarm, "n", "Raise an alarm in n seconds"); - COMMAND('q', 0, Quit, "", "End the sad existence of this program"); - -#ifdef __MWERKS__ - SIOUXSettings.asktosaveonclose = false; -#else - InitGraf((Ptr) &qd.thePort); -#endif - - act.sa_handler = signal_handler; - act.sa_mask = 0; - act.sa_flags = 0; - sigaction(SIGINT, &act, NULL); - - if (--argc <= 0) - Help('h', 0, ""); - - do { - if (argc > 0 && strcmp(inputfrom = *++argv, "-")) { - printf("Executing %sÉ\n", inputfrom); - input = fopen(inputfrom, "r"); - } else { - inputfrom = 0; - input = stdin; - } - - inputline = 1; - - while (HellHoundOnMyTrail && (Prompt(), fgets(cmd, 80, input))) { -#if __profile__ - ProfilerSetStatus(1); -#endif - Dispatch(cmd); -#if __profile__ - ProfilerSetStatus(0); -#endif - ++inputline; - } - } while (HellHoundOnMyTrail && --argc > 0); - -#if __profile__ - ProfilerDump("\pGUSI.prof"); - ProfilerTerm(); -#endif - - printf("So long, it's been good to know you.\n"); -} diff --git a/GUSI/Examples/GUSITest.h b/GUSI/Examples/GUSITest.h deleted file mode 100755 index 8b96439..0000000 --- a/GUSI/Examples/GUSITest.h +++ /dev/null @@ -1,110 +0,0 @@ -/********************************************************************* -File : GUSI - Grand Unified Socket Interface -File : GUSITest.h - Common testing gear -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:54 chombier -Initial import - -Revision 1.2 2000/05/23 06:43:25 neeri -Separate out descriptor commands - -Revision 1.1 1998/10/25 11:57:29 neeri -Ready to release 2.0a3 - -Revision 1.2 1994/12/31 01:18:29 neeri -Benchmark support. - -Revision 1.1 1994/02/25 02:48:06 neeri -Initial revision - -Revision 0.1 1992/09/08 00:00:00 neeri -Factor out more common code - -*********************************************************************/ - -#ifndef _GUSITEST_ -#define _GUSITEST_ - -typedef void (*TestCmd)(char ch1, char ch2, const char * restcmd); - -#include "GUSITest_P.h" - -#include - -extern FILE * input; -extern int inputline; - -/* void COMMAND( - char ch1, char ch2, Command name - TestCmd p, Command to be run - char * s, Arguments to command - char * h); Explanation for command - - Example: - COMMAND('m', 'd', MkDir, "directory", "Make a new directory"); -*/ - -#define COMMAND(ch1,ch2,p,s,h) \ - DISPATCH(ch1,ch2) = (p), \ - USAGE(ch1,ch2) = (s), \ - HELPMSG(ch1,ch2) = (h) - -/* An useful macro for dumping variables. - - Example: - DUMP(statbuf.st_dev,d); -*/ - -#define DUMP(EXPR, MODE) printf("# %s = %"#MODE"\n", #EXPR, EXPR) - -/* Add common commands for descriptors */ - -void AddDescriptorCommands(); - -/* Add common commands for sockets */ - -void AddSocketCommands(); - -/* Run the test. Define your commands with COMMAND and call this */ - -void RunTest(int argc, char ** argv); - -/* Print a MPW executable location note */ - -void Where(); - -/* Print a prompt */ - -void Prompt(); - -/* Return a string of the current error number, e.g. "EINVAL" */ - -const char * Explain(); - -/* Print a usage message for a command */ - -void Usage(char ch1, char ch2); - -/* Clean up sockets */ - -void CleanupSockets(); - -extern int sock; /* Socket to read/write to */ -extern int accsock; /* Socket to accept connections on */ - -/* Keep statistics on a series of values */ - -typedef struct { - int count; - long min; - long max; - long sum; -} Sampler; - -void InitSampler(Sampler * samp); -void Sample(Sampler * samp, long sample); - -#endif diff --git a/GUSI/Examples/GUSITest.r b/GUSI/Examples/GUSITest.r deleted file mode 100755 index eb0f86d..0000000 --- a/GUSI/Examples/GUSITest.r +++ /dev/null @@ -1,37 +0,0 @@ -/********************************************************************* -Project : GUSI - Grand Unified Socket Interface -File : GUSITest - Testing gear -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:54 chombier -Initial import - -Revision 1.1 1998/10/25 11:57:30 neeri -Ready to release 2.0a3 - -Revision 1.2 1994/12/31 01:16:51 neeri -Add GU·I resource. - -Revision 1.1 1994/02/25 02:48:17 neeri -Initial revision - -Revision 0.2 1993/03/03 00:00:00 neeri -define GUSI_PREF_VERSION - -Revision 0.1 1992/07/13 00:00:00 neeri -Include GUSI.r - -*********************************************************************/ - -#define GUSI_PREF_VERSION '0150' - -#include "GUSI.r" - -resource 'GU·I' (GUSIRsrcID) { - text, mpw, noAutoSpin, useChdir, approxStat, - noTCPDaemon, noUDPDaemon, - noConsole, - {}; -}; diff --git a/GUSI/Examples/GUSITest.rsrc b/GUSI/Examples/GUSITest.rsrc deleted file mode 100755 index 4213b8d..0000000 Binary files a/GUSI/Examples/GUSITest.rsrc and /dev/null differ diff --git a/GUSI/Examples/GUSITest_P.h b/GUSI/Examples/GUSITest_P.h deleted file mode 100755 index 64d89e7..0000000 --- a/GUSI/Examples/GUSITest_P.h +++ /dev/null @@ -1,38 +0,0 @@ -/********************************************************************* -File : GUSI - Grand Unified Socket Interface -File : GUSITest_P.h - Common testing gear -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:54 chombier -Initial import - -Revision 1.1 1994/02/25 02:48:27 neeri -Initial revision - -*********************************************************************/ - -#ifndef _GUSITEST_P_ -#define _GUSITEST_P_ - -#include - -#define NROFCHARS 26 -#define DECODE(ch) ((ch) ? (ch) - (isupper(ch) ? 'A' : 'a') + 1 : 0) -#define CMDCODE(ch1,ch2) (DECODE(ch1)*(NROFCHARS+1)+DECODE(ch2)) -#define NROFCMDS (NROFCHARS+1)*(NROFCHARS+1) - -typedef struct { - TestCmd proc; - const char * syntax; - const char * help; -} CmdDef; - -extern CmdDef commands[NROFCMDS]; - -#define DISPATCH(ch1,ch2) commands[CMDCODE(ch1,ch2)].proc -#define USAGE(ch1,ch2) commands[CMDCODE(ch1,ch2)].syntax -#define HELPMSG(ch1,ch2) commands[CMDCODE(ch1,ch2)].help - -#endif \ No newline at end of file diff --git a/GUSI/Examples/GUSIThreadTest.c b/GUSI/Examples/GUSIThreadTest.c deleted file mode 100755 index d7c0544..0000000 --- a/GUSI/Examples/GUSIThreadTest.c +++ /dev/null @@ -1,147 +0,0 @@ -/********************************************************************* -File : GUSI - Grand Unified Socket Interface -File : GUSIThreadTest - Testthread related features -Author : Matthias Neeracher -Language : MPW C - -$Log$ -Revision 1.1.1.1 2001/03/03 21:49:54 chombier -Initial import - -Revision 1.1 2000/10/29 20:31:53 neeri -Releasing 2.1.3 - -*********************************************************************/ - -#include "GUSITest.h" - -#include -#include - -#include - -typedef struct { - pthread_mutex_t fMutex; - int fCounter; - int fLoops; - char fType; -} Shared; - -void * -MutexPerformanceProc(void *arg) -{ - Shared * shared = (Shared *)arg; - - int i; - - if (shared->fType == 'm') { - for (i = 0; i < shared->fLoops; i++) { - pthread_mutex_lock(&shared->fMutex); - shared->fCounter++; - pthread_mutex_unlock(&shared->fMutex); - } - } else { - pthread_mutex_lock(&shared->fMutex); - pthread_mutex_unlock(&shared->fMutex); - for (i = 0; i < shared->fLoops; i++) { - shared->fCounter++; - if (shared->fType == 'y') - sched_yield(); - } - } - return(NULL); -} -/* end incr */ - -void MutexPerformance(char ch1, char ch2, const char * cmd) -{ - int nloops; - int nthreads; - pthread_t tid[20]; - Shared shared; - int i; - int fairness; - unsigned long start_time; - unsigned long stop_time; - - if (sscanf(cmd, "%d %d", &shared.fLoops, &nthreads) != 2) - Usage(ch1, ch2); - else { - if (nthreads < 1) { - printf("Too few threads specified, using 1\n"); - nthreads = 1; - } else if (nthreads > 20) { - printf("Too many threads specified, using 20\n"); - nthreads = 20; - } - shared.fCounter = 0; - shared.fType = ch1; - pthread_mutex_init(&shared.fMutex, NULL); - pthread_mutex_lock(&shared.fMutex); - - for (i = 0; i < nthreads; i++) - pthread_create(&tid[i], NULL, MutexPerformanceProc, &shared); - - start_time = LMGetTicks(); - - pthread_mutex_unlock(&shared.fMutex); - - /* 4wait for all the threads */ - pthread_join(tid[0], NULL); - fairness = shared.fCounter; - for (i = 1; i < nthreads; i++) - pthread_join(tid[i], NULL); - - stop_time = LMGetTicks(); - - printf("Time: %f seconds, Fairness: %.2f%\n", - (stop_time - start_time) / 60.0, - (fairness * 100.0) / ((shared.fLoops-1) * nthreads + 1)); - if (shared.fCounter != shared.fLoops * nthreads) - printf("error: counter = %ld\n", shared.fCounter); - - pthread_mutex_destroy(&shared.fMutex); - } -} - -void Sleep(char ch1, char ch2, const char * cmd) -{ - int seconds; - - if (sscanf(cmd, "%d", &seconds) != 1) - Usage(ch1, ch2); - else - printf("Remaining: %ds\n", sleep(seconds)); -} - -void Times(char ch1, char ch2, const char * cmd) -{ - time_t lmk, gmk; - time_t now = time(NULL); - struct tm * t = localtime(&now); - printf("Localtime %d/%d/%d %d:%02d:%02d %s\n", - t->tm_year+1900, t->tm_mon+1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec, t->tm_isdst ? "DST" : ""); - lmk = mktime(t); - - t = gmtime(&now); - printf("GMtime %d/%d/%d %d:%02d:%02d %s\n", - t->tm_year+1900, t->tm_mon+1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec, t->tm_isdst ? "DST" : ""); - gmk = mktime(t); - - printf("Now %u Local %u GM %u\n", now, lmk, gmk); -} - -main(int argc, char ** argv) -{ - printf("GUSIFileTest MN 25OCt00\n\n"); - - COMMAND('m', 'p', MutexPerformance, "#loops #threads", "Test mutex performance"); - COMMAND('y', 'p', MutexPerformance, "#loops #threads", "Test yield performance"); - COMMAND('n', 'p', MutexPerformance, "#loops #threads", "Test noyield performance"); - COMMAND('s', 'l', Sleep, "seconds", "sleep"); - COMMAND('t', 'm', Times, "", "Test time related functions"); - - RunTest(argc, argv); -} diff --git a/GUSI/Examples/MSLGUSITest.pch b/GUSI/Examples/MSLGUSITest.pch deleted file mode 100755 index 2cc364f..0000000 Binary files a/GUSI/Examples/MSLGUSITest.pch and /dev/null differ diff --git a/GUSI/Examples/Makefile b/GUSI/Examples/Makefile deleted file mode 100755 index 5b8bb98..0000000 Binary files a/GUSI/Examples/Makefile and /dev/null differ diff --git a/GUSI/GUSIConfig.mk b/GUSI/GUSIConfig.mk deleted file mode 100755 index afc045a..0000000 Binary files a/GUSI/GUSIConfig.mk and /dev/null differ diff --git a/GUSI/GUSIConfig/GUSIConfig b/GUSI/GUSIConfig/GUSIConfig deleted file mode 100755 index cf8d3ff..0000000 Binary files a/GUSI/GUSIConfig/GUSIConfig and /dev/null differ diff --git a/GUSI/GUSI_Install.MPW b/GUSI/GUSI_Install.MPW deleted file mode 100755 index 1d43817..0000000 Binary files a/GUSI/GUSI_Install.MPW and /dev/null differ diff --git a/GUSI/MANIFEST b/GUSI/MANIFEST deleted file mode 100755 index 1473f4f..0000000 Binary files a/GUSI/MANIFEST and /dev/null differ diff --git a/GUSI/MacDistr b/GUSI/MacDistr deleted file mode 100755 index 450ad27..0000000 Binary files a/GUSI/MacDistr and /dev/null differ diff --git a/GUSI/Makefile.mk b/GUSI/Makefile.mk deleted file mode 100755 index 1abb4dc..0000000 Binary files a/GUSI/Makefile.mk and /dev/null differ diff --git a/GUSI/README b/GUSI/README deleted file mode 100755 index c7825be..0000000 --- a/GUSI/README +++ /dev/null @@ -1,436 +0,0 @@ - GUSI 2 -- A multithreaded POSIX library -INTRODUCTION - -GUSI is an extension and partial replacement of the standard C runtime library -supplied with your compiler. The main objective of GUSI is to faciliate the -porting of software written for UNIX systems by implementing a substantial subset -of the Single Unix Specification library routines: - - - BSD style sockets. - - Pthreads. - - Many other POSIX facilities such as diropen(). - -REQUIREMENTS - -To use GUSI, you need one of the following compilers: - - - Metrowerks CodeWarrior Pro 5 or later. - - SC/SCpp 8.8.4d1c1 or later. - - MrC/MrCpp 4.1.0a6c1 or later. - -GETTING STARTED - -If you're new to GUSI, start by reading the manual in :doc:GUSI.pdf. - -If you're using GUSI with the Metrowerks CodeWarrior IDE, also read -:doc:GUSI_CW_Guide.pdf if you haver any difficulties getting your first GUSI -project to compile/link. - -If you're using GUSI in combination with the MPW shell and/or the MPW compilers, -please run GUSI_Install.MPW. For more details, please consider reading the -documentation in the doc folder. - -To recompile GUSI with the MPW compilers, you need an STL library. I've found -STLport, available at http://www.stlport.org/download.shtml, to work perfectly -for my purposes. To install it, put it anywhere on your disk and run -STLport_Install.MPW. Current versions of GUSI have been compiled with STLport 3.1.2. - -GUSI USER LICENSE - -My primary objective in distributing GUSI is to have it used as widely as -possible, while protecting my moral rights of authorship and limiting my -exposure to liability. - -Copyright (C) 1992-2001 Matthias Neeracher - -Permission is granted to anyone to use this software for any purpose on any -computer system, and to redistribute it freely, subject to the following -restrictions: - -- The author is not responsible for the consequences of use of this software, - no matter how awful, even if they arise from defects in it. -- The origin of this software must not be misrepresented, either by explicit - claim or by omission. -- You are allowed to distributed modified copies of the software, in source - and binary form, provided they are marked plainly as altered versions, and - are not misrepresented as being the original software. - -While I am giving GUSI away for free, that does not mean that I don't like -getting appreciation for it. If you want to do something for me beyond your -obligations outlined above, you can - -- Acknowledge the use of GUSI in the about box of your application and/or - your documentation. -- Send me a CD as described in - http://www.iis.ee.ethz.ch/~neeri/macintosh/donations.html - -BUGS, QUESTIONS, SUGGESTIONS - -Please report any problems you experience with the code or the documentation to -me. I'd also be interested in hearing about your success stories, if you have -any. - -GUSI ON WWW - -An online version of the GUSI manual and a GUSI FAQ are available at -http://www.iis.ee.ethz.ch/~neeri/macintosh.html - -MAILING LIST - -There is a mailing list for announcing new releases and discussions about -how to make GUSI change your life. To subscribe, send a mail: - ----------------------------------- -To: gusi-request@iis.ee.ethz.ch -Subject: (is ignored) - -subscribe ----------------------------------- - -Mail is now processed by a daemon, so please follow the above format. - - Matthias Neeracher - 20875 Valley Green Dr. #50 - Cupertino, CA 95014 - - e-Mail: - Fax: +1 (408) 514-2605 ext. 0023 - -KNOWN BUGS - - - MSG_PEEK does not yet work for for native OpenTransport sockets, only for MacTCP - sockets [John Cargill-Ek]. - - hstrerror() is not yet implemented [Darrell Walisser]. - -RELEASE NOTES - -Version 2.1.9 22Jul01 - - - Fixed st_blksize for files on HFS+ volumes, made st_blksize be expressed in - terms of st_blksize, not as 512 byte blocks [Marcel Riechert, Chris Nandor, - MacPerl Bug #424874]. - - Errors in MPW calls would still not be propagated correctly in CW 68K code - [Chris Nandor, MacPerl Bug #436537]. - - If STDOUT and STDERR were reidrected to the same file, MPW tools would not - work correctly [Chris Nandor, MacPerl Bug #436506]. - -Version 2.1.8 02Jul01 - - - truncate() was broken [Chris Nandor, MacPerl Bug #436893]. - - errors of MPW calls wouldn't be propagated correctly in MWPPC code - [Chris Nandor, MacPerl Bug #436537]. - - open(..., O_CREAT|O_EXCL) would fail with MPW sockets [Thomas Wegner, MacPerl Bug #425901]. - - S_ISFIFO and S_ISSOCK were broken (a bug apparently inherited straight from BSD). - [Thomas Wegner, MacPerl Bug #430930]. - -Version 2.1.7 15Apr01 - - - Path resolution of absolute paths with embedded aliases was broken. - - GUSIFSpGetCatInfo returned garbage in the ioNamePtr field [Alan Fry]. - -Version 2.1.6 08Apr01 - - - Fix handling of error codes in select() [Jean-Pierre Stierlin]. - - Paths starting with ::: were mishandled [Chris Nandor, MacPerl Bug #409940]. - - Made minor tweaks to make GUSI work better with Natty (Don't ask yet). - - Fixed major bugs in relative path generation. - - MPW tools were unable to open files which were open as windows - [Thomas Wegner, MacPerl Bug #231006] - - Used delete where delete[] was appropriate [Wade Williams]. - - Fixed handling of network configuration changes [Jean-Pierre Stierlin]. - - Fixed a number of logic bugs related to select() [Michael Johnson, Wade Williams]. - - Clean out fNextListener after accept() [Joe van Tunen]. - - Fixed CW Project to include specific directories rather than {Compiler}. - -Version 2.1.5 21Jan01 - - - Make literate programming tools configurable to some extent [Jack Jansen]. - - Made countless tweaks to scheduling and wakeups [Andreas Grosam, Keith Stattenfield]. - - Prevent inlining of overridable functions [Andreas Grosam]. - - Socket options did not work properly for OT sockets created by accept [Andreas Grosam]. - - pthread_cond_timedwait never returned ETIMEDOUT [Andreas Grosam]. - -Version 2.1.4 22Dec00 - - - Using a GUSIFSxxx call before any POSIX calls could cause programs to hang - because the default context was not initialized yet. - - GUSIForeignThreads was unable to open ThreadsLib [Max Horn]. - - GUSI diagnostic messages were sometimes emitted at A5 unsafe times - [Jean-Pierre Stierlin]. - - Added ssh entry in hard coded services table [Jean-Pierre Stierlin]. - -Version 2.1.3 29Oct00 - - - More CW 6 fixes, especially for massive problems with time related functions - [Richard Wesley]. - - Nonstandard macros defined in sys/cdefs.h conflicted with CW macros [David Willis]. - - PPC sockets were totally broken; they seemed to have slipped entirely through any - sort of acceptance testing [David Willis]. - - Deal with CW's non-standard signature for fdopen. - - Include two new tests (GUSIThreadTest, GUSIPPCTest) in interactive test suite. - - Switched to distributing XML versions of the CW projects for space savings and - portability. - -Version 2.1.2 16Oct00 - - - Fixes for CodeWarrior 6 [Jack Jansen, Jeff Shulman]. - - SC would always use A5 relative addresses, with disastrous consequences in - completion routines [Jean-Pierre Stierlin]. - - The OpenTransport code for dealing with multiple incoming connections had - severe bugs [Gordon McMillan]. - - Accommodate the fact that CodeWarrior internally uses a different numbering - scheme for SIGINT [Jack Jansen]. - -Version 2.1.1 05Jun00 - - - Some functions were returning references to stack values [Alexandre Parenteau]. - - Fixed a shocking amount of bugs in time(), localtime(), and gmtime() - [Jack Jansen, Alexandre Parenteau]. - - Keep DCon support from crashing under Sfio. - - Introduced preliminary support for multiple descriptor tables. - -Version 2.1.0 29May00 - - - Improved formatting of the woven documentation [Peter Teeson]. - - Updated to Universal Headers 3.3.1 [Tom Bayley]. - - Tuned scheduling again [Jack Jansen]. - - Implemented proper linger model, closing sockets immediately (while - actually putting them into a background queue to allow pending data to - be transmitted) [Rich Cook, Oebele Dijkstra]. - - MacTCP sockets would hang on close with pending data [Jack Jansen]. - - Fixed bugs in lseek for read-only files [Jack Jansen]. - - Failed OpenTransport DNS lookups would return garbage data instead of - error [Karl Armstrong, Mike Johnson]. - - Repeatedly calling a connect on a nonblocking socket could cause an infinite - loop [Mike Johnson]. - - Fixed leak in OT UDP sendto [Tom Bayley]. - - (Hopefully) fixed a problem that could cause select() not to return a - ready to read status [Mike Johnson]. - -Version 2.0.6 14Mar00 - - - Fixed several race conditions causing hangs in OpenTransport code - [Alexandre Parenteau]. - - Console would get initialized twice [Steven Gillispie]. - - Suffix finding code was broken [Alexandre Parenteau]. - - open(":x:y", O_RDWR) would create x as a file if it didn't exist [Alexandre Parenteau]. - - Temporary name creation would crash horribly [Alexandre Parenteau]. - - rename() was broken [Alexandre Parenteau]. - - Try to enforce alignment of struct and class fields when GUSI headers are - included by clients with arbitrary default alignments [Alexandre Parenteau]. - - Custom thread switchers were not getting correctly reinstalled upon destruction - of a thread [Andre Radke]. - - GUSIFileSpec::Resolve needed to clear fValidInfo [Alexandre Parenteau]. - - Accidentally had reversed the logic for my "fix" of the double destruction of detached - threads [Stephen Coy]. - - getservbyname would crash if /etc/services did not exist - [Christopher Stern, Alexandre Parenteau]. - -Version 2.0.5 06Mar00 - - - Added a visual manual for first time CodeWarrior GUSI users [Rich Cook]. - - Forgot include guard in inttypes.h - - Device families did not check that the paths passed to them were device paths - [Christopher Stern] - - Sped up thread switching by a factor of up to 1000 [Jack Jansen]. - - Called InitGraf in one location without checking configuration flag - [Alexandre Parenteau]. - - Used a flaky plausibility test for automatic InitGraf. - - Detached threads were deleted twice [Stephen Coy]. - - Force order of static destructors by closing descriptors before deleting threads - [Christopher Stern]. - - Checked for nonexistent devices in file calls [Alexandre Parenteau]. - - readdir() would always return an error at the end of the directory, which is against - the specification [Alexandre Parenteau]. - - sleep() from the main thread didn't [Darrell Walisser]. - - Renamed CodeWarrior projects to .mcp for cross platform compilability [Chris Brown]. - -Version 2.0.4 16Jan00 - - - Updated to CodeWarrior 5.3 compilers (this shouldn't affect any existing CW 5 users - negatively, I think. If it does, please alert me.). - - Some of the macros in pthread.h had PTHREAD_ misspelled as PTHREADS_ [Mike Davis] - - GUSI's version of rename() was incorrectly mangled, so clients would link with - the standard rename() [Matthew Nolan]. - - Removing an open file in the temporary items folder would fail [Jack Jansen]. - -Version 2.0.3 13Dec99 - - - Closing a OpenTransport TCP socket with data pending would hang - [Oebele Dijkstra, Darrell Walisser]. - - Calling gethostbyname() before any sockets were opened would malfunction. - -Version 2.0.2 12Dec99 - - - Attempting to set SO_LINGER would crash [Keith Rollin]. - - Passing a null timezone argument to gettimeofday() would misbehave [Christopher Stern]. - - GUSISetThreadSwitcher would get the wrong linkage [Bruno Litman]. - - read() on OpenTransport TCP/IP sockets had wrong results on disconnected sockets - [Keith Rollin]. - - select() would return a wrong result if any descriptors were ready for both reading - and writing [Keith Rollin]. - - Added pause() call. - -Version 2.0.1 14Nov99 - - - select() would sometimes unecessarily poll [David Lawrence]. - - Added GUSIwithPPCSockets, GUSIwithLocalSockets, which I had forgotten - [Darrell Walisser]. - - GUSI would generate SIGINT for background applications if Command-. was - pressed in the foreground application [Darrell Walisser]. - - Calling signal() before any sockets were created would crash [Darrell Walisser]. - - gethostname() would garble the name if running with TCP/IP off - [Christopher Stern]. - - stat() would not return an error for nonexistent files [Christopher Stern]. - -Version 2.0 23Oct99 - - - Removed the advertising clause from the BSD headers, as UCB no longer - requires it. Thanks! - - Included DCon.h in the distribution so GUSI compiles even if you - don't have DCon. Thanks to Ed Wynne, Phasic Interware, Inc., - for his permission to do so. [Steven Gillispie] - -Version 2.0fc2 14Oct99 - - - Open Transport sockets didn't close their connections in an orderly way - [Steven Gillispie]. - -Version 2.0fc1 25Sep99 - - - The number and severity of bug reports has decreased sufficiently to - convince me to declare final candidate status on GUSI 2. Please report - all bugs immediately. - - Added sanity checks on A5 before attempting to call InitGraf [Brian Pink]. - - Renamed the socket option IPPROTO_IP/IP_BROADCAST to its correct name - SOL_SOCKET/SO_BROADCAST [Chris Brown]. - -Version 2.0b10 08Sep99 - - - I found several bugs in GUSI when trying to port the Darwin Streaming Server - to MacOS. - - Attempted to deal with threads created outside GUSI (e.g. in PowerPlant) - [Eli Bishop]. - - File manager sockets would misbehave when switching off read-ahead. - - Implemented the interface detection ioctl calls for OpenTransport TCP/IP. - - getsockname would not work on sockets returned fropm accept under - OpenTransport. - - recvfrom would not correctly return the sorce socket address under - OpenTransport except for a connected datagram socket [Philippe Lang]. - - Nonblocking reads on OpenTransport stream sockets did in fact block. - - Nonblocking reads on OpenTransport datagram sockets leaked memory. - - Implemented inet_aton and minimal pthread_condattr and pthread_mutexattr - support. - - Fixed bugs in the documentation [Chris Brown]. Added warning about - interaction between GUSIConfig and precompiled headers [Steven Gillispie]. - -Version 2.0b9 02Sep99 - - - OpenTransport operations in threads sometimes would hang - [Brian Pink, David Catmull]. - -Version 2.0b8 25Aug99 - - - Fixed problems with nonblocking connects in MacTCP [Philippe Lang]. - - Open transport sockets needed to have an explicit unbind [Steven Gillispie]. - - Work on literate edition of the source code. - -Version 2.0b7 04Aug99 - - - Adapted to CodeWarrior Pro 5. - - Updated documentation. - - Tried to clarify license and added pointer to donations page. - -Version 2.0b6 01Aug99 (Happy 708th birthday, Switzerland!) - - - Philippe Lang convinced me to support the SO_ERROR socket option, and while - I was at it, I supported as many socket options as I reasonably could - (mostly on Open Transport). - - Found out that the member fields of a struct timespec are named tv_xxx, not - ts_xxx, thanks to W. Richard Stevens' sample code. - - Fixed conditional macros in sys/un.h [Michel Rabozee]. - - Calling MSL __close_all() turned out not to have been such a hot idea. - -Version 2.0b5 19Jul99 - - - Rick Waits correctly pointed out that most of the new files - promised in b4 were actually missing. - - Fixed bug in MacTCP UDP code [Philippe Lang]. - - Specified bool support in Example project so it would compile again [Rick Waits]. - -Version 2.0b4 18Jul99 - - - Added support for SIOW based programs. - - Added mkdir/rmdir. - - Fixed Open Transport nonblocking connects [Philippe Lang]. - - Fixed long standing inability to give new files the right type and - creator [Chris Jacobson]. - - Add MPW makefile and examples to :Examples [Rick Waits]. - -Version 2.0b3 30Jun99 - - - Added support for Standard C and UNIX 98 style signal handling. - - Added support for using sfio with SC and MrC. - - Improved performance of file I/O. - - Tried to improve documentation for SC and MrC [Rick Waits]. - - Added GUSI_Install.MPW installation script. - - Eradicated dependences on STL from GUSI headers. - -Version 2.0b2 07Jun99 - - - Added support for SC[pp] and MrC[pp] compilers. I compiled with SCpp 8.8.4d1c1 - and MrCpp 4.1.0a5c3, and intend to maintain the code for newer, but not older - versions of these compilers. Unfortunately, Stdio does not work yet when - using GUSI with MrCpp due to shared library conflicts. I intend to support - sfio for SC and MrC in the near future, though. - - Added back STDIN_FILENO & co. Fixed various bad comments in header guards - [Chris Jacobson]. - - select for OpenTransport datagram (UDP) sockets was broken [Philippe Lang]. - - Allow recursive locks for mutexes. - - Added a CodeWarrior project files to simplify rebuilds. - - Some more work on PPC sockets. - -Version 2.0b1 14Apr99 - - - Added support for broadcast and multicast options [Tom Bayley, Quinn]. - - Rewrote GUSIConfig in C++. - - Brought documentation up to date. - - Event handling for AppleEvents was broken [Chris Jacobson]. - - Changed auto-spin default to off, as this feature has less importance in - GUSI II and can easier be turned on with configuration files. - - Introduced GUSIContextFactory to add more flexibility to GUSIContext - creation. Made switching in and out fully virtualized. - - Massively improved and simplified the handling of race conditions - in wakeups [George Warner & Quinn] - - Added support for the DCon debugging console, and also switched to DCon - for our own debugging output. - - Added support for the PPC (Program-to-program communications) toolbox. - - Fixed several bugs in Open Transport support. - - Removed GUSIwithThreading, which is no longer necessary. - -Version 2.0a4 22Nov98 - - - Since my Mac is getting packed up, a hasty and somewhat incomplete, but - interesting release. - - Changed configuration system to explicit configuration files created with - GUSI_Configurator. This change is not reflected in the examples yet. - - Added OpenTransport TCP/IP support (finally!) - -Version 2.0a3 25Oct98 - - - Added MacTCP UDP support, SIOUX support, MSG_PEEK support. - - Fixed many bugs. - - Started adapting old test programs in Examples - -Version 2.0a2 11Oct98 - - - Much more feature complete version: Added most file routines and domain name - support. - - Incorporated as much as I could of Michel Rabozee's excellent feedback. - -Version 2.0a1 02Aug98 - - - A sneak peek to give an impression of the flavor of the new facilities - in GUSI2. This version is far from feature complete, lacking most file - routines, UDP support, support for AppleTalk, OpenTransport support, - and support of the domain name resolver. \ No newline at end of file diff --git a/GUSI/STLport_Install.MPW b/GUSI/STLport_Install.MPW deleted file mode 100755 index 6a0ac30..0000000 Binary files a/GUSI/STLport_Install.MPW and /dev/null differ diff --git a/GUSI/doc/GUSI.pdf b/GUSI/doc/GUSI.pdf deleted file mode 100755 index 60dda10..0000000 Binary files a/GUSI/doc/GUSI.pdf and /dev/null differ diff --git a/GUSI/doc/GUSI_CW_Guide.pdf b/GUSI/doc/GUSI_CW_Guide.pdf deleted file mode 100755 index 9998409..0000000 Binary files a/GUSI/doc/GUSI_CW_Guide.pdf and /dev/null differ diff --git a/GUSI/doc/pod/GUSI.cmd b/GUSI/doc/pod/GUSI.cmd deleted file mode 100755 index 2d1e6d1..0000000 Binary files a/GUSI/doc/pod/GUSI.cmd and /dev/null differ diff --git a/GUSI/doc/pod/GUSI.pod b/GUSI/doc/pod/GUSI.pod deleted file mode 100755 index 2c2d0f2..0000000 Binary files a/GUSI/doc/pod/GUSI.pod and /dev/null differ diff --git a/GUSI/doc/pod/GUSI_Common.pod b/GUSI/doc/pod/GUSI_Common.pod deleted file mode 100755 index 5cffd3c..0000000 Binary files a/GUSI/doc/pod/GUSI_Common.pod and /dev/null differ diff --git a/GUSI/doc/pod/GUSI_Files.pod b/GUSI/doc/pod/GUSI_Files.pod deleted file mode 100755 index 8424165..0000000 Binary files a/GUSI/doc/pod/GUSI_Files.pod and /dev/null differ diff --git a/GUSI/doc/pod/GUSI_Install.pod b/GUSI/doc/pod/GUSI_Install.pod deleted file mode 100755 index c03bcfa..0000000 Binary files a/GUSI/doc/pod/GUSI_Install.pod and /dev/null differ diff --git a/GUSI/doc/pod/GUSI_Misc.pod b/GUSI/doc/pod/GUSI_Misc.pod deleted file mode 100755 index 3e9a49e..0000000 Binary files a/GUSI/doc/pod/GUSI_Misc.pod and /dev/null differ diff --git a/GUSI/doc/pod/GUSI_Sockets.pod b/GUSI/doc/pod/GUSI_Sockets.pod deleted file mode 100755 index 38894be..0000000 Binary files a/GUSI/doc/pod/GUSI_Sockets.pod and /dev/null differ diff --git a/GUSI/doc/pod/GUSI_Threads.pod b/GUSI/doc/pod/GUSI_Threads.pod deleted file mode 100755 index d3d3a59..0000000 Binary files a/GUSI/doc/pod/GUSI_Threads.pod and /dev/null differ diff --git a/GUSI/include/GUSIBasics.h b/GUSI/include/GUSIBasics.h deleted file mode 100755 index a26170e..0000000 --- a/GUSI/include/GUSIBasics.h +++ /dev/null @@ -1,177 +0,0 @@ -// = -#ifndef _GUSIBasics_ -#define _GUSIBasics_ - -#ifdef GUSI_SOURCE - -#include -#include -#include - -#include - -// \section{Definition of compiler features} -// -// If possible, we use unnamed namespaces to wrap internal code. -// -// = -#ifdef __MWERKS__ -#define GUSI_COMPILER_HAS_NAMESPACE -#endif - -#ifdef GUSI_COMPILER_HAS_NAMESPACE -#define GUSI_USING_STD_NAMESPACE using namespace std; using namespace std::rel_ops; -#else -#define GUSI_USING_STD_NAMESPACE -#endif - -// Asynchronous MacOS calls need completion procedures which in classic 68K code -// often take parameters in address registers. The way to handle this differs -// a bit between compilers. Note that the [[pascal]] keyword is ignored when -// generating CFM code. -// -// = -#if TARGET_RT_MAC_CFM -#define GUSI_COMPLETION_PROC_A0(proc, type) \ - void (*const proc##Entry)(type * param) = proc; -#define GUSI_COMPLETION_PROC_A1(proc, type) \ - void (*const proc##Entry)(type * param) = proc; -#elif defined(__MWERKS__) -#define GUSI_COMPLETION_PROC_A0(proc, type) \ - static pascal void proc##Entry(type * param : __A0) { proc(param); } -#define GUSI_COMPLETION_PROC_A1(proc, type) \ - static pascal void proc##Entry(type * param : __A1) { proc(param); } -#else -void * GUSIGetA0() ONEWORDINLINE(0x2008); -void * GUSIGetA1() ONEWORDINLINE(0x2009); -#define GUSI_COMPLETION_PROC_A0(proc, type) \ - static pascal void proc##Entry() \ - { proc(reinterpret_cast(GUSIGetA0())); } -#define GUSI_COMPLETION_PROC_A1(proc, type) \ - static pascal void proc##Entry() \ - { proc(reinterpret_cast(GUSIGetA1())); } -#endif -// %define GUSI_COMPLETION_PROC_A0 GUSI_COMPLETION_PROC_A1 -// -// SC seems to have an issue with mutable fields. -// -// = -#if defined(__SC__) -#define mutable -#define GUSI_MUTABLE(class, field) const_cast(this)->field -#else -#define GUSI_MUTABLE(class, field) field -#endif -// SC pretends to support standard scoping rules, but is in fact broken in -// some cases. -// -// = -#if defined(__SC__) -#define for if (0) ; else for -#endif -// The MPW compilers don't predeclare [[qd]]. -// -// = -#if defined(__SC__) || defined(__MRC__) -#define GUSI_NEEDS_QD QDGlobals qd; -#else -#define GUSI_NEEDS_QD -#endif -// \section{Definition of hook handling} -// -// GUSI supports a number of hooks. Every one of them has a different prototype, -// but is passed as a [[GUSIHook]]. Hooks are encoded with an [[OSType]]. -// -// = -typedef unsigned long OSType; -typedef void (*GUSIHook)(void); -void GUSISetHook(OSType code, GUSIHook hook); -GUSIHook GUSIGetHook(OSType code); -// Currently, three hooks are supported: [[GUSI_SpinHook]] defines a function to -// be called when GUSI waits on an event. -// [[GUSI_ExecHook]] defines a function that determines whether a file is to be -// considered ``executable''. [[GUSI_EventHook]] defines a routine that is called -// when a certain event happens. To install an event hook, pass [[GUSI_EventHook]] -// plus the event code. A few events, that is mouse-down and high level events, -// are handled automatically by GUSI. Passing [[-1]] for the hook disables default -// handling of an event. -// -// = -typedef bool (*GUSISpinFn)(bool wait); -#define GUSI_SpinHook 'spin' - -struct FSSpec; -typedef bool (*GUSIExecFn)(const FSSpec * file); -#define GUSI_ExecHook 'exec' - -struct EventRecord; -typedef void (*GUSIEventFn)(EventRecord * ev); -#define GUSI_EventHook 'evnt' -// For the purposes of the functions who actually call the hooks, here's the direct -// interface. -// -// = -#ifdef GUSI_INTERNAL -extern GUSISpinFn gGUSISpinHook; -extern GUSIExecFn gGUSIExecHook; -#endif /* GUSI_INTERNAL */ -// \section{Definition of error handling} -// -// Like a good POSIX citizen, GUSI reports all errors in the [[errno]] global -// variable. This happens either through the [[GUSISetPosixError]] routine, which -// stores its argument untranslated, or through the [[GUSISetMacError]] routine, -// which translates MacOS error codes into the correct POSIX codes. The mapping -// of [[GUSISetMacError]] is not always appropriate, so some routines will have to -// preprocess some error codes. [[GUSIMapMacError]] returns the POSIX error corresponding -// to a MacOS error. -// -// The domain name routines use an analogous variable [[h_errno]], which is -// manipulated with [[GUSISetHostError]] and [[GUSISetMacHostError]]. -// -// All routines return 0 if 0 was passed and -1 otherwise. -// -// = -typedef short OSErr; - -int GUSISetPosixError(int error); -int GUSISetMacError(OSErr error); -int GUSIMapMacError(OSErr error); -int GUSISetHostError(int error); -int GUSISetMacHostError(OSErr error); -// POSIX routines should never set [[errno]] from nonzero to zero. On the other -// hand, it's sometimes useful to see whether some particular region of the -// program set the error code or not. Therefore, we have such regions allocate -// a [[GUSIErrorSaver]] statically, which guarantees that previous error codes -// get restored if necessary. -// -// = -class GUSIErrorSaver { -public: - GUSIErrorSaver() { fSavedErrno = ::errno; ::errno = 0; } - ~GUSIErrorSaver() { if (!::errno) ::errno = fSavedErrno; } -private: - int fSavedErrno; -}; -// \section{Definition of event handling} -// -// [[GUSIHandleNextEvent]] events by calling handlers installed -// using the [[GUSI_EventHook]] mechanism. -// -// = -void GUSIHandleNextEvent(long sleepTime); -// \section{Definition of string formatting} -// -// We occasionally need sprintf. To keep compatibility with MSL, Stdio, and Sfio, -// we use an internal version which can be overridden. -// -// = -int GUSI_vsprintf(char * s, const char * format, va_list args); -int GUSI_sprintf(char * s, const char * format, ...); - -#endif /* GUSI_SOURCE */ - -#if TARGET_API_MAC_CARBON -# define LMGetTicks() TickCount() -#endif - -#endif /* _GUSIBasics_ */ diff --git a/GUSI/include/GUSIBuffer.h b/GUSI/include/GUSIBuffer.h deleted file mode 100755 index 9e7fe71..0000000 --- a/GUSI/include/GUSIBuffer.h +++ /dev/null @@ -1,409 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIBuffer.nw - Buffering for GUSI -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:08 chombier -// % Initial import -// % -// % Revision 1.20 2001/01/17 08:33:14 neeri -// % Need to set fOldBuffer to nil after deleting -// % -// % Revision 1.19 2000/10/16 04:34:22 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.18 2000/05/23 06:53:14 neeri -// % Improve formatting -// % -// % Revision 1.17 2000/03/15 07:22:06 neeri -// % Enforce alignment choices -// % -// % Revision 1.16 1999/09/09 07:19:18 neeri -// % Fix read-ahead switch-off -// % -// % Revision 1.15 1999/08/26 05:44:59 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.14 1999/06/30 07:42:05 neeri -// % Getting ready to release 2.0b3 -// % -// % Revision 1.13 1999/05/30 03:09:29 neeri -// % Added support for MPW compilers -// % -// % Revision 1.12 1999/03/17 09:05:05 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.11 1998/11/22 23:06:50 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.10 1998/10/25 11:28:43 neeri -// % Added MSG_PEEK support, recursive locks. -// % -// % Revision 1.9 1998/08/02 12:31:36 neeri -// % Another typo -// % -// % Revision 1.8 1998/08/02 11:20:06 neeri -// % Fixed some typos -// % -// % Revision 1.7 1998/01/25 20:53:51 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.6 1997/11/13 21:12:08 neeri -// % Fall 1997 -// % -// % Revision 1.5 1996/12/22 19:57:55 neeri -// % TCP streams work -// % -// % Revision 1.4 1996/12/16 02:16:02 neeri -// % Add Size(), make inlines inline, use BlockMoveData -// % -// % Revision 1.3 1996/11/24 13:00:26 neeri -// % Fix comment leaders -// % -// % Revision 1.2 1996/11/24 12:52:05 neeri -// % Added GUSIPipeSockets -// % -// % Revision 1.1.1.1 1996/11/03 02:43:32 neeri -// % Imported into CVS -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Buffering for GUSI} -// -// This section defines four classes that handle buffering for GUSI: -// [[GUSIScatterer]], [[GUSIGatherer]], and their common ancestor -// [[GUSIScattGath]] convert between [[iovecs]] and simple buffers in the -// absence of specialized communications routines. A [[GUSIRingBuffer]] -// mediates between a producer and a consumer, one of which is typically -// normal code and the other interrupt level code. -// -// -// = -#ifndef _GUSIBuffer_ -#define _GUSIBuffer_ - -#ifdef GUSI_SOURCE - -#include -#include - -#include - -#include "GUSIDiag.h" -#include "GUSIBasics.h" - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of scattering/gathering} -// -// A [[GUSIScattGath]] translates between an array of [[iovecs]] and a simple buffer, -// allocating scratch space if necessary. -// -// = -class GUSIScattGath { -protected: - // On constructing a [[GUSIScattGath]], we pass an array of [[iovecs]]. For the - // simpler functions, a variant with a single [[buffer]] and [[length]] is also - // available. - // - // = - GUSIScattGath(const iovec *iov, int count, bool gather); - GUSIScattGath(void * buffer, size_t length, bool gather); - virtual ~GUSIScattGath(); -public: - // The [[iovec]], the buffer and its length are then available for public scrutinity. - // Copy constructor and assignment both are a bit nontrivial. - // - // = - const iovec * IOVec() const; - int Count() const; - void * Buffer() const; - operator void *() const; - int Length() const; - int SetLength(int len) const; - void operator=(const GUSIScattGath & other); - GUSIScattGath(const GUSIScattGath & other); -private: - // \section{Implementation of scattering/gathering} - // - // A [[GUSIScattGath]] always consists of [[fIo]], an array of [[iovecs]], [[fCount]], - // the number of sections in the array, and [[fLen]], the total size of the data area. - // If [[fCount]] is 1, [[fBuf]] will be a copy of the pointer to the single section. If - // [[fCount]] is greater than 1, [[fScratch]] will contain a [[Handle]] to a scratch - // area of size [[len]] and [[fBuf]] will contain [[*scratch]]. If the object was - // constructed without providing an [[iovec]] array, [[fTrivialIo]] will be set up - // to hold one. - // - // = - const iovec * fIo; - iovec fTrivialIo; - mutable int fCount; - mutable Handle fScratch; - mutable void * fBuf; - mutable int fLen; - bool fGather; -}; -// A [[GUSIScatterer]] distributes the contents of a buffer over an array of -// [[iovecs]]. -// -// = -class GUSIScatterer : public GUSIScattGath { -public: - GUSIScatterer(const iovec *iov, int count) - : GUSIScattGath(iov, count, false) {} - GUSIScatterer(void * buffer, size_t length) - : GUSIScattGath(buffer, length, false) {} - - GUSIScatterer & operator=(const GUSIScatterer & other) - { *static_cast(this) = other; return *this; } -}; -// A [[GUSIGatherer]] collects the contents of an array of [[iovecs]] into a single -// buffer. -// -// = -class GUSIGatherer : public GUSIScattGath { -public: - GUSIGatherer(const struct iovec *iov, int count) - : GUSIScattGath(iov, count, true) {} - GUSIGatherer(const void * buffer, size_t length) - : GUSIScattGath(const_cast(buffer), length, true) {} - - GUSIGatherer & operator=(const GUSIGatherer & other) - { *static_cast(this) = other; return *this; } -}; - -// \section{Definition of ring buffering} -// -// A [[GUSIRingBuffer]] typically has on one side a non-preeemptive piece of code -// and on the other side a piece of interrupt code. To transfer data from and to -// the buffer, two interfaces are available: A direct interface that transfers -// memory, and an indirect interface that allocates memory regions and then -// has OS routines transfer data from or to them -// -// = -class GUSIRingBuffer { -public: - // On construction of a [[GUSIRingBuffer]], a buffer of the specified size is - // allocated and not released until destruction. [[operator void*]] may be used - // to determine whether construction was successful. - // - // = - GUSIRingBuffer(size_t bufsiz); - ~GUSIRingBuffer(); - operator void*(); - // The direct interface to [[GUSIRingBuffer]] is straightforward: [[Produce]] copies - // memory into the buffer, [[Consume]] copies memory from the buffer, [[Free]] - // determines how much space there is for [[Produce]] and [[Valid]] determines - // how much space there is for [[Consume]]. - // - // = - void Produce(void * from, size_t & len); - void Produce(const GUSIGatherer & gather, size_t & len, size_t & offset); - void Produce(const GUSIGatherer & gather, size_t & len); - void Consume(void * to, size_t & len); - void Consume(const GUSIScatterer & scatter, size_t & len, size_t & offset); - void Consume(const GUSIScatterer & scatter, size_t & len); - size_t Free(); - size_t Valid(); - // [[ProduceBuffer]] tries to find in the ring buffer a contiguous free block of - // memory of the specified size [[len]] or otherwise the biggest available free - // block, returns a pointer to it and sets [[len]] to its length. [[ValidBuffer]] - // specifies that the next [[len]] bytes of the ring buffer now contain valid data. - // - // [[ConsumeBuffer]] returns a pointer to the next valid byte and sets [[len]] to - // the minimum of the number of contiguous valid bytes and the value of len on - // entry. [[FreeBuffer]] specifies that the next [[len]] bytes of the ring - // buffer were consumed and are no longer needed. - // - // = - void * ProduceBuffer(size_t & len); - void * ConsumeBuffer(size_t & len); - void ValidBuffer(void * buffer, size_t len); - void FreeBuffer(void * buffer, size_t len); - // Before the nonpreemptive partner changes any of the buffer's data structures, - // the [[GUSIRingBuffer]] member functions call [[Lock]], and after the change is - // complete, they call [[Release]]. An interrupt level piece of code before - // changing any data structures has to determine whether the buffer is locked by - // calling [[Locked]]. If the buffer is locked or otherwise in an unsuitable state, - // the code can specify a procedure to be called during the next [[Release]] by - // calling [[Defer]]. A deferred procedure should call [[ClearDefer]] to avoid - // getting activated again at the next opportunity. - // - // = - void Lock(); - void Release(); - bool Locked(); - typedef void (*Deferred)(void *); - void Defer(Deferred def, void * ar); - void ClearDefer(); - // It is possible to switch buffer sizes during the existence of a buffer, but we - // have to be somewhat careful, since some asynchronous call may still be writing - // into the old buffer. [[PurgeBuffers]], called at safe times, cleans up old - // buffers. - // - // = - void SwitchBuffer(size_t bufsiz); - size_t Size(); - void PurgeBuffers(); - // Sometimes, it's necessary to do nondestructive reads, a task complex enough to - // warrant its own class. - // - // = - class Peeker { - public: - Peeker(GUSIRingBuffer & buffer); - ~Peeker(); - - void Peek(void * to, size_t & len); - void Peek(const GUSIScatterer & scatter, size_t & len); - private: - // A [[GUSIRingBuffer::Peeker]] has to keep its associated [[GUSIRingBuffer]] locked during - // its entire existence. - // - // = - GUSIRingBuffer & fTopBuffer; - GUSIRingBuffer * fCurBuffer; - Ptr fPeek; - // The core routine for reading is [[PeekBuffer]] which automatically advances the - // peeker as well. - // - // = - void * PeekBuffer(size_t & len); - }; - friend class Peeker; - - void Peek(void * to, size_t & len); - void Peek(const GUSIScatterer & scatter, size_t & len); -private: - // \section{Implementation of ring buffering} - // - // The buffer area of a ring buffer extends between [[fBuffer]] and [[fEnd]]. [[fValid]] - // contains the number of valid bytes, while [[fFree]] and [[fSpare]] (Whose purpose - // will be explained later) sum up to the number of free bytes. [[fProduce]] points at the - // next free byte, while [[fConsume]] points at the next valid byte. [[fInUse]] - // indicates that an asynchronous call might be writing into the buffer. - // - // = - Ptr fBuffer; - Ptr fEnd; - Ptr fConsume; - Ptr fProduce; - size_t fFree; - size_t fValid; - size_t fSpare; - bool fInUse; - // The relationships between the various pointers are captured by [[Invariant]] which - // uses the auxiliary function [[Distance]] to determine the distance between two - // pointers in the presence of wrap around areas. - // - // = - bool Invariant(); - size_t Distance(Ptr from, Ptr to); - // The lock mechanism relies on [[fLocked]], and the deferred procedure and its argument - // are stored in [[fDeferred]] and [[fDeferredArg]]. - // - // = - int fLocked; - Deferred fDeferred; - void * fDeferredArg; - // We only switch the next time the buffer is empty, so we are prepared to create - // the new buffer dynamically and forward requests to it for a while. - // - // = - GUSIRingBuffer * fNewBuffer; - GUSIRingBuffer * fOldBuffer; - void ObsoleteBuffer(); - // The scatter/gather variants of [[Produce]] and [[Consume]] rely on a common - // strategy. - // - // = - void IterateIOVec(const GUSIScattGath & sg, size_t & len, size_t & offset, bool produce); -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// Clients need readonly access to the buffer address and read/write access to the length. -// [[operator void*]] server to check whether the [[GUSIScattGath]] was constructed -// successfully. -// -// = -inline const iovec * GUSIScattGath::IOVec() const - { return fIo; } -inline int GUSIScattGath::Count() const - { return fCount; } -inline GUSIScattGath::operator void *() const - { return Buffer(); } -inline int GUSIScattGath::Length() const - { return fLen; } -inline int GUSIScattGath::SetLength(int len) const - { return GUSI_MUTABLE(GUSIScattGath, fLen) = len; } -// = -inline void GUSIRingBuffer::Produce(const GUSIGatherer & gather, size_t & len, size_t & offset) -{ - IterateIOVec(gather, len, offset, true); -} - -inline void GUSIRingBuffer::Consume(const GUSIScatterer & scatter, size_t & len, size_t & offset) -{ - IterateIOVec(scatter, len, offset, false); -} - -inline void GUSIRingBuffer::Produce(const GUSIGatherer & gather, size_t & len) -{ - size_t offset = 0; - - IterateIOVec(gather, len, offset, true); -} - -inline void GUSIRingBuffer::Consume(const GUSIScatterer & scatter, size_t & len) -{ - size_t offset = 0; - - IterateIOVec(scatter, len, offset, false); -} -// The lock support is rather straightforward. -// -// = -inline void GUSIRingBuffer::Lock() { ++fLocked; } -inline bool GUSIRingBuffer::Locked() { return (fLocked!=0); } -inline void GUSIRingBuffer::ClearDefer() { fDeferred = nil; } -inline void GUSIRingBuffer::Release() -{ - GUSI_CASSERT_INTERNAL(fLocked > 0); - if (--fLocked <= 0 && fDeferred) - fDeferred(fDeferredArg); -} -inline void GUSIRingBuffer::Defer(Deferred def, void * ar) -{ - fDeferred = def; - fDeferredArg = ar; -} -// The size is stored only implicitely. -// -// = -inline size_t GUSIRingBuffer::Size() { return fEnd - fBuffer; } -// = -inline void GUSIRingBuffer::Peek(void * to, size_t & len) -{ - Peeker peeker(*this); - - peeker.Peek(to, len); -} - -inline void GUSIRingBuffer::Peek(const GUSIScatterer & scatter, size_t & len) -{ - Peeker peeker(*this); - - peeker.Peek(scatter, len); -} -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIBuffer_ */ diff --git a/GUSI/include/GUSIConfig.h b/GUSI/include/GUSIConfig.h deleted file mode 100755 index 87c1712..0000000 --- a/GUSI/include/GUSIConfig.h +++ /dev/null @@ -1,289 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIConfig.nw - Configuration settings -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.18 2001/01/22 04:31:11 neeri -// % Last minute changes for 2.1.5 -// % -// % Revision 1.17 2001/01/17 08:40:17 neeri -// % Prevent inlining of overridable functions -// % -// % Revision 1.16 2000/05/23 06:54:39 neeri -// % Improve formatting, update to latest universal headers -// % -// % Revision 1.15 2000/03/15 07:10:29 neeri -// % Fix suffix searching code -// % -// % Revision 1.14 2000/03/06 06:24:34 neeri -// % Fix plausibility tests for A5 -// % -// % Revision 1.13 1999/09/26 03:56:44 neeri -// % Sanity check for A5 -// % -// % Revision 1.12 1999/08/26 05:44:59 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.11 1999/06/28 05:57:03 neeri -// % Support SIGINT generation -// % -// % Revision 1.10 1999/05/29 06:26:41 neeri -// % Fixed header guards -// % -// % Revision 1.9 1999/03/29 09:51:28 neeri -// % New configuration system with support for hardcoded configurations. -// % -// % Revision 1.8 1999/03/17 09:05:05 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.7 1998/10/11 16:45:10 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.6 1998/08/01 21:32:01 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.5 1998/01/25 20:53:52 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.4 1997/11/13 21:12:10 neeri -// % Fall 1997 -// % -// % Revision 1.3 1996/11/24 13:00:27 neeri -// % Fix comment leaders -// % -// % Revision 1.2 1996/11/24 12:52:06 neeri -// % Added GUSIPipeSockets -// % -// % Revision 1.1.1.1 1996/11/03 02:43:32 neeri -// % Imported into CVS -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{GUSI Configuration settings} -// -// GUSI stores its global configuration settings in the [[GUSIConfiguration]] -// singleton class. To create the instance, GUSI calls the [[GUSISetupConfig]] -// hook. -// -// = -#ifndef _GUSIConfig_ -#define _GUSIConfig_ - -#ifdef GUSI_SOURCE - -#include "GUSIFileSpec.h" - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of configuration settings} -// -// The GUSIConfiguration has a single instance with read only access, accessible -// with the static [[Instance]] member function. -// -// = -class GUSIConfiguration { -public: - enum { kNoResource = -1, kDefaultResourceID = 10240 }; - - static GUSIConfiguration * Instance(); - static GUSIConfiguration * CreateInstance(short resourceID = kDefaultResourceID); - - // To determine the file type and creator of a newly created file, we first try - // to match one of the [[FileSuffix]] suffices. - // - // = - struct FileSuffix { - char suffix[4]; - OSType suffType; - OSType suffCreator; - }; - short fNumSuffices; - FileSuffix * fSuffices; - - void ConfigureSuffices(short numSuffices, FileSuffix * suffices); - // If none of the suffices matches, we apply the default type and creator. These - // rules are applied with [[SetDefaultFType]]. - // - // = - OSType fDefaultType; - OSType fDefaultCreator; - - void ConfigureDefaultTypeCreator(OSType defaultType, OSType defaultCreator); - void SetDefaultFType(const GUSIFileSpec & name) const; - // To simplify Macintosh friendly ports of simple, I/O bound programs it is - // possible to specify automatic yielding on read() and write() calls. - // [[AutoSpin]] will spin a cursor and/or yield the CPU if desired. - // - // = - bool fAutoSpin; - - void ConfigureAutoSpin(bool autoSpin); - void AutoSpin() const; - // GUSI applications can crash hard if QuickDraw is not initialized. Therefore, we - // offer to initialize it automatically with the [[fAutoInitGraf]] feature. - // - // = - bool fAutoInitGraf; - - void ConfigureAutoInitGraf(bool autoInitGraf); - void AutoInitGraf(); - // Due to the organization of a UNIX filesystem, it is fairly easy to find - // out how many subdirectories a given directory has, since the [[nlink]] field of - // its inode will automatically contain the number of subdirectories[[+2]]. Therefore, - // some UNIX derived code depends on this behaviour. When [[fAccurateStat]] is set, - // GUSI emulates this behaviour, but be warned that this makes [[stat]] on - // directories a much more expensive operation. If [[fAccurateStat]] is not set, - // stat() gives the total number of entries in the directory[[+2]] as a conservative - // estimate. - // - // = - bool fAccurateStat; - - void ConfigureAccurateStat(bool accurateState); - // The [[fSigPipe]] feature causes a signal [[SIGPIPE]] to be raised if an attempt - // is made to write to a broken pipe. - // - // = - bool fSigPipe; - - void ConfigureSigPipe(bool sigPipe); - void BrokenPipe(); - // The [[fSigInt]] feature causes a signal [[SIGINT]] to be raised if the user presses - // command-period. - // - // = - bool fSigInt; - - void ConfigureSigInt(bool sigInt); - void CheckInterrupt(); - // If [[fSharedOpen]] is set, open() opens files with shared read/write permission. - // - // = - bool fSharedOpen; - - void ConfigureSharedOpen(bool sharedOpen); - // If [[fHandleAppleEvents]] is set, GUSI automatically handles AppleEvents in its - // event handling routine. - // - // = - bool fHandleAppleEvents; - - void ConfigureHandleAppleEvents(bool handleAppleEvents); -protected: - GUSIConfiguration(short resourceID = kDefaultResourceID); -private: - // \section{Implementation of configuration settings} - // - // The sole instance of [[GUSIConfiguration]] is created on demand. - // - // = - static GUSIConfiguration * sInstance; - // [[ConfigureSuffices]] sets up the suffix table. - // - // = - bool fWeOwnSuffices; - // [[AutoSpin]] tests the flag inline, but performs the actual spinning out of - // line. - // - // = - void DoAutoSpin() const; - // [[AutoInitGraf]] works rather similarly to [[AutoSpin]]. - // - // = - void DoAutoInitGraf(); - // [[CheckInterrupt]] raises a [[SIGINT]] signal if desired. - // - // = - bool CmdPeriod(const EventRecord * event); -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// To create the sole instance of [[GUSIConfiguration]], we call [[GUSISetupConfig]] -// which has to call [[GUSIConfiguration::CreateInstance]]. -// -// = -#ifdef __MRC__ -#pragma noinline_func GUSISetupConfig -#endif - -extern "C" void GUSISetupConfig(); -// = -inline GUSIConfiguration * GUSIConfiguration::Instance() -{ - if (!sInstance) - GUSISetupConfig(); - if (!sInstance) - sInstance = new GUSIConfiguration(); - - return sInstance; -} - -inline GUSIConfiguration * GUSIConfiguration::CreateInstance(short resourceID) -{ - if (!sInstance) - sInstance = new GUSIConfiguration(resourceID); - - return sInstance; -} -// = -inline void GUSIConfiguration::ConfigureDefaultTypeCreator(OSType defaultType, OSType defaultCreator) -{ - fDefaultType = defaultType; - fDefaultCreator = defaultCreator; -} -// = -inline void GUSIConfiguration::ConfigureAutoSpin(bool autoSpin) -{ - fAutoSpin = autoSpin; -} -// = -inline void GUSIConfiguration::AutoSpin() const -{ - if (fAutoSpin) - DoAutoSpin(); -} -// = -inline void GUSIConfiguration::ConfigureAutoInitGraf(bool autoInitGraf) -{ - fAutoInitGraf = autoInitGraf; -} -// = -inline void GUSIConfiguration::AutoInitGraf() -{ - if (fAutoInitGraf) - DoAutoInitGraf(); -} -// = -inline void GUSIConfiguration::ConfigureSigPipe(bool sigPipe) -{ - fSigPipe = sigPipe; -} -// = -inline void GUSIConfiguration::ConfigureSigInt(bool sigInt) -{ - fSigInt = sigInt; -} -// = -inline void GUSIConfiguration::ConfigureAccurateStat(bool accurateStat) -{ - fAccurateStat = accurateStat; -} -inline void GUSIConfiguration::ConfigureSharedOpen(bool sharedOpen) -{ - fSharedOpen = sharedOpen; -} -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIConfig_ */ diff --git a/GUSI/include/GUSIContext.h b/GUSI/include/GUSIContext.h deleted file mode 100755 index dfb0c2f..0000000 --- a/GUSI/include/GUSIContext.h +++ /dev/null @@ -1,506 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIContext.nw - Thread and Process structures -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/07 09:50:40 chombier -// % First Imported. -// % -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.22 2001/01/22 04:31:11 neeri -// % Last minute changes for 2.1.5 -// % -// % Revision 1.21 2001/01/17 08:43:42 neeri -// % Tweak scheduling -// % -// % Revision 1.20 2000/12/23 06:09:21 neeri -// % May need to create context for IO completions -// % -// % Revision 1.19 2000/10/16 04:34:22 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.18 2000/06/01 06:31:09 neeri -// % Delete SigContext -// % -// % Revision 1.17 2000/05/23 06:56:19 neeri -// % Improve formatting, add socket closing queue, tune scheduling -// % -// % Revision 1.16 2000/03/15 07:11:50 neeri -// % Fix detached delete (again), switcher restore -// % -// % Revision 1.15 2000/03/06 08:10:09 neeri -// % Fix sleep in main thread -// % -// % Revision 1.14 2000/03/06 06:13:46 neeri -// % Speed up thread/process switching through minimal quotas -// % -// % Revision 1.13 1999/12/13 02:40:50 neeri -// % GUSISetThreadSwitcher had Boolean <-> bool inconsistency -// % -// % Revision 1.12 1999/11/15 07:25:32 neeri -// % Safe context setup. Check interrupts only in foreground. -// % -// % Revision 1.11 1999/09/09 07:18:06 neeri -// % Added support for foreign threads -// % -// % Revision 1.10 1999/08/26 05:44:59 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.9 1999/06/28 05:59:02 neeri -// % Add signal handling support -// % -// % Revision 1.8 1999/05/30 03:09:29 neeri -// % Added support for MPW compilers -// % -// % Revision 1.7 1999/03/17 09:05:05 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.6 1999/02/25 03:34:24 neeri -// % Introduced GUSIContextFactory, simplified wakeup -// % -// % Revision 1.5 1998/11/22 23:06:51 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.4 1998/10/11 16:45:11 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.3 1998/08/01 21:26:18 neeri -// % Switch dynamically to threading model -// % -// % Revision 1.2 1998/02/11 12:57:11 neeri -// % PowerPC Build -// % -// % Revision 1.1 1998/01/25 21:02:41 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Thread and Process structures} -// -// This section defines the process and thread switching engine of GUSI. -// -// In some execution environments, completion routines execute at interrupt level. -// GUSI therefore is designed so all information needed to operate from interrupt -// level is accessible from a [[GUSISocket]]. This information is separated into -// per-process data, collected in [[GUSIProcess]], and per-thread data, collected -// in [[GUSIContext]]. [[GUSIProcess]] is always a singleton, while [[GUSIContext]] -// is a singleton if threading is disabled, and has multiple instances if threading -// is enabled. By delegating the [[GUSIContext]] creation process to an instance -// of a [[GUSIContextFactory]], we gain some extra flexibility. -// -// As soon as GUSI has started an asynchronous call, it calls the [[Wait]] member -// function of its context. [[msec]] will set a time limit after which the call will -// return in any case. Exceptional events may also cause [[GUSIWait]] to return, so -// it is not safe to assume that the call will have completed upon return. -// -// -// = -#ifndef _GUSIContext_ -#define _GUSIContext_ - -#include -#include -#include - -#include -#include - -__BEGIN_DECLS -// To maintain correct state, we have to remain informed which thread is active, so -// we install all sorts of hooks. Clients have to use the C++ interface or call -// [[GUSINewThread]], [[GUSISetThreadSwitcher]], and [[GUSISetThreadTerminator]]. -// instead of the thread manager routines. -// -// = -OSErr GUSINewThread( - ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, - void **threadResult, ThreadID *threadMade); -OSErr GUSISetThreadSwitcher(ThreadID thread, - ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut); -OSErr GUSISetThreadTerminator(ThreadID thread, - ThreadTerminationProcPtr threadTerminator, void *terminationProcParam); -__END_DECLS - -#ifndef GUSI_SOURCE - -typedef struct GUSIContext GUSIContext; - -#else - -#include "GUSISpecific.h" -#include "GUSIBasics.h" -#include "GUSIContextQueue.h" - -#include -#include -#include - -// \section{Definition of completion handling} -// -// {\tt GUSIContext} is heavily circular both with classes declared herein and -// in other files. Therefore, we start by declaring a few class names. -// -// = -class GUSISocket; -class GUSIContext; -class GUSIProcess; -class GUSISigProcess; -class GUSISigContext; -class GUSITimer; - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// Ultimately, we will call through to the thread manager, but if an application uses foreign -// sources of threads, we might have to go through indirections. -// -// = -class GUSIThreadManagerProxy { -public: - virtual OSErr NewThread( - ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade); - virtual OSErr SetThreadSwitcher( - ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, - Boolean inOrOut); - virtual OSErr SetThreadTerminator( - ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminatorParam); - - virtual ~GUSIThreadManagerProxy() {} - - static GUSIThreadManagerProxy * Instance(); -protected: - GUSIThreadManagerProxy() {} - - static GUSIThreadManagerProxy * MakeInstance(); -}; -// A [[GUSIProcess]] contains all the data needed to wake up a process: -// -// \begin{itemize} -// \item The [[ProcessSerialNumber]] of the process. -// \item The [[ThreadTaskRef]] if threads are enabled. -// \item The contents of the A5 register. -// \end{itemize} -// -// The sole instance of [[GUSIProcess]] is obtained by calling the [[GUSIProcess::Instance]] static member -// function, which will create the instance if necessary. Interrupt level prcedures may access the application's -// A5 register either manually by calling [[GetA5]] or simply by declaring a [[GUSIProcess::A5Saver]] in a scope. -// -// = -enum GUSIYieldMode { - kGUSIPoll, // Busy wait for some unblockable condition - kGUSIBlock, // Wait for some blockable condition - kGUSIYield // Yield to some other eligible thread -}; - -class GUSIProcess { -public: - static GUSIProcess * Instance(); - static void DeleteInstance(); - void GetPSN(ProcessSerialNumber * psn); - void AcquireTaskRef(); - ThreadTaskRef GetTaskRef(); - long GetA5(); - bool Threading(); - void Yield(GUSIYieldMode wait); - void Wakeup(); - GUSISigProcess * SigProcess() { return fSigProcess; } - void QueueForClose(GUSISocket * sock); - // A [[GUSIProcess::A5Saver]] is a class designed to restore the process A5 - // register for the scope of its declaration. - // - // = - class A5Saver { - public: - A5Saver(long processA5); - A5Saver(GUSIContext * context); - A5Saver(GUSIProcess * process); - ~A5Saver(); - private: - long fSavedA5; - }; -protected: - friend class GUSIContext; - - GUSIProcess(bool threading); - ~GUSIProcess(); - - int fReadyThreads; - int fExistingThreads; - GUSISigProcess * fSigProcess; -private: - // \section{Implementation of completion handling} - // - // [[Instance]] returns the sole instance of [[GUSIProcess]], creating it if - // necessary. - // - // = - static GUSIProcess * sInstance; - // Much of the information stored in a [[GUSIProcess]] is static and read-only. - // - // = - ProcessSerialNumber fProcess; - ThreadTaskRef fTaskRef; - long fA5; - // The exception is the [[fClosing]] socket queue and some yielding related flags. - // - // = - GUSISocket * fClosing; - UInt32 fResumeTicks; - bool fWillSleep; - bool fDontSleep; -}; -// A [[GUSIContext]] gathers thread related data. The central operation on a -// [[GUSIContext]] is [[Wakeup]]. If the process is not asleep when [[Wakeup]] -// is called, it is marked for deferred wakeup. -// -// A [[GUSIContext]] can either be created from an existing thread manager -// [[ThreadID]] or by specifying the parameters for a [[NewThread]] call. -// -// [[Current]] returns the current [[GUSIContext]]. [[Setup]] initializes the -// default context for either the threading or the non-threading model. -// -// [[Yield]] suspends the current process or thread until something interesting -// happens if [[wait]] is [[kGUSIBlock]. Otherwise, [[Yield]] switches, -// but does not suspend. For an ordinary thread context, [[Yield]] simply yields -// the thread. For the context in a non-threading application, [[Yield]] does a -// [[WaitNextEvent]]. For the main thread context, [[Yield]] does both. -// -// [[Done]] tests whether the thread has terminated yet. If [[join]] is set, -// the caller is willing to wait. [[Result]] returns the default location to store -// the thread result if no other is specified. -// -// By default, a context is joinable. Calling [[Detach]] will cause the context to -// be destroyed automatically upon thread termination, and joins are no longer allowed. -// A joinable context will not be destroyed automatically before the end of the -// program, so you will have to call [[Liquidate]] to do that. -// -// [[SetSwitchIn]], [[SetSwitchOut]], and [[SetTerminator]] set per-thread user -// switch and termination procedures. [[SwitchIn]], [[SwitchOut]], and [[Terminate]] -// call the user defined procedures then perform their own actions. -// -// = -class GUSIContext : public GUSISpecificTable { -public: - friend class GUSIProcess; - friend class GUSIContextFactory; - - ThreadID ID() { return fThreadID; } - virtual void Wakeup(); - void ClearWakeups() { fWakeup = false; } - GUSIProcess * Process() { return fProcess; } - void Detach() { fFlags |= detached; } - void Liquidate(); - OSErr Error() { return sError; } - bool Done(bool join); - void * Result() { return fResult; } - GUSISigContext * SigContext() { return fSigContext; } - - static GUSIContext * Current() { return sCurrentContext; } - static GUSIContext * CreateCurrent(bool threading = false) - { if (!sCurrentContext) Setup(threading); return sCurrentContext; } - static GUSIContext * Lookup(ThreadID id); - static void Setup(bool threading); - static bool Yield(GUSIYieldMode wait); - static void SigWait(sigset_t sigs); - static void SigSuspend(); - static bool Raise(bool allSigs = false); - static sigset_t Pending(); - static sigset_t Blocked(); - - void SetSwitchIn(ThreadSwitchProcPtr switcher, void *switchParam); - void SetSwitchOut(ThreadSwitchProcPtr switcher, void *switchParam); - void SetTerminator(ThreadTerminationProcPtr terminator, void *terminationParam); - - static GUSIContextQueue::iterator begin() { return sContexts.begin(); } - static GUSIContextQueue::iterator end() { return sContexts.end(); } - static void LiquidateAll() { sContexts.LiquidateAll(); } -protected: - // = - friend class GUSIContextFactory; - // The thread switcher updates the pointer to the current context and switches - // the global error variables. - // - // = - friend pascal void GUSIThreadSwitchIn(ThreadID thread, GUSIContext * context); - friend pascal void GUSIThreadSwitchOut(ThreadID thread, GUSIContext * context); - // The terminator wakes up the joining thread if a join is pending. - // - // = - friend pascal void GUSIThreadTerminator(ThreadID thread, GUSIContext * context); - - GUSIContext(ThreadID id); - GUSIContext( - ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade); - - virtual void SwitchIn(); - virtual void SwitchOut(); - virtual void Terminate(); - - // At this point, we need to introduce all the private data of a [[GUSIContext]]. - // - // \begin{itemize} - // \item [[fThreadID]] stores the thread manager thread ID. - // \item [[fProcess]] keeps a pointer to the process structure, so completion - // routines can get at it. - // \item [[sCurrentContext]] always points at the current context. - // \item [[sContexts]] contains a queue of all contexts. - // \item [[sHasThreads]] reminds us whether we are threading or not. - // \item We define our own switch-in and termination procedures. If the user specifies procedures - // we store them in [[fSwitchInProc]], [[fSwitchOutProc]], and [[fTerminateProc]] and their parameters - // in [[fSwitchInParam]], [[fSwitchOutParam]], and [[fTerminateParam]] so we can call through to them - // from our procedures. - // \item [[fJoin]] contains the context waiting for us to die; - // \item [[done]] reminds us if the thread is still alive. [[detached]] guarantees - // that we will never wait for that thread anymore. - // \item Last of all, we keep the global error variables [[errno]] and [[h_errno]] - // for each context in the [[fErrno]] and [[fHostErrno]] fields. - // \end{itemize} - // - // - // = - ThreadID fThreadID; - GUSIProcess * fProcess; - GUSIContext * fNext; - GUSISigContext * fSigContext; - ThreadSwitchProcPtr fSwitchInProc; - ThreadSwitchProcPtr fSwitchOutProc; - ThreadTerminationProcPtr fTerminateProc; - void * fSwitchInParam; - void * fSwitchOutParam; - void * fTerminateParam; - void * fResult; - GUSIContext * fJoin; - enum { - done = 1 << 0, - detached= 1 << 1, - asleep = 1 << 2 - }; - char fFlags; - bool fWakeup; - UInt32 fEntryTicks; - int fErrno; - int fHostErrno; - - class Queue : public GUSIContextQueue { - public: - void LiquidateAll(); - - ~Queue() { LiquidateAll(); } - }; - - static Queue sContexts; - static GUSIContext * sCurrentContext; - static bool sCreatingCurrentContext; - static bool sHasThreading; - static OSErr sError; - // The [[GUSIContext]] constructor links the context into the queue of existing - // contexts and installs the appropriate thread hooks. We split this into two - // routines: [[StartSetup]] does static setup before the thread id is determined, - // [[FinishSetup]] does the queueing. - // - // = - void StartSetup(); - void FinishSetup(); - // Destruction of a [[GUSIContext]] requires some cleanup. - // - // = - virtual ~GUSIContext(); -}; -// [[GUSIContext]] instances are created by instances of [[GUSIContextFactory]]. -// -// = -class GUSIContextFactory { -public: - static GUSIContextFactory * Instance(); - static void SetInstance(GUSIContextFactory * instance); - static void DeleteInstance(); - - virtual GUSIContext * CreateContext(ThreadID id); - virtual GUSIContext * CreateContext( - ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options = kCreateIfNeeded, - void **threadResult = nil, ThreadID *threadMade = nil); - - virtual ~GUSIContextFactory(); -protected: - GUSIContextFactory(); -}; -// To make it possible to install an alternative [[GUSIContextFactory]], we provide the -// [[GUSISetupContextFactory()]] hook for overriding; -// -// = -extern "C" void GUSISetupContextFactory(); -// Many asynchronous calls take the same style of I/O parameter block and thus -// can be handled by the same completion procedure. [[StartIO]] prepares -// a parameter block for asynchronous I/O; [[FinishIO]] waits for the I/O -// to complete. The parameter block has to be wrapped in a [[GUSIIOPBWrapper]]. -// -// = -void GUSIStartIO(IOParam * pb); -OSErr GUSIFinishIO(IOParam * pb); -OSErr GUSIControl(IOParam * pb); -template struct GUSIIOPBWrapper { - GUSIContext * fContext; - PB fPB; - - GUSIIOPBWrapper() {} - GUSIIOPBWrapper(const PB & pb) { memcpy(&fPB, &pb, sizeof(PB)); } - - PB * operator->(){ return &fPB; } - void StartIO() { GUSIStartIO(reinterpret_cast(&fPB)); } - OSErr FinishIO() { return GUSIFinishIO(reinterpret_cast(&fPB)); } - OSErr Control() { return GUSIControl(reinterpret_cast(&fPB)); } -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// = -inline GUSIProcess * GUSIProcess::Instance() -{ - if (!sInstance) - sInstance = new GUSIProcess(GUSIContext::sHasThreading); - return sInstance; -} -inline void GUSIProcess::DeleteInstance() -{ - delete sInstance; - sInstance = 0; -} -// = -inline void GUSIProcess::GetPSN(ProcessSerialNumber * psn) - { *psn = fProcess; } -inline void GUSIProcess::AcquireTaskRef() - { GetThreadCurrentTaskRef(&fTaskRef); } -inline ThreadTaskRef GUSIProcess::GetTaskRef() - { return fTaskRef; } -inline long GUSIProcess::GetA5() - { return fA5; } -inline bool GUSIProcess::Threading() - { return fTaskRef!=0;} -// An [[A5Saver]] is trivially implemented but it simplifies bookkeeping. -// -// = -inline GUSIProcess::A5Saver::A5Saver(long processA5) - { fSavedA5 = SetA5(processA5); } -inline GUSIProcess::A5Saver::A5Saver(GUSIProcess * process) - { fSavedA5 = SetA5(process->GetA5()); } -inline GUSIProcess::A5Saver::A5Saver(GUSIContext * context) - { fSavedA5 = SetA5(context->Process()->GetA5()); } -inline GUSIProcess::A5Saver::~A5Saver() - { SetA5(fSavedA5); } - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIContext_ */ diff --git a/GUSI/include/GUSIContextQueue.h b/GUSI/include/GUSIContextQueue.h deleted file mode 100755 index ed2e77e..0000000 --- a/GUSI/include/GUSIContextQueue.h +++ /dev/null @@ -1,237 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIContext.nw - Thread and Process structures -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.9 2001/01/17 08:45:13 neeri -// % Improve memory allocation safety somewhat -// % -// % Revision 1.8 2000/05/23 06:58:03 neeri -// % Improve formatting -// % -// % Revision 1.7 2000/03/15 07:22:06 neeri -// % Enforce alignment choices -// % -// % Revision 1.6 1999/08/26 05:45:00 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.5 1999/05/30 03:09:29 neeri -// % Added support for MPW compilers -// % -// % Revision 1.4 1999/03/17 09:05:06 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/08/02 11:20:07 neeri -// % Fixed some typos -// % -// % Revision 1.2 1998/08/01 21:32:02 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:43 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Context Queues} -// -// At all times through its existence, a [[GUSIContext]] will exist in various -// queues: A queue of all contexts, queues of contexts waiting on a socket -// event, a mutex, or a condition variable, and so on. Since a context is often -// in several queues simultaneously, it's better to define queues non-intrusively. -// -// = -#ifndef _GUSIContextQueue_ -#define _GUSIContextQueue_ - -#ifndef GUSI_SOURCE - -typedef struct GUSIContextQueue GUSIContextQueue; -#else - -#include - -// \section{Definition of context queues} -// -// We'd like to avoid having to include \texttt{GUSIContext} here, for reasons that -// should be rather obvious. -// -// = -class GUSIContext; - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// The class [[GUSIContextQueue]] tries to present an interface that is a subset of -// what C++ standard library list template classes offer. -// -// = -class GUSIContextQueue { -public: - GUSIContextQueue(); - ~GUSIContextQueue(); - - bool empty(); - GUSIContext * front() const; - GUSIContext * back() const; - void push_front(GUSIContext * context); - void push_back(GUSIContext * context); - void push(GUSIContext * context) { push_back(context); } - void pop_front(); - void pop() { pop_front(); } - void remove(GUSIContext * context); - - void Wakeup(); - - // We define a forward iterator, but no reverse iterator. - // - // = - struct element; - class iterator { - friend class GUSIContextQueue; - public: - iterator & operator++(); - iterator operator++(int); - bool operator==(const iterator other) const; - GUSIContext * operator*(); - GUSIContext * operator->(); - private: - // A [[GUSIContextQueue::iterator]] is just a wrapper for a - // [[GUSIContextQueue::element]]. - // - // = - element * fCurrent; - - iterator(element * elt) : fCurrent(elt) {} - iterator() : fCurrent(0) {} - }; - - iterator begin(); - iterator end(); -private: - // \section{Implementation of context queues} - // - // Efficiency of context queues is quite important, so we provide a custom - // allocator for queue elements. - // - // = - struct element { - GUSIContext * fContext; - element * fNext; - - element(GUSIContext * context, element * next = 0) - : fContext(context), fNext(next) {} - void * operator new(size_t); - void operator delete(void *, size_t); - private: - // Elements are allocated in blocks of increasing size. - // - // = - struct header { - short fFree; - short fMax; - header *fNext; - }; - static header * sBlocks; - }; - // A [[GUSIContextQueue]] is a single linked list with a separate back pointer. - // - // = - element * fFirst; - element * fLast; -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// = -inline GUSIContextQueue::GUSIContextQueue() - : fFirst(0), fLast(0) -{ -} -// None of the member functions are very large, so we'll inline them. -// -// = -inline bool GUSIContextQueue::empty() -{ - return !fFirst; -} - -inline GUSIContext * GUSIContextQueue::front() const -{ - return fFirst ? fFirst->fContext : reinterpret_cast(0); -} - -inline GUSIContext * GUSIContextQueue::back() const -{ - return fLast ? fLast->fContext : reinterpret_cast(0); -} - -inline void GUSIContextQueue::push_front(GUSIContext * context) -{ - fFirst = new element(context, fFirst); - if (!fLast) - fLast = fFirst; -} - -inline void GUSIContextQueue::pop_front() -{ - if (element * e = fFirst) { - if (!(fFirst = fFirst->fNext)) - fLast = 0; - delete e; - } -} -// The constructors are not public, so only [[begin]] and [[end]] call them. -// -// = -inline GUSIContextQueue::iterator GUSIContextQueue::begin() -{ - return iterator(fFirst); -} - -inline GUSIContextQueue::iterator GUSIContextQueue::end() -{ - return iterator(); -} -// = -inline GUSIContextQueue::iterator & GUSIContextQueue::iterator::operator++() -{ - fCurrent = fCurrent->fNext; - - return *this; -} - -inline GUSIContextQueue::iterator GUSIContextQueue::iterator::operator++(int) -{ - GUSIContextQueue::iterator it(*this); - fCurrent = fCurrent->fNext; - - return it; -} - -inline bool GUSIContextQueue::iterator::operator==(const iterator other) const -{ - return fCurrent == other.fCurrent; -} - -inline GUSIContext * GUSIContextQueue::iterator::operator*() -{ - return fCurrent->fContext; -} - -inline GUSIContext * GUSIContextQueue::iterator::operator->() -{ - return fCurrent->fContext; -} -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIContextQueue_ */ diff --git a/GUSI/include/GUSIDCon.h b/GUSI/include/GUSIDCon.h deleted file mode 100755 index 8b3debf..0000000 --- a/GUSI/include/GUSIDCon.h +++ /dev/null @@ -1,69 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIDCon.nw - DCon interface -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.4 2000/03/06 06:03:30 neeri -// % Check device families for file paths -// % -// % Revision 1.3 1999/08/26 05:45:00 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.2 1999/05/29 06:26:41 neeri -// % Fixed header guards -// % -// % Revision 1.1 1999/03/17 09:05:06 neeri -// % Added GUSITimer, expanded docs -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{DCon interface} -// -// A [[GUSIDConSocket]] implements an interface to DCon, Cache Computing's -// debugging console. For more information about DCon, see -// \href{http://www.cache-computing.com/products/dcon/}{Cache Computing's site} -// at \verb|http://www.cache-computing.com/products/dcon/|. -// -// All instances of [[GUSIDConSocket]] are created by the [[GUSIDConDevice]] -// singleton, so -// there is no point in exporting the class itself. -// -// = -#ifndef _GUSIDCon_ -#define _GUSIDCon_ - -#ifdef GUSI_INTERNAL - -#include "GUSIDevice.h" - -// \section{Definition of [[GUSIDConDevice]]} -// -// [[GUSIDConDevice]] is a singleton subclass of [[GUSIDevice]]. -// -// = -class GUSIDConDevice : public GUSIDevice { -public: - static GUSIDConDevice * Instance(); - virtual bool Want(GUSIFileToken & file); - virtual GUSISocket * open(GUSIFileToken & file, int flags); -protected: - GUSIDConDevice() {} - static GUSIDConDevice * sInstance; -}; - -// = -inline GUSIDConDevice * GUSIDConDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSIDConDevice; - return sInstance; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIDCon_ */ diff --git a/GUSI/include/GUSIDescriptor.h b/GUSI/include/GUSIDescriptor.h deleted file mode 100755 index b24dced..0000000 --- a/GUSI/include/GUSIDescriptor.h +++ /dev/null @@ -1,217 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIDescriptor.nw - Descriptor Table -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.2 2001/03/28 14:03:59 chombier -// % GUSI 2.1.6b2 update -// % -// % Revision 1.1.1.1 2001/03/07 09:50:41 chombier -// % First Imported. -// % -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.15 2001/01/22 04:31:11 neeri -// % Last minute changes for 2.1.5 -// % -// % Revision 1.14 2001/01/17 08:40:17 neeri -// % Prevent inlining of overridable functions -// % -// % Revision 1.13 2000/06/12 04:23:43 neeri -// % Return values, not references; Introduce support for multiple descriptor tables -// % -// % Revision 1.12 2000/05/23 06:58:03 neeri -// % Improve formatting -// % -// % Revision 1.11 2000/03/15 07:14:26 neeri -// % Prevent double destruction of descriptor table -// % -// % Revision 1.10 2000/03/06 06:26:57 neeri -// % Introduce (and call) CloseAllDescriptors() -// % -// % Revision 1.9 1999/08/26 05:45:01 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.8 1999/08/02 07:02:43 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.7 1999/06/30 07:42:05 neeri -// % Getting ready to release 2.0b3 -// % -// % Revision 1.6 1999/05/29 06:26:42 neeri -// % Fixed header guards -// % -// % Revision 1.5 1999/04/29 05:00:48 neeri -// % Fix bug with bizarre uses of dup2 -// % -// % Revision 1.4 1999/03/17 09:05:06 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/10/11 16:45:12 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.2 1998/08/01 21:32:03 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:44 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.1 1996/12/16 02:12:40 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Mapping descriptors to sockets} -// -// POSIX routines do not, of course, operate on [[GUSISockets]] but on -// numerical descriptors. The [[GUSIDescriptorTable]] singleton maps between -// descriptors and their [[GUSISockets]]. -// -// = -#ifndef _GUSIDescriptor_ -#define _GUSIDescriptor_ - -#ifdef GUSI_SOURCE - -#include "GUSISocket.h" - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of [[GUSIDescriptorTable]]} -// -// A [[GUSIDescriptorTable]] is another singleton class, behaving in many aspects -// like an array of [[GUSISocket]] pointers. [[InstallSocket]] installs a new socket -// into the table, picking the first available slot with a descriptor greater than -// or equal to [[start]]. [[RemoveSocket]] empties one slot. -// [[GUSIDescriptorTable::LookupSocket]] is a shorthand for -// [[ (*GUSIDescriptorTable::Instance())[fd] ]]. -// -// To allow for light-weight processes, we provide a copy constructor and -// the [[SetInstance]] member. -// -// = -class GUSIDescriptorTable { -public: -// enum { SIZE = 64 }; - enum { SIZE = 256 }; - - static GUSIDescriptorTable * Instance(); - - int InstallSocket(GUSISocket * sock, int start = 0); - int RemoveSocket(int fd); - GUSISocket * operator[](int fd); - static GUSISocket * LookupSocket(int fd); - - class iterator; - friend class iterator; - - iterator begin(); - iterator end(); - - ~GUSIDescriptorTable(); - - static void CloseAllDescriptors(); - - static void SetInstance(GUSIDescriptorTable * table); - - GUSIDescriptorTable(); - GUSIDescriptorTable(const GUSIDescriptorTable & parent); -private: - // \section{Implementation of [[GUSIDescriptorTable]]} - // - // On creation, a [[GUSIDescriptorTable]] clears all descriptors. - // - // = - GUSISocket * fSocket[SIZE]; - int fInvalidDescriptor; - // = - static GUSIDescriptorTable * sGUSIDescriptorTable; -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// If no instance exists yet, [[GUSIDescriptorTable::Instance]] creates one and -// calls [[GUSISetupConsole]] if the [[setupConsole]] parameter is true. -// [[GUSISetupConsole]] calls [[GUSIDefaultSetupConsole]], which first calls -// [[GUSISetupConsoleDescriptors]] to set up file descriptors 0, 1, and 2, and -// then calls [[GUSISetupConsoleStdio]] to deal with the necessary initializations -// on the stdio level. -// -// = -extern "C" { -void GUSISetupDescriptorTable(); -void GUSISetupConsole(); -void GUSIDefaultSetupConsole(); -void GUSISetupConsoleDescriptors(); -void GUSISetupConsoleStdio(); -} -// Destructing a [[GUSIDescriptorTable]] may be a bit problematic, as this -// may have effects reaching up into the stdio layer. We therefore factor -// out the stdio aspects into the procedures [[StdioClose]] and [[StdioFlush]] -// which we then can redefine in other, stdio library specific, libraries. -// -// = -extern "C" { -void GUSIStdioClose(); -void GUSIStdioFlush(); -} - -// = -class GUSIDescriptorTable::iterator { -public: - iterator(GUSIDescriptorTable * table, int fd = 0) : fTable(table), fFd(fd) {} - GUSIDescriptorTable::iterator & operator++(); - GUSIDescriptorTable::iterator operator++(int); - int operator*() { return fFd; } - bool operator==(const GUSIDescriptorTable::iterator & other) const; -private: - GUSIDescriptorTable * fTable; - int fFd; -}; - -inline GUSIDescriptorTable::iterator & GUSIDescriptorTable::iterator::operator++() -{ - while (++fFd < fTable->fInvalidDescriptor && !fTable->fSocket[fFd]) - ; - - return *this; -} - -inline GUSIDescriptorTable::iterator GUSIDescriptorTable::iterator::operator++(int) -{ - int oldFD = fFd; - - while (++fFd < fTable->fInvalidDescriptor && !fTable->fSocket[fFd]) - ; - - return GUSIDescriptorTable::iterator(fTable, oldFD); -} - -inline bool GUSIDescriptorTable::iterator::operator==( - const GUSIDescriptorTable::iterator & other) const -{ - return fFd == other.fFd; -} - -inline GUSIDescriptorTable::iterator GUSIDescriptorTable::begin() -{ - return iterator(this); -} - -inline GUSIDescriptorTable::iterator GUSIDescriptorTable::end() -{ - return iterator(this, fInvalidDescriptor); -} - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIDescriptor_ */ diff --git a/GUSI/include/GUSIDevice.h b/GUSI/include/GUSIDevice.h deleted file mode 100755 index 3b77a5a..0000000 --- a/GUSI/include/GUSIDevice.h +++ /dev/null @@ -1,381 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIDevice.nw - Devices -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.13 2000/06/12 04:22:30 neeri -// % Return values, not references -// % -// % Revision 1.12 2000/05/23 06:58:03 neeri -// % Improve formatting -// % -// % Revision 1.11 2000/03/15 07:22:06 neeri -// % Enforce alignment choices -// % -// % Revision 1.10 2000/03/06 06:30:30 neeri -// % Check for nonexistent device -// % -// % Revision 1.9 1999/08/26 05:45:01 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.8 1999/07/19 06:21:02 neeri -// % Add mkdir/rmdir, fix various file manager related bugs -// % -// % Revision 1.7 1999/05/29 06:26:42 neeri -// % Fixed header guards -// % -// % Revision 1.6 1999/03/17 09:05:07 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.5 1998/11/22 23:06:52 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.4 1998/10/25 11:37:38 neeri -// % More configuration hooks -// % -// % Revision 1.3 1998/10/11 16:45:13 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.2 1998/08/01 21:28:57 neeri -// % Add directory operations -// % -// % Revision 1.1 1998/01/25 21:02:45 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.1 1996/12/16 02:12:40 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Devices} -// -// Similar to the creation of sockets, operations on files like opening or -// renaming them need to be dispatched to a variety of special cases (Most of -// them of the form "Dev:" preceded by a device name). Analogous to the -// [[GUSISocketFactory]] subclasses registered in a [[GUSISocketDomainRegistry]], -// we therefore have subclasses of [[GUSIDevice]] registered in a -// [[GUSIDeviceRegistry]], although the details of the two registries are -// quite different. -// -// During resolution of a file name, the name and information about it is passed -// around in a [[GUSIFileToken]]. -// -// = -#ifndef _GUSIDevice_ -#define _GUSIDevice_ - -#ifdef GUSI_SOURCE - -#include "GUSISocket.h" -#include "GUSIFileSpec.h" - -#include -#include - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of [[GUSIFileToken]]} -// -// A [[GUSIFileToken]] consists of a pointer to the name as a C string, of a pointer -// to the [[GUSIDevice]] the token resolves to, and, if the token refers to a -// file name rather than a device name, a pointer to a [[GUSIFileSpec]]. Since -// depending on the call, different [[GUSIDevice]] subclasses may handle it, a -// request code has to be passed to the constructor, too. -// -// = -class GUSIDevice; - -class GUSIFileToken : public GUSIFileSpec { -public: - enum Request { - // \section{Operations on Devices} - // - // The [[open]] operation creates a new socket for the specified path or file - // specification. - // - // = - kWillOpen, - // [[remove]] deletes a path or file specification. - // - // = - kWillRemove, - // [[rename]] renames a path or file specification. - // - // = - kWillRename, - // [[stat]] gathers statistical data about a file or directory. - // - // = - kWillStat, - // [[chmod]] changes file modes, to the extent that this is meaningful on MacOS. - // - // = - kWillChmod, - // [[utime]] bumps a file's modification time. - // - // = - kWillUtime, - // [[access]] checks access permissions for a file. - // - // = - kWillAccess, - // [[mkdir]] creates a directory. - // - // = - kWillMkdir, - // [[rmdir]] deletes a directory. - // - // = - kWillRmdir, - // [[opendir]] opens a directory handle on the given directory. - // - // = - kWillOpendir, - // [[symlink]] creates a symbolic link to a file. - // - // = - kWillSymlink, - // [[readlink]] reads the contents of a symbolic link. - // - // = - kWillReadlink, - // [[fgetfileinfo]] and [[fsetfileinfo]] reads and set the type and creator - // code of a file. - // - // = - kWillGetfileinfo, - kWillSetfileinfo, - // [[faccess]] manipulates MPW properties of files. - // - // = - kWillFaccess, - kNoRequest - }; - - GUSIFileToken(const char * path, Request request, bool useAlias = false); - GUSIFileToken(const GUSIFileSpec & spec, Request request); - GUSIFileToken(short fRefNum, Request request); - - bool IsFile() const { return fIsFile; } - bool IsDevice() const { return !fIsFile; } - Request WhichRequest() const { return fRequest; } - GUSIDevice * Device() const { return fDevice; } - const char * Path() const { return fPath; } - - static bool StrFragEqual(const char * name, const char * frag); - enum StdStream { - kStdin, - kStdout, - kStderr, - kConsole, - kNoStdStream = -2 - }; - static StdStream StrStdStream(const char * name); - -private: - GUSIDevice * fDevice; - const char * fPath; - bool fIsFile; - Request fRequest; -}; -// \section{Definition of [[GUSIDirectory]]} -// -// [[GUSIDirectory]] is a directory handle to iterate over all entries in a -// directory. -// -// = -class GUSIDirectory { -public: - virtual ~GUSIDirectory() {} - virtual dirent * readdir() = 0; - virtual long telldir() = 0; - virtual void seekdir(long pos) = 0; - virtual void rewinddir() = 0; -protected: - friend class GUSIDevice; - GUSIDirectory() {} -}; -// \section{Definition of [[GUSIDeviceRegistry]]} -// -// The [[GUSIDeviceRegistry]] is a singleton class registering all socket -// domains. -// -// = -class GUSIDeviceRegistry { -public: - // The only instance of [[GUSIDeviceRegistry]] is, as usual, obtained by calling - // [[Instance]]. - // - // = - static GUSIDeviceRegistry * Instance(); - // = - GUSISocket * open(const char * path, int flags); - // = - int remove(const char * path); - // = - int rename(const char * oldname, const char * newname); - // = - int stat(const char * path, struct stat * buf, bool useAlias); - // = - int chmod(const char * path, mode_t mode); - // = - int utime(const char * path, const utimbuf * times); - // = - int access(const char * path, int mode); - // = - int mkdir(const char * path); - // = - int rmdir(const char * path); - // = - GUSIDirectory * opendir(const char * path); - // = - int symlink(const char * target, const char * newlink); - // = - int readlink(const char * path, char * buf, int bufsize); - // = - int fgetfileinfo(const char * path, OSType * creator, OSType * type); - int fsetfileinfo(const char * path, OSType creator, OSType type); - // = - int faccess(const char * path, unsigned * cmd, void * arg); - // [[AddDevice]] and [[RemoveDevice]] add and remove a [[GUSIDevice]]. - // - // = - void AddDevice(GUSIDevice * device); - void RemoveDevice(GUSIDevice * device); - // It is convenient to define iterators to iterate across all devices. - // - // = - class iterator; - - iterator begin(); - iterator end(); -protected: - // On construction, a [[GUSIFileToken]] looks up the appropriate device in the - // [[GUSIDeviceRegistry]]. - // - // = - friend class GUSIFileToken; - - GUSIDevice * Lookup(GUSIFileToken & file); -private: - // = - static GUSIDeviceRegistry * sInstance; - // Devices are stored in a linked list. On creation of the registry, it immediately - // registers the instance for plain Macintosh file sockets, to which pretty much all - // operations default. This device will never refuse any request. - // - // = - GUSIDevice * fFirstDevice; - GUSIDeviceRegistry(); -}; -// \section{Definition of [[GUSIDevice]]} -// -// [[GUSIDevice]] consists of a few maintenance functions and the -// device operations. The request dispatcher first calls [[Want]] for -// each candidate device and as soon as it's successful, calls the specific -// operation. Devices are kept in a linked list by the [[GUSIDeviceRegistry]]. -// -// = -class GUSIDevice { -public: - virtual bool Want(GUSIFileToken & file); - - // = - virtual GUSISocket * open(GUSIFileToken & file, int flags); - // = - virtual int remove(GUSIFileToken & file); - // = - virtual int rename(GUSIFileToken & from, const char * newname); - // = - virtual int stat(GUSIFileToken & file, struct stat * buf); - // = - virtual int chmod(GUSIFileToken & file, mode_t mode); - // = - virtual int utime(GUSIFileToken & file, const utimbuf * times); - // = - virtual int access(GUSIFileToken & file, int mode); - // = - virtual int mkdir(GUSIFileToken & file); - // = - virtual int rmdir(GUSIFileToken & file); - // = - virtual GUSIDirectory * opendir(GUSIFileToken & file); - // = - virtual int symlink(GUSIFileToken & to, const char * newlink); - // = - virtual int readlink(GUSIFileToken & link, char * buf, int bufsize); - // = - virtual int fgetfileinfo(GUSIFileToken & file, OSType * creator, OSType * type); - virtual int fsetfileinfo(GUSIFileToken & file, OSType creator, OSType type); - // = - virtual int faccess(GUSIFileToken & file, unsigned * cmd, void * arg); -protected: - friend class GUSIDeviceRegistry; - friend class GUSIDeviceRegistry::iterator; - - GUSIDevice() : fNextDevice(nil) {} - virtual ~GUSIDevice() {} - - GUSIDevice * fNextDevice; -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// \section{Implementation of [[GUSIDeviceRegistry]]} -// -// -// = -extern "C" void GUSISetupDevices(); - -// = -inline GUSIDeviceRegistry * GUSIDeviceRegistry::Instance() -{ - if (!sInstance) { - sInstance = new GUSIDeviceRegistry(); - GUSISetupDevices(); - } - - return sInstance; -} -// The [[GUSIDeviceRegistry]] forward iterator is simple. -// -// = -class GUSIDeviceRegistry::iterator { -public: - iterator(GUSIDevice * device = 0) : fDevice(device) {} - GUSIDeviceRegistry::iterator & operator++() - { fDevice = fDevice->fNextDevice; return *this; } - GUSIDeviceRegistry::iterator operator++(int) - { GUSIDeviceRegistry::iterator old(*this); fDevice = fDevice->fNextDevice; return old; } - bool operator==(const GUSIDeviceRegistry::iterator other) const - { return fDevice==other.fDevice; } - GUSIDevice & operator*() { return *fDevice; } - GUSIDevice * operator->() { return fDevice; } -private: - GUSIDevice * fDevice; -}; - -inline GUSIDeviceRegistry::iterator GUSIDeviceRegistry::begin() -{ - return GUSIDeviceRegistry::iterator(fFirstDevice); -} - -inline GUSIDeviceRegistry::iterator GUSIDeviceRegistry::end() -{ - return GUSIDeviceRegistry::iterator(); -} - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIDevice_ */ diff --git a/GUSI/include/GUSIDiag.h b/GUSI/include/GUSIDiag.h deleted file mode 100755 index 409be2a..0000000 --- a/GUSI/include/GUSIDiag.h +++ /dev/null @@ -1,222 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIDiag.nw - Assertions and diagnostics -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.12 2000/06/12 04:20:58 neeri -// % Introduce GUSI_*printf -// % -// % Revision 1.11 2000/05/23 06:58:04 neeri -// % Improve formatting -// % -// % Revision 1.10 1999/08/26 05:45:01 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.9 1999/08/02 07:02:43 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.8 1999/05/29 06:26:42 neeri -// % Fixed header guards -// % -// % Revision 1.7 1999/04/10 04:45:47 neeri -// % Add DCon stubs -// % -// % Revision 1.6 1999/03/17 09:05:07 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.5 1999/02/25 03:49:00 neeri -// % Switched to DCon for logging -// % -// % Revision 1.4 1998/01/25 20:53:53 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.3 1996/12/16 02:17:20 neeri -// % Tune messages -// % -// % Revision 1.2 1996/11/24 12:52:07 neeri -// % Added GUSIPipeSockets -// % -// % Revision 1.1.1.1 1996/11/03 02:43:32 neeri -// % Imported into CVS -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Assertions and diagnostic messages} -// -// GUSI reports on three kinds of error conditions: -// -// \begin{itemize} -// \item {\bf Internal} errors are usually caused by bugs in GUSI. They should be -// considered fatal. -// \item {\bf Client} errors are caused by calling GUSI routines with bad -// parameters. They are typically handled by returning an appropriate error -// code. -// \item {\bf External} errors are caused by various OS and Network related -// problems. Typically, they are also handled by returning an appropriate -// error code. -// \end{itemize} -// -// If you feel lucky, you can turn off the checking for internal and client errors, -// but external errors will always be checked. -// -// = -#ifndef _GUSIDiag_ -#define _GUSIDiag_ - -#include -#include -#include - -#include - -__BEGIN_DECLS -// \section{Definition of diagnostics} -// -// Depending on the diagnostic level, messages get printed to the DCon console. -// -// = -extern char * GUSI_diag_log; -// Printing is done by passing an argument list to [[GUSI_log]]. To simplify the job -// for the diagnostic macros, [[GUSI_log]] returns a [[bool]] value which is -// always [[false]]. [[GUSI_break]] stops with a [[DebugStr]] call. [[GUSI_pos]] -// establishes the source code position for diagnostic messages. -// instead of logging. -// -// = -bool GUSI_pos(const char * file, int line); -bool GUSI_log(const char * format, ...); -bool GUSI_break(const char * format, ...); -// There are four levels of diagnostic handling: -// \begin{itemize} -// \item [[GUSI_DIAG_RECKLESS]] totally ignores all internal and client errors. This -// setting is not recommended. -// \item [[GUSI_DIAG_RELAXED]] ignores internal errors, but checks client errors. This -// setting is probably the best for production code. -// \item [[GUSI_DIAG_CAUTIOUS]] checks and logs internal and client errors. This -// setting is best for GUSI client development. -// \item [[GUSI_DIAG_PARANOID]] immediately stops at internal errors, checks and -// logs client and external errors. This is the preferred setting for GUSI -// internal development. -// \end{itemize} -// -// -// = -#define GUSI_DIAG_RECKLESS 0 -#define GUSI_DIAG_RELAXED 1 -#define GUSI_DIAG_CAUTIOUS 2 -#define GUSI_DIAG_PARANOID 3 -// [[GUSI_DIAG]] is defined to the diagnostic level. It can be overridden on a -// module by module basis, or by changing the default setting here. -// [[GUSI_MESSAGE_LEVEL]] determines how important a message has to be to print it. -// [[GUSI_LOG_POS]] determines whether we want to log the code position. -// -// = -#ifndef GUSI_DIAG -#define GUSI_DIAG GUSI_DIAG_PARANOID -#endif -#ifndef GUSI_LOG_POS -#define GUSI_LOG_POS 0 -#endif -#ifndef GUSI_MESSAGE_LEVEL -#define GUSI_MESSAGE_LEVEL 3 -#endif -// = -#if GUSI_LOG_POS -#define GUSI_POS GUSI_pos(__FILE__, __LINE__) -#define GUSI_LOG GUSI_POS || GUSI_log -#else -#define GUSI_LOG GUSI_log -#endif -#define GUSI_BREAK GUSI_break -// = -#if GUSI_DIAG == GUSI_DIAG_RECKLESS -// [[GUSI_DIAG_RECKLESS]] only checks for external errors. -// -// = -#define GUSI_ASSERT_INTERNAL(COND, ARGLIST) true -#define GUSI_ASSERT_CLIENT(COND, ARGLIST) true -#define GUSI_ASSERT_EXTERNAL(COND, ARGLIST) (COND) -#define GUSI_SASSERT_INTERNAL(COND, MSG) true -#define GUSI_SASSERT_CLIENT(COND, MSG) true -#define GUSI_SASSERT_EXTERNAL(COND, MSG) (COND) -#elif GUSI_DIAG == GUSI_DIAG_RELAXED -// [[GUSI_DIAG_RELAXED]] ignores internal errors, but checks client errors. -// -// = -#define GUSI_ASSERT_INTERNAL(COND, ARGLIST) true -#define GUSI_ASSERT_CLIENT(COND, ARGLIST) (COND) -#define GUSI_ASSERT_EXTERNAL(COND, ARGLIST) (COND) -#define GUSI_SASSERT_INTERNAL(COND, MSG) true -#define GUSI_SASSERT_CLIENT(COND, MSG) (COND) -#define GUSI_SASSERT_EXTERNAL(COND, MSG) (COND) -#elif GUSI_DIAG == GUSI_DIAG_CAUTIOUS -// [[GUSI_DIAG_CAUTIOUS]] checks and logs internal and client errors. -// -// = -#define GUSI_ASSERT_INTERNAL(COND, ARGLIST) ((COND) || GUSI_LOG ARGLIST) -#define GUSI_ASSERT_CLIENT(COND, ARGLIST) ((COND) || GUSI_LOG ARGLIST) -#define GUSI_ASSERT_EXTERNAL(COND, ARGLIST) (COND) -#define GUSI_SASSERT_INTERNAL(COND, MSG) ((COND) || GUSI_LOG ("%s", MSG)) -#define GUSI_SASSERT_CLIENT(COND, MSG) ((COND) || GUSI_LOG ("%s", MSG)) -#define GUSI_SASSERT_EXTERNAL(COND, MSG) (COND) -#elif GUSI_DIAG == GUSI_DIAG_PARANOID -// [[GUSI_DIAG_PARANOID]] immediately stops at internal errors, checks and -// logs client and external errors. -// -// = -#define GUSI_ASSERT_INTERNAL(COND, ARGLIST) ((COND) || GUSI_BREAK ARGLIST) -#define GUSI_ASSERT_CLIENT(COND, ARGLIST) ((COND) || GUSI_LOG ARGLIST) -#define GUSI_ASSERT_EXTERNAL(COND, ARGLIST) ((COND) || GUSI_LOG ARGLIST) -#define GUSI_SASSERT_INTERNAL(COND, MSG) ((COND) || GUSI_BREAK ("%s", (MSG))) -#define GUSI_SASSERT_CLIENT(COND, MSG) ((COND) || GUSI_LOG ("%s", MSG)) -#define GUSI_SASSERT_EXTERNAL(COND, MSG) ((COND) || GUSI_LOG ("%s", MSG)) -#else -#error "GUSI_DIAG defined to illegal value: " GUSI_DIAG -#endif -// There are 11 different diagnostic macros. [[GUSI_ASSERT_INTERNAL]], -// [[GUSI_ASSERT_CLIENT]] and [[GUSI_ASSERT_EXTERNAL]] check for internal, -// client, and external errors, respectively. Their first argument is a -// conditional expression which when [[false]] indicates that an error -// happened. [[GUSI_MESSAGE]] has the same logging status as -// [[GUSI_ASSERT_EXTERNAL]], but does not check any conditions. The [[SASSERT]] -// and [[SMESSAGE]] variants do the same checking, but only take a simple -// message instead of an argument list. The [[CASSERT]] variants simply output -// the condition as the message. -// -// = -#define GUSI_CASSERT_INTERNAL(COND) \ - GUSI_SASSERT_INTERNAL(COND, "(" #COND ") -- assertion failed.\n" ) -#define GUSI_CASSERT_CLIENT(COND) \ - GUSI_SASSERT_CLIENT(COND, "(" #COND ") -- assertion failed.\n" ) -#define GUSI_CASSERT_EXTERNAL(COND) \ - GUSI_SASSERT_EXTERNAL(COND, "(" #COND ") -- assertion failed.\n" ) -#define GUSI_MESSAGE1(ARGLIST) \ - GUSI_ASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>1, ARGLIST) -#define GUSI_SMESSAGE1(MSG) \ - GUSI_SASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>1, MSG) -#define GUSI_MESSAGE2(ARGLIST) \ - GUSI_ASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>2, ARGLIST) -#define GUSI_SMESSAGE2(MSG) \ - GUSI_SASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>2, MSG) -#define GUSI_MESSAGE3(ARGLIST) \ - GUSI_ASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>3, ARGLIST) -#define GUSI_SMESSAGE3(MSG) \ - GUSI_SASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>3, MSG) -#define GUSI_MESSAGE4(ARGLIST) \ - GUSI_ASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>4, ARGLIST) -#define GUSI_SMESSAGE4(MSG) \ - GUSI_SASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>4, MSG) -#define GUSI_MESSAGE5(ARGLIST) \ - GUSI_ASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>5, ARGLIST) -#define GUSI_SMESSAGE5(MSG) \ - GUSI_SASSERT_EXTERNAL(GUSI_MESSAGE_LEVEL>5, MSG) -#define GUSI_MESSAGE(ARGLIST) GUSI_MESSAGE3(ARGLIST) -#define GUSI_SMESSAGE(MSG) GUSI_SMESSAGE3(MSG) -__END_DECLS - -#endif /* _GUSIDiag_ */ diff --git a/GUSI/include/GUSIFSWrappers.h b/GUSI/include/GUSIFSWrappers.h deleted file mode 100755 index 0e8c75e..0000000 --- a/GUSI/include/GUSIFSWrappers.h +++ /dev/null @@ -1,113 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIFSWrappers.nw - Pseudo-synchronous file calls -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.8 2001/07/23 06:31:37 neeri -// % Use PBXGetVolInfoSync to get correct block size for stat() (MacPerl Bug #424874) -// % -// % Revision 1.7 2001/01/17 08:45:49 neeri -// % Make open calls synchronous -// % -// % Revision 1.6 2000/05/23 06:58:04 neeri -// % Improve formatting -// % -// % Revision 1.5 2000/01/17 01:41:52 neeri -// % Handle special cases in FSMoveRename -// % -// % Revision 1.4 1999/08/26 05:45:01 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.3 1999/07/19 06:21:02 neeri -// % Add mkdir/rmdir, fix various file manager related bugs -// % -// % Revision 1.2 1999/05/30 02:16:54 neeri -// % Cleaner definition of GUSICatInfo -// % -// % Revision 1.1 1998/10/11 16:45:14 neeri -// % Ready to release 2.0a2 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Pseudo-synchronous File System Calls} -// -// MacOS offers a wide variety of file system APIs, but the most convenient -// of them--the [[FSpXXX]] calls only works synchronously. The routines defined -// here offer a version of these calls, executed asynchronously and embedded -// into the [[GUSIContext]] switching model. -// -// = -#ifndef _GUSIFSWrappers_ -#define _GUSIFSWrappers_ - -#ifdef GUSI_SOURCE - -#include - -#include - -#include "GUSIFileSpec.h" - -__BEGIN_DECLS -// = -OSErr GUSIFSOpenDriver(StringPtr name, short * refNum); -// = -OSErr GUSIFSGetFInfo(const FSSpec * spec, FInfo * info); -OSErr GUSIFSSetFInfo(const FSSpec * spec, const FInfo * info); -// = -OSErr GUSIFSOpenDF(const FSSpec * spec, char permission, short * refNum); -OSErr GUSIFSOpenRF(const FSSpec * spec, char permission, short * refNum); -// = -OSErr GUSIFSGetVolParms(short vRefNum, GetVolParmsInfoBuffer * volParms); -// = -OSErr GUSIFSCreate(const FSSpec * spec, OSType creator, OSType type, ScriptCode script); -// = -OSErr GUSIFSDelete(const FSSpec * spec); -// = -OSErr GUSIFSDirCreate(const FSSpec * spec); -// = -OSErr GUSIFSSetFLock(const FSSpec * spec); -OSErr GUSIFSRstFLock(const FSSpec * spec); -// = -OSErr GUSIFSRename(const FSSpec * spec, ConstStr255Param newname); -// = -OSErr GUSIFSCatMove(const FSSpec * spec, const FSSpec * dest); -// = -OSErr GUSIFSMoveRename(const FSSpec * spec, const FSSpec * dest); -__END_DECLS -#ifdef __cplusplus -// = -OSErr GUSIFSGetCatInfo(GUSIIOPBWrapper * info); -OSErr GUSIFSSetCatInfo(GUSIIOPBWrapper * info); -// = -OSErr GUSIFSGetFCBInfo(GUSIIOPBWrapper * fcb); -// = -OSErr GUSIFSGetVInfo(GUSIIOPBWrapper * pb); -OSErr GUSIFSHGetVInfo(GUSIIOPBWrapper * pb); -// According to Andreas Grosam, [[PBOpenAsync]] may cause the file not to be closed properly when the -// process quits, so we call that call synchronously. -// -// = -OSErr GUSIFSOpen(GUSIIOPBWrapper * pb); -// = -OSErr GUSIFSHGetFInfo(GUSIIOPBWrapper * pb); -OSErr GUSIFSHSetFInfo(GUSIIOPBWrapper * pb); -// = -OSErr GUSIFSHGetVolParms(GUSIIOPBWrapper * pb); -// = -OSErr GUSIFSCreate(const FSSpec * spec); -// = -OSErr GUSIFSCatMove(const FSSpec * spec, long dest); -// Getting the correct allocation block size can be sort of tricky. [[PBHGetVInfoAsync]] returns -// a value tweaked to allow free space calculations on large volumes, so we have to walk the -// fcb queue to get a legitimate value. -// -// = -OSErr GUSIFSXGetVolInfo(GUSIIOPBWrapper * pb); -#endif - -#endif /* GUSI_SOURCE */ - -#endif /* GUSIFSWrappers */ diff --git a/GUSI/include/GUSIFactory.h b/GUSI/include/GUSIFactory.h deleted file mode 100755 index 794ccff..0000000 --- a/GUSI/include/GUSIFactory.h +++ /dev/null @@ -1,203 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIFactory.nw - Socket factories -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:10 chombier -// % Initial import -// % -// % Revision 1.10 2000/05/23 07:00:00 neeri -// % Improve formatting -// % -// % Revision 1.9 2000/03/15 07:22:07 neeri -// % Enforce alignment choices -// % -// % Revision 1.8 1999/11/15 07:27:18 neeri -// % Getting ready for GUSI 2.0.1 -// % -// % Revision 1.7 1999/08/26 05:45:02 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.6 1999/05/29 06:26:43 neeri -// % Fixed header guards -// % -// % Revision 1.5 1998/11/22 23:06:53 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.4 1998/10/25 11:37:37 neeri -// % More configuration hooks -// % -// % Revision 1.3 1998/08/02 11:20:08 neeri -// % Fixed some typos -// % -// % Revision 1.2 1998/01/25 20:53:54 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.1 1996/12/16 02:12:40 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Socket Factories} -// -// Instead of creating sockets of some specific subtype of [[GUSISocket]], -// directly, we choose the more flexible approach of creating them in -// some instance of a subtype of the abstract factory class [[GUSISocketFactory]]. -// For even more flexibility and a direct mapping to BSD socket domains, -// [[GUSISocketFactory]] instances are collected in a [[GUSISocketDomainRegistry]]. -// If several types and or protocols in a domain are implemented, they are collected -// in a [[GUSISocketTypeRegistry]]. -// -// = -#ifndef _GUSIFactory_ -#define _GUSIFactory_ - -#ifdef GUSI_SOURCE - -#include "GUSISocket.h" - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of [[GUSISocketFactory]]} -// -// [[GUSISocketFactory]] consists of a few maintenance functions and the socket -// operations. -// -// = -class GUSISocketFactory { -public: - virtual int socketpair(int domain, int type, int protocol, GUSISocket * s[2]); - virtual GUSISocket * socket(int domain, int type, int protocol) = 0; -protected: - GUSISocketFactory() {} - virtual ~GUSISocketFactory() {} -}; -// \section{Definition of [[GUSISocketDomainRegistry]]} -// -// The [[GUSISocketDomainRegistry]] is a singleton class registering all socket -// domains. -// -// = -class GUSISocketDomainRegistry : public GUSISocketFactory { -public: - // The only instance of [[GUSISocketDomainRegistry]] is, as usual, obtained by calling - // [[Instance]]. Calling [[socket]] on this instance will then create a socket. - // - // = - virtual GUSISocket * socket(int domain, int type, int protocol); - virtual int socketpair(int domain, int type, int protocol, GUSISocket * s[2]); - static GUSISocketDomainRegistry * Instance(); - // [[AddFactory]] and [[RemoveFactory]] add and remove a [[GUSISocketFactory]] - // for a given domain number. Both return the previous registrant. - // - // = - GUSISocketFactory * AddFactory(int domain, GUSISocketFactory * factory); - GUSISocketFactory * RemoveFactory(int domain); -private: - // = - static GUSISocketDomainRegistry * sInstance; - // We store domain factories in a table that is quite comfortably sized. - // - // = - GUSISocketFactory * factory[AF_MAX]; - GUSISocketDomainRegistry(); -}; -// \section{Definition of [[GUSISocketTypeRegistry]]} -// -// A [[GUSISocketTypeRegistry]] registers factories for some domain by type and -// protocol. -// -// = -class GUSISocketTypeRegistry : public GUSISocketFactory { -public: - // [[GUSISocketTypeRegistry]] is not a singleton, but each instance is somewhat - // singletonish in that it does some delayed initialization only when it's used - // and at that point registers itself with the [[GUSISocketDomainRegistry]]. - // Calling [[socket]] on these instances will then create a socket. - // - // = - GUSISocketTypeRegistry(int domain, int maxfactory); - virtual GUSISocket * socket(int domain, int type, int protocol); - virtual int socketpair(int domain, int type, int protocol, GUSISocket * s[2]); - // [[AddFactory]] and [[RemoveFactory]] add and remove a [[GUSISocketFactory]] - // for a given type and protocol (both of which can be specified as 0 to match any - // value). Both return the previous registrant. - // - // = - GUSISocketFactory * AddFactory(int type, int protocol, GUSISocketFactory * factory); - GUSISocketFactory * RemoveFactory(int type, int protocol); -private: - // \section{Implementation of [[GUSISocketTypeRegistry]]} - // - // We store type factories in a fixed size table. This table is only - // initialized when any non-constructor public member is called. - // - // = - struct Entry { - int type; - int protocol; - GUSISocketFactory * factory; - Entry() : type(0), protocol(0), factory(nil) {} - }; - Entry * factory; - int domain; - int maxfactory; - // [[Initialize]] initializes the table and registers the object with the - // [[GUSISocketDomainRegistry]] the first time it's called. - // - // = - void Initialize(); - // Unlike for a [[GUSISocketDomainRegistry]], match identification for a - // [[GUSISocketTypeRegistry]] takes a linear search. [[Find]] stops - // when it has found either a match or an empty slot. - // - // = - bool Find(int type, int protocol, bool exact, Entry *&found); -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// \section{Implementation of [[GUSISocketDomainRegistry]]} -// -// By now, you should know how singletons are created. Could it be that the -// combination of Design Patterns and Literate Programming leads to a -// proliferation of cliches? -// -// = -extern "C" void GUSISetupFactories(); - -// = -inline GUSISocketDomainRegistry * GUSISocketDomainRegistry::Instance() -{ - if (!sInstance) { - sInstance = new GUSISocketDomainRegistry(); - GUSISetupFactories(); - } - - return sInstance; -} -// [[RemoveFactory]] can actually be implemented in terms of [[AddFactory]] but -// that might confuse readers. -// -// = -inline GUSISocketFactory * GUSISocketDomainRegistry::RemoveFactory(int domain) -{ - return AddFactory(domain, nil); -} -// = -inline GUSISocketTypeRegistry::GUSISocketTypeRegistry(int domain, int maxfactory) - : domain(domain), maxfactory(maxfactory), factory(nil) -{ -} - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIFactory_ */ diff --git a/GUSI/include/GUSIFileSpec.h b/GUSI/include/GUSIFileSpec.h deleted file mode 100755 index 578b315..0000000 --- a/GUSI/include/GUSIFileSpec.h +++ /dev/null @@ -1,599 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIFileSpec.nw - File specifications -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.19 2001/04/16 01:50:02 neeri -// % Fix GUSIFSpGetCatInfo (MacPerl bug #232702); Fix parsing of absolute paths with embedded aliases. -// % -// % Revision 1.18 2001/04/01 07:40:15 neeri -// % Fix :::paths (MacPerl Bug #409940) -// % -// % Revision 1.17 2001/03/20 02:34:22 neeri -// % Commented out false friends -// % -// % Revision 1.16 2001/03/09 09:20:53 neeri -// % Fixed major bugs in relative path generation -// % -// % Revision 1.15 2001/01/17 08:46:45 neeri -// % Get rid of excess directory seperators when name is empty -// % -// % Revision 1.14 2000/12/23 06:10:17 neeri -// % Add GUSIFSpTouchFolder, GUSIFSpGetCatInfo; copy error in copy constructor -// % -// % Revision 1.13 2000/10/16 03:59:36 neeri -// % Make FSSpec a member of GUSIFileSpec instead of a base class -// % -// % Revision 1.12 2000/06/12 04:20:58 neeri -// % Introduce GUSI_*printf -// % -// % Revision 1.11 2000/05/23 07:00:00 neeri -// % Improve formatting -// % -// % Revision 1.10 2000/03/15 07:16:08 neeri -// % Fix path construction, temp name bugs -// % -// % Revision 1.9 2000/03/06 06:34:11 neeri -// % Added C FSSpec convenience calls -// % -// % Revision 1.8 1999/08/26 05:45:02 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.7 1999/07/19 06:21:02 neeri -// % Add mkdir/rmdir, fix various file manager related bugs -// % -// % Revision 1.6 1999/06/28 06:00:53 neeri -// % add support for generating temp names from basename -// % -// % Revision 1.5 1999/05/30 02:16:53 neeri -// % Cleaner definition of GUSICatInfo -// % -// % Revision 1.4 1999/03/17 09:05:07 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/10/11 16:45:15 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.2 1998/08/01 21:32:04 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:46 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{File specifications} -// -// While the Macintosh toolbox has a convenient type [[FSSpec]] to pass to -// file system routines, it lacks manipulation functions. We provide them here. -// This module has been known under a different name and with different data types -// in GUSI 1. -// -// = -#ifndef _GUSIFileSpec_ -#define _GUSIFileSpec_ - -#include -#include -#include - -#include -#include - -__BEGIN_DECLS -// \section{C Interfaces to [[GUSIFileSpec]]} -// -// Many of the API routines defined here are useful to C code and not too hard to make accessible, -// even though I prefer the C++ versions. As opposed to GUSI 1, we stick to our namespace now. -// -// = -/* - * Construct a FSSpec from... - */ -/* ... the refNum of an open file. */ -OSErr GUSIFRefNum2FSp(short fRefNum, FSSpec * desc); -/* ... a working directory & file name. */ -OSErr GUSIWD2FSp(short wd, ConstStr31Param name, FSSpec * desc); -/* ... a path name. */ -OSErr GUSIPath2FSp(const char * path, FSSpec * desc); -/* ... a special object. */ -OSErr GUSISpecial2FSp(OSType object, short vol, FSSpec * desc); -/* ... a temporary file path. */ -OSErr GUSIMakeTempFSp(short vol, long dirID, FSSpec * desc); - -/* - * Convert a FSSpec into... - */ -/* ... a full path name. */ -char * GUSIFSp2FullPath(const FSSpec * desc); -/* ... a relative path name if possible, full if not */ -char * GUSIFSp2RelPath(const FSSpec * desc); -/* ... a path relative to the specified directory */ -char * GUSIFSp2DirRelPath(const FSSpec * desc, const FSSpec * dir); -/* ... an GUSI-=specific ASCII encoding. */ -char * GUSIFSp2Encoding(const FSSpec * desc); - -/* - * Construct FSSpec of... - */ -/* ... (vRefNum, parID) */ -OSErr GUSIFSpUp(FSSpec * desc); -/* ... file (name) in directory denoted by desc */ -OSErr GUSIFSpDown(FSSpec * desc, ConstStr31Param name); -/* ... of nth file in directory denoted by (vRefNum, parID) */ -OSErr GUSIFSpIndex(FSSpec * desc, short n); - -/* Resolve if alias file */ -OSErr GUSIFSpResolve(FSSpec * spec); - -/* Touch folder containing the object */ -OSErr GUSIFSpTouchFolder(const FSSpec * spec); - -/* Get catalog information (after resolving leaf aliases) */ -OSErr GUSIFSpGetCatInfo(FSSpec * spec, CInfoPBRec * info); -__END_DECLS - -#ifdef GUSI_SOURCE - -#include "GUSIBasics.h" -#include "GUSIContext.h" - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of [[GUSICatInfo]]} -// -// [[GUSICatInfo]] is a wrapper for [[CInfoPBRec]]. Since the latter is a [[union]], we cannot -// inherit from it. -// -// = -class GUSICatInfo { - CInfoPBRec fInfo; -public: - bool IsFile() const; - bool IsAlias() const; - bool DirIsExported() const; - bool DirIsMounted() const; - bool DirIsShared() const; - bool HasRdPerm() const; - bool HasWrPerm() const; - bool Locked() const; - - CInfoPBRec & Info() { return fInfo; } - operator CInfoPBRec &() { return fInfo; } - struct HFileInfo & FileInfo() { return fInfo.hFileInfo; } - struct DirInfo & DirInfo() { return fInfo.dirInfo; } - struct FInfo & FInfo() { return fInfo.hFileInfo.ioFlFndrInfo; } - struct FXInfo & FXInfo() { return fInfo.hFileInfo.ioFlXFndrInfo; } - - const CInfoPBRec & Info() const { return fInfo; } - operator const CInfoPBRec &() const { return fInfo; } - const struct HFileInfo & FileInfo() const{ return fInfo.hFileInfo; } - const struct DirInfo & DirInfo() const { return fInfo.dirInfo; } - const struct FInfo & FInfo() const { return fInfo.hFileInfo.ioFlFndrInfo; } - const struct FXInfo & FXInfo() const { return fInfo.hFileInfo.ioFlXFndrInfo; } -}; -// \section{Definition of [[GUSIFileSpec]]} -// -// A [[GUSIFileSpec]] is a manipulation friendly version of an [[FSSpec]]. Due to -// conversion operators, a [[GUSIFileSpec]] can be used whereever a [[const FSSpec]] -// is specified. For any long term storage, [[FSSpec]] should be used rather than the -// much bulkier [[GUSIFileSpec]]. -// -// = -class GUSIFileSpec { -public: - // A [[GUSIFileSpec]] can be constructed in lots of different ways. Most of the - // constructors have a final argument [[useAlias]] that, when [[true]], suppresses - // resolution of leaf aliases. - // - // First, two trivial cases: The default constructor and the copy constructor, which - // do exactly what you'd expect them to do. - // - // = - GUSIFileSpec() {} - GUSIFileSpec(const GUSIFileSpec & spec); - // The [[FSSpec]] conversion is almost a copy constructor, but by default resolves - // leaf aliases. - // - // = - GUSIFileSpec(const FSSpec & spec, bool useAlias = false); - // A number of convenience constructors let you construct a [[GUSIFileSpec]] from - // various components. - // - // = - // Construct from volume reference number, directory ID & file name - GUSIFileSpec(short vRefNum, long parID, ConstStr31Param name, bool useAlias = false); - - // Construct from working directory & file name - GUSIFileSpec(short wd, ConstStr31Param name, bool useAlias = false); - - // Construct from full or relative path - GUSIFileSpec(const char * path, bool useAlias = false); - - // Construct from open file reference number - explicit GUSIFileSpec(short fRefNum); - // Finally, there is a constructor for constructing a [[GUSIFileSpec]] for one of - // the folders obtainable with [[FindFolder]]. - // - // = - GUSIFileSpec(OSType object, short vol = kOnSystemDisk); - // All [[GUSIFileSpecs]] have an error variable from which the last error - // is available. - // - // = - OSErr Error() const; - operator void*() const; - bool operator!() const; - // While earlier versions of GUSI maintained a notion of "current directory" that - // was independent of the HFS default directory, there is no such distinction anymore - // in GUSI 2. [[SetDefaultDirectory]] sets the default directory to [[vRefNum, dirID]]. - // [[GetDefaultDirectory]] sets [[vRefNum,dirID]] to the default directory. Neither - // routine affects the [[name]]. [[GetVolume]] gets the named or indexed volume. - // - // = - OSErr SetDefaultDirectory(); - OSErr GetDefaultDirectory(); - OSErr GetVolume(short index = -1); - // Conversions of [[GUSIFileSpec]] to [[FSSpec]] values and references is, of course, - // simple. Pointers are a bit trickier; we define an custom [[operator&]] and two - // smart pointer classes. [[operator->]], however, is simpler. - // - // = - operator const FSSpec &() const; - - class pointer { - public: - pointer(GUSIFileSpec * ptr); - operator GUSIFileSpec *() const; - operator const FSSpec *() const; - private: - GUSIFileSpec * ptr; - }; - pointer operator&(); - - class const_pointer { - public: - const_pointer(const GUSIFileSpec * ptr); - operator const GUSIFileSpec *() const; - operator const FSSpec *() const; - private: - const GUSIFileSpec * ptr; - }; - const_pointer operator&() const; - - const FSSpec * operator->() const; - - friend class pointer; - friend class const_pointer; - // Each [[GUSIFileSpec]] has an implicit [[GUSICatInfo]] record associated with it. - // [[CatInfo]] calls [[GetCatInfo]] if the record is not already valid and - // returns a pointer to the record. [[DirInfo]] replaces the [[GUSIFileSpec]] by - // the specification of its parent directory and returns a pointer to information - // about the parent. Both calls return a [[nil]] pointer if the object does not exist. - // If all you are interested in is whether the object exists, call [[Exists]]. - // - // = - const GUSICatInfo * CatInfo(short index); - const GUSICatInfo * DirInfo(); - const GUSICatInfo * CatInfo() const; - bool Exists() const; - // In many POSIXish contexts, it's necessary to specify path names with C string. - // Although this practice is dangerous on a Mac, we of course have to conform to - // it. The basic operations are getting a full path and getting a path relative to - // a directory (the current directory by default). - // - // = - char * FullPath() const; - char * RelativePath() const; - char * RelativePath(const FSSpec & dir) const; - // If the path ultimately is going to flow back into a GUSI routine again, it is - // possible to simply encode the [[GUSIFileSpec]] in ASCII. This is fast and reliable, - // but you should of course not employ it with any non-GUSI destination routine and - // should never store such a part across a reboot. The standard [[GUSIFileSpec]] - // constructors for paths will accept encoded paths. - // - // The encoding is defined as: - // - // \begin{itemize} - // \item 1 byte: DC1 (ASCII 0x11) - // \item 4 bytes: Volume reference number in zero-padded hex - // \item 8 bytes: Directory ID in zero-padded hex - // \item n bytes: Partial pathname, starting with ':' - // \end{itemize} - // - // = - char * EncodedPath() const; - // Most aliases are resolved implicitly, but occasionally you may want to do - // explicit resolution. [[Resolve]] resolves an alias. If [[gently]] is set, - // nonexistent target files of aliases don't cause an error to be returned. - // - // = - OSErr Resolve(bool gently = true); - // [[AliasPath]] returns the path an alias points to without mounting any volumes. - // - // = - char * AliasPath() const; - // A major feature of the [[GUSIFileSpec]] class is the set of operators for - // manipulating a file specification. - // - // [[operator--]] replaces a file specification with the directory specification of - // its parent. - // - // = - GUSIFileSpec & operator--(); - // [[operator++]] sets the [[dirID]] of a directory specification to the ID of the - // directory. - // - // = - GUSIFileSpec & operator++(); - // The two versions of [[operator+=]], which internally both call [[AddPathComponent]], - // replace a directory specification with the specification - // - // = - GUSIFileSpec & AddPathComponent(const char * name, int length, bool fullSpec); - GUSIFileSpec & operator+=(ConstStr31Param name); - GUSIFileSpec & operator+=(const char * name); - // [[operator+]] provides a non-destructive variant of [[operator+=]]. - // - // = - // - // These don't need access to the GUSIFileSpec internals - // - // friend GUSIFileSpec operator+(const FSSpec & spec, ConstStr31Param name); - // friend GUSIFileSpec operator+(const FSSpec & spec, const char * name); - // Array access replaces the file specification with the [[index]]th object in the - // {\em parent directory} of the specification (allowing the same specification to - // be reused for reading a directory). - // - // = - GUSIFileSpec & operator[](short index); - // To manipulate the fields of the file specification directly, there is a procedural - // interface. - // - // = - void SetVRef(short vref); - void SetParID(long parid); - void SetName(ConstStr63Param nam); - void SetName(const char * nam); - // For some modifications to propagate quickly, the surrounding folder needs to - // have its date modified. - // - // = - OSErr TouchFolder(); - // Two [[GUSIFileSpecs]] can be compared for (in)equality. - // - // = - friend bool operator==(const GUSIFileSpec & one, const GUSIFileSpec & other); - // [[IsParentOf]] determines whether the object specifies a parent directory of - // [[other]]. - // - // = - bool IsParentOf(const GUSIFileSpec & other) const; -protected: - // \section{Implementation of [[GUSIFileSpec]]} - // - // [[sError]] contains the error code for failed calls. [[Error]] returns the value. - // - // = - mutable OSErr fError; - // For path name constructions, a sometimes large scratch area is needed which is - // maintained in [[sScratch]]. A scratch request preserves a preexisting scratch area - // at the {\em end} of the new area if [[extend]] is nonzero. - // - // = - static char * sScratch; - static long sScratchSize; - - static char * CScratch(bool extend = false); - static StringPtr PScratch(); - // A [[GUSIFileSpec]] has a [[GUSICatInfo]] embedded and a flag [[fValidInfo]] indicating - // that it is valid. - // - // = - FSSpec fSpec; - GUSIIOPBWrapper fInfo; - bool fValidInfo; - // For convenience, we define a fictivous parent directory of all volumes. - // - // = - enum { ROOT_MAGIC_COOKIE = 666 }; - // Each accumulation step is preformed in [[PrependPathComponent]]. - // - // = - OSErr PrependPathComponent(char *&path, ConstStr63Param component, bool colon) const; -}; -// A [[GUSITempFileSpec]] is just a [[GUSIFileSpec]] with constructors to construct -// filenames for temporary files. -// -// = -class GUSITempFileSpec : public GUSIFileSpec { -public: - GUSITempFileSpec(short vRefNum = kOnSystemDisk); - GUSITempFileSpec(short vRefNum, long parID); - GUSITempFileSpec(ConstStr31Param basename); - GUSITempFileSpec(short vRefNum, ConstStr31Param basename); - GUSITempFileSpec(short vRefNum, long parID, ConstStr31Param basename); -private: - void TempName(); - void TempName(ConstStr31Param basename); - - static int sID; -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// \section{Implementation of [[GUSICatInfo]]} -// -// All of the member functions for [[GUSICatInfo]] are inline. -// -// = -inline bool GUSICatInfo::IsFile() const -{ - return !(DirInfo().ioFlAttrib & 0x10); -} - -inline bool GUSICatInfo::IsAlias() const -{ - return - !(FileInfo().ioFlAttrib & 0x10) && - (FInfo().fdFlags & (1 << 15)); -} - -inline bool GUSICatInfo::DirIsExported() const -{ - return (FileInfo().ioFlAttrib & 0x20) != 0; -} - -inline bool GUSICatInfo::DirIsMounted() const -{ - return (FileInfo().ioFlAttrib & 0x08) != 0; -} - -inline bool GUSICatInfo::DirIsShared() const -{ - return (FileInfo().ioFlAttrib & 0x04) != 0; -} - -inline bool GUSICatInfo::HasRdPerm() const -{ - return !(DirInfo().ioACUser & 0x02) != 0; -} - -inline bool GUSICatInfo::HasWrPerm() const -{ - return !(DirInfo().ioACUser & 0x04) != 0; -} - -inline bool GUSICatInfo::Locked() const -{ - return (FileInfo().ioFlAttrib & 0x11) == 0x01; -} -// = -inline OSErr GUSIFileSpec::Error() const -{ - return fError; -} - -inline GUSIFileSpec::operator void*() const -{ - return (void *)!fError; -} - -inline bool GUSIFileSpec::operator!() const -{ - return fError!=0; -} -// = -inline StringPtr GUSIFileSpec::PScratch() -{ - return (StringPtr) CScratch(); -} -// = -inline OSErr GUSIFileSpec::SetDefaultDirectory() -{ - return fError = HSetVol(nil, fSpec.vRefNum, fSpec.parID); -} - -inline OSErr GUSIFileSpec::GetDefaultDirectory() -{ - fSpec.name[0] = 0; - fValidInfo = false; - return fError = HGetVol(nil, &fSpec.vRefNum, &fSpec.parID); -} -// [[operator+=]] and [[operator+]] are merely wrappers around [[AddPathComponent]]. -// -// = -inline GUSIFileSpec & GUSIFileSpec::operator+=(ConstStr31Param name) -{ - return AddPathComponent((char *) name+1, name[0], true); -} - -inline GUSIFileSpec & GUSIFileSpec::operator+=(const char * name) -{ - return AddPathComponent(name, strlen(name), true); -} -// The other variations of the call are simple. -// -// = -inline const GUSICatInfo * GUSIFileSpec::CatInfo() const -{ - return const_cast(this)->CatInfo(0); -} - -inline const GUSICatInfo * GUSIFileSpec::DirInfo() -{ - if (CatInfo(-1)) { - fSpec.parID = fInfo->DirInfo().ioDrParID; - fValidInfo = true; - - return &fInfo.fPB; - } else - return nil; -} - -inline bool GUSIFileSpec::Exists() const -{ - return CatInfo() != nil; -} -// Reference conversion is straightforward, as is [[operator->]]. -// -// = -inline GUSIFileSpec::operator const FSSpec &() const -{ - return fSpec; -} -inline const FSSpec * GUSIFileSpec::operator->() const -{ - return &fSpec; -} -// Pointers, however, are a trickier issue, as they might be used either as a -// [[GUSIFileSpec *]] or as an [[FSSpec *]]. -// -// = -inline GUSIFileSpec::const_pointer::const_pointer(const GUSIFileSpec * ptr) - : ptr(ptr) -{ -} -inline GUSIFileSpec::const_pointer::operator const GUSIFileSpec *() const -{ - return ptr; -} -inline GUSIFileSpec::const_pointer::operator const FSSpec *() const -{ - return &ptr->fSpec; -} -inline GUSIFileSpec::const_pointer GUSIFileSpec::operator&() const -{ - return const_pointer(this); -} -// [[GUSIFileSpec::pointer]] is the non-constant equivalent to [[GUSIFileSpec::const_pointer]]. -// -// = -inline GUSIFileSpec::pointer::pointer(GUSIFileSpec * ptr) - : ptr(ptr) -{ -} -inline GUSIFileSpec::pointer::operator GUSIFileSpec *() const -{ - return ptr; -} -inline GUSIFileSpec::pointer::operator const FSSpec *() const -{ - return &ptr->fSpec; -} -inline GUSIFileSpec::pointer GUSIFileSpec::operator&() -{ - return pointer(this); -} - -#endif /* GUSI_SOURCE */ - -#endif /* GUSIFileSpec */ diff --git a/GUSI/include/GUSIForeignThreads.h b/GUSI/include/GUSIForeignThreads.h deleted file mode 100755 index 4e3a20a..0000000 --- a/GUSI/include/GUSIForeignThreads.h +++ /dev/null @@ -1,52 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIForeignThreads.nw - Foreign thread support -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:11 chombier -// % Initial import -// % -// % Revision 1.4 2000/12/23 06:10:48 neeri -// % Use kPowerPCCFragArch, NOT GetCurrentArchitecture() -// % -// % Revision 1.3 2000/05/23 07:00:00 neeri -// % Improve formatting -// % -// % Revision 1.2 2000/03/06 08:28:32 neeri -// % Releasing 2.0.5 -// % -// % Revision 1.1 1999/09/09 07:18:06 neeri -// % Added support for foreign threads -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Supporting threads made outside of GUSI} -// -// As convenient as the pthreads interface is, some applications may link to other -// libraries which create thread manager threads directly, such as the PowerPlant -// thread classes. -// -// Unfortunately, there is no really elegant way to welcome these lost sheep into the -// pthread flock, since the thread manager offers no way to retrieve thread switching -// and termination procedures. We therefore have to resort to a violent technique used -// already successfully for MPW support: On CFM, we override the default entry point and -// use the CFM manager to find the real implementation. -// -// For non-CFM, we unfortunately don't have such an effective technique, since the -// thread manager is called through traps (and no, I'm not going to patch any traps -// for this). You will therefore have to recompile your foreign libraries with -// a precompiled header that includes \texttt{GUSIForeignThreads.h}. -// -// = -#ifndef _GUSIForeignThreads_ -#define _GUSIForeignThreads_ - -#define NewThread(style, entry, param, stack, options, result, made) \ - GUSINewThread((style), (entry), (param), (stack), (options), (result), (made)) -#define SetThreadSwitcher(thread, switcher, param, inOrOut) \ - GUSISetThreadSwitcher((thread), (switcher), (param), (inOrOut)) -#define SetThreadTerminator(thread, threadTerminator, terminationProcParam) \ - GUSISetThreadTerminator((thread), (threadTerminator), (terminationProcParam)) -#endif /* _GUSIForeignThreads_ */ diff --git a/GUSI/include/GUSIInet.h b/GUSI/include/GUSIInet.h deleted file mode 100755 index 8c0d23e..0000000 --- a/GUSI/include/GUSIInet.h +++ /dev/null @@ -1,68 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMTInet.nw - Common routines for MacTCP -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:11 chombier -// % Initial import -// % -// % Revision 1.5 1999/08/26 05:45:02 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.4 1999/05/29 06:26:43 neeri -// % Fixed header guards -// % -// % Revision 1.3 1998/11/22 23:06:53 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.2 1998/10/25 11:57:34 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.1 1998/08/01 21:32:05 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.4 1998/02/11 12:57:12 neeri -// % PowerPC Build -// % -// % Revision 1.3 1998/01/25 20:53:55 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.2 1996/12/22 19:57:56 neeri -// % TCP streams work -// % -// % Revision 1.1 1996/12/16 02:12:40 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{TCP/IP shared infrastructure} -// -// Both the MacTCP and the forthcoming open transport implementation of TCP/IP -// sockets share a common registry. -// -// = -#ifndef _GUSIInet_ -#define _GUSIInet_ - -#ifdef GUSI_SOURCE - -#include - -__BEGIN_DECLS -// = -void GUSIwithInetSockets(); -__END_DECLS - -#ifdef GUSI_INTERNAL - -#include "GUSIFactory.h" - -extern GUSISocketTypeRegistry gGUSIInetFactories; - -#endif /* GUSI_INTERNAL */ - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIInet_ */ diff --git a/GUSI/include/GUSIInternal.h b/GUSI/include/GUSIInternal.h deleted file mode 100755 index 2781eda..0000000 --- a/GUSI/include/GUSIInternal.h +++ /dev/null @@ -1,104 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIBasics.nw - Common routines for GUSI -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.20 2001/01/17 08:32:30 neeri -// % Atomic locks turned out not to be necessary after all -// % -// % Revision 1.19 2001/01/17 08:31:10 neeri -// % Added PPC error codes, tweaked nullEvent handling, added atomic locks -// % -// % Revision 1.18 2000/10/16 04:34:22 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.17 2000/06/12 04:20:58 neeri -// % Introduce GUSI_*printf -// % -// % Revision 1.16 2000/05/23 06:51:55 neeri -// % Reorganize errors to improve formatting -// % -// % Revision 1.15 2000/03/15 07:22:05 neeri -// % Enforce alignment choices -// % -// % Revision 1.14 1999/08/26 05:44:58 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.13 1999/08/02 07:02:42 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.12 1999/06/28 05:56:01 neeri -// % Get rid of STL includes in header -// % -// % Revision 1.11 1999/06/08 04:31:29 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.10 1999/05/30 03:09:28 neeri -// % Added support for MPW compilers -// % -// % Revision 1.9 1999/04/10 04:45:05 neeri -// % Handle MacTCP errors correctly -// % -// % Revision 1.8 1999/03/17 09:05:04 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.7 1998/10/25 11:57:33 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.6 1998/10/11 16:45:09 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.5 1998/01/25 20:53:50 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.4 1996/12/22 19:57:54 neeri -// % TCP streams work -// % -// % Revision 1.3 1996/11/24 12:52:04 neeri -// % Added GUSIPipeSockets -// % -// % Revision 1.2 1996/11/18 00:53:46 neeri -// % TestTimers (basic threading/timer test) works -// % -// % Revision 1.1.1.1 1996/11/03 02:43:32 neeri -// % Imported into CVS -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Common routines for GUSI} -// -// This section defines various services used by all parts of GUSI: -// -// \begin{itemize} -// \item Various hooks to customize GUSI. -// \item The propagation of {\bf errors} to the [[errno]] and [[h_errno]] -// global variables. -// \item Waiting for completion of asynchronous calls. -// \item Event handling. -// \item Compiler features. -// \end{itemize} -// -// To protect our name space further, we maintain a strict C interface unless -// [[GUSI_SOURCE]] is defined, and may avoid defining some stuff unless -// [[GUSI_INTERNAL]] is defined. The following header is therefore included -// first by all GUSI source files. -// -// = -#ifndef _GUSIInternal_ -#define _GUSIInternal_ - -#include - -#define GUSI_SOURCE -#define GUSI_INTERNAL - -#if !TARGET_RT_MAC_CFM -#pragma segment GUSI -#endif - -#endif /* _GUSIInternal_ */ diff --git a/GUSI/include/GUSIMPW.h b/GUSI/include/GUSIMPW.h deleted file mode 100755 index 465e4ed..0000000 --- a/GUSI/include/GUSIMPW.h +++ /dev/null @@ -1,65 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMPW.nw - MPW Interface -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.13 2001/01/17 08:48:04 neeri -// % Introduce Expired(), Reset() -// % -// % Revision 1.12 2000/05/23 07:01:53 neeri -// % Improve formatting -// % -// % Revision 1.11 1999/08/26 05:45:03 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.10 1999/07/19 06:17:08 neeri -// % Add SIOW support -// % -// % Revision 1.9 1999/07/07 04:17:41 neeri -// % Final tweaks for 2.0b3 -// % -// % Revision 1.8 1999/06/08 04:31:29 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.7 1999/05/29 06:26:43 neeri -// % Fixed header guards -// % -// % Revision 1.6 1999/04/29 05:33:20 neeri -// % Fix fcntl prototype -// % -// % Revision 1.5 1999/03/29 09:51:28 neeri -// % New configuration system with support for hardcoded configurations. -// % -// % Revision 1.4 1999/03/17 09:05:08 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/11/22 23:06:54 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.2 1998/10/25 11:57:35 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.1 1998/08/01 21:32:06 neeri -// % About ready for 2.0a1 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{MPW Support} -// -// In MPW tools, we have to direct some of the I/O operations to the standard -// library functions, which we otherwise try to avoid as much as possible. -// Getting at those library calls is a bit tricky: For 68K, we rename entries -// in the MPW glue library, while for PowerPC, we look up the symbols dynamically. -// -// MPW support is installed implicitly through [[GUSISetupConsoleDescriptors]] -// -// = -#ifndef _GUSIMPW_ -#define _GUSIMPW_ - -#endif /* _GUSIMPW_ */ diff --git a/GUSI/include/GUSIMSL.h b/GUSI/include/GUSIMSL.h deleted file mode 100755 index 930144f..0000000 --- a/GUSI/include/GUSIMSL.h +++ /dev/null @@ -1,56 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMSL.nw - Interface to the MSL -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.8 2000/10/29 19:17:04 neeri -// % Accommodate MSL's non-compliant fopen signature -// % -// % Revision 1.7 2000/10/16 04:34:22 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.6 2000/05/23 07:03:25 neeri -// % Improve formatting -// % -// % Revision 1.5 1999/08/26 05:45:03 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.4 1999/08/02 07:02:43 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.3 1999/04/14 04:20:21 neeri -// % Override console hooks -// % -// % Revision 1.2 1999/04/10 04:53:58 neeri -// % Use simpler internal MSL routines -// % -// % Revision 1.1 1998/08/01 21:32:07 neeri -// % About ready for 2.0a1 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{The Interface to the MSL} -// -// This section interfaces GUSI to the Metrowerks Standard Library (MSL) -// by reimplementing various internal MSL routines. Consequently, some of -// the code used here is borrowed from the MSL code itself. The routines -// here are in three different categories: -// -// \begin{itemize} -// \item Overrides of MSL functions (all internal, as it happens). -// \item Implementations of ANSI library specific public GUSI functions like -// [[fdopen]]. -// \item Implementations of ANSI library specific internal GUSI functions. -// \end{itemize} -// -// -// = -#ifndef _GUSIMSL_ -#define _GUSIMSL_ - -#endif /* _GUSIMSL_ */ diff --git a/GUSI/include/GUSIMTInet.h b/GUSI/include/GUSIMTInet.h deleted file mode 100755 index 97ba1e7..0000000 --- a/GUSI/include/GUSIMTInet.h +++ /dev/null @@ -1,194 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMTInet.nw - Common routines for MacTCP -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.14 2000/10/16 04:34:23 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.13 2000/05/23 07:03:25 neeri -// % Improve formatting -// % -// % Revision 1.12 1999/08/26 05:45:04 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.11 1999/08/02 07:02:43 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.10 1999/06/30 07:42:06 neeri -// % Getting ready to release 2.0b3 -// % -// % Revision 1.9 1999/05/29 06:26:43 neeri -// % Fixed header guards -// % -// % Revision 1.8 1999/04/29 05:33:19 neeri -// % Fix fcntl prototype -// % -// % Revision 1.7 1999/03/17 09:05:08 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.6 1998/10/25 11:57:35 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.5 1998/10/11 16:45:16 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.4 1998/02/11 12:57:12 neeri -// % PowerPC Build -// % -// % Revision 1.3 1998/01/25 20:53:55 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.2 1996/12/22 19:57:56 neeri -// % TCP streams work -// % -// % Revision 1.1 1996/12/16 02:12:40 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Basic MacTCP code} -// -// A [[GUSIMTInetSocket]] defines the infrastructure shared between -// MacTCP TCP and UDP sockets. -// -// = -#ifndef _GUSIMTInet_ -#define _GUSIMTInet_ - -#ifdef GUSI_SOURCE - -#include - -__BEGIN_DECLS -// = -void GUSIwithMTInetSockets(); -__END_DECLS - -#ifdef GUSI_INTERNAL - -#include "GUSISocket.h" -#include "GUSISocketMixins.h" - -#include -#include - -// \section{Definition of [[GUSIMTInetSocket]]} -// -// MacTCP related sockets are buffered, have a standard state model, and can be -// nonblocking. -// -// = -class GUSIMTInetSocket : - public GUSISocket, - protected GUSISMBlocking, - protected GUSISMState, - protected GUSISMInputBuffer, - protected GUSISMOutputBuffer, - protected GUSISMAsyncError -{ -public: - GUSIMTInetSocket(); - // [[bind]] for MacTCP sockets has the fatal flaw that it is totally unable to - // reserve a socket. - // - // = - virtual int bind(void * addr, socklen_t namelen); - // [[getsockname]] and [[getpeername]] return the stored values. - // - // = - virtual int getsockname(void * addr, socklen_t * namelen); - virtual int getpeername(void * addr, socklen_t * namelen); - // [[shutdown]] just delegates to [[GUSISMState]]. - // - // = - virtual int shutdown(int how); - // [[fcntl]] handles the blocking support. - // - // = - virtual int fcntl(int cmd, va_list arg); - // [[ioctl]] deals with blocking support and with [[FIONREAD]]. - // - // = - virtual int ioctl(unsigned int request, va_list arg); - // [[getsockopt]] and [[setsockopt]] are available for setting buffer sizes and - // getting asynchronous errors. - // - // = - virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen); - // = - virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen); - // MacTCP sockets implement socket style calls. - // - // = - virtual bool Supports(ConfigOption config); - // MacTCP I/O calls communicate by means of read and write data structures, - // of which we need only the most primitive variants. - // - // = - #if PRAGMA_STRUCT_ALIGN - #pragma options align=mac68k - #endif - class MiniWDS { - public: - u_short fLength; - char * fDataPtr; - u_short fZero; - - MiniWDS() : fZero(0) {} - Ptr operator &() { return (Ptr)this; } - }; - class MidiWDS { - public: - u_short fLength; - char * fDataPtr; - u_short fLength2; - char * fDataPtr2; - u_short fZero; - - MidiWDS() : fZero(0) {} - Ptr operator &() { return (Ptr)this; } - }; - #if PRAGMA_STRUCT_ALIGN - #pragma options align=reset - #endif - // The only other interesting bit in the interface is the driver management, which - // arranges to open the MacTCP driver and domain name resolver at most once, - // as late as possible in the program (If you open some SLIP or PPP drivers - // before the Toolbox is initialized, you'll wish you'd curled up by the fireside - // with a nice Lovecraft novel instead). [[Driver]] returns the driver reference - // number of the MacTCP driver. [[HostAddr]] returns our host's IP address. - // - // = - static short Driver(); - static u_long HostAddr(); -protected: - // All MacTCP related sockets need a [[StreamPtr]]; they store their own and - // their peer's address away, and the save errors reported at interrupt time - // in an [[fAsyncError]] field. - // - // = - StreamPtr fStream; - sockaddr_in fSockAddr; - sockaddr_in fPeerAddr; - // \section{Implementation of [[GUSIMTInetSocket]]} - // - // [[Driver]] preserves error status in an [[OSErr]] - // variable, initially [[1]] to convey unresolvedness. - // - // = - static short sDrvrRefNum; - static OSErr sDrvrState; - static u_long sHostAddress; -}; - -#endif /* GUSI_INTERNAL */ - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIMTInet_ */ diff --git a/GUSI/include/GUSIMTNetDB.h b/GUSI/include/GUSIMTNetDB.h deleted file mode 100755 index c7174f1..0000000 --- a/GUSI/include/GUSIMTNetDB.h +++ /dev/null @@ -1,69 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSINetDB.nw - Convert between names and adresses -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.7 2000/06/12 04:20:59 neeri -// % Introduce GUSI_*printf -// % -// % Revision 1.6 2000/03/06 06:10:02 neeri -// % Reorganize Yield() -// % -// % Revision 1.5 1999/08/26 05:45:04 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.4 1999/05/30 03:09:30 neeri -// % Added support for MPW compilers -// % -// % Revision 1.3 1999/03/17 09:05:08 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/10/25 11:57:36 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.1 1998/10/11 16:45:17 neeri -// % Ready to release 2.0a2 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{IP Name Lookup in MacTCP} -// -// -// = -#ifndef _GUSIMTNetDB_ -#define _GUSIMTNetDB_ - -#ifdef GUSI_INTERNAL -#include "GUSINetDB.h" - -// \section{Definition of [[GUSIMTNetDB]]} -// -// -// = -class GUSIMTNetDB : public GUSINetDB { -public: - static void Instantiate(); - static bool Resolver(); - - // = - virtual hostent * gethostbyname(const char * name); - // = - virtual hostent * gethostbyaddr(const void * addr, size_t len, int type); - // = - virtual char * inet_ntoa(in_addr inaddr); - // = - virtual long gethostid(); -private: - GUSIMTNetDB() {} - GUSISpecificData fHost; - static OSErr sResolverState; -}; - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIMTNetDB_ */ diff --git a/GUSI/include/GUSIMTTcp.h b/GUSI/include/GUSIMTTcp.h deleted file mode 100755 index 71808b0..0000000 --- a/GUSI/include/GUSIMTTcp.h +++ /dev/null @@ -1,113 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMTTcp.nw - TCP code for MacTCP -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.17 2000/10/16 04:01:59 neeri -// % Save A5 in completion routines -// % -// % Revision 1.16 2000/05/23 07:04:20 neeri -// % Improve formatting, fix hang on close -// % -// % Revision 1.15 2000/03/06 06:10:02 neeri -// % Reorganize Yield() -// % -// % Revision 1.14 1999/08/26 05:42:13 neeri -// % Fix nonblocking connects -// % -// % Revision 1.13 1999/08/02 07:02:44 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.12 1999/06/28 06:04:58 neeri -// % Support interrupted calls -// % -// % Revision 1.11 1999/06/08 04:31:29 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.10 1999/05/30 03:09:30 neeri -// % Added support for MPW compilers -// % -// % Revision 1.9 1999/03/17 09:05:08 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.8 1998/11/22 23:06:55 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.7 1998/10/25 11:31:42 neeri -// % Add MSG_PEEK support, make releases more orderly. -// % -// % Revision 1.6 1998/10/11 16:45:18 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.5 1998/08/01 21:32:07 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.4 1998/01/25 20:53:56 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.3 1997/11/13 21:12:11 neeri -// % Fall 1997 -// % -// % Revision 1.2 1996/12/22 19:57:57 neeri -// % TCP streams work -// % -// % Revision 1.1 1996/12/16 02:12:41 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{MacTCP TCP sockets} -// -// A [[GUSIMTTcpSocket]] implements the TCP socket class for MacTCP. All instances -// of [[GUSIMTTcpSocket]] are created by the [[GUSIMTTcpFactory]] singleton, so -// there is no point in exporting the class itself. -// -// = -#ifndef _GUSIMTTcp_ -#define _GUSIMTTcp_ - -#ifdef GUSI_SOURCE - -#include - -__BEGIN_DECLS -// \section{Definition of [[GUSIMTTcpFactory]]} -// -// [[GUSIMTTcpFactory]] is a singleton subclass of [[GUSISocketFactory]]. -// -// = -void GUSIwithMTTcpSockets(); -__END_DECLS - -#ifdef GUSI_INTERNAL - -#include "GUSIFactory.h" - -// = -class GUSIMTTcpFactory : public GUSISocketFactory { -public: - static GUSISocketFactory * Instance(); - virtual GUSISocket * socket(int domain, int type, int protocol); -private: - GUSIMTTcpFactory() {} - static GUSISocketFactory * instance; -}; - -// = -inline GUSISocketFactory * GUSIMTTcpFactory::Instance() -{ - if (!instance) - instance = new GUSIMTTcpFactory; - return instance; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIMTTcp_ */ diff --git a/GUSI/include/GUSIMTUdp.h b/GUSI/include/GUSIMTUdp.h deleted file mode 100755 index c35e500..0000000 --- a/GUSI/include/GUSIMTUdp.h +++ /dev/null @@ -1,95 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMTUdp.nw - UDP code for MacTCP -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.11 2000/10/16 04:02:00 neeri -// % Save A5 in completion routines -// % -// % Revision 1.10 2000/05/23 07:05:16 neeri -// % Improve formatting -// % -// % Revision 1.9 2000/03/06 06:10:01 neeri -// % Reorganize Yield() -// % -// % Revision 1.8 1999/08/26 05:45:04 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.7 1999/08/02 07:02:44 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.6 1999/07/20 04:25:53 neeri -// % Fixed race condition in sendto() -// % -// % Revision 1.5 1999/06/28 06:04:59 neeri -// % Support interrupted calls -// % -// % Revision 1.4 1999/05/29 06:26:44 neeri -// % Fixed header guards -// % -// % Revision 1.3 1999/03/17 09:05:09 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/11/22 23:06:57 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.1 1998/10/25 11:57:37 neeri -// % Ready to release 2.0a3 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{MacTCP UDP sockets} -// -// A [[GUSIMTUdpSocket]] implements the UDP socket class for MacTCP. All instances -// of [[GUSIMTUdpSocket]] are created by the [[GUSIMTUdpFactory]] singleton, so -// there is no point in exporting the class itself. -// -// = -#ifndef _GUSIMTUdp_ -#define _GUSIMTUdp_ - -#ifdef GUSI_SOURCE - -#include - -__BEGIN_DECLS -// \section{Definition of [[GUSIMTUdpFactory]]} -// -// [[GUSIMTUdpFactory]] is a singleton subclass of [[GUSISocketFactory]]. -// -// = -void GUSIwithMTUdpSockets(); -__END_DECLS - -#ifdef GUSI_INTERNAL - -#include "GUSIFactory.h" - -// = -class GUSIMTUdpFactory : public GUSISocketFactory { -public: - static GUSISocketFactory * Instance(); - virtual GUSISocket * socket(int domain, int type, int protocol); -private: - GUSIMTUdpFactory() {} - static GUSISocketFactory * instance; -}; - -// = -inline GUSISocketFactory * GUSIMTUdpFactory::Instance() -{ - if (!instance) - instance = new GUSIMTUdpFactory; - return instance; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIMTUdp_ */ diff --git a/GUSI/include/GUSIMacFile.h b/GUSI/include/GUSIMacFile.h deleted file mode 100755 index d40e0ad..0000000 --- a/GUSI/include/GUSIMacFile.h +++ /dev/null @@ -1,178 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIMacFile.nw - Disk files -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.24 2001/01/17 08:58:06 neeri -// % Releasing 2.1.4 -// % -// % Revision 1.23 2000/12/23 06:11:36 neeri -// % Move diagnostics to A5 safe time -// % -// % Revision 1.22 2000/10/16 04:02:00 neeri -// % Save A5 in completion routines -// % -// % Revision 1.21 2000/05/23 07:07:05 neeri -// % Improve formatting, fix lseek for readonly files -// % -// % Revision 1.20 2000/03/15 07:17:11 neeri -// % Fix rename for existing targets -// % -// % Revision 1.19 2000/03/06 08:12:27 neeri -// % New Yield system; fix readdir at end of directory -// % -// % Revision 1.18 1999/11/15 07:24:32 neeri -// % Return error for stat() of nonexistent files. -// % -// % Revision 1.17 1999/09/09 07:19:19 neeri -// % Fix read-ahead switch-off -// % -// % Revision 1.16 1999/08/26 05:45:05 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.15 1999/08/05 05:55:35 neeri -// % Updated for CW Pro 5 -// % -// % Revision 1.14 1999/08/02 07:02:45 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.13 1999/07/19 06:21:03 neeri -// % Add mkdir/rmdir, fix various file manager related bugs -// % -// % Revision 1.12 1999/07/07 04:17:41 neeri -// % Final tweaks for 2.0b3 -// % -// % Revision 1.11 1999/06/28 06:07:15 neeri -// % Support I/O alignment, more effective writeback strategy -// % -// % Revision 1.10 1999/05/30 02:18:05 neeri -// % Cleaner definition of GUSICatInfo -// % -// % Revision 1.9 1999/04/29 05:33:19 neeri -// % Fix fcntl prototype -// % -// % Revision 1.8 1999/04/10 04:54:39 neeri -// % stat() was broken for directories -// % -// % Revision 1.7 1999/03/29 09:51:28 neeri -// % New configuration system with support for hardcoded configurations. -// % -// % Revision 1.6 1999/03/17 09:05:09 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.5 1998/11/22 23:06:57 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.4 1998/10/11 16:45:19 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.3 1998/08/01 21:28:58 neeri -// % Add directory operations -// % -// % Revision 1.2 1998/02/11 12:57:14 neeri -// % PowerPC Build -// % -// % Revision 1.1 1998/01/25 21:02:48 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Disk files} -// -// A [[GUSIMacFileSocket]] implements the operations on mac files. All instances -// of [[GUSIMacFileSocket]] are created by the [[GUSIMacFileDevice]] singleton, so -// there is no point in exporting the class itself. -// -// A [[GUSIMacDirectory]] implements directory handles on mac directories. -// -// = -#ifndef _GUSIMacFile_ -#define _GUSIMacFile_ - -#ifdef GUSI_INTERNAL - -#include "GUSIDevice.h" - -// \section{Definition of [[GUSIMacFileDevice]]} -// -// [[GUSIMacFileDevice]] is a singleton subclass of [[GUSIDevice]]. -// -// = -class GUSIMacFileDevice : public GUSIDevice { -public: - static GUSIMacFileDevice * Instance(); - virtual bool Want(GUSIFileToken & file); - - // = - virtual GUSISocket * open(GUSIFileToken & file, int flags); - // The normal case of [[remove]] is straightforward, but we also want to support - // the removing of open files, which is frequently used in POSIX code, as much - // as possible. - // - // = - virtual int remove(GUSIFileToken & file); - // [[rename]] can be a surprisingly difficult operation. - // - // = - virtual int rename(GUSIFileToken & file, const char * newname); - // [[stat]] is a rather intimidating function which needs to pull together - // information from various sources. - // - // = - virtual int stat(GUSIFileToken & file, struct stat * buf); - // = - virtual int chmod(GUSIFileToken & file, mode_t mode); - // = - virtual int utime(GUSIFileToken & file, const utimbuf * times); - // = - virtual int access(GUSIFileToken & file, int mode); - // = - virtual int mkdir(GUSIFileToken & file); - // = - virtual int rmdir(GUSIFileToken & file); - // = - virtual GUSIDirectory * opendir(GUSIFileToken & file); - // [[symlink]] has to reproduce the Finder's alias creation process, which is - // quite complex. - // - // = - virtual int symlink(GUSIFileToken & to, const char * newlink); - // = - virtual int readlink(GUSIFileToken & link, char * buf, int bufsize); - // = - virtual int fgetfileinfo(GUSIFileToken & file, OSType * creator, OSType * type); - virtual int fsetfileinfo(GUSIFileToken & file, OSType creator, OSType type); - // [[faccess]] is a somewhat curious case in that [[GUSIMacFileDevice]] - // accepts responsibility for handling it, but then does not, in fact, handle - // it. - // - // = - virtual int faccess(GUSIFileToken & file, unsigned * cmd, void * arg); - - GUSISocket * open(short fileRef, int flags); - - int MarkTemporary(const FSSpec & file); - void CleanupTemporaries(bool giveup); - - ~GUSIMacFileDevice(); -protected: - GUSIMacFileDevice() : fTemporaries(0) {} - - // [[MarkTemporary]] moves the file to the temporary folder and puts it on a list - // of death candidates. - // - // = - struct TempQueue { - TempQueue * fNext; - FSSpec fSpec; - } * fTemporaries; -}; - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIMacFile_ */ diff --git a/GUSI/include/GUSINetDB.h b/GUSI/include/GUSINetDB.h deleted file mode 100755 index 8f93464..0000000 --- a/GUSI/include/GUSINetDB.h +++ /dev/null @@ -1,266 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSINetDB.nw - Convert between names and adresses -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.10 2000/12/23 06:11:55 neeri -// % Add SSH service -// % -// % Revision 1.9 2000/05/23 07:10:35 neeri -// % Improve formatting -// % -// % Revision 1.8 2000/03/15 07:18:43 neeri -// % Fix GUSIBuiltinServiceDB::sServices -// % -// % Revision 1.7 1999/11/15 07:23:23 neeri -// % Fix gethostname for non-TCP/IP case -// % -// % Revision 1.6 1999/08/26 05:45:05 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.5 1999/05/30 03:09:30 neeri -// % Added support for MPW compilers -// % -// % Revision 1.4 1999/03/17 09:05:10 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/11/22 23:06:58 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.2 1998/10/25 11:33:38 neeri -// % Fixed disastrous bug in inet_addr, support alternative NL conventions -// % -// % Revision 1.1 1998/10/11 16:45:20 neeri -// % Ready to release 2.0a2 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Converting Between Names and IP Addresses} -// -// The [[GUSINetDB]] class coordinates access to the domain name server database. -// -// The [[GUSIServiceDB]] class is responsible for a database of TCP/IP service -// name to port number mappings. -// -// The [[hostent]] and [[servent]] classes are somewhat inconvenient to set up as -// they reference extra chunks of memory, so we define the wrapper classes -// [[GUSIhostent]] and [[GUSIservent]]. -// -// = -#ifndef _GUSINetDB_ -#define _GUSINetDB_ - -#ifdef GUSI_SOURCE -#include "GUSISpecific.h" - -#include -#include -#include - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of [[GUSIhostent]] and [[GUSIservent]]} -// -// A [[GUSIhostent]] may need a lot of data, so we allocate the name data -// dynamically. -// -// = -class GUSIhostent : public hostent { -public: - GUSIhostent(); - - void Alloc(size_t size); - - char * fAlias[16]; - char * fAddressList[16]; - char * fName; - size_t fAlloc; - char fAddrString[16]; -}; - -extern "C" void GUSIKillHostEnt(void * hostent); - -// A [[GUSIservent]] typically will remain more modest in its needs, so the -// data is allocated statically. -// -// = -class GUSIservent : public servent { -public: - GUSIservent(); - - char * fAlias[8]; - char fName[256]; -}; -// \section{Definition of [[GUSIServiceDB]]} -// -// [[GUSIServiceDB]] is a singleton, used as a primitive iterator. The semantics of -// these iterators conform only very superficially to real iterators: -// -// \begin{itemize} -// \item Only a single instance of the iterator is supported. -// \item Comparison operators all compare against [[end]], no matter what -// arguments are passed. -// \end{itemize} -// -// = -extern "C" void GUSIKillServiceDBData(void * entry); - -class GUSIServiceDB { -public: - static GUSIServiceDB * Instance(); - // Iterating is accomplished by a public interface conforming to STL iterator - // protocols. - // - // = - class iterator { - public: - inline bool operator==(const iterator & other); - inline bool operator!=(const iterator & other); - inline iterator & operator++(); - inline servent * operator*(); - }; - inline static iterator begin(); - inline static iterator end(); -protected: - static GUSIServiceDB * sInstance; - GUSIServiceDB() {} - virtual ~GUSIServiceDB() {} - - friend void GUSIKillServiceDBData(void * entry); - - // This interface does not access any data elements in the iterator, but directly - // calls through to a private interface in the [[GUSIServiceDB]], which explains - // the limitations in the iterator implementation. - // - // = - friend class iterator; - - class Data { - public: - Data() : fCurrent(0) {} - - servent * fCurrent; - GUSIservent fServent; - }; - typedef GUSISpecificData SpecificData; - static SpecificData sData; - - virtual void Reset() = 0; - virtual void Next() = 0; -}; -// \section{Definition of [[GUSINetDB]]} -// -// -// = -class GUSINetDB { -public: - // [[GUSINetDB]] is a singleton, but usually instantiated by an instance of a - // derived class. - // - // = - static GUSINetDB * Instance(); - // The public interface of [[GUSINetDB]] consists of three areas. The first set of - // calls is concerned with host names and IP numbers. - // - // <[[GUSINetDB]] host database>= - virtual hostent * gethostbyname(const char * name); - virtual hostent * gethostbyaddr(const void * addr, size_t len, int type); - virtual char * inet_ntoa(in_addr inaddr); - virtual in_addr_t inet_addr(const char *address); - virtual long gethostid(); - virtual int gethostname(char *machname, int buflen); - // The next set of calls is concerned with TCP and UDP services. - // - // <[[GUSINetDB]] service database>= - virtual servent * getservbyname(const char * name, const char * proto); - virtual servent * getservbyport(int port, const char * proto); - virtual servent * getservent(); - virtual void setservent(int stayopen); - virtual void endservent(); - // Finally, there is a set of calls concerned with protocols. - // - // <[[GUSINetDB]] protocol database>= - virtual protoent * getprotobyname(const char * name); - virtual protoent * getprotobynumber(int proto); - virtual protoent * getprotoent(); - virtual void setprotoent(int stayopen); - virtual void endprotoent(); -protected: - GUSINetDB(); - virtual ~GUSINetDB() {} - // \section{Implementation of [[GUSINetDB]]} - // - // [[GUSINetDB]] is a singleton, but typically implemented by an instance - // of a subclass (stored into [[fInstance]] by that subclass) rather than the - // base class. - // - // = - static GUSINetDB * sInstance; - // The service database is implemented in terms of [[GUSIServiceDB]]. Only - // [[getservent]] and [[setservent]] accesse [[GUSIServiceDB]] directly, however. - // - // = - bool fServiceOpen; - GUSIServiceDB::iterator fServiceIter; - // The protocol database is similar, in principle, to the service database, but it - // lends itself naturally to a much simpler implementation. - // - // = - int fNextProtocol; - static protoent sProtocols[2]; -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -#ifdef GUSI_INTERNAL - -// Iterators can be defined without regard to the implementation of the -// [[GUSIServiceDB]] currently used. -// -// = -GUSIServiceDB::iterator GUSIServiceDB::begin() -{ - Instance()->Reset(); - Instance()->Next(); - - return iterator(); -} -GUSIServiceDB::iterator GUSIServiceDB::end() -{ - return iterator(); -} -bool GUSIServiceDB::iterator::operator==(const GUSIServiceDB::iterator &) -{ - return !GUSIServiceDB::sData->fCurrent; -} -bool GUSIServiceDB::iterator::operator!=(const GUSIServiceDB::iterator &) -{ - return GUSIServiceDB::sData->fCurrent - == static_cast(nil); -} -GUSIServiceDB::iterator & GUSIServiceDB::iterator::operator++() -{ - GUSIServiceDB::Instance()->Next(); - return *this; -} -servent * GUSIServiceDB::iterator::operator*() -{ - return GUSIServiceDB::sData->fCurrent; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSINetDB_ */ diff --git a/GUSI/include/GUSINull.h b/GUSI/include/GUSINull.h deleted file mode 100755 index 99985c3..0000000 --- a/GUSI/include/GUSINull.h +++ /dev/null @@ -1,75 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSINull.nw - Null device -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.7 2000/03/06 06:03:29 neeri -// % Check device families for file paths -// % -// % Revision 1.6 1999/08/26 05:45:05 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.5 1999/05/29 06:26:44 neeri -// % Fixed header guards -// % -// % Revision 1.4 1999/04/29 05:34:22 neeri -// % Support stat/fstat -// % -// % Revision 1.3 1999/03/17 09:05:10 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/11/22 23:06:59 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.1 1998/08/01 21:32:09 neeri -// % About ready for 2.0a1 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Null device} -// -// A [[GUSINullSocket]] implements the null socket class for MacTCP. All instances -// of [[GUSINullSocket]] are created by the [[GUSINullDevice]] singleton, so -// there is no point in exporting the class itself. -// -// = -#ifndef _GUSINull_ -#define _GUSINull_ - -#ifdef GUSI_INTERNAL - -#include "GUSIDevice.h" - -// \section{Definition of [[GUSINullDevice]]} -// -// [[GUSINullDevice]] is a singleton subclass of [[GUSIDevice]]. -// -// = -class GUSINullDevice : public GUSIDevice { -public: - static GUSINullDevice * Instance(); - virtual bool Want(GUSIFileToken & file); - virtual GUSISocket * open(GUSIFileToken & file, int flags); - virtual int stat(GUSIFileToken & file, struct stat * buf); - GUSISocket * open(); -protected: - GUSINullDevice() {} - static GUSINullDevice * sInstance; -}; - -// = -inline GUSINullDevice * GUSINullDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSINullDevice; - return sInstance; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSINull_ */ diff --git a/GUSI/include/GUSIOTInet.h b/GUSI/include/GUSIOTInet.h deleted file mode 100755 index 17e892e..0000000 --- a/GUSI/include/GUSIOTInet.h +++ /dev/null @@ -1,71 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIOpenTransport.nw- OpenTransport sockets -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.11 2001/01/17 08:54:12 neeri -// % Add Clone() implementations -// % -// % Revision 1.10 2000/06/12 04:20:59 neeri -// % Introduce GUSI_*printf -// % -// % Revision 1.9 2000/05/23 09:05:27 neeri -// % Improve formatting -// % -// % Revision 1.8 1999/09/26 03:57:12 neeri -// % Renamed broadcast option -// % -// % Revision 1.7 1999/09/09 07:20:29 neeri -// % Fix numerous bugs, add support for interface ioctls -// % -// % Revision 1.6 1999/08/26 05:45:06 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.5 1999/08/02 07:02:45 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.4 1999/05/29 06:26:44 neeri -// % Fixed header guards -// % -// % Revision 1.3 1999/04/14 04:21:19 neeri -// % Correct option sizes -// % -// % Revision 1.2 1999/04/10 05:17:51 neeri -// % Implement broadcast/multicast options -// % -// % Revision 1.1 1999/03/17 09:05:10 neeri -// % Added GUSITimer, expanded docs -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Open Transport TCP/IP sockets} -// -// For TCP and UDP, the strategy classes do most of the work, the derived socket -// classes only have to do option management. -// -// = -#ifndef _GUSIOTInet_ -#define _GUSIOTInet_ - -#ifdef GUSI_SOURCE - -#include - -__BEGIN_DECLS -// \section{Definition of Open Transport Internet hooks} -// -// -// = -void GUSIwithOTInetSockets(); -void GUSIwithOTTcpSockets(); -void GUSIwithOTUdpSockets(); -__END_DECLS - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSIOTInet_ */ diff --git a/GUSI/include/GUSIOTNetDB.h b/GUSI/include/GUSIOTNetDB.h deleted file mode 100755 index 706d3a9..0000000 --- a/GUSI/include/GUSIOTNetDB.h +++ /dev/null @@ -1,93 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIOTNetDB.nw - Open Transport DNS lookups -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.8 2000/06/12 04:20:59 neeri -// % Introduce GUSI_*printf -// % -// % Revision 1.7 2000/05/23 07:11:45 neeri -// % Improve formatting, handle failed lookups correctly -// % -// % Revision 1.6 2000/03/06 06:10:01 neeri -// % Reorganize Yield() -// % -// % Revision 1.5 1999/12/14 06:27:47 neeri -// % initialize OT before opening resolver -// % -// % Revision 1.4 1999/08/26 05:45:06 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.3 1999/06/30 07:42:06 neeri -// % Getting ready to release 2.0b3 -// % -// % Revision 1.2 1999/05/30 03:09:31 neeri -// % Added support for MPW compilers -// % -// % Revision 1.1 1999/03/17 09:05:10 neeri -// % Added GUSITimer, expanded docs -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{IP Name Lookup in Open Transport} -// -// -// = -#ifndef _GUSIOTNetDB_ -#define _GUSIOTNetDB_ - -#ifdef GUSI_INTERNAL -#include "GUSINetDB.h" -#include "GUSIContext.h" -#include "GUSIOpenTransport.h" - -// \section{Definition of [[GUSIOTNetDB]]} -// -// We don't want to open the Open Transport headers files in our public header, but we -// need [[InetSvcRef]]. -// -// = -class TInternetServices; -typedef TInternetServices* InetSvcRef; - -// = -class GUSIOTNetDB : public GUSINetDB { -public: - static void Instantiate(); - bool Resolver(); - - // = - virtual hostent * gethostbyname(const char * name); - // = - virtual hostent * gethostbyaddr(const void * addr, size_t len, int type); - // = - virtual char * inet_ntoa(in_addr inaddr); - // = - virtual long gethostid(); -private: - GUSISpecificData fHost; - // \section{Implementation of [[GUSIOTNetDB]]} - // - // - // = - GUSIOTNetDB(); - // The [[GUSIOTNetDB]] notifier operates similarly to the [[GUSIOTSocket]] notifier, - // but it has to get the context to wake up somehow from its parameters. - // - // = - uint16_t fEvent; - uint32_t fCompletion; - OSStatus fAsyncError; - InetSvcRef fSvc; - GUSIContext * fCreationContext; - friend pascal void GUSIOTNetDBNotify(GUSIOTNetDB *, OTEventCode, OTResult, void *); -}; - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIOTNetDB_ */ diff --git a/GUSI/include/GUSIOpenTransport.h b/GUSI/include/GUSIOpenTransport.h deleted file mode 100755 index beb1f1f..0000000 --- a/GUSI/include/GUSIOpenTransport.h +++ /dev/null @@ -1,456 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIOpenTransport.nw- OpenTransport sockets -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.2 2001/03/28 14:04:32 chombier -// % GUSI 2.1.6b2 update -// % -// % Revision 1.21 2001/03/20 08:12:55 neeri -// % Further select repairs -// % -// % Revision 1.20 2001/03/20 02:35:21 neeri -// % Refined new select() implementation -// % -// % Revision 1.19 2001/03/09 09:25:21 neeri -// % Fixed select logic bugs, listener queue -// % -// % Revision 1.18 2001/01/17 08:58:06 neeri -// % Releasing 2.1.4 -// % -// % Revision 1.17 2000/10/16 04:07:23 neeri -// % Fix accept code -// % -// % Revision 1.16 2000/06/01 06:31:10 neeri -// % Reset shutdown flags on connect, refine test for data available, fix memory leak in UDP sendto -// % -// % Revision 1.15 2000/05/23 07:13:19 neeri -// % Improve formatting, implement immediate close and sorrect linger handling -// % -// % Revision 1.14 2000/03/15 07:19:53 neeri -// % Fix numerous race conditions -// % -// % Revision 1.13 2000/03/06 06:10:01 neeri -// % Reorganize Yield() -// % -// % Revision 1.12 1999/12/14 06:28:29 neeri -// % Read pending data while closing -// % -// % Revision 1.11 1999/12/13 02:44:19 neeri -// % Fix SO_LINGER, read results for disconnected sockets -// % -// % Revision 1.10 1999/10/15 02:48:50 neeri -// % Make disconnects orderly -// % -// % Revision 1.9 1999/09/09 07:20:29 neeri -// % Fix numerous bugs, add support for interface ioctls -// % -// % Revision 1.8 1999/09/03 06:31:36 neeri -// % Needed more mopups -// % -// % Revision 1.7 1999/08/26 05:43:09 neeri -// % Supply missing Unbind -// % -// % Revision 1.6 1999/08/02 07:02:45 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.5 1999/07/19 06:17:44 neeri -// % Fix nonblocking connect -// % -// % Revision 1.4 1999/06/28 06:04:59 neeri -// % Support interrupted calls -// % -// % Revision 1.3 1999/05/30 03:06:41 neeri -// % MPW compiler compatibility, fix select for datagram sockets -// % -// % Revision 1.2 1999/04/29 05:33:19 neeri -// % Fix fcntl prototype -// % -// % Revision 1.1 1999/03/17 09:05:11 neeri -// % Added GUSITimer, expanded docs -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Open Transport socket infrastructure} -// -// A [[GUSIOTSocket]] defines a class of Open Transport sockets. Since most -// families differ only in a few details, like address representation, we -// abstract the typical differences in a strategy class [[GUSIOTStrategy]]. -// -// = -#ifndef _GUSIOpenTransport_ -#define _GUSIOpenTransport_ - -#ifdef GUSI_INTERNAL - -#include "GUSISocket.h" -#include "GUSISocketMixins.h" -#include "GUSIFactory.h" - -#include -#include - -#undef O_ASYNC -#undef O_NDELAY -#undef O_NONBLOCK -#undef SIGHUP -#undef SIGURG -#undef AF_INET -#undef TCP_KEEPALIVE -#undef TCP_NODELAY -#undef TCP_MAXSEG - -#if UNIVERSAL_INTERFACES_VERSION >= 0x0340 -#undef IP_OPTIONS -#undef IP_TOS -#undef IP_TTL -#undef IP_REUSEADDR -#undef IP_DONTROUTE -#undef IP_BROADCAST -#undef IP_HDRINCL -#undef IP_RCVOPTS -#undef IP_RCVDSTADDR -#undef IP_MULTICAST_IF -#undef IP_MULTICAST_TTL -#undef IP_MULTICAST_LOOP -#undef IP_ADD_MEMBERSHIP -#undef IP_DROP_MEMBERSHIP -#undef IP_RCVIFADDR - -#undef SIGURG -#endif - -#include -#include - -// \section{Definition of [[GUSIOTStrategy]]} -// -// A [[GUSIOTStrategy]] contains all the tricky parts of each Open Transport -// family. -// -// = -class GUSIOTStrategy { -public: - // [[CreateConfiguration]] creates an appropriate [[OTConfiguration]]. This - // method is not virtual, as it relies on the strategy method - // [[ConfigPath]]. - // - // = - OTConfiguration * CreateConfiguration(); - // [[PackAddress]] converts a socket address into an OT address, and - // [[UnpackAddress]] performs the reverse step. [[CopyAddress]] copies an address. - // - // = - virtual int PackAddress( - const void * address, socklen_t len, TNetbuf & addr, bool non_null = false) = 0; - virtual int UnpackAddress(const TNetbuf & addr, void * address, socklen_t * len) = 0; - virtual int CopyAddress(const TNetbuf & from, TNetbuf & to); - // [[EndpointInfo]] returns a data structure storing endpoint parameters. We only - // need one copy per socket type. - // - // = - TEndpointInfo * EndpointInfo() { return &fEndpointInfo; } -protected: - // = - virtual const char * ConfigPath() = 0; - // = - TEndpointInfo fEndpointInfo; - // \section{Implementation of [[GUSIOTStrategy]]} - // - // [[GUSIOTStrategy]] is mostly abstract, except for the [[CreateConfiguration]] - // and [[CopyAddress]] methods. - // - // = - OTConfiguration * fConfig; - GUSIOTStrategy() : fConfig(nil) {} - virtual ~GUSIOTStrategy(); -}; -// \section{Definition of [[GUSIOTFactory]] and descendants} -// -// A [[GUSIOTFactory]] is an abstract class combining a socket creation -// mechanism with a strategy instance. To clarify our intent, we isolate -// the latter in [[GUSIOTStrategy]]. -// -// = -class GUSIOTFactory : public GUSISocketFactory { -public: - static bool Initialize(); -protected: - virtual GUSIOTStrategy *Strategy(int domain, int type, int protocol) = 0; -private: - // \section{Implementation of [[GUSIOTFactory]] and descendants} - // - // - // = - static bool sOK; -}; -// = -class GUSIOTStreamFactory : public GUSIOTFactory { -public: - GUSISocket * socket(int domain, int type, int protocol); -}; -// = -class GUSIOTDatagramFactory : public GUSIOTFactory { -public: - GUSISocket * socket(int domain, int type, int protocol); -}; -// \section{Definition of [[GUSIOT]]} -// -// Open Transport allocates and deallocates many data structures, which we -// simplify with a smart template. Allocation works via class allocation -// operators, which is a bit weird admittedly. -// -// = -template class GUSIOT : public T { -public: - void * operator new(size_t, EndpointRef ref) - { OSStatus err; return OTAlloc(ref, tag, T_ALL, &err); } - void * operator new(size_t, EndpointRef ref, int fields) - { OSStatus err; return OTAlloc(ref, tag, fields, &err); } - void operator delete(void * o) - { if (o) OTFree(o, tag); } -}; -template class GUSIOTAddr : public GUSIOT { -public: - int Pack(GUSIOTStrategy * strategy, const void * address, socklen_t len, bool non_null=false) - { return strategy->PackAddress(address, len, addr, non_null); } - int Unpack(GUSIOTStrategy * strategy, void * address, socklen_t * len) - { return strategy->UnpackAddress(addr, address, len); } - int Copy(GUSIOTStrategy * strategy, GUSIOTAddr * to) - { return strategy->CopyAddress(addr, to->addr); } -}; - -typedef GUSIOTAddr GUSIOTTBind; -typedef GUSIOTAddr GUSIOTTCall; -typedef GUSIOTAddr GUSIOTTUnitData; -typedef GUSIOTAddr GUSIOTTUDErr; -typedef GUSIOT GUSIOTTDiscon; -typedef GUSIOT GUSIOTTOptMgmt; -// \section{Definition of [[GUSIOTSocket]] and descendants} -// -// Open Transport sockets are rather lightweight, since OT is rather similar -// to sockets already. -// -// = -class GUSIOTSocket : - public GUSISocket, - protected GUSISMBlocking, - protected GUSISMState, - protected GUSISMAsyncError -{ -public: - // = - virtual int bind(void * name, socklen_t namelen); - // [[getsockname]] and [[getpeername]] unpack the stored addresses. - // Note that the reaction to [[nil]] addresses is a bit different. - // - // = - virtual int getsockname(void * name, socklen_t * namelen); - // [[shutdown]] just delegates to [[GUSISMState]]. - // - // = - virtual int shutdown(int how); - // [[fcntl]] handles the blocking support. - // - // = - virtual int fcntl(int cmd, va_list arg); - // [[ioctl]] deals with blocking support and with [[FIONREAD]]. - // - // = - virtual int ioctl(unsigned int request, va_list arg); - // Before we call [[select]], we check whether there is data currently available and turn - // off the data flags otherwise. - // - // = - virtual bool pre_select(bool wantRead, bool wantWrite, bool wantExcept); - // [[getsockopt]] and [[setsockopt]] are available for a variety of options. - // - // = - virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen); - // = - virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen); - // Open Transport sockets implement socket style calls. - // - // = - virtual bool Supports(ConfigOption config); -protected: - GUSIOTSocket(GUSIOTStrategy * strategy); - - // \section{Implementation of [[GUSIOTSocket]]} - // - // Open Transport may call this routine for dozens and dozens of different - // reasons. Pretty much every call results in a wakeup of the threads attached - // to the socket. We save some of the more interesting events in bitsets. - // in [[MopupEvents]]. - // - // = - uint16_t fNewEvent; - uint16_t fCurEvent; - uint16_t fEvent; - uint32_t fNewCompletion; - uint32_t fCurCompletion; - uint32_t fCompletion; - friend pascal void GUSIOTNotify(GUSIOTSocket *, OTEventCode, OTResult, void *); - // To avoid race conditions with the notifier, we sometimes need a lock. - // - // = - class Lock { - public: - Lock(EndpointRef end) : fEndpoint(end) { OTEnterNotifier(fEndpoint); } - ~Lock() { OTLeaveNotifier(fEndpoint); } - private: - EndpointRef fEndpoint; - }; - // For some events, we have to take a followup action at a more convenient time. - // - // = - virtual void MopupEvents(); - // [[GUSIOTSocket]] creates an asynchronous endpoint for the appropriate - // provider. - // - // = - GUSIOTStrategy * fStrategy; - EndpointRef fEndpoint; - linger fLinger; - UInt32 fDeadline; - // The destructor tears down the connection as gracefully as possible. It also respects - // the linger settings. - // - // = - virtual void close(); - virtual ~GUSIOTSocket(); - // [[Clone]] creates another socket of the same class. - // - // = - virtual GUSIOTSocket * Clone() = 0; - // At the time the socket function [[bind]] is called, we are not really ready - // yet to call [[OTBind]], but if we don't call it, we can't report whether the - // address was free. - // - // = - GUSIOTTBind * fSockName; - int BindToAddress(GUSIOTTBind * addr); - // Open Transport takes unbinding a lot more serious than MacTCP. - // - // = - void Unbind(); - - friend class GUSIOTStreamSocket; - friend class GUSIOTDatagramSocket; -}; -// = -class GUSIOTStreamSocket : public GUSIOTSocket { -public: - // [[Clone]] creates another socket of the same class. - // - // = - virtual GUSIOTSocket * Clone(); - // = - virtual void close(); - virtual bool Close(UInt32 now); - ~GUSIOTStreamSocket(); - // Stream sockets include a mopup action for connect and disconnect. - // - // = - virtual void MopupEvents(); - // [[listen]] is a bit embarassing, because we already committed ourselves - // to a queue length of [[0]], so we have to unbind and rebind ourselves. - // - // = - virtual int listen(int qlen); - // = - virtual int getpeername(void * name, socklen_t * namelen); - // [[accept]] may become quite complex, because connections could nest. The - // listening socket calls [[OTListen]], queues candidates by their - // [[fNextListener]] field, and then trys calling [[OTAccept]] on the first - // candidate. - // - // = - virtual GUSISocket * accept(void * address, socklen_t * addrlen); - // [[connect]] is comparatively simple. - // - // = - virtual int connect(void * address, socklen_t addrlen); - // Data transfer is simple as well. Here is the version for stream protocols. - // - // = - virtual ssize_t recvfrom(const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen); - // = - virtual ssize_t sendto(const GUSIGatherer & buffer, int flags, const void * to, socklen_t tolen); - // [[select]] for stream sockets intermingles data information and connection - // information as usual. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * except); - // [[shutdown]] for stream sockets has to send an orderly disconnect. - // - // = - virtual int shutdown(int how); -protected: - GUSIOTStreamSocket(GUSIOTStrategy * strategy); - - // Since all we need to know is in the [[GUSIOTStrategy]], it often suffices - // simply to create a [[GUSIOTSocket]]. Stream and datagram sockets differ - // merely in the descendant they create. - // - // = - friend class GUSIOTStreamFactory; - // = - friend pascal void GUSIOTNotify(GUSIOTSocket *, OTEventCode, OTResult, void *); - // The peer address for a [[GUSIOTStreamSocket]] is stored in a [[GUSIOTTCall]] - // structure. - // - // = - GUSIOTTCall * fPeerName; - // = - GUSIOTStreamSocket * fNextListener; -}; -// = -class GUSIOTDatagramSocket : public GUSIOTSocket { -public: - // [[Clone]] creates another socket of the same class. - // - // = - virtual GUSIOTSocket * Clone(); - // = - ~GUSIOTDatagramSocket(); - // = - virtual int getpeername(void * name, socklen_t * namelen); - // A datagram socket can [[connect]] as many times as it wants. - // - // = - virtual int connect(void * address, socklen_t addrlen); - // Datagram protocols use slightly different calls for data transfers. - // - // = - virtual ssize_t recvfrom(const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen); - // [[sendto]] needs either a valid [[to]] address or a stored peer address set by - // [[connect]]. - // - // = - virtual ssize_t sendto(const GUSIGatherer & buffer, int flags, const void * to, socklen_t tolen); - // [[select]] for datagram sockets returns data information only. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * except); -protected: - GUSIOTDatagramSocket(GUSIOTStrategy * strategy); - - // = - friend class GUSIOTDatagramFactory; - // Datagram sockets might be bound at rather arbitrary times. - // - // = - int BindIfUnbound(); - // The peer address for a [[GUSIOTDatagramSocket]] is stored in a [[GUSIOTTBind]] - // structure. - // - // = - GUSIOTTBind * fPeerName; -}; - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIOpenTransport_ */ diff --git a/GUSI/include/GUSIPOSIX.h b/GUSI/include/GUSIPOSIX.h deleted file mode 100755 index 7e56ecb..0000000 --- a/GUSI/include/GUSIPOSIX.h +++ /dev/null @@ -1,115 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIPOSIX.nw - POSIX/Socket wrappers -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.22 2001/01/17 08:58:06 neeri -// % Releasing 2.1.4 -// % -// % Revision 1.21 2000/10/29 18:36:32 neeri -// % Fix time_t signedness issues -// % -// % Revision 1.20 2000/10/16 04:34:23 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.19 2000/06/12 04:24:50 neeri -// % Fix time, localtime, gmtime -// % -// % Revision 1.18 2000/05/23 07:15:30 neeri -// % Improve formatting -// % -// % Revision 1.17 2000/03/06 08:18:25 neeri -// % Fix sleep, usleep, chdir; new Yield system -// % -// % Revision 1.16 2000/01/17 01:41:21 neeri -// % Fix rename() mangling -// % -// % Revision 1.15 1999/12/13 03:01:48 neeri -// % Another select() fix -// % -// % Revision 1.14 1999/11/15 07:22:34 neeri -// % Safe context setup. Fix sleep checking. -// % -// % Revision 1.13 1999/09/09 07:21:22 neeri -// % Add support for inet_aton -// % -// % Revision 1.12 1999/08/26 05:45:06 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.11 1999/07/19 06:21:03 neeri -// % Add mkdir/rmdir, fix various file manager related bugs -// % -// % Revision 1.10 1999/07/07 04:17:42 neeri -// % Final tweaks for 2.0b3 -// % -// % Revision 1.9 1999/06/28 06:04:59 neeri -// % Support interrupted calls -// % -// % Revision 1.8 1999/05/30 03:09:31 neeri -// % Added support for MPW compilers -// % -// % Revision 1.7 1999/04/29 05:33:18 neeri -// % Fix fcntl prototype -// % -// % Revision 1.6 1999/03/29 09:51:29 neeri -// % New configuration system with support for hardcoded configurations. -// % -// % Revision 1.5 1999/03/17 09:05:11 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.4 1998/10/25 11:35:19 neeri -// % chdir, getcwd, setxxxent -// % -// % Revision 1.3 1998/10/11 16:45:22 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.2 1998/08/01 21:32:09 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:49 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{POSIX/Socket Wrappers} -// -// Now everything is in place to define the POSIX and socket routines -// themselves. As opposed to our usual practice, we don't declare the -// exported routines here, as they all have been declared in [[unistd.h]] -// or [[sys/socket.h]] already. The exceptions are [[remove]] and [[rename]], -// which are declared in [[stdio.h]], which we'd rather not include, and -// various calls which are not consistently declared. -// -// = -#ifndef _GUSIPOSIX_ -#define _GUSIPOSIX_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -__BEGIN_DECLS -int remove(const char * path); -int rename(const char *oldname, const char *newname); -int fgetfileinfo(const char * path, OSType * creator, OSType * type); -void fsetfileinfo(const char * path, OSType creator, OSType type); -time_t time(time_t * timer); -struct tm * localtime(const time_t * timer); -struct tm * gmtime(const time_t * timer); -time_t mktime(struct tm *timeptr); -__END_DECLS - -#endif /* _GUSIPOSIX_ */ diff --git a/GUSI/include/GUSIPPC.h b/GUSI/include/GUSIPPC.h deleted file mode 100755 index 616a162..0000000 --- a/GUSI/include/GUSIPPC.h +++ /dev/null @@ -1,37 +0,0 @@ -// The [[GUSIPPCFactory]] singleton creates [[GUSIPPCSockets]]. -// -// = -#ifndef _GUSIPPC_ -#define _GUSIPPC_ - -#ifdef GUSI_INTERNAL - -#include "GUSISocket.h" -#include "GUSIFactory.h" -#include - -// \section{Definition of [[GUSIPPCFactory]]} -// -// [[GUSIPPCFactory]] is a singleton subclass of [[GUSISocketFactory]]. -// -// = -class GUSIPPCFactory : public GUSISocketFactory { -public: - static GUSISocketFactory * Instance(); - virtual GUSISocket * socket(int domain, int type, int protocol); -private: - GUSIPPCFactory() {} - static GUSISocketFactory * sInstance; -}; - -// = -inline GUSISocketFactory * GUSIPPCFactory::Instance() -{ - if (!sInstance) - sInstance = new GUSIPPCFactory; - return sInstance; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIPPC_ */ diff --git a/GUSI/include/GUSIPThread.h b/GUSI/include/GUSIPThread.h deleted file mode 100755 index e3f64b0..0000000 --- a/GUSI/include/GUSIPThread.h +++ /dev/null @@ -1,30 +0,0 @@ -// = -#ifndef _GUSIPThread_ -#define _GUSIPThread_ - -#include "GUSISpecific.h" -#include "GUSIContext.h" -#include "GUSIContextQueue.h" - -#include - -// = -struct GUSIPThread : public GUSIContext { -private: - GUSIPThread() : GUSIContext(0) {} // Never called -}; -// = -struct GUSIPThreadKey : public GUSISpecific { - GUSIPThreadKey(GUSIPThreadKeyDestructor destructor) : GUSISpecific(destructor) {} -}; -// = -struct GUSIPThreadMutex : public GUSIContextQueue { - bool fPolling; - - GUSIPThreadMutex() : fPolling(false) {} -}; -// = -struct GUSIPThreadCond : public GUSIContextQueue { -}; - -#endif /* _GUSIPThread_ */ diff --git a/GUSI/include/GUSIPipe.h b/GUSI/include/GUSIPipe.h deleted file mode 100755 index b5d7f29..0000000 --- a/GUSI/include/GUSIPipe.h +++ /dev/null @@ -1,88 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIPipe.nw - Pipes -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.12 2000/05/23 07:18:03 neeri -// % Improve formatting -// % -// % Revision 1.11 2000/03/06 06:09:59 neeri -// % Reorganize Yield() -// % -// % Revision 1.10 1999/11/15 07:20:59 neeri -// % Add GUSIwithLocalSockets -// % -// % Revision 1.9 1999/08/26 05:45:07 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.8 1999/06/28 06:05:00 neeri -// % Support interrupted calls -// % -// % Revision 1.7 1999/05/29 06:26:45 neeri -// % Fixed header guards -// % -// % Revision 1.6 1999/03/17 09:05:12 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.5 1998/11/22 23:07:00 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.4 1998/10/25 11:57:38 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.3 1998/01/25 20:53:57 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.2 1996/12/22 19:57:58 neeri -// % TCP streams work -// % -// % Revision 1.1 1996/11/24 12:52:08 neeri -// % Added GUSIPipeSockets -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{The GUSI Pipe Socket Class} -// -// Pipes and socket pairs are implemented with the [[GUSIPipeSocket]] class. -// The [[GUSIPipeFactory]] singleton creates pairs of [[GUSIPipeSockets]]. -// -// = -#ifndef _GUSIPipe_ -#define _GUSIPipe_ - -#ifdef GUSI_INTERNAL - -#include "GUSISocket.h" -#include "GUSIFactory.h" - -// \section{Definition of [[GUSIPipeFactory]]} -// -// [[GUSIPipeFactory]] is a singleton subclass of [[GUSISocketFactory]]. -// -// = -class GUSIPipeFactory : public GUSISocketFactory { -public: - static GUSISocketFactory * Instance(); - virtual GUSISocket * socket(int domain, int type, int protocol); - virtual int socketpair(int domain, int type, int protocol, GUSISocket * s[2]); -private: - GUSIPipeFactory() {} - static GUSISocketFactory * sInstance; -}; - -// = -inline GUSISocketFactory * GUSIPipeFactory::Instance() -{ - if (!sInstance) - sInstance = new GUSIPipeFactory; - return sInstance; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSIPipe_ */ diff --git a/GUSI/include/GUSISIOUX.h b/GUSI/include/GUSISIOUX.h deleted file mode 100755 index a580e3c..0000000 --- a/GUSI/include/GUSISIOUX.h +++ /dev/null @@ -1,48 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSISIOUX.nw - SIOUX Support -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.8 2000/05/23 07:18:03 neeri -// % Improve formatting -// % -// % Revision 1.7 2000/03/06 06:03:29 neeri -// % Check device families for file paths -// % -// % Revision 1.6 1999/08/26 05:45:08 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.5 1999/06/08 04:31:30 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.4 1999/05/29 06:26:45 neeri -// % Fixed header guards -// % -// % Revision 1.3 1999/03/17 09:05:12 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/11/22 23:07:01 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.1 1998/10/25 11:57:39 neeri -// % Ready to release 2.0a3 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{SIOUX Support} -// -// To combine GUSI with SIOUX, terminal I/O needs to interface with the SIOUX -// event handling. -// -// SIOUX support is installed implicitly through [[GUSISetupConsoleDescriptors]] -// -// = -#ifndef _GUSISIOUX_ -#define _GUSISIOUX_ - -#endif /* _GUSISIOUX_ */ diff --git a/GUSI/include/GUSISIOW.h b/GUSI/include/GUSISIOW.h deleted file mode 100755 index ed9bfb5..0000000 --- a/GUSI/include/GUSISIOW.h +++ /dev/null @@ -1,27 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSISIOW.nw - SIOW Interface -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.2 1999/08/26 05:45:08 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.1 1999/07/19 06:17:08 neeri -// % Add SIOW support -// % -// -// \chapter{SIOW Support} -// -// SIOW support is based on MPW support, adding a few event hooks so update and activate events -// get handled during blocking calls. SIOW support is installed implecitly through [[GUSIDefaultSetupConsole]]. -// -// = -#ifndef _GUSISIOW_ -#define _GUSISIOW_ - -#endif /* _GUSISIOW_ */ diff --git a/GUSI/include/GUSISignal.h b/GUSI/include/GUSISignal.h deleted file mode 100755 index 7a7578c..0000000 --- a/GUSI/include/GUSISignal.h +++ /dev/null @@ -1,149 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSISignal.nw - Signal engine -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:13 chombier -// % Initial import -// % -// % Revision 1.7 2000/10/16 04:08:51 neeri -// % Add binary compatibility for CW SIGINT -// % -// % Revision 1.6 2000/05/23 07:18:03 neeri -// % Improve formatting -// % -// % Revision 1.5 2000/03/15 07:22:07 neeri -// % Enforce alignment choices -// % -// % Revision 1.4 1999/12/13 03:07:25 neeri -// % Releasing 2.0.2 -// % -// % Revision 1.3 1999/11/15 07:20:18 neeri -// % Safe context setup -// % -// % Revision 1.2 1999/08/26 05:45:09 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.1 1999/06/30 07:42:07 neeri -// % Getting ready to release 2.0b3 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Signal support} -// -// We support signals in the half assed way characteristic for GUSI's approach to -// asynchronous issues: Delivery is very much synchronous, basically within [[Yield]] -// calls. Signal handling behavior is encapsulated in the classes [[GUSISigContext]] and -// [[GUSISigProcess]] whose instances are manufactured by a [[GUSISigFactory]]. -// -// = -#ifndef _GUSISIGNAL_ -#define _GUSISIGNAL_ - -#include - -#ifdef GUSI_SOURCE - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of the signal handling engine} -// -// A [[GUSISigProcess]] contains the per-process signal state. [[GetAction]] and [[SetAction]] manipulate the -// action associated with a signal, [[Pending]] returns the set of pending signals, [[Post]] marks a signal -// as pending (but possibly blocked), and [[Raise]] executes a signal (which we have determined is not -// blocked). -// -// = -class GUSISigContext; - -class GUSISigProcess { -public: - virtual struct sigaction & GetAction(int sig); - virtual int SetAction(int sig, const struct sigaction & act); - virtual sigset_t Pending() const; - virtual void ClearPending(sigset_t clear); - virtual void Post(int sig); - virtual bool Raise(int sig, GUSISigContext * context); - - virtual ~GUSISigProcess(); -protected: - // [[GUSISigProcess]] stores the signal handlers and the set of signals pending against the process. - // - // = - sigset_t fPending; - struct sigaction fAction[NSIG-1]; - // Some actions can't be caught and/or ignored. [[CantCatch]] and [[CantIgnore]] report those. - // - // = - virtual bool CantCatch(int sig); - virtual bool CantIgnore(int sig); - // The default behavior for many signals is to abort the process. - // - // = - virtual bool DefaultAction(int sig, const struct sigaction & act); - - friend class GUSISigFactory; - GUSISigProcess(); -}; -// A [[GUSISigContext]] contains the per-thread signal state, primarily blocking info. To support -// [[pthread_kill]], we have out own set of pending signals. [[GetBlocked]] and [[SetBlocked]] manipulate -// the set of blocking signals, [[Pending]] returns the set of pending signals, [[Post]] marks a -// signal as pending (but possibly blocked), and [[Raise]] executes all eligible signals. -// -// = -class GUSISigContext { -public: - virtual sigset_t GetBlocked() const; - virtual void SetBlocked(sigset_t sigs); - virtual sigset_t Pending() const; - virtual sigset_t Pending(GUSISigProcess * proc) const; - virtual void ClearPending(sigset_t clear); - virtual void Post(int sig); - virtual sigset_t Ready(GUSISigProcess * proc); - virtual bool Raise(GUSISigProcess * proc, bool allSigs = false); - - virtual ~GUSISigContext(); -protected: - // [[GUSISigContext]] mainly deals with a set of blocked signals, which it inherits from its parent. - // - // = - sigset_t fPending; - sigset_t fBlocked; - // Many signals cannot be blocked. [[CantBlock]] defines those. - // - // = - virtual sigset_t CantBlock(); - - friend class GUSISigFactory; - GUSISigContext(const GUSISigContext * parent); -}; -// The [[GUSISigFactory]] singleton creates the above two classes, allowing a future extension to -// handle more signals. -// -// = -class GUSISigFactory { -public: - virtual GUSISigProcess * CreateSigProcess(); - virtual GUSISigContext * CreateSigContext(const GUSISigContext * parent); - - virtual ~GUSISigFactory(); - - static GUSISigFactory * Instance(); - static void SetInstance(GUSISigFactory * instance); -protected: - GUSISigFactory() {} -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -#endif - -#endif /* _GUSISIGNAL_ */ diff --git a/GUSI/include/GUSISocket.h b/GUSI/include/GUSISocket.h deleted file mode 100755 index 09feba4..0000000 --- a/GUSI/include/GUSISocket.h +++ /dev/null @@ -1,362 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSISocket.nw - The socket class -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:14 chombier -// % Initial import -// % -// % Revision 1.18 2000/10/16 04:34:23 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.17 2000/05/23 07:19:34 neeri -// % Improve formatting, add close queue -// % -// % Revision 1.16 2000/03/15 07:20:53 neeri -// % Add GUSISocket::AddContextInScope -// % -// % Revision 1.15 1999/10/15 02:48:51 neeri -// % Make disconnects orderly -// % -// % Revision 1.14 1999/09/26 03:59:26 neeri -// % Releasing 2.0fc1 -// % -// % Revision 1.13 1999/08/26 05:45:09 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.12 1999/06/08 04:31:31 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.11 1999/05/29 06:26:45 neeri -// % Fixed header guards -// % -// % Revision 1.10 1999/04/29 05:33:18 neeri -// % Fix fcntl prototype -// % -// % Revision 1.9 1999/03/17 09:05:13 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.8 1998/11/22 23:07:01 neeri -// % Releasing 2.0a4 in a hurry -// % -// % Revision 1.7 1998/10/11 16:45:23 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.6 1998/08/01 21:29:53 neeri -// % Use context queues -// % -// % Revision 1.5 1998/01/25 20:53:58 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.4 1997/11/13 21:12:12 neeri -// % Fall 1997 -// % -// % Revision 1.3 1996/11/24 13:00:28 neeri -// % Fix comment leaders -// % -// % Revision 1.2 1996/11/24 12:52:09 neeri -// % Added GUSIPipeSockets -// % -// % Revision 1.1.1.1 1996/11/03 02:43:32 neeri -// % Imported into CVS -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{The GUSI Socket Class} -// -// GUSI is constructed around the [[GUSISocket]] class. This class is -// mostly an abstract superclass, but all virtual procedures are implemented -// to return sensible error codes. -// -// = -#ifndef _GUSISocket_ -#define _GUSISocket_ - -#ifdef GUSI_SOURCE - -#include "GUSIBasics.h" -#include "GUSIContext.h" -#include "GUSIContextQueue.h" -#include "GUSIBuffer.h" - -#include -#include -#include - -#include -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of [[GUSISocket]]} -// -// [[GUSISocket]] consists of a few maintenance functions and the socket operations. -// Each operation consists to a POSIX/BSD function with the file descriptor operand -// left out. -// -// = -class GUSISocket { - // Since a single [[GUSISocket]] may (through [[dup]]) be installed multiply - // in a descriptor table or even in multiple descriptor tables, [[GUSISocket]]s - // are not destroyed directly, but by manipulating a reference count. As soon - // as the reference count hits zero, the destructor (which, of course, should - // probably be overridden) is called. - // - // Since destructors cannot call virtual functions, we call [[close]] which - // eventually calls the destructor. Some socket types can take quite long to close - // under unfavorable circumstances. To speed up the process, we have the option of - // queueing the socket up and regularly having [[Close]] called on it. - // - // = - public: - void AddReference(); - void RemoveReference(); - - virtual void close(); - void CheckClose(UInt32 now = LMGetTicks()); - protected: - GUSISocket(); - virtual ~GUSISocket(); - virtual bool Close(UInt32 now = LMGetTicks()); - private: - u_long fRefCount; - // [[GUSIContext]]s are defined in {\tt GUSIBasics}. A context references all - // information you need in a completion procedure: The contents of [[A5]], - // the process ID, and thread information. [[Wakeup]] wakes up the threads - // and/or processes associated with the socket and is guaranteed to work even - // at interrupt level. [[AddContext]] adds another context. [[RemoveContext]] - // indicates that this context no longer should be woken up when something happens. - // To keep a context added inside a scope, declare an automatic object of class - // [[AddContextInScope]]. - // - // = - public: - void Wakeup(); - void AddContext(GUSIContext * context = nil); - void RemoveContext(GUSIContext * context = nil); - - class AddContextInScope { - public: - AddContextInScope(GUSISocket * sock, GUSIContext * context = nil) - : fSocket(sock), fContext(context) - { fSocket->AddContext(fContext); } - ~AddContextInScope() { fSocket->RemoveContext(fContext); } - private: - GUSISocket * fSocket; - GUSIContext * fContext; - }; - private: - GUSIContextQueue fContexts; - // There may be various reasons to keep sockets in queue. Currently the - // only reason is to queue up dying sockets. - // - // = - public: - void Enqueue(GUSISocket ** queue); - void Dequeue(); - private: - GUSISocket ** fQueue; - GUSISocket * fNextSocket; - GUSISocket * fPrevSocket; - // Both read and write calls on sockets come in five different variants: - // - // \begin{enumerate} - // \item [[read]] and [[write]] - // \item [[recv]] and [[send]] - // \item [[readv]] and [[writev]] - // \item [[recvfrom]] and [[sendto]] - // \item [[recvmsg]] and [[sendmsg]] - // \end{enumerate} - // - // GUSI initially maps variants 3 and 5 of these calls to the [[recvmsg]] and - // [[sendmsg]] member functions, variants 2 and 4 to the [[recvfrom]] and - // [[sendto]] member functions, and variant 1 to the [[read]] and - // [[write]] member functions. - // - // The simpler member functions can always be translated into the complex member - // functions, and under some circumstances, the opposite is also possible. - // To avoid translation loops, the translation routines (i.e., the default - // implementation of [[GUSISocket::read]] and [[GUSISocket::recvmsg]] - // check for the availablility of the other function by calling [[Supports]]. - // This member function must be overridden for any reasonable socket class. - // - // = - protected: - enum ConfigOption { - kSimpleCalls, // [[read]], [[write]] - kSocketCalls, // [[recvfrom]], [[sendto]] - kMsgCalls // [[recvmsg]], [[sendmsg]] - }; - virtual bool Supports(ConfigOption config); -public: - // Most sockets have names, which to [[GUSISocket]] are just opaque blocks of - // memory. A name for a socket is established (before the socket is actually - // used, of course) through [[bind]]. The name may be queried with - // [[getsockname]] and once the socket is connected, the name of the peer - // endpoint may be queried with [[getpeername]]. - // - // = - virtual int bind(void * name, socklen_t namelen); - virtual int getsockname(void * name, socklen_t * namelen); - virtual int getpeername(void * name, socklen_t * namelen); - // Sockets follow either a virtual circuit model where all data is exchanged - // with the same peer throughout the lifetime of the connection, or a datagram - // model where potentially every message is exchanged with a different peer. - // - // The vast majority of protocols follow the virtual circuit model. The server - // end, typically after calling [[bind]] to attach the socket to a well known - // address, calls [[listen]] to establish its willingness to accept connections. - // [[listen]] takes a queue length parameter, which however is ignored for many - // types of sockets. - // - // Incoming connections are then accepted by calling [[accept]]. When [[accept]] - // is successful, it always returns a new [[GUSISocket]], while the original socket - // remains available for further connections. To avoid blocking on [[accept]], you may poll for connections with an - // [[accept()] call in nonblocking mode or query the result of [[select]] whether - // the socket is ready for reading. - // - // The client end in the virtual circuit model connects itself to the well known - // address by calling [[connect]]. To avoid blocking on [[connect]], you may - // call it in nonblocking mode and then query the result of [[select]] whether - // the socket is ready for writing. - // - // In the datagram model, you don't need to establish connections. You may call - // [[connect]] anyway to temporarily establish a virtual circuit. - // - // = - virtual int listen(int qlen); - virtual GUSISocket * accept(void * address, socklen_t * addrlen); - virtual int connect(void * address, socklen_t addrlen); - // As mentioned before, there are three variants each for reading and writing. - // The socket variants provide a means to pass a peer address for the datagram - // model, while the msg variants also provides fields for passing access rights, - // which is, however not currently supported in GUSI. As syntactic sugar, the more - // traditional flavors with [[buffer]]/[[length]] buffers are also supported. - // - // = - virtual ssize_t read(const GUSIScatterer & buffer); - virtual ssize_t write(const GUSIGatherer & buffer); - virtual ssize_t recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen); - virtual ssize_t sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t tolen); - virtual ssize_t recvmsg(msghdr * msg, int flags); - virtual ssize_t sendmsg(const msghdr * msg, int flags); - - ssize_t read(void * buffer, size_t length); - ssize_t write(const void * buffer, size_t length); - ssize_t recvfrom( - void * buffer, size_t length, int flags, void * from, socklen_t * fromlen); - ssize_t sendto( - const void * buffer, size_t length, int flags, const void * to, socklen_t tolen); - // A multitude of parameters can be manipulated for a [[GUSISocket]] through - // the socket oriented calls [[getsockopt]], [[setsockopt]], the file oriented - // call [[fcntl]], and the device oriented call [[ioctl]]. - // - // [[isatty]] returns whether the socket should be considered an interactive - // console. - // - // = - virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen); - virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen); - virtual int fcntl(int cmd, va_list arg); - virtual int ioctl(unsigned int request, va_list arg); - virtual int isatty(); - // Three of the operations make sense primarily for files, and most other socket - // types accept the default implementations. [[fstat]] returns information about - // an open file, [[lseek]] repositions the read/write pointer, and [[ftruncate]] - // cuts off an open file at a certain point. - // - // = - virtual int fstat(struct stat * buf); - virtual off_t lseek(off_t offset, int whence); - virtual int ftruncate(off_t offset); - // [[select]] polls or waits for one of a group of [[GUSISocket]] to become - // ready for reading, writing, or for an exceptional condition to occur. - // First, [[pre_select]] is called once for all [[GUSISocket]]s in the group. - // It returns [[true]] is the socket will wake up as soon as one of the events - // occurs and [[false]] if GUSI needs to poll. - // Next, [[select]] is called for all [[GUSISocket]]s once or multiple times, - // until a condition becomes true or the call times out. Finally, [[post_select]] - // is called for all members of the group. - // - // = - virtual bool pre_select(bool wantRead, bool wantWrite, bool wantExcept); - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - virtual void post_select(bool wantRead, bool wantWrite, bool wantExcept); - // A socket connection is usually full duplex. By calling [[shutdown(1)]], you - // indicate that you won't write any more data on this socket. The values 0 (no - // more reads) and 2 (no more read/write) are used less frequently. - // - // = - virtual int shutdown(int how); - // Some socket types do not write out data immediately. Calling [[fsync]] guarantees - // that all data is written. - // - // = - virtual int fsync(); -}; - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// \section{Implementation of [[GUSISocket]]} -// -// \subsection{General socket management} -// -// -// = -inline void GUSISocket::AddReference() -{ - ++fRefCount; -} - -inline void GUSISocket::RemoveReference() -{ - if (!--fRefCount) - close(); -} - -// \subsection{Context management} -// -// -// = -inline void GUSISocket::Wakeup() -{ - fContexts.Wakeup(); -} - -// The traditional flavors of the I/O calls are translated to the scatterer/gatherer -// variants. -// -// = -inline ssize_t GUSISocket::read(void * buffer, size_t length) -{ - return read(GUSIScatterer(buffer, length)); -} - -inline ssize_t GUSISocket::write(const void * buffer, size_t length) -{ - return write(GUSIGatherer(buffer, length)); -} - -inline ssize_t GUSISocket::recvfrom( - void * buffer, size_t length, int flags, void * from, socklen_t * fromlen) -{ - return recvfrom(GUSIScatterer(buffer, length), flags, from, fromlen); -} - -inline ssize_t GUSISocket::sendto( - const void * buffer, size_t length, int flags, const void * to, socklen_t tolen) -{ - return sendto(GUSIGatherer(buffer, length), flags, to, tolen); -} - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSISocket_ */ diff --git a/GUSI/include/GUSISocketMixins.h b/GUSI/include/GUSISocketMixins.h deleted file mode 100755 index 883bd63..0000000 --- a/GUSI/include/GUSISocketMixins.h +++ /dev/null @@ -1,360 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSISocketMixins.nw - Useful building blocks -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:14 chombier -// % Initial import -// % -// % Revision 1.11 2000/10/16 04:10:12 neeri -// % Add GUSISMProcess -// % -// % Revision 1.10 2000/05/23 07:24:58 neeri -// % Improve formatting -// % -// % Revision 1.9 1999/08/26 05:45:09 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.8 1999/08/02 07:02:46 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.7 1999/05/29 06:26:45 neeri -// % Fixed header guards -// % -// % Revision 1.6 1999/04/29 05:33:18 neeri -// % Fix fcntl prototype -// % -// % Revision 1.5 1999/03/17 09:05:13 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.4 1998/10/11 16:45:24 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.3 1998/01/25 20:53:59 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.2 1997/11/13 21:12:13 neeri -// % Fall 1997 -// % -// % Revision 1.1 1996/12/16 02:12:42 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Mixin Classes for Sockets} -// -// This section contains some building block classes for sockets: -// -// \begin{itemize} -// \item [[GUSISMBlocking]] implements the blocking/nonblocking flag. -// \item [[GUSISMState]] implements a state variable. -// \item [[GUSISMInputBuffer]] provides a [[GUSIBuffer]] for input. -// \item [[GUSISMOutputBuffer]] provides a [[GUSIBuffer]] for output. -// \item [[GUSISMAsyncError]] provides storage for asynchronous errors. -// \item [[GUSISMProcess]] maintains a link to the process instance. -// \end{itemize} -// -// -// = -#ifndef _GUSISocketMixins_ -#define _GUSISocketMixins_ - -#ifdef GUSI_INTERNAL - -#include "GUSISocket.h" -#include "GUSIBuffer.h" - -#include -#include - -// \section{Definition of [[GUSISocketMixins]]} -// -// [[GUSISMBlocking]] implements the [[fBlocking]] flags and the [[DoIoctl]] and -// [[DoFcntl]] variants to manipulate it. These two functions work like their -// [[GUSISocket]] member function counterparts, but handle the return value -// differently: The POSIX function result is stored in [[*result]], while the -// return value indicates whether the request was handled. -// -// = -class GUSISMBlocking { -public: - GUSISMBlocking(); - bool fBlocking; - bool DoFcntl(int * result, int cmd, va_list arg); - bool DoIoctl(int * result, unsigned int request, va_list arg); -}; -// [[GUSISMState]] captures the state of a socket over its lifetime. It starts out -// as [[Unbound]]. [[bind]] will put it into [[Unconnected]] state, though few -// socket classes care about this distinction. [[listen]] will put it into -// [[Listening]] state. [[accept]] starts a [[Connected]] new socket. -// [[connect]] puts an [[Unconnected]] socket into [[Connecting]] state from -// where it emerges [[Connected]]. [[fReadShutdown]] and [[fWriteShutdown]] record -// shutdown promises. -// -// = -class GUSISMState { -public: - enum State { - Unbound, - Unconnected, - Listening, - Connecting, - Connected, - Closing - }; - GUSISMState(); - State fState; - bool fReadShutdown; - bool fWriteShutdown; - void Shutdown(int how); -}; -// [[GUSISMInputBuffer]] defines the input buffer and some socket options that go -// with it. [[DoGetSockOpt]] and [[DoSetSockOpt]] work the same way as -// [[DoFcntl]] and [[DoIoctl]] above. -// -// = -class GUSISMInputBuffer { -public: - GUSIRingBuffer fInputBuffer; - GUSISMInputBuffer(); - bool DoGetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t * optlen); - bool DoSetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t optlen); - bool DoIoctl(int * result, unsigned int request, va_list arg); -}; -// [[GUSISMOutputBuffer]] defines the output buffer and some socket options that go -// with it. -// -// = -class GUSISMOutputBuffer { -public: - GUSIRingBuffer fOutputBuffer; - GUSISMOutputBuffer(); - bool DoGetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t * optlen); - bool DoSetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t optlen); -}; -// [[GUSISMAsyncError]] stores asynchronous errors and makes them available via -// [[getsockopt]]. [[GetAsyncError]] returns the error and resets the stored value. -// -// = -class GUSISMAsyncError { -public: - GUSISMAsyncError(); - int fAsyncError; - int SetAsyncPosixError(int error); - int SetAsyncMacError(OSErr error); - int GetAsyncError(); - bool DoGetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t * optlen); -}; -// [[GUSISMProcess]] stores a link to the global [[GUSIProcess]] instance, which is useful for completion routines. -// -// = -class GUSISMProcess { -public: - GUSISMProcess(); - - GUSIProcess * Process(); -private: - GUSIProcess * fProcess; -}; - -// \section{Implementation of [[GUSISocketMixins]]} -// -// Because all the member functions are simple and called in few places, it -// makes sense to inline them. -// -// All sockets start out blocking. -// -// = -inline GUSISMBlocking::GUSISMBlocking() : fBlocking(true) {} -// For historical reasons, there is both an [[ioctl]] and a [[fcntl]] interface -// to the blocking flag. -// -// = -inline bool GUSISMBlocking::DoFcntl(int * result, int cmd, va_list arg) -{ - switch(cmd) { - case F_GETFL : - return (*result = fBlocking ? 0: FNDELAY), true; - case F_SETFL : - fBlocking = !(va_arg(arg, int) & FNDELAY); - - return (*result = 0), true; - } - return false; -} -inline bool GUSISMBlocking::DoIoctl(int * result, unsigned int request, va_list arg) -{ - if (request == FIONBIO) { - fBlocking = !*va_arg(arg, int *); - return (*result = 0), true; - } - return false; -} -// Sockets start out as unconnected. -// -// = -inline GUSISMState::GUSISMState() : - fState(Unbound), fReadShutdown(false), fWriteShutdown(false) {} -// = -inline void GUSISMState::Shutdown(int how) -{ - if (!(how & 1)) - fReadShutdown = true; - if (how > 0) - fWriteShutdown = true; -} -// Buffers initially are 8K. -// -// = -inline GUSISMInputBuffer::GUSISMInputBuffer() : fInputBuffer(8192) {} -// [[getsockopt]] is used to obtain the buffer size. -// -// = -inline bool GUSISMInputBuffer::DoGetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t *) -{ - if (level == SOL_SOCKET && optname == SO_RCVBUF) { - *(int *)optval = (int)fInputBuffer.Size(); - - return (*result = 0), true; - } - return false; -} -// [[setsockopt]] modifies the buffer size. -// -// = -inline bool GUSISMInputBuffer::DoSetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t) -{ - if (level == SOL_SOCKET && optname == SO_RCVBUF) { - fInputBuffer.SwitchBuffer(*(int *)optval); - - return (*result = 0), true; - } - return false; -} -// [[ioctl]] returns the number of available bytes. -// -// = -inline bool GUSISMInputBuffer::DoIoctl(int * result, unsigned int request, va_list arg) -{ - if (request == FIONREAD) { - *va_arg(arg, long *) = fInputBuffer.Valid(); - return (*result = 0), true; - } - return false; -} -// [[GUSISMOutputBuffer]] works identically to the input buffer. -// -// = -inline GUSISMOutputBuffer::GUSISMOutputBuffer() : fOutputBuffer(8192) {} -// [[getsockopt]] is used to obtain the buffer size. -// -// = -inline bool GUSISMOutputBuffer::DoGetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t *) -{ - if (level == SOL_SOCKET && optname == SO_SNDBUF) { - *(int *)optval = (int)fOutputBuffer.Size(); - - return (*result = 0), true; - } - return false; -} -// [[setsockopt]] is modifies the buffer size. -// -// = -inline bool GUSISMOutputBuffer::DoSetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t) -{ - if (level == SOL_SOCKET && optname == SO_SNDBUF) { - fOutputBuffer.SwitchBuffer(*(int *)optval); - - return (*result = 0), true; - } - return false; -} -// = -inline GUSISMAsyncError::GUSISMAsyncError() - : fAsyncError(0) -{ -} -// The central member functions of [[GUSISMAsyncError]] are [[SetAsyncXXXError]] and -// [[GetAsyncError]]. -// -// = -inline int GUSISMAsyncError::SetAsyncPosixError(int error) -{ - if (error) { - fAsyncError = error; - GUSI_MESSAGE(("GUSISMAsyncError::SetAsyncPosixError %d\n", fAsyncError)); - - return -1; - } - return 0; -} -inline int GUSISMAsyncError::GetAsyncError() -{ - int err = fAsyncError; - fAsyncError = 0; - return err; -} -// For some reason, the CW Pro 4 compilers generated bad code for this in some combination, so -// we make it out of line. -// -// = -inline int GUSISMAsyncError::SetAsyncMacError(OSErr error) -{ - if (error) { - fAsyncError = GUSIMapMacError(error); - GUSI_MESSAGE(("GUSISMAsyncError::SetAsyncMacError %d -> %d\n", error, fAsyncError)); - - return -1; - } - return 0; -} -// [[DoGetSockOpt]] only handles [[SO_ERROR]] (hi Philippe!). -// -// = -inline bool GUSISMAsyncError::DoGetSockOpt( - int * result, int level, int optname, - void *optval, socklen_t * optlen) -{ - if (level == SOL_SOCKET && optname == SO_ERROR) { - *(int *)optval = GetAsyncError(); - *optlen = sizeof(int); - - return (*result = 0), true; - } - return false; -} -// = -inline GUSISMProcess::GUSISMProcess() - : fProcess(GUSIProcess::Instance()) -{ -} - -inline GUSIProcess * GUSISMProcess::Process() -{ - return fProcess; -} - -#endif /* GUSI_INTERNAL */ - -#endif /* _GUSISocketMixins_ */ diff --git a/GUSI/include/GUSISpecific.h b/GUSI/include/GUSISpecific.h deleted file mode 100755 index 0797aa1..0000000 --- a/GUSI/include/GUSISpecific.h +++ /dev/null @@ -1,186 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSISpecific.nw - Thread specific variables -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:14 chombier -// % Initial import -// % -// % Revision 1.9 2000/10/16 04:11:21 neeri -// % Plug memory leak -// % -// % Revision 1.8 2000/03/15 07:22:07 neeri -// % Enforce alignment choices -// % -// % Revision 1.7 1999/08/26 05:45:10 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.6 1999/05/30 03:09:31 neeri -// % Added support for MPW compilers -// % -// % Revision 1.5 1999/04/29 04:58:20 neeri -// % Fix key destruction bug -// % -// % Revision 1.4 1999/03/17 09:05:13 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/10/11 16:45:25 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.2 1998/08/01 21:32:11 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:52 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Thread Specific Variables} -// -// It is often useful to have variables which maintain a different value -// for each process. The [[GUSISpecific]] class implements such a mechanism -// in a way that is easily mappable to pthreads. -// -// -// = -#ifndef _GUSISpecific_ -#define _GUSISpecific_ - -#ifndef GUSI_SOURCE - -typedef struct GUSISpecific GUSISpecific; - -#else - -#include -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of Thread Specific Variables} -// -// A [[GUSISpecific]] instance contains a variable ID and a per-process -// destructor. -// -// = -extern "C" { - typedef void (*GUSISpecificDestructor)(void *); -} - -class GUSISpecific { - friend class GUSISpecificTable; -public: - GUSISpecific(GUSISpecificDestructor destructor = nil); - ~GUSISpecific(); - - void Destruct(void * data); -private: - GUSISpecificDestructor fDestructor; - unsigned fID; - static unsigned sNextID; -}; -// A [[GUSIContext]] contains a [[GUSISpecificTable]] storing the values of all -// thread specific variables defined for this thread. -// -// = -class GUSISpecificTable { - friend class GUSISpecific; -public: - GUSISpecificTable(); - ~GUSISpecificTable(); - void * GetSpecific(const GUSISpecific * key) const; - void SetSpecific(const GUSISpecific * key, void * value); - void DeleteSpecific(const GUSISpecific * key); -private: - static void Register(GUSISpecific * key); - static void Destruct(GUSISpecific * key); - - // We store a [[GUSISpecificTable]] as a contiguous range of IDs. - // - // = - void *** fValues; - unsigned fAlloc; - - bool Valid(const GUSISpecific * key) const; - // All keys are registered in a global table. - // - // = - static GUSISpecific *** sKeys; - static unsigned sKeyAlloc; -}; -// To simplify having a particular variable assume a different instance in every -// thread, we define the [[GUSISpecificData]] template. -// -// = -template -class GUSISpecificData { -public: - GUSISpecificData() : fKey(D) { } - T & operator*() { return *get(); } - T * operator->() { return get(); } - - const GUSISpecific * Key() const { return &fKey; } - T * get(GUSISpecificTable * table); - T * get() { return get(GUSIContext::Current()); } -protected: - GUSISpecific fKey; -}; - -template - T * GUSISpecificData::get(GUSISpecificTable * table) -{ - void * data = table->GetSpecific(&fKey); - - if (!data) - table->SetSpecific(&fKey, data = new T); - - return static_cast(data); -} - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -// = -inline GUSISpecific::GUSISpecific(GUSISpecificDestructor destructor) - : fDestructor(destructor), fID(sNextID++) -{ - GUSISpecificTable::Register(this); -} - -inline GUSISpecific::~GUSISpecific() -{ - GUSISpecificTable::Destruct(this); -} - -inline void GUSISpecific::Destruct(void * data) -{ - if (fDestructor) - fDestructor(data); -} -// = -inline bool GUSISpecificTable::Valid(const GUSISpecific * key) const -{ - return key && key->fID < fAlloc; -} -// = -inline GUSISpecificTable::GUSISpecificTable() - : fValues(nil), fAlloc(0) -{ -} -// = -inline void * GUSISpecificTable::GetSpecific(const GUSISpecific * key) const -{ - if (Valid(key)) - return fValues[0][key->fID]; - else - return nil; -} - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSISpecific_ */ diff --git a/GUSI/include/GUSITimer.h b/GUSI/include/GUSITimer.h deleted file mode 100755 index 376e306..0000000 --- a/GUSI/include/GUSITimer.h +++ /dev/null @@ -1,192 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSITimer.nw - Timing functions -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:16 chombier -// % Initial import -// % -// % Revision 1.12 2001/01/17 08:48:04 neeri -// % Introduce Expired(), Reset() -// % -// % Revision 1.11 2000/10/29 18:36:32 neeri -// % Fix time_t signedness issues -// % -// % Revision 1.10 2000/06/12 04:24:50 neeri -// % Fix time, localtime, gmtime -// % -// % Revision 1.9 2000/05/23 07:24:58 neeri -// % Improve formatting -// % -// % Revision 1.8 2000/03/15 07:22:07 neeri -// % Enforce alignment choices -// % -// % Revision 1.7 1999/11/15 07:20:18 neeri -// % Safe context setup -// % -// % Revision 1.6 1999/08/26 05:45:10 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.5 1999/08/02 07:02:46 neeri -// % Support for asynchronous errors and other socket options -// % -// % Revision 1.4 1999/07/07 04:17:43 neeri -// % Final tweaks for 2.0b3 -// % -// % Revision 1.3 1999/06/28 06:08:46 neeri -// % Support flexible timer classes -// % -// % Revision 1.2 1999/05/30 03:06:21 neeri -// % Fixed various bugs in cleanup and wakeup -// % -// % Revision 1.1 1999/03/17 09:05:14 neeri -// % Added GUSITimer, expanded docs -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Timing functions} -// -// This section defines mechanisms to measure time. The basic mechanism is -// [[GUSITimer]] which can wake up a [[GUSIContext]] at some later time. -// -// = -#ifndef _GUSITimer_ -#define _GUSITimer_ - -#ifndef GUSI_SOURCE - -typedef struct GUSITimer GUSITimer; - -#else -#include "GUSISpecific.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=native -#endif - -// \section{Definition of timing} -// -// [[GUSITime]] is an universal (if somewhat costly) format for -// the large variety of timing formats used in MacOS and POSIX. -// -// = -class GUSITime { -public: - enum Format {seconds, ticks, msecs, usecs, nsecs}; - -#if !TYPE_LONGLONG - GUSITime(int32_t val, Format format); - GUSITime(uint32_t val, Format format); -#endif - GUSITime(int64_t val, Format format=nsecs) { Construct(val, format); } - GUSITime(const timeval & tv); - GUSITime(const timespec & ts); - GUSITime(const tm & t); - GUSITime() {} - - int32_t Get(Format format) { return S32Set(Get64(format)); } - uint32_t UGet(Format format) - { return U32SetU(SInt64ToUInt64(Get64(format))); } - int64_t Get64(Format format); - - operator int64_t() { return fTime; } - operator timeval(); - operator timespec(); - operator tm(); - - GUSITime GM2LocalTime(); - GUSITime Local2GMTime(); - - GUSITime & operator +=(const GUSITime & other) - { fTime = S64Add(fTime, other.fTime); return *this; } - GUSITime & operator -=(const GUSITime & other) - { fTime = S64Subtract(fTime, other.fTime); return *this; } - - - static GUSITime Now(); - static timezone & Zone(); -private: - void Construct(int64_t val, Format format); - time_t Deconstruct(int64_t & remainder); - - int64_t fTime; - - static int64_t sTimeOffset; - static timezone sTimeZone; -}; - -inline GUSITime operator+(const GUSITime & a, const GUSITime & b) - { GUSITime t(a); return t+=b; } -inline GUSITime operator-(const GUSITime & a, const GUSITime & b) - { GUSITime t(a); return t-=b; } -// A [[GUSITimer]] is a time manager task that wakes up a [[GUSIContext]]. -// -// = -#if PRAGMA_STRUCT_ALIGN -#pragma options align=mac68k -#endif -class GUSIContext; - -extern "C" void GUSIKillTimers(void * timers); - -class GUSITimer : public TMTask { -public: - GUSITimer(bool wakeup = true, GUSIContext * context = 0); - virtual ~GUSITimer(); - - void Sleep(long ms, bool driftFree = false); - void MicroSleep(long us, bool driftFree = false) - { Sleep(-us, driftFree); } - GUSIContext * Context() { return fQueue->fContext; } - GUSITimer * Next() { return fNext; } - bool Primed() { return (qType&kTMTaskActive) != 0; } - bool Expired() { return !(qType&kTMTaskActive); } - virtual void Wakeup(); - void Kill(); - void Reset(); - - struct Queue { - GUSITimer * fTimer; - GUSIContext * fContext; - - Queue() : fTimer(0) {} - }; - - QElem * Elem() { return reinterpret_cast(&this->qLink); } -protected: - Queue * fQueue; - GUSITimer * fNext; - - class TimerQueue : public GUSISpecificData { - public: - ~TimerQueue(); - }; - - static TimerQueue sTimerQueue; - static TimerUPP sTimerProc; -}; -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -#endif /* GUSI_SOURCE */ - -#endif /* _GUSITimer_ */ diff --git a/GUSI/include/arpa/inet.h b/GUSI/include/arpa/inet.h deleted file mode 100755 index 90bae70..0000000 --- a/GUSI/include/arpa/inet.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)inet.h 8.1 (Berkeley) 6/2/93 - */ - -#ifndef _INET_H_ -#define _INET_H_ - -/* Adapted for GUSI by Matthias Neeracher */ - -/* External definitions for functions in inet(3) */ - -#include - -/* XNS mandates availability of xtonx() and uintx_t -- neeri */ - -#include -#include - -__BEGIN_DECLS -in_addr_t inet_addr __P((const char *)); -int inet_aton __P((const char *, struct in_addr *)); -in_addr_t inet_lnaof __P((struct in_addr)); -struct in_addr inet_makeaddr __P((uint32_t , in_addr_t)); -in_addr_t inet_netof __P((struct in_addr)); -in_addr_t inet_network __P((const char *)); -char *inet_ntoa __P((struct in_addr)); -__END_DECLS - -#endif /* !_INET_H_ */ diff --git a/GUSI/include/compat.h b/GUSI/include/compat.h deleted file mode 100755 index b3da34c..0000000 --- a/GUSI/include/compat.h +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)compat.h 8.1 (Berkeley) 6/2/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _COMPAT_H_ -#define _COMPAT_H_ - -/* - * If your system doesn't specify a max size for a SIZE_T, check - * to make sure this is the right one. - */ -#ifndef SIZE_T_MAX -#define SIZE_T_MAX UINT_MAX -#endif - -#define index(a, b) strchr(a, b) -#define rindex(a, b) strrchr(a, b) -#define bzero(a, b) memset(a, 0, b) -#define bcmp(a, b, n) memcmp(a, b, n) -#define bcopy(a, b, n) memmove(b, a, n) - -/* POSIX 1003.2 RE limit. */ -#ifndef _POSIX2_RE_DUP_MAX -#define _POSIX2_RE_DUP_MAX 255 -#endif - -#ifndef MAX -#define MAX(_a,_b) ((_a)<(_b)?(_b):(_a)) -#endif -#ifndef MIN -#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) -#endif - -#endif /* !_COMPAT_H_ */ diff --git a/GUSI/include/dirent.h b/GUSI/include/dirent.h deleted file mode 100755 index 4dcbc7c..0000000 --- a/GUSI/include/dirent.h +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)dirent.h 8.1 (Berkeley) 6/8/93 - */ - -#ifndef _DIRENT_H_ -#define _DIRENT_H_ - -struct dirent { - ino_t d_ino; /* file number of entry */ - char d_name[255 + 1]; /* name must be no longer than this */ -}; - -typedef void * DIR; - -#include - -__BEGIN_DECLS -DIR *opendir __P((const char *)); -struct dirent *readdir __P((DIR *)); -void rewinddir __P((DIR *)); -int closedir __P((DIR *)); -long telldir __P((DIR *)); -void seekdir __P((DIR *, long)); -__END_DECLS - -#endif /* !_DIRENT_H_ */ diff --git a/GUSI/include/errno.h b/GUSI/include/errno.h deleted file mode 100755 index 9b60e3b..0000000 --- a/GUSI/include/errno.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Metrowerks Standard Library Version 2.4 1998 March 10 */ - -/* - * errno.h -*/ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _ERRNO_H -#define _ERRNO_H - -#ifdef __MWERKS__ -#include -#include -/* - * Undef error codes defined by MSL. We are overriding the MSL implementations, so - * these versions of the codes should never be generated anyway. - */ -#undef EEXIST -#undef ENOTEMPTY -#undef EISDIR -#undef EPERM -#undef EACCES -#undef EBADF -#undef EDEADLOCK -#undef EMFILE -#undef ENOENT -#undef ENFILE -#undef ENOSPC -#undef EINVAL -#undef EIO -#undef ENOMEM -#undef ENOSYS -#undef ENAMETOOLONG - -#if UNIVERSAL_INTERFACES_VERSION >= 0x0340 -#undef EDEADLK -#undef EAGAIN -#endif - -#else -#include -#endif - -#include - -#if defined(__cplusplus) && defined(_MSL_USING_NAMESPACE) && (__MSL__ < 0x5000) - using namespace std; -#endif - -#endif diff --git a/GUSI/include/fcntl.h b/GUSI/include/fcntl.h deleted file mode 100755 index bc5da0d..0000000 --- a/GUSI/include/fcntl.h +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * Copyright (c) 1983, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 - * - * Adapted for GUSI by Matthias Neeracher - */ - -#ifndef _FCNTL_H_ -#define _FCNTL_H_ - -/* - * This file includes the definitions for open and fcntl - * described by POSIX for ; it also includes - * related kernel definitions. - */ - -#include - -/* open-only flags */ -#define O_RDONLY 0x0001 /* open for reading only */ -#define O_WRONLY 0x0002 /* open for writing only */ -#define O_RDWR 0x0000 /* open for reading and writing */ -#define O_ACCMODE 0x0003 /* mask for above modes */ - -#define O_NONBLOCK 0x0004 /* no delay */ -#define O_APPEND 0x0008 /* set append mode */ -#define O_CREAT 0x0200 /* create if nonexistant */ -#define O_TRUNC 0x0400 /* truncate to zero length */ -#define O_EXCL 0x0800 /* error if already exists */ - -#ifndef _POSIX_SOURCE -/* Mac specific */ -#define O_ALIAS 0x2000 /* Open alias file (if the file is an alias) */ -#define O_RSRC 0x4000 /* Open the resource fork */ -#endif - -/* defined by POSIX 1003.1; BSD default, so no bit required */ -#define O_NOCTTY 0 /* don't assign controlling terminal */ - -#ifndef _POSIX_SOURCE -#define FNDELAY O_NONBLOCK /* compat */ -#endif - -/* - * Constants used for fcntl(2) - */ - -/* command values */ -#define F_DUPFD 0 /* duplicate file descriptor */ -#define F_GETFD 1 /* get file descriptor flags */ -#define F_SETFD 2 /* set file descriptor flags */ -#define F_GETFL 3 /* get file status flags */ -#define F_SETFL 4 /* set file status flags */ -#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ -#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ -#define F_GETLK 7 /* get record locking information */ -#define F_SETLK 8 /* set record locking information */ -#define F_SETLKW 9 /* F_SETLK; wait if blocked */ - -/* file descriptor flags (F_GETFD, F_SETFD) */ -#define FD_CLOEXEC 1 /* close-on-exec flag */ - -/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ -#define F_RDLCK 1 /* shared or read lock */ -#define F_UNLCK 2 /* unlock */ -#define F_WRLCK 3 /* exclusive or write lock */ - -/* - * Advisory file segment locking data type - - * information passed to system by user - */ -struct flock { - off_t l_start; /* starting offset */ - off_t l_len; /* len = 0 means until end of file */ - pid_t l_pid; /* lock owner */ - short l_type; /* lock type: read/write, etc. */ - short l_whence; /* type of l_start */ -}; - -#include -#include - -__BEGIN_DECLS -int open __P((const char *, int, ...)); -int creat __P((const char *, ...)); -int fcntl __P((int, int, ...)); - -/* This properly belongs into stdio.h, but that header is outside of - GUSI's control -*/ -#if defined(__MWERKS__) && __MWERKS__ < 0x2401 && !defined(_SFSTDIO_H) -FILE * fdopen(int fildes, char *type); -#else -FILE * fdopen(int fildes, const char *type); -#endif -__END_DECLS - -#endif /* !_FCNTL_H_ */ - diff --git a/GUSI/include/inttypes.h b/GUSI/include/inttypes.h deleted file mode 100755 index 1d6fa3f..0000000 --- a/GUSI/include/inttypes.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Written for GUSI by Matthias Neeracher */ - -#ifndef _INTTYPES_H_ -#define _INTTYPES_H_ - -/* - * Regrettably, this is needed for *int64_t - */ -#include -#include - -#if __MSL__ < 0x7001 -#if __MSL__ < 0x6000 -typedef char int8_t; -#else -typedef signed char int8_t; -#endif -typedef short int16_t; -typedef long int32_t; -typedef SInt64 int64_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; -typedef UInt64 uint64_t; -typedef long intptr_t; -typedef unsigned long uintptr_t; -#else -#include -#endif - -#endif /* _INTTYPES_H_ */ diff --git a/GUSI/include/machine/ansi.h b/GUSI/include/machine/ansi.h deleted file mode 100755 index d129481..0000000 --- a/GUSI/include/machine/ansi.h +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ansi.h 8.2 (Berkeley) 1/4/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _ANSI_H_ -#define _ANSI_H_ - -/* - * Types which are fundamental to the implementation and may appear in - * more than one standard header are defined here. Standard headers - * then use: - * #ifdef _BSD_SIZE_T_ - * typedef _BSD_SIZE_T_ size_t; - * #undef _BSD_SIZE_T_ - * #endif - */ -#define _BSD_CLOCK_T_ unsigned long /* clock() */ -#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */ -#define _BSD_SIZE_T_ unsigned long /* sizeof() */ -#define _BSD_SSIZE_T_ long /* byte count or error */ -#define _BSD_TIME_T_ unsigned long /* time() */ -#define _BSD_VA_LIST_ char * /* va_list */ - -/* - * Runes (wchar_t) is declared to be an ``int'' instead of the more natural - * ``unsigned long'' or ``long''. Two things are happening here. It is not - * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, - * it looks like 10646 will be a 31 bit standard. This means that if your - * ints cannot hold 32 bits, you will be in trouble. The reason an int was - * chosen over a long is that the is*() and to*() routines take ints (says - * ANSI C), but they use _RUNE_T_ instead of int. By changing it here, you - * lose a bit of ANSI conformance, but your programs will still work. - * - * Note that _WCHAR_T_ and _RUNE_T_ must be of the same type. When wchar_t - * and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains - * defined for ctype.h. - */ -#define _BSD_WCHAR_T_ int /* wchar_t */ -#define _BSD_RUNE_T_ int /* rune_t */ - -#endif /* _ANSI_H_ */ diff --git a/GUSI/include/machine/endian.h b/GUSI/include/machine/endian.h deleted file mode 100755 index da06027..0000000 --- a/GUSI/include/machine/endian.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 1987, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 8.1 (Berkeley) 6/10/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _ENDIAN_H_ -#define _ENDIAN_H_ - -/* xtonx() now defined in terms of inttypes -- neeri */ - -#include - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ - -#define BYTE_ORDER BIG_ENDIAN - -#include - -__BEGIN_DECLS -uint32_t htonl __P((uint32_t)); -uint16_t htons __P((uint16_t)); -uint32_t ntohl __P((uint32_t)); -uint16_t ntohs __P((uint16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. - */ -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) - -#define NTOHL(x) (x) -#define NTOHS(x) (x) -#define HTONL(x) (x) -#define HTONS(x) (x) - -#endif /* !_POSIX_SOURCE */ -#endif /* !_ENDIAN_H_ */ diff --git a/GUSI/include/machine/signal.h b/GUSI/include/machine/signal.h deleted file mode 100755 index da0db49..0000000 --- a/GUSI/include/machine/signal.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 1986, 1989, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)signal.h 8.1 (Berkeley) 6/10/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -/* - * Machine-dependent signal definitions - */ - -typedef int sig_atomic_t; diff --git a/GUSI/include/net/if.h b/GUSI/include/net/if.h deleted file mode 100755 index 6679196..0000000 --- a/GUSI/include/net/if.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)if.h 8.1 (Berkeley) 6/10/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -/* - * Structures defining a network interface, providing a packet - * transport mechanism (ala level 0 of the PUP protocols). - * - * Each interface accepts output datagrams of a specified maximum - * length, and provides higher level routines with input datagrams - * received from its medium. - * - * Output occurs when the routine if_output is called, with three parameters: - * (*ifp->if_output)(ifp, m, dst, rt) - * Here m is the mbuf chain to be sent and dst is the destination address. - * The output routine encapsulates the supplied datagram if necessary, - * and then transmits it on its medium. - * - * On input, each interface unwraps the data received by it, and either - * places it on the input queue of a internetwork datagram routine - * and posts the associated software interrupt, or passes the datagram to a raw - * packet input routine. - * - * Routines exist for locating interfaces by their addresses - * or for locating a interface on a certain network, as well as more general - * routing and gateway routines maintaining information used to locate - * interfaces. These routines live in the files if.c and route.c - */ - -#define IFF_UP 0x1 /* interface is up */ -#define IFF_BROADCAST 0x2 /* broadcast address valid */ -#define IFF_DEBUG 0x4 /* turn on debugging */ -#define IFF_LOOPBACK 0x8 /* is a loopback net */ -#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ -#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ -#define IFF_RUNNING 0x40 /* resources allocated */ -#define IFF_NOARP 0x80 /* no address resolution protocol */ -#define IFF_PROMISC 0x100 /* receive all packets */ -#define IFF_ALLMULTI 0x200 /* receive all multicast packets */ -#define IFF_OACTIVE 0x400 /* transmission in progress */ -#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ -#define IFF_LINK0 0x1000 /* per link layer defined bit */ -#define IFF_LINK1 0x2000 /* per link layer defined bit */ -#define IFF_LINK2 0x4000 /* per link layer defined bit */ -#define IFF_MULTICAST 0x8000 /* supports multicast */ - -/* flags set internally only: */ -#define IFF_CANTCHANGE \ - (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ - IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI) - -/* - * Interface request structure used for socket - * ioctl's. All interface ioctl's must have parameter - * definitions which begin with ifr_name. The - * remainder may be interface specific. - */ -struct ifreq { -#define IFNAMSIZ 16 - char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ - union { - struct sockaddr ifru_addr; - struct sockaddr ifru_dstaddr; - struct sockaddr ifru_broadaddr; - short ifru_flags; - int ifru_metric; - caddr_t ifru_data; - } ifr_ifru; -#define ifr_addr ifr_ifru.ifru_addr /* address */ -#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ -#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ -#define ifr_flags ifr_ifru.ifru_flags /* flags */ -#define ifr_metric ifr_ifru.ifru_metric /* metric */ -#define ifr_data ifr_ifru.ifru_data /* for use by interface */ -}; - -struct ifaliasreq { - char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ - struct sockaddr ifra_addr; - struct sockaddr ifra_broadaddr; - struct sockaddr ifra_mask; -}; - -/* - * Structure used in SIOCGIFCONF request. - * Used to retrieve interface configuration - * for machine (useful for programs which - * must know all networks accessible). - */ -struct ifconf { - int ifc_len; /* size of associated buffer */ - union { - caddr_t ifcu_buf; - struct ifreq *ifcu_req; - } ifc_ifcu; -#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ -#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ -}; - diff --git a/GUSI/include/netdb.h b/GUSI/include/netdb.h deleted file mode 100755 index c748cbd..0000000 --- a/GUSI/include/netdb.h +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 1980, 1983, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)netdb.h 8.1 (Berkeley) 6/2/93 - * $Id$ - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _NETDB_H_ -#define _NETDB_H_ - -#define _PATH_HEQUIV "/etc/hosts.equiv" -#define _PATH_HOSTS "/etc/hosts" -#define _PATH_NETWORKS "/etc/networks" -#define _PATH_PROTOCOLS "/etc/protocols" -#define _PATH_SERVICES "/etc/services" - -/* - * Structures returned by network data base library. All addresses are - * supplied in host order, and returned in network order (suitable for - * use in system calls). - */ -struct hostent { - char *h_name; /* official name of host */ - char **h_aliases; /* alias list */ - int h_addrtype; /* host address type */ - int h_length; /* length of address */ - char **h_addr_list; /* list of addresses from name server */ -#define h_addr h_addr_list[0] /* address, for backward compatiblity */ -}; - -struct servent { - char *s_name; /* official service name */ - char **s_aliases; /* alias list */ - int s_port; /* port # */ - char *s_proto; /* protocol to use */ -}; - -struct protoent { - char *p_name; /* official protocol name */ - char **p_aliases; /* alias list */ - int p_proto; /* protocol # */ -}; - -/* - * Error return codes from gethostbyname() and gethostbyaddr() - * (left in h_errno). - */ - -extern int h_errno; - -#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ -#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ -#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ -#define NO_DATA 4 /* Valid name, no data record of requested type */ -#define NO_ADDRESS NO_DATA /* no address, look for MX record */ - -#include - -__BEGIN_DECLS -void endhostent __P((void)); -void endprotoent __P((void)); -void endservent __P((void)); -struct hostent *gethostbyaddr __P((const void *, size_t, int)); -struct hostent *gethostbyname __P((const char *)); -struct hostent *gethostent __P((void)); -struct protoent *getprotobyname __P((const char *)); -struct protoent *getprotobynumber __P((int)); -struct protoent *getprotoent __P((void)); -struct servent *getservbyname __P((const char *, const char *)); -struct servent *getservbyport __P((int, const char *)); -struct servent *getservent __P((void)); -void herror __P((const char *)); -char *hstrerror __P((int)); -void setprotoent __P((int)); -void setservent __P((int)); -__END_DECLS - -#endif /* !_NETDB_H_ */ diff --git a/GUSI/include/netinet/in.h b/GUSI/include/netinet/in.h deleted file mode 100755 index e67251e..0000000 --- a/GUSI/include/netinet/in.h +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)in.h 8.3 (Berkeley) 1/3/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _NETINET_IN_H_ -#define _NETINET_IN_H_ - -/* xtonx() mandated available by XNS -- neeri */ -#include - -/* - * Constants and structures defined by the internet system, - * Per RFC 790, September 1981, and numerous additions. - */ - -/* - * Protocols - */ -#define IPPROTO_IP 0 /* dummy for IP */ -#define IPPROTO_ICMP 1 /* control message protocol */ -#define IPPROTO_IGMP 2 /* group mgmt protocol */ -#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ -#define IPPROTO_TCP 6 /* tcp */ -#define IPPROTO_EGP 8 /* exterior gateway protocol */ -#define IPPROTO_PUP 12 /* pup */ -#define IPPROTO_UDP 17 /* user datagram protocol */ -#define IPPROTO_IDP 22 /* xns idp */ -#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ -#define IPPROTO_EON 80 /* ISO cnlp */ -#define IPPROTO_ENCAP 98 /* encapsulation header */ - -#define IPPROTO_RAW 255 /* raw IP packet */ -#define IPPROTO_MAX 256 - - -/* - * Local port number conventions: - * Ports < IPPORT_RESERVED are reserved for - * privileged processes (e.g. root). - * Ports > IPPORT_USERRESERVED are reserved - * for servers, not necessarily privileged. - */ -#define IPPORT_RESERVED 1024 -#define IPPORT_USERRESERVED 5000 - -/* Types mandated by XNS -- neeri */ -typedef uint16_t in_port_t; -typedef uint32_t in_addr_t; - -/* - * Internet address (a structure for historical reasons) - */ -struct in_addr { - in_addr_t s_addr; -}; - -/* - * Definitions of bits in internet address integers. - * On subnets, the decomposition of addresses to host and net parts - * is done according to subnet mask, not the masks here. - */ -#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) -#define IN_CLASSA_NET 0xff000000 -#define IN_CLASSA_NSHIFT 24 -#define IN_CLASSA_HOST 0x00ffffff -#define IN_CLASSA_MAX 128 - -#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) -#define IN_CLASSB_NET 0xffff0000 -#define IN_CLASSB_NSHIFT 16 -#define IN_CLASSB_HOST 0x0000ffff -#define IN_CLASSB_MAX 65536 - -#define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) -#define IN_CLASSC_NET 0xffffff00 -#define IN_CLASSC_NSHIFT 8 -#define IN_CLASSC_HOST 0x000000ff - -#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) -#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ -#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ -#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ -#define IN_MULTICAST(i) IN_CLASSD(i) - -#define IN_EXPERIMENTAL(i) (((long)(i) & 0xf0000000) == 0xf0000000) -#define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) - -#define INADDR_ANY (u_long)0x00000000 -#define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ -#define INADDR_NONE 0xffffffff /* -1 return */ - -#define INADDR_UNSPEC_GROUP (u_long)0xe0000000 /* 224.0.0.0 */ -#define INADDR_ALLHOSTS_GROUP (u_long)0xe0000001 /* 224.0.0.1 */ -#define INADDR_MAX_LOCAL_GROUP (u_long)0xe00000ff /* 224.0.0.255 */ - -#define IN_LOOPBACKNET 127 /* official! */ - -/* Mandated by XNS -- neeri */ -#ifndef _SA_FAMILY_T_DEFINED -#define _SA_FAMILY_T_DEFINED -typedef uint16_t sa_family_t; -#endif - -/* - * Socket address, internet style. - */ -struct sockaddr_in { - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - unsigned char sin_zero[8]; -}; - -/* - * Structure used to describe IP options. - * Used to store options internally, to pass them to a process, - * or to restore options retrieved earlier. - * The ip_dst is used for the first-hop gateway when using a source route - * (this gets put into the header proper). - */ -typedef struct { - struct in_addr ip_dst; /* first hop, 0 w/o src rt */ - char ip_opts[40]; /* actually variable in size */ -} ip_opts; - -/* - * Options for use with [gs]etsockopt at the IP level. - * First word of comment is data type; bool is stored in int. - */ -#define IP_OPTIONS 0x01 -#define IP_TOS 0x02 -#define IP_TTL 0x03 -#define IP_REUSEADDR 0x04 -#define IP_DONTROUTE 0x10 -#define IP_BROADCAST 0x20 -#define IP_HDRINCL 0x1002 -#define IP_RCVOPTS 0x1005 -#define IP_RCVDSTADDR 0x1007 -#define IP_MULTICAST_IF 0x1010 /* set/get IP multicast interface */ -#define IP_MULTICAST_TTL 0x1011 /* set/get IP multicast timetolive */ -#define IP_MULTICAST_LOOP 0x1012 /* set/get IP multicast loopback */ -#define IP_ADD_MEMBERSHIP 0x1013 /* add an IP group membership */ -#define IP_DROP_MEMBERSHIP 0x1014 /* drop an IP group membership */ -#define IP_BROADCAST_IF 0x1015 /* Set interface for broadcasts */ -#define IP_RCVIFADDR 0x1016 /* Set interface for broadcasts */ - - -/* - * Defaults and limits for options - */ -#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ -#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ -#define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */ - -/* - * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. - */ -struct ip_mreq { - struct in_addr imr_multiaddr; /* IP multicast address of group */ - struct in_addr imr_interface; /* local IP address of interface */ -}; - -/* - * Definitions for inet sysctl operations. - * - * Third level is protocol number. - * Fourth level is desired variable within that protocol. - */ -#define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */ - -#define CTL_IPPROTO_NAMES { \ - { "ip", CTLTYPE_NODE }, \ - { "icmp", CTLTYPE_NODE }, \ - { "igmp", CTLTYPE_NODE }, \ - { "ggp", CTLTYPE_NODE }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { "tcp", CTLTYPE_NODE }, \ - { 0, 0 }, \ - { "egp", CTLTYPE_NODE }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { "pup", CTLTYPE_NODE }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { "udp", CTLTYPE_NODE }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { "idp", CTLTYPE_NODE }, \ -} - -/* - * Names for IP sysctl objects - */ -#define IPCTL_FORWARDING 1 /* act as router */ -#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ -#define IPCTL_DEFTTL 3 /* default TTL */ -#ifdef notyet -#define IPCTL_DEFMTU 4 /* default MTU */ -#endif -#define IPCTL_MAXID 5 - -#define IPCTL_NAMES { \ - { 0, 0 }, \ - { "forwarding", CTLTYPE_INT }, \ - { "redirect", CTLTYPE_INT }, \ - { "ttl", CTLTYPE_INT }, \ - { "mtu", CTLTYPE_INT }, \ -} - -#endif /* _NETINET_IN_H_ */ - diff --git a/GUSI/include/netinet/tcp.h b/GUSI/include/netinet/tcp.h deleted file mode 100755 index e517024..0000000 --- a/GUSI/include/netinet/tcp.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp.h 8.1 (Berkeley) 6/10/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -typedef u_long tcp_seq; -/* - * TCP header. - * Per RFC 793, September, 1981. - */ -struct tcphdr { - u_short th_sport; /* source port */ - u_short th_dport; /* destination port */ - tcp_seq th_seq; /* sequence number */ - tcp_seq th_ack; /* acknowledgement number */ - u_char th_off:4, /* data offset */ - th_x2:4; /* (unused) */ - u_char th_flags; -#define TH_FIN 0x01 -#define TH_SYN 0x02 -#define TH_RST 0x04 -#define TH_PUSH 0x08 -#define TH_ACK 0x10 -#define TH_URG 0x20 - u_short th_win; /* window */ - u_short th_sum; /* checksum */ - u_short th_urp; /* urgent pointer */ -}; - -#define TCPOPT_EOL 0 -#define TCPOPT_NOP 1 -#define TCPOPT_MAXSEG 2 -#define TCPOLEN_MAXSEG 4 -#define TCPOPT_WINDOW 3 -#define TCPOLEN_WINDOW 3 -#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ -#define TCPOLEN_SACK_PERMITTED 2 -#define TCPOPT_SACK 5 /* Experimental */ -#define TCPOPT_TIMESTAMP 8 -#define TCPOLEN_TIMESTAMP 10 -#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ - -#define TCPOPT_TSTAMP_HDR \ - (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) - -/* - * Default maximum segment size for TCP. - * With an IP MSS of 576, this is 536, - * but 512 is probably more convenient. - * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)). - */ -#define TCP_MSS 512 - -#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ - -#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ - -/* - * User-settable options (used with setsockopt). - */ -#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ -#define TCP_MAXSEG 0x02 /* set maximum segment size */ -#define TCP_KEEPALIVE 0x08 /* seconds between keepalive packets */ diff --git a/GUSI/include/pthread.h b/GUSI/include/pthread.h deleted file mode 100755 index 54008e6..0000000 --- a/GUSI/include/pthread.h +++ /dev/null @@ -1,299 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIPThread.nw - Pthreads wrappers -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:16 chombier -// % Initial import -// % -// % Revision 1.14 2001/01/17 08:55:16 neeri -// % Detect and return ETIMEDOUT condition -// % -// % Revision 1.13 2000/10/29 20:31:53 neeri -// % Releasing 2.1.3 -// % -// % Revision 1.12 2000/05/23 07:16:35 neeri -// % Improve formatting, make data types opaque, tune mutexes -// % -// % Revision 1.11 2000/03/06 06:10:00 neeri -// % Reorganize Yield() -// % -// % Revision 1.10 2000/01/17 01:40:31 neeri -// % Correct macro spelling, update references -// % -// % Revision 1.9 1999/11/15 07:20:19 neeri -// % Safe context setup -// % -// % Revision 1.8 1999/09/09 07:22:15 neeri -// % Add support for mutex and cond attribute creation/destruction -// % -// % Revision 1.7 1999/08/26 05:45:07 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.6 1999/07/07 04:17:42 neeri -// % Final tweaks for 2.0b3 -// % -// % Revision 1.5 1999/06/30 07:42:07 neeri -// % Getting ready to release 2.0b3 -// % -// % Revision 1.4 1999/05/30 03:06:55 neeri -// % MPW compiler compatibility, recursive mutex locks -// % -// % Revision 1.3 1999/03/17 09:05:12 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/08/01 21:32:10 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:51 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{Pthreads Wrappers} -// -// As opposed to POSIX.1, with which I think I'm reasonable competent by now, -// I have little practical experience, let alone in-depth familiarity with -// Pthreads, so I'm going by what I learned from -// -// \begin{itemize} -// \item Reading \emph{B.~Nicols, D.~Buttlar, and J.~Proulx Farrell, -// ``Pthreads Programming'', O'Reilly \& Associates} and -// \emph{D.~Butenhof, ``Programming with POSIX Threads'', Addison Wesley}. -// -// \item Taking a few glimpses at Chris Provenzano's pthreads implementation. -// \item Reading the news:comp.programming.threads newsgroup. -// \end{itemize} -// -// If you believe that I've misunderstood Pthreads in my implementation, feel free -// to contact me. -// -// As opposed to most other modules, the header files we're generating here don't -// have GUSI in its name. -// -// = -#ifndef _PTHREAD_H_ -#define _PTHREAD_H_ - -#include -#include -#include - -__BEGIN_DECLS -// \section{Definition of Pthread data types} -// -// I used to be fairly cavalier about exposing internal GUSI data structures, -// on second thought this was not a good idea. To keep C happy, we define -// [[struct]] wrappers for what ultimately will mostly be classes. -// -// = -typedef struct GUSIPThread * pthread_t; -// A [[pthread_attr_t]] collects thread creation attributes. This is implemented -// as a pointer so it's easier to change the size of the underlying data structure. -// -// = -typedef struct GUSIPThreadAttr * pthread_attr_t; -// A [[pthread_key_t]] is a key to look up thread specific data. -// -// = -typedef struct GUSIPThreadKey * pthread_key_t; -// A [[pthread_once_t]] registers whether some routine has run once. It must always -// be statically initialized to [[PTHREAD_ONCE_INIT]] (Although in our implementation, -// it doesn't matter). -// -// = -typedef char pthread_once_t; - -enum { - PTHREAD_ONCE_INIT = 0 -}; -// A [[pthread_mutex_t]] is a mutual exclusion variable, implemented as a pointer -// to a [[GUSIContextQueue]]. For initialization convenience, a 0 value means -// an unlocked mutex. No attributes are supported so far. -// -// = -typedef struct GUSIPThreadMutex * pthread_mutex_t; -typedef void * pthread_mutexattr_t; - -#define PTHREAD_MUTEX_INITIALIZER 0 -// A [[pthread_cond_t]] is a condition variable, which looks rather similar -// to a mutex, but has different semantics. No attributes are supported so far. -// -// = -typedef struct GUSIPThreadCond * pthread_cond_t; -typedef void * pthread_condattr_t; - -#define PTHREAD_COND_INITIALIZER 0 -// [[pthread_attr_init]] initializes an attribute object with the -// default values. -// -// = -int pthread_attr_init(pthread_attr_t * attr); -// [[pthread_attr_destroy]] destroys an attribute object. -// -// = -int pthread_attr_destroy(pthread_attr_t * attr); -// The detach state defines whether a thread will be defined joinable or -// detached. -// -// = -enum { - PTHREAD_CREATE_JOINABLE, - PTHREAD_CREATE_DETACHED -}; - -int pthread_attr_getdetachstate(const pthread_attr_t * attr, int * state); -int pthread_attr_setdetachstate(pthread_attr_t * attr, int state); -// The stack size defines how much stack space will be allocated. Stack overflows -// typically lead to utterly nasty crashes. -// -// = -int pthread_attr_getstacksize(const pthread_attr_t * attr, size_t * size); -int pthread_attr_setstacksize(pthread_attr_t * attr, size_t size); -// \section{Creation and Destruction of PThreads} -// -// First, we define wrapper to map the different calling conventions of Pthreads -// and Macintosh threads. -// -// = -__BEGIN_DECLS -typedef void * (*GUSIPThreadProc)(void *); -__END_DECLS -// [[pthread_create]] stuffs the arguments in a [[CreateArg]] and creates the -// context. -// -// = -int pthread_create( - pthread_t * thread, - const pthread_attr_t * attr, GUSIPThreadProc proc, void * arg); -// A thread can either be detached, in which case it will just go away after it's -// done, or it can be joinable, in which case it will wait for [[pthread_join]] -// to be called. -// -// = -int pthread_detach(pthread_t thread); -// [[pthread_join]] waits for the thread to die and optionally returns its last -// words. -// -// = -int pthread_join(pthread_t thread, void **value); -// [[pthread_exit]] ends the existence of a thread. -// -// = -int pthread_exit(void *value); -// \section{Pthread thread specific data} -// -// Thread specific data offers a possibility to quickly look up a value that may be -// different for every thread. -// -// [[pthread_key_create]] creates an unique key visible to all threads in a -// process. -// -// = -__BEGIN_DECLS -typedef void (*GUSIPThreadKeyDestructor)(void *); -__END_DECLS - -int pthread_key_create(pthread_key_t * key, GUSIPThreadKeyDestructor destructor); -// [[pthread_key_delete]] deletes a key, but does not call any destructors. -// -// = -int pthread_key_delete(pthread_key_t key); -// [[pthread_getspecific]] returns the thread specific value for a key. -// -// = -void * pthread_getspecific(pthread_key_t key); -// [[pthread_setspecific]] sets a new thread specific value for a key. -// -// = -int pthread_setspecific(pthread_key_t key, void * value); -// \section{Synchronization mechanisms of PThreads} -// -// Since we're only dealing with cooperative threads, all synchronization -// mechanisms can be implemented using means that might look naive to a student -// of computer science, but that actually work perfectly well in our case. -// -// We currently don't support mutex and condition variable attributes. To minimize -// the amount of code changes necessary inclients, we support creating and destroying -// them, at least. -// -// = -int pthread_mutexattr_init(pthread_mutexattr_t * attr); -int pthread_mutexattr_destroy(pthread_mutexattr_t * attr); -// = -int pthread_mutex_init(pthread_mutex_t * mutex, const pthread_mutexattr_t *); -int pthread_mutex_destroy(pthread_mutex_t * mutex); -// Lock may create the queue if it was allocated statically. Mutexes are implemented -// as a queue of context, with the frontmost context holding the lock. Simple enough, -// isn't it? -// -// = -int pthread_mutex_lock(pthread_mutex_t * mutex); -// Strangely enough, [[pthread_mutex_trylock]] is much more of a problem if we want -// to maintain a semblance of scheduling fairness. In particular, we need the [[Yield]] -// in case somebody checks a mutex in a loop with no other yield point. -// -// = -int pthread_mutex_trylock(pthread_mutex_t * mutex); -// Unlocking pops us off the queue and wakes up the new lock owner. -// -// = -int pthread_mutex_unlock(pthread_mutex_t * mutex); -// On to condition variable attributes, which we don't really support either. -// -// = -int pthread_condattr_init(pthread_condattr_t * attr); -int pthread_condattr_destroy(pthread_condattr_t * attr); -// Condition variables in some respects work very similar to mutexes. -// -// = -int pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t *); -int pthread_cond_destroy(pthread_cond_t * cond); -// [[pthread_cond_wait]] releases the mutex, sleeps on the condition variable, -// and reacquires the mutex. -// -// = -int pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex); -// [[pthread_cond_timedwait]] adds a timeout value (But it still could block -// indefinitely trying to reacquire the mutex). Note that the timeout specifies -// an absolute wakeup time, not an interval. -// -// = -int pthread_cond_timedwait( - pthread_cond_t * cond, pthread_mutex_t * mutex, - const struct timespec * patience); -// [[pthread_cond_signal]] wakes up a context from the queue. Since we typically -// still hold the associated mutex, it would be a bad idea (though not a disastrous -// one) to put a yield in here. -// -// = -int pthread_cond_signal(pthread_cond_t * cond); -// [[pthread_cond_broadcast]] wakes up a the entire queue (but only one context -// will get the mutex). -// -// = -int pthread_cond_broadcast(pthread_cond_t * cond); -// \section{Pthread varia} -// -// [[pthread_self]] returns the current thread. -// -// = -pthread_t pthread_self(void); -// [[pthread_equal]] compares two thread handles. -// -// = -int pthread_equal(pthread_t t1, pthread_t t2); -// [[pthread_once]] calls a routines, guaranteeing that it will be called exactly -// once per process. -// -// = -__BEGIN_DECLS -typedef void (*GUSIPThreadOnceProc)(void); -__END_DECLS - -int pthread_once(pthread_once_t * once_block, GUSIPThreadOnceProc proc); -__END_DECLS - -#endif /* _PTHREAD_H_ */ diff --git a/GUSI/include/sched.h b/GUSI/include/sched.h deleted file mode 100755 index 5b69c1c..0000000 --- a/GUSI/include/sched.h +++ /dev/null @@ -1,16 +0,0 @@ -// = -#ifndef _SCHED_H_ -#define _SCHED_H_ - -#include -/* Required by UNIX 98 */ -#include - -__BEGIN_DECLS -// [[sched_yield]] yields the processor for other runnable threads. -// -// = -int sched_yield(); -__END_DECLS - -#endif /* _SCHED_H_ */ diff --git a/GUSI/include/signal.h b/GUSI/include/signal.h deleted file mode 100755 index 15d40ea..0000000 --- a/GUSI/include/signal.h +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)signal.h 8.3 (Berkeley) 3/30/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _USER_SIGNAL_H -#define _USER_SIGNAL_H - -#include -#include -#include -#include - -#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) -extern const char *const sys_signame[NSIG]; -#endif - -__BEGIN_DECLS -int raise __P((int)); -#ifndef _ANSI_SOURCE -int kill __P((pid_t, int)); -int sigaction __P((int, const struct sigaction *, struct sigaction *)); -int sigaddset __P((sigset_t *, int)); -int sigdelset __P((sigset_t *, int)); -int sigemptyset __P((sigset_t *)); -int sigfillset __P((sigset_t *)); -int sigismember __P((const sigset_t *, int)); -int sigpending __P((sigset_t *)); -int sigprocmask __P((int, const sigset_t *, sigset_t *)); -int sigsuspend __P((const sigset_t *)); -int pthread_kill __P((pthread_t, int)); -int pthread_sigmask __P((int, const sigset_t *, sigset_t *)); -int sigwait __P((const sigset_t *, int *)); -#endif /* !_ANSI_SOURCE */ -__END_DECLS - -/* List definitions after function declarations, or Reiser cpp gets upset. */ -#define sigaddset(set, signo) (*(set) |= 1 << ((signo) - 1), 0) -#define sigdelset(set, signo) (*(set) &= ~(1 << ((signo) - 1)), 0) -#define sigemptyset(set) (*(set) = 0, 0) -#define sigfillset(set) (*(set) = ~(sigset_t)0, 0) -#define sigismember(set, signo) ((*(set) & (1 << ((signo) - 1))) != 0) - -#endif /* !_USER_SIGNAL_H */ diff --git a/GUSI/include/sys/cdefs.h b/GUSI/include/sys/cdefs.h deleted file mode 100755 index 309dc07..0000000 --- a/GUSI/include/sys/cdefs.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Berkeley Software Design, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)cdefs.h 8.7 (Berkeley) 1/21/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _CDEFS_H_ -#define _CDEFS_H_ - -#if defined(__cplusplus) -#define __BEGIN_DECLS extern "C" { -#define __END_DECLS } -#else -#define __BEGIN_DECLS -#define __END_DECLS -#endif - -#define __P(x) x - -#endif /* !_CDEFS_H_ */ diff --git a/GUSI/include/sys/errno.h b/GUSI/include/sys/errno.h deleted file mode 100755 index f0b689a..0000000 --- a/GUSI/include/sys/errno.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)errno.h 8.5 (Berkeley) 1/21/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#define EPERM 1 /* Operation not permitted */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* Input/output error */ -#define ENXIO 6 /* Device not configured */ -#define E2BIG 7 /* Argument list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file descriptor */ -#define ECHILD 10 /* No child processes */ -#define EDEADLK 11 /* Resource deadlock avoided */ - /* 11 was EAGAIN */ -#define ENOMEM 12 /* Cannot allocate memory */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ECANCELED 15 /* Operation cancelled */ -#define EBUSY 16 /* Device busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* Operation not supported by device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* Too many open files in system */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Inappropriate ioctl for device */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ - -/* math software */ -#define EDOM 33 /* Numerical argument out of domain */ -#define ERANGE 34 /* Result too large */ - -/* non-blocking and interrupt i/o */ -#define EAGAIN 35 /* Resource temporarily unavailable */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#define EINPROGRESS 36 /* Operation now in progress */ -#define EALREADY 37 /* Operation already in progress */ - -/* ipc/network software -- argument errors */ -#define ENOTSOCK 38 /* Socket operation on non-socket */ -#define EDESTADDRREQ 39 /* Destination address required */ -#define EMSGSIZE 40 /* Message too long */ -#define EPROTOTYPE 41 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 42 /* Protocol not available */ -#define EPROTONOSUPPORT 43 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ -#define EOPNOTSUPP 45 /* Operation not supported */ -#define EPFNOSUPPORT 46 /* Protocol family not supported */ -#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ -#define EADDRINUSE 48 /* Address already in use */ -#define EADDRNOTAVAIL 49 /* Can't assign requested address */ - -/* ipc/network software -- operational errors */ -#define ENETDOWN 50 /* Network is down */ -#define ENETUNREACH 51 /* Network is unreachable */ -#define ENETRESET 52 /* Network dropped connection on reset */ -#define ECONNABORTED 53 /* Software caused connection abort */ -#define ECONNRESET 54 /* Connection reset by peer */ -#define ENOBUFS 55 /* No buffer space available */ -#define EISCONN 56 /* Socket is already connected */ -#define ENOTCONN 57 /* Socket is not connected */ -#define ESHUTDOWN 58 /* Can't send after socket shutdown */ -#define ETOOMANYREFS 59 /* Too many references: can't splice */ -#define ETIMEDOUT 60 /* Operation timed out */ -#define ECONNREFUSED 61 /* Connection refused */ - -#define ELOOP 62 /* Too many levels of symbolic links */ -#define ENAMETOOLONG 63 /* File name too long */ - -/* should be rearranged */ -#define EHOSTDOWN 64 /* Host is down */ -#define EHOSTUNREACH 65 /* No route to host */ -#define ENOTEMPTY 66 /* Directory not empty */ - -#define ENOLCK 77 /* No locks available */ -#define ENOSYS 78 /* Function not implemented */ - -#ifndef _POSIX_SOURCE -#define ELOOK 67 /* Internal mapping for kOTLookErr, don't return to client */ -#define ELAST 78 /* Must be equal largest errno */ -#endif /* _POSIX_SOURCE */ diff --git a/GUSI/include/sys/filio.h b/GUSI/include/sys/filio.h deleted file mode 100755 index 7100542..0000000 --- a/GUSI/include/sys/filio.h +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)filio.h 8.1 (Berkeley) 3/28/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_FILIO_H_ -#define _SYS_FILIO_H_ - -#include - -/* Generic file-descriptor ioctl's. */ -#define FIOCLEX _IO('f', 1) /* set close on exec on fd */ -#define FIONCLEX _IO('f', 2) /* remove close on exec */ -#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ -#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ -#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */ -#define FIOSETOWN _IOW('f', 124, int) /* set owner */ -#define FIOGETOWN _IOR('f', 123, int) /* get owner */ - -#endif /* !_SYS_FILIO_H_ */ diff --git a/GUSI/include/sys/ioccom.h b/GUSI/include/sys/ioccom.h deleted file mode 100755 index eed5717..0000000 --- a/GUSI/include/sys/ioccom.h +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ioccom.h 8.2 (Berkeley) 3/28/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_IOCCOM_H_ -#define _SYS_IOCCOM_H_ - -/* - * Ioctl's have the command encoded in the lower word, and the size of - * any in or out parameters in the upper word. The high 3 bits of the - * upper word are used to encode the in/out status of the parameter. - */ -#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ -#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) -#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16)) -#define IOCGROUP(x) (((x) >> 8) & 0xff) - -#define IOCPARM_MAX NBPG /* max size of ioctl, mult. of NBPG */ -#define IOC_VOID 0x20000000 /* no parameters */ -#define IOC_OUT 0x40000000 /* copy out parameters */ -#define IOC_IN 0x80000000 /* copy in parameters */ -#define IOC_INOUT (IOC_IN|IOC_OUT) -#define IOC_DIRMASK 0xe0000000 /* mask for IN/OUT/VOID */ - -#define _IOC(inout,group,num,len) \ - (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)) -#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) -#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) -#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) -/* this should be _IORW, but stdio got there first */ -#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) - -#endif /* !_SYS_IOCCOM_H_ */ diff --git a/GUSI/include/sys/ioctl.h b/GUSI/include/sys/ioctl.h deleted file mode 100755 index a38e29f..0000000 --- a/GUSI/include/sys/ioctl.h +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ioctl.h 8.6 (Berkeley) 3/28/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_IOCTL_H_ -#define _SYS_IOCTL_H_ - -#include - -/* - * Pun for SunOS prior to 3.2. SunOS 3.2 and later support TIOCGWINSZ - * and TIOCSWINSZ (yes, even 3.2-3.5, the fact that it wasn't documented - * nonwithstanding). - */ -struct ttysize { - unsigned short ts_lines; - unsigned short ts_cols; - unsigned short ts_xxx; - unsigned short ts_yyy; -}; -#define TIOCGSIZE TIOCGWINSZ -#define TIOCSSIZE TIOCSWINSZ - -#include - -#include -#include - -#include - -__BEGIN_DECLS -int ioctl __P((int, unsigned long, ...)); -__END_DECLS -#endif /* !_SYS_IOCTL_H_ */ diff --git a/GUSI/include/sys/ppc.h b/GUSI/include/sys/ppc.h deleted file mode 100755 index 5b688e1..0000000 --- a/GUSI/include/sys/ppc.h +++ /dev/null @@ -1,55 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : GUSIPPC.nw - Program-Program Communications -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:50:18 chombier -// % Initial import -// % -// % Revision 1.9 2000/10/29 19:13:57 neeri -// % Numerous fixes to make it actually work -// % -// % Revision 1.8 2000/10/16 04:34:23 neeri -// % Releasing 2.1.2 -// % -// % Revision 1.7 2000/05/23 07:15:31 neeri -// % Improve formatting -// % -// % Revision 1.6 2000/03/06 06:10:00 neeri -// % Reorganize Yield() -// % -// % Revision 1.5 1999/11/15 07:21:36 neeri -// % Add GUSIwithPPCSockets -// % -// % Revision 1.4 1999/08/26 05:45:07 neeri -// % Fixes for literate edition of source code -// % -// % Revision 1.3 1999/06/28 06:05:00 neeri -// % Support interrupted calls -// % -// % Revision 1.2 1999/06/08 04:31:30 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.1 1999/03/17 09:05:12 neeri -// % Added GUSITimer, expanded docs -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \chapter{The GUSI PPC Socket Class} -// -// The [[GUSIPPCSocket]] class implements communication via the Program-Program -// Communications Toolbox (For a change, the PPC does not stand for ``PowerPC'' -// here). -// -// We give PPC sockets their own official looking header. -// -// = -#include - -struct sockaddr_ppc { - sa_family_t sppc_family; /* AF_PPC */ - LocationNameRec sppc_location; - PPCPortRec sppc_port; -}; diff --git a/GUSI/include/sys/signal.h b/GUSI/include/sys/signal.h deleted file mode 100755 index a39d92e..0000000 --- a/GUSI/include/sys/signal.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1989, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)signal.h 8.2 (Berkeley) 1/21/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_SIGNAL_H_ -#define _SYS_SIGNAL_H_ - -#include - -#define NSIG 32 /* counting 0; could be 33 (mask is 1-32) */ - -#ifndef _ANSI_SOURCE -#include /* sigcontext; codes for SIGILL, SIGFPE */ -#endif - -__BEGIN_DECLS -typedef void (*__sig_handler)(int); -__END_DECLS - -/* 1 is SIGABRT for MPW and CW */ -#define SIGINT 2 /* interrupt */ -#define SIGQUIT 3 /* quit */ -/* 4 is SIGINT for CW */ -#define SIGABRT 6 /* abort() */ -#define SIGFPE 8 /* floating point exception */ -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGSEGV 11 /* segmentation violation */ -#define SIGPIPE 13 /* write on a pipe with no one to read it */ -#define SIGALRM 14 /* alarm clock */ -#define SIGTERM 15 /* software termination signal from kill */ -#ifndef _POSIX_SOURCE -#define SIGURG 16 /* urgent condition on IO channel */ -#endif -#define SIGSTOP 17 /* sendable stop signal not from tty */ -#define SIGTSTP 18 /* stop signal from tty */ -#define SIGCONT 19 /* continue a stopped process */ -#define SIGCHLD 20 /* to parent on child stop or exit */ -#define SIGTTIN 21 /* to readers pgrp upon background tty read */ -#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ -#define SIGHUP 24 /* hangup */ -#define SIGILL 25 /* illegal instruction (not reset when caught) */ -#ifndef _POSIX_SOURCE -#define SIGIO 23 /* input/output possible signal */ -#define SIGPROF 27 /* profiling time alarm */ -#define SIGWINCH 28 /* window size changes */ -#endif -#define SIGUSR1 30 /* user defined signal 1 */ -#define SIGUSR2 31 /* user defined signal 2 */ - -#define SIG_DFL (__sig_handler)0 -#define SIG_IGN (__sig_handler)1 -#define SIG_ERR (__sig_handler)-1 - -#ifndef _ANSI_SOURCE -typedef unsigned int sigset_t; - -/* - * Signal vector "template" used in sigaction call. - */ -struct sigaction { - __sig_handler sa_handler; /* signal handler */ - sigset_t sa_mask; /* signal mask to apply */ - int sa_flags; /* see signal options below */ -}; -#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ -#define SA_RESETHAND 0x0001 /* emulate ANSI signals */ -#define SA_RESTART 0x0002 /* restart slow system calls */ -#define SA_NODEFER 0x0004 /* don't block current signal */ - -/* - * Flags for sigprocmask: - */ -#define SIG_BLOCK 1 /* block specified signal set */ -#define SIG_UNBLOCK 2 /* unblock specified signal set */ -#define SIG_SETMASK 3 /* set specified signal set */ - -#endif /* !_ANSI_SOURCE */ - -/* - * For historical reasons; programs expect signal's return value to be - * defined by . - */ -__BEGIN_DECLS -__sig_handler signal __P((int, __sig_handler)); -__END_DECLS -#endif /* !_SYS_SIGNAL_H_ */ diff --git a/GUSI/include/sys/socket.h b/GUSI/include/sys/socket.h deleted file mode 100755 index bc1f8ee..0000000 --- a/GUSI/include/sys/socket.h +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)socket.h 8.4 (Berkeley) 2/21/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_SOCKET_H_ -#define _SYS_SOCKET_H_ - -/* - * Definitions related to sockets: types, address families, options. - */ - -/* - * Types - */ -#define SOCK_STREAM 1 /* stream socket */ -#define SOCK_DGRAM 2 /* datagram socket */ -#define SOCK_RAW 3 /* raw-protocol interface */ -#define SOCK_RDM 4 /* reliably-delivered message */ -#define SOCK_SEQPACKET 5 /* sequenced packet stream */ - -/* - * Option flags per-socket. - */ -#define SO_DEBUG 0x0001 /* turn on debugging info recording */ -#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ -#define SO_REUSEADDR 0x0004 /* allow local address reuse */ -#define SO_KEEPALIVE 0x0008 /* keep connections alive */ -#define SO_DONTROUTE 0x0010 /* just use interface addresses */ -#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ -#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ -#define SO_LINGER 0x0080 /* linger on close if data present */ -#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ -#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ - -/* - * Additional options, not kept in so_options. - */ -#define SO_SNDBUF 0x1001 /* send buffer size */ -#define SO_RCVBUF 0x1002 /* receive buffer size */ -#define SO_SNDLOWAT 0x1003 /* send low-water mark */ -#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ -#define SO_SNDTIMEO 0x1005 /* send timeout */ -#define SO_RCVTIMEO 0x1006 /* receive timeout */ -#define SO_ERROR 0x1007 /* get error status and clear */ -#define SO_TYPE 0x1008 /* get socket type */ - -/* Mandated by XNS -- neeri */ -typedef unsigned socklen_t; - -/* - * Structure used for manipulating linger option. - */ -struct linger { - int l_onoff; /* option on/off */ - int l_linger; /* linger time */ -}; - -/* - * Level number for (get/set)sockopt() to apply to socket itself. - */ -#define SOL_SOCKET 0xffff /* options for socket level */ - -/* - * Address families. - */ -#define AF_UNSPEC 0 /* unspecified */ -#define AF_LOCAL 1 /* local to host (pipes, portals) */ -#define AF_UNIX AF_LOCAL /* backward compatibility */ -#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ -#define AF_PPC 3 /* PPC Toolbox */ -#define AF_PAP 4 /* Printer Access Protocol */ -#define AF_APPLETALK 16 /* Apple Talk */ - -#define ATALK_SYMADDR 272 /* Symbolic Address for AppleTalk */ - -#define AF_MAX 20 - -#define PF_UNSPEC 0 /* unspecified */ -#define PF_LOCAL 1 /* local to host (pipes, portals) */ -#define PF_UNIX AF_LOCAL /* backward compatibility */ -#define PF_INET 2 /* internetwork: UDP, TCP, etc. */ -#define PF_PPC 3 /* PPC Toolbox */ -#define PF_PAP 4 /* Printer Access Protocol */ -#define PF_APPLETALK 16 /* Apple Talk */ - -/* Mandated by XNS -- neeri */ -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#ifndef _SA_FAMILY_T_DEFINED -#define _SA_FAMILY_T_DEFINED -typedef unsigned short sa_family_t; -#endif - -/* - * Structure used by kernel to store most - * addresses. - */ -struct sockaddr { - sa_family_t sa_family; /* address family */ - char sa_data[14]; /* actually longer; address value */ -}; - -/* - * Definitions for network related sysctl, CTL_NET. - * - * Second level is protocol family. - * Third level is protocol number. - * - * Further levels are defined by the individual families below. - */ -#define NET_MAXID AF_MAX - -#define CTL_NET_NAMES { \ - { 0, 0 }, \ - { "unix", CTLTYPE_NODE }, \ - { "inet", CTLTYPE_NODE }, \ - { "ppc", CTLTYPE_NODE }, \ - { "pap", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "", CTLTYPE_NODE }, \ - { "appletalk", CTLTYPE_NODE }, \ -} - -/* - * PF_ROUTE - Routing table - * - * Three additional levels are defined: - * Fourth: address family, 0 is wildcard - * Fifth: type of info, defined below - * Sixth: flag(s) to mask with for NET_RT_FLAGS - */ -#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ -#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ -#define NET_RT_IFLIST 3 /* survey interface list */ -#define NET_RT_MAXID 4 - -#define CTL_NET_RT_NAMES { \ - { 0, 0 }, \ - { "dump", CTLTYPE_STRUCT }, \ - { "flags", CTLTYPE_STRUCT }, \ - { "iflist", CTLTYPE_STRUCT }, \ -} - -/* - * Maximum queue length specifiable by listen. - */ -#define SOMAXCONN 5 - -/* - * Message header for recvmsg and sendmsg calls. - * Used value-result for recvmsg, value only for sendmsg. - */ -struct msghdr { - void * msg_name; /* optional address */ - socklen_t msg_namelen; /* size of address */ - struct iovec *msg_iov; /* scatter/gather array */ - int msg_iovlen; /* # elements in msg_iov */ - void * msg_control; /* ancillary data, see below */ - socklen_t msg_controllen; /* ancillary data buffer len */ - int msg_flags; /* flags on received message */ -}; - -#define MSG_OOB 0x1 /* process out-of-band data */ -#define MSG_PEEK 0x2 /* peek at incoming message */ -#define MSG_DONTROUTE 0x4 /* send without using routing tables */ -#define MSG_EOR 0x8 /* data completes record */ -#define MSG_TRUNC 0x10 /* data discarded before delivery */ -#define MSG_CTRUNC 0x20 /* control data lost before delivery */ -#define MSG_WAITALL 0x40 /* wait for full request or error */ -#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ - -/* - * Header for ancillary data objects in msg_control buffer. - * Used for additional information with/about a datagram - * not expressible by flags. The format is a sequence - * of message elements headed by cmsghdr structures. - */ -struct cmsghdr { - socklen_t cmsg_len; /* data byte count, including hdr */ - int cmsg_level; /* originating protocol */ - int cmsg_type; /* protocol-specific type */ -/* followed by u_char cmsg_data[]; */ -}; - -/* given pointer to struct cmsghdr, return pointer to data */ -#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1)) - -/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ -#define CMSG_NXTHDR(mhdr, cmsg) \ - (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \ - (mhdr)->msg_control + (mhdr)->msg_controllen) ? \ - (struct cmsghdr *)NULL : \ - (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) - -#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) - -/* "Socket"-level control message types: */ -#define SCM_RIGHTS 0x01 /* access rights (array of int) */ - -#include - -__BEGIN_DECLS -int accept __P((int, struct sockaddr *, socklen_t *)); -int bind __P((int, const struct sockaddr *, socklen_t)); -int connect __P((int, const struct sockaddr *, socklen_t)); -int getpeername __P((int, struct sockaddr *, socklen_t *)); -int getsockname __P((int, struct sockaddr *, socklen_t *)); -int getsockopt __P((int, int, int, void *, socklen_t *)); -int listen __P((int, int)); -ssize_t recv __P((int, void *, size_t, int)); -ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, socklen_t *)); -ssize_t recvmsg __P((int, struct msghdr *, int)); -ssize_t send __P((int, const void *, size_t, int)); -ssize_t sendto __P((int, const void *, - size_t, int, const struct sockaddr *, socklen_t)); -ssize_t sendmsg __P((int, const struct msghdr *, int)); -int setsockopt __P((int, int, int, const void *, socklen_t)); -int shutdown __P((int, int)); -int socket __P((int, int, int)); -int socketpair __P((int, int, int, int *)); -__END_DECLS - -#endif /* !_SYS_SOCKET_H_ */ diff --git a/GUSI/include/sys/sockio.h b/GUSI/include/sys/sockio.h deleted file mode 100755 index 834eefb..0000000 --- a/GUSI/include/sys/sockio.h +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)sockio.h 8.1 (Berkeley) 3/28/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_SOCKIO_H_ -#define _SYS_SOCKIO_H_ - -#include - -/* Socket ioctl's. */ -#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ -#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ -#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ -#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ -#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ -#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ -#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ - -#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */ -#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */ - -#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ -#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */ -#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ -#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ -#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */ -#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ -#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ -#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ -#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */ -#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ -#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ -#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */ -#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ -#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */ -#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ -#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ -#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ -#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ -#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ -#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */ - -#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ -#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ - -#endif /* !_SYS_SOCKIO_H_ */ diff --git a/GUSI/include/sys/stat.h b/GUSI/include/sys/stat.h deleted file mode 100755 index 644895e..0000000 --- a/GUSI/include/sys/stat.h +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)stat.h 8.6 (Berkeley) 3/8/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_STAT_H_ -#define _SYS_STAT_H_ - -#include - -struct stat { - dev_t st_dev; /* inode's device */ - ino_t st_ino; /* inode's number */ - mode_t st_mode; /* inode protection mode */ - nlink_t st_nlink; /* number of hard links */ - uid_t st_uid; /* user ID of the file's owner */ - gid_t st_gid; /* group ID of the file's group */ - dev_t st_rdev; /* device type */ - time_t st_atime; /* time of last access */ - time_t st_mtime; /* time of last data modification */ - time_t st_ctime; /* time of last file status change */ - off_t st_size; /* file size, in bytes */ - long st_blocks; /* blocks allocated for file */ - unsigned long st_blksize; /* optimal blocksize for I/O */ - unsigned long st_flags; /* user defined flags for file */ -}; - -#define S_ISUID 0004000 /* set user id on execution */ -#define S_ISGID 0002000 /* set group id on execution */ - -#define S_IRWXU 0000700 /* RWX mask for owner */ -#define S_IRUSR 0000400 /* R for owner */ -#define S_IWUSR 0000200 /* W for owner */ -#define S_IXUSR 0000100 /* X for owner */ - -#define S_IRWXG 0000070 /* RWX mask for group */ -#define S_IRGRP 0000040 /* R for group */ -#define S_IWGRP 0000020 /* W for group */ -#define S_IXGRP 0000010 /* X for group */ - -#define S_IRWXO 0000007 /* RWX mask for other */ -#define S_IROTH 0000004 /* R for other */ -#define S_IWOTH 0000002 /* W for other */ -#define S_IXOTH 0000001 /* X for other */ - -#define S_IFMT 0170000 /* type of file mask */ -#define S_IFIFO 0010000 /* named pipe (fifo) */ -#define S_IFCHR 0020000 /* character special */ -#define S_IFDIR 0040000 /* directory */ -#define S_IFBLK 0060000 /* block special */ -#define S_IFREG 0100000 /* regular */ -#define S_IFLNK 0120000 /* symbolic link */ -#define S_IFSOCK 0140000 /* socket */ - -#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ -#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ -#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ -#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ -#define S_ISFIFO(m) ((m & 0170000) == 0010000 || \ - (m & 0170000) == 0140000) /* fifo or socket */ -#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */ -#define S_ISSOCK(m) ((m & 0170000) == 0010000 || \ - (m & 0170000) == 0140000) /* fifo or socket */ - -#include - -__BEGIN_DECLS -int chmod __P((const char *, mode_t)); -int fstat __P((int, struct stat *)); -int mkdir __P((const char *, ...)); -int stat __P((const char *, struct stat *)); -int lstat __P((const char *, struct stat *)); -__END_DECLS - -#endif /* !_SYS_STAT_H_ */ diff --git a/GUSI/include/sys/time.h b/GUSI/include/sys/time.h deleted file mode 100755 index 65d7a39..0000000 --- a/GUSI/include/sys/time.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)time.h 8.1 (Berkeley) 6/2/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ - -#include -#include - -/* - * Structure returned by gettimeofday(2) system call, - * and used in other calls. - */ -struct timeval { - time_t tv_sec; /* seconds */ - suseconds_t tv_usec; /* and microseconds */ -}; - -/* - * Structure defined by POSIX.4 to be like a timeval. - */ -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ -}; - -#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ - (ts)->tv_sec = (tv)->tv_sec; \ - (ts)->tv_nsec = (tv)->tv_usec * 1000; \ -} -#define TIMESPEC_TO_TIMEVAL(tv, ts) { \ - (tv)->tv_sec = (ts)->tv_sec; \ - (tv)->tv_usec = (ts)->tv_nsec / 1000; \ -} - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; -#define DST_NONE 0 /* not on dst */ -#define DST_USA 1 /* USA style dst */ -#define DST_AUST 2 /* Australian style dst */ -#define DST_WET 3 /* Western European dst */ -#define DST_MET 4 /* Middle European dst */ -#define DST_EET 5 /* Eastern European dst */ -#define DST_CAN 6 /* Canada */ - -/* Operations on timevals. */ -#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) -#define timercmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec) ? \ - ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) - -/* - * Names of the interval timers, and structure - * defining a timer setting. - */ -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerval { - struct timeval it_interval; /* timer interval */ - struct timeval it_value; /* current value */ -}; - -/* - * Getkerninfo clock information structure - */ -struct clockinfo { - int hz; /* clock frequency */ - int tick; /* micro-seconds per hz tick */ - int stathz; /* statistics clock frequency */ - int profhz; /* profiling clock frequency */ -}; - -#define NBBY 8 /* number of bits in a byte */ - -/* - * Select uses bit masks of file descriptors in longs. These macros - * manipulate such bit fields (the filesystem macros use chars). - * FD_SETSIZE may be defined by the user, but the default here should - * be enough for most uses. - */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 256 -#endif - -typedef long fd_mask; -#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ - -#ifndef howmany -#define howmany(x, y) (((x)+((y)-1))/(y)) -#endif - -typedef struct fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} fd_set; - -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) -#define FD_COPY(f, t) memcpy(t, f, sizeof(*(f))) -#define FD_ZERO(p) memset(p, 0, sizeof(*(p))) - -#include - -#include - -__BEGIN_DECLS -int getitimer __P((int, struct itimerval *)); -int gettimeofday __P((struct timeval *, struct timezone *)); -int setitimer __P((int, const struct itimerval *, struct itimerval *)); -int utimes __P((const char *, const struct timeval *)); -int select __P((int, fd_set *, fd_set *, fd_set *, struct timeval *)); -__END_DECLS - -#endif /* !_SYS_TIME_H_ */ diff --git a/GUSI/include/sys/ttycom.h b/GUSI/include/sys/ttycom.h deleted file mode 100755 index 56a2a19..0000000 --- a/GUSI/include/sys/ttycom.h +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ttycom.h 8.1 (Berkeley) 3/28/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_TTYCOM_H_ -#define _SYS_TTYCOM_H_ - -/* MPW specific codes */ -#define FIOINTERACTIVE (('f'<<8)|0x02) /* If device is interactive */ -#define FIOREFNUM (('f'<<8)|0x05) /* Return fs refnum */ -#define FIOSETEOF (('f'<<8)|0x06) /* Set file length */ - -#include - -/* - * Tty ioctl's except for those supported only for backwards compatibility - * with the old tty driver. - */ - -/* - * Window/terminal size structure. This information is stored by the kernel - * in order to provide a consistent interface, but is not used by the kernel. - */ -struct winsize { - unsigned short ws_row; /* rows, in characters */ - unsigned short ws_col; /* columns, in characters */ - unsigned short ws_xpixel; /* horizontal size, pixels */ - unsigned short ws_ypixel; /* vertical size, pixels */ -}; - -#define TIOCMODG _IOR('t', 3, int) /* get modem control state */ -#define TIOCMODS _IOW('t', 4, int) /* set modem control state */ -#define TIOCM_LE 0001 /* line enable */ -#define TIOCM_DTR 0002 /* data terminal ready */ -#define TIOCM_RTS 0004 /* request to send */ -#define TIOCM_ST 0010 /* secondary transmit */ -#define TIOCM_SR 0020 /* secondary receive */ -#define TIOCM_CTS 0040 /* clear to send */ -#define TIOCM_CAR 0100 /* carrier detect */ -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RNG 0200 /* ring */ -#define TIOCM_RI TIOCM_RNG -#define TIOCM_DSR 0400 /* data set ready */ - /* 8-10 compat */ -#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */ -#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */ - /* 15 unused */ -#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ - /* 17-18 compat */ -#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */ -#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */ -#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */ -#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */ -#define TIOCGETD _IOR('t', 26, int) /* get line discipline */ -#define TIOCSETD _IOW('t', 27, int) /* set line discipline */ - /* 127-124 compat */ -#define TIOCSBRK _IO('t', 123) /* set break bit */ -#define TIOCCBRK _IO('t', 122) /* clear break bit */ -#define TIOCSDTR _IO('t', 121) /* set data terminal ready */ -#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */ -#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ -#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ - /* 117-116 compat */ -#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ -#define TIOCSTI _IOW('t', 114, char) /* simulate terminal input */ -#define TIOCNOTTY _IO('t', 113) /* void tty association */ -#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ -#define TIOCPKT_DATA 0x00 /* data packet */ -#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ -#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ -#define TIOCPKT_STOP 0x04 /* stop output */ -#define TIOCPKT_START 0x08 /* start output */ -#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ -#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ -#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */ -#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ -#define TIOCSTART _IO('t', 110) /* start output, like ^Q */ -#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ -#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ -#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ -#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ -#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */ -#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ -#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ -#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ -#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */ -#define TIOCCONS _IOW('t', 98, int) /* become virtual console */ -#define TIOCSCTTY _IO('t', 97) /* become controlling tty */ -#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */ -#define TIOCSIG _IO('t', 95) /* pty: generate signal */ -#define TIOCDRAIN _IO('t', 94) /* wait till output drained */ - -#define TTYDISC 0 /* termios tty line discipline */ -#define TABLDISC 3 /* tablet discipline */ -#define SLIPDISC 4 /* serial IP discipline */ - -#endif /* !_SYS_TTYCOM_H_ */ diff --git a/GUSI/include/sys/types.h b/GUSI/include/sys/types.h deleted file mode 100755 index 4c8ba1c..0000000 --- a/GUSI/include/sys/types.h +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)types.h 8.4 (Berkeley) 1/21/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_TYPES_H_ -#define _SYS_TYPES_H_ - -/* Machine type dependent parameters. */ -#include - -#ifndef _POSIX_SOURCE -typedef unsigned char u_char; -typedef unsigned short u_short; -typedef unsigned int u_int; -typedef unsigned long u_long; -typedef char * caddr_t; /* core address */ -#endif - -typedef unsigned long dev_t; /* device number */ -typedef unsigned long gid_t; /* group id */ -typedef unsigned long ino_t; /* inode number */ -typedef unsigned short mode_t; /* permissions */ -typedef unsigned short nlink_t; /* link count */ -typedef long off_t; /* file offset */ -typedef long pid_t; /* process id */ -typedef unsigned long uid_t; /* user id */ -typedef long suseconds_t;/* Microseconds */ -typedef unsigned long useconds_t;/* Microseconds */ - -/* - * This belongs in unistd.h, but is placed here to ensure that programs - * casting the second parameter of lseek to off_t will get the correct - * version of lseek. - */ -#include -__BEGIN_DECLS -off_t lseek __P((int, off_t, int)); -__END_DECLS - -#include - -/* Pthreads data types */ -#include - -/* To avoid ugly namespace issues, we borrow all ANSI C defined types - from ANSI headers -*/ - -/* size_t */ -#include -/* time_t and clock_t */ -#include - -#ifdef _BSD_SSIZE_T_ -typedef _BSD_SSIZE_T_ ssize_t; -#undef _BSD_SSIZE_T_ -#endif - -#endif /* !_SYS_TYPES_H_ */ diff --git a/GUSI/include/sys/uio.h b/GUSI/include/sys/uio.h deleted file mode 100755 index 7ac29ad..0000000 --- a/GUSI/include/sys/uio.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)uio.h 8.5 (Berkeley) 2/22/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_UIO_H_ -#define _SYS_UIO_H_ - -struct iovec { - void *iov_base; /* Base address. */ - size_t iov_len; /* Length. */ -}; - -#include - -__BEGIN_DECLS -ssize_t readv __P((int, const struct iovec *, int)); -ssize_t writev __P((int, const struct iovec *, int)); -__END_DECLS -#endif /* !_SYS_UIO_H_ */ diff --git a/GUSI/include/sys/un.h b/GUSI/include/sys/un.h deleted file mode 100755 index e203b05..0000000 --- a/GUSI/include/sys/un.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)un.h 8.1 (Berkeley) 6/2/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_UN_H_ -#define _SYS_UN_H_ - -/* - * Definitions for UNIX IPC domain. - */ -struct sockaddr_un { - sa_family_t sun_family; /* AF_UNIX */ - char sun_path[104]; /* path name (gag) */ -}; - -/* actual length of an initialized sockaddr_un */ -#define SUN_LEN(su) \ - (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) - -#endif /* _SYS_UN_H_ */ diff --git a/GUSI/include/sys/unistd.h b/GUSI/include/sys/unistd.h deleted file mode 100755 index fc2662b..0000000 --- a/GUSI/include/sys/unistd.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)unistd.h 8.2 (Berkeley) 1/7/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _SYS_UNISTD_H_ -#define _SYS_UNISTD_H_ - -/* compile-time symbolic constants */ -#undef _POSIX_JOB_CONTROL /* implementation supports job control */ - -#define _POSIX_VERSION 198808L -#define _POSIX2_VERSION 199212L -#define _XOPEN_VERSION 500 - -/* execution-time symbolic constants */ - /* chown requires appropriate privileges */ -#define _POSIX_CHOWN_RESTRICTED 1 - /* too-long path components generate errors */ -#define _POSIX_NO_TRUNC 1 - /* may disable terminal special characters */ -#define _POSIX_VDISABLE ((unsigned char)'\377') - -/* access function */ -#define F_OK 0 /* test for existence of file */ -#define X_OK 0x01 /* test for execute or search permission */ -#define W_OK 0x02 /* test for write permission */ -#define R_OK 0x04 /* test for read permission */ - -/* whence values for lseek(2) */ -#define SEEK_SET 0 /* set file offset to offset */ -#define SEEK_CUR 1 /* set file offset to current plus offset */ -#define SEEK_END 2 /* set file offset to EOF plus offset */ - -#ifndef _POSIX_SOURCE -/* whence values for lseek(2); renamed by POSIX 1003.1 */ -#define L_SET SEEK_SET -#define L_INCR SEEK_CUR -#define L_XTND SEEK_END -#endif - -/* configurable pathname variables */ -#define _PC_LINK_MAX 1 -#define _PC_MAX_CANON 2 -#define _PC_MAX_INPUT 3 -#define _PC_NAME_MAX 4 -#define _PC_PATH_MAX 5 -#define _PC_PIPE_BUF 6 -#define _PC_CHOWN_RESTRICTED 7 -#define _PC_NO_TRUNC 8 -#define _PC_VDISABLE 9 - -/* configurable system variables */ -#define _SC_ARG_MAX 1 -#define _SC_CHILD_MAX 2 -#define _SC_CLK_TCK 3 -#define _SC_NGROUPS_MAX 4 -#define _SC_OPEN_MAX 5 -#define _SC_JOB_CONTROL 6 -#define _SC_SAVED_IDS 7 -#define _SC_VERSION 8 -#define _SC_BC_BASE_MAX 9 -#define _SC_BC_DIM_MAX 10 -#define _SC_BC_SCALE_MAX 11 -#define _SC_BC_STRING_MAX 12 -#define _SC_COLL_WEIGHTS_MAX 13 -#define _SC_EXPR_NEST_MAX 14 -#define _SC_LINE_MAX 15 -#define _SC_RE_DUP_MAX 16 -#define _SC_2_VERSION 17 -#define _SC_2_C_BIND 18 -#define _SC_2_C_DEV 19 -#define _SC_2_CHAR_TERM 20 -#define _SC_2_FORT_DEV 21 -#define _SC_2_FORT_RUN 22 -#define _SC_2_LOCALEDEF 23 -#define _SC_2_SW_DEV 24 -#define _SC_2_UPE 25 -#define _SC_STREAM_MAX 26 -#define _SC_TZNAME_MAX 27 - -/* configurable system strings */ -#define _CS_PATH 1 - -#endif /* !_SYS_UNISTD_H_ */ diff --git a/GUSI/include/unistd.h b/GUSI/include/unistd.h deleted file mode 100755 index 4410edc..0000000 --- a/GUSI/include/unistd.h +++ /dev/null @@ -1,168 +0,0 @@ -/*- - * Copyright (c) 1991, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)unistd.h 8.10 (Berkeley) 4/16/94 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _UNISTD_H_ -#define _UNISTD_H_ - -#include -#include -#include - -#ifndef NULL -#define NULL 0 /* null pointer constant */ -#endif - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -__BEGIN_DECLS -void _exit __P((int)); -int access __P((const char *, int)); -unsigned int alarm __P((unsigned int)); -int chdir __P((const char *)); -int close __P((int)); -size_t confstr __P((int, char *, size_t)); -int dup __P((int)); -int dup2 __P((int, int)); -int execl __P((const char *, const char *, ...)); -int execle __P((const char *, const char *, ...)); -int execlp __P((const char *, const char *, ...)); -int execv __P((const char *, char * const *)); -int execve __P((const char *, char * const *, char * const *)); -int execvp __P((const char *, char * const *)); -long fpathconf __P((int, int)); -char *getcwd __P((char *, size_t)); -gid_t getegid __P((void)); -uid_t geteuid __P((void)); -gid_t getgid __P((void)); -int getgroups __P((int, gid_t [])); -char *getlogin __P((void)); -pid_t getpgrp __P((void)); -pid_t getpid __P((void)); -pid_t getppid __P((void)); -uid_t getuid __P((void)); -int isatty __P((int)); -int link __P((const char *, const char *)); -off_t lseek __P((int, off_t, int)); -long pathconf __P((const char *, int)); -int pause __P((void)); -int pipe __P((int *)); -ssize_t read __P((int, void *, size_t)); -int rmdir __P((const char *)); -int setgid __P((gid_t)); -int setpgid __P((pid_t, pid_t)); -pid_t setsid __P((void)); -int setuid __P((uid_t)); -unsigned int sleep __P((unsigned int)); -long sysconf __P((int)); -pid_t tcgetpgrp __P((int)); -int tcsetpgrp __P((int, pid_t)); -char *ttyname __P((int)); -useconds_t ualarm __P((useconds_t, useconds_t)); -int unlink __P((const char *)); -int usleep __P((unsigned int)); -ssize_t write __P((int, const void *, size_t)); - -#ifndef _POSIX_SOURCE -int acct __P((const char *)); -int async_daemon __P((void)); -char *brk __P((const char *)); -int chroot __P((const char *)); -char *crypt __P((const char *, const char *)); -int des_cipher __P((const char *, char *, long, int)); -int des_setkey __P((const char *key)); -int encrypt __P((char *, int)); -void endusershell __P((void)); -int exect __P((const char *, char * const *, char * const *)); -int fchdir __P((int)); -int fchown __P((int, int, int)); -int fsync __P((int)); -int ftruncate __P((int, off_t)); -int getdtablesize __P((void)); -long gethostid __P((void)); -int gethostname __P((char *, int)); -mode_t getmode __P((const void *, mode_t)); -int getpagesize __P((void)); -char *getpass __P((const char *)); -char *getusershell __P((void)); -char *getwd __P((char *)); /* obsoleted by getcwd() */ -int initgroups __P((const char *, int)); -int iruserok __P((unsigned long, int, const char *, const char *)); -int mknod __P((const char *, mode_t, dev_t)); -int mkstemp __P((char *)); -char *mktemp __P((char *)); -int nfssvc __P((int, void *)); -int nice __P((int)); -void psignal __P((unsigned int, const char *)); -extern const char *const sys_siglist[]; -int profil __P((char *, int, int, int)); -int rcmd __P((char **, int, const char *, - const char *, const char *, int *)); -char *re_comp __P((const char *)); -int re_exec __P((const char *)); -int readlink __P((const char *, char *, int)); -int reboot __P((int)); -int revoke __P((const char *)); -int rresvport __P((int *)); -int ruserok __P((const char *, int, const char *, const char *)); -char *sbrk __P((int)); -int setegid __P((gid_t)); -int seteuid __P((uid_t)); -int setgroups __P((int, const gid_t *)); -void sethostid __P((long)); -int sethostname __P((const char *, int)); -int setkey __P((const char *)); -int setlogin __P((const char *)); -void *setmode __P((const char *)); -int setpgrp __P((void)); -int setregid __P((gid_t, gid_t)); -int setreuid __P((uid_t, uid_t)); -int setrgid __P((gid_t)); -int setruid __P((uid_t)); -void setusershell __P((void)); -int swapon __P((const char *)); -int symlink __P((const char *, const char *)); -void sync __P((void)); -int syscall __P((int, ...)); -int truncate __P((const char *, off_t)); -int ttyslot __P((void)); -void *valloc __P((size_t)); /* obsoleted by malloc() */ -pid_t vfork __P((void)); -#endif /* !_POSIX_SOURCE */ -__END_DECLS - -#endif /* !_UNISTD_H_ */ diff --git a/GUSI/include/utime.h b/GUSI/include/utime.h deleted file mode 100755 index b5b0410..0000000 --- a/GUSI/include/utime.h +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * [¤3 Deleted as of 22Jul99, see - * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - * for details] - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)utime.h 8.1 (Berkeley) 6/2/93 - */ - -/* Adapted for GUSI by Matthias Neeracher */ - -#ifndef _UTIME_H_ -#define _UTIME_H_ - -struct utimbuf { - time_t actime; /* Access time */ - time_t modtime; /* Modification time */ -}; - -#include - -__BEGIN_DECLS -int utime __P((const char *, const struct utimbuf *)); -__END_DECLS - -#endif /* !_UTIME_H_ */ diff --git a/GUSI/project/GUSI2.CWPro6.mcp b/GUSI/project/GUSI2.CWPro6.mcp deleted file mode 100644 index f5f60c1..0000000 Binary files a/GUSI/project/GUSI2.CWPro6.mcp and /dev/null differ diff --git a/GUSI/project/GUSI2.CWPro7.mcp b/GUSI/project/GUSI2.CWPro7.mcp deleted file mode 100644 index 88c45d2..0000000 Binary files a/GUSI/project/GUSI2.CWPro7.mcp and /dev/null differ diff --git a/GUSI/project/GUSI2.mcp b/GUSI/project/GUSI2.mcp deleted file mode 100755 index 4dfd610..0000000 Binary files a/GUSI/project/GUSI2.mcp and /dev/null differ diff --git a/GUSI/scripts/EzDepend b/GUSI/scripts/EzDepend deleted file mode 100755 index 0729656..0000000 Binary files a/GUSI/scripts/EzDepend and /dev/null differ diff --git a/GUSI/scripts/update-source b/GUSI/scripts/update-source deleted file mode 100755 index 8aae372..0000000 Binary files a/GUSI/scripts/update-source and /dev/null differ diff --git a/GUSI/scripts/weavem b/GUSI/scripts/weavem deleted file mode 100755 index 2a36234..0000000 Binary files a/GUSI/scripts/weavem and /dev/null differ diff --git a/GUSI/src/GUSI.tex b/GUSI/src/GUSI.tex deleted file mode 100755 index 170ba4d..0000000 Binary files a/GUSI/src/GUSI.tex and /dev/null differ diff --git a/GUSI/src/GUSIBasics.nw b/GUSI/src/GUSIBasics.nw deleted file mode 100755 index aa58fc2..0000000 Binary files a/GUSI/src/GUSIBasics.nw and /dev/null differ diff --git a/GUSI/src/GUSIBuffer.nw b/GUSI/src/GUSIBuffer.nw deleted file mode 100755 index 67e203f..0000000 Binary files a/GUSI/src/GUSIBuffer.nw and /dev/null differ diff --git a/GUSI/src/GUSIConfig.nw b/GUSI/src/GUSIConfig.nw deleted file mode 100755 index 4671d48..0000000 Binary files a/GUSI/src/GUSIConfig.nw and /dev/null differ diff --git a/GUSI/src/GUSIContext.nw b/GUSI/src/GUSIContext.nw deleted file mode 100755 index 5f33b1d..0000000 Binary files a/GUSI/src/GUSIContext.nw and /dev/null differ diff --git a/GUSI/src/GUSIContextQueue.nw b/GUSI/src/GUSIContextQueue.nw deleted file mode 100755 index 48ffb4d..0000000 Binary files a/GUSI/src/GUSIContextQueue.nw and /dev/null differ diff --git a/GUSI/src/GUSIDCon.nw b/GUSI/src/GUSIDCon.nw deleted file mode 100755 index 36a109a..0000000 Binary files a/GUSI/src/GUSIDCon.nw and /dev/null differ diff --git a/GUSI/src/GUSIDescriptor.nw b/GUSI/src/GUSIDescriptor.nw deleted file mode 100755 index 8bbd736..0000000 Binary files a/GUSI/src/GUSIDescriptor.nw and /dev/null differ diff --git a/GUSI/src/GUSIDevice.nw b/GUSI/src/GUSIDevice.nw deleted file mode 100755 index a88a7e6..0000000 Binary files a/GUSI/src/GUSIDevice.nw and /dev/null differ diff --git a/GUSI/src/GUSIDiag.nw b/GUSI/src/GUSIDiag.nw deleted file mode 100755 index 3a2033f..0000000 Binary files a/GUSI/src/GUSIDiag.nw and /dev/null differ diff --git a/GUSI/src/GUSIFSWrappers.nw b/GUSI/src/GUSIFSWrappers.nw deleted file mode 100755 index 3c82024..0000000 Binary files a/GUSI/src/GUSIFSWrappers.nw and /dev/null differ diff --git a/GUSI/src/GUSIFactory.nw b/GUSI/src/GUSIFactory.nw deleted file mode 100755 index 30bcd37..0000000 Binary files a/GUSI/src/GUSIFactory.nw and /dev/null differ diff --git a/GUSI/src/GUSIFileSpec.nw b/GUSI/src/GUSIFileSpec.nw deleted file mode 100755 index 3a12abe..0000000 Binary files a/GUSI/src/GUSIFileSpec.nw and /dev/null differ diff --git a/GUSI/src/GUSIForeignThreads.nw b/GUSI/src/GUSIForeignThreads.nw deleted file mode 100755 index 2d01bf5..0000000 Binary files a/GUSI/src/GUSIForeignThreads.nw and /dev/null differ diff --git a/GUSI/src/GUSIInet.nw b/GUSI/src/GUSIInet.nw deleted file mode 100755 index b72f8be..0000000 Binary files a/GUSI/src/GUSIInet.nw and /dev/null differ diff --git a/GUSI/src/GUSIMPW.nw b/GUSI/src/GUSIMPW.nw deleted file mode 100755 index a486f08..0000000 Binary files a/GUSI/src/GUSIMPW.nw and /dev/null differ diff --git a/GUSI/src/GUSIMPWStdio.nw b/GUSI/src/GUSIMPWStdio.nw deleted file mode 100755 index 9af7b7e..0000000 Binary files a/GUSI/src/GUSIMPWStdio.nw and /dev/null differ diff --git a/GUSI/src/GUSIMSL.nw b/GUSI/src/GUSIMSL.nw deleted file mode 100755 index 43c317c..0000000 Binary files a/GUSI/src/GUSIMSL.nw and /dev/null differ diff --git a/GUSI/src/GUSIMTInet.nw b/GUSI/src/GUSIMTInet.nw deleted file mode 100755 index 542aa22..0000000 Binary files a/GUSI/src/GUSIMTInet.nw and /dev/null differ diff --git a/GUSI/src/GUSIMTNetDB.nw b/GUSI/src/GUSIMTNetDB.nw deleted file mode 100755 index b210b38..0000000 Binary files a/GUSI/src/GUSIMTNetDB.nw and /dev/null differ diff --git a/GUSI/src/GUSIMTTcp.nw b/GUSI/src/GUSIMTTcp.nw deleted file mode 100755 index 120ecd3..0000000 Binary files a/GUSI/src/GUSIMTTcp.nw and /dev/null differ diff --git a/GUSI/src/GUSIMTUdp.nw b/GUSI/src/GUSIMTUdp.nw deleted file mode 100755 index 5b6de6a..0000000 Binary files a/GUSI/src/GUSIMTUdp.nw and /dev/null differ diff --git a/GUSI/src/GUSIMacFile.nw b/GUSI/src/GUSIMacFile.nw deleted file mode 100755 index b7fe100..0000000 Binary files a/GUSI/src/GUSIMacFile.nw and /dev/null differ diff --git a/GUSI/src/GUSINetDB.nw b/GUSI/src/GUSINetDB.nw deleted file mode 100755 index 3179a28..0000000 Binary files a/GUSI/src/GUSINetDB.nw and /dev/null differ diff --git a/GUSI/src/GUSINull.nw b/GUSI/src/GUSINull.nw deleted file mode 100755 index 8fb95cd..0000000 Binary files a/GUSI/src/GUSINull.nw and /dev/null differ diff --git a/GUSI/src/GUSIOTInet.nw b/GUSI/src/GUSIOTInet.nw deleted file mode 100755 index c9b789d..0000000 Binary files a/GUSI/src/GUSIOTInet.nw and /dev/null differ diff --git a/GUSI/src/GUSIOTNetDB.nw b/GUSI/src/GUSIOTNetDB.nw deleted file mode 100755 index b96d63f..0000000 Binary files a/GUSI/src/GUSIOTNetDB.nw and /dev/null differ diff --git a/GUSI/src/GUSIOpenTransport.nw b/GUSI/src/GUSIOpenTransport.nw deleted file mode 100755 index 594318d..0000000 Binary files a/GUSI/src/GUSIOpenTransport.nw and /dev/null differ diff --git a/GUSI/src/GUSIPOSIX.nw b/GUSI/src/GUSIPOSIX.nw deleted file mode 100755 index 143ea6f..0000000 Binary files a/GUSI/src/GUSIPOSIX.nw and /dev/null differ diff --git a/GUSI/src/GUSIPPC.nw b/GUSI/src/GUSIPPC.nw deleted file mode 100755 index cf7d1b3..0000000 Binary files a/GUSI/src/GUSIPPC.nw and /dev/null differ diff --git a/GUSI/src/GUSIPThread.nw b/GUSI/src/GUSIPThread.nw deleted file mode 100755 index 7eaf79a..0000000 Binary files a/GUSI/src/GUSIPThread.nw and /dev/null differ diff --git a/GUSI/src/GUSIPipe.nw b/GUSI/src/GUSIPipe.nw deleted file mode 100755 index 58b1dec..0000000 Binary files a/GUSI/src/GUSIPipe.nw and /dev/null differ diff --git a/GUSI/src/GUSISIOUX.nw b/GUSI/src/GUSISIOUX.nw deleted file mode 100755 index 88b03f5..0000000 Binary files a/GUSI/src/GUSISIOUX.nw and /dev/null differ diff --git a/GUSI/src/GUSISIOW.nw b/GUSI/src/GUSISIOW.nw deleted file mode 100755 index c0c7a10..0000000 Binary files a/GUSI/src/GUSISIOW.nw and /dev/null differ diff --git a/GUSI/src/GUSISfio.nw b/GUSI/src/GUSISfio.nw deleted file mode 100755 index 00a992e..0000000 Binary files a/GUSI/src/GUSISfio.nw and /dev/null differ diff --git a/GUSI/src/GUSISignal.nw b/GUSI/src/GUSISignal.nw deleted file mode 100755 index 6c72dfe..0000000 Binary files a/GUSI/src/GUSISignal.nw and /dev/null differ diff --git a/GUSI/src/GUSISocket.nw b/GUSI/src/GUSISocket.nw deleted file mode 100755 index 8194bcb..0000000 Binary files a/GUSI/src/GUSISocket.nw and /dev/null differ diff --git a/GUSI/src/GUSISocketMixins.nw b/GUSI/src/GUSISocketMixins.nw deleted file mode 100755 index c9c241f..0000000 Binary files a/GUSI/src/GUSISocketMixins.nw and /dev/null differ diff --git a/GUSI/src/GUSISpecific.nw b/GUSI/src/GUSISpecific.nw deleted file mode 100755 index cef8874..0000000 Binary files a/GUSI/src/GUSISpecific.nw and /dev/null differ diff --git a/GUSI/src/GUSITimer.nw b/GUSI/src/GUSITimer.nw deleted file mode 100755 index cf2b23c..0000000 Binary files a/GUSI/src/GUSITimer.nw and /dev/null differ diff --git a/GUSI/src/Makefile.mk b/GUSI/src/Makefile.mk deleted file mode 100755 index 4c00064..0000000 Binary files a/GUSI/src/Makefile.mk and /dev/null differ diff --git a/GUSI/src/Makefile.nw b/GUSI/src/Makefile.nw deleted file mode 100755 index 4c202e7..0000000 Binary files a/GUSI/src/Makefile.nw and /dev/null differ diff --git a/GUSI/src/tangled/GUSIBasics.cp b/GUSI/src/tangled/GUSIBasics.cp deleted file mode 100755 index 7eb6380..0000000 --- a/GUSI/src/tangled/GUSIBasics.cp +++ /dev/null @@ -1,387 +0,0 @@ -// = -#define GUSI_MESSAGE_LEVEL 5 - -#include "GUSIInternal.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// \section{Implementation of hook handling} -// -// Each hook is represented by a hook variable and a piece of code in the set and -// get routine. -// -// = -__BEGIN_DECLS -// Every hook then has to add to the three above code sections. Here is the spin hook. -// -// = -GUSISpinFn gGUSISpinHook; -// Here is the exec hook. I guess you see the pattern now -// -// = -GUSIExecFn gGUSIExecHook; -// The event hook is somewhat different as it is a whole array of hooks. -// -// = -const short kGUSIDefaultEventMask = mDownMask+highLevelEventMask; -short gGUSIEventMask = kGUSIDefaultEventMask; -GUSIEventFn gGUSIEventHook[16]; -__END_DECLS -void GUSISetHook(OSType code, GUSIHook hook) -{ - switch (code) { - // = - case GUSI_SpinHook: - gGUSISpinHook = (GUSISpinFn) hook; - break; - // = - case GUSI_ExecHook: - gGUSIExecHook = (GUSIExecFn) hook; - break; - // = - case GUSI_EventHook + nullEvent: - case GUSI_EventHook + mouseDown: - case GUSI_EventHook + mouseUp: - case GUSI_EventHook + keyDown: - case GUSI_EventHook + keyUp: - case GUSI_EventHook + autoKey: - case GUSI_EventHook + updateEvt: - case GUSI_EventHook + diskEvt: - case GUSI_EventHook + activateEvt: - case GUSI_EventHook + osEvt: - code -= GUSI_EventHook; - if (hook == (GUSIHook) -1) { - gGUSIEventHook[code] = (GUSIEventFn) 0; - gGUSIEventMask &= ~(1 << code); - } else { - gGUSIEventHook[code] = (GUSIEventFn) hook; - if (hook || kGUSIDefaultEventMask & (1 << code)) - gGUSIEventMask |= 1 << code; - else - gGUSIEventMask &= ~(1 << code); - } - break; - case GUSI_EventHook + kHighLevelEvent: - if (hook != (GUSIHook) -1) - gGUSIEventMask |= highLevelEventMask; - else - gGUSIEventMask &= ~highLevelEventMask; - break; - default: - GUSI_ASSERT_CLIENT(0, - ( "Illegal code %lx ('%c%c%c%c') passed to GUSISetHook\n", - code, - (code >> 24) & 0xff, - (code >> 16) & 0xff, - (code >> 8) & 0xff, - (code) & 0xff - )); - break; - } -} -GUSIHook GUSIGetHook(OSType code) -{ - switch (code) { - // = - case GUSI_SpinHook: - return (GUSIHook) gGUSISpinHook; - // = - case GUSI_ExecHook: - return (GUSIHook) gGUSIExecHook; - // = - case GUSI_EventHook + nullEvent: - case GUSI_EventHook + mouseDown: - case GUSI_EventHook + mouseUp: - case GUSI_EventHook + keyDown: - case GUSI_EventHook + keyUp: - case GUSI_EventHook + autoKey: - case GUSI_EventHook + updateEvt: - case GUSI_EventHook + diskEvt: - case GUSI_EventHook + activateEvt: - case GUSI_EventHook + osEvt: - return (GUSIHook) gGUSIEventHook[code - GUSI_EventHook]; - case GUSI_EventHook + kHighLevelEvent: - return (GUSIHook) ((gGUSIEventMask & highLevelEventMask) ? 0 : -1); - default: - GUSI_ASSERT_CLIENT(0, - ( "Illegal code %lx ('%c%c%c%c') passed to GUSIGetHook\n", - code, - (code >> 24) & 0xff, - (code >> 16) & 0xff, - (code >> 8) & 0xff, - (code) & 0xff - )); - return (GUSIHook) nil; - } -} -// \section{Implementation of error handling} -// -// -// = -int GUSISetPosixError(int error) -{ - if (error > 0) { - errno = error; - - return -1; - } else if (error < 0) { - errno = EINVAL; - - return -1; - } else - return 0; -} -// = -inline int GUSIErrorMapping(OSErr error, int posixError) -{ - GUSI_MESSAGE(("Error MacOS %d -> POSIX %d\n", error, posixError)); - return posixError; -} - -int GUSIMapMacError(OSErr error) -{ - switch (error) { - case noErr: - return 0; - // The errors we handle originate mainly from four major sources. The first - // of them is the File Manager. - // - // = - case opWrErr: - case wrPermErr: - return GUSIErrorMapping(error, EPERM); - case bdNamErr: - return GUSIErrorMapping(error, ENAMETOOLONG); - case afpObjectTypeErr: - return GUSIErrorMapping(error, ENOTDIR); - case fnfErr: - case nsvErr: - case dirNFErr: - return GUSIErrorMapping(error, ENOENT); - case dupFNErr: - return GUSIErrorMapping(error, EEXIST); - case dirFulErr: - case dskFulErr: - return GUSIErrorMapping(error, ENOSPC); - case fBsyErr: - return GUSIErrorMapping(error, EBUSY); - case tmfoErr: - return GUSIErrorMapping(error, ENFILE); - case fLckdErr: - case permErr: - case afpAccessDenied: - case kOTAccessErr: /* -3152 Missing access permission */ - return GUSIErrorMapping(error, EACCES); - case wPrErr: - case vLckdErr: - return GUSIErrorMapping(error, EROFS); - case badMovErr: - return GUSIErrorMapping(error, EINVAL); - case diffVolErr: - return GUSIErrorMapping(error, EXDEV); - // MacTCP generates another group of errors. - // - // = - case openFailed: - return GUSIErrorMapping(error, ECONNREFUSED); - case duplicateSocket: - return GUSIErrorMapping(error, EADDRINUSE); - case connectionTerminated: - return GUSIErrorMapping(error, ECONNREFUSED); - case commandTimeout: - return GUSIErrorMapping(error, ETIMEDOUT); - case ipBadLapErr: - case ipBadCnfgErr: - case ipNoCnfgErr: - case ipLoadErr: - return GUSIErrorMapping(error, ENETDOWN); - // Open Transport both generates its own version of many - // POSIX error codes and a number of ``native'' error codes. - // - // = - case kOTLookErr: /* -3158 An event occurred - call Look() */ - return GUSIErrorMapping(error, ELOOK); - case kOTAddressBusyErr: /* -3172 Address requested is already in use */ - return GUSIErrorMapping(error, EADDRINUSE); - case kOTNoAddressErr: /* -3154 No address was specified */ - case kOTOutStateErr: /* -3155 Call issued in wrong state */ - return GUSIErrorMapping(error, ENOTCONN); - case kOTFlowErr: /* -3161 Provider is flow-controlled */ - return GUSIErrorMapping(error, EWOULDBLOCK); - case kOTNotSupportedErr: /* -3167 Command is not supported */ - return GUSIErrorMapping(error, EOPNOTSUPP); - case kOTCanceledErr: /* -3180 The command was cancelled */ - return GUSIErrorMapping(error, ECANCELED); - case kEAGAINErr: /* Seems to be returned for refused connections */ - return GUSIErrorMapping(error, ECONNREFUSED); -// A little macro provides a great service in translating the POSIXish OpenTransport errors. -// -// = -#define MAP_OT_POSIX_ERROR(err) case k##err##Err: return err - -MAP_OT_POSIX_ERROR(EPERM); /* Permission denied */ -MAP_OT_POSIX_ERROR(ENOENT); /* No such file or directory */ -MAP_OT_POSIX_ERROR(EINTR); /* Interrupted system service */ -MAP_OT_POSIX_ERROR(EIO); /* I/O error */ -MAP_OT_POSIX_ERROR(ENXIO); /* No such device or address */ -MAP_OT_POSIX_ERROR(EBADF); /* Bad file number */ -MAP_OT_POSIX_ERROR(ENOMEM); /* Not enough space */ -MAP_OT_POSIX_ERROR(EACCES); /* Permission denied */ -MAP_OT_POSIX_ERROR(EFAULT); /* Bad address */ -MAP_OT_POSIX_ERROR(EBUSY); /* Device or resource busy */ -MAP_OT_POSIX_ERROR(EEXIST); /* File exists */ -MAP_OT_POSIX_ERROR(ENODEV); /* No such device */ -MAP_OT_POSIX_ERROR(EINVAL); /* Invalid argument */ -MAP_OT_POSIX_ERROR(ENOTTY); /* Not a character device */ -MAP_OT_POSIX_ERROR(EPIPE); /* Broken pipe */ -MAP_OT_POSIX_ERROR(ERANGE); /* Message size too large for STREAM */ -MAP_OT_POSIX_ERROR(EWOULDBLOCK); /* */ -MAP_OT_POSIX_ERROR(EALREADY); /* */ -MAP_OT_POSIX_ERROR(ENOTSOCK); /* Socket operation on non-socket */ -MAP_OT_POSIX_ERROR(EDESTADDRREQ); /* Destination address required */ -MAP_OT_POSIX_ERROR(EMSGSIZE); /* Message too long */ -MAP_OT_POSIX_ERROR(EPROTOTYPE); /* Protocol wrong type for socket */ -MAP_OT_POSIX_ERROR(ENOPROTOOPT); /* Protocol not available */ -MAP_OT_POSIX_ERROR(EPROTONOSUPPORT);/* Protocol not supported */ -MAP_OT_POSIX_ERROR(ESOCKTNOSUPPORT);/* Socket type not supported */ -MAP_OT_POSIX_ERROR(EOPNOTSUPP); /* Operation not supported on socket */ -MAP_OT_POSIX_ERROR(EADDRINUSE); /* Address already in use */ -MAP_OT_POSIX_ERROR(EADDRNOTAVAIL); /* Can't assign requested address */ -MAP_OT_POSIX_ERROR(ENETDOWN); /* Network is down */ -MAP_OT_POSIX_ERROR(ENETUNREACH); /* Network is unreachable */ -MAP_OT_POSIX_ERROR(ENETRESET); /* Network dropped connection on reset */ -MAP_OT_POSIX_ERROR(ECONNABORTED); /* Software caused connection abort */ -MAP_OT_POSIX_ERROR(ECONNRESET); /* Connection reset by peer */ -MAP_OT_POSIX_ERROR(ENOBUFS); /* No buffer space available */ -MAP_OT_POSIX_ERROR(EISCONN); /* Socket is already connected */ -MAP_OT_POSIX_ERROR(ENOTCONN); /* Socket is not connected */ -MAP_OT_POSIX_ERROR(ESHUTDOWN); /* Can't send after socket shutdown */ -MAP_OT_POSIX_ERROR(ETOOMANYREFS); /* Too many references: can't splice */ -MAP_OT_POSIX_ERROR(ETIMEDOUT); /* Connection timed out */ -MAP_OT_POSIX_ERROR(ECONNREFUSED); /* Connection refused */ -MAP_OT_POSIX_ERROR(EHOSTDOWN); /* Host is down */ -MAP_OT_POSIX_ERROR(EHOSTUNREACH); /* No route to host */ -MAP_OT_POSIX_ERROR(EINPROGRESS); /* */ -MAP_OT_POSIX_ERROR(ESRCH); /* */ - // Finally, the PPC Toolbox generates some errors. - // - // = - case destPortErr: /* -906 Port does not exist at destination*/ - return GUSIErrorMapping(error, EADDRNOTAVAIL); - case portNameExistsErr: /* -910 port is already open (perhaps in another app)*/ - return GUSIErrorMapping(error, EISCONN); - case userRejectErr: /* -912 Destination rejected the session request*/ - return GUSIErrorMapping(error, ECONNREFUSED); - case noResponseErr: /* -916 unable to contact destination*/ - return GUSIErrorMapping(error, ENETUNREACH); - case memFullErr: - return GUSIErrorMapping(error, ENOMEM); - default: - return GUSIErrorMapping(error, EINVAL); - } -} - -int GUSISetMacError(OSErr error) -{ - return GUSISetPosixError(GUSIMapMacError(error)); -} -// [[h_errno]] is defined here. -// -// = -int h_errno; - -int GUSISetHostError(int error) -{ - if (error) { - h_errno = error; - - return -1; - } else - return 0; -} - -int GUSISetMacHostError(OSErr error) -{ - switch (error) { - case noErr: - return 0; - case nameSyntaxErr: - case noNameServer: - case authNameErr: - h_errno = HOST_NOT_FOUND; - break; - case noResultProc: - case dnrErr: - default: - h_errno = NO_RECOVERY; - break; - case noAnsErr: - case outOfMemory: - h_errno = TRY_AGAIN; - break; - } - return -1; -} -// \section{Implementation of event handling} -// -// -// = -void GUSIHandleNextEvent(long sleepTime) -{ - EventRecord event; - - if (WaitNextEvent(gGUSIEventMask|1, &event, sleepTime, nil)) - switch (event.what) { -#if !TARGET_API_MAC_CARBON - case mouseDown: - if (!gGUSIEventHook[mouseDown]) { - WindowPtr win; - if (FindWindow(event.where, &win) == inSysWindow) - SystemClick(&event, win); - return; - } - break; -#endif - case kHighLevelEvent: - AEProcessAppleEvent(&event); // Ignore errors - - return; - } - - if (gGUSIEventHook[event.what]) - gGUSIEventHook[event.what](&event); -} -// \section{Implementation of string formatting} -// -// -// = -int GUSI_vsprintf(char * s, const char * format, va_list args) -{ - return vsprintf(s, format, args); -} - -int GUSI_sprintf(char * s, const char * format, ...) -{ - va_list ap; - - va_start(ap, format); - int len = GUSI_vsprintf(s, format, ap); - va_end(ap); - - return len; -} diff --git a/GUSI/src/tangled/GUSIBuffer.cp b/GUSI/src/tangled/GUSIBuffer.cp deleted file mode 100755 index 51f5359..0000000 --- a/GUSI/src/tangled/GUSIBuffer.cp +++ /dev/null @@ -1,570 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIBuffer.h" - -#include -#include -#include - -GUSI_USING_STD_NAMESPACE - -// The constructor of [[GUSIScattGath]] does a case distinction between an empty -// IO vector, a vector with only one element, and a vector with several elements. -// -// = -GUSIScattGath::GUSIScattGath(const iovec *iov, int cnt, bool gather) - : fIo(iov), fCount(cnt), fScratch(nil), fGather(gather) -{ - if (fCount < 1) { - // The first two cases are obvious. - // - // <[[GUSIScattGath]] constructed with empty IO vector>= - fBuf = nil; - fLen = 0; - } else if (fCount == 1) { - // <[[GUSIScattGath]] constructed with contiguous IO vector>= - fBuf = (void *) iov->iov_base; - fLen = (int) iov->iov_len; - } else { - // Only the third case is of any interest. We construct a scratch area. Note that - // [[cnt]] and [[iov]] are used; we don't want to alter the member fields. Since - // [[GUSIScattGath]] usually persist only for short times, [[fScratch]] is allocated - // as a locked handle rather than a pointer. - // - // <[[GUSIScattGath]] constructed with sparse IO vector>= - fBuf = nil; - for (fLen = 0; cnt--; ++iov) - fLen += (int) iov->iov_len; - } -} -// The backwards compatible constructor of [[GUSIScattGath]] uses the [[fTrivialIo]] -// field to simulate the [[iovec]] array. -// -// = -GUSIScattGath::GUSIScattGath(void * buffer, size_t length, bool gather) - : fIo(&fTrivialIo), fCount(1), fScratch(nil), fGather(gather) -{ - fTrivialIo.iov_base = static_cast(fBuf = buffer); - fTrivialIo.iov_len = fLen = length; -} -// A call to [[Buffer]] is an indication that the caller prefers for the data to -// be contiguous, so we allocate a scratch buffer and gather, if necessary. -// -// = -void * GUSIScattGath::Buffer() const -{ - if (!fScratch && fCount > 1) { - if (GUSI_MUTABLE(GUSIScattGath, fScratch) = NewHandle(fLen)) { - HLock(fScratch); - GUSI_MUTABLE(GUSIScattGath, fBuf) = (void *) *fScratch; - if (fGather) { - // = - char * buffer = static_cast(fBuf); - const iovec * io = fIo; - for (int count = fCount; count--; ++io) { - memcpy(buffer, io->iov_base, io->iov_len); - - buffer += io->iov_len; - } - } - } else { - GUSI_MUTABLE(GUSIScattGath, fCount) = 0; - GUSI_MUTABLE(GUSIScattGath, fBuf) = nil; - } - } - - return fBuf; -} -// The destructor of [[GUSIScattGath]] gets rid of the scratch area if one was -// allocated. If it works in scatter mode, the data is first scattered. -// -// = -GUSIScattGath::~GUSIScattGath() -{ - if (fScratch) { - if (!fGather) { - // = - char * buffer = static_cast(fBuf); - const iovec * io = fIo; - int length = fLen; - for (int count = fCount; count-- && length; ++io) { - int sect = min(length, int(io->iov_len)); - - memcpy(io->iov_base, buffer, sect); - - buffer += sect; - length -= sect; - } - } - DisposeHandle(fScratch); - } -} -// The copy constructor and the assignment operator both have to ensure that the -// two objects don't end up sharing the same scratch area. -// -// = -void GUSIScattGath::operator=(const GUSIScattGath & other) -{ - if (fScratch) - DisposeHandle(fScratch); - // = - fIo = other.fIo; - fCount = other.fCount; - fLen = other.fLen; - fGather = other.fGather; - // = - fScratch = nil; - fBuf = other.fScratch ? nil : other.fBuf; -} - -GUSIScattGath::GUSIScattGath(const GUSIScattGath & other) -{ - // = - fIo = other.fIo; - fCount = other.fCount; - fLen = other.fLen; - fGather = other.fGather; - // = - fScratch = nil; - fBuf = other.fScratch ? nil : other.fBuf; -} -// = -size_t GUSIRingBuffer::Distance(Ptr from, Ptr to) -{ - if (from > to) - return (fEnd - from) + (to - fBuffer); - else - return to-from; -} -// = -bool GUSIRingBuffer::Invariant() -{ - Lock(); - - bool invariant = - GUSI_CASSERT_INTERNAL(fProduce >= fBuffer && fProduce < fEnd) - && GUSI_CASSERT_INTERNAL(fConsume >= fBuffer && fConsume < fEnd) - && GUSI_CASSERT_INTERNAL(fFree + fValid + fSpare == fEnd - fBuffer) - && GUSI_CASSERT_INTERNAL(Distance(fConsume, fProduce) == (fValid + fSpare) % (fEnd - fBuffer)) - && GUSI_CASSERT_INTERNAL(Distance(fProduce, fConsume) == fFree % (fEnd - fBuffer)); - - Release(); - - return invariant; -} -// The constructor initializes everything. -// -// = -GUSIRingBuffer::GUSIRingBuffer(size_t bufsiz) -{ - // = - fBuffer = fConsume = fProduce = bufsiz ? NewPtr(bufsiz) : 0; - fEnd = fBuffer+bufsiz; - - fValid = fSpare = 0; - fFree = bufsiz; - // = - fInUse = false; - // = - fLocked = 0; - fDeferred = nil; - fDeferredArg = nil; - // = - fNewBuffer = nil; - fOldBuffer = nil; - - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::GUSIRingBuffer()!\n"); -} -// = -void GUSIRingBuffer::SwitchBuffer(size_t bufsiz) -{ - PurgeBuffers(); - Lock(); - if (fNewBuffer) - fNewBuffer->SwitchBuffer(bufsiz); - else if (bufsiz == fEnd-fBuffer) // No change - return; - else if (!fInUse && !fValid) { - if (fBuffer) - DisposePtr(fBuffer); - // = - fBuffer = fConsume = fProduce = bufsiz ? NewPtr(bufsiz) : 0; - fEnd = fBuffer+bufsiz; - - fValid = fSpare = 0; - fFree = bufsiz; - } else - fNewBuffer = new GUSIRingBuffer(bufsiz); - Release(); -} -void GUSIRingBuffer::PurgeBuffers() -{ - if (fOldBuffer) { - delete fOldBuffer; - - fOldBuffer = nil; - } -} -// [[ObsoleteBuffer]] swaps the data structures of [[fNewBuffer]] and the current -// buffer and finally prepends [[fNewBuffer]] to [[fOldBuffer]]. -// -// = -void GUSIRingBuffer::ObsoleteBuffer() -{ - Ptr oldBuffer = fBuffer; - fBuffer = fNewBuffer->fBuffer; - fEnd = fNewBuffer->fEnd; - fConsume = fNewBuffer->fConsume; - fProduce = fNewBuffer->fProduce; - fFree = fNewBuffer->fFree; - fValid = fNewBuffer->fValid; - fSpare = fNewBuffer->fSpare; - fInUse = fNewBuffer->fInUse; - fNewBuffer->fOldBuffer = fOldBuffer; - fOldBuffer = fNewBuffer; - fNewBuffer = fOldBuffer->fNewBuffer; - fOldBuffer->fBuffer = oldBuffer; - fOldBuffer->fNewBuffer = nil; -} -// The destructor cleans up deferred procedures and allocated memory. -// -// = -GUSIRingBuffer::~GUSIRingBuffer() -{ - Lock(); - Release(); - if (fBuffer) - DisposePtr(fBuffer); - PurgeBuffers(); - if (fNewBuffer) - delete fNewBuffer; -} -// Since the direct interface is built on the indirect interface, we deal with the latter -// first. [[ProduceBuffer]] is the most complicated member function, as it has the most -// freedom in how to do its job. -// -// = -void * GUSIRingBuffer::ProduceBuffer(size_t & len) -{ - Lock(); - // If a new buffer exists, [[ProduceBuffer]] requests get directed there. - // - // = - while (fNewBuffer) { - if (!fValid) - ObsoleteBuffer(); - else { - void * buf = fNewBuffer->ProduceBuffer(len); - Release(); - return buf; - } - } - size_t requested_length = len; - - // To keep free space as contiguous as possible, we reset the production and consumption - // pointers whenever the buffer becomes empty. Since this code is only called from - // [[ProduceBuffer]], we know that there is no outstanding data producing call. This - // is also a good opportunity to switch buffers. - // - // = - if (!fValid) { - fProduce = fConsume = fBuffer; - fSpare = 0; - fFree = fEnd - fBuffer; - } - // At the core of [[ProduceBuffer]] is the code to calculate the best possible free block - // in [[streak]] and adjust [[len]]. - // - // = - size_t streak = fEnd - fProduce; - if (streak >= fFree) - streak = fFree; - else - // Now we turn to the secret of [[fSpare]]: If a large produce buffer is asked for, the free - // area wraps around, and most of the free area is at the beginning of the buffer, [[fProduce]] - // skips the rest of the buffer and the number of skipped bytes is noted in [[fSpare]] so - // [[fConsume]] will skip them later, too. - // - // = - if (streak < (fFree >> 1) && streak < len) { - fSpare = streak; - fProduce = fBuffer; - fFree -= fSpare; - streak = fFree; - } - if (len > streak) - len = streak; - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::ProduceBuffer()!\n"); - GUSI_CASSERT_INTERNAL(len <= requested_length); - void * result = fProduce; - fInUse = true; - Release(); - return result; -} -// Compared to [[ProduceBuffer]], [[ConsumeBuffer]] is quite simple as we don't have the -// option of skipping anything. -// -// = -void * GUSIRingBuffer::ConsumeBuffer(size_t & len) -{ - Lock(); - size_t requested_length = len; - // At this point, empty buffers can be thrown away unless they are in use - // - // <[[ObsoleteBuffer]] if possible>= - while (fNewBuffer && !fValid && !fInUse) - ObsoleteBuffer(); - size_t streak = fEnd - fConsume - fSpare; - if (streak > fValid) - streak = fValid; - if (len > streak) - len = streak; - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::ConsumeBuffer()!\n"); - GUSI_CASSERT_INTERNAL(len <= requested_length); - void * result = fConsume; - Release(); - return result; -} -// [[ValidBuffer]] concludes an action started by [[ProduceBuffer]] by advancing [[fProduce]]. -// -// = -void GUSIRingBuffer::ValidBuffer(void * buffer, size_t len) -{ - Lock(); - if (fNewBuffer && (buffer < fBuffer || buffer >= fEnd)) { - fNewBuffer->ValidBuffer(buffer, len); - Release(); - return; - } - GUSI_CASSERT_INTERNAL(len <= fFree); - GUSI_CASSERT_INTERNAL(fProduce + len <= fEnd); - fInUse = false; - fValid += len; - fFree -= len; - fProduce += len; - if (fProduce == fEnd) - fProduce = fBuffer; - // At this point, empty buffers can be thrown away unless they are in use - // - // <[[ObsoleteBuffer]] if possible>= - while (fNewBuffer && !fValid && !fInUse) - ObsoleteBuffer(); - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::ValidBuffer()!\n"); - Release(); -} -// [[FreeBuffer]] concludes an action started by [[ConsumeBuffer]] by advancing [[fConsume]]. -// -// = -void GUSIRingBuffer::FreeBuffer(void *, size_t len) -{ - Lock(); - fFree += len; - fValid -= len; - fConsume += len; - - if (fConsume == fEnd-fSpare) { - fConsume = fBuffer; - fFree += fSpare; - fSpare = 0; - } - // At this point, empty buffers can be thrown away unless they are in use - // - // <[[ObsoleteBuffer]] if possible>= - while (fNewBuffer && !fValid && !fInUse) - ObsoleteBuffer(); - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::FreeBuffer()!\n"); - Release(); -} -// Now for the direct interface. [[Produce]] combines [[ProduceBuffer]] with [[ValidBuffer]]. -// -// = -void GUSIRingBuffer::Produce(void * from, size_t & len) -{ - size_t part; - size_t rest; - void * buf; - - PurgeBuffers(); - for (rest = len; (part = rest) && fFree; rest -= part) { - buf = ProduceBuffer(part); - BlockMoveData(from, buf, part); - ValidBuffer(buf, part); - - from = static_cast(from)+part; - } - len -= rest; - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::Produce()!\n"); -} -// [[Consume]] combines [[ConsumeBuffer]] with [[FreeBuffer]]. -// -// = -void GUSIRingBuffer::Consume(void * to, size_t & len) -{ - size_t part; - size_t rest; - void * buf; - - PurgeBuffers(); - for (rest = len; (part = rest) && fValid; rest -= part) { - buf = ConsumeBuffer(part); - if (to) { - BlockMoveData(buf, to, part); - to = static_cast(to)+part; - } - FreeBuffer(buf, part); - } - - len -= rest; - GUSI_SASSERT_INTERNAL( - Invariant(), "Invariant violated in GUSIRingBuffer::Consume()!\n"); -} -// = -void GUSIRingBuffer::IterateIOVec( - const GUSIScattGath & sg, size_t & len, size_t & offset, bool produce) -{ - const iovec * vec = sg.IOVec(); - iovec io = vec[0]; - - if (!len) // Surprising as it is, nobody notices this any sooner - return; - - Lock(); - // = - size_t off = offset; - - while (off >= io.iov_len) { - off -= io.iov_len; - do { - io = *++vec; - } while (!io.iov_len); - } - io.iov_base = static_cast(io.iov_base)+off; - io.iov_len = io.iov_len-off; - size_t part; - size_t rest = len; - while (part = min(rest, io.iov_len)) { - size_t donepart = part; - if (produce) - Produce(io.iov_base, donepart); - else - Consume(io.iov_base, donepart); - rest -= donepart; - if (donepart != part) - break; - do { - io = *++vec; - } while (!io.iov_len); - } - len -= rest; - offset += len; - Release(); -} -// [[Free]] returns the free buffer space of the most recent buffer. -// -// = -size_t GUSIRingBuffer::Free() -{ - if (fNewBuffer) - return fNewBuffer->Free(); - else - return fFree; -} -// [[Free]] returns the sum of the valid bytes of all buffers. -// -// = -size_t GUSIRingBuffer::Valid() -{ - if (fNewBuffer) - return fNewBuffer->Valid()+fValid; - else - return fValid; -} -// = -GUSIRingBuffer::Peeker::Peeker(GUSIRingBuffer & buffer) - : fTopBuffer(buffer) -{ - fTopBuffer.Lock(); - for (fCurBuffer = &fTopBuffer; fCurBuffer && !fCurBuffer->fValid; ) - fCurBuffer = fCurBuffer->fNewBuffer; - if (fCurBuffer) - fPeek = fCurBuffer->fConsume; -} -GUSIRingBuffer::Peeker::~Peeker() -{ - fTopBuffer.Release(); -} -// = -void * GUSIRingBuffer::Peeker::PeekBuffer(size_t & len) -{ - size_t streak; - - if (!fCurBuffer) - return nil; - - if (fPeek < fCurBuffer->fConsume) - streak = fCurBuffer->fConsume - fPeek; - else - streak = fCurBuffer->fEnd - fPeek - fCurBuffer->fSpare; - if (streak > fCurBuffer->fValid) - streak = fCurBuffer->fValid; - if (len > streak) - len = streak; - void * result = fPeek; - // = - fPeek += len; - if (fPeek == fCurBuffer->fEnd-fCurBuffer->fSpare) - fPeek = fCurBuffer->fBuffer; - if (fPeek == fCurBuffer->fConsume) { - while ((fCurBuffer = fCurBuffer->fNewBuffer) && !fCurBuffer->fValid) - ; - if (fCurBuffer) - fPeek = fCurBuffer->fConsume; - } - - return result; -} -// The implementation of [[Peek]] itself is then fairly simple. -// -// = -void GUSIRingBuffer::Peeker::Peek(void * to, size_t & len) -{ - size_t part; - size_t rest; - void * buf; - - for (rest = len; (part = rest) && (buf = PeekBuffer(part)); rest -= part) { - BlockMoveData(buf, to, part); - to = static_cast(to)+part; - } - - len -= rest; -} -// = -void GUSIRingBuffer::Peeker::Peek(const GUSIScatterer & scatter, size_t & len) -{ - const iovec * vec = scatter.IOVec(); - iovec io = vec[0]; - - while (!io.iov_len) - io = *++vec; - - size_t part; - size_t rest = len; - while (part = min(rest, io.iov_len)) { - size_t donepart = part; - Peek(io.iov_base, donepart); - rest -= donepart; - if (donepart != part) - break; - do { - io = *++vec; - } while (!io.iov_len); - } - len -= rest; -} diff --git a/GUSI/src/tangled/GUSIConfig.cp b/GUSI/src/tangled/GUSIConfig.cp deleted file mode 100755 index fbfd240..0000000 --- a/GUSI/src/tangled/GUSIConfig.cp +++ /dev/null @@ -1,301 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIConfig.h" -#include "GUSIDiag.h" -#include "GUSIContext.h" -#include "GUSIBasics.h" -#include "GUSIFSWrappers.h" - -#include -#include - -#include -#include -#include -#include -#include - -// The configuration resource format of GUSI is quite old by now and has grown -// over the years. We have to be careful to keep it compatible across versions. -// -// = -struct GUSIConfigRsrc { - OSType fDefaultType; - OSType fDefaultCreator; - - bool fAutoSpin; - unsigned char fFlags; - - OSType fVersion; - - short fNumSuffices; - GUSIConfiguration::FileSuffix fSuffices[1]; -}; -// = -GUSIConfiguration * GUSIConfiguration::sInstance = nil; -// The default implementation of [[GUSISetupConfig]] simply creates the instance. -// Feel free to override it. -// -// = -// -// Prevent inlining to allow override -// -#ifdef __MWERKS__ -#pragma dont_inline on -#endif - -void GUSISetupConfig() -{ - GUSIConfiguration::CreateInstance(); -} - -#ifdef __MWERKS__ -#pragma dont_inline reset -#endif -// The [[GUSIConfiguration]] constructor initializes all fields to reasonable defaults -// and then looks for a configuration resources, if one is specified. -// -// = -GUSIConfiguration::GUSIConfiguration(short resourceID) -{ - // We show all fields with their three initialization methods tracks: - // - // \begin{itemize} - // \item How they are initialized. - // \item How they are read from the configuration resource. - // \item How they are set via a member function. - // \end{itemize} - // - // After that, we show how they are used. - // - // [[ConfigureDefaultTypeCreator]] sets the default type and creator. - // - // = - fDefaultType = 'TEXT'; - fDefaultCreator = 'MPS '; - // = - fNumSuffices = 0; - fSuffices = nil; - fWeOwnSuffices = false; - // [[ConfigureAutoSpin]] sets the autospin flag, which is enabled by default. - // - // = - fAutoSpin = true; - // [[ConfigureAutoInitGraf]] controls automatic initialization of QuickDraw. - // - // = - fAutoInitGraf = true; - // [[ConfigureSigPipe]] controls whether [[SIGPIPE]] signals are generated. - // - // = - fSigPipe = false; - // [[ConfigureSigInt] controls whether [[SIGINT]] signals are generated. - // - // = - fSigInt = true; - // [[fAccurateStat]] and [[fSharedOpen]] are tested from client code. - // - // = - fAccurateStat = false; - fSharedOpen = false; - // [[ConfigureHandleAppleEvents]] is somewhat unusual in that it calls out into - // client code instead of the other way around. - // - // = - fHandleAppleEvents = true; - - if (resourceID == kNoResource) - return; - - GUSIConfigRsrc ** rsrc = - reinterpret_cast(Get1Resource('GU·I', resourceID)); - long size = GetHandleSize(Handle(rsrc)); - - if (!rsrc || !size) - return; - - OSType version = '0102'; - if (size >= 14) - version = rsrc[0]->fVersion; - - // = - if (size >= 4 && rsrc[0]->fDefaultType) - fDefaultType = rsrc[0]->fDefaultType; - if (size >= 8 && rsrc[0]->fDefaultCreator) - fDefaultType = rsrc[0]->fDefaultCreator; - // = - if (version >= '0120' && size >= 16) - fNumSuffices = rsrc[0]->fNumSuffices; - if (fNumSuffices && (fSuffices = new FileSuffix[fNumSuffices])) { - fWeOwnSuffices = true; - memcpy(fSuffices, rsrc[0]->fSuffices, fNumSuffices*sizeof(FileSuffix)); - for (int i=0; i= - if (size >= 9) - fAutoSpin = (rsrc[0]->fAutoSpin != 0); - // = - fAutoInitGraf = version < '0174' || (rsrc[0]->fFlags & 0x04) == 0; - // = - fSigPipe = version >= '0174' && (rsrc[0]->fFlags & 0x01) != 0; - // = - fSigInt = true; - // = - fAccurateStat = (rsrc[0]->fFlags & 0x80) != 0; - fSharedOpen = version >= '0174' && (rsrc[0]->fFlags & 0x02) != 0; - // = - ConfigureHandleAppleEvents(version < '0181' || (rsrc[0]->fFlags & 0x08) == 0); -} -// = -void GUSIConfiguration::ConfigureSuffices(short numSuffices, FileSuffix * suffices) -{ - if (fWeOwnSuffices) { - delete fSuffices; - fWeOwnSuffices = false; - } - fNumSuffices = numSuffices; - fSuffices = suffices; -} -// [[SetDefaultFType]] assigns the preferred file type to a file. -// -// = -void GUSIConfiguration::SetDefaultFType(const GUSIFileSpec & name) const -{ - FInfo info; - - if (GUSIFSGetFInfo(&name, &info)) - return; - info.fdType = fDefaultType; - info.fdCreator = fDefaultCreator; - - // = - Ptr dot = PLstrrchr(name->name, '.'); - if (dot && (name->name[0] - (dot-Ptr(name->name))) <= 4) { - char searchsuffix[5]; - memset(searchsuffix, 0, 5); - strncpy(searchsuffix, dot+1, name->name[0] - (dot-Ptr(name->name))); - - for (int i = 0; i= -void GUSIConfiguration::DoAutoSpin() const -{ - GUSIContext::Yield(kGUSIYield); -} -// To make sure that A5 doesn't point into an overly wild location, we perform some sanity -// checks before getting to the point. -// -// = -void GUSIConfiguration::DoAutoInitGraf() -{ -#if !TARGET_API_MAC_CARBON - Ptr curA5 = LMGetCurrentA5(); - - if (!(reinterpret_cast(curA5) & 1) - && curA5 > reinterpret_cast(ApplicationZone()) - && curA5 < LMGetBufPtr() - ) - if (*reinterpret_cast(curA5) != &qd.thePort) - InitGraf(&qd.thePort); -#endif - fAutoInitGraf = false; -} -// [[BrokenPipe]] raises a [[SIGPIPE]] signal if desired. -// -// = -void GUSIConfiguration::BrokenPipe() -{ - if (fSigPipe) - raise(SIGPIPE); -} -// = -void GUSIConfiguration::CheckInterrupt() -{ - if (fSigInt) { -#if !TARGET_API_MAC_CARBON - EvQElPtr eventQ; - - for (eventQ = (EvQElPtr) LMGetEventQueue()->qHead; eventQ; ) - if (CmdPeriod(reinterpret_cast(&eventQ->evtQWhat))) { - raise(SIGINT); - FlushEvents(-1, 0); - break; - } else - eventQ = (EvQElPtr)eventQ->qLink; -#else - if ( CheckEventQueueForUserCancel() ) { - raise(SIGINT); - FlushEvents(-1, 0); - } -#endif - } -} -// Checking for the Command-Period key combination is rather complex. Our technique is copied -// straight from tech note 263. -// -// = -bool GUSIConfiguration::CmdPeriod(const EventRecord * event) -{ - // = - const long kMaskModifiers = 0xFE00; // we need the modifiers without the - // command key for KeyTrans - const long kMaskVirtualKey = 0x0000FF00; // get virtual key from event message - // for KeyTrans - const long kUpKeyMask = 0x0080; - const long kShiftWord = 8; // we shift the virtual key to mask it - // into the keyCode for KeyTrans - const long kMaskASCII1 = 0x00FF0000; // get the key out of the ASCII1 byte - const long kMaskASCII2 = 0x000000FF; // get the key out of the ASCII2 byte - - if ((event->what == keyDown) || (event->what == autoKey)) { - // see if the command key is down. If it is, find out the ASCII - // equivalent for the accompanying key. - - if (event->modifiers & cmdKey ) { - // = - short virtualKey = (event->message & kMaskVirtualKey) >> kShiftWord; - short keyCode = (event->modifiers & kMaskModifiers) | virtualKey; - UInt32 state = 0; - Handle hKCHR = nil; - Ptr KCHRPtr = reinterpret_cast(GetScriptManagerVariable(smKCHRCache)); - if (!KCHRPtr) { - short script = GetScriptManagerVariable(smKeyScript); - short kcID = GetScriptVariable(script, smScriptKeys); - hKCHR = GetResource('KCHR', kcID); - KCHRPtr = *hKCHR; - } - short keyInfo; - if (KCHRPtr) { - keyInfo = KeyTranslate(KCHRPtr, keyCode, &state); - if (hKCHR) - ReleaseResource(hKCHR); - } else - keyInfo = event->message; - - if ((keyInfo & kMaskASCII2) == '.' || (keyInfo & kMaskASCII1) == ('.' << 16)) - return true; - } // end the command key is down - } // end key down event - - return false; -} -// = -void GUSIConfiguration::ConfigureHandleAppleEvents(bool handleAppleEvents) -{ - if (fHandleAppleEvents != handleAppleEvents) { - fHandleAppleEvents = handleAppleEvents; - GUSISetHook(GUSI_EventHook+kHighLevelEvent, (GUSIHook) (fHandleAppleEvents ? 0 : -1)); - } -} diff --git a/GUSI/src/tangled/GUSIContext.cp b/GUSI/src/tangled/GUSIContext.cp deleted file mode 100755 index d4e6bbe..0000000 --- a/GUSI/src/tangled/GUSIContext.cp +++ /dev/null @@ -1,760 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIContext.h" -#include "GUSIDiag.h" -#include "GUSISignal.h" -#include "GUSIConfig.h" -#include "GUSIDescriptor.h" -#include "GUSITimer.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -GUSI_USING_STD_NAMESPACE - -// = -GUSIProcess * GUSIProcess::sInstance; -// = -GUSI_NEEDS_QD - -GUSIProcess::GUSIProcess(bool threading) -{ - GetCurrentProcess(&fProcess); - fA5 = (long) LMGetCurrentA5(); - if (threading) - AcquireTaskRef(); - else - fTaskRef = 0; - GUSIConfiguration::Instance()->AutoInitGraf(); - fReadyThreads = 0; - fExistingThreads= 0; - fResumeTicks = 0; - fWillSleep = false; - fDontSleep = false; - fSigProcess = GUSISigFactory::Instance()->CreateSigProcess(); - fClosing = 0; -} -// We can't do this inline as this would create a circular dependency. -// -// = -void GUSIProcess::QueueForClose(GUSISocket * sock) -{ - sock->Enqueue(&fClosing); -} -// On termination of the [[GUSIProcess]], we accelerate the closings of all -// pending sockets. -// -// = -GUSIProcess::~GUSIProcess() -{ - UInt32 start = LMGetTicks(); - UInt32 now = start; - - while (fClosing) { - fClosing->CheckClose(now); - if (now < start+300) // Normal speed for 5 seconds - now = LMGetTicks(); - else - now += 300; // Accelerate - } -} -// [[GUSIContext::Setup]] initializes the default context. We have to employ -// [[sCreatingCurrentContext]] to avoid nasty recursions. -// -// = -void GUSIContext::Setup(bool threading) -{ - bool wasThreading = sHasThreading; - if (threading) - sHasThreading = true; - if (!sCurrentContext && !sCreatingCurrentContext) { - MaxApplZone(); // It's about time, too! - - sCreatingCurrentContext = true; - sCurrentContext = - GUSIContextFactory::Instance()->CreateContext(kApplicationThreadID); - sCreatingCurrentContext = false; - } else if (!wasThreading && threading) { - // Sometimes we only recognize that we need threading after the application context - // has already been created. Assuming a disciplined use of threads, we can assume - // that the current context is still the application context, so all we have to do - // is to set the thread switcher for it. - // - // = - GUSIThreadManagerProxy::Instance()->SetThreadSwitcher( - kApplicationThreadID, (ThreadSwitchProcPtr)GUSIThreadSwitchIn, sCurrentContext, true); - GUSIThreadManagerProxy::Instance()->SetThreadSwitcher( - kApplicationThreadID, (ThreadSwitchProcPtr)GUSIThreadSwitchOut, sCurrentContext, false); - GUSIProcess::Instance()->AcquireTaskRef(); - } -} -// = -GUSIContext::Queue GUSIContext::sContexts; -GUSIContext * GUSIContext::sCurrentContext; -bool GUSIContext::sCreatingCurrentContext; -bool GUSIContext::sHasThreading; -OSErr GUSIContext::sError; -// = -extern int h_errno; - -void GUSIContext::StartSetup() -{ - fSwitchInProc = 0; - fSwitchOutProc = 0; - fTerminateProc = 0; - fErrno = errno; - fHostErrno = h_errno; - fJoin = nil; - fFlags = 0; - fWakeup = false; -} - -void GUSIContext::FinishSetup() -{ - fProcess = GUSIProcess::Instance(); - fSigContext = - GUSISigFactory::Instance()->CreateSigContext( - sCurrentContext ? sCurrentContext->fSigContext : 0); - ++fProcess->fReadyThreads; - ++fProcess->fExistingThreads; - sContexts.push(this); - if (sHasThreading) { - GUSIThreadManagerProxy::Instance()->SetThreadSwitcher( - fThreadID, (ThreadSwitchProcPtr)GUSIThreadSwitchIn, this, true); - GUSIThreadManagerProxy::Instance()->SetThreadSwitcher( - fThreadID, (ThreadSwitchProcPtr)GUSIThreadSwitchOut, this, false); - if (fThreadID != kApplicationThreadID) - GUSIThreadManagerProxy::Instance()->SetThreadTerminator( - fThreadID, (ThreadTerminationProcPtr)GUSIThreadTerminator, this); - } - GUSI_MESSAGE(("Create #%d\n", fThreadID)); -} -// The preexisting thread constructor is now simple to define. -// -// = -GUSIContext::GUSIContext(ThreadID id) -{ - StartSetup(); - fThreadID = id; - sError = 0; - FinishSetup(); -} -// And so is the creation contructor, come to think of it. -// -// = -GUSIContext::GUSIContext(ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, void ** result, ThreadID * thread) -{ - StartSetup(); - if (!result) - result = &fResult; - sError = GUSIThreadManagerProxy::Instance()->NewThread( - kCooperativeThread, threadEntry, threadParam, - stackSize, options, result, &fThreadID); - if (thread) - *thread = fThreadID; - if (sError) - return; - FinishSetup(); -} -// [[GUSIContext::Lookup]] does a linear search. -// -// = -GUSIContext * GUSIContext::Lookup(ThreadID id) -{ - for (GUSIContextQueue::iterator context = begin(); context != end(); ++context) - if (context->fThreadID == id) - return *context; - return nil; -} -// = -GUSIContext::~GUSIContext() -{ - sContexts.remove(this); - - delete fSigContext; -} -// Furthermore, at the end of an application, we need some global cleanup. This -// is especially true for MPW tools. Furthermore, we shouldn't start throwing away -// contexts before all sockets are closed. Afterwards, we kill the [[GUSIProcess]] -// instance as well. -// -// = -void GUSIContext::Queue::LiquidateAll() -{ - GUSIContextFactory::DeleteInstance(); - GUSIDescriptorTable::CloseAllDescriptors(); - while (!empty()) - front()->Liquidate(); - GUSIProcess::DeleteInstance(); -} - -void GUSIContext::Liquidate() -{ - GUSI_MESSAGE4(("GUSIContext::Liquidate %08x\n", fThreadID)); - switch (fThreadID) { - case kApplicationThreadID: // Main thread, restore switchers - if (sHasThreading) { - SetThreadSwitcher(fThreadID, fSwitchInProc, fSwitchInParam, true); - SetThreadSwitcher(fThreadID, fSwitchOutProc, fSwitchOutParam, false); - } - break; - default: // Other thread, terminate - if (!(fFlags & done)) { - fFlags &= ~detached; // Will destroy context ourselves - DisposeThread(fThreadID, nil, false); - } - break; - } - delete this; -} -// [[GUSIContext::Wakeup]] awakens a context. In every asynchronous call, there -// is a risk of race conditions, i.e., the call completes before the -// thread/process making it goes to sleep. For threads, we can handle this case -// by checking for a wakeup in the switch out procedure (an idea due to Quinn). -// -// = -void GUSIContext::Wakeup() -{ - if (fWakeup) { - GUSI_MESSAGE(("Duplicate wakeup #%d\n", fThreadID)); - } else { - GUSI_MESSAGE(("Wakeup #%d\n", fThreadID)); - fWakeup = true; - if (fThreadID && fThreadID != kApplicationThreadID) - SetThreadReadyGivenTaskRef(Process()->GetTaskRef(), fThreadID); - Process()->Wakeup(); - } -} -// The code for processes used to be quite complex. However, it turned out that there are -// in fact no race cvonditions with [[WaitNextEvent]] and it was my attempted countermeasures -// which caused trouble instead. Thanks to Keith Stattenfield for finally setting me straight. -// -// \begin{itemize} -// \item If [[fDontSleep]] is set, the process will not go to sleep in the first place (presumably because -// a wakeup is already pending). -// \item Otherwise, if [[fWillSleep]] is not set, we can prevent the process from going to sleep by setting -// [[fDontSleep]]. -// \item Otherwise, we can wake it up by calling [[WakeUpProcess]], whether or not [[WaitNextEvent]] -// has already been called. -// \end{itemize} -// -// -// = -void GUSIProcess::Wakeup() -{ - if (fDontSleep) { - GUSI_SMESSAGE("Duplicate WakeUpProcess\n"); - } else { - fDontSleep = true; - - if (!fWillSleep) { - GUSI_SMESSAGE("Caught sleep in time\n"); - } else { - GUSI_SMESSAGE("WakeUpProcess\n"); - - WakeUpProcess(&fProcess); - } - } -} -// The thread wrappers are fairly trivial. -// -// = -OSErr GUSINewThread( - ThreadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade) -{ - GUSIContext * context = GUSIContextFactory::Instance()->CreateContext( - threadEntry, threadParam, stackSize, options, - threadResult, threadMade); - OSErr err = context->Error(); - if (err) - context->Liquidate(); - return err; -} -// = -#ifdef __MRC__ -#pragma noinline_func GUSISetupContextFactory -#endif -#ifdef __MWERKS__ -#pragma dont_inline on -#endif - -void GUSISetupContextFactory() -{ -} - -#ifdef __MWERKS__ -#pragma dont_inline reset -#endif -// = -static GUSIContextFactory * sGUSIContextFactory; -static bool sGUSIContextFactorySetup; - -GUSIContextFactory * GUSIContextFactory::Instance() -{ - if (!sGUSIContextFactorySetup) { - sGUSIContextFactorySetup = true; - GUSISetupContextFactory(); - } - - if (!sGUSIContextFactory) - SetInstance(new GUSIContextFactory()); - - return sGUSIContextFactory; -} - -void GUSIContextFactory::SetInstance(GUSIContextFactory * instance) -{ - sGUSIContextFactory = instance; -} - -void GUSIContextFactory::DeleteInstance() -{ - delete sGUSIContextFactory; - sGUSIContextFactory = 0; -} - -GUSIContextFactory::GUSIContextFactory() -{ -} - -GUSIContextFactory::~GUSIContextFactory() -{ -} -// = -GUSIContext * GUSIContextFactory::CreateContext( - ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade -) -{ - GUSIContext::Setup(true); - - return new GUSIContext(threadEntry, threadParam, stackSize, options, - threadResult, threadMade); -} - -GUSIContext * GUSIContextFactory::CreateContext(ThreadID threadMade) -{ - GUSIContext::Setup(true); - - return new GUSIContext(threadMade); -} -// The thread switcher dispatches to the appropriate member function. -// -// = -OSErr GUSISetThreadSwitcher( - ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut) -{ - GUSIContext * context; - if (!(context = GUSIContext::Lookup(thread))) - return GUSIThreadManagerProxy::Instance()->SetThreadSwitcher( - thread, threadSwitcher, switchProcParam, inOrOut); - if (inOrOut) - context->SetSwitchIn(threadSwitcher, switchProcParam); - else - context->SetSwitchOut(threadSwitcher, switchProcParam); - return noErr; -} - -void GUSIContext::SetSwitchIn(ThreadSwitchProcPtr switcher, void *switchParam) -{ - fSwitchInProc = switcher; - fSwitchInParam= switchParam; -} - -void GUSIContext::SetSwitchOut(ThreadSwitchProcPtr switcher, void *switchParam) -{ - fSwitchOutProc = switcher; - fSwitchOutParam= switchParam; -} -// Similar for the thread terminator. -// -// = -OSErr GUSISetThreadTerminator( - ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam) -{ - GUSIContext * context; - if (!(context = GUSIContext::Lookup(thread))) - return GUSIThreadManagerProxy::Instance()->SetThreadTerminator( - thread, threadTerminator, terminationProcParam); - context->SetTerminator(threadTerminator, terminationProcParam); - - return noErr; -} - -void GUSIContext::SetTerminator(ThreadTerminationProcPtr terminator, void *terminationParam) -{ - fTerminateProc = terminator; - fTerminateParam= terminationParam; -} -// The hooks, after having performed their task, call through to user defined hooks. -// -// = -#if GENERATING68K && GENERATINGCFM -#define CallThreadSwitchProc(userRoutine, thread, context) \ - CallUniversalProc((userRoutine), uppThreadSwitchProcInfo, (thread), (context)) -#define CallThreadTerminationProc(userRoutine, thread, context) \ - CallUniversalProc((userRoutine), uppThreadTerminationProcInfo, (thread), (context)) -#else -#define CallThreadSwitchProc(userRoutine, thread, context) \ - (*userRoutine)((thread), (context)) -#define CallThreadTerminationProc(userRoutine, thread, context) \ - (*userRoutine)((thread), (context)) -#endif -// = -pascal void GUSIThreadSwitchIn(ThreadID, GUSIContext * context) -{ - context->SwitchIn(); -} - -void GUSIContext::SwitchIn() -{ - if (sCurrentContext != this) { - GUSI_MESSAGE(("Yield #%d -> #%d\n", sCurrentContext->fThreadID, fThreadID)); - - fEntryTicks = LMGetTicks(); - } - sCurrentContext = this; - errno = fErrno; - h_errno = fHostErrno; - - if (fFlags & asleep) { - fFlags &= ~asleep; - ++fProcess->fReadyThreads; - fProcess->fDontSleep = false; // We're back to at least 2 threads - } - - if (fSwitchInProc) - CallThreadSwitchProc(fSwitchInProc, fThreadID, fSwitchInParam); -} -// When we are switched out, we check whether we should wake up again right away. -// Pleasantly enough, there are no race conditions between this code and -// [[GUSIContext::Wakeup()]]: -// -// \begin{Itemize} -// \item By the time [[GUSIThreadSwitchOut]] is called, the thread state is -// already set to stopped, so the [[GetThreadStateGivenTaskRef]] call in -// [[GUSIContext::Wakeup]] will take effect. -// \item If [[GUSIContext::Wakeup]] is called before [[GUSIThreadSwitchOut]], -// it will be able to set [[fWakeup]] in time for the switchout procedure -// to notice and set the thread to ready again. -// \end{itemize} -// -// -// = -pascal void GUSIThreadSwitchOut(ThreadID, GUSIContext * context) -{ - context->SwitchOut(); -} - -void GUSIContext::SwitchOut() -{ - if (fSwitchOutProc) - CallThreadSwitchProc(fSwitchOutProc, fThreadID, fSwitchOutParam); - fErrno = errno; - fHostErrno = h_errno; - - ThreadTaskRef taskRef = Process()->GetTaskRef(); - ThreadState state; - if (!GetThreadStateGivenTaskRef(taskRef, fThreadID, &state)) - if (state == kStoppedThreadState) - if (fWakeup) { - SetThreadReadyGivenTaskRef(taskRef, fThreadID); - } else { - GUSI_MESSAGE(("Sleep #%d\n", fThreadID)); - fFlags |= asleep; - --fProcess->fReadyThreads; - } -} -// = -pascal void GUSIThreadTerminator(ThreadID, GUSIContext * context) -{ - context->Terminate(); -} - -void GUSIContext::Terminate() -{ - --fProcess->fExistingThreads; - if (!(fFlags & asleep)) - --fProcess->fReadyThreads; - if (fTerminateProc) - CallThreadTerminationProc(fTerminateProc, fThreadID, fTerminateParam); - if (fFlags & detached) { - delete this; - } else { - fFlags |= done; - if (fJoin) - fJoin->Wakeup(); - } - GUSI_MESSAGE(("Terminate #%d\n", fThreadID)); -} -// [[Done]] is simple unless [[join]] is set. Otherwise, we set [[fJoin]] and -// wait. If some other process is already joining, we bail out. -// -// = -bool GUSIContext::Done(bool join) -{ - if ((fFlags & done) || !join || fJoin) - return (fFlags & done); - fJoin = GUSIContext::sCurrentContext; - while (!(fFlags & done)) - Yield(kGUSIBlock); - return (fFlags & done); -} -// [[Yield]] tries to do the smart thing in all contexts. The basic idea is that -// both in threading and non-threading contexts, everyone gets their fair turn. -// We'll start with some constants determining scheduling policy (which we possibly -// should make user configurable). -// -// = -const int kThreadTimeSliceTicks = 12; -const int kProcessTimeSliceTicks = 20; -const int kProcessSleepTicks = 60; -// = -bool GUSIContext::Yield(GUSIYieldMode wait) -{ - // = - bool mainThread = CreateCurrent()->fThreadID == kApplicationThreadID; - bool block = wait == kGUSIBlock && !mainThread; - GUSIProcess * process = GUSIProcess::Instance(); - // = - if (wait == kGUSIYield && LMGetTicks() - sCurrentContext->fEntryTicks < kThreadTimeSliceTicks) - return false; - - bool interrupt = false; - - do { - // = - if (mainThread) - process->Yield(wait); - // = - if (interrupt = Raise()) - goto done; - // = - if (sHasThreading) { - if (block) - SetThreadState(kCurrentThreadID, kStoppedThreadState, kNoThreadID); - else - YieldToAnyThread(); - } - } while (wait == kGUSIBlock && !sCurrentContext->fWakeup); -done: - sCurrentContext->fWakeup = false; - - return interrupt; -} -// [[SigWait]] and [[SigSuspend]] are similar to [[Yield]]. The former waits for -// one of the specified signals to become pending, while the latter waits for -// any signal to become executed. -// -// = -void GUSIContext::SigWait(sigset_t sigs) -{ - GUSIYieldMode wait = kGUSIBlock; - // = - bool mainThread = CreateCurrent()->fThreadID == kApplicationThreadID; - bool block = wait == kGUSIBlock && !mainThread; - GUSIProcess * process = GUSIProcess::Instance(); - - for (;;) { - // = - if (mainThread) - process->Yield(wait); - if (Pending() & sigs) - break; - Raise(); - // = - if (sHasThreading) { - if (block) - SetThreadState(kCurrentThreadID, kStoppedThreadState, kNoThreadID); - else - YieldToAnyThread(); - } - } - sCurrentContext->fWakeup = false; -} - -void GUSIContext::SigSuspend() -{ - GUSIYieldMode wait = kGUSIBlock; - // = - bool mainThread = CreateCurrent()->fThreadID == kApplicationThreadID; - bool block = wait == kGUSIBlock && !mainThread; - GUSIProcess * process = GUSIProcess::Instance(); - - for (;;) { - // = - if (mainThread) - process->Yield(wait); - if (Raise(true)) - break; - // = - if (sHasThreading) { - if (block) - SetThreadState(kCurrentThreadID, kStoppedThreadState, kNoThreadID); - else - YieldToAnyThread(); - } - } - sCurrentContext->fWakeup = false; -} -// [[GUSIProcess::Yield]] tries to narrow down the critical time for race conditions, -// so we rarely have to force a wakeup. This is done using the [[fWillSleep]] and [[fDontSleep]] -// flags. The former signals the processes willingness to block, the latter is set by wakeup -// routines to try stopping it from doing so. According to Andreas Grosam, the thread manager -// may need a number of calls to [[YieldToAnyThread]] to reorganize its queues, so we leave the -// [[fDontSleep]] flag set until the number of ready threads increases above 2 or the number of -// threads in the process drops to 1 -- the application thread itself. -// -// = -void GUSIProcess::Yield(GUSIYieldMode wait) -{ - // By definition, an interrupt key press is only intended for us if we are in front. - // Applications can check this condition relatively easily by keeping track of - // suspend and resume events, but as a library, the only reliable way is to compare - // PSNs. - // - // = - ProcessSerialNumber front; - Boolean same; - - if (!GetFrontProcess(&front) && !SameProcess(&front, &fProcess, &same) && same) - GUSIConfiguration::Instance()->CheckInterrupt(); - if (wait == kGUSIBlock) { - fWillSleep = true; - if (fReadyThreads > 1 || fDontSleep) { - GUSI_SMESSAGE("Don't Sleep\n"); - wait = kGUSIYield; - } - } - if (fExistingThreads < 2) // Single threaded process skips sleep only once - fDontSleep = false; - if (wait == kGUSIYield && LMGetTicks() - fResumeTicks < kProcessTimeSliceTicks) { - fWillSleep = false; - return; - } - if (gGUSISpinHook) { - gGUSISpinHook(wait == kGUSIBlock); - } else { - GUSI_SMESSAGE("Suspend\n"); - GUSIHandleNextEvent(wait == kGUSIBlock ? kProcessSleepTicks : 0); - GUSI_SMESSAGE("Resume\n"); - } - if (fExistingThreads < 2) // Single threaded process skips sleep only once - fDontSleep = false; - fWillSleep = false; - fResumeTicks = LMGetTicks(); - if (fClosing) - fClosing->CheckClose(); -} -// [[Raise]] raises all eligible signals. [[Pending]] returns the pending signals. -// [[Blocked]] returns the blocked signals. -// -// = -bool GUSIContext::Raise(bool allSigs) -{ - return sCurrentContext->SigContext()->Raise( - GUSIProcess::Instance()->SigProcess(), allSigs); -} - -sigset_t GUSIContext::Pending() -{ - return sCurrentContext->SigContext()->Pending( - GUSIProcess::Instance()->SigProcess()); -} - -sigset_t GUSIContext::Blocked() -{ - return sCurrentContext->SigContext()->GetBlocked(); -} -// Many different asynchronous calls can be handled by [[GUSIIODone]]. -// -// = -inline GUSIContext *& Context(IOParam * pb) -{ - return reinterpret_cast(pb)[-1]; -} -static void GUSIIODone(IOParam * pb) -{ - if (Context(pb)) - Context(pb)->Wakeup(); -} - -GUSI_COMPLETION_PROC_A0(GUSIIODone, IOParam) -// Since we (or at least I) never quite know when a call is executed synchronously, -// we set the context field to [[nil]] until after the call. This avoids having to -// wake up a running context, which is a fairly costly operation. -// -// = -void GUSIStartIO(IOParam * pb) -{ - static IOCompletionUPP sIODone = 0; - - if (!sIODone) - sIODone = NewIOCompletionProc(reinterpret_cast(GUSIIODoneEntry)); - Context(pb) = nil; - pb->ioCompletion = sIODone; -} - -OSErr GUSIFinishIO(IOParam * pb) -{ - Context(pb) = GUSIContext::CreateCurrent(); - while (pb->ioResult > 0) - GUSIContext::Yield(kGUSIBlock); - return pb->ioResult; -} - -OSErr GUSIControl(IOParam * pb) -{ - GUSIStartIO(pb); - PBControlAsync(reinterpret_cast(pb)); - return GUSIFinishIO(pb); -} -// The default implementation of [[GUSIThreadManagerProxy]] is trivial. -// -// = -static auto_ptr sGUSIThreadManagerProxy; - -OSErr GUSIThreadManagerProxy::NewThread( - ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, - Size stackSize, ThreadOptions options, - void **threadResult, ThreadID *threadMade) -{ - return ::NewThread( - threadStyle, threadEntry, threadParam, stackSize, options, - threadResult, threadMade); -} - -OSErr GUSIThreadManagerProxy::SetThreadSwitcher(ThreadID thread, - ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut) -{ - return ::SetThreadSwitcher(thread, threadSwitcher, switchProcParam, inOrOut); -} - -OSErr GUSIThreadManagerProxy::SetThreadTerminator(ThreadID thread, - ThreadTerminationProcPtr threadTerminator, void *terminationProcParam) -{ - return ::SetThreadTerminator(thread, threadTerminator, terminationProcParam); -} - -GUSIThreadManagerProxy * GUSIThreadManagerProxy::Instance() -{ - if (!sGUSIThreadManagerProxy.get()) - sGUSIThreadManagerProxy = auto_ptr(MakeInstance()); - return sGUSIThreadManagerProxy.get(); -} - -GUSIThreadManagerProxy * GUSIThreadManagerProxy::MakeInstance() -{ - return new GUSIThreadManagerProxy; -} diff --git a/GUSI/src/tangled/GUSIContextQueue.cp b/GUSI/src/tangled/GUSIContextQueue.cp deleted file mode 100755 index d104b20..0000000 --- a/GUSI/src/tangled/GUSIContextQueue.cp +++ /dev/null @@ -1,127 +0,0 @@ -// = -#include "GUSIInternal.h" - -#define GUSI_DIAG GUSI_DIAG_CAUTIOUS -#include "GUSIDiag.h" - -#include "GUSIContextQueue.h" -#include "GUSIContext.h" - -#include - -#include - -// = -GUSIContextQueue::element::header * GUSIContextQueue::element::sBlocks = 0; -// [[operator new]] must be prepared to allocate a new block. -// -// = -void * GUSIContextQueue::element::operator new(size_t) -{ - header * b; - - for (b = sBlocks; b; b = b->fNext) - if (b->fFree) - break; - - if (!b) { - short max = sBlocks ? (sBlocks->fMax << 1) : 64; - b = reinterpret_cast
(NewPtr(max << 3)); - if (!b) - return 0; - memset(b, 0, max << 3); - b->fMax = max; - b->fFree= max-1; - b->fNext= sBlocks; - sBlocks = b; - } - - element * e = reinterpret_cast(b); - while ((++e)->fContext) - ; - --b->fFree; - - return e; -} -// To avoid borderline cases, [[operator delete]] only deletes a block if there -// are enough other free elements. -// -// = -void GUSIContextQueue::element::operator delete(void * elem, size_t) -{ - header * h = static_cast
(elem); - header * b; - header * p = 0; - - for (b = sBlocks; b; b = b->fNext) - if (h > b && h < b+b->fMax) { - memset(h, 0, sizeof(header)); - if (++b->fFree == b->fMax-1) { - // = - int sum = 0; - for (header * s = sBlocks; s; s = s->fNext) - if (s != b) - if ((sum += s->fFree) > 32) { - if (p) - p->fNext = b->fNext; - else - sBlocks = b->fNext; - DisposePtr(reinterpret_cast(b)); - - break; - } - } - return; - } - // Can't reach -} - -// = -GUSIContextQueue::~GUSIContextQueue() -{ - while (!empty()) - pop_front(); -} -// Making [[remove]] inline as well would probably push things too far, though. -// -// = -void GUSIContextQueue::remove(GUSIContext * context) -{ - if (fFirst) - if (fFirst->fContext == context) - pop_front(); - else { - element * prev = fFirst; - for (element * cur = prev->fNext; cur; cur = cur->fNext) - if (cur->fContext == context) { - if (!(prev->fNext = cur->fNext)) // Delete last element - fLast = prev; - delete cur; - - return; - } else - prev = cur; - } -} -// I'd love to have [[push_back]] inline, but it doesn't seem to work. -// -// = -void GUSIContextQueue::push_back(GUSIContext * context) -{ - if (element * e = new element(context)) { - if (fLast) - fLast->fNext = e; - else - fFirst = e; - fLast = e; - } -} -// [[Wakeup]] is the only context specific operation. -// -// = -void GUSIContextQueue::Wakeup() -{ - GUSI_MESSAGE(("Wakeup #%h\n", this)); - for (element * cur = fFirst; cur; cur = cur->fNext) - cur->fContext->Wakeup(); -} diff --git a/GUSI/src/tangled/GUSIDCon.cp b/GUSI/src/tangled/GUSIDCon.cp deleted file mode 100755 index 731192b..0000000 --- a/GUSI/src/tangled/GUSIDCon.cp +++ /dev/null @@ -1,117 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIDCon.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" - -#include -#include - -#include - -// \section{Definition of [[GUSIDConSocket]]} -// -// A [[GUSIDConSocket]] writes to the console or to a file. -// -// = -class GUSIDConSocket : - public GUSISocket -{ - char * fLog; -public: - GUSIDConSocket(const char * log); - ~GUSIDConSocket(); - // Read always returns EOF. - // - // = - virtual ssize_t read(const GUSIScatterer & buffer); - // Writes get translated into their DCon equivalents. - // - // = - virtual ssize_t write(const GUSIGatherer & buffer); - // DCon sockets implement simple calls. - // - // = - virtual bool Supports(ConfigOption config); - // As the name says, DCon sockets are consolish. - // - // = - virtual int isatty(); -}; -// \section{Implementation of [[GUSIDConDevice]]} -// -// You can use [[GUSIDConSocket]]s directly from C++, but the usual way to use them -// is to call [[GUSIwithDConSockets]] to have [["Dev:DCon"]] and [["Dev:DCon:xxx"]] -// mapped to them. -// -// = -extern "C" void GUSIwithDConSockets() -{ - GUSIDeviceRegistry::Instance()->AddDevice(GUSIDConDevice::Instance()); -} -// = -GUSIDConDevice * GUSIDConDevice::sInstance = nil; -// [[GUSIDConDevice]] will handle only the open request. -// -// = -bool GUSIDConDevice::Want(GUSIFileToken & file) -{ - if (!file.IsDevice()) - return false; - - const char * path = file.Path(); - - return file.WhichRequest() == GUSIFileToken::kWillOpen - && file.StrFragEqual(path+4, "dcon") - && (!path[8] || (path[8] == ':' && path[9])); -} -// Open will never fail except for lack of memory. -// -// = -GUSISocket * GUSIDConDevice::open(GUSIFileToken & file, int) -{ - const char * path = file.Path(); - - GUSISocket * sock = - path[8] ? new GUSIDConSocket(path+9) : new GUSIDConSocket(nil); - if (!sock) - GUSISetPosixError(ENOMEM); - return sock; -} -// \section{Implementation of [[GUSIDConSocket]]} -// -// The implementation of [[GUSIDConSocket]] is trivial. -// -// -// = -GUSIDConSocket::GUSIDConSocket(const char * log) - : fLog(nil) -{ - if (log) - fLog = strcpy(new char[strlen(log)+1], log); -} -GUSIDConSocket::~GUSIDConSocket() -{ - delete fLog; -} -// = -ssize_t GUSIDConSocket::read(const GUSIScatterer &) -{ - return 0; -} -// = -ssize_t GUSIDConSocket::write(const GUSIGatherer & buffer) -{ - dfprintf(fLog, "%.*s", buffer.Length(), buffer.Buffer()); - return buffer.Length(); -} -// = -bool GUSIDConSocket::Supports(ConfigOption config) -{ - return config == kSimpleCalls; -} -// = -int GUSIDConSocket::isatty() -{ - return 1; -} diff --git a/GUSI/src/tangled/GUSIDescriptor.cp b/GUSI/src/tangled/GUSIDescriptor.cp deleted file mode 100755 index 1d23314..0000000 --- a/GUSI/src/tangled/GUSIDescriptor.cp +++ /dev/null @@ -1,233 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIDescriptor.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" -#include "GUSINull.h" - -#include -#include -#include -#include - -GUSI_USING_STD_NAMESPACE - -// = -GUSIDescriptorTable::GUSIDescriptorTable() - : fInvalidDescriptor(0) -{ -} -// = -#ifdef __MRC__ -#pragma noinline_func GUSISetupConsole, GUSISetupConsoleDescriptors, GUSISetupConsoleStdio -#pragma noinline_func GUSIStdioClose, GUSIStdioFlush, GUSISetupDescriptorTable -#endif -// = -GUSIDescriptorTable * GUSIDescriptorTable::sGUSIDescriptorTable; - -// Application programmers may elect to override [[GUSISetupConsole]] to do their -// own initializations (notably to add further socket factories and devices), but -// if they chose to do so, they generally should include a call to -// [[GUSIDefaultSetupConsole]] in their version. -// -// = -// -// Prevent inlining to allow override -// -#ifdef __MWERKS__ -#pragma dont_inline on -#endif - -void GUSISetupConsole() -{ - GUSIDefaultSetupConsole(); -} - -#ifdef __MWERKS__ -#pragma dont_inline reset -#endif -// The file descriptor part and the stdio part of the initialization functionality -// are usually handled in different GUSI sublibraries, therefore we separate them -// into different hooks. There never should be a reason to override -// [[GUSIDefaultSetupConsole]] itself. -// -// = -void GUSIDefaultSetupConsole() -{ - GUSISetupConsoleDescriptors(); - GUSISetupConsoleStdio(); -} -// It may be necessary to override this function (notably for MPW support), but this -// version covers the basic case. To avoid any dependence on Null devices being -// installed in the device table, we call the instance directly. -// -// = -// -// Prevent inlining to allow override -// -#ifdef __MWERKS__ -#pragma dont_inline on -#endif - -void GUSISetupConsoleDescriptors() -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSINullDevice * null = GUSINullDevice::Instance(); - - if (open("dev:console", O_RDONLY) < 0) - table->InstallSocket(null->open()); - if (open("dev:console", O_WRONLY) < 0) - table->InstallSocket(null->open()); - if (open("dev:console", O_WRONLY) < 0) - table->InstallSocket(null->open()); -} - -#ifdef __MWERKS__ -#pragma dont_inline reset -#endif -// If, for any reason, the default descriptor table does not do the job for you, override -// [[GUSISetupDescriptorTable]]. -// -// = -// -// Prevent inlining to allow override -// -#ifdef __MWERKS__ -#pragma dont_inline on -#endif - -void GUSISetupDescriptorTable() -{ -} - -#ifdef __MWERKS__ -#pragma dont_inline reset -#endif - -GUSIDescriptorTable * GUSIDescriptorTable::Instance() -{ - static bool sNeedConsoleSetup = true; - - if (!sGUSIDescriptorTable) { - GUSISetupDescriptorTable(); - - if (!sGUSIDescriptorTable) - sGUSIDescriptorTable = new GUSIDescriptorTable(); - } - if (sNeedConsoleSetup) { - sNeedConsoleSetup = false; - GUSISetupConsole(); - } - return sGUSIDescriptorTable; -} - -void GUSIDescriptorTable::SetInstance(GUSIDescriptorTable * table) -{ - sGUSIDescriptorTable = table; -} - -void GUSIDescriptorTable::CloseAllDescriptors() -{ - delete sGUSIDescriptorTable; - sGUSIDescriptorTable = nil; -} -// = -// -// Prevent inlining to allow override -// -#ifdef __MWERKS__ -#pragma dont_inline on -#endif - -void GUSIStdioClose() { } -void GUSIStdioFlush() { } -void GUSISetupConsoleStdio() { } - -#ifdef __MWERKS__ -#pragma dont_inline reset -#endif - -GUSIDescriptorTable::~GUSIDescriptorTable() -{ - GUSIStdioFlush(); - GUSIStdioClose(); - - for (iterator i = begin(); i != end(); ++i) - RemoveSocket(*i); -} -// To keep the range of descriptor slots to search as small as possible, only -// descriptors smaller than [[fInvalidDescriptor]] are potentially valid. -// -// = -int GUSIDescriptorTable::InstallSocket(GUSISocket * sock, int start) -{ - if (start<0 || start >= SIZE) - return GUSISetPosixError(EINVAL); - - while (start fInvalidDescriptor) - fSocket[fInvalidDescriptor++] = static_cast(nil); - if (start < SIZE) - ++fInvalidDescriptor; - else - return GUSISetPosixError(EMFILE); - -found: - fSocket[start] = sock; - - sock->AddReference(); - - return start; -} -// = -int GUSIDescriptorTable::RemoveSocket(int fd) -{ - GUSISocket * sock; - - if (fd<0 || fd >= fInvalidDescriptor || !(sock = fSocket[fd])) - return GUSISetPosixError(EBADF); - - fSocket[fd] = nil; - - sock->RemoveReference(); - - return 0; -} -// = -GUSISocket * GUSIDescriptorTable::operator[](int fd) -{ - GUSISocket * sock; - - if (fd<0 || fd >= fInvalidDescriptor || !(sock = fSocket[fd])) - return GUSISetPosixError(EBADF), static_cast(nil); - else - return sock; -} -// = -GUSISocket * GUSIDescriptorTable::LookupSocket(int fd) -{ - GUSIDescriptorTable * table = Instance(); - GUSISocket * sock; - - if (fd<0 || fd >= table->fInvalidDescriptor || !(sock = table->fSocket[fd])) - return GUSISetPosixError(EBADF), static_cast(nil); - else - return sock; -} -// The copy constructor has to increment the reference counts of all sockets in the table. -// -// = -GUSIDescriptorTable::GUSIDescriptorTable(const GUSIDescriptorTable & parent) - : fInvalidDescriptor(parent.fInvalidDescriptor) -{ - memcpy(fSocket, parent.fSocket, fInvalidDescriptor*sizeof(GUSISocket *)); - - iterator e = end(); - for (iterator i = begin(); i != e; ++i) - if (GUSISocket * s = fSocket[*i]) - s->AddReference(); -} diff --git a/GUSI/src/tangled/GUSIDevice.cp b/GUSI/src/tangled/GUSIDevice.cp deleted file mode 100755 index cf2952e..0000000 --- a/GUSI/src/tangled/GUSIDevice.cp +++ /dev/null @@ -1,454 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIDevice.h" -#include "GUSIMacFile.h" -#include "GUSINull.h" -#include "GUSIDiag.h" - -#include -#include - -GUSI_USING_STD_NAMESPACE - -// \section{Implementation of [[GUSIFileToken]]} -// -// Identifying a name starting with "Dev:" as a file or a device is a dangerous job. -// Currently, there is no possibility to entirely disable device interpretation, so -// we're using the following heuristics in order to minimize conflicts with real file -// names: -// -// \begin{itemize} -// \item Any name corresponding to an existing file is a file -// \item Any name not recognized by any device domain is a file -// \end{itemize} -// -// We need many case insensitive comparisons. Since we always compare to fixed -// strings withing the ASCII set, we can do a cheap implementation. -// -// = -bool GUSIFileToken::StrFragEqual(const char * name, const char * frag) -{ - do { - if ((*name++ | 0x20) != *frag++) - return false; - } while (*frag); - - return true; -} - -GUSIFileToken::GUSIFileToken(const char * path, Request request, bool useAlias) - : fPath(path), GUSIFileSpec(path, useAlias), fDevice(nil), fRequest(request), fIsFile(false) -{ - if (!StrFragEqual(path, "dev:") || (!Error() && Exists())) - goto treatAsFile; - - if (fDevice = GUSIDeviceRegistry::Instance()->Lookup(*this)) - return; - -treatAsFile: - fIsFile = true; - fDevice = GUSIDeviceRegistry::Instance()->Lookup(*this); -} -// Some names need to be detected frequently. We've already established that the -// name starts with [["dev:"]]. -// -// = -GUSIFileToken::StdStream GUSIFileToken::StrStdStream(const char * name) -{ - if (StrFragEqual(name+4, "console") && !name[11]) - return kConsole; - if (StrFragEqual(name+4, "std")) - if (StrFragEqual(name+7, "in") && !name[9]) - return kStdin; - else if (StrFragEqual(name+7, "out") && !name[10]) - return kStdout; - else if (StrFragEqual(name+7, "err") && !name[10]) - return kStderr; - return kNoStdStream; -} -// The other constructors of [[GUSIFileToken]] are always called for real files -// and thus present no ambiguities. -// -// = -GUSIFileToken::GUSIFileToken(const GUSIFileSpec & spec, Request request) - : fPath(nil), GUSIFileSpec(spec), fDevice(nil), fRequest(request), fIsFile(true) -{ - fDevice = GUSIDeviceRegistry::Instance()->Lookup(*this); -} - -GUSIFileToken::GUSIFileToken(short fRefNum, Request request) - : fPath(nil), GUSIFileSpec(fRefNum), fDevice(nil), fRequest(request), fIsFile(true) -{ - fDevice = GUSIDeviceRegistry::Instance()->Lookup(*this); -} -// \section{Implementation of [[GUSIDevice]]} -// -// By default, a device wants no files. -// -// = -bool GUSIDevice::Want(GUSIFileToken &) -{ - return false; -} -// = -GUSISocket * GUSIDevice::open(GUSIFileToken &, int) -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - GUSISetPosixError(EOPNOTSUPP); - - return nil; -} - -int GUSIDevice::remove(GUSIFileToken &) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::rename(GUSIFileToken &, const char *) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::stat(GUSIFileToken &, struct stat *) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::chmod(GUSIFileToken &, mode_t) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::utime(GUSIFileToken &, const utimbuf *) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::access(GUSIFileToken &, int) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::mkdir(GUSIFileToken &) -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - GUSISetPosixError(EOPNOTSUPP); - - return nil; -} - -int GUSIDevice::rmdir(GUSIFileToken &) -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - GUSISetPosixError(EOPNOTSUPP); - - return nil; -} - -GUSIDirectory * GUSIDevice::opendir(GUSIFileToken &) -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - GUSISetPosixError(EOPNOTSUPP); - - return nil; -} - -int GUSIDevice::symlink(GUSIFileToken &, const char *) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::readlink(GUSIFileToken &, char *, int) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::fgetfileinfo(GUSIFileToken &, OSType *, OSType *) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::fsetfileinfo(GUSIFileToken &, OSType, OSType) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} - -int GUSIDevice::faccess(GUSIFileToken &, unsigned *, void *) -// Since individual devices are free to opt out of every operation, we have to -// implement them all as empty functions here. Calling any of these functions is -// an internal error. -// -// = -{ - GUSI_SASSERT_INTERNAL(false, "Undefined device operation"); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -GUSIDeviceRegistry * GUSIDeviceRegistry::sInstance; -// = -GUSIDeviceRegistry::GUSIDeviceRegistry() - : fFirstDevice(nil) -{ - AddDevice(GUSIMacFileDevice::Instance()); -} -// [[AddDevice]] and [[RemoveDevice]] add and remove a [[GUSIDevice]]. -// -// = -void GUSIDeviceRegistry::AddDevice(GUSIDevice * device) -{ - device->fNextDevice = fFirstDevice; - fFirstDevice = device; -} - -void GUSIDeviceRegistry::RemoveDevice(GUSIDevice * device) -{ - if (fFirstDevice == device) - fFirstDevice = device->fNextDevice; - else - for (iterator dev = begin(); dev != end(); ++dev) - if (dev->fNextDevice == device) { - dev->fNextDevice = device->fNextDevice; - - break; - } -} -// To look up, we iterate through all devices. -// -// = -GUSIDevice * GUSIDeviceRegistry::Lookup(GUSIFileToken & file) -{ - for (iterator dev = begin(); dev != end(); ++dev) - if (dev->Want(file)) - return &(*dev); - - return static_cast(nil); -} -// = -GUSISocket * GUSIDeviceRegistry::open(const char * path, int flags) -{ - GUSIFileToken file(path, GUSIFileToken::kWillOpen, (flags & O_ALIAS) != 0); - - if (GUSIDevice * device = file.Device()) - return device->open(file, flags); - else - return GUSISetPosixError(ENOENT), static_cast(nil); -} -// = -int GUSIDeviceRegistry::remove(const char * path) -{ - GUSIFileToken file(path, GUSIFileToken::kWillRemove, true); - - if (GUSIDevice * device = file.Device()) - return device->remove(file); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::rename(const char * oldname, const char * newname) -{ - GUSIFileToken oldfile(oldname, GUSIFileToken::kWillRename, true); - - if (GUSIDevice * device = oldfile.Device()) - return device->rename(oldfile, newname); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::stat(const char * path, struct stat * buf, bool useAlias) -{ - GUSIFileToken file(path, GUSIFileToken::kWillStat, useAlias); - - if (GUSIDevice * device = file.Device()) - return device->stat(file, buf); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::chmod(const char * path, mode_t mode) -{ - GUSIFileToken file(path, GUSIFileToken::kWillChmod, false); - - if (GUSIDevice * device = file.Device()) - return device->chmod(file, mode); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::utime(const char * path, const utimbuf * times) -{ - GUSIFileToken file(path, GUSIFileToken::kWillUtime, false); - - if (GUSIDevice * device = file.Device()) - return device->utime(file, times); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::access(const char * path, int mode) -{ - GUSIFileToken file(path, GUSIFileToken::kWillAccess, false); - - if (GUSIDevice * device = file.Device()) - return device->access(file, mode); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::mkdir(const char * path) -{ - GUSIFileToken file(path, GUSIFileToken::kWillMkdir); - - if (GUSIDevice * device = file.Device()) - return device->mkdir(file); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::rmdir(const char * path) -{ - GUSIFileToken file(path, GUSIFileToken::kWillRmdir); - - if (GUSIDevice * device = file.Device()) - return device->rmdir(file); - else - return GUSISetPosixError(ENOENT); -} -// = -GUSIDirectory * GUSIDeviceRegistry::opendir(const char * path) -{ - GUSIFileToken file(path, GUSIFileToken::kWillOpendir); - - if (GUSIDevice * device = file.Device()) - return device->opendir(file); - else - return GUSISetPosixError(ENOENT), static_cast(nil); -} -// = -int GUSIDeviceRegistry::symlink(const char * target, const char * newlink) -{ - GUSIFileToken file(target, GUSIFileToken::kWillSymlink, true); - - if (GUSIDevice * device = file.Device()) - return device->symlink(file, newlink); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::readlink(const char * path, char * buf, int bufsize) -{ - GUSIFileToken file(path, GUSIFileToken::kWillReadlink, true); - - if (GUSIDevice * device = file.Device()) - return device->readlink(file, buf, bufsize); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::fgetfileinfo(const char * path, OSType * creator, OSType * type) -{ - GUSIFileToken file(path, GUSIFileToken::kWillGetfileinfo, true); - - if (GUSIDevice * device = file.Device()) - return device->fgetfileinfo(file, creator, type); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::fsetfileinfo(const char * path, OSType creator, OSType type) -{ - GUSIFileToken file(path, GUSIFileToken::kWillSetfileinfo, true); - - if (GUSIDevice * device = file.Device()) - return device->fsetfileinfo(file, creator, type); - else - return GUSISetPosixError(ENOENT); -} -// = -int GUSIDeviceRegistry::faccess(const char * path, unsigned * cmd, void * arg) -{ - GUSIFileToken file(path, GUSIFileToken::kWillFaccess, true); - - if (GUSIDevice * device = file.Device()) - return device->faccess(file, cmd, arg); - else - return GUSISetPosixError(ENOENT); -} diff --git a/GUSI/src/tangled/GUSIDiag.cp b/GUSI/src/tangled/GUSIDiag.cp deleted file mode 100755 index 3697d76..0000000 --- a/GUSI/src/tangled/GUSIDiag.cp +++ /dev/null @@ -1,70 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIDiag.h" -#include "GUSIBasics.h" - -#include -#include - -// \section{Implementation of diagnostics} -// -// Ultimately, the whole macro jungle above expands into only three rather simple -// routines. The simplest of them is [[GUSI_pos]]. -// -// = -char * GUSI_diag_log; - -bool GUSI_pos(const char * file, int line) -{ - dfprintf(GUSI_diag_log, "File '%s'; Line %d # ", file, line); - - return false; -} -// [[GUSI_log]] has to do arglist juggling. -// -// = -bool GUSI_log(const char * format, ...) -{ - va_list ap; - - va_start(ap, format); - - char f[100]; - GUSI_sprintf(f, "%d: %s", LMGetTicks(), format); - vdfprintf(GUSI_diag_log, f, ap); - - va_end(ap); - - return false; -} -// [[GUSI_break]] does a [[DebugStr]]. -// -// = -bool GUSI_break(const char * format, ...) -{ - va_list ap; - char breakmsgbuf[250]; - - va_start(ap, format); - - strcpy(breakmsgbuf+1, "GUSI: "); - breakmsgbuf[0] = GUSI_vsprintf(breakmsgbuf+7, format, ap)+6; - - va_end(ap); - - DebugStr((StringPtr) breakmsgbuf); - - return false; -} -// To offer additional flexibility, we define stub functions for the DCon functions -// we use, so even with logging enabled, we can get rid of debug messages simply -// by linking without DCon. -// -// = -void dfprintf(const char *,const char *,...) -{ -} - -void vdfprintf(const char *,const char *,va_list) -{ -} diff --git a/GUSI/src/tangled/GUSIFSWrappers.cp b/GUSI/src/tangled/GUSIFSWrappers.cp deleted file mode 100755 index c4f7680..0000000 --- a/GUSI/src/tangled/GUSIFSWrappers.cp +++ /dev/null @@ -1,472 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIFSWrappers.h" -#include "GUSIContext.h" - -#include -#include -#include -#include -#include -#include -#include - -// = -OSErr GUSIFSGetCatInfo(GUSIIOPBWrapper * info) -{ - info->StartIO(); - PBGetCatInfoAsync(&info->fPB.Info()); - return info->FinishIO(); -} - -OSErr GUSIFSSetCatInfo(GUSIIOPBWrapper * info) -{ - info->StartIO(); - PBSetCatInfoAsync(&info->fPB.Info()); - return info->FinishIO(); -} -// = -OSErr GUSIFSGetFCBInfo(GUSIIOPBWrapper * fcb) -{ - fcb->StartIO(); - PBGetFCBInfoAsync(&fcb->fPB); - return fcb->FinishIO(); -} -// = -OSErr GUSIFSGetVInfo(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBGetVInfoAsync(&pb->fPB); - return pb->FinishIO(); -} -OSErr GUSIFSHGetVInfo(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBHGetVInfoAsync(&pb->fPB); - return pb->FinishIO(); -} -// = -OSErr GUSIFSOpen(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBOpenSync(&pb->fPB); - return pb->FinishIO(); -} -OSErr GUSIFSOpenDriver(StringPtr name, short * refNum) -{ - GUSIIOPBWrapper pb; - - pb->ioParam.ioNamePtr = name; - pb->ioParam.ioPermssn = fsCurPerm; - - OSErr err = GUSIFSOpen(&pb); - *refNum = pb->ioParam.ioRefNum; - - return err; -} -// = -OSErr GUSIFSHGetFInfo(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBHGetFInfoAsync(&pb->fPB); - return pb->FinishIO(); -} -OSErr GUSIFSHSetFInfo(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBHSetFInfoAsync(&pb->fPB); - return pb->FinishIO(); -} -OSErr GUSIFSGetFInfo(const FSSpec * spec, FInfo * info) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - pb->fileParam.ioFDirIndex = 0; - - OSErr err = GUSIFSHGetFInfo(&pb); - if (!err) - *info = pb->fileParam.ioFlFndrInfo; - - return err; -} -OSErr GUSIFSSetFInfo(const FSSpec * spec, const FInfo * info) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - pb->fileParam.ioFDirIndex = 0; - - OSErr err = GUSIFSHGetFInfo(&pb); - if (!err) { - pb->fileParam.ioDirID = spec->parID; /* Gets overwritten by PBHGetInfo */ - pb->fileParam.ioFlFndrInfo = *info; - err = GUSIFSHSetFInfo(&pb); - } - - return err; -} -// = -OSErr GUSIFSOpenDF(const FSSpec * spec, char permission, short * refNum) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - pb->ioParam.ioPermssn = permission; - - pb.StartIO(); - PBHOpenDFSync(&pb.fPB); - OSErr err = pb.FinishIO(); - if (!err) - *refNum = pb->ioParam.ioRefNum; - - return err; -} - -OSErr GUSIFSOpenRF(const FSSpec * spec, char permission, short * refNum) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - pb->ioParam.ioPermssn = permission; - - pb.StartIO(); - PBHOpenRFSync(&pb.fPB); - OSErr err = pb.FinishIO(); - if (!err) - *refNum = pb->ioParam.ioRefNum; - - return err; -} -// = -OSErr GUSIFSHGetVolParms(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBHGetVolParmsAsync(&pb->fPB); - return pb->FinishIO(); -} -OSErr GUSIFSGetVolParms(short vRefNum, GetVolParmsInfoBuffer * volParms) -{ - GUSIIOPBWrapper pb; - - pb->ioParam.ioNamePtr = nil; - pb->ioParam.ioVRefNum = vRefNum; - pb->ioParam.ioBuffer = Ptr(&volParms); - pb->ioParam.ioReqCount = sizeof(GetVolParmsInfoBuffer); - - return GUSIFSHGetVolParms(&pb); -} -// = -OSErr GUSIFSCreate(const FSSpec * spec) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - - pb.StartIO(); - PBHCreateAsync(&pb.fPB); - return pb.FinishIO(); -} - -OSErr GUSIFSCreate(const FSSpec * spec, OSType creator, OSType type, ScriptCode script) -{ - OSErr err; - - if (err = GUSIFSCreate(spec)) - return err; - - GUSIIOPBWrapper info; - info->FileInfo().ioVRefNum = spec->vRefNum; - info->FileInfo().ioDirID = spec->parID; - info->FileInfo().ioNamePtr = const_cast(spec->name); - - if (err = GUSIFSGetCatInfo(&info)) - goto nuke; - - info->FInfo().fdCreator = creator; - info->FInfo().fdType = type; - - if (script == smSystemScript) - info->FXInfo().fdScript = 0; - else - info->FXInfo().fdScript = script | 0x80; - - if (err = GUSIFSSetCatInfo(&info)) - goto nuke; - - return noErr; -nuke: - GUSIFSDelete(spec); - - return err; -} -// = -OSErr GUSIFSDelete(const FSSpec * spec) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - - pb.StartIO(); - PBHDeleteAsync(&pb.fPB); - return pb.FinishIO(); -} -// = -OSErr GUSIFSDirCreate(const FSSpec * spec) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - - pb.StartIO(); - PBDirCreateAsync(&pb.fPB); - return pb.FinishIO(); -} -// = -OSErr GUSIFSSetFLock(const FSSpec * spec) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - - pb.StartIO(); - PBHSetFLockAsync(&pb.fPB); - return pb.FinishIO(); -} -OSErr GUSIFSRstFLock(const FSSpec * spec) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - - pb.StartIO(); - PBHRstFLockAsync(&pb.fPB); - return pb.FinishIO(); -} -// = -OSErr GUSIFSRename(const FSSpec * spec, ConstStr255Param newname) -{ - GUSIIOPBWrapper pb; - - pb->fileParam.ioVRefNum = spec->vRefNum; - pb->fileParam.ioDirID = spec->parID; - pb->fileParam.ioNamePtr = const_cast(spec->name); - pb->ioParam.ioMisc = (Ptr)const_cast(newname); - - pb.StartIO(); - PBHRenameAsync(&pb.fPB); - return pb.FinishIO(); -} -// = -static OSErr GUSIFSCatMove1(GUSIIOPBWrapper * pb) -{ - pb->StartIO(); - PBCatMoveAsync(&pb->fPB); - return pb->FinishIO(); -} -OSErr GUSIFSCatMove(const FSSpec * spec, long dest) -{ - GUSIIOPBWrapper pb; - - pb->ioVRefNum = spec->vRefNum; - pb->ioDirID = spec->parID; - pb->ioNamePtr = const_cast(spec->name); - pb->ioNewName = nil; - pb->ioNewDirID = dest; - - return GUSIFSCatMove1(&pb); -} -OSErr GUSIFSCatMove(const FSSpec * spec, const FSSpec * dest) -{ - GUSIIOPBWrapper pb; - - pb->ioVRefNum = spec->vRefNum; - pb->ioDirID = spec->parID; - pb->ioNamePtr = const_cast(spec->name); - pb->ioNewName = const_cast(dest->name); - pb->ioNewDirID = dest->parID; - - return GUSIFSCatMove1(&pb); -} -// = -static OSErr GUSIFSMoveRename1(const FSSpec * spec, const FSSpec * dest) -{ - OSErr err; - - if (err = GUSIFSCatMove(spec, dest->parID)) - return err; - - FSSpec corner(*spec); - corner.parID = dest->parID; - if (err = GUSIFSRename(&corner, dest->name)) - GUSIFSCatMove(&corner, spec->parID); - - return err; -} -OSErr GUSIFSMoveRename(const FSSpec * spec, const FSSpec * dest) -{ - OSErr err; - GUSIIOPBWrapper pb; - - // Sometimes we get away with a simple call where a complex call would do - // the wrong thing. - // - // = - if (spec->vRefNum != dest->vRefNum) - return GUSISetPosixError(EXDEV); - if (spec->parID == dest->parID) - return GUSIFSRename(spec, dest->name); - else if (EqualString(spec->name, dest->name, true, true)) - return GUSIFSCatMove(spec, dest->parID); - // If possible, we use the combined call. - // - // = - GetVolParmsInfoBuffer volParms; - - if (!GUSIFSGetVolParms(spec->vRefNum, &volParms) - && (volParms.vMAttrib & (1 << bHasMoveRename)) - ) { - pb->copyParam.ioVRefNum = spec->vRefNum; - pb->copyParam.ioDirID = spec->parID; - pb->copyParam.ioNamePtr = const_cast(spec->name); - pb->copyParam.ioNewName = nil; - pb->copyParam.ioNewDirID = dest->parID; - pb->copyParam.ioCopyName = const_cast(dest->name); - - pb.StartIO(); - PBHMoveRenameAsync(&pb.fPB); - err = pb.FinishIO(); - - if (err != paramErr) - return err; - } - // = - GUSIFileSpec corner(*spec); - corner.SetParID(dest->parID); - if (corner.Exists()) { - GUSITempFileSpec temp(dest->vRefNum, dest->parID); - err = GUSIFSRename(&corner, temp->name); - if (!err) { - err = GUSIFSMoveRename1(spec, dest); - GUSIFSRename(&temp, corner->name); - } - } else - err = GUSIFSMoveRename1(spec, dest); - - return err; -} -// [[PBXGetVolInfoSync]] was a late addition to InterfaceLib, so we avoid linking to it -// and instead employ the method demonstrated in MoreFiles, calling the routine via its -// trap or via a dynamic lookup. -// -// = -#if TARGET_API_MAC_CARBON || !TARGET_RT_MAC_CFM - // Carbon builds and 68K builds don't need this glue - #define CallPBXGetVolInfoAsync PBXGetVolInfoAsync -#else // TARGET_API_MAC_CARBON || !TARGET_RT_MAC_CFM - /* This is exactly like the simple mixed mode glue in InterfaceLib in Mac OS 8.5 and 8.6 */ - static pascal OSErr PBXGetVolInfoAsyncGlue(XVolumeParamPtr paramBlock) - { - enum - { - uppFSDispatchProcInfo = kRegisterBased - | REGISTER_RESULT_LOCATION(kRegisterD0) - | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) - | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(long))) /* selector */ - | REGISTER_ROUTINE_PARAMETER(2, kRegisterD1, SIZE_CODE(sizeof(long))) /* trap word */ - | REGISTER_ROUTINE_PARAMETER(3, kRegisterA0, SIZE_CODE(sizeof(XVolumeParamPtr))) - }; - - static UniversalProcPtr fsDispatchTrapAddress = NULL; - - /* Is this the first time we've been called? */ - if ( fsDispatchTrapAddress == NULL ) - { - /* Yes - Get the trap address of _FSDispatch */ - fsDispatchTrapAddress = NGetTrapAddress(_FSDispatch, OSTrap); - } - return ( CallOSTrapUniversalProc(fsDispatchTrapAddress, - uppFSDispatchProcInfo, - kFSMXGetVolInfo, - _FSDispatch | kAsyncMask, - paramBlock) ); - } - - /* - ** PBXGetVolInfoSync was added to the File Manager in System software 7.5.2. - ** However, PBXGetVolInfoSync wasn't added to InterfaceLib until Mac OS 8.5. - ** This wrapper calls PBXGetVolInfoSync if it is found in InterfaceLib; - ** otherwise, it calls PBXGetVolInfoSyncGlue. This ensures that your program - ** is calling the latest implementation of PBXGetVolInfoSync. - */ - static pascal OSErr CallPBXGetVolInfoAsync(XVolumeParamPtr paramBlock) - { - typedef pascal OSErr (*PBXGetVolInfoProcPtr) (XVolumeParamPtr paramBlock); - - OSErr result; - CFragConnectionID connID; - static PBXGetVolInfoProcPtr PBXGetVolInfoAsyncPtr = NULL; - - //* Is this the first time we've been called? */ - if ( PBXGetVolInfoAsyncPtr == NULL ) - { - /* Yes - Get our connection ID to InterfaceLib */ - result = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kLoadCFrag, &connID, NULL, NULL); - if ( result == noErr ) - { - /* See if PBXGetVolInfoSync is in InterfaceLib */ - if ( FindSymbol(connID, "\pPBXGetVolInfoAsync", &(Ptr)PBXGetVolInfoAsyncPtr, NULL) != noErr ) - { - /* Use glue code if symbol isn't found */ - PBXGetVolInfoAsyncPtr = PBXGetVolInfoAsyncGlue; - } - } - } - /* Call PBXGetVolInfoAsync if present; otherwise, call PBXGetVolInfoAsyncGlue */ - return ( (*PBXGetVolInfoAsyncPtr)(paramBlock) ); - } -#endif // TARGET_API_MAC_CARBON || !TARGET_RT_MAC_CFM -// = -OSErr GUSIFSXGetVolInfo(GUSIIOPBWrapper * pb) -{ -#if !TARGET_API_MAC_CARBON - /* See if large volume support is available */ - long response; - if (!Gestalt(gestaltFSAttr, &response) && (response & (1L << gestaltFSSupports2TBVols))) { -#endif // !TARGET_API_MAC_CARBON - pb->StartIO(); - CallPBXGetVolInfoAsync(&pb->fPB); - return pb->FinishIO(); -#if !TARGET_API_MAC_CARBON - } else { - OSErr result = GUSIFSHGetVInfo(reinterpret_cast *>(pb)); - - if (!result) - for (VCB * vcb = (VCB *)(GetVCBQHdr()->qHead); vcb; vcb = (VCB *)(vcb->qLink)) - if (vcb->vcbVRefNum == pb->fPB.ioVRefNum) { - pb->fPB.ioVAlBlkSiz = vcb->vcbAlBlkSiz; - - return noErr; - } - return result; - } -#endif -} diff --git a/GUSI/src/tangled/GUSIFactory.cp b/GUSI/src/tangled/GUSIFactory.cp deleted file mode 100755 index fbc3c86..0000000 --- a/GUSI/src/tangled/GUSIFactory.cp +++ /dev/null @@ -1,141 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIFactory.h" -#include "GUSIDiag.h" -#include "GUSIInet.h" - -// \section{Implementation of [[GUSISocketFactory]]} -// -// We define this so compilers know where to place the vtable. Furthermore, very few -// domains provide a definition for [[socketpair]], while defining [[socket]] is -// pretty much mandatory. -// -// = -int GUSISocketFactory::socketpair(int, int, int, GUSISocket * [2]) -{ - return GUSISetPosixError(EOPNOTSUPP); -} -// = -GUSISocketDomainRegistry * GUSISocketDomainRegistry::sInstance; -// = -GUSISocketDomainRegistry::GUSISocketDomainRegistry() -{ - for (int i = 0; i= -GUSISocket * GUSISocketDomainRegistry::socket(int domain, int type, int protocol) -{ - if (!GUSI_CASSERT_CLIENT(domain >= 0 && domain < AF_MAX) || !factory[domain]) - return GUSISetPosixError(EAFNOSUPPORT), static_cast(nil); - return factory[domain]->socket(domain, type, protocol); -} -// So is [[socketpair]]. -// -// = -int GUSISocketDomainRegistry::socketpair(int domain, int type, int protocol, GUSISocket * s[2]) -{ - if (!GUSI_CASSERT_CLIENT(domain >= 0 && domain < AF_MAX) || !factory[domain]) - return GUSISetPosixError(EAFNOSUPPORT); - return factory[domain]->socketpair(domain, type, protocol, s); -} -// [[AddFactory]] and [[RemoveFactory]] add and remove a [[GUSISocketFactory]] -// for a given domain number. Both return the previous registrant. Out of range -// errors are considered internal errors rather than merely client errors. -// -// = -GUSISocketFactory * GUSISocketDomainRegistry::AddFactory(int domain, GUSISocketFactory * f) -{ - if (!GUSI_CASSERT_INTERNAL(domain >= 0 && domain < AF_MAX)) - return nil; - GUSISocketFactory * old = factory[domain]; - factory[domain] = f; - - return old; -} -// = -void GUSISocketTypeRegistry::Initialize() -{ - if (!factory) { - factory = new Entry[maxfactory]; - GUSISocketDomainRegistry::Instance()->AddFactory(domain, this); - } -} -// = -bool GUSISocketTypeRegistry::Find(int type, int protocol, bool exact, Entry *&found) -{ - Initialize(); - for (Entry * ent = factory; entfactory) { - found = ent; - return false; - } else if ( - // [[protocol]] may be specified as [[0]] in the call, but not [[type]]. - // - // type]]>= - (ent->type == type || (!exact && !ent->type)) - && // protocol]]>= - (ent->protocol == protocol || (!exact && (!ent->protocol || !protocol))) - ) { - found = ent; - return true; - } - found = nil; - return false; -} -// The [[socket]] and [[socketpair]] calls are swiftly delegated to some registered -// domain. -// -// = -GUSISocket * GUSISocketTypeRegistry::socket(int domain, int type, int protocol) -{ - Entry * ent; - bool found = Find(type, protocol, false, ent); - if (!GUSI_CASSERT_CLIENT(found)) - return GUSISetPosixError(EPROTONOSUPPORT), static_cast(nil); - return ent->factory->socket(domain, type, protocol); -} - -int GUSISocketTypeRegistry::socketpair(int domain, int type, int protocol, GUSISocket * s[2]) -{ - Entry * ent; - bool found = Find(type, protocol, false, ent); - if (!GUSI_CASSERT_CLIENT(found)) - return GUSISetPosixError(EPROTONOSUPPORT); - return ent->factory->socketpair(domain, type, protocol, s); -} -// [[AddFactory]] and [[RemoveFactory]] add and remove a [[GUSISocketFactory]] -// Both return the previous registrant. Table overflow errors are considered -// internal errors rather than merely client errors. -// -// = -GUSISocketFactory * GUSISocketTypeRegistry::AddFactory(int type, int protocol, GUSISocketFactory * f) -{ - Entry * ent; - bool previous = Find(type, protocol, true, ent); - if (!GUSI_CASSERT_INTERNAL(ent)) - return nil; - GUSISocketFactory * old = previous ? ent->factory : nil; - ent->type = type; - ent->protocol = protocol; - ent->factory = f; - - return old; -} -// [[RemoveFactory]] has to take care of keeping all valid entries together. -// -// = -GUSISocketFactory * GUSISocketTypeRegistry::RemoveFactory(int type, int protocol) -{ - Entry * ent; - if (!Find(type, protocol, true, ent)) - return nil; - GUSISocketFactory * old = ent->factory; - while (++ent - factory < maxfactory && ent->factory) - ent[-1] = ent[0]; - ent[-1].factory = nil; - - return old; -} diff --git a/GUSI/src/tangled/GUSIFileSpec.cp b/GUSI/src/tangled/GUSIFileSpec.cp deleted file mode 100755 index c7dfb84..0000000 --- a/GUSI/src/tangled/GUSIFileSpec.cp +++ /dev/null @@ -1,844 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIFileSpec.h" -#include "GUSIFSWrappers.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -// First, we test whether the path represents an encoded [FSSpec]]. This is potentially -// ambiguous, but no sane person would start a disk name with DC1. The [[ReadHex]] function, -// which only works on big endian machines, reads a specified number of hex digits. -// -// = -bool ReadHex(const char * path, int bytes, char * result) -{ - char hexbyte[3]; - hexbyte[2] = 0; - while (bytes--) { - hexbyte[0] = *path++; hexbyte[1] = *path++; - if (isxdigit(hexbyte[0]) && isxdigit(hexbyte[1])) - *result++ = (char) strtol(hexbyte, nil, 16); - else - return false; - } - return true; -} -// = -char * GUSIFileSpec::sScratch; -long GUSIFileSpec::sScratchSize; -// = -char * GUSIFileSpec::CScratch(bool extend) -{ - if (extend) { - char * newScratch = NewPtr(sScratchSize + 64); - if (!newScratch) - return nil; - BlockMoveData(sScratch, newScratch+64, sScratchSize); - sScratchSize += 64; - DisposePtr(sScratch); - - return sScratch = newScratch; - } else if (!sScratchSize) - if (sScratch = NewPtr(256)) - sScratchSize = 256; - - return sScratch; -} -// = -GUSIFileSpec::GUSIFileSpec(const GUSIFileSpec & spec) - : fValidInfo(false), fSpec(spec.fSpec), fError(spec.fError) -{ -} -// = -GUSIFileSpec::GUSIFileSpec(const FSSpec & spec, bool useAlias) - : fValidInfo(false), fSpec(spec), fError(noErr) -{ - if (!useAlias) - Resolve(); -} -// = -GUSIFileSpec::GUSIFileSpec(short vRefNum, long parID, ConstStr31Param name, bool useAlias) - : fValidInfo(false) -{ - OSErr err; - - if ((err = FSMakeFSSpec(vRefNum, parID, name, &fSpec)) && (err != fnfErr)) { - fSpec.vRefNum = vRefNum; - fSpec.parID = parID; - memcpy(fSpec.name, name, *name+1); - } - fError = noErr; - - if (!useAlias) - Resolve(); - - if (EqualString(fSpec.name, name, false, true)) - memcpy(fSpec.name, name, *name+1); -} -// = -GUSIFileSpec::GUSIFileSpec(short wd, ConstStr31Param name, bool useAlias) - : fValidInfo(false) -{ - if ((fError = FSMakeFSSpec(wd, 0, name, &fSpec)) && (fError != fnfErr)) - return; - - if (!useAlias) - Resolve(); - - if (EqualString(fSpec.name, name, false, true)) - memcpy(fSpec.name, name, *name+1); -} -// = -GUSIFileSpec::GUSIFileSpec(OSType object, short vol) - : fValidInfo(false) -{ - fError = FindFolder(vol, object, true, &fSpec.vRefNum, &fSpec.parID); -} -// = -GUSIFileSpec::GUSIFileSpec(short fRefNum) - : fValidInfo(false) -{ - GUSIIOPBWrapper fcb; - - fcb->ioNamePtr = fSpec.name; - fcb->ioRefNum = fRefNum; - fcb->ioFCBIndx = 0; - - if (fError = GUSIFSGetFCBInfo(&fcb)) - return; - - fSpec.vRefNum = fcb->ioFCBVRefNum; - fSpec.parID = fcb->ioFCBParID; -} -// The pathname constructor is by far the most complex constructor. This code is also -// probably not portable to Rhapsody, whatever and whenever that will be. -// -// To minimize the number of [[CatInfo]] calls necessary, the [[fullSpec]] variable -// reflects whether the entire [[FSSpec]] under construction or only the [[vRefNum]] -// and [[parID]] are valid. -// -// = -GUSIFileSpec::GUSIFileSpec(const char * path, bool useAlias) - : fValidInfo(false) -{ - const char * nextPath; - bool fullSpec = false; - - fSpec.vRefNum = 0; - fSpec.parID = 0; - - // = - if (*path == 0x11 && path[13] == ':') // Magic DC1 character - if ( - !ReadHex(path+1, 2, (char *)&fSpec.vRefNum) || !ReadHex(path+5, 4, (char *)&fSpec.parID) - ) { - fSpec.vRefNum = 0; - fSpec.parID = 0; - } else - path += 13; - // = - if (!fSpec.vRefNum && !fSpec.parID) - GetDefaultDirectory(); - int pathLen = (int)strlen(path); - StringPtr ppath = PScratch(); - if (pathLen < 256 && ppath) { - memcpy(ppath+1, path, ppath[0] = pathLen); - - short saveVRefNum = fSpec.vRefNum; - long saveParID = fSpec.parID; - - switch (fError = FSMakeFSSpec(fSpec.vRefNum, fSpec.parID, ppath, &fSpec)) { - case fnfErr: - fError = noErr; - - return; - case noErr: - if (!useAlias) - Resolve(); - - while ((nextPath = strchr(path, ':')) && nextPath[1]) - path = nextPath+1; - memcpy(ppath+1, path, ppath[0] = strlen(path) - (nextPath != 0)); - if (EqualString(fSpec.name, ppath, false, true)) - memcpy(fSpec.name, ppath, ppath[0]+1); - - return; - default: - fSpec.vRefNum = saveVRefNum; - fSpec.parID = saveParID; - break; - } - } - // For relative paths, we now skip a leading colon. For absolute paths, we get - // the volume information. [[fullSpec]] is true for absolute paths, but not for - // relative paths. - // - // = - if (path[0] == ':') { - ++path; - } else if (nextPath = strchr(path, ':')) { - if (nextPath - (char *) path > 62) { - fError = bdNamErr; - - return; - } - - memcpy(fSpec.name+1, (char *) path, fSpec.name[0] = nextPath - path); - - if (GetVolume()) - return; - - path = nextPath + 1; - fullSpec = true; - } - - fError = noErr; - while (*path && !fError) { - if (*path == ':') { - // Going upwards is a bit more complicated than might seem necessary at first, because - // if [["a:b"]] is an alias pointing to [["c:d:e:"]], we want a:b::"]] to be the same as - // [["c:d:"]]. - // - // = - if (!fullSpec) - --(*this); - if (!fError) - Resolve(); - fullSpec = false; - while (!fError && *++path == ':') - --(*this); - } else { - if (nextPath = strchr(path, ':')) { - AddPathComponent(path, nextPath-path, fullSpec); - fullSpec = true; - path = nextPath+1; - } else { - AddPathComponent(path, strlen(path), fullSpec); - fullSpec = true; - break; - } - } - } - if (!fError) { - if (!fullSpec) - --(*this); - if (!useAlias) - Resolve(); - } else if (*path && fError == fnfErr) { - fError = dirNFErr; - } -} -// If [[name]] is used, we have to make sure that it ends with a colon. -// -// = -OSErr GUSIFileSpec::GetVolume(short index) -{ - fValidInfo = false; - if (fSpec.name[0] || index>=0) { - GUSIIOPBWrapper vol; - - vol->volumeParam.ioVRefNum = fSpec.vRefNum; - vol->volumeParam.ioNamePtr = fSpec.name; - vol->volumeParam.ioVolIndex = index; - - if (index < 0 && fSpec.name[fSpec.name[0]] != ':') - fSpec.name[++fSpec.name[0]] = ':'; - - if (fError = GUSIFSGetVInfo(&vol)) - return fError; - - fSpec.vRefNum = vol->volumeParam.ioVRefNum; - } else { - fError = noErr; - fSpec.vRefNum = 0; - } - fSpec.parID = fsRtParID; - - return fError; -} -// [[operator--]] replaces file specifications with their parent directory, volumes with -// the root pseudo directory. -// -// = -GUSIFileSpec & GUSIFileSpec::operator--() -{ - if (fSpec.parID == fsRtParID) { - fSpec.vRefNum = ROOT_MAGIC_COOKIE; - fSpec.parID = 0; - fSpec.name[0] = 0; - fError = noErr; - fValidInfo = false; - } else - DirInfo(); - - return *this; -} -// [[operator++]] walks down one path component. -// -// = -GUSIFileSpec & GUSIFileSpec::operator++() -{ - if (!fSpec.parID && fSpec.vRefNum == ROOT_MAGIC_COOKIE) { - fSpec.vRefNum = 0; - fSpec.parID = fsRtParID; - fSpec.name[0] = 0; - fValidInfo = false; - - goto punt; - } - - if (!CatInfo()) - goto punt; - if (fInfo->IsAlias()) - if (Resolve() || !CatInfo()) - goto punt; - if (fInfo->IsFile()) { - fError = afpObjectTypeErr; - - goto punt; - } - - fSpec.parID = fInfo->DirInfo().ioDrDirID; - fSpec.name[0] = 0; - fValidInfo = false; - -punt: - return *this; -} -// [AddPathComponent]] is the basic operation for descending a directory hierarchy. -// -// = -GUSIFileSpec & GUSIFileSpec::AddPathComponent(const char * name, int length, bool fullSpec) -{ - if (length > 63) { - fError = bdNamErr; - - goto punt; - } - - if (fullSpec) - if (!++(*this)) - goto punt; - - memcpy(fSpec.name+1, name, fSpec.name[0] = length); - fValidInfo = false; - - if (fSpec.parID == fsRtParID) - GetVolume(); - -punt: - return *this; -} -// = -GUSIFileSpec operator+(const FSSpec & spec, ConstStr31Param name) -{ - GUSIFileSpec s(spec); - - return s += name; -} - -GUSIFileSpec operator+(const FSSpec & spec, const char * name) -{ - GUSIFileSpec s(spec); - - return s += name; -} -// = -GUSIFileSpec & GUSIFileSpec::operator[](short index) -{ - if (fSpec.parID == fsRtParID) - GetVolume(index); - else - CatInfo(index); - - return *this; -} -// = -void GUSIFileSpec::SetVRef(short vref) -{ - fSpec.vRefNum = vref; - fValidInfo = false; -} - -void GUSIFileSpec::SetParID(long parid) -{ - fSpec.parID = parid; - fValidInfo = false; -} - -void GUSIFileSpec::SetName(ConstStr63Param name) -{ - PLstrcpy(fSpec.name, name); - fValidInfo = false; -} - -void GUSIFileSpec::SetName(const char * name) -{ - memcpy(fSpec.name+1, name, fSpec.name[0] = strlen(name)); - fValidInfo = false; -} -// = -OSErr GUSIFileSpec::TouchFolder() -{ - GUSIFileSpec folder(*this, true); - - if (!folder.DirInfo()) - return fError = folder.Error(); - - GetDateTime(&folder.fInfo->DirInfo().ioDrMdDat); - folder.fInfo->DirInfo().ioDrDirID = folder.fInfo->DirInfo().ioDrParID; - - return fError = GUSIFSSetCatInfo(&folder.fInfo); -} -// The sort of information obtained depends on the [[index]] parameter. -// -// = -const GUSICatInfo * GUSIFileSpec::CatInfo(short index) -{ - if (fValidInfo && !index) // Valid already - return &fInfo.fPB; - - fInfo->DirInfo().ioVRefNum = fSpec.vRefNum; - fInfo->DirInfo().ioDrDirID = fSpec.parID; - fInfo->DirInfo().ioNamePtr = (StringPtr) fSpec.name; - fInfo->DirInfo().ioFDirIndex = index; - fInfo->DirInfo().ioACUser = 0; - - fValidInfo = !(fError = GUSIFSGetCatInfo(&fInfo)) && index>=0; - - return fError ? nil : &fInfo.fPB; -} -// We start the path getting functions with the full path. The full and relative -// path functions are quite similar, iterating a file specification [[current]] -// upward, accumulating the path in [[path]]. -// -// = -char * GUSIFileSpec::FullPath() const -{ - char * path = CScratch(); - GUSIFileSpec current(*this); - const GUSICatInfo * info = current.CatInfo(); - bool directory = info && !info->IsFile(); - - if (!path) - return nil; - *(path += sScratchSize-1) = 0; - - for (;;) { - if (PrependPathComponent(path, current.fSpec.name, directory)) - return nil; - directory = current.fSpec.name[0] != 0; - if (current.fSpec.parID == fsRtParID) - return path; - if (!--current) - return nil; - } -} -// = -OSErr GUSIFileSpec::PrependPathComponent(char *&path, ConstStr63Param component, bool colon) const -{ - if (colon) - *--path = ':'; - if (path-sScratch < *component+1) { - long length = sScratch+sScratchSize-path; - if (!CScratch(true)) - return GUSI_MUTABLE(GUSIFileSpec, fError) = -108; - path = sScratch+sScratchSize-length; - } - memcpy(path -= *component, component+1, *component); - return noErr; -} -// [[RelativePath]] works similarly, but has to compare with the stop directory -// at each step. [[GetVolume]] is called to translate all drive numbers to real -// volume numbers. -// -// = -char * GUSIFileSpec::RelativePath(const FSSpec & dir) const -{ - GUSIFileSpec current(dir); - if (current.fSpec.name[0]) - ++current; - long relDirID= current.fSpec.parID; - if (current.GetVolume(0)) - return FullPath(); - short relVRef = current.fSpec.vRefNum; - current = *this; - if (current.GetVolume(0) || current.fSpec.vRefNum != relVRef) - return FullPath(); - - current = *this; - - char * path = CScratch(); - const GUSICatInfo * info = current.CatInfo(); - bool directory = info && !info->IsFile(); - - if (!path) - return nil; - if (directory && info->DirInfo().ioDrDirID == relDirID) - return strcpy(path, ":"); - *(path += sScratchSize-1) = 0; - - for (;;) { - if (PrependPathComponent(path, current.fSpec.name, directory)) - return nil; - if (current.fSpec.parID == relDirID) { - if (directory) - *--path = ':'; - return path; - } - directory = current.fSpec.name[0] != 0; - if (current.fSpec.parID == fsRtParID) - return path; - if (!--current) - return nil; - } -} -// = -char * GUSIFileSpec::RelativePath() const -{ - GUSIFileSpec here; - here.GetDefaultDirectory(); - return RelativePath(here); -} -// Encoding is simple. Note the use of the [["%#s"]] Metrowerks specific extension. -// -// = -char * GUSIFileSpec::EncodedPath() const -{ - if (!CScratch()) - return nil; - - GUSI_sprintf(sScratch, "\021%04hX%08X:%#s", fSpec.vRefNum, fSpec.parID, fSpec.name); - - return sScratch; -} -// = -OSErr GUSIFileSpec::Resolve(bool gently) -{ - const GUSICatInfo * info = CatInfo(); - - if (!info || (!info->IsAlias() && (fError = resFNotFound))) - if (gently) - return fError = noErr; - else - return fError; - - Boolean isFolder; - Boolean wasAlias; - - fValidInfo = false; - - return fError = ResolveAliasFile(&fSpec, true, &isFolder, &wasAlias); -} -// Getting the target of an alias without resolving it is quite tricky. We have to guess -// whether the target is a file or a directory. -// -// = -char * GUSIFileSpec::AliasPath() const -{ - const GUSICatInfo * info = CatInfo(); - if (!info || (!info->IsAlias() && (GUSI_MUTABLE(GUSIFileSpec, fError) = resFNotFound))) - return nil; - - char * path = CScratch(); - if (!path) - return nil; - *(path += sScratchSize-1) = 0; - - AliasHandle alias; - // = - short oldRes = CurResFile(); - short res = FSpOpenResFile(&fSpec, fsRdPerm); - if (res == -1) { - GUSI_MUTABLE(GUSIFileSpec, fError) = ResError(); - alias = nil; - } else { - if (alias = (AliasHandle) Get1Resource('alis', 0)) - DetachResource((Handle) alias); - else - GUSI_MUTABLE(GUSIFileSpec, fError) = ResError(); - - CloseResFile(res); - } - UseResFile(oldRes); - - if (!alias) - return nil; - bool directory; - // We have to guess whether the alias points at a file or a directory, but if the alias - // was constructed by GUSI or by the Finder, this guess should be correct (though not - // necessarily up to date). - // - // = - directory = false; - if (info->FInfo().fdCreator == 'MACS') - switch (info->FInfo().fdType) { - case 'srvr': - case 'fadr': - case 'faet': - case 'hdsk': - case 'famn': - case 'fash': - case 'fdrp': - directory = true; - } - Str63 component; - - /* - Build path from target up to root. Separate with colons. - */ - for (short index = 0; - !(GUSI_MUTABLE(GUSIFileSpec, fError) = GetAliasInfo(alias, index, component)); - ++index - ) - if (!*component || PrependPathComponent(path, component, directory)) - break; - else - directory = true; - - if (!fError - && !(GUSI_MUTABLE(GUSIFileSpec, fError) = GetAliasInfo(alias, asiVolumeName, component)) - ) - PrependPathComponent(path, component, true); - - DisposeHandle((Handle) alias); - - return fError ? nil : path; -} -// Comparisons are again a bit tricky because of the volume numbers. -// -// = -bool operator==(const GUSIFileSpec & one, const GUSIFileSpec & other) -{ - if (one.fSpec.parID != other.fSpec.parID || !EqualString(one.fSpec.name, other.fSpec.name, false, true)) - return false; - if (one.fSpec.vRefNum == other.fSpec.vRefNum) - return true; - GUSIFileSpec current; - current = one; - current.GetVolume(0); - short vRef1 = current.fSpec.vRefNum; - current = other; - current.GetVolume(0); - short vRef2 = current.fSpec.vRefNum; - - return vRef1 == vRef2; -} -// = -bool GUSIFileSpec::IsParentOf(const GUSIFileSpec & other) const -{ - for (GUSIFileSpec current(other); !(--current).Error();) - if (current == *this) - return true; - - return false; -} -// The constructors for [[GUSITempFileSpec]] differ in the base -// constructors they call. -// -// = -GUSITempFileSpec::GUSITempFileSpec(short vRefNum) - : GUSIFileSpec(kTemporaryFolderType, vRefNum) -{ - TempName(); -} -GUSITempFileSpec::GUSITempFileSpec(short vRefNum, long parID) -{ - SetVRef(vRefNum); - SetParID(parID); - - TempName(); -} -// Optionally, a base name can be specified for a temporary name. -// -// = -GUSITempFileSpec::GUSITempFileSpec(ConstStr63Param basename) - : GUSIFileSpec(kTemporaryFolderType, kOnSystemDisk) -{ - TempName(basename); -} -GUSITempFileSpec::GUSITempFileSpec(short vRefNum, ConstStr31Param basename) - : GUSIFileSpec(kTemporaryFolderType, vRefNum) -{ - TempName(basename); -} -GUSITempFileSpec::GUSITempFileSpec(short vRefNum, long parID, ConstStr31Param basename) -{ - SetVRef(vRefNum); - SetParID(parID); - - TempName(basename); -} -// The names are searched by [[TempName]]. To avoid excessive searching, each -// search starts at a new location. -// -// = -int GUSITempFileSpec::sID = 0; - -void GUSITempFileSpec::TempName() -{ - for (;;) { - char name[8]; - - GUSI_sprintf(name, "tmp%04d", sID++); - SetName(name); - - sID %= 10000; - fValidInfo = false; - if (!Exists()) { - if (fError == fnfErr) - fError = noErr; - return; - } - } -} -// The search with an existing base name is a slight variation on the above. -// -// = -void GUSITempFileSpec::TempName(ConstStr31Param basename) -{ - for (int id = 0;;++id) { - Str32 name; - int len = 2; - - if (id < 10) - ; - else if (id < 100) - len = 3; - else if (id < 1000) - len = 4; - else if (id < 10000) - len = 5; - else { - fError = fnfErr; - return; - } - - // I think it looks a bit prettier if the number is stuck before the first dot, instead of at the end. - // - // = - if (!id) { - memcpy(name, basename, *basename+1); - } else if (*basename + len > 31) { - name[0] = 30; - memcpy(name+1, basename+1, 31-len); - GUSI_sprintf(reinterpret_cast(name+32-len), "%d", id); - } else { - name[0] = *basename + len; - unsigned char * period = reinterpret_cast(memchr(basename+1, '.', *basename)); - int prelen = period ? (period-basename)-1 : *basename; - memcpy(name+1, basename+1, prelen); - GUSI_sprintf(reinterpret_cast(name+1+prelen), ".%d", id); - memcpy(name+1+prelen+len, period, *basename-prelen); - } - SetName(name); - - fValidInfo = false; - if (!Exists()) { - if (fError == fnfErr) - fError = noErr; - return; - } - } -} -// \section{Implementation of C APIs to [[GUSIFileSpec]]} -// -// The C API is fairly easy to implement. We move the common parts of the [[FSSpec]] constructors -// into an auxiliary procedure. -// -// = -static OSErr GUSIFileSpec2FSp(const GUSIFileSpec & spec, FSSpec * desc) -{ - if (!spec.Error()) - *desc = spec; - - return spec.Error(); -} -// The constructors now turn into one liners. -// -// = -OSErr GUSIFRefNum2FSp(short fRefNum, FSSpec * desc) - { return GUSIFileSpec2FSp(GUSIFileSpec(fRefNum), desc); } -OSErr GUSIWD2FSp(short wd, ConstStr31Param name, FSSpec * desc) - { return GUSIFileSpec2FSp(GUSIFileSpec(wd, name, true), desc); } -OSErr GUSIPath2FSp(const char * path, FSSpec * desc) - { return GUSIFileSpec2FSp(GUSIFileSpec(path, true), desc); } -OSErr GUSISpecial2FSp(OSType object, short vol, FSSpec * desc) - { return GUSIFileSpec2FSp(GUSIFileSpec(object, vol), desc); } -// The temporary constructor is only a little bit trickier. -// -// = -OSErr GUSIMakeTempFSp(short vol, long dirID, FSSpec * desc) - { return GUSIFileSpec2FSp((dirID ? GUSITempFileSpec(vol, dirID) : GUSITempFileSpec(vol)), desc); } -// The manipulators look a bit like constructors. -// -// -// = -OSErr GUSIFSpUp(FSSpec * desc) - { return GUSIFileSpec2FSp(--GUSIFileSpec(*desc, true), desc); } -OSErr GUSIFSpDown(FSSpec * desc, ConstStr31Param name) - { return GUSIFileSpec2FSp(*desc+name, desc); } -OSErr GUSIFSpIndex(FSSpec * desc, short n) - { GUSIFileSpec spec(*desc); return GUSIFileSpec2FSp(spec[n], desc); } -OSErr GUSIFSpResolve(FSSpec * desc) - { return GUSIFileSpec2FSp(GUSIFileSpec(*desc), desc); } -// The deconstructors are two liners anyway. -// -// = -char * GUSIFSp2FullPath(const FSSpec * desc) -{ - GUSIFileSpec spec(*desc, true); - - return spec.FullPath(); -} - -char * GUSIFSp2RelPath(const FSSpec * desc) -{ - GUSIFileSpec spec(*desc, true); - - return spec.RelativePath(); -} - -char * GUSIFSp2DirRelPath(const FSSpec * desc, const FSSpec * dir) -{ - GUSIFileSpec spec(*desc, true); - - return spec.RelativePath(*dir); -} - -char * GUSIFSp2Encoding(const FSSpec * desc) -{ - GUSIFileSpec spec(*desc, true); - - return spec.EncodedPath(); -} -// = -OSErr GUSIFSpTouchFolder(const FSSpec * desc) -{ - GUSIFileSpec spec(*desc); - - return spec.TouchFolder(); -} - -OSErr GUSIFSpGetCatInfo(FSSpec * desc, CInfoPBRec * info) -{ - GUSIFileSpec spec(*desc); - const GUSICatInfo * gci = spec.CatInfo(); - - if (gci) { - *info = gci->Info(); - *desc = spec; - info->hFileInfo.ioNamePtr = desc->name; - } - - return spec.Error(); -} diff --git a/GUSI/src/tangled/GUSIForeignThreads.cp b/GUSI/src/tangled/GUSIForeignThreads.cp deleted file mode 100755 index 7726036..0000000 --- a/GUSI/src/tangled/GUSIForeignThreads.cp +++ /dev/null @@ -1,190 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIContext.h" - -#include -#include - -// \section{Interfacing to the Thread Manager routines} -// -// As mentioned above, our interface strategy differs for non-CFM and CFM code. We try -// to handle this with a macro. As opposed to the MPW interface, we have to handle CFM68K. -// -// = -extern "C" { -#if !TARGET_RT_MAC_CFM -#define DECL_thread(name, pname, ret, args) ret name args; -#ifdef __MWERKS__ -#pragma pointers_in_D0 -#endif -// Now we only have to declare the list once, and can reuse it numerous times. -// -// = -DECL_thread(GUSIStdNewThread, "\pNewThread", OSErr, - (ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, - void *threadParam, Size stackSize, ThreadOptions options, - void **threadResult, ThreadID *threadMade)) -DECL_thread(GUSIStdSetThreadSwitcher, "\pSetThreadSwitcher", OSErr, - (ThreadID thread, ThreadSwitchProcPtr threadSwitcher, - void *switchProcParam, Boolean inOrOut)) -DECL_thread(GUSIStdSetThreadTerminator, "\pSetThreadTerminator", OSErr, - (ThreadID thread, ThreadTerminationProcPtr threadTerminator, - void *terminationProcParam)) -#ifdef __MWERKS__ -#pragma pointers_in_A0 -#endif -static bool ConnectToThreadLibrary() { return true; } -#define sGUSIThreadFailure 0 -#else -#define DECL_thread(name, pname, ret, args) static ret (*name) args; -// Now we only have to declare the list once, and can reuse it numerous times. -// -// = -DECL_thread(GUSIStdNewThread, "\pNewThread", OSErr, - (ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, - void *threadParam, Size stackSize, ThreadOptions options, - void **threadResult, ThreadID *threadMade)) -DECL_thread(GUSIStdSetThreadSwitcher, "\pSetThreadSwitcher", OSErr, - (ThreadID thread, ThreadSwitchProcPtr threadSwitcher, - void *switchProcParam, Boolean inOrOut)) -DECL_thread(GUSIStdSetThreadTerminator, "\pSetThreadTerminator", OSErr, - (ThreadID thread, ThreadTerminationProcPtr threadTerminator, - void *terminationProcParam)) -// On PowerPC, we have to connect to the dynamic library (which, in principle, -// can fail). -// -// = -static OSErr sGUSIThreadFailure = 1; - -static void DoConnectToThreadLibrary() -{ - CFragConnectionID ThreadsLib; - CFragSymbolClass symClass; - Ptr whoCares; - Str255 error; - - if (sGUSIThreadFailure = GetSharedLibrary( - StringPtr("\pThreadsLib"), kPowerPCCFragArch, kLoadCFrag, - &ThreadsLib, &whoCares, error) - ) - return; - -#undef DECL_thread -#define DECL_thread(name, pname, ret, args) \ - if (sGUSIThreadFailure = FindSymbol(ThreadsLib, pname, (Ptr *) &name, &symClass)) \ - goto failed; - // Now we only have to declare the list once, and can reuse it numerous times. - // - // = - DECL_thread(GUSIStdNewThread, "\pNewThread", OSErr, - (ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, - void *threadParam, Size stackSize, ThreadOptions options, - void **threadResult, ThreadID *threadMade)) - DECL_thread(GUSIStdSetThreadSwitcher, "\pSetThreadSwitcher", OSErr, - (ThreadID thread, ThreadSwitchProcPtr threadSwitcher, - void *switchProcParam, Boolean inOrOut)) - DECL_thread(GUSIStdSetThreadTerminator, "\pSetThreadTerminator", OSErr, - (ThreadID thread, ThreadTerminationProcPtr threadTerminator, - void *terminationProcParam)) - - return; - -failed: -#undef DECL_thread -#define DECL_thread(name, pname, ret, args) name = 0; - // Now we only have to declare the list once, and can reuse it numerous times. - // - // = - DECL_thread(GUSIStdNewThread, "\pNewThread", OSErr, - (ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, - void *threadParam, Size stackSize, ThreadOptions options, - void **threadResult, ThreadID *threadMade)) - DECL_thread(GUSIStdSetThreadSwitcher, "\pSetThreadSwitcher", OSErr, - (ThreadID thread, ThreadSwitchProcPtr threadSwitcher, - void *switchProcParam, Boolean inOrOut)) - DECL_thread(GUSIStdSetThreadTerminator, "\pSetThreadTerminator", OSErr, - (ThreadID thread, ThreadTerminationProcPtr threadTerminator, - void *terminationProcParam)) -} - -static bool ConnectToThreadLibrary() -{ - if (sGUSIThreadFailure == 1) - DoConnectToThreadLibrary(); - return !sGUSIThreadFailure; -} -#endif -} -// \section{Redirecting thread manager calls to their GUSI equivalents} -// -// People naively using thread manager calls will find themselves redirected to GUSI routines instead. -// -// = -pascal OSErr NewThread( - ThreadStyle style, ThreadEntryProcPtr entry, void *param, - Size stack, ThreadOptions options, void **result, ThreadID *made) -{ - return GUSINewThread(style, entry, param, stack, options, result, made); -} - -pascal OSErr SetThreadSwitcher( - ThreadID thread, ThreadSwitchProcPtr switcher, void *param, Boolean inOrOut) -{ - return GUSISetThreadSwitcher(thread, switcher, param, inOrOut); -} - -pascal OSErr SetThreadTerminator( - ThreadID thread, ThreadTerminationProcPtr terminator, void *terminatorParam) -{ - return GUSISetThreadTerminator(thread, terminator, terminatorParam); -} -// \section{Installing our GUSI thread manager hooks} -// -// [[GUSIThreadManagerForeignProxy]] is now quite straighforward. -// -// = -class GUSIThreadManagerForeignProxy : public GUSIThreadManagerProxy { -public: - virtual OSErr NewThread( - ThreadStyle style, ThreadEntryProcPtr entry, void *param, - Size stack, ThreadOptions options, void **result, ThreadID *made); - virtual OSErr SetThreadSwitcher(ThreadID thread, - ThreadSwitchProcPtr switcher, void *switchProcParam, Boolean inOrOut); - virtual OSErr SetThreadTerminator(ThreadID thread, - ThreadTerminationProcPtr terminator, void *terminatorParam); -}; -// Finally, to make sure that these hooks are called, we sneak in and replace [[GUSIThreadManagerProxy::MakeInstance]]. -// -// = -GUSIThreadManagerProxy * GUSIThreadManagerProxy::MakeInstance() -{ - return new GUSIThreadManagerForeignProxy; -} -// Note that the calls below resolve to a statically linked procedure on non-CFM, but call through an indirect procedure pointer on -// CFM. -// -// = -OSErr GUSIThreadManagerForeignProxy::NewThread( - ThreadStyle style, ThreadEntryProcPtr entry, void *param, - Size stack, ThreadOptions options, void **result, ThreadID *made) -{ - if (!ConnectToThreadLibrary()) - return sGUSIThreadFailure; - return GUSIStdNewThread(style, entry, param, stack, options, result, made); -} - -OSErr GUSIThreadManagerForeignProxy::SetThreadSwitcher( - ThreadID thread, ThreadSwitchProcPtr switcher, void *param, Boolean inOrOut) -{ - if (!ConnectToThreadLibrary()) - return sGUSIThreadFailure; - return GUSIStdSetThreadSwitcher(thread, switcher, param, inOrOut); -} - -OSErr GUSIThreadManagerForeignProxy::SetThreadTerminator( - ThreadID thread, ThreadTerminationProcPtr terminator, void *terminatorParam) -{ - if (!ConnectToThreadLibrary()) - return sGUSIThreadFailure; - return GUSIStdSetThreadTerminator(thread, terminator, terminatorParam); -} diff --git a/GUSI/src/tangled/GUSIInet.cp b/GUSI/src/tangled/GUSIInet.cp deleted file mode 100755 index b0623cf..0000000 --- a/GUSI/src/tangled/GUSIInet.cp +++ /dev/null @@ -1,20 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIInet.h" -#include "GUSIMTInet.h" -#include "GUSIOpenTransport.h" -#include "GUSIOTInet.h" - -#include -#include - -GUSISocketTypeRegistry gGUSIInetFactories(AF_INET, 8); - -// = -void GUSIwithInetSockets() -{ - if (GUSIOTFactory::Initialize()) - GUSIwithOTInetSockets(); - else - GUSIwithMTInetSockets(); -} diff --git a/GUSI/src/tangled/GUSIMPW.cp b/GUSI/src/tangled/GUSIMPW.cp deleted file mode 100755 index c6e4e2f..0000000 --- a/GUSI/src/tangled/GUSIMPW.cp +++ /dev/null @@ -1,475 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIMPW.h" -#include "GUSIDevice.h" -#include "GUSIDescriptor.h" -#include "GUSIMacFile.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" -#include "GUSITimer.h" -#include "GUSIConfig.h" - -#include -#include -#include -#include - -#include - -#include - -// \section{Interfacing to MPW library routines} -// -// As mentioned above, our interface strategy differs for 68K and PPC code. We try -// to handle this with a macro. -// -// = -extern "C" { -#if !defined(powerc) && !defined(__powerc) -#define DECL_stdlib(name, pname, ret, args) ret name args; -#ifdef __MWERKS__ -#pragma pointers_in_D0 -#endif -// Now we only have to declare the list once, and can reuse it numerous times. -// -// = -DECL_stdlib(MPW_open, "\popen", int, (const char * name, int flags)) -DECL_stdlib(MPW_close, "\pclose", int, (int s)) -DECL_stdlib(MPW_read, "\pread", int, (int s, char *buffer, unsigned buflen)) -DECL_stdlib(MPW_write, "\pwrite", int, (int s, char *buffer, unsigned buflen)) -DECL_stdlib(MPW_fcntl, "\pfcntl", int, (int s, unsigned int cmd, int arg)) -DECL_stdlib(MPW_ioctl, "\pioctl", int, (int d, unsigned int request, long *argp)) -DECL_stdlib(MPW_lseek, "\plseek", long, (int fd, long offset, int whence)) -DECL_stdlib(MPW_faccess, "\pfaccess", int, (char *fileName, unsigned int cmd, long * arg)) -DECL_stdlib(MPW_getenv, "\pgetenv", char *, (const char *env)) -#ifdef __MWERKS__ -#pragma pointers_in_A0 -#endif -static bool ConnectToMPWLibrary() { return true; } -#ifdef __MWERKS__ -extern int _mpwerrno; -static void UpdateMPWErrno() { errno = _mpwerrno; } -#else -static void UpdateMPWErrno() { } -#endif -#else -#define DECL_stdlib(name, pname, ret, args) ret (*name) args; -// Now we only have to declare the list once, and can reuse it numerous times. -// -// = -DECL_stdlib(MPW_open, "\popen", int, (const char * name, int flags)) -DECL_stdlib(MPW_close, "\pclose", int, (int s)) -DECL_stdlib(MPW_read, "\pread", int, (int s, char *buffer, unsigned buflen)) -DECL_stdlib(MPW_write, "\pwrite", int, (int s, char *buffer, unsigned buflen)) -DECL_stdlib(MPW_fcntl, "\pfcntl", int, (int s, unsigned int cmd, int arg)) -DECL_stdlib(MPW_ioctl, "\pioctl", int, (int d, unsigned int request, long *argp)) -DECL_stdlib(MPW_lseek, "\plseek", long, (int fd, long offset, int whence)) -DECL_stdlib(MPW_faccess, "\pfaccess", int, (char *fileName, unsigned int cmd, long * arg)) -DECL_stdlib(MPW_getenv, "\pgetenv", char *, (const char *env)) -int * MPW_errno; -static void UpdateMPWErrno() { errno = *MPW_errno; } -// On PowerPC, we have to connect to the dynamic library (which, in principle, -// can fail). -// -// = -static bool sConnected; - -static void DoConnectToMPWLibrary() -{ - CFragConnectionID StdCLib; - CFragSymbolClass symClass; - Ptr whoCares; - Str255 error; - - if (GetSharedLibrary( - StringPtr("\pStdCLib"), kPowerPCCFragArch, kLoadCFrag, &StdCLib, &whoCares, error) - ) - return; - - if (FindSymbol(StdCLib, "\perrno", (Ptr *) &MPW_errno, &symClass)) - goto failed; -#undef DECL_stdlib -#define DECL_stdlib(name, pname, ret, args) \ - if (FindSymbol(StdCLib, pname, (Ptr *) &name, &symClass)) \ - goto failed; - // Now we only have to declare the list once, and can reuse it numerous times. - // - // = - DECL_stdlib(MPW_open, "\popen", int, (const char * name, int flags)) - DECL_stdlib(MPW_close, "\pclose", int, (int s)) - DECL_stdlib(MPW_read, "\pread", int, (int s, char *buffer, unsigned buflen)) - DECL_stdlib(MPW_write, "\pwrite", int, (int s, char *buffer, unsigned buflen)) - DECL_stdlib(MPW_fcntl, "\pfcntl", int, (int s, unsigned int cmd, int arg)) - DECL_stdlib(MPW_ioctl, "\pioctl", int, (int d, unsigned int request, long *argp)) - DECL_stdlib(MPW_lseek, "\plseek", long, (int fd, long offset, int whence)) - DECL_stdlib(MPW_faccess, "\pfaccess", int, (char *fileName, unsigned int cmd, long * arg)) - DECL_stdlib(MPW_getenv, "\pgetenv", char *, (const char *env)) - - sConnected = true; - - return; - -failed: -#undef DECL_stdlib -#define DECL_stdlib(name, pname, ret, args) name = 0; - - // Now we only have to declare the list once, and can reuse it numerous times. - // - // = - DECL_stdlib(MPW_open, "\popen", int, (const char * name, int flags)) - DECL_stdlib(MPW_close, "\pclose", int, (int s)) - DECL_stdlib(MPW_read, "\pread", int, (int s, char *buffer, unsigned buflen)) - DECL_stdlib(MPW_write, "\pwrite", int, (int s, char *buffer, unsigned buflen)) - DECL_stdlib(MPW_fcntl, "\pfcntl", int, (int s, unsigned int cmd, int arg)) - DECL_stdlib(MPW_ioctl, "\pioctl", int, (int d, unsigned int request, long *argp)) - DECL_stdlib(MPW_lseek, "\plseek", long, (int fd, long offset, int whence)) - DECL_stdlib(MPW_faccess, "\pfaccess", int, (char *fileName, unsigned int cmd, long * arg)) - DECL_stdlib(MPW_getenv, "\pgetenv", char *, (const char *env)) -} - -static bool ConnectToMPWLibrary() -{ - if (!sConnected) - DoConnectToMPWLibrary(); - return sConnected; -} -#endif -} -// \section{Definition of [[GUSIMPWSocket]]} -// -// A [[GUSIMPWSocket]] is a proxy class for an MPW file descriptor. -// -// -// = -class GUSIMPWSocket : public GUSISocket { -public: - ~GUSIMPWSocket(); - - // Some member functions are fairly trivial wrappers. - // - // = - ssize_t read(const GUSIScatterer & buffer); - // = - ssize_t write(const GUSIGatherer & buffer); - // = - virtual off_t lseek(off_t offset, int whence); - // [[fcntl]] and [[ioctl]] have to get their final arguments from [[va_lists]]. - // - // = - virtual int fcntl(int cmd, va_list arg); - // = - virtual int ioctl(unsigned int request, va_list arg); - // [[ftruncate]] translates into an [[ioctl]] request. - // - // = - virtual int ftruncate(off_t offset); - // Since we know we're running on a pseudodevice, we can pass on that fact. - // - // = - virtual int fstat(struct stat * buf); - // And we also know we're a TTY. - // - // = - virtual int isatty(); - // We have no choice but to be optimistic and claim that we are always ready for - // reading and writing. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * exception); -protected: - friend class GUSIMPWDevice; - - GUSIMPWSocket(int fd); -private: - int fFD; -}; -// \section{Definition of [[GUSIMPWDevice]]} -// -// A [[GUSIMPWDevice]] is a singleton class supporting the standard [[open]] and -// [[faccess]] operations and a domain specific [[stdopen]] operation to support -// opening already-open descriptors. -// -// = -class GUSIMPWDevice : public GUSIDevice { -public: - static GUSIMPWDevice * Instance(); - - // [[GUSIMPWDevice]] is prepared to handle an [[open]] on a limited set of device names - // and on all files. - // - // = - virtual bool Want(GUSIFileToken & file); - // = - virtual GUSISocket * open(GUSIFileToken &, int flags); - - GUSISocket * stdopen(int fd, int flags); -private: - GUSIMPWDevice() {} - - static GUSIMPWDevice * sInstance; -}; -// \section{Implementation of [[GUSIMPWSocket]]} -// -// A [[GUSIMPWSocket]] acts as a wrapper for a file descriptor from the MPW library. -// -// = -GUSIMPWSocket::GUSIMPWSocket(int fd) - : fFD(fd) -{ -} -GUSIMPWSocket::~GUSIMPWSocket() -{ - MPW_close(fFD); - UpdateMPWErrno(); -} -// = -ssize_t GUSIMPWSocket::read(const GUSIScatterer & buffer) -{ - GUSIStdioFlush(); - GUSIConfiguration::Instance()->AutoSpin(); - int res = MPW_read(fFD, (char *) buffer.Buffer(), (unsigned)buffer.Length()); - if (res < 0) - UpdateMPWErrno(); - return buffer.SetLength(res); -} -// = -ssize_t GUSIMPWSocket::write(const GUSIGatherer & buffer) -{ - GUSIConfiguration::Instance()->AutoSpin(); - int res = MPW_write(fFD, (char *) buffer.Buffer(), (unsigned)buffer.Length()); - if (res < 0) - UpdateMPWErrno(); - return res; -} -// = -off_t GUSIMPWSocket::lseek(off_t offset, int whence) -{ - off_t res = MPW_lseek(fFD, offset, (long)whence); - if (res < 0) - UpdateMPWErrno(); - return res; -} -// = -int GUSIMPWSocket::fcntl(int cmd, va_list arg) -{ - int res = MPW_fcntl(fFD, cmd, va_arg(arg, int)); - if (res < 0) - UpdateMPWErrno(); - return res; -} -// = -int GUSIMPWSocket::ioctl(unsigned int request, va_list arg) -{ - int res = MPW_ioctl(fFD, request, va_arg(arg, long *)); - if (res < 0) - UpdateMPWErrno(); - return res; -} -// = -int GUSIMPWSocket::ftruncate(off_t offset) -{ - int res = MPW_ioctl(fFD, FIOSETEOF, (long *) offset); - if (res < 0) - UpdateMPWErrno(); - return res; -} -// = -int GUSIMPWSocket::fstat(struct stat * buf) -{ - GUSISocket::fstat(buf); - buf->st_mode = S_IFCHR | 0666; - - return 0; -} -// = -int GUSIMPWSocket::isatty() -{ - return 1; -} -// = -bool GUSIMPWSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - cond = *canRead = true; - if (canWrite) - cond = *canWrite = true; - - return cond; -} -// \section{Implementation of [[GUSIMPWDevice]]} -// -// [[GUSIMPWDevice]] is a singleton class. -// -// = -GUSIMPWDevice * GUSIMPWDevice::sInstance; -// = -GUSIMPWDevice * GUSIMPWDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSIMPWDevice(); - return sInstance; -} -// = -bool GUSIMPWDevice::Want(GUSIFileToken & file) -{ - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - return !file.IsDevice() || (file.StrStdStream(file.Path()) > -1); - default: - return false; - } -} -// [[open]] translates the file flags, opens the file, and passes the resulting -// descriptor to [[stdopen]]. -// -// The values of some of the flags that MPW uses differ a bit from the ones used -// in our headers. -// -// = -#define MPW_O_RDONLY 0 /* Bits 0 and 1 are used internally */ -#define MPW_O_WRONLY 1 /* Values 0..2 are historical */ -#define MPW_O_RDWR 2 /* NOTE: it goes 0, 1, 2, *!* 8, 16, 32, ... */ -#define MPW_O_APPEND (1<< 3) /* append (writes guaranteed at the end) */ -#define MPW_O_RSRC (1<< 4) /* Open the resource fork */ -#define MPW_O_ALIAS (1<< 5) /* Open alias file */ -#define MPW_O_CREAT (1<< 8) /* Open with file create */ -#define MPW_O_TRUNC (1<< 9) /* Open with truncation */ -#define MPW_O_EXCL (1<<10) /* w/ O_CREAT: Exclusive "create-only" */ -#define MPW_O_BINARY (1<<11) /* Open as a binary stream */ -#define MPW_O_NRESOLVE (1<<14) /* Don't resolve any aliases */ -// [[TranslateOpenFlags]] translates the header flags into the MPW flags. -// -// = -static int TranslateOpenFlags(int mode) -{ - int mpwMode; - - switch (mode & 3) { - case O_RDWR: - mpwMode = MPW_O_RDWR; - break; - case O_RDONLY: - mpwMode = MPW_O_RDONLY; - break; - case O_WRONLY: - mpwMode = MPW_O_WRONLY; - break; - } - if (mode & O_APPEND) - mpwMode |= MPW_O_APPEND; - if (mode & O_CREAT) - mpwMode |= MPW_O_CREAT; - if (mode & O_EXCL) - mpwMode |= MPW_O_EXCL; - if (mode & O_TRUNC) - mpwMode |= MPW_O_TRUNC; - - return mpwMode; -} -// = -extern int StandAlone; - -GUSISocket * GUSIMPWDevice::open(GUSIFileToken & file, int flags) -{ - if (!ConnectToMPWLibrary()) - return GUSISetPosixError(ENOEXEC), static_cast(nil); - - // To ensure that our fancy path handling gets applied to all complex paths, but MPW gets - // to do its magic on [[Dev:]] paths, we normalize paths if they contain more than 1 colon. - // - // = - const char * path = file.Path(); - const char * colon = strchr(path, ':'); - if (colon && strchr(colon, ':')) - path = file.RelativePath(); - int fd = MPW_open(path, TranslateOpenFlags(flags)); - - if (fd == -1) { - UpdateMPWErrno(); - return static_cast(nil); - } else if (!file.IsDevice() && !StandAlone && MPW_ioctl(fd, FIOINTERACTIVE, nil) == -1) { - MPW_close(fd); - return GUSIMacFileDevice::Instance()->open(file, flags & ~(O_CREAT | O_EXCL)); - } else - return stdopen(fd, flags); -} -// [[stdopen]] handles the GUSI side of the opening. -// -// = -GUSISocket * GUSIMPWDevice::stdopen(int fd, int flags) -{ - if (!ConnectToMPWLibrary()) - return GUSISetPosixError(ENOEXEC), static_cast(nil); - - // Our support of MacOS files is far superiour to our MPW console support, so - // whenever we find that in fact we're talking to a real file, we switch to - // using a [[MacFileSocket]] instead. This whole parocedure does not apply to - // SIOW applications: The initial sockets 0, 1, and 2 get closed right away and - // calling anything else on them would be counterproductive. - // - // = - short fRef; - - if (!StandAlone - && MPW_ioctl(fd, FIOINTERACTIVE, nil) == -1 - && MPW_ioctl(fd, FIOREFNUM, (long *) &fRef) != -1 - ) { - static short sOutFRef = 0; - static GUSISocket * sOutSocket; - - MPW_close(fd); - if (fd == 1) { - sOutFRef = fRef; - return sOutSocket = GUSIMacFileDevice::Instance()->open(fRef, flags); - } else if (fd == 2 && fRef == sOutFRef) { - // Standard output and error redirected to same file - return sOutSocket; - } else - return GUSIMacFileDevice::Instance()->open(fRef, flags); - } - - GUSISocket * sock = new GUSIMPWSocket(fd); - - return sock ? sock : (GUSISetPosixError(ENOMEM), static_cast(nil)); -} -// = -char *GUSIGetEnv(const char * name) -{ - if (!ConnectToMPWLibrary()) - return static_cast(nil); - return MPW_getenv(name); -} -// = -void GUSIMPWSpin(bool wait) -{ - static GUSITimer sSpinDue(false); - - GUSIConfiguration::Instance()->AutoInitGraf(); - - if (sSpinDue.Expired()) { - RotateCursor(32); - sSpinDue.Sleep(125, true); - } else if (wait) - GUSIHandleNextEvent(600); -} -// As opposed to an application, an MPW tool connects to the three standard -// descriptors on startup. -// -// = -void GUSISetupConsoleDescriptors() -{ - GUSIMPWDevice * mpw = GUSIMPWDevice::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - GUSIDeviceRegistry::Instance()->AddDevice(mpw); - - if (!(*table)[0]) { - table->InstallSocket(mpw->stdopen(0, O_RDONLY)); - table->InstallSocket(mpw->stdopen(1, O_WRONLY)); - table->InstallSocket(mpw->stdopen(2, O_WRONLY)); - } - - GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)-1); - GUSISetHook(GUSI_SpinHook, (GUSIHook)GUSIMPWSpin); -} diff --git a/GUSI/src/tangled/GUSIMPWStdio.cp b/GUSI/src/tangled/GUSIMPWStdio.cp deleted file mode 100755 index df5693e..0000000 --- a/GUSI/src/tangled/GUSIMPWStdio.cp +++ /dev/null @@ -1,146 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIDescriptor.h" - -#include -#include -#include - -// \section{Implementation of MPW ANSI library specific public GUSI functions} -// -// We have to reimplement a substantial portion of the MPW stdio library -// because of shared library problems and incompatible macro definitions for -// [[open]] flags. -// -// We'll start with a couple of internals. [[findfile]] searches for a free -// [[FILE]] structure. -// -// = -static FILE * findfile() -{ - FILE * stream; - - for (stream = _iob; stream < _iob+_NFILE; ++stream) - if (!(stream->_flag & (_IOREAD | _IOWRT | _IORW))) - return stream; - - return NULL; -} -// [[fdreopen]] initializes a [[FILE]] for use, which is actually quite simple. -// -// = -static FILE *fdreopen(int fd, short flags, FILE* stream) -{ - stream->_cnt = 0; - stream->_ptr = NULL; - stream->_base = NULL; - stream->_end = NULL; - stream->_size = NULL; - stream->_flag = flags; - stream->_file = fd; - - return stream; -} -// [[mode2flags]] parses the mode string and translates it to [[open]] and stdio -// flags. -// -// = -static int mode2flags(const char * mode, int * openflags, int * stdioflags) -{ - bool read_write = mode[1] == '+' || mode[2] == '+'; - - *openflags = 0; - *stdioflags = 0; - - switch (mode[0]) { - case 'r': - *openflags |= read_write ? O_RDWR : O_RDONLY; - *stdioflags |= read_write ? _IORW : _IOREAD; - break; - case 'w': - *openflags |= (read_write ? O_RDWR : O_WRONLY) | O_CREAT | O_TRUNC; - *stdioflags |= read_write ? _IORW : _IOWRT; - break; - case 'a': - *openflags |= (read_write ? O_RDWR : O_WRONLY) | O_CREAT | O_APPEND; - *stdioflags |= read_write ? _IORW : _IOWRT; - break; - default: - return -1; - } - - return 0; -} -// [[fopen]], [[freopen]], and [[fdopen]] can then be composed from the above. -// -// = -FILE *fopen(const char *filename, const char *mode) -{ - FILE * stream; - int flags; - int ioflags; - int fd; - - if ((stream = findfile()) - && mode2flags(mode, &flags, &ioflags) >= 0 - && (fd = open(filename, flags)) >= 0 - ) - return fdreopen(fd, ioflags, stream); - else - return NULL; -} -// = -FILE *freopen(const char *filename, const char *mode, FILE *stream) -{ - int flags; - int ioflags; - int fd; - - flags = errno; - fclose(stream); - errno = flags; - - if (mode2flags(mode, &flags, &ioflags) >= 0 - && (fd = open(filename, flags)) >= 0 - ) - return fdreopen(fd, ioflags, stream); - else - return NULL; -} -// = -FILE *fdopen(int fd, const char *mode) -{ - FILE * stream; - int flags; - int ioflags; - - if ((stream = findfile()) - && mode2flags(mode, &flags, &ioflags) >= 0 - ) - return fdreopen(fd, ioflags, stream); - else - return NULL; -} -// \section{Implementation of internal GUSI functions for MPW Stdio} -// -// -// = -void GUSIStdioClose() -{ - for (FILE * f = _iob; f<_iob+_NFILE; ++f) - if (f->_flag & (_IOREAD|_IOWRT)) - fclose(f); -} - -void GUSIStdioFlush() { fflush(NULL); } -// MPW Stdio already does everything to get started, no need for us to get in the -// act. With MrC, however, we have to pay attention that ioctl does not get stripped, -// otherwise the library will call a bad version internally. -// -// = -static void * sDontStrip; - -void GUSISetupConsoleStdio() -{ - sDontStrip = ioctl; -} diff --git a/GUSI/src/tangled/GUSIMSL.cp b/GUSI/src/tangled/GUSIMSL.cp deleted file mode 100755 index f4e6c70..0000000 --- a/GUSI/src/tangled/GUSIMSL.cp +++ /dev/null @@ -1,261 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIMSL.h" -#include "GUSIDescriptor.h" - -#include -#include -#include -#include - -GUSI_USING_STD_NAMESPACE - -// = -extern __file_modes __temp_file_mode; -extern "C" { -// = -void __temp_file_name(char * name_str, void * fsspec); -// \section{Implementation of ANSI library specific public GUSI functions} -// -// [[fdopen]] is an operation inherently tied to the ANSI library used. -// -// = -FILE * __find_unopened_file(); -// __handle_reopen is declared in -// \section{Implementation of ANSI library specific internal GUSI functions} -// -// While there is a function [[__close_all]], it turns out that calling it is -// problematic, at least under CodeWarrior Pro 4, because it may fail -// catastrophically upon being called a second time. -// -// = -void __flush_all(void); -// \section{Implementation of MSL override functions} -// -// All opens from the ANSI C and C++ libraries eventually call [[__open_file]], so -// that's one of our most important override candidates. We translate the file mode -// and call [[open]]. -// -// = -int __open_file(const char * name, __file_modes mode, __file_handle * handle); -// [[__open_temp_file]] is used to open files that get deleted after they are closed. -// We simply use the underlying GUSI support for the POSIXish [[open() / unlink]] -// idiom. -// -// = -int __open_temp_file(__file_handle * handle); -// I/O operations in MSL lead to calls to [[__read_file]], [[__write_file]], -// [[__position_file]], and [[__close_file]], so we'll reimplement those. -// -// = -int __read_file( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc); -// We treat the console variations almost identically to their file counterparts, -// except that we have to try to guess the correct handle. -// -// = -int __read_console( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc); -// = -int __write_file( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc); -// = -int __write_console( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc); -// The only one of these presenting us with some subtlety is [[__position_file]]. -// Unless we catch the case of positioning at a place where the position already is, -// MSL will be unable to [[fdopen]] any sockets. -// -// = -int __position_file( - __file_handle handle, unsigned long * position, int mode, __idle_proc idle_proc); -// = -int __close_file(__file_handle handle); -// [[__close_console]] is an undecidable function unless you build with MPW -// MSL libraries. -// -// = -int __close_console(__file_handle handle); -} - -// = -int __open_file(const char * name, __file_modes mode, __file_handle * handle) -{ - int fd; - int posixmode; - - // Translation of the constants is pretty obvious. - // - // = - switch (mode.open_mode) { - case __must_exist: - posixmode = 0; - break; - case __create_if_necessary: - posixmode = O_CREAT; - break; - case __create_or_truncate: - posixmode = O_CREAT | O_TRUNC; - break; - } - - switch (mode.io_mode) { - case __read: - posixmode |= O_RDONLY; - break; - case __write: - posixmode |= O_WRONLY; - break; - case __read_write: - posixmode |= O_RDWR; - break; - case __write | __append: - posixmode |= O_WRONLY | O_APPEND; - break; - case __read_write | __append: - posixmode |= O_RDWR | O_APPEND; - break; - } - - fd = open(name, posixmode); - - if (fd == -1) - return __io_error; - - *handle = (unsigned) fd; - - return __no_io_error; -} -// = -int __open_temp_file(__file_handle * handle) -{ - char temp_name[L_tmpnam]; - FSSpec spec; - int ioresult; - - __temp_file_name(temp_name, &spec); - - ioresult = __open_file(temp_name, __temp_file_mode, handle); - - if (ioresult == __no_io_error) - { - unlink(temp_name); - } - - return(ioresult); -} -// = -int __read_file( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc) -{ - int result = read((int) handle, (char *) buffer, (int) *count); - - if (result < 0) { - *count = 0; - - return __io_error; - } else { - *count = result; - - return result ? __no_io_error : __io_EOF; - } -} -// = -int __read_console( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc) -{ - return __read_file(handle, buffer, count, idle_proc); -} -// = -int __write_file( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc) -{ - int result = write((int) handle, (char *) buffer, (int) *count); - - if (result < 0) { - *count = 0; - - return __io_error; - } else { - *count = result; - - return __no_io_error; - } -} -// = -static __file_handle GuessHandle(__file_handle handle, unsigned char * buffer) -{ - if (handle) - return handle; - if (buffer > stderr->buffer && (buffer - stderr->buffer) < stderr->buffer_size) - return 2; - return 1; -} - -int __write_console( - __file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc) -{ - return __write_file(GuessHandle(handle, buffer), buffer, count, idle_proc); -} -// = -int __position_file( - __file_handle handle, unsigned long * position, int mode, __idle_proc) -{ - long result = lseek((int) handle, *position, mode); - - if (result < 0) - if (errno == ESPIPE && !*position && mode != SEEK_END) - *position = 0; - else - return __io_error; - else - *position = result; - - return __no_io_error; -} -// = -int __close_file(__file_handle handle) -{ - return close((int) handle) < 0 ? __io_error : __no_io_error; -} -// = -int __close_console(__file_handle handle) -{ - return __close_file(handle); -} -// = -#if __MSL__ >= 0x6000 && __MSL__ < 0x7001 -#define fdopen _fdopen -#endif -#if defined(__MWERKS__) && __MWERKS__ < 0x2401 && !defined(_SFSTDIO_H) -FILE * fdopen(int fildes, char *type) -#else -FILE * fdopen(int fildes, const char *type) -#endif -{ - FILE *str; - - if (!(str = __find_unopened_file())) - return(0); - - return(__handle_reopen(fildes, type, str)); -} -// = -void GUSIStdioClose() { } -void GUSIStdioFlush() { __flush_all(); } -// = -static void MSLSetupStdio(int fd, FILE * f) -{ - f->handle = fd; - f->position_proc = __position_file; - f->read_proc = __read_file; - f->write_proc = __write_file; - f->close_proc = __close_file; -} - -void GUSISetupConsoleStdio() -{ - MSLSetupStdio(0, stdin); - MSLSetupStdio(1, stdout); - MSLSetupStdio(2, stderr); -} diff --git a/GUSI/src/tangled/GUSIMTInet.cp b/GUSI/src/tangled/GUSIMTInet.cp deleted file mode 100755 index b77c651..0000000 --- a/GUSI/src/tangled/GUSIMTInet.cp +++ /dev/null @@ -1,188 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIMTInet.h" -#include "GUSIMTTcp.h" -#include "GUSIMTUdp.h" -#include "GUSIDiag.h" -#include "GUSIFSWrappers.h" - -#include -#include -#include - -#include - -GUSI_USING_STD_NAMESPACE - -// = -short GUSIMTInetSocket::sDrvrRefNum = 0; -OSErr GUSIMTInetSocket::sDrvrState = 1; -u_long GUSIMTInetSocket::sHostAddress = 0; -// [[Driver]] opens the driver if necessary and stores its refnum. -// -// = -short GUSIMTInetSocket::Driver() -{ - if (sDrvrState == 1) - sDrvrState = GUSIFSOpenDriver("\p.IPP", &sDrvrRefNum); - - return sDrvrState ? 0 : sDrvrRefNum; -} -// [[HostAddr]] does an [[ipctlGetAddr]] control call if necessary. -// -// = -u_long GUSIMTInetSocket::HostAddr() -{ - if (!sHostAddress && Driver()) { - GUSIIOPBWrapper ga; - - ga->ioCRefNum = Driver(); - ga->csCode = ipctlGetAddr; - - if (!ga.Control()) - sHostAddress = ga->ourAddress; - } - return sHostAddress; -} -// Initial values should be fairly obvious. -// -// = -GUSIMTInetSocket::GUSIMTInetSocket() - : fStream(nil) -{ - memset(&fSockAddr, 0, sizeof(sockaddr_in)); - fSockAddr.sin_family = AF_INET; - - fPeerAddr = fSockAddr; -} -// = -int GUSIMTInetSocket::bind(void * addr, socklen_t namelen) -{ - struct sockaddr_in *name = (struct sockaddr_in *)addr; - // The address to be passed must be up to a minimal standard of decency. - // For instance, the host address must be either the real IP number of - // our host or one of the two legitimate pseudo-addresses for - // [["localhost"]]. - // - // = - if (!GUSI_ASSERT_CLIENT( - namelen >= sizeof(struct sockaddr_in), - ("bind: address len %d < %d\n", namelen, sizeof(struct sockaddr_in))) - ) - return GUSISetPosixError(EINVAL); - if (!GUSI_ASSERT_CLIENT( - name->sin_family == AF_INET, - ("bind: family %d != %d\n", name->sin_family, AF_INET)) - ) - return GUSISetPosixError(EAFNOSUPPORT); - if (!GUSI_SASSERT_CLIENT(!fSockAddr.sin_port, "bind: Socket already bound\n")) - return GUSISetPosixError(EINVAL); - switch (name->sin_addr.s_addr) { - default: - if (!GUSI_ASSERT_CLIENT( - name->sin_addr.s_addr == HostAddr(), - ("bind: addr %08X != %08X\n", name->sin_addr.s_addr, HostAddr())) - ) - return GUSISetPosixError(EADDRNOTAVAIL); - case 0: - case 0x7F000001: - break; - } - fSockAddr.sin_addr.s_addr = name->sin_addr.s_addr; - fSockAddr.sin_port = name->sin_port; - - return 0; -} -// = -int GUSIMTInetSocket::getsockname(void *name, socklen_t *namelen) -{ - if (!GUSI_SASSERT_CLIENT(*namelen >= 0, "getsockname: passed negative length\n")) - return GUSISetPosixError(EINVAL); - - memcpy(name, &fSockAddr, *namelen = min(*namelen, socklen_t(sizeof(sockaddr_in)))); - return 0; -} -int GUSIMTInetSocket::getpeername(void *name, socklen_t *namelen) -{ - if (!GUSI_SASSERT_CLIENT(*namelen >= 0, "getpeername: passed negative length\n")) - return GUSISetPosixError(EINVAL); - - memcpy(name, &fPeerAddr, *namelen = min(*namelen, socklen_t(sizeof(sockaddr_in)))); - return 0; -} -// = -int GUSIMTInetSocket::shutdown(int how) -{ - if (!GUSI_SASSERT_CLIENT(how >= 0 && how < 3, "shutdown: 0,1, or 2\n")) - return GUSISetPosixError(EINVAL); - - GUSISMState::Shutdown(how); - - return 0; -} -// = -int GUSIMTInetSocket::fcntl(int cmd, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoFcntl(&result, cmd, arg)) - return result; - - GUSI_ASSERT_CLIENT(false, ("fcntl: illegal request %d\n", cmd)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIMTInetSocket::ioctl(unsigned int request, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoIoctl(&result, request, arg) - || GUSISMInputBuffer::DoIoctl(&result, request, arg) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("ioctl: illegal request %d\n", request)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIMTInetSocket::getsockopt(int level, int optname, void *optval, socklen_t * optlen) -{ - int result; - - if (GUSISMInputBuffer::DoGetSockOpt(&result, level, optname, optval, optlen) - || GUSISMOutputBuffer::DoGetSockOpt(&result, level, optname, optval, optlen) - || GUSISMAsyncError::DoGetSockOpt(&result, level, optname, optval, optlen) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("getsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIMTInetSocket::setsockopt(int level, int optname, void *optval, socklen_t optlen) -{ - int result; - - if (GUSISMInputBuffer::DoSetSockOpt(&result, level, optname, optval, optlen) - || GUSISMOutputBuffer::DoSetSockOpt(&result, level, optname, optval, optlen) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("setsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -bool GUSIMTInetSocket::Supports(ConfigOption config) -{ - return config == kSocketCalls; -} -// = -void GUSIwithMTInetSockets() -{ - GUSIwithMTTcpSockets(); - GUSIwithMTUdpSockets(); -} diff --git a/GUSI/src/tangled/GUSIMTNetDB.cp b/GUSI/src/tangled/GUSIMTNetDB.cp deleted file mode 100755 index 3b81993..0000000 --- a/GUSI/src/tangled/GUSIMTNetDB.cp +++ /dev/null @@ -1,171 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIMTNetDB.h" -#include "GUSIMTInet.h" -#include "GUSIContext.h" - -#include - -#include -#include -#include - -// \section{Implementation of [[GUSIMTNetDB]]} -// -// To implement this, we need to include the MacTCP DNR code, a somewhat unpleasant -// operation. If possible, we wrap within an anonymous namespace. -// -// = -#ifdef GUSI_COMPILER_HAS_NAMESPACE -namespace { -#include - -#include "dnr.c" -} -#else -#include "dnr.c" -#endif -// When a DNR call terminates, it wakes up the thread issuing the call. -// -// = -static pascal void DNRDone(struct hostInfo *, GUSIContext * context) -{ - context->Wakeup(); -} - -#if GENERATINGCFM -RoutineDescriptor uDNRDone = - BUILD_ROUTINE_DESCRIPTOR(uppResultProcInfo, DNRDone); -#else -#define uDNRDone DNRDone -#endif -// The MacTCP DNR code is installed by calling [[Instantiate]], which initializes -// the singleton instance of [[GUSINetDB]]. -// -// = -void GUSIMTNetDB::Instantiate() -{ - if (!sInstance) - sInstance = new GUSIMTNetDB; -} -// = -OSErr GUSIMTNetDB::sResolverState = 1; - -bool GUSIMTNetDB::Resolver() -{ - GUSIMTInetSocket::Driver(); - if (sResolverState == 1) - sResolverState = OpenResolver(nil); - - return !sResolverState; -} -// Naturally, MacTCP keeps its host data in different structures than the socket -// standard. -// -// = -static void CopyHost(hostInfo & macHost, GUSIhostent & unixHost) -{ - /* for some reason there is a dot at the end of the name */ - size_t len = strlen(macHost.cname); - if (macHost.cname[len-1] == '.') - macHost.cname[--len] = 0; - len = (len+4) & ~3; - - unixHost.Alloc(len+NUM_ALT_ADDRS*4); - strcpy(unixHost.h_name, macHost.cname); - unixHost.h_aliases[0] = NULL; // Aliases not supported - unixHost.h_addrtype = AF_INET; - unixHost.h_length = 4; - - int addrs = 0; - for (int i=0; i= -hostent * GUSIMTNetDB::gethostbyname(const char * name) -{ - // = - if (!Resolver()) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - if (!strcmp(name, "localhost")) { - long ipaddr = gethostid(); - if (ipaddr) - return gethostbyaddr((char *) &ipaddr, sizeof(in_addr), AF_INET); - return GUSISetHostError(HOST_NOT_FOUND), static_cast(nil); - } - // = - hostInfo macHost; - GUSIhostent & unixHost = *fHost; - - for (int i=0; i(name), &macHost, ResultUPP(&uDNRDone), - reinterpret_cast(GUSIContext::Current()) - ) == cacheFault - ) - do { - GUSIContext::Yield(kGUSIBlock); - } while (macHost.rtnCode == cacheFault); - if (macHost.rtnCode) - return GUSISetMacHostError(macHost.rtnCode), static_cast(nil); - if (macHost.cname[0] == 0) - return GUSISetHostError(HOST_NOT_FOUND), static_cast(nil); - - CopyHost(macHost, unixHost); - - return &unixHost; -} -// = -hostent * GUSIMTNetDB::gethostbyaddr(const void * addrP, size_t, int) -{ - // = - if (!Resolver()) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - // = - hostInfo macHost; - GUSIhostent & unixHost = *fHost; - - for (int i=0; i(gethostid()); - - if (AddrToName(addr, &macHost, ResultUPP(&uDNRDone), - reinterpret_cast(GUSIContext::Current()) - ) == cacheFault - ) - do { - GUSIContext::Yield(kGUSIBlock); - } while (macHost.rtnCode == cacheFault); - - if (macHost.rtnCode) - return GUSISetMacHostError(macHost.rtnCode), static_cast(nil); - /* For some reason, the IP address usually seems to be set to 0 */ - if (!macHost.addr[0]) - macHost.addr[0] = addr; - CopyHost(macHost, unixHost); - - return &unixHost; -} -// = -char * GUSIMTNetDB::inet_ntoa(in_addr inaddr) -{ - GUSIhostent & unixHost = *fHost; - GUSI_sprintf(unixHost.fAddrString, "%d.%d.%d.%d", - (inaddr.s_addr >> 24) & 0xFF, - (inaddr.s_addr >> 16) & 0xFF, - (inaddr.s_addr >> 8) & 0xFF, - inaddr.s_addr & 0xFF); - return unixHost.fAddrString; -} -// = -long GUSIMTNetDB::gethostid() -{ - return static_cast(GUSIMTInetSocket::HostAddr()); -} diff --git a/GUSI/src/tangled/GUSIMTTcp.cp b/GUSI/src/tangled/GUSIMTTcp.cp deleted file mode 100755 index e3079ec..0000000 --- a/GUSI/src/tangled/GUSIMTTcp.cp +++ /dev/null @@ -1,833 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIMTTcp.h" -#include "GUSIMTInet.h" -#include "GUSIMTNetDB.h" -#include "GUSIInet.h" -#include "GUSIDiag.h" -#include "GUSISocketMixins.h" - -#include - -#include - -#include - -GUSI_USING_STD_NAMESPACE - -// \section{Definition of [[GUSIMTTcpSocket]]} -// -// The only specfic data member, [[fSelf]], serves as the [[userDataPtr]] of -// the TCP notification procedure. Since [[accept]] associates a different -// [[GUSIMTTcpSocket]] with the same TCP [[StreamPtr]], passing [[this]] for this -// purpose would be fatal. -// -// = -class GUSIMTTcpSocket : public GUSIMTInetSocket, public GUSISMProcess { -public: - GUSIMTTcpSocket(); - ~GUSIMTTcpSocket(); - // [[connect]] opens a connection actively. - // - // = - virtual int connect(void * address, socklen_t addrlen); - // Most of the dirty work of [[listen]] is already handled in [[GUSIMTTListen]]. - // - // = - virtual int listen(int queueLength); - // [[accept]] also is able to delegate most of the hard work to [[GUSIMTTListen]]. - // - // = - virtual GUSISocket * accept(void *from, socklen_t *fromlen); - // [[recvfrom]] reads from [[fInputBuffer]]. - // - // = - virtual ssize_t recvfrom(const GUSIScatterer & buffer, int, void * from, socklen_t * fromlen); - // [[sendto]] writes to [[fOutputBuffer]]. As opposed to reads, writes have to - // be executed fully. This leads to a problem when a nonblocking write wants to - // write more data than the total length of the buffer. In this case, GUSI disregards - // the nonblocking flag. - // - // = - virtual ssize_t sendto(const GUSIGatherer & buffer, int flags, const void * to, socklen_t); - // [[select]] checks for various conditions on the socket. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - // [[shutdown]] for writing sends a closing notice. [[fOutputBuffer]] is locked and - // released so the [[TCPClose]] is sent. - // - // = - virtual int shutdown(int how); -private: - GUSIMTTcpSocket ** fSelf; - // \section{Implementation of [[GUSIMTTcpSocket]]} - // - // The implementation of [[GUSIMTTcpSocket]] consists of a synchronous high level - // part which mostly deals with [[GUSIRingBuffers]] and an asynchronous low - // level part. The low level procedures in their single-mindedness are actually - // simpler to explain, so we start with them. - // - // \subsection{Interrupt level routines for [[GUSIMTTcpSocket]]} - // - // Both [[GUSIMTTSendDone]] and [[GUSIMTTRecvDone]] are always called with the - // same [[TCPiopb]] in a [[GUSIMTTcpSocket]] so they can easily find out the address - // of the socket itself. [[GUSIMTTSend]] and [[GUSIMTTRecv]] set up send and receive - // calls. - // - // = - TCPiopb fSendPB; - MiniWDS fSendWDS; - TCPiopb fRecvPB; - friend void GUSIMTTSend(GUSIMTTcpSocket * sock); - friend void GUSIMTTRecv(GUSIMTTcpSocket * sock); - friend void GUSIMTTSendDone(TCPiopb * pb); - friend void GUSIMTTRecvDone(TCPiopb * pb); - static TCPIOCompletionUPP sSendProc; - static TCPIOCompletionUPP sRecvProc; - // For some global events, MacTCP calls a notification procedure. - // - // = - friend pascal void GUSIMTTNotify( - StreamPtr, u_short, GUSIMTTcpSocket **, - u_short, struct ICMPReport *); - static TCPNotifyUPP sNotifyProc; - // When a [[connect]] completes, we can fill in the peer address. [[connect]] - // uses [[fSendPB]]. - // - // = - friend void GUSIMTTConnectDone(TCPiopb * pb); - static TCPIOCompletionUPP sConnectProc; - // Passive opens work similarly, but it is necessary to build a backlog if the - // interrupt level gets opens faster than the high level routines can accept them. - // - // = - struct Listener { - StreamPtr fTcp; - GUSIMTTcpSocket ** fRef; - sockaddr_in fSockAddr; - sockaddr_in fPeerAddr; - bool fBusy; - }; - Listener * fListeners; - bool fRestartListen; - char fNumListeners; - char fCurListener; - char fNextListener; - friend void GUSIMTTListenDone(TCPiopb * pb); - friend void GUSIMTTListen(GUSIMTTcpSocket * sock); - static TCPIOCompletionUPP sListenProc; - // [[CreateStream]] creates a TCP stream. - // - // = - StreamPtr CreateStream(GUSIMTTcpSocket ** socketRef); - // [[SetupListener]] prepares a [[Listener]]. - // - // = - void SetupListener(Listener & listener); - // [[accept]] uses a special constructor of [[GUSIMTTcpSocket]] which constructs - // a socket directly from a [[Listener]]. - // - // = - GUSIMTTcpSocket(Listener & listener); -}; -// [[GUSIMTTSendDone]] does all its work between [[fSendPB]] and [[fOutputBuffer]]. -// If a send fails, the whole send buffer is cleared. -// -// = -void GUSIMTTSendDone(TCPiopb * pb) -{ - GUSIMTTcpSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMTTcpSocket, fSendPB)); - GUSIProcess::A5Saver saveA5(sock->Process()); - if (sock->fOutputBuffer.Locked()) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTTSendDone), pb); - else { - sock->fOutputBuffer.ClearDefer(); - sock->fOutputBuffer.FreeBuffer(sock->fSendWDS.fDataPtr, sock->fSendWDS.fLength); - if (sock->SetAsyncMacError(sock->fSendPB.ioResult)) { - for (long valid; valid = sock->fOutputBuffer.Valid(); ) - sock->fOutputBuffer.FreeBuffer(nil, valid); - sock->fWriteShutdown = true; - } - GUSIMTTSend(sock); - sock->Wakeup(); - } -} -// [[GUSIMTTSend]] starts a tcp send call if there is data to send and otherwise -// sets itself up as the deferred procedure of the output buffer (and thus is -// guaranteed to be called the next time data is deposited in the buffer again). -// If all data has been delivered and a shutdown is requested, send one. -// -// = -void GUSIMTTSend(GUSIMTTcpSocket * sock) -{ - size_t valid = sock->fOutputBuffer.Valid(); - - sock->fOutputBuffer.ClearDefer(); - if (!valid) { - if (!sock->fWriteShutdown) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTTSend), sock); - else if (sock->fState == GUSIMTTcpSocket::Connected) { - sock->fState = GUSISMState::Closing; - sock->fSendPB.ioCompletion = nil; - sock->fSendPB.csCode = TCPClose; - sock->fSendPB.csParam.close.validityFlags = timeoutValue | timeoutAction; - sock->fSendPB.csParam.close.ulpTimeoutValue = 60 /* seconds */; - sock->fSendPB.csParam.close.ulpTimeoutAction= 0 /* 0:abort 1:report */; - - PBControlAsync(ParmBlkPtr(&sock->fSendPB)); - } - } else { - valid = min(valid, min((size_t)65535, sock->fOutputBuffer.Size() >> 1)); - - sock->fSendWDS.fDataPtr = - static_cast(sock->fOutputBuffer.ConsumeBuffer(valid)); - sock->fSendWDS.fLength = (u_short) valid; - - sock->fSendPB.ioCompletion = sock->sSendProc; - sock->fSendPB.csCode = TCPSend; - sock->fSendPB.csParam.send.validityFlags = timeoutValue | timeoutAction; - sock->fSendPB.csParam.send.ulpTimeoutValue = 60 /* seconds */; - sock->fSendPB.csParam.send.ulpTimeoutAction = 0 /* 0:abort 1:report */; - sock->fSendPB.csParam.send.wdsPtr = &sock->fSendWDS; - sock->fSendPB.csParam.send.sendFree = 0; - sock->fSendPB.csParam.send.sendLength = 0; - sock->fSendPB.csParam.send.urgentFlag = 0; - sock->fSendPB.csParam.send.pushFlag = - valid == sock->fOutputBuffer.Valid(); - - PBControlAsync(ParmBlkPtr(&sock->fSendPB)); - } -} -// [[GUSIMTTRecvDone]] does all its work between [[fRecvPB]] and [[fInputBuffer]]. -// -// = -void GUSIMTTRecvDone(TCPiopb * pb) -{ - GUSIMTTcpSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMTTcpSocket, fRecvPB)); - GUSIProcess::A5Saver saveA5(sock->Process()); - if (sock->fInputBuffer.Locked()) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTTRecvDone), pb); - else { - sock->fInputBuffer.ClearDefer(); - switch (sock->fRecvPB.ioResult) { - case noErr: - sock->fInputBuffer.ValidBuffer( - sock->fRecvPB.csParam.receive.rcvBuff, - sock->fRecvPB.csParam.receive.rcvBuffLen); - // Fall through - case commandTimeout: - GUSIMTTRecv(sock); - break; - default: - sock->SetAsyncMacError(sock->fRecvPB.ioResult); - case connectionClosing: - sock->fReadShutdown = true; - break; - } - sock->Wakeup(); - } -} -// [[GUSIMTTRecv]] starts a tcp receive call if there is room left and otherwise -// sets itself up as the deferred procedure of the output buffer (and thus is -// guaranteed to be called the next time there is free space in the buffer again). -// -// = -void GUSIMTTRecv(GUSIMTTcpSocket * sock) -{ - size_t free = sock->fInputBuffer.Free(); - if (!free) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTTRecv), sock); - else { - sock->fInputBuffer.ClearDefer(); - free = min(free, min((size_t)65535, sock->fInputBuffer.Size() >> 1)); - - sock->fRecvPB.ioCompletion = sock->sRecvProc; - sock->fRecvPB.csCode = TCPRcv; - sock->fRecvPB.csParam.receive.rcvBuff = - static_cast(sock->fInputBuffer.ProduceBuffer(free)); - sock->fRecvPB.csParam.receive.rcvBuffLen= free; - sock->fRecvPB.csParam.receive.commandTimeoutValue = 120; - - PBControlAsync(ParmBlkPtr(&sock->fRecvPB)); - } -} -// = -pascal void GUSIMTTNotify( - StreamPtr, - u_short eventCode, GUSIMTTcpSocket ** sp, u_short, struct ICMPReport *) -{ - GUSIMTTcpSocket * sock = *sp; - - switch (eventCode) { - case TCPClosing: - sock->fReadShutdown = true; - break; - case TCPTerminate: - sock->fReadShutdown = true; - sock->fWriteShutdown = true; - sock->fState = GUSISMState::Unconnected; - break; - } - sock->Wakeup(); -} -// = -void GUSIMTTConnectDone(TCPiopb * pb) -{ - GUSIMTTcpSocket * sock = - (GUSIMTTcpSocket *)((char *)pb-offsetof(GUSIMTTcpSocket, fSendPB)); - GUSIProcess::A5Saver saveA5(sock->Process()); - if (!sock->SetAsyncMacError(pb->ioResult)) { - sock->fSockAddr.sin_family = AF_INET; - sock->fSockAddr.sin_addr.s_addr = pb->csParam.open.localHost; - sock->fSockAddr.sin_port = pb->csParam.open.localPort; - sock->fPeerAddr.sin_family = AF_INET; - sock->fPeerAddr.sin_addr.s_addr = pb->csParam.open.remoteHost; - sock->fPeerAddr.sin_port = pb->csParam.open.remotePort; - sock->fState = GUSISMState::Connected; - - GUSIMTTSend(sock); - GUSIMTTRecv(sock); - } else - sock->fState = GUSISMState::Unconnected; - GUSI_MESSAGE(("Connect %x\n", sock)); - sock->Wakeup(); -} -// [[GUSIMTTListenDone]] saves the connection parameters and starts the -// next passive open, if possible. Blocking on [[fInputBuffer]] is somewhat -// bizarre; we're not actually using the buffer, just its lock. The only -// times this lock is used is while we're waiting for a local socket number -// to be assigned to an unbound listener socket and when the socket is shutting -// down. -// -// = -void GUSIMTTListenDone(TCPiopb * pb) -{ - bool allowRestart = true; - GUSIMTTcpSocket * sock = - (GUSIMTTcpSocket *)((char *)pb-offsetof(GUSIMTTcpSocket, fRecvPB)); - GUSIProcess::A5Saver saveA5(sock->Process()); - switch (pb->ioResult) { - case commandTimeout: - case openFailed: - break; - default: - if (!sock->SetAsyncMacError(pb->ioResult)) { - GUSIMTTcpSocket::Listener & listener = sock->fListeners[sock->fCurListener]; - listener.fSockAddr.sin_family = AF_INET; - listener.fSockAddr.sin_addr.s_addr = pb->csParam.open.localHost; - listener.fSockAddr.sin_port = pb->csParam.open.localPort; - listener.fPeerAddr.sin_family = AF_INET; - listener.fPeerAddr.sin_addr.s_addr = pb->csParam.open.remoteHost; - listener.fPeerAddr.sin_port = pb->csParam.open.remotePort; - listener.fBusy = true; - sock->fCurListener = (sock->fCurListener+1) % sock->fNumListeners; - GUSI_MESSAGE(("Listen %x\n", &listener)); - } else - allowRestart = false; - } - sock->Wakeup(); - if (allowRestart) - if (sock->fInputBuffer.Locked()) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTTListenDone), pb); - else { - sock->fInputBuffer.ClearDefer(); - GUSIMTTListen(sock); - } -} -// [[GUSIMTTListen]] initiates a passive open. -// -// = -void GUSIMTTListen(GUSIMTTcpSocket * sock) -{ - if (sock->fRestartListen = sock->fListeners[sock->fCurListener].fBusy) - return; - sock->fRecvPB.tcpStream = sock->fListeners[sock->fCurListener].fTcp; - sock->fRecvPB.ioCompletion = sock->sListenProc; - sock->fRecvPB.csCode = TCPPassiveOpen; - sock->fRecvPB.csParam.open.validityFlags = timeoutValue | timeoutAction; - sock->fRecvPB.csParam.open.ulpTimeoutValue = 300 /* seconds */; - sock->fRecvPB.csParam.open.ulpTimeoutAction = 1 /* 1:abort 0:report */; - sock->fRecvPB.csParam.open.commandTimeoutValue = 0 /* infinity */; - sock->fRecvPB.csParam.open.remoteHost = 0; - sock->fRecvPB.csParam.open.remotePort = 0; - sock->fRecvPB.csParam.open.localHost = sock->fSockAddr.sin_addr.s_addr; - sock->fRecvPB.csParam.open.localPort = sock->fSockAddr.sin_port; - sock->fRecvPB.csParam.open.dontFrag = 0; - sock->fRecvPB.csParam.open.timeToLive = 0; - sock->fRecvPB.csParam.open.security = 0; - sock->fRecvPB.csParam.open.optionCnt = 0; - - // If we do a [[listen]] on an unbound socket, MacTCP assigns a socket number, - // which strangely happens at some time {\em after} the asynchronous call has - // initially returned but {\em before} the call has completed. Thus, we lock to - // prevent further opens from starting and then do a sort-of-busy wait. Thanks - // to Peter Lewis for his explanations on that point. - // - // = - if (!sock->fSockAddr.sin_port) { - sock->fInputBuffer.Lock(); - PBControlAsync(ParmBlkPtr(&sock->fRecvPB)); - while (!sock->fRecvPB.csParam.open.localPort) - GUSIContext::Yield(kGUSIPoll); - sock->fSockAddr.sin_port = sock->fRecvPB.csParam.open.localPort; - sock->fInputBuffer.Release(); - } else - PBControlAsync(ParmBlkPtr(&sock->fRecvPB)); -} -// The UPPs for the completion procedures are set up the first time a socket -// is constructed. -// -// = -TCPIOCompletionUPP GUSIMTTcpSocket::sSendProc = 0; -TCPIOCompletionUPP GUSIMTTcpSocket::sRecvProc = 0; -// The UPP for the notification procedure is set up the first time a socket -// is constructed. -// -// = -TCPNotifyUPP GUSIMTTcpSocket::sNotifyProc = 0; -// = -TCPIOCompletionUPP GUSIMTTcpSocket::sConnectProc = 0; -// = -TCPIOCompletionUPP GUSIMTTcpSocket::sListenProc = 0; -// = -StreamPtr GUSIMTTcpSocket::CreateStream(GUSIMTTcpSocket ** socketRef) -{ - fSendPB.ioCompletion = nil; - fSendPB.csCode = TCPCreate; - fSendPB.csParam.create.rcvBuff = (char *)NewPtr(8192); - fSendPB.csParam.create.rcvBuffLen = 8192; - fSendPB.csParam.create.notifyProc = sNotifyProc; - fSendPB.csParam.create.userDataPtr = Ptr(socketRef); - - PBControlSync(ParmBlkPtr(&fSendPB)); - - if (fSendPB.ioResult) - return nil; - else - return fSendPB.tcpStream; -} -// = -void GUSIMTTcpSocket::SetupListener(Listener & listener) -{ - listener.fRef = new (GUSIMTTcpSocket *); - *listener.fRef = this; - listener.fTcp = CreateStream(listener.fRef); - listener.fBusy = false; -} -// \subsection{High level interface for [[GUSIMTTcpSocket]]} -// -// The constructor has to initialize a rather large number of data fields, and as a -// side effect opens the MacTCP driver if necessary. No other interesting activity -// occurs. -// -// = -GUSIMTTcpSocket::GUSIMTTcpSocket() -{ - // = - if (!sSendProc) - sSendProc = NewTCPIOCompletionProc(GUSIMTTSendDone); - if (!sRecvProc) - sRecvProc = NewTCPIOCompletionProc(GUSIMTTRecvDone); - // The send and receive parameter blocks are highly specialized and never really - // change during the existence of a socket. - // - // = - fSendPB.ioCRefNum = GUSIMTInetSocket::Driver(); - fRecvPB.ioCRefNum = GUSIMTInetSocket::Driver(); - // = - fSelf = nil; - if (!sNotifyProc) - sNotifyProc = NewTCPNotifyProc(TCPNotifyProcPtr(GUSIMTTNotify)); - // = - if (!sConnectProc) - sConnectProc = NewTCPIOCompletionProc(GUSIMTTConnectDone); - // = - fListeners = nil; - fRestartListen = true; - fNumListeners = 0; - fCurListener = 0; - fNextListener = 0; - if (!sListenProc) - sListenProc = NewTCPIOCompletionProc(GUSIMTTListenDone); -} -// = -int GUSIMTTcpSocket::connect(void * address, socklen_t addrlen) -{ - sockaddr_in * addr = (sockaddr_in *) address; - - // = - if (!GUSI_CASSERT_CLIENT(addrlen >= int(sizeof(sockaddr_in)))) - return GUSISetPosixError(EINVAL); - if (!GUSI_CASSERT_CLIENT(addr->sin_family == AF_INET)) - return GUSISetPosixError(EAFNOSUPPORT); - if (GUSISetPosixError(GetAsyncError())) // non-blocking connect failed - return -1; - switch (fState) { - case Connecting: - return GUSISetPosixError(EALREADY); // non-blocking connect in progress - case Unbound: - case Unconnected: - break; // Go ahead - default: - return GUSISetPosixError(EISCONN); // Already connected in some form - } - - if (!fSelf) { - fSelf = new (GUSIMTTcpSocket *); - *fSelf = this; - } - if (!fStream) - if (!(fStream = CreateStream(fSelf))) - return GUSISetPosixError(ENFILE); - - fSendPB.tcpStream = fStream; - fRecvPB.tcpStream = fStream; - - fSendPB.ioCompletion = sConnectProc; - fSendPB.csCode = TCPActiveOpen; - fSendPB.csParam.open.validityFlags = timeoutValue | timeoutAction; - fSendPB.csParam.open.ulpTimeoutValue = 60 /* seconds */; - fSendPB.csParam.open.ulpTimeoutAction = 1 /* 1:abort 0:report */; - fSendPB.csParam.open.commandTimeoutValue= 0; - fSendPB.csParam.open.remoteHost = addr->sin_addr.s_addr; - fSendPB.csParam.open.remotePort = addr->sin_port; - fSendPB.csParam.open.localHost = fSockAddr.sin_addr.s_addr; - fSendPB.csParam.open.localPort = fSockAddr.sin_port; - fSendPB.csParam.open.dontFrag = 0; - fSendPB.csParam.open.timeToLive = 0; - fSendPB.csParam.open.security = 0; - fSendPB.csParam.open.optionCnt = 0; - fState = Connecting; - - SetAsyncPosixError(0); - if (GUSISetMacError(PBControlAsync(ParmBlkPtr(&fSendPB)))) - return -1; - - if (!fBlocking) - return GUSISetPosixError(EINPROGRESS); - - AddContext(); - while (fSendPB.ioResult == inProgress) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - - return GUSISetPosixError(GetAsyncError()); -} -// = -int GUSIMTTcpSocket::listen(int queueLength) -{ - // = - if (!GUSI_CASSERT_CLIENT(fState <= Unconnected)) - return GUSISetPosixError(EISCONN); - // For some weird reason, BSD multiplies queue lengths with a fudge factor. - // - // = - if (queueLength < 1) - queueLength = 1; - else if (queueLength > 4) - queueLength = 8; - else - queueLength = ((queueLength * 3) >> 1) + 1; - - fInputBuffer.SwitchBuffer(0); - fOutputBuffer.SwitchBuffer(0); - fState = Listening; - fListeners = new Listener[fNumListeners = queueLength]; - while (queueLength--) - SetupListener(fListeners[queueLength]); - - GUSIMTTListen(this); - - return 0; -} -// = -GUSISocket * GUSIMTTcpSocket::accept(void *from, socklen_t *fromlen) -{ - GUSIMTTcpSocket * sock; - - // = - if (!GUSI_CASSERT_CLIENT(fState == Listening)) { - GUSISetPosixError(ENOTCONN); - return nil; - } - // Listener slots are filled one by one, so we simply check whether the next listener - // block has been filled yet. - // - // = - if (!fListeners[fNextListener].fBusy && !fReadShutdown) { - if (!fBlocking) - return GUSISetPosixError(EWOULDBLOCK), static_cast(0); - bool signal = false; - AddContext(); - while (!fListeners[fNextListener].fBusy && !fReadShutdown) - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - RemoveContext(); - if (signal) - return GUSISetPosixError(EINTR), static_cast(0); - } - if (!fListeners[fNextListener].fBusy && fReadShutdown) { - GUSISetPosixError(ESHUTDOWN); - return nil; - } - - sock = new GUSIMTTcpSocket(fListeners[fNextListener]); - - SetupListener(fListeners[fNextListener]); - fNextListener = (fNextListener+1) % fNumListeners; - - if (fRestartListen) - GUSIMTTListen(this); - - if (sock && from) - sock->getpeername(from, fromlen); - - return sock; -} -// = -GUSIMTTcpSocket::GUSIMTTcpSocket(Listener & listener) -{ - // = - if (!sSendProc) - sSendProc = NewTCPIOCompletionProc(GUSIMTTSendDone); - if (!sRecvProc) - sRecvProc = NewTCPIOCompletionProc(GUSIMTTRecvDone); - // The send and receive parameter blocks are highly specialized and never really - // change during the existence of a socket. - // - // = - fSendPB.ioCRefNum = GUSIMTInetSocket::Driver(); - fRecvPB.ioCRefNum = GUSIMTInetSocket::Driver(); - // = - fSelf = nil; - if (!sNotifyProc) - sNotifyProc = NewTCPNotifyProc(TCPNotifyProcPtr(GUSIMTTNotify)); - // = - if (!sConnectProc) - sConnectProc = NewTCPIOCompletionProc(GUSIMTTConnectDone); - // = - fListeners = nil; - fRestartListen = true; - fNumListeners = 0; - fCurListener = 0; - fNextListener = 0; - if (!sListenProc) - sListenProc = NewTCPIOCompletionProc(GUSIMTTListenDone); - fSockAddr = listener.fSockAddr; - fPeerAddr = listener.fPeerAddr; - fSelf = listener.fRef; - *fSelf = this; - fStream = listener.fTcp; - fState = Connected; - fSendPB.tcpStream = fStream; - fRecvPB.tcpStream = fStream; - - GUSIMTTSend(this); - GUSIMTTRecv(this); -} -// = -ssize_t GUSIMTTcpSocket::recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen) -{ - if (from) - getpeername(from, fromlen); - - // = - if (!fInputBuffer.Valid()) - if (GUSISetPosixError(GetAsyncError())) - return -1; - else if (fReadShutdown) - return 0; - switch (fState) { - case Unbound: - case Unconnected: - case Listening: - return GUSISetPosixError(ENOTCONN); - case Closing: - case Connecting: - case Connected: - break; - } - // The socket needs to be in [[Connected]] or [[Closing]] state and the input buffer needs to be - // nonempty before a read can succeed. - // - // = - if (!fReadShutdown - && (fState == Connecting || fState == Connected || fState == Closing) - && !fInputBuffer.Valid() - ) { - if (!fBlocking) - return GUSISetPosixError(EWOULDBLOCK); - bool signal = false; - AddContext(); - while (!fReadShutdown - && (fState == Connecting || fState == Connected || fState == Closing) - && !fInputBuffer.Valid() - ) - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - RemoveContext(); - if (signal) - return GUSISetPosixError(EINTR); - } - - size_t len = buffer.Length(); - if (flags & MSG_PEEK) - fInputBuffer.Peek(buffer, len); - else - fInputBuffer.Consume(buffer, len); - - return (ssize_t)len; -} -// = -ssize_t GUSIMTTcpSocket::sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t) -{ - // = - if (GUSISetPosixError(GetAsyncError())) - return -1; - if (fWriteShutdown) - return GUSISetPosixError(ESHUTDOWN); - - if (!GUSI_SASSERT_CLIENT(!to, "Can't sendto() on a stream socket")) - return GUSISetPosixError(EOPNOTSUPP); - switch (fState) { - case Unbound: - case Unconnected: - case Listening: - return GUSISetPosixError(ENOTCONN); - case Closing: - case Connecting: - case Connected: - break; - } - - if (!fBlocking && (fState == Connecting || !fOutputBuffer.Free())) - return GUSISetPosixError(EWOULDBLOCK); - - size_t rest = buffer.Length(); - size_t offset = 0; - while (rest) { - size_t len = rest; - // = - if (!fBlocking && !fOutputBuffer.Free()) - break; - if (!fWriteShutdown && (fState == Connecting || fState == Connected) && !fOutputBuffer.Free()) { - bool signal = false; - AddContext(); - while (!fWriteShutdown && (fState == Connecting || fState == Connected) && !fOutputBuffer.Free()) - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - RemoveContext(); - if (signal) - if (offset) - break; - else - GUSISetPosixError(EINTR); - } - if (fWriteShutdown && !fOutputBuffer.Free()) - if (offset) - break; - else - return GUSISetPosixError(ESHUTDOWN); - fOutputBuffer.Produce(buffer, len, offset); - rest -= len; - } - - return offset; -} -// = -bool GUSIMTTcpSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = fReadShutdown || - fAsyncError || - (fState == Listening - ? fListeners[fNextListener].fBusy - : fInputBuffer.Valid() > 0 - ) - ) - cond = true; - if (canWrite) - if (*canWrite = fWriteShutdown || fAsyncError || fOutputBuffer.Free()) - cond = true; - - if (cond) - GUSI_MESSAGE(("Select%s%s\n", - (canRead && *canRead ? " read" : ""), - (canWrite && *canWrite ? " write" : ""))); - - return cond; -} -// = -int GUSIMTTcpSocket::shutdown(int how) -{ - if (GUSIMTInetSocket::shutdown(how)) - return -1; - fOutputBuffer.Lock(); - fOutputBuffer.Release(); - - return 0; -} -// MacTCP has ways to make you feel very sorry for yourself if you don't close -// streams. -// -// = -GUSIMTTcpSocket::~GUSIMTTcpSocket() -{ - TCPiopb pb; - - pb.ioCRefNum = GUSIMTInetSocket::Driver(); - pb.csCode = TCPRelease; - - if (fState == Listening) { - // = - fInputBuffer.Lock(); - for (int i = 0; i Unconnected) { - size_t consume = 0x7F000000; - fInputBuffer.Consume(nil, consume); - - GUSIContext::Yield(kGUSIBlock); - } - RemoveContext(); - - if (PBControlSync(ParmBlkPtr(&pb))) - return; - - DisposePtr(pb.csParam.create.rcvBuff); /* there is no release pb */ - } -} -// \section{Implementation of [[GUSIMTTcpFactory]]} -// -// -// = -GUSISocketFactory * GUSIMTTcpFactory::instance = nil; -// = -GUSISocket * GUSIMTTcpFactory::socket(int, int, int) -{ - return new GUSIMTTcpSocket(); -} -// = -void GUSIwithMTTcpSockets() -{ - gGUSIInetFactories.AddFactory(SOCK_STREAM, 0, GUSIMTTcpFactory::Instance()); - GUSIMTNetDB::Instantiate(); -} diff --git a/GUSI/src/tangled/GUSIMTUdp.cp b/GUSI/src/tangled/GUSIMTUdp.cp deleted file mode 100755 index 2f8dd1d..0000000 --- a/GUSI/src/tangled/GUSIMTUdp.cp +++ /dev/null @@ -1,497 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIMTUdp.h" -#include "GUSIMTInet.h" -#include "GUSIMTNetDB.h" -#include "GUSIInet.h" -#include "GUSIDiag.h" -#include "GUSISocketMixins.h" - -#include - -#include - -#include - -GUSI_USING_STD_NAMESPACE - -// \section{Definition of [[GUSIMTUdpSocket]]} -// -// [[GUSIMTUdpSocket]] have no interesting data of their own. -// -// = -class GUSIMTUdpSocket : public GUSIMTInetSocket, public GUSISMProcess { -public: - GUSIMTUdpSocket(); - ~GUSIMTUdpSocket(); - // [[connect]] installs a peer address. - // - // = - virtual int connect(void * address, socklen_t addrlen); - // [[recvfrom]] reads from [[fInputBuffer]]. - // - // = - virtual ssize_t recvfrom(const GUSIScatterer & buffer, int, void * from, socklen_t * fromlen); - // [[sendto]] writes to [[fOutputBuffer]]. It is very important that the output buffer be locked - // between writing the header and writing the data. - // - // = - virtual ssize_t sendto(const GUSIGatherer & buffer, int flags, const void * to, socklen_t addrlen); - // [[select]] checks for various conditions on the socket. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - // [[shutdown]] for writing sends a closing notice. [[fOutputBuffer]] is locked and - // released so the send procedure is called. - // - // = - virtual int shutdown(int how); -private: - // \section{Implementation of [[GUSIMTUdpSocket]]} - // - // The implementation of [[GUSIMTUdpSocket]] consists of a synchronous high level - // part which mostly deals with [[GUSIRingBuffers]] and an asynchronous low - // level part. We'll start with the low level procedures. - // - // \subsection{Interrupt level routines for [[GUSIMTUdpSocket]]} - // - // Both [[GUSIMTUSendDone]] and [[GUSIMTURecvDone]] are always called with the - // same [[UDPiopb]] in a [[GUSIMTUdpSocket]] so they can easily find out the address - // of the socket itself. [[GUSIMTUSend]] and [[GUSIMTURecv]] set up send and receive - // calls. - // - // = - UDPiopb fSendPB; - MidiWDS fSendWDS; - UDPiopb fRecvPB; - friend void GUSIMTUSend(GUSIMTUdpSocket * sock); - friend void GUSIMTURecv(GUSIMTUdpSocket * sock); - friend void GUSIMTUSendDone(UDPiopb * pb); - friend void GUSIMTURecvDone(UDPiopb * pb); - static UDPIOCompletionUPP sSendProc; - static UDPIOCompletionUPP sRecvProc; - // [[CreateStream]] creates a UDP stream. - // - // = - int CreateStream(); -}; -// [[GUSIMTUSendDone]] does all its work between [[fSendPB]] and [[fOutputBuffer]]. -// If a send fails, the whole send buffer is cleared. -// -// = -void GUSIMTUSendDone(UDPiopb * pb) -{ - GUSIMTUdpSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMTUdpSocket, fSendPB)); - GUSIProcess::A5Saver saveA5(sock->Process()); - if (sock->fOutputBuffer.Locked()) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTUSendDone), pb); - else { - sock->fOutputBuffer.ClearDefer(); - sock->fOutputBuffer.FreeBuffer(sock->fSendWDS.fDataPtr, sock->fSendWDS.fLength); - switch (sock->fSendPB.ioResult) { - case noErr: - break; /* Everything ok */ - case insufficientResources: - break; /* Queue overflow, discard packet but proceed */ - default: - sock->SetAsyncMacError(sock->fSendPB.ioResult); - for (long valid; valid = sock->fOutputBuffer.Valid(); ) - sock->fOutputBuffer.FreeBuffer(nil, valid); - sock->fWriteShutdown = true; - } - GUSIMTUSend(sock); - sock->Wakeup(); - } -} -// Since UDP consists of distinct packets, each packet is prefixed by a header when -// stored in a GUSIBuffer. -// -// = -struct GUSIUDPHeader { - in_addr_t fPeerAddr; - in_port_t fPeerPort; - uint16_t fLength; -}; -// [[GUSIMTUSend]] starts an UDP send call if there is data to send and otherwise -// sets itself up as the deferred procedure of the output buffer (and thus is -// guaranteed to be called the next time data is deposited in the buffer again). -// If all data has been delivered and a shutdown is requested, send one. -// -// To avoid race conditions, we insist that a valid request consist of at least -// 1 byte of packet data. -// -// = -void GUSIMTUSend(GUSIMTUdpSocket * sock) -{ - sock->fOutputBuffer.ClearDefer(); - if (!sock->fOutputBuffer.Valid() || sock->fOutputBuffer.Locked()) { - if (!sock->fWriteShutdown) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTUSend), sock); - else - sock->fState = GUSISMState::Closing; - } else { - sock->fOutputBuffer.ClearDefer(); - - GUSIUDPHeader header; - size_t len = sizeof(GUSIUDPHeader); - - sock->fOutputBuffer.Consume(&header, len); - - // Since we have to preserve packet sizes and [[GUSIBuffer]] does not, we sometimes - // might get the packet data in two pieces. - // - // = - len = header.fLength; - sock->fSendWDS.fDataPtr = - static_cast(sock->fOutputBuffer.ConsumeBuffer(len)); - sock->fSendWDS.fLength = (u_short) len; - if (len < header.fLength) { - len = header.fLength - len; - sock->fSendWDS.fDataPtr2 = - static_cast(sock->fOutputBuffer.ConsumeBuffer(len)); - sock->fSendWDS.fLength2 = (u_short) len; - } else - sock->fSendWDS.fLength2 = 0; - - sock->fSendPB.ioCompletion = sock->sSendProc; - sock->fSendPB.csCode = UDPWrite; - sock->fSendPB.csParam.send.remoteHost = header.fPeerAddr; - sock->fSendPB.csParam.send.remotePort = header.fPeerPort; - sock->fSendPB.csParam.send.wdsPtr = &sock->fSendWDS; - sock->fSendPB.csParam.send.checkSum = true; - sock->fSendPB.csParam.send.sendLength = 0; - - PBControlAsync(ParmBlkPtr(&sock->fSendPB)); - } -} -// [[GUSIMTURecvDone]] does all its work between [[fRecvPB]] and [[fInputBuffer]]. -// -// = -void GUSIMTURecvDone(UDPiopb * pb) -{ - GUSIMTUdpSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMTUdpSocket, fRecvPB)); - GUSIProcess::A5Saver saveA5(sock->Process()); - if (sock->fInputBuffer.Locked()) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTURecvDone), pb); - else { - sock->fInputBuffer.ClearDefer(); - switch (sock->fRecvPB.ioResult) { - case noErr: - // If the packet is too big, or if the socket is bound and a packet arrives from - // a different peer, we drop it. Whether we drop or not, we must release the buffers. - // Since we reuse the same completion procedure, we also must check whether we - // arrived here on a read or on a buffer return. - // - // = - if (sock->fRecvPB.csCode == UDPRead) { - long needed = sock->fRecvPB.csParam.receive.rcvBuffLen+8; - if (sock->fInputBuffer.Size() < needed) - ; // Drop - else if (sock->fInputBuffer.Free() < needed) { - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMTURecvDone), pb); - return; - } else if (sock->fPeerAddr.sin_port && - ( sock->fRecvPB.csParam.receive.remoteHost != sock->fPeerAddr.sin_addr.s_addr - || sock->fRecvPB.csParam.receive.remotePort != sock->fPeerAddr.sin_port - ) - ) { - ; // Drop - } else { - GUSIUDPHeader header; - size_t len = sizeof(GUSIUDPHeader); - - header.fPeerAddr = sock->fRecvPB.csParam.receive.remoteHost; - header.fPeerPort = sock->fRecvPB.csParam.receive.remotePort; - header.fLength = sock->fRecvPB.csParam.receive.rcvBuffLen; - - sock->fInputBuffer.Produce(&header, len); - len = header.fLength; - sock->fInputBuffer.Produce( - sock->fRecvPB.csParam.receive.rcvBuff, len); - } - sock->fRecvPB.csCode = UDPBfrReturn; - PBControlAsync(ParmBlkPtr(&sock->fRecvPB)); - - return; - } - // Fall through - case commandTimeout: - GUSIMTURecv(sock); - break; - default: - sock->SetAsyncMacError(sock->fRecvPB.ioResult); - sock->fReadShutdown = true; - break; - } - sock->Wakeup(); - } -} -// [[GUSIMTURecv]] starts an UDP receive call. No free space is necessary in -// the buffer. -// -// = -void GUSIMTURecv(GUSIMTUdpSocket * sock) -{ - sock->fRecvPB.ioCompletion = sock->sRecvProc; - sock->fRecvPB.csCode = UDPRead; - sock->fRecvPB.csParam.receive.timeOut = 0; - sock->fRecvPB.csParam.receive.secondTimeStamp = 0; - - PBControlAsync(ParmBlkPtr(&sock->fRecvPB)); -} -// The UPPs for the completion procedures are set up the first time a socket -// is constructed. -// -// = -UDPIOCompletionUPP GUSIMTUdpSocket::sSendProc = 0; -UDPIOCompletionUPP GUSIMTUdpSocket::sRecvProc = 0; -// = -int GUSIMTUdpSocket::CreateStream() -{ - fSendPB.ioCompletion = nil; - fSendPB.csCode = UDPCreate; - fSendPB.csParam.create.rcvBuff = (char *)NewPtr(4096); - fSendPB.csParam.create.rcvBuffLen = 4096; - fSendPB.csParam.create.notifyProc = nil; - fSendPB.csParam.create.userDataPtr = nil; - fSendPB.csParam.create.localPort = fSockAddr.sin_port; - - PBControlSync(ParmBlkPtr(&fSendPB)); - - if (fSendPB.ioResult) - return GUSISetMacError(fSendPB.ioResult); - - fState = Connected; - fStream = fRecvPB.udpStream = fSendPB.udpStream; - fSockAddr.sin_port = fSendPB.csParam.create.localPort; - - GUSIMTUSend(this); - GUSIMTURecv(this); - - return 0; -} -// \subsection{High level interface for [[GUSIMTUdpSocket]]} -// -// The constructor has to initialize a rather large number of data fields, and as a -// side effect opens the MacUDP driver if necessary. No other interesting activity -// occurs. -// -// = -GUSIMTUdpSocket::GUSIMTUdpSocket() -{ - // = - if (!sSendProc) - sSendProc = NewUDPIOCompletionProc(GUSIMTUSendDone); - if (!sRecvProc) - sRecvProc = NewUDPIOCompletionProc(GUSIMTURecvDone); - // The send and receive parameter blocks are highly specialized and never really - // change during the existence of a socket. - // - // = - fSendPB.ioCRefNum = GUSIMTInetSocket::Driver(); - fRecvPB.ioCRefNum = GUSIMTInetSocket::Driver(); -} -// = -int GUSIMTUdpSocket::connect(void * address, socklen_t addrlen) -{ - sockaddr_in * addr = (sockaddr_in *) address; - - // = - if (!GUSI_CASSERT_CLIENT(addrlen >= int(sizeof(sockaddr_in)))) - return GUSISetPosixError(EINVAL); - if (!GUSI_CASSERT_CLIENT(addr->sin_family == AF_INET)) { - memset(&fPeerAddr, 0, sizeof(sockaddr_in)); - return GUSISetPosixError(EAFNOSUPPORT); - } - // = - if (!fStream && CreateStream()) - return -1; - - fPeerAddr = *addr; - - return 0; -} -// = -ssize_t GUSIMTUdpSocket::recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen) -{ - // = - if (!fInputBuffer.Valid()) - if (GUSISetPosixError(GetAsyncError())) - return -1; - else if (fReadShutdown) - return 0; - if (!GUSI_CASSERT_CLIENT(!from || *fromlen >= int(sizeof(sockaddr_in)))) - return GUSISetPosixError(EINVAL); - // = - if (!fStream && CreateStream()) - return -1; - // The input buffer needs to be nonempty before a read can succeed. - // - // = - if (!fReadShutdown && !fInputBuffer.Valid()) { - if (!fBlocking) - return GUSISetPosixError(EWOULDBLOCK); - bool signal = false; - AddContext(); - while (!fReadShutdown && !fInputBuffer.Valid()) - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - RemoveContext(); - if (signal) - return GUSISetPosixError(EINTR); - } - - GUSIUDPHeader header; - size_t len = sizeof(GUSIUDPHeader); - - if (flags & MSG_PEEK) { - GUSIRingBuffer::Peeker peeker(fInputBuffer); - - peeker.Peek(&header, len); - len = min(buffer.Length(), (int) header.fLength); - peeker.Peek(buffer, len); - } else { - fInputBuffer.Consume(&header, len); - - len = min(buffer.Length(), (int)header.fLength); - fInputBuffer.Consume(buffer, len); - } - - if (from) { - sockaddr_in * addr = (sockaddr_in *) from; - *fromlen = sizeof(sockaddr_in); - addr->sin_family = AF_INET; - addr->sin_addr.s_addr = header.fPeerAddr; - addr->sin_port = header.fPeerPort; - } - - return (int)len; -} -// = -ssize_t GUSIMTUdpSocket::sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t addrlen) -{ - // = - if (GUSISetPosixError(GetAsyncError())) - return -1; - if (!GUSI_CASSERT_CLIENT(!to || addrlen >= int(sizeof(sockaddr_in)))) - return GUSISetPosixError(EINVAL); - if (!GUSI_CASSERT_CLIENT(buffer.Length() < 0x10000)) - return GUSISetPosixError(EINVAL); - // = - if (!fStream && CreateStream()) - return -1; - // = - size_t needed = buffer.Length()+8; - if (!fBlocking && fOutputBuffer.Free() < needed) - return GUSISetPosixError(EWOULDBLOCK); - if (!fWriteShutdown && fOutputBuffer.Free() < needed) { - if (fOutputBuffer.Size() < needed) - return GUSISetPosixError(EINVAL); - bool signal = false; - AddContext(); - while (!fWriteShutdown && fOutputBuffer.Free() < needed) - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - RemoveContext(); - if (signal) - return GUSISetPosixError(EINTR); - } - if (fWriteShutdown) - return GUSISetPosixError(ESHUTDOWN); - - GUSIUDPHeader header; - if (fPeerAddr.sin_port) { - header.fPeerAddr = fPeerAddr.sin_addr.s_addr; - header.fPeerPort = fPeerAddr.sin_port; - } else if (to) { - header.fPeerAddr = static_cast(to)->sin_addr.s_addr; - header.fPeerPort = static_cast(to)->sin_port; - } else - return GUSISetPosixError(ENOTCONN); - header.fLength = (uint16_t)buffer.Length(); - - fOutputBuffer.Lock(); - size_t len = sizeof(GUSIUDPHeader); - fOutputBuffer.Produce(&header, len); - len = buffer.Length(); - size_t offset = 0; - fOutputBuffer.Produce(buffer, len, offset); - fOutputBuffer.Release(); - - return len; -} -// = -bool GUSIMTUdpSocket::select(bool * canRead, bool * canWrite, bool *) -{ - // = - if (!fStream && CreateStream()) - return -1; - - bool cond = false; - if (canRead) - if (*canRead = fReadShutdown || fAsyncError || fInputBuffer.Valid() > 0) - cond = true; - if (canWrite) - if (*canWrite = fWriteShutdown || fAsyncError || fOutputBuffer.Free()>1600) - cond = true; - - return cond; -} -// = -int GUSIMTUdpSocket::shutdown(int how) -{ - if (GUSIMTInetSocket::shutdown(how)) - return -1; - fOutputBuffer.Lock(); - fOutputBuffer.Release(); - - return 0; -} -// MacTCP has ways to make you feel very sorry for yourself if you don't close -// streams. -// -// = -GUSIMTUdpSocket::~GUSIMTUdpSocket() -{ - if (fStream) { - UDPiopb pb; - - pb.ioCRefNum = GUSIMTInetSocket::Driver(); - pb.csCode = UDPRelease; - pb.udpStream = fStream; - - if (fState != Closing) { - shutdown(2); - - AddContext(); - while (fState != Closing) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - - if (PBControlSync(ParmBlkPtr(&pb))) - return; - - DisposePtr(pb.csParam.create.rcvBuff); /* there is no release pb */ - } -} -// \section{Implementation of [[GUSIMTUdpFactory]]} -// -// -// = -GUSISocketFactory * GUSIMTUdpFactory::instance = nil; -// = -GUSISocket * GUSIMTUdpFactory::socket(int, int, int) -{ - return new GUSIMTUdpSocket(); -} -// = -void GUSIwithMTUdpSockets() -{ - gGUSIInetFactories.AddFactory(SOCK_DGRAM, 0, GUSIMTUdpFactory::Instance()); - GUSIMTNetDB::Instantiate(); -} diff --git a/GUSI/src/tangled/GUSIMacFile.cp b/GUSI/src/tangled/GUSIMacFile.cp deleted file mode 100755 index 21b8f20..0000000 --- a/GUSI/src/tangled/GUSIMacFile.cp +++ /dev/null @@ -1,1549 +0,0 @@ -// = -#define GUSI_MESSAGE_LEVEL 5 - -#include "GUSIInternal.h" -#include "GUSIMacFile.h" -#include "GUSIFSWrappers.h" -#include "GUSISocketMixins.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" -#include "GUSIConfig.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -GUSI_USING_STD_NAMESPACE - -// \subsection{Interrupt level routines for [[GUSIMacFileSocket]]} -// -// -// = -class GUSIMacFileSocket; - -static void GUSIMFRead(GUSIMacFileSocket * sock); -static void GUSIMFReadDone(ParamBlockRec * pb); -static void GUSIMFWrite(GUSIMacFileSocket * sock); -static void GUSIMFWriteDone(ParamBlockRec * pb); -static void GUSIMFWakeup(ParamBlockRec * pb); -// \section{Definition of [[GUSIMacFileSocket]]} -// -// -// = -class GUSIMacFileSocket : - public GUSISocket, - public GUSISMProcess, - protected GUSISMAsyncError, - protected GUSISMBlocking, - protected GUSISMState, - protected GUSISMInputBuffer, - protected GUSISMOutputBuffer -{ -public: - GUSIMacFileSocket(short fileRef, bool append, int mode); - ~GUSIMacFileSocket(); - // = - virtual ssize_t read(const GUSIScatterer & buffer); - // To speed up writes, they go into a write-behind buffer and are flushed out - // asynchronously. This causes errors to be reported with some delay. - // - // = - virtual ssize_t write(const GUSIGatherer & buffer); - // = - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - // = - virtual int fsync(); - // [[fcntl]] handles the blocking support. - // - // = - virtual int fcntl(int cmd, va_list arg); - // [[ioctl]] deals with blocking support and with [[FIONREAD]]. - // - // = - virtual int ioctl(unsigned int request, va_list arg); - // [[getsockopt]] and [[setsockopt]] are available for setting buffer sizes and getting - // asynchronous errors. - // - // = - virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen); - // = - virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen); - // = - virtual off_t lseek(off_t offset, int whence); - // = - virtual int ftruncate(off_t offset); - // [[fstat]] is implemented via [[stat]] (early implementations had it the other - // way around, but this failed with directories). - // - // = - virtual int fstat(struct stat * buf); - // File sockets implement simple calls. - // - // = - virtual bool Supports(ConfigOption config); -private: - // \section{Implementation of [[GUSIMacFileSocket]]} - // - // The implementation of [[GUSIMacFileSocket]] consists of a synchronous high level - // part which mostly deals with [[GUSIRingBuffers]] and an asynchronous low - // level part. Since file sockets have some different properties than other sockets, - // it is helpful to start with the high level routines. - // - // \subsection{High level interface for [[GUSIMacFileSocket]]} - // - // The constructor has to initialize a rather large number of data fields. - // - // = - short fFileRef; - bool fAppend; - bool fWriteBehind; - // Under some circumstances, [[read]] uses a readahead buffer. Since this - // optimization can actually pessimize applications, we're very conservative - // by only turning it on for readonly files and by turning it off as soon as - // [[lseek]] is called. [[SyncRead]] puts the socket into a predictable state - // afterwards. - // - // [[fPosition]] contains the next position where operations apply, not counting - // read-ahead data, but counting write-behind. [[fReadAhead]] indicates that a - // read-ahead should be started on the first read operation. [[fBeyondEOF]] indicates - // that [[fPosition]] resulted from a seek beyond the current end of file position. - // - // = - bool fReadAhead; - bool fBeyondEOF; - long fPosition; - // = - void SyncRead(); - // As opposed to [[SyncRead]], [[SyncWrite]] doesn't change the long-term strategy. - // By temporarily turning off [[fWriteBehind]], it signals that the write strategy - // should write the remaining data even if it does not align to cache blocks. - // - // = - void SyncWrite(); - // It is often advantageous to keep I/O requests a multiple of the allocation - // block size. - // - // = - size_t fBlockSize; - // = - ParamBlockRec fReadPB; - ParamBlockRec fWritePB; - friend void GUSIMFRead(GUSIMacFileSocket * sock); - friend void GUSIMFReadDone(ParamBlockRec * pb); - friend void GUSIMFWrite(GUSIMacFileSocket * sock); - friend void GUSIMFWriteDone(ParamBlockRec * pb); - friend void GUSIMFWakeup(ParamBlockRec * pb); - static IOCompletionUPP sReadProc; - static IOCompletionUPP sWriteProc; - static IOCompletionUPP sWakeupProc; -}; -// \section{Definition of [[GUSIMacDirectory]]} -// -// -// = -class GUSIMacDirectory : public GUSIDirectory { -public: - GUSIMacDirectory(const FSSpec & spec); - - // = - virtual dirent * readdir(); - // = - virtual long telldir(); - // = - virtual void seekdir(long pos); - // = - virtual void rewinddir(); -private: - // \section{Implementation of [[GUSIMacDirectory]]} - // - // - // = - GUSIFileSpec fDir; - short fPos; - dirent fEnt; -}; -// [[GUSIMFWriteDone]] does all its work between [[fWritePB]] and [[fOutputBuffer]]. -// If a write fails, the whole write buffer is cleared. -// -// = -static void GUSIMFWriteDone(ParamBlockRec * pb) -{ - GUSIMacFileSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMacFileSocket, fWritePB)); - // To atone for the risky practice of [[reinterpret_cast<>]], we at least check for - // plausibility by comparing the two fields storing the file reference number. - // - // = - GUSI_CASSERT_INTERNAL(sock->fFileRef == pb->ioParam.ioRefNum); - GUSIProcess::A5Saver saveA5(sock->Process()); - GUSI_SMESSAGE("Write done.\n"); - if (sock->fOutputBuffer.Locked()) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMFWriteDone), pb); - else { - sock->fOutputBuffer.ClearDefer(); - sock->fOutputBuffer.FreeBuffer( - sock->fWritePB.ioParam.ioBuffer, sock->fWritePB.ioParam.ioReqCount); - if (sock->SetAsyncMacError(sock->fWritePB.ioParam.ioResult)) { - for (long valid; valid = sock->fOutputBuffer.Valid(); ) - sock->fOutputBuffer.FreeBuffer(nil, valid); - sock->fWriteShutdown = true; - } - GUSIMFWrite(sock); - sock->Wakeup(); - } -} -// [[GUSIMFWrite]] starts a file write call if there is data to write and otherwise -// sets itself up as the deferred procedure of the output buffer (and thus is -// guaranteed to be called the next time data is deposited in the buffer again). -// If all data has been delivered and a shutdown is requested, terminate. -// -// = -static void GUSIMFWrite(GUSIMacFileSocket * sock) -{ - size_t valid = sock->fOutputBuffer.Valid(); - if (sock->fWriteShutdown && !valid) - sock->fOutputBuffer.ClearDefer(); - else if (!valid) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMFWrite), sock); - else { - sock->fOutputBuffer.ClearDefer(); - valid = min(valid, sock->fOutputBuffer.Size() >> 1); - sock->fWritePB.ioParam.ioBuffer = - static_cast(sock->fOutputBuffer.ConsumeBuffer(valid)); - // Whenever possible, we try to maintain alignment with allocation block - // boundaries. If write to a write-only file is aligned, we request that it - // not be cached, which improves performance. - // - // = - long pos = sock->fPosition - sock->fOutputBuffer.Valid(); - size_t align = pos % sock->fBlockSize; - if (align) - valid = min(valid, sock->fBlockSize-align); - else if (valid > sock->fBlockSize) - valid -= valid % sock->fBlockSize; - sock->fWritePB.ioParam.ioPosMode = fsAtMark + - (sock->fWriteBehind && valid >= sock->fBlockSize) ? noCacheMask : 0; - sock->fWritePB.ioParam.ioReqCount = valid; - sock->fWritePB.ioParam.ioActCount = 0; - - GUSI_MESSAGE(("Async write (0x%x bytes).\n", valid)); - PBWriteAsync(&sock->fWritePB); - } -} -// [[GUSIMFReadDone]] does all its work between [[fReadPB]] and [[fInputBuffer]]. -// If a read fails, the whole write buffer is cleared. -// -// = -static void GUSIMFReadDone(ParamBlockRec * pb) -{ - GUSIMacFileSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMacFileSocket, fReadPB)); - // To atone for the risky practice of [[reinterpret_cast<>]], we at least check for - // plausibility by comparing the two fields storing the file reference number. - // - // = - GUSI_CASSERT_INTERNAL(sock->fFileRef == pb->ioParam.ioRefNum); - GUSIProcess::A5Saver saveA5(sock->Process()); - GUSI_MESSAGE(("Read done (0x%x/%d).\n", pb->ioParam.ioActCount, pb->ioParam.ioResult)); - if (sock->fInputBuffer.Locked()) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMFReadDone), pb); - else { - sock->fInputBuffer.ClearDefer(); - sock->fInputBuffer.ValidBuffer( - sock->fReadPB.ioParam.ioBuffer, sock->fReadPB.ioParam.ioActCount); - if (sock->SetAsyncMacError(sock->fReadPB.ioParam.ioResult)) - sock->fReadShutdown = true; - else if (!sock->fReadShutdown) - GUSIMFRead(sock); - sock->Wakeup(); - } -} -// [[GUSIMFRead]] starts a file read call. -// -// = -static void GUSIMFRead(GUSIMacFileSocket * sock) -{ - size_t free = sock->fInputBuffer.Free(); - if (free < (sock->fInputBuffer.Size() >> 2)) { - if (!sock->fReadShutdown) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIMFRead), sock); - else - sock->fInputBuffer.ClearDefer(); - } else { - sock->fInputBuffer.ClearDefer(); - free = min(free, sock->fInputBuffer.Size() >> 1); - // Whenever possible, we try to maintain alignment with allocation block - // boundaries. - // - // = - long pos = sock->fPosition + sock->fInputBuffer.Valid(); - size_t align = pos % sock->fBlockSize; - if (align) - free = min(free, sock->fBlockSize-align); - else if (free > sock->fBlockSize) - free -= free % sock->fBlockSize; - - sock->fReadPB.ioParam.ioBuffer = - static_cast(sock->fInputBuffer.ProduceBuffer(free)); - sock->fReadPB.ioParam.ioReqCount = free; - sock->fReadPB.ioParam.ioActCount = 0; - - GUSI_MESSAGE(("Async read 0x%x 0x%x (0x%x bytes).\n", sock, &sock->fReadPB, free)); - PBReadAsync(&sock->fReadPB); - } -} -// [[GUSIMFWakeup]] simply wakes up its socket. -// -// = -static void GUSIMFWakeup(ParamBlockRec * pb) -{ - GUSIMacFileSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIMacFileSocket, fReadPB)); - // To atone for the risky practice of [[reinterpret_cast<>]], we at least check for - // plausibility by comparing the two fields storing the file reference number. - // - // = - GUSI_CASSERT_INTERNAL(sock->fFileRef == pb->ioParam.ioRefNum); - sock->Wakeup(); -} -// On 68K machines, completion procedures get called with the argument in the -// A0 register, which really cramps our style. Therefore, we wrap each -// procedure. -// -// = -GUSI_COMPLETION_PROC_A0(GUSIMFReadDone, ParamBlockRec) -GUSI_COMPLETION_PROC_A0(GUSIMFWriteDone, ParamBlockRec) -GUSI_COMPLETION_PROC_A0(GUSIMFWakeup, ParamBlockRec) -// \section{Implementation of [[GUSIMacFileDevice]]} -// -// -// = -static auto_ptr sGUSIMacFileDevice; -// = -GUSIMacFileDevice * GUSIMacFileDevice::Instance() -{ - if (!sGUSIMacFileDevice.get()) - sGUSIMacFileDevice = auto_ptr(new GUSIMacFileDevice); - return sGUSIMacFileDevice.get(); -} -// = -GUSIMacFileDevice::~GUSIMacFileDevice() -{ - CleanupTemporaries(true); -} -// [[GUSIMacFileDevice]] will handle no device requests. It will always fail -// if any parent directory of the file does not exist, and for most calls -// fails unless the file itself exists. -// -// = -bool GUSIMacFileDevice::Want(GUSIFileToken & file) -{ - if (!file.IsFile()) - return false; - if (!file.Error() && file.Exists()) - return true; - if (file.Error() == fnfErr) - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - case GUSIFileToken::kWillMkdir: - case GUSIFileToken::kWillSymlink: // A borderline case - return true; - } - - return false; -} -// = -GUSISocket * GUSIMacFileDevice::open(GUSIFileToken & file, int flags) -{ - OSErr err; - char permission; - short fileRef; - - // First, we need to translate the POSIX open flags into a Mac file permission. - // - // = - switch (flags & 3) { - case O_RDONLY: - permission = fsRdPerm; - break; - case O_WRONLY: - case O_RDWR: - permission = - GUSIConfiguration::Instance()->fSharedOpen ? fsRdWrShPerm : fsRdWrPerm; - break; - } -tryOpen: - // Now, we attempt to open the data or resource fork of the file. - // - // = - if (flags & O_RSRC) - err = GUSIFSOpenRF(&file, permission, &fileRef); - else - err = GUSIFSOpenDF(&file, permission, &fileRef); - // If the file did not exist, we try to create it. We don't need to worry - // about special casing for [[O_RSRC]] here, I think. - // - // = - if (err == fnfErr && (flags & O_CREAT)) { - if (!(err = GUSIFSCreate(&file))) { - GUSIConfiguration::Instance()->SetDefaultFType(file); - file.TouchFolder(); - } - if (!err || err == dupFNErr) { - flags &= ~(O_CREAT | O_EXCL); // Avoid loop or false positive - goto tryOpen; // Retry - } - } - // Now we check whether the [[Open]] ultimately succeeded. - // - // = - switch (err) { - case afpObjectTypeErr: - return GUSISetPosixError(EISDIR), static_cast(nil); - default: - return GUSISetMacError(err), static_cast(nil); - case noErr: - break; - } - // If we got to this point with [[O_EXCL]] still set, the file must have existed, - // but it shouldn't have. If [[O_TRUNC]] is set, truncate the file. - // - // = - if (flags & O_EXCL) { - FSClose(fileRef); - return GUSISetPosixError(EEXIST), static_cast(nil); - } - - if (flags & O_TRUNC) - SetEOF(fileRef, 0); - - return open(fileRef, flags); -} -// There is also a special case backdoor [[open]], available only for -// [[GUSIMacFileDevice]] to handle files which are already open somehow. -// This open will never fail except for lack of memory. -// -// = -GUSISocket * GUSIMacFileDevice::open(short fileRef, int flags) -{ - GUSISocket * sock; - - if (!(sock = - new GUSIMacFileSocket(fileRef, (flags & O_APPEND) != 0, flags & 3) - )) { - FSClose(fileRef); - GUSISetPosixError(ENOMEM); - } - - return sock; -} -// = -int GUSIMacFileDevice::remove(GUSIFileToken & file) -{ - OSErr err; - - switch (err = GUSIFSDelete(&file)) { - case noErr: - return 0; - case fBsyErr: - return MarkTemporary(file); - default: - return GUSISetMacError(err); - } -} -// = -int GUSIMacFileDevice::MarkTemporary(const FSSpec & file) -{ - OSErr err; - GUSITempFileSpec temp(file.vRefNum, file.name); - - if (err = GUSIFSMoveRename(&file, &temp)) - return GUSISetMacError(err); - TempQueue * q = new TempQueue; - q->fNext = fTemporaries; - q->fSpec = temp; - fTemporaries = q; - - return 0; -} -// [[CleanupTemporaries]] tries at promising times to delete as many of the temporary -// files as possible. -// -// = -void GUSIMacFileDevice::CleanupTemporaries(bool giveup) -{ - TempQueue ** p = &fTemporaries; - - for (TempQueue * q = *p; q; q = *p) - if (GUSIFSDelete(&q->fSpec) != fBsyErr || giveup) { - // Delete entry - *p = q->fNext; - delete q; - } else { - // Keep entry - p = &q->fNext; - } -} -// = -int GUSIMacFileDevice::rename(GUSIFileToken & file, const char * newname) -{ - OSErr err; - GUSIFileSpec newfile(newname, true); - - // We can only move a file around a volume. - // - // = - if (!file.Exists()) - return GUSISetMacError(file.Error()); - if (file->vRefNum != newfile->vRefNum) - return GUSISetPosixError(EXDEV); - bool samename = EqualString(file->name, newfile->name, true, true); - bool samedir = file->parID == newfile->parID; - bool newexists= newfile.Exists(); - // If one of the two files is locked, or if the two names are distinct only by case, - // we call ourselves recursively, wrapped in the special case code. These conditions - // are rare, so some inefficiency is not all that tragic. - // - // = - if (samename && samedir) - return 0; - if (file.CatInfo()->Locked()) { - GUSIFSRstFLock(&file); - int res = rename(file, newname); - GUSIFSSetFLock(res ? &file : &newfile); - return res; - } - if (newexists && file.CatInfo()->Locked()) { - GUSIFSRstFLock(&newfile); - int res = rename(file, newname); - if (res) - GUSIFSSetFLock(&newfile); - return res; - } - if (samedir && !samename && EqualString(file->name, newfile->name, false, true)) - newexists = false; - // If the target name refers to an existing file, we stash it away until we're - // sure the rename succeeded. - // - // = - GUSIFileSpec target; - if (newexists) { - target = GUSITempFileSpec(newfile->vRefNum, newfile->parID); - if (err = GUSIFSRename(&newfile, target->name)) - return GUSISetMacError(err); - } - if (samedir) - err = GUSIFSRename(&file, newfile->name); - else if (samename) - err = GUSIFSCatMove(&file, newfile->parID); - else - err = GUSIFSMoveRename(&file, &newfile); - -cleanuptarget: - // = - if (newexists) - if (!err) - GUSIFSDelete(&target); - else - GUSIFSRename(&target, newfile->name); - - return GUSISetMacError(err); -} -// = -int GUSIMacFileDevice::stat(GUSIFileToken & file, struct stat * buf) -{ - if (file.IsDevice()) { - // Any existing device should return an OK result, so give just a set of defaults. - // - // <[[return]] an alibi [[stat]] buffer>= - buf->st_dev = 'dev '; - buf->st_ino = '????'; - buf->st_mode = S_IFCHR | 0666 ; - buf->st_nlink = 1; - buf->st_uid = 0; - buf->st_gid = 0; - buf->st_rdev = 0; - buf->st_size = 1; - buf->st_atime = time(NULL); - buf->st_mtime = time(NULL); - buf->st_ctime = time(NULL); - buf->st_blksize = 0; - buf->st_blocks = 1; - - return 0; - } else if (!file.Exists()) - return GUSISetPosixError(ENOENT); - - const GUSICatInfo & cb = *file.CatInfo(); - GUSIIOPBWrapper pb; - Str63 vName; - - pb->ioNamePtr = vName; - pb->ioVRefNum = file->vRefNum; - pb->ioVolIndex = 0; - - if (GUSIFSXGetVolInfo(&pb)) - return GUSISetPosixError(ENOENT); - - buf->st_dev = pb->ioVRefNum; - buf->st_ino = cb.DirInfo().ioDrDirID; - buf->st_nlink = 1; - buf->st_uid = 0; - buf->st_gid = 0; - buf->st_rdev = 0; - buf->st_atime = cb.FileInfo().ioFlMdDat; - buf->st_mtime = cb.FileInfo().ioFlMdDat; - buf->st_ctime = cb.FileInfo().ioFlCrDat; - buf->st_blksize = pb->ioVAlBlkSiz; - - if (!cb.IsFile()) { - // Depending on our preference settings, we employ a faster or a slower method - // in determining the link count. The \emph{accurate} method sets the link - // count to 2 plus the number of subdirectories, while the fast method establishes - // an upper boundary on that number as 2 plus the number of subitems. - // - // = - ++buf->st_nlink; - if (GUSIConfiguration::Instance()->fAccurateStat) { - GUSIFileSpec spec; - - spec.SetVRef(pb->ioVRefNum); - spec.SetParID(cb.DirInfo().ioDrDirID); - for (int i = 0; i++ < cb.DirInfo().ioDrNmFls;) { - spec = spec[i]; - if (!spec.Error() && spec.CatInfo() && !spec.CatInfo()->IsFile()) - ++buf->st_nlink; - } - } else { - buf->st_nlink += cb.DirInfo().ioDrNmFls; - } - buf->st_mode = S_IFDIR | 0666; - if (!gGUSIExecHook || gGUSIExecHook(&file)) - buf->st_mode |= 0111; - - buf->st_size = cb.DirInfo().ioDrNmFls; - } else if (cb.IsAlias()) { - buf->st_mode = S_IFLNK | 0777; - buf->st_size = cb.FileInfo().ioFlRLgLen; /* Data fork is ignored */ - } else if (cb.FInfo().fdType == '·OCK') { - buf->st_mode = S_IFSOCK | 0666; - buf->st_size = cb.FileInfo().ioFlRLgLen; /* Data fork is ignored */ - } else { - buf->st_mode = S_IFREG | 0666; - if (cb.FileInfo().ioFlAttrib & 0x01) - buf->st_mode &= ~0222; - - if (gGUSIExecHook) { - if (gGUSIExecHook(&file)) - buf->st_mode |= 0111; - } else - switch (cb.FInfo().fdType) { - case 'APPL': - case 'appe': - buf->st_mode |= 0111; - } - - buf->st_size = cb.FileInfo().ioFlLgLen; /* Resource fork is ignored */ - } - - buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize; - - return 0; -} -// = -int GUSIMacFileDevice::chmod(GUSIFileToken & file, mode_t mode) -{ - if (file.IsDevice()) - return GUSISetPosixError(EINVAL); - if (!file.Exists()) - return GUSISetPosixError(ENOENT); - if (file.IsFile()) - if (mode & S_IWUSR) { - if (file.CatInfo()->Locked()) - GUSIFSRstFLock(&file); - } else { - if (!file.CatInfo()->Locked()) - GUSIFSSetFLock(&file); - } - - return 0; -} -// = -int GUSIMacFileDevice::utime(GUSIFileToken & file, const utimbuf * times) -{ - if (file.IsDevice()) - return GUSISetPosixError(EINVAL); - if (!file.Exists()) - return GUSISetPosixError(ENOENT); - GUSIIOPBWrapper info; - info.fPB = *file.CatInfo(); - info->FileInfo().ioDirID = file->parID; - if (times) - info->FileInfo().ioFlMdDat = times->modtime; - return GUSISetMacError(GUSIFSSetCatInfo(&info)); -} -// = -int GUSIMacFileDevice::access(GUSIFileToken & file, int mode) -{ - if (file.IsDevice()) - return GUSISetPosixError(EINVAL); - - const GUSICatInfo * info = file.CatInfo(); - - if (!info) - switch (file.Error()) { - case afpAccessDenied: - return GUSISetPosixError(EACCES); - case ioErr: - return GUSISetPosixError(EIO); - case bdNamErr: - case fnfErr: - case nsvErr: - case paramErr: - case dirNFErr: - case afpObjectTypeErr: - /* ENOENT */ - default: - return GUSISetPosixError(ENOENT); /* Don't know what the error is. */ - } - - // - // Under our simplifying assumptions, we don't check AppleShare permissions, - // so if we managed to do a GetCatInfo, R_OK and F_OK are already assumed - // to be true - // - if (mode & W_OK) { - // - // Check if volume is locked - // - GUSIIOPBWrapper vol; - - vol->volumeParam.ioNamePtr = nil; - vol->volumeParam.ioVolIndex = 0; - vol->volumeParam.ioVRefNum = file->vRefNum; - - if (GUSIFSHGetVInfo(&vol)) - return GUSISetPosixError(EINVAL); // Should never happen - - if (vol->volumeParam.ioVAtrb & 0x8080) - return GUSISetPosixError(EROFS); // Yup, volume is locked - - // - // Check if file is locked - // - if (info->Locked()) - return GUSISetPosixError(EACCES); // Yup, file is locked - } - - if (mode & X_OK) - if (gGUSIExecHook) { - if (!gGUSIExecHook(&file)) - return GUSISetPosixError(EACCES); - } else - switch (info->FInfo().fdType) { - case 'APPL': - case 'appe': - break; - default: - return GUSISetPosixError(EACCES); - } - - return 0; -} -// = -int GUSIMacFileDevice::mkdir(GUSIFileToken & file) -{ - return GUSISetMacError(GUSIFSDirCreate(&file)); -} -// = -int GUSIMacFileDevice::rmdir(GUSIFileToken & file) -{ - return GUSISetMacError(GUSIFSDelete(&file)); -} -// = -GUSIDirectory * GUSIMacFileDevice::opendir(GUSIFileToken & file) -{ - GUSIDirectory * dir = 0; - - ++file; - if (!file.Error()) - dir = new GUSIMacDirectory(file); - else - GUSISetPosixError(ENOTDIR); - - return dir; -} -// [[VRef2Icon]] finds the driver icon for a volume. -// -// = -static OSErr VRef2Icon(short vRef, Handle * icon) -{ - OSErr err; - short cRef; - - { - // = - GUSIIOPBWrapper hpb; - hpb->volumeParam.ioVRefNum = vRef; - hpb->volumeParam.ioNamePtr = nil; - hpb->volumeParam.ioVolIndex = 0; - if (err = GUSIFSHGetVInfo(&hpb)) - return err; - vRef = hpb->volumeParam.ioVDrvInfo; - cRef = hpb->volumeParam.ioVDRefNum; - } - { - // = - GUSIIOPBWrapper pb; - pb->cntrlParam.ioVRefNum = vRef; - pb->cntrlParam.ioCRefNum = cRef; - pb->cntrlParam.csCode = 21; - - if (err = pb.Control()) - return err; - - PtrToHand(*(Ptr *) pb->cntrlParam.csParam, icon, 256); - } - - return noErr; -} -// [[AliasTypeExpert]] finds the right file type, creator, icon location and icon -// ID for the alias. This is complicated by many special cases. -// -// = -typedef OSType AliasTypeMap[2]; - -static AliasTypeMap sMap[] = { - // This is the current list of special folders. I suppose it should be revised - // occasionally. In fact, it is probably already out of date. - // - // = - {'amnu', 'faam'}, - {'ctrl', 'fact'}, - {'extn', 'faex'}, - {'pref', 'fapf'}, - {'prnt', 'fapn'}, - {'empt', 'trsh'}, - {'trsh', 'trsh'}, - {'strt', 'fast'}, - {'macs', 'fasy'}, - { 0, 0} -}; - -static void AliasTypeExpert( - const GUSIFileSpec & file, - OSType * fCreator, - OSType * fType, - GUSIFileSpec * iconFile, - short * iconID) -{ - const GUSICatInfo * info = file.CatInfo(); - - *fCreator = 'MACS'; - *iconFile = file; - *iconID = kCustomIconResource; - - if (!info->IsFile()) { - // One of the complex issues is the various AppleShare related aliases, but those - // should not change too much. - // - // = - GetVolParmsInfoBuffer volParms; - - if (!GUSIFSGetVolParms(file->vRefNum, &volParms) && volParms.vMServerAdr) - if (file->parID == fsRtParID) - *fType = 'srvr'; - else if (!info->HasRdPerm()) - *fType = 'fadr'; - else - *fType = 'faet'; - else if (file->parID == fsRtParID) - *fType = 'hdsk'; - else if (info->DirIsMounted()) - *fType = 'famn'; - else if (info->DirIsExported()) - *fType = 'fash'; - else if (info->DirIsShared()) - *fType = 'faet'; - else - *fType = 'fdrp'; -// = -if (file->parID != fsRtParID && info->DirInfo().ioDrDirID < 9) { - short vRef; - long dirID; - - for (AliasTypeMap * mapp = sMap; **mapp; ++mapp) - if (FindFolder(file->vRefNum, (*mapp)[0], false, &vRef, &dirID)) - continue; - else if (dirID == info->DirInfo().ioDrDirID) { - *fType = (*mapp)[1]; - - break; - } -} - if (file->parID == fsRtParID) { - iconFile->SetParID(fsRtDirID); - iconFile->SetName("\pIcon\n"); - } else { - *iconFile += "\pIcon\n"; - } - } else { - *fType = info->FInfo().fdType; - *fCreator= info->FInfo().fdCreator; - } - - return; -error: - *fType = 0; - *fCreator = 0; -} -// [[AddIconsToFile]] adds the appropriate icons to the alias file as the custom -// icon. The mechanical part of the work is performed by [[CopyIconFamily]] -// -// = -static OSType sIconTypes[] = { - 'ICN#', - 'ics#', - 'icl4', - 'ics4', - 'icl8', - 'ics8', - 0 -}; - -static bool CopyIconFamily( - short srcResFile, short srcID, short dstResFile, short dstID) -{ - Handle icon; - bool success = false; - - for (OSType * types = sIconTypes; *types; ++types) { - UseResFile(srcResFile); - if (icon = Get1Resource(*types, srcID)) { - UseResFile(dstResFile); - DetachResource(icon); - AddResource(icon, *types, dstID, "\p"); - - success = success || !ResError(); - } - } - - return success; -} - -static bool AddIconsToFile( - const GUSIFileSpec & origFile, short aliasFile, - const GUSIFileSpec & iconFile, short iconID, - bool plainDisk) -{ - bool hasCustomIcons = false; - short iFile = FSpOpenResFile(&iconFile, fsRdPerm); - - if (iFile != -1) { - hasCustomIcons = - CopyIconFamily(iFile, iconID, aliasFile, kCustomIconResource); - CloseResFile(iFile); - } - if (!hasCustomIcons && plainDisk) { - Handle icon; - if (!VRef2Icon(origFile->vRefNum, &icon)) { - AddResource(icon, 'ICN#', kCustomIconResource, "\p"); - - hasCustomIcons = !ResError(); - } - } - - return hasCustomIcons; -} -// = -int GUSIMacFileDevice::symlink(GUSIFileToken & to, const char * newlink) -{ - if (!to.Exists()) - return GUSISetPosixError(EIO); - if (to.IsDevice()) - return GUSISetPosixError(EINVAL); - - OSType fileType; - OSType fileCreator; - short iconID; - short aliasFile; - AliasHandle alias; - bool customIcon; - GUSIFileSpec iconFile; - FInfo info; - - // = - GUSIFileSpec newnm(newlink, true); - - if (newnm.Error()) - return GUSISetPosixError(EIO); - if (newnm.Exists()) - return GUSISetPosixError(EEXIST); - - AliasTypeExpert(to, &fileCreator, &fileType, &iconFile, &iconID); - FSpCreateResFile(&newnm, fileCreator, fileType, smSystemScript); - - if (ResError()) - return GUSISetPosixError(EIO); - - aliasFile = FSpOpenResFile(&newnm, fsRdWrPerm); - if (aliasFile == -1) - goto deleteFile; - - if (NewAlias(nil, &to, &alias)) - goto closeFile; - - AddResource((Handle) alias, 'alis', 0, to->name); - if (ResError()) - goto deleteAlias; - - customIcon = AddIconsToFile(to, aliasFile, iconFile, iconID, - fileType == 'hdsk' && fileCreator == 'MACS'); - - CloseResFile(aliasFile); - - GUSIFSGetFInfo(&newnm, &info); - info.fdFlags |= kIsAlias | (customIcon ? kHasCustomIcon : 0); - info.fdFlags &= ~kHasBeenInited; - GUSIFSSetFInfo(&newnm, &info); - newnm.TouchFolder(); - - return 0; - -deleteAlias: - DisposeHandle((Handle) alias); -closeFile: - CloseResFile(aliasFile); -deleteFile: - GUSIFSDelete(&newnm); - - return GUSISetPosixError(EIO); -} -// = -int GUSIMacFileDevice::readlink(GUSIFileToken & link, char * buf, int bufsize) -{ - if (link.IsDevice()) - return GUSISetPosixError(EINVAL); - - char * resPath = link.AliasPath(); - - if (!(resPath)) - if (link.Error() == resFNotFound) - return GUSISetPosixError(EINVAL); - else - return GUSISetMacError(link.Error()); - - int len = strlen(resPath); - strncpy(buf, resPath, bufsize); - - if (len >= bufsize) - return GUSISetPosixError(ENAMETOOLONG); - else - return len; -} -// = -int GUSIMacFileDevice::fgetfileinfo(GUSIFileToken & file, OSType * creator, OSType * type) -{ - FInfo info; - - if (file.IsDevice()) - return GUSISetPosixError(EINVAL); - if (file.Error() || !file.Exists() || GUSIFSGetFInfo(&file, &info)) - return GUSISetPosixError(EIO); - if (creator) - *creator = info.fdCreator; - if (type) - *type = info.fdType; - - return 0; -} -// = -int GUSIMacFileDevice::fsetfileinfo(GUSIFileToken & file, OSType creator, OSType type) -{ - FInfo info; - - if (file.IsDevice()) - return GUSISetPosixError(EINVAL); - if (file.Error() || !file.Exists() || GUSIFSGetFInfo(&file, &info)) - return GUSISetPosixError(EIO); - - info.fdType = type; - info.fdCreator = creator; - info.fdFlags &= ~kHasBeenInited; - - if (GUSIFSSetFInfo(&file, &info)) - return GUSISetPosixError(EIO); - return 0; -} -// = -int GUSIMacFileDevice::faccess(GUSIFileToken &, unsigned *, void *) -{ - return GUSISetPosixError(EINVAL); -} -// = -GUSIMacFileSocket::GUSIMacFileSocket(short fileRef, bool append, int mode) - : fFileRef(fileRef), fAppend(append), fWriteBehind(false) -{ - switch (mode) { - case O_RDONLY: - fWriteShutdown = true; - fWritePB.ioParam.ioResult = wrPermErr; - break; - case O_WRONLY: - fWriteBehind = true; - // Fall through - case O_RDWR: - fReadShutdown = true; - break; - } - // = - fPosition = 0; - fReadAhead = !fReadShutdown; - fBeyondEOF = false; - // = - fBlockSize = 4096; - - GUSIIOPBWrapper fcb; - Str63 name; - - fcb->ioNamePtr = name; - fcb->ioRefNum = fFileRef; - fcb->ioFCBIndx = 0; - if (!GUSIFSGetFCBInfo(&fcb)) { - GUSIIOPBWrapper info; - info->ioNamePtr = name; - info->ioVRefNum = fcb->ioVRefNum; - info->ioVolIndex= 0; - - if (!GUSIFSXGetVolInfo(&info)) - fBlockSize = info->ioVAlBlkSiz; - } - // = - if (!fReadShutdown && !sReadProc) - sReadProc = NewIOCompletionProc(reinterpret_cast(GUSIMFReadDoneEntry)); - if (!fWriteShutdown && !sWriteProc) - sWriteProc = NewIOCompletionProc(reinterpret_cast(GUSIMFWriteDoneEntry)); - if (!sWakeupProc) - sWakeupProc = NewIOCompletionProc(reinterpret_cast(GUSIMFWakeupEntry)); - // The write and read parameter blocks are highly specialized and never really - // change during the existence of a socket. - // - // = - fReadPB.ioParam.ioResult = 0; - fReadPB.ioParam.ioRefNum = fFileRef; - fReadPB.ioParam.ioPosMode = fsAtMark; - if (!fWriteShutdown) { - fWritePB.ioParam.ioCompletion = sWriteProc; - fWritePB.ioParam.ioResult = 0; - fWritePB.ioParam.ioRefNum = fFileRef; - fWritePB.ioParam.ioPosMode = fsAtMark; - - GUSIMFWrite(this); - } -} -// = -GUSIMacFileSocket::~GUSIMacFileSocket() -{ - fsync(); - if (fFileRef) - FSClose(fFileRef); - GUSIMacFileDevice::Instance()->CleanupTemporaries(false); -} -// = -void GUSIMacFileSocket::SyncRead() -{ - fReadAhead = false; - fReadShutdown = true; - // As soon as [[fReadShutdown]] is set, no new reads will be started, so just wait - // for the current ones to complete. - // - // = - if (fReadPB.ioParam.ioResult == 1) { - AddContext(); - while (fReadPB.ioParam.ioResult == 1) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - // If there was data in the buffer, we need to move the file position back by - // the amount of data. - // - // = - size_t consume = 0x7F000000; - fInputBuffer.Consume(nil, consume); -} -// = -void GUSIMacFileSocket::SyncWrite() -{ - fOutputBuffer.Lock(); - bool saveWriteBehind = fWriteBehind; - fWriteBehind = false; - fOutputBuffer.Release(); - AddContext(); - while (!fWriteShutdown && fOutputBuffer.Valid()) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - fOutputBuffer.Lock(); - fWriteBehind = saveWriteBehind; - fOutputBuffer.Release(); -} -// = -ssize_t GUSIMacFileSocket::read(const GUSIScatterer & buffer) -{ - size_t rest = buffer.Length(); - size_t offset = 0; - - GUSI_MESSAGE(("pos: %d len: %d\n", fPosition, rest)); - - SyncWrite(); - if (fBeyondEOF) - if (GUSISetPosixError(GetAsyncError())) - return -1; - else - return 0; - - // As long as there has been no [[fReadShutdown]], we use the read-ahead buffer. - // - // = - while (!fReadAhead && (!fReadShutdown || fInputBuffer.Valid()) && rest) { - if (fInputBuffer.Valid()) { - size_t len = rest; - fInputBuffer.Lock(); - fInputBuffer.Consume(buffer, len, offset); - fPosition += len; - fInputBuffer.Release(); - rest -= len; - } else { - if (GUSISetPosixError(GetAsyncError())) - return -1; - if (!fBlocking) - if (!offset) // Nothing read yet - return GUSISetPosixError(EWOULDBLOCK); - else - return offset; - AddContext(); - while (!fReadShutdown && !fInputBuffer.Valid()) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - } - // If there is still data to be read, read it now. - // - // = - if (!rest) - return buffer.Length(); - do { - size_t len = rest; - fReadPB.ioParam.ioCompletion = sWakeupProc; - fReadPB.ioParam.ioBuffer = - buffer.Count()==1 ? - static_cast(buffer.Buffer())+offset - : static_cast(fInputBuffer.ProduceBuffer(len)); - fReadPB.ioParam.ioReqCount = len; - GUSI_MESSAGE(("Sync read (0x%x bytes).\n", len)); - PBReadAsync(&fReadPB); - // As soon as [[fReadShutdown]] is set, no new reads will be started, so just wait - // for the current ones to complete. - // - // = - if (fReadPB.ioParam.ioResult == 1) { - AddContext(); - while (fReadPB.ioParam.ioResult == 1) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - GUSI_MESSAGE(("Read done (0x%x/%d).\n", fReadPB.ioParam.ioActCount, fReadPB.ioParam.ioResult)); - switch (fReadPB.ioParam.ioResult) { - case eofErr: - case noErr: - rest -= fReadPB.ioParam.ioActCount; - fPosition += fReadPB.ioParam.ioActCount; - if (buffer.Count() == 1) { - offset += fReadPB.ioParam.ioActCount; - } else { - fInputBuffer.ValidBuffer(fReadPB.ioParam.ioBuffer, fReadPB.ioParam.ioActCount); - fInputBuffer.Consume( - buffer, *reinterpret_cast(&fReadPB.ioParam.ioActCount), offset); - } - if (rest && len == fReadPB.ioParam.ioActCount) - continue; - break; - default: - return GUSISetMacError(fReadPB.ioParam.ioResult); - } - } while (0); - size_t done = buffer.Length() - rest; - // We wait for the first [[read]] (and handle it synchronously) before deciding that - // file access is sequential enough for read-ahead. - // - // = - if (fReadAhead && !fReadShutdown) { - fReadAhead = false; - fReadPB.ioParam.ioCompletion = sReadProc; - GUSIMFRead(this); - } - - return int(done); -} -// = -ssize_t GUSIMacFileSocket::write(const GUSIGatherer & buffer) -{ - if (GUSISetPosixError(GetAsyncError())) - return -1; - if (fWriteShutdown) // Background error - return GUSISetMacError(fWritePB.ioParam.ioResult); - - if (fAppend) - lseek(0, SEEK_END); - else if (fBeyondEOF) { - // If a [[seek]] operation went beyond EOF and we try to do a [[write]] the space - // in-between has to be filled with null bytes. - // - // = - long targetPos = fPosition; - - for (lseek(0, SEEK_END); fPosition < targetPos; ) { - // = - if (!fWriteShutdown && !fOutputBuffer.Free()) { - AddContext(); - while (!fWriteShutdown && !fOutputBuffer.Free()) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - if (fWriteShutdown) - return GUSISetMacError(fWritePB.ioParam.ioResult); - size_t size = targetPos - fPosition; - Ptr p = static_cast(fOutputBuffer.ProduceBuffer(size)); - memset(p, 0, size); - fPosition += size; - fOutputBuffer.ValidBuffer(p, size); - } - } - - size_t rest = buffer.Length(); - size_t offset = 0; - if (!fBlocking && fOutputBuffer.Free() < rest) - return GUSISetPosixError(EWOULDBLOCK); - while (rest) { - size_t len = rest; - // = - if (!fWriteShutdown && !fOutputBuffer.Free()) { - AddContext(); - while (!fWriteShutdown && !fOutputBuffer.Free()) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - if (fWriteShutdown) - return GUSISetMacError(fWritePB.ioParam.ioResult); - fOutputBuffer.Lock(); - fOutputBuffer.Produce(buffer, len, offset); - fPosition += len; - fOutputBuffer.Release(); - rest -= len; - } - - return buffer.Length(); -} -// = -bool GUSIMacFileSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = fBeyondEOF || fAsyncError || fReadAhead || fReadShutdown - || fInputBuffer.Valid() - ) - cond = true; - if (canWrite) - if (*canWrite = fBeyondEOF || fAsyncError || fWriteShutdown || fOutputBuffer.Free()) - cond = true; - - return cond; -} -// = -int GUSIMacFileSocket::fsync() -{ - SyncWrite(); - if (fWriteShutdown) - return GUSISetMacError(fWritePB.ioParam.ioResult); - else - return 0; -} -// = -int GUSIMacFileSocket::fcntl(int cmd, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoFcntl(&result, cmd, arg)) - return result; - - GUSI_ASSERT_CLIENT(false, ("fcntl: illegal request %d\n", cmd)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIMacFileSocket::ioctl(unsigned int request, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoIoctl(&result, request, arg) - || GUSISMInputBuffer::DoIoctl(&result, request, arg) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("ioctl: illegal request %d\n", request)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIMacFileSocket::getsockopt(int level, int optname, void *optval, socklen_t * optlen) -{ - int result; - - if (GUSISMInputBuffer::DoGetSockOpt(&result, level, optname, optval, optlen) - || GUSISMOutputBuffer::DoGetSockOpt(&result, level, optname, optval, optlen) - || GUSISMAsyncError::DoGetSockOpt(&result, level, optname, optval, optlen) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("getsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIMacFileSocket::setsockopt(int level, int optname, void *optval, socklen_t optlen) -{ - int result; - - if (GUSISMInputBuffer::DoSetSockOpt(&result, level, optname, optval, optlen) - || GUSISMOutputBuffer::DoSetSockOpt(&result, level, optname, optval, optlen) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("setsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -off_t GUSIMacFileSocket::lseek(off_t offset, int whence) -{ - if (!fReadShutdown || fInputBuffer.Valid()) - SyncRead(); - else if (!fWriteShutdown) - SyncWrite(); - - long eof; - long pos; - - switch (whence) { - case SEEK_CUR: - pos = fPosition; - break; - case SEEK_END: - if (GUSISetMacError(GetEOF(fFileRef, &eof))) - return -1; - pos = eof; - break; - case SEEK_SET: - pos = 0; - break; - default: - return GUSISetPosixError(EINVAL); - } - GUSI_MESSAGE(("pos: %d off: %d eof: %d whence: %d\n", pos, offset, eof, whence)); - pos += offset; - - if (fPosition == pos) - return fPosition; - - if (whence != SEEK_END && GUSISetMacError(GetEOF(fFileRef, &eof))) - return -1; - if (pos > eof) - fBeyondEOF = true; - else if (pos < 0) - return GUSISetPosixError(EINVAL); - else if (GUSISetMacError(SetFPos(fFileRef, fsFromStart, pos))) - return -1; - else - fBeyondEOF = false; - - return fPosition = pos; -} -// = -int GUSIMacFileSocket::ftruncate(off_t offset) -{ - if (lseek(offset, SEEK_SET) == -1) - return -1; - if (fBeyondEOF) - return lseek(0, SEEK_END) == -1 ? -1 : 0; - else - return GUSISetMacError(SetEOF(fFileRef, fPosition)); -} -// = -int GUSIMacFileSocket::fstat(struct stat * buf) -{ - fsync(); - - GUSIFileSpec spec(fFileRef); - - if (!spec.Exists()) - return GUSISetPosixError(ENOENT); - - GUSIFileToken token(spec, GUSIFileToken::kWillStat); - - return token.Device()->stat(token, buf); -} -// = -bool GUSIMacFileSocket::Supports(ConfigOption config) -{ - return config == kSimpleCalls; -} -// The UPPs for the completion procedures are set up the first time a socket -// is constructed. -// -// = -IOCompletionUPP GUSIMacFileSocket::sReadProc = 0; -IOCompletionUPP GUSIMacFileSocket::sWriteProc = 0; -IOCompletionUPP GUSIMacFileSocket::sWakeupProc = 0; -// = -GUSIMacDirectory::GUSIMacDirectory(const FSSpec & spec) - : fDir(spec) -{ - fPos = 1; -} -// = -dirent * GUSIMacDirectory::readdir() -{ - fDir[fPos]; - if (OSErr err = fDir.Error()) - return GUSISetMacError(err == fnfErr ? 0 : err), static_cast(nil); - - ++fPos; - const GUSICatInfo * info(fDir.CatInfo()); - fEnt.d_ino = info->DirInfo().ioDrDirID; - memcpy(fEnt.d_name, (char *)fDir->name+1, fDir->name[0]); - fEnt.d_name[fDir->name[0]] = 0; - - return &fEnt; -} -// = -long GUSIMacDirectory::telldir() -{ - return fPos; -} -// = -void GUSIMacDirectory::seekdir(long pos) -{ - fPos = pos; -} -// = -void GUSIMacDirectory::rewinddir() -{ - fPos = 1; -} diff --git a/GUSI/src/tangled/GUSINetDB.cp b/GUSI/src/tangled/GUSINetDB.cp deleted file mode 100755 index 5c6201f..0000000 --- a/GUSI/src/tangled/GUSINetDB.cp +++ /dev/null @@ -1,396 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSINetDB.h" -#include "GUSIFileSpec.h" -#include "GUSIFactory.h" - -#include -#include -#include -#include - -#include -#include - -// = -GUSINetDB * GUSINetDB::sInstance; - -GUSINetDB * GUSINetDB::Instance() -{ - if (!sInstance) { - GUSISocketDomainRegistry::Instance(); - if (!sInstance) - sInstance = new GUSINetDB(); - } - return sInstance; -} -GUSINetDB::GUSINetDB() -{ - GUSIContext::Setup(false); - - // = - fServiceOpen = false; - // = - fNextProtocol = 0; -} -// The host functions are not implemented unless the programmer adds -// support for either MacTCP or OpenTransport net database support. -// -// = -hostent * GUSINetDB::gethostbyname(const char *) -{ - return (h_errno = NO_RECOVERY), static_cast(nil); -} -hostent * GUSINetDB::gethostbyaddr(const void *, size_t, int) -{ - return (h_errno = NO_RECOVERY), static_cast(nil); -} -char * GUSINetDB::inet_ntoa(in_addr) -{ - return (h_errno = NO_RECOVERY), static_cast(nil); -} -in_addr_t GUSINetDB::inet_addr(const char * address) -{ - int a[4]; - if (sscanf(address, "%d.%d.%d.%d", a, a+1, a+2, a+3) != 4) - return static_cast(GUSISetHostError(NO_RECOVERY)); - else if ((a[0] & 0xFFFFFF00) || (a[1] & 0xFFFFFF00) - || (a[2] & 0xFFFFFF00) || (a[3] & 0xFFFFFF00)) - return static_cast(GUSISetHostError(NO_RECOVERY)); - else - return (in_addr_t)((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]); -} -long GUSINetDB::gethostid() -{ - return 0; -} -// Unlike the other functions, [[gethostname]] is defined entirely in terms -// of the other functions and thus network independent. -// -// = -int GUSINetDB::gethostname(char *machname, int buflen) -{ - static char * sHostName = nil; - - if (!sHostName) { - in_addr ipaddr; - if (!(ipaddr.s_addr = static_cast(gethostid()))) { - // If there is no TCP/IP support, we still can get the system's idea of what - // the Mac is named. - // - // = - Handle hostString = GetResource('STR ', -16413); - char hsState = HGetState(hostString); - HLock(hostString); - sHostName = new char[**hostString+1]; - memcpy(sHostName, *hostString+1, **hostString); - sHostName[**hostString] = 0; - HSetState(hostString, hsState); - } else { - // = - hostent * ent = gethostbyaddr((char *) &ipaddr, 0, 0); - char * name = ent ? ent->h_name : inet_ntoa(ipaddr); - sHostName = new char[strlen(name)+1]; - strcpy(sHostName, name); - } - } - strncpy(machname, sHostName, unsigned(buflen)); - machname[buflen-1] = 0; /* extra safeguard */ - - return 0; -} -// = -servent * GUSINetDB::getservent() -{ - if (!fServiceOpen) - setservent(0); - else - ++fServiceIter; - if (fServiceIter == GUSIServiceDB::end()) - endservent(); - return *fServiceIter; -} -void GUSINetDB::setservent(int) -{ - fServiceIter = GUSIServiceDB::begin(); - fServiceOpen = true; -} -void GUSINetDB::endservent() -{ - fServiceOpen = false; -} -// [[getservbyname]] and [[getservbyport]] operate in terms of -// [[getservent]]. -// -// = -servent * GUSINetDB::getservbyname(const char * name, const char * proto) -{ - servent * ent; - - for (setservent(0); ent = getservent(); ) { - if (!strcmp(name, ent->s_name)) - goto haveName; - for (char ** al = ent->s_aliases; *al; ++al) - if (!strcmp(name, *al)) - goto haveName; - continue; -haveName: - if (!proto || !strcmp(proto, ent->s_proto)) - break; - } - return ent; -} - -servent * GUSINetDB::getservbyport(int port, const char * proto) -{ - servent * ent; - - for (setservent(0); ent = getservent(); ) - if (port == ent->s_port && (!proto || !strcmp(proto, ent->s_proto))) - break; - - return ent; -} -// = -protoent GUSINetDB::sProtocols[] = { - { "udp", {NULL}, IPPROTO_UDP}, - { "tcp", {NULL}, IPPROTO_TCP} -}; -// Under these circumstances, the iterator functions reduce to triviality. -// -// = -protoent * GUSINetDB::getprotoent() -{ - fNextProtocol = !fNextProtocol; - return sProtocols+!fNextProtocol; -} -void GUSINetDB::setprotoent(int) -{ - fNextProtocol = 0; -} -void GUSINetDB::endprotoent() -{ - fNextProtocol = 0; -} -// = -protoent * GUSINetDB::getprotobyname(const char * name) -{ - for (int i = 0; i<2; ++i) - if (!strcmp(name, sProtocols[i].p_name)) - return sProtocols+i; - return static_cast(nil); -} -protoent * GUSINetDB::getprotobynumber(int proto) -{ - for (int i = 0; i<2; ++i) - if (proto == sProtocols[i].p_proto) - return sProtocols+i; - return static_cast(nil); -} -// \section{Implementation of [[GUSIServiceDB]]} -// -// [[GUSIServiceDB]] is a singleton which is always instantiated by an instance -// of a derived class. The derived classes [[GUSIFileServiceDB]] and -// [[GUSIBuiltinServiceDB]] are defined here, but others are possible as well. -// -// = -// [[GUSIFileServiceDB]] is the traditional implementation, based on reading a file -// from disk. This class is not $100\%$ thread safe: The normal functions are OK, but -// [[getservent]] will not be safe. -// -// = -class GUSIFileServiceDB : public GUSIServiceDB { -public: - static GUSIFileServiceDB * Instance(); -protected: - FILE * fFile; - pthread_mutex_t fLock; - - GUSIFileServiceDB(FILE * file) - : fFile(file), fLock(0) { } - - virtual void Reset(); - virtual void Next(); -}; -// [[GUSIBuiltinServiceDB]] is the most simple implementation of the service -// database, based on a compiled-in table of the most important services. -// -// = - -extern "C" void GUSIKillBuiltinServiceDBEntry(void * entry); - -class GUSIBuiltinServiceDB : public GUSIServiceDB { -public: - static GUSIBuiltinServiceDB * Instance() { return new GUSIBuiltinServiceDB; } -protected: - friend void GUSIKillBuiltinServiceDBEntry(void * entry); - - struct Entry { - Entry() : fValue(0) {} - - int fValue; - }; - typedef GUSISpecificData SpecificEntry; - static SpecificEntry sEntry; - - virtual void Reset(); - virtual void Next(); - - static servent sServices[]; -}; - -// Constructing a [[GUSIFileServiceDB]] can only succeed if the services file exists. -// -// = -GUSIFileServiceDB * GUSIFileServiceDB::Instance() -{ - GUSIFileSpec services(kPreferencesFolderType, kOnSystemDisk); - - if (services.Error()) - return static_cast(nil); - - services.SetName("\p/etc/services"); - - FILE * f = fopen(services.FullPath(), "r"); - - return f ? new GUSIFileServiceDB(f) : static_cast(nil); -} -// [[Reset]] simply rewinds the file. -// -// = -void GUSIFileServiceDB::Reset() -{ - rewind(fFile); -} -// [[Next]] has to parse the lines of the file. -// -// = -void GUSIFileServiceDB::Next() -{ - GUSIservent & service = sData->fServent; - - pthread_mutex_lock(&fLock); - sData->fCurrent = static_cast(nil); - while (fgets(service.fName, 128, fFile)) { - char * p; - if (p = strpbrk(service.fName, "#\n\r")) // Line terminated at newline or '#' - *p = 0; - if (!(service.s_name = strtok(service.fName, " \t")) - || !(p = strtok(NULL, " \t")) - || !(service.s_proto = strpbrk(p, "/,")) - ) - continue; - - *service.s_proto++ = 0; - service.s_port = atoi(p); - - int aliascount; - for (aliascount = 0; aliascount < 15; ) - if (!(service.s_aliases[aliascount++] = strtok(NULL, " \t"))) - break; - service.s_aliases[aliascount] = NULL; - sData->fCurrent = &service; - - break; - } - pthread_mutex_unlock(&fLock); -} -// = -GUSIBuiltinServiceDB::SpecificEntry GUSIBuiltinServiceDB::sEntry; - -void GUSIKillBuiltinServiceDBEntry(void * entry) -{ - delete reinterpret_cast(entry); -} - -static char * sNoAliases[1] = {NULL}; - -servent GUSIBuiltinServiceDB::sServices[] = -{ - { "echo", sNoAliases, 7, "udp"}, - { "discard", sNoAliases, 9, "udp"}, - { "time", sNoAliases, 37, "udp"}, - { "domain", sNoAliases, 53, "udp"}, - { "sunrpc", sNoAliases, 111, "udp"}, - { "tftp", sNoAliases, 69, "udp"}, - { "biff", sNoAliases, 512, "udp"}, - { "who", sNoAliases, 513, "udp"}, - { "talk", sNoAliases, 517, "udp"}, - - { "ftp-data", sNoAliases, 20, "tcp"}, - { "ftp", sNoAliases, 21, "tcp"}, - { "ssh", sNoAliases, 22, "tcp"}, - { "telnet", sNoAliases, 23, "tcp"}, - { "smtp", sNoAliases, 25, "tcp"}, - { "time", sNoAliases, 37, "tcp"}, - { "whois", sNoAliases, 43, "tcp"}, - { "domain", sNoAliases, 53, "tcp"}, - { "hostnames", sNoAliases, 101, "tcp"}, - { "nntp", sNoAliases, 119, "tcp"}, - { "finger", sNoAliases, 79, "tcp"}, - { "http", sNoAliases, 80, "tcp"}, - { "ntp", sNoAliases, 123, "tcp"}, - { "uucp", sNoAliases, 540, "tcp"}, - { NULL, NULL, -1, NULL} -}; -// = -void GUSIBuiltinServiceDB::Reset() -{ - sEntry->fValue = 0; -} -void GUSIBuiltinServiceDB::Next() -{ - if (!sServices[sEntry->fValue].s_name) - sData->fCurrent = static_cast(nil); - else - sData->fCurrent = sServices + sEntry->fValue++; -} -// By default, we try to construct a [[GUSIFileServiceDB]] and fall back to -// the [[GUSIBuiltinServiceDB]] if that fails. -// -// = -GUSIServiceDB::SpecificData GUSIServiceDB::sData; - -void GUSIKillServiceDBData(void * data) -{ - delete reinterpret_cast(data); -} - -GUSIServiceDB * GUSIServiceDB::sInstance; - -GUSIServiceDB * GUSIServiceDB::Instance() -{ - if (!sInstance) - if (!(sInstance = GUSIFileServiceDB::Instance())) - sInstance = GUSIBuiltinServiceDB::Instance(); - return sInstance; -} -// \section{Implementation of [[GUSIhostent]] and [[GUSIservent]]} -// -// The wrapper classes are rather simple. Note that a [[GUSIhostent]] never -// shrinks. -// -// = -GUSIhostent::GUSIhostent() - : fName(nil), fAlloc(0) -{ - h_aliases = fAlias; - h_addr_list = fAddressList; -} -void GUSIhostent::Alloc(size_t size) -{ - if (size > fAlloc) { - if (fName) - delete[] fName; - h_name = fName = new char[fAlloc = size]; - } -} -void GUSIKillHostEnt(void * hostent) -{ - delete reinterpret_cast(hostent); -} -// = -GUSIservent::GUSIservent() -{ - s_aliases = fAlias; -} diff --git a/GUSI/src/tangled/GUSINull.cp b/GUSI/src/tangled/GUSINull.cp deleted file mode 100755 index 70f94bd..0000000 --- a/GUSI/src/tangled/GUSINull.cp +++ /dev/null @@ -1,141 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSINull.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" - -#include -#include -#include - -#include - -// \section{Definition of [[GUSINullSocket]]} -// -// -// = -class GUSINullSocket : - public GUSISocket -{ -public: - GUSINullSocket(); - // Read always returns EOF. - // - // = - virtual ssize_t read(const GUSIScatterer & buffer); - // Writes always succeed. - // - // = - virtual ssize_t write(const GUSIGatherer & buffer); - // Stat returns our special stat block. - // - // = - virtual int fstat(struct stat * buf); - // Null sockets implement simple calls. - // - // = - virtual bool Supports(ConfigOption config); -}; -// \section{Implementation of [[GUSINullDevice]]} -// -// You can use [[GUSINullSocket]]s directly from C++, but the usual way to use them -// is to call [[GUSIwithNullSockets]] to have [["Dev:Null"]] mapped to them. -// -// = -extern "C" void GUSIwithNullSockets() -{ - GUSIDeviceRegistry::Instance()->AddDevice(GUSINullDevice::Instance()); -} -// = -GUSINullDevice * GUSINullDevice::sInstance = nil; -// [[GUSINullDevice]] will handle only the open request. -// -// = -bool GUSINullDevice::Want(GUSIFileToken & file) -{ - if (!file.IsDevice()) - return false; - - const char * path = file.Path(); - - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - case GUSIFileToken::kWillStat: - return file.StrFragEqual(path+4, "null") && !path[8]; - default: - return false; - } -} -// Open will never fail except for lack of memory. -// -// = -GUSISocket * GUSINullDevice::open(GUSIFileToken &, int) -{ - GUSISocket * sock = new GUSINullSocket; - if (!sock) - GUSISetPosixError(ENOMEM); - return sock; -} - -GUSISocket * GUSINullDevice::open() -{ - GUSISocket * sock = new GUSINullSocket; - if (!sock) - GUSISetPosixError(ENOMEM); - return sock; -} -// The only original part o a null socket's reply to [[stat]] and [[fstat]] is the device/inode. -// -// = -static int GUSINullStat(struct stat * buf) -{ - buf->st_dev = 'dev '; - buf->st_ino = 'null'; - buf->st_mode = S_IFCHR | 0666 ; - buf->st_nlink = 1; - buf->st_uid = 0; - buf->st_gid = 0; - buf->st_rdev = 0; - buf->st_size = 1; - buf->st_atime = time(NULL); - buf->st_mtime = time(NULL); - buf->st_ctime = time(NULL); - buf->st_blksize = 0; - buf->st_blocks = 1; - - return 0; -} - -int GUSINullDevice::stat(GUSIFileToken &, struct stat * buf) -{ - return GUSINullStat(buf); -} -// \section{Implementation of [[GUSINullSocket]]} -// -// The implementation of [[GUSINullSocket]] is trivial. -// -// -// = -GUSINullSocket::GUSINullSocket() -{ -} -// = -ssize_t GUSINullSocket::read(const GUSIScatterer &) -{ - return 0; -} -// = -ssize_t GUSINullSocket::write(const GUSIGatherer & buffer) -{ - return buffer.Length(); -} -// = -int GUSINullSocket::fstat(struct stat * buf) -{ - return GUSINullStat(buf); -} -// = -bool GUSINullSocket::Supports(ConfigOption config) -{ - return config == kSimpleCalls; -} diff --git a/GUSI/src/tangled/GUSIOTInet.cp b/GUSI/src/tangled/GUSIOTInet.cp deleted file mode 100755 index 7f9b94a..0000000 --- a/GUSI/src/tangled/GUSIOTInet.cp +++ /dev/null @@ -1,813 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIOTInet.h" -#include "GUSIOpenTransport.h" -#include "GUSIOTNetDB.h" -#include "GUSIInet.h" -#include "GUSIDiag.h" - -#include -#include -#include -#include - -// \section{Definition of [[GUSIOTTcpFactory]]} -// -// The only way that the [[GUSIOTTcpFactory]] differs from the [[GUSIOTFactory]] -// is that it defines a strategy and an instantiation mechanism. -// -// = -class GUSIOTTcpFactory : public GUSIOTStreamFactory { -public: - static GUSISocketFactory * Instance(); -protected: - GUSIOTTcpFactory() {} - - GUSISocket * socket(int domain, int type, int protocol); - virtual GUSIOTStrategy *Strategy(int domain, int type, int protocol); -private: - // \section{Implementation of [[GUSIOTTcpFactory]]} - // - // - // = - static GUSISocketFactory * sInstance; -}; -// \section{Definition of [[GUSIOTUdpFactory]]} -// -// The [[GUSIOTUdpFactory]] is the datagram equivalent of [[GUSIOTTcpFactory]]. -// It returns its own socket typ to support multicasting. -// -// = -class GUSIOTUdpFactory : public GUSIOTDatagramFactory { -public: - static GUSISocketFactory * Instance(); -protected: - GUSIOTUdpFactory() {} - - GUSISocket * socket(int domain, int type, int protocol); - virtual GUSIOTStrategy *Strategy(int domain, int type, int protocol); -private: - // \section{Implementation of [[GUSIOTUdpFactory]]} - // - // - // = - static GUSISocketFactory * sInstance; -}; -// \section{Definition of [[GUSIOTInetStrategy]]} -// -// TCP and UDP sockets use different creation configurations, but the same -// address packing routines. -// -// = -class GUSIOTInetStrategy : public GUSIOTStrategy { -protected: - virtual int PackAddress( - const void * address, socklen_t len, TNetbuf & addr, bool non_null); - virtual int UnpackAddress(const TNetbuf & addr, void * address, socklen_t * len); -}; -// \section{Definition of [[GUSIOTMInetOptions]]} -// -// The options common to TCP and UDP sockets are implemented in the mixin class -// [[GUSIOTMInetOptions]]. -// -// = -class GUSIOTMInetOptions { -protected: - bool DoGetSockOpt( - int * result, EndpointRef endpoint, int level, int optname, - void *optval, socklen_t * optlen); - bool DoSetSockOpt( - int * result, EndpointRef endpoint, int level, int optname, - void *optval, socklen_t optlen); - bool DoIoctl(int * result, unsigned int request, va_list arg); -}; -// \section{Definition of [[GUSIOTTcpStrategy]]} -// -// The [[GUSIOTTcpStrategy]] defines the configuration for TCP sockets -// -// = -class GUSIOTTcpStrategy : public GUSIOTInetStrategy { -protected: - virtual const char * ConfigPath(); -}; -// \section{Definition of [[GUSIOTTcpSocket]]} -// -// A [[GUSIOTUdpSocket]] supports TCP stream services over Open Transport. -// -// = -class GUSIOTTcpSocket : public GUSIOTStreamSocket, protected GUSIOTMInetOptions { -public: - // \section{Implementation of [[GUSIOTTcpSocket]]} - // - // [[Clone]] creates another socket of the same class. - // - // = - virtual GUSIOTSocket * Clone(); - // [[getsockopt]] and [[setsockopt]] for [[GUSIOTTcpSocket]] add the options - // for multicast. - // - // = - virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen); - // = - virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen); - // [[ioctl]] deals with interface access. - // - // = - virtual int ioctl(unsigned int request, va_list arg); -protected: - GUSIOTTcpSocket(GUSIOTStrategy * strategy) : GUSIOTStreamSocket(strategy) {} - - friend class GUSIOTTcpFactory; -}; -// \section{Definition of [[GUSIOTUdpStrategy]]} -// -// The [[GUSIOTUdpStrategy]] defines the configuration for UDP sockets -// -// = -class GUSIOTUdpStrategy : public GUSIOTInetStrategy { -protected: - virtual const char * ConfigPath(); -}; -// \section{Definition of [[GUSIOTUdpSocket]]} -// -// A [[GUSIOTUdpSocket]] supports UDP datagram services over Open Transport. -// -// = -class GUSIOTUdpSocket : public GUSIOTDatagramSocket, protected GUSIOTMInetOptions { -public: - // \section{Implementation of [[GUSIOTUdpSocket]]} - // - // [[Clone]] creates another socket of the same class. - // - // = - virtual GUSIOTSocket * Clone(); - // [[getsockopt]] and [[setsockopt]] for [[GUSIOTUdpSocket]] add the options - // for multicast. - // - // = - virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen); - // = - virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen); - // [[ioctl]] deals with interface access. - // - // = - virtual int ioctl(unsigned int request, va_list arg); -protected: - GUSIOTUdpSocket(GUSIOTStrategy * strategy) : GUSIOTDatagramSocket(strategy) {} - - friend class GUSIOTUdpFactory; -}; -// = -GUSISocketFactory * GUSIOTTcpFactory::sInstance; - -GUSISocketFactory * GUSIOTTcpFactory::Instance() -{ - if (!sInstance) - sInstance = new GUSIOTTcpFactory; - return sInstance; -} -// The real smarts of [[GUSIOTTcpFactory]] are in the [[Strategy]] member -// function. -// -// = -GUSIOTStrategy * GUSIOTTcpFactory::Strategy(int, int, int) -{ - static GUSIOTStrategy * tcpStrategy = new GUSIOTTcpStrategy; - - return tcpStrategy; -} -// OpenTransport TCP sockets have a little bit of added functionality over -// stream sockets. -// -// = -GUSISocket * GUSIOTTcpFactory::socket(int domain, int type, int protocol) -{ - GUSIOTStrategy * strategy = Strategy(domain, type, protocol); - if (Initialize() && strategy) - return new GUSIOTTcpSocket(strategy); - else - return static_cast(0); -} -// = -GUSISocketFactory * GUSIOTUdpFactory::sInstance; - -GUSISocketFactory * GUSIOTUdpFactory::Instance() -{ - if (!sInstance) - sInstance = new GUSIOTUdpFactory; - return sInstance; -} -// The real smarts of [[GUSIOTUdpFactory]] are in the [[Strategy]] member -// function. -// -// = -GUSIOTStrategy * GUSIOTUdpFactory::Strategy(int, int, int) -{ - static GUSIOTStrategy * udpStrategy = new GUSIOTUdpStrategy; - - return udpStrategy; -} -// OpenTransport UDP sockets have a little bit of added functionality over -// datagram sockets. -// -// = -GUSISocket * GUSIOTUdpFactory::socket(int domain, int type, int protocol) -{ - GUSIOTStrategy * strategy = Strategy(domain, type, protocol); - if (Initialize() && strategy) - return new GUSIOTUdpSocket(strategy); - else - return static_cast(0); -} -// \section{Implementation of [[GUSIOTInetStrategy]]} -// -// [[GUSIOTInetStrategy]] defines the packing and unpacking functions. -// -// = -int GUSIOTInetStrategy::PackAddress( - const void * address, socklen_t len, TNetbuf & addr, bool non_null) -{ - const sockaddr_in *name = (const sockaddr_in *)address; - // = - if (!GUSI_ASSERT_CLIENT( - len >= sizeof(struct sockaddr_in), - ("PackAddress: address len %d < %d\n", len, sizeof(struct sockaddr_in))) - ) - return GUSISetPosixError(EINVAL); - if (!GUSI_ASSERT_CLIENT( - name->sin_family == AF_INET, - ("PackAddress: family %d != %d\n", name->sin_family, AF_INET)) - ) - return GUSISetPosixError(EAFNOSUPPORT); - if (non_null && (!name->sin_addr.s_addr || !name->sin_port)) - return GUSISetPosixError(EADDRNOTAVAIL); - OTInitInetAddress( - reinterpret_cast(addr.buf), - name->sin_port, name->sin_addr.s_addr); - addr.len = 16; - - return 0; -} -// = -int GUSIOTInetStrategy::UnpackAddress(const TNetbuf & addr, void * address, socklen_t * len) -{ - sockaddr_in *name = (sockaddr_in *)address; - // = - if (!GUSI_ASSERT_CLIENT( - *len >= sizeof(struct sockaddr_in), - ("UnpackAddress: address len %d < %d\n", len, sizeof(struct sockaddr_in))) - ) - return GUSISetPosixError(EINVAL); - const InetAddress * otaddr = reinterpret_cast(addr.buf); - name->sin_family = AF_INET; - name->sin_port = otaddr->fPort; - name->sin_addr.s_addr = otaddr->fHost; - *len = sizeof(struct sockaddr_in); - - return 0; -} -// \section{Implementation of [[GUSIOTMInetOptions]]} -// -// -// = -bool GUSIOTMInetOptions::DoGetSockOpt( - int * result, EndpointRef endpoint, int level, int optname, - void *optval, socklen_t * optlen) -{ - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + 50 ]; - TOption* opt = (TOption*)optBuffer; - int len; - - optReq.flags = T_CURRENT; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = INET_IP; - opt->name = optname; - - switch (level) { - case SOL_SOCKET: - switch (optname) { - case SO_REUSEPORT: - opt->name = SO_REUSEADDR; - // Fall through - case SO_REUSEADDR: - case SO_DONTROUTE: - len = 4; - break; - default: - goto notSupported; - } - break; - case IPPROTO_IP: - switch (optname) { - case IP_OPTIONS: - len = *optlen; - break; - case IP_TOS: - case IP_TTL: - len = 1; - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - optReq.opt.maxlen = sizeof(optBuffer); - if (*result = GUSISetMacError(OTOptionManagement(endpoint, &optReq, &optReq))) - return true; - switch (optname) { - case IP_TOS: - case IP_TTL: - *reinterpret_cast(optval) = *reinterpret_cast(opt->value); - *optlen = 4; - break; - case IP_OPTIONS: - len = optReq.opt.len; - // Fall through - default: - memcpy(optval, opt->value, len); - *optlen = len; - break; - } - - return true; -notSupported: - return false; -} -// = -bool GUSIOTMInetOptions::DoSetSockOpt( - int * result, EndpointRef endpoint, int level, int optname, - void *optval, socklen_t optlen) -{ - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(struct linger) ]; - TOption* opt = (TOption*)optBuffer; - t_kpalive kpal = {1, 120}; - int len; - char val; - - optReq.flags = T_NEGOTIATE; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = INET_IP; - opt->name = optname; - - switch (level) { - case SOL_SOCKET: - switch (optname) { - case SO_REUSEPORT: - opt->name = SO_REUSEADDR; - // Fall through - case SO_REUSEADDR: - case SO_DONTROUTE: - len = 4; - break; - default: - goto notSupported; - } - break; - case IPPROTO_IP: - switch (optname) { - case IP_OPTIONS: - len = optlen; - break; - case IP_TOS: - case IP_TTL: - val = *reinterpret_cast(optval); - optval = &val; - len = 1; - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - optReq.opt.maxlen = sizeof(optBuffer); - memcpy(opt->value, optval, len); - - *result = GUSISetMacError(OTOptionManagement(endpoint, &optReq, &optReq)); - - return true; -notSupported: - return false; -} -// Internet sockets have to support a fairly complex set of [[ioctl]] options to -// obtain information about hwardware interfaces. We don't support changing any -// of the information. -// -// [[SetInterface]] fills in an [[ifreq]] structure. The name is synthesized, encoding -// the interface index and secondary IP address for fast lookup. -// -// = -static void SetAddress(sockaddr_in * sa, InetHost addr) -{ - sa->sin_family = AF_INET; - sa->sin_port = 0; - sa->sin_addr.s_addr = addr; -} - -static void SetInterface(ifreq * ifr, int ifNum, int aliasNum, InetHost addr) -{ - GUSI_sprintf(ifr->ifr_name, (aliasNum ? "ot%d:%d" : "ot%d"), ifNum, aliasNum); - SetAddress(reinterpret_cast(&ifr->ifr_addr), addr); -} -// [[GetInterfaceList]] gets a list of all IP addresses. -// -// = -static int GetInterfaceList(ifconf * conf) -{ - InetInterfaceInfo info; - int maxInterfaces = conf->ifc_len / sizeof(ifreq); - int numInterfaces = 0; - SInt32 interface = 0; - ifreq * ifr = conf->ifc_req; - - if (!maxInterfaces) - return GUSISetPosixError(EINVAL); - - while (!OTInetGetInterfaceInfo(&info, numInterfaces)) { - SetInterface(ifr++, numInterfaces, 0, info.fAddress); - if (++interface == maxInterfaces) - goto bufferFull; - if (info.fIPSecondaryCount) { - InetHost * secondaries = new InetHost[info.fIPSecondaryCount]; - OTInetGetSecondaryAddresses(secondaries, &info.fIPSecondaryCount, numInterfaces); - for (int i = 0; i < info.fIPSecondaryCount; ++i) { - SetInterface(ifr++, numInterfaces, i+1, secondaries[i]); - if (++interface == maxInterfaces) - goto bufferFull; - } - delete[] secondaries; - } - ++numInterfaces; - } -bufferFull: - conf->ifc_len = interface * sizeof(ifreq); - - return 0; -} -// [[GetInterfaceParam]] gets a parameter for an interface. Secondary IP addresses are only -// retrieved for [[SIOCGIFADDR]]. -// -// = -static int GetInterfaceParam(ifreq * ifr, unsigned int request) -{ - int ifnum = atoi(ifr->ifr_name+2); - int ifalias = 0; - char * alias = strchr(ifr->ifr_name, ':'); - if (alias) - ifalias = atoi(alias+1); - - InetInterfaceInfo info; - if (OTInetGetInterfaceInfo(&info, ifnum) || ifalias > info.fIPSecondaryCount) - return GUSISetPosixError(ENOENT); - if (ifalias && request == SIOCGIFADDR) { - InetHost * secondaries = new InetHost[info.fIPSecondaryCount]; - OTInetGetSecondaryAddresses(secondaries, &info.fIPSecondaryCount, ifnum); - info.fAddress = secondaries[ifalias-1]; - delete[] secondaries; - } - switch (request) { - case SIOCGIFADDR: - SetAddress(reinterpret_cast(&ifr->ifr_addr), info.fAddress); - break; - case SIOCGIFFLAGS: - ifr->ifr_flags = IFF_UP | IFF_BROADCAST | IFF_MULTICAST; - break; - case SIOCGIFBRDADDR: - SetAddress(reinterpret_cast(&ifr->ifr_addr), info.fBroadcastAddr); - break; - case SIOCGIFNETMASK: - SetAddress(reinterpret_cast(&ifr->ifr_addr), info.fNetmask); - break; - } - - return 0; -} - -// = -bool GUSIOTMInetOptions::DoIoctl(int * result, unsigned int request, va_list arg) -{ - switch (request) { - case SIOCGIFCONF: - *result = GetInterfaceList(va_arg(arg, ifconf *)); - - return true; - case SIOCGIFADDR: - case SIOCGIFFLAGS: - case SIOCGIFBRDADDR: - case SIOCGIFNETMASK: - *result = GetInterfaceParam(va_arg(arg, ifreq *), request); - - return true; - } - - return false; -} -// \section{Implementation of [[GUSIOTTcpStrategy]]} -// -// [[GUSIOTTcpStrategy]] merely needs to define the creation options. -// -// = -const char * GUSIOTTcpStrategy::ConfigPath() -{ - return kTCPName; -} -// = -GUSIOTSocket * GUSIOTTcpSocket::Clone() -{ - return new GUSIOTTcpSocket(fStrategy); -} -// = -int GUSIOTTcpSocket::getsockopt(int level, int optname, void *optval, socklen_t * optlen) -{ - int result = GUSIOTSocket::getsockopt(level, optname, optval, optlen); - - if (!result || errno != EOPNOTSUPP - || GUSIOTMInetOptions::DoGetSockOpt(&result, fEndpoint, level, optname, optval, optlen) - ) - return result; - - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(long) ]; - TOption* opt = (TOption*)optBuffer; - int len; - - optReq.flags = T_CURRENT; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = INET_TCP; - opt->name = optname; - - switch (level) { - case IPPROTO_TCP: - switch (optname) { - case TCP_MAXSEG: - case TCP_NODELAY: - len = 4; - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - optReq.opt.maxlen = sizeof(optBuffer); - if (GUSISetMacError(OTOptionManagement(fEndpoint, &optReq, &optReq))) - return -1; - memcpy(optval, opt->value, len); - *optlen = len; - - return 0; -notSupported: - GUSI_ASSERT_CLIENT(false, ("getsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIOTTcpSocket::setsockopt(int level, int optname, void *optval, socklen_t optlen) -{ - int result = GUSIOTSocket::setsockopt(level, optname, optval, optlen); - - if (!result || errno != EOPNOTSUPP - || GUSIOTMInetOptions::DoSetSockOpt(&result, fEndpoint, level, optname, optval, optlen) - ) - return result; - - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(TIPAddMulticast) ]; - TOption* opt = (TOption*)optBuffer; - int len; - - optReq.flags = T_NEGOTIATE; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = INET_TCP; - opt->name = optname; - - switch (level) { - case IPPROTO_TCP: - switch (optname) { - case TCP_MAXSEG: - case TCP_NODELAY: - len = 4; - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - optReq.opt.maxlen = sizeof(optBuffer); - memcpy(opt->value, optval, len); - - return GUSISetMacError(OTOptionManagement(fEndpoint, &optReq, &optReq)); -notSupported: - GUSI_ASSERT_CLIENT(false, ("setsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIOTTcpSocket::ioctl(unsigned int request, va_list arg) -{ - int result; - - if (GUSIOTMInetOptions::DoIoctl(&result, request, arg)) - return result; - else - return GUSIOTSocket::ioctl(request, arg); -} -// \section{Implementation of [[GUSIOTUdpStrategy]]} -// -// [[GUSIOTUdpStrategy]] merely needs to define the creation options. -// -// = -const char * GUSIOTUdpStrategy::ConfigPath() -{ - return kUDPName; -} -// = -GUSIOTSocket * GUSIOTUdpSocket::Clone() -{ - return new GUSIOTUdpSocket(fStrategy); -} -// = -int GUSIOTUdpSocket::getsockopt(int level, int optname, void *optval, socklen_t * optlen) -{ - int result = GUSIOTSocket::getsockopt(level, optname, optval, optlen); - - if (!result || errno != EOPNOTSUPP - || GUSIOTMInetOptions::DoGetSockOpt(&result, fEndpoint, level, optname, optval, optlen) - ) - return result; - - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(long) ]; - TOption* opt = (TOption*)optBuffer; - int len; - - optReq.flags = T_CURRENT; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->name = optname; - - switch (level) { - case SOL_SOCKET: - opt->level = INET_IP; - switch (optname) { - case SO_BROADCAST: - len = 4; - break; - default: - goto notSupported; - } - break; - case IPPROTO_IP: - opt->level = INET_IP; - switch (optname) { - case IP_HDRINCL: - case IP_RCVDSTADDR: - case IP_MULTICAST_IF: - len = 4; - break; - case IP_MULTICAST_TTL: - case IP_MULTICAST_LOOP: - len = 1; - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - if (GUSISetMacError(OTOptionManagement(fEndpoint, &optReq, &optReq))) - return -1; - switch (optname) { - case IP_MULTICAST_TTL: - case IP_MULTICAST_LOOP: - *reinterpret_cast(optval) = *reinterpret_cast(opt->value); - *optlen = 4; - break; - case IP_HDRINCL: - case IP_RCVDSTADDR: - case SO_BROADCAST: - case IP_MULTICAST_IF: - memcpy(optval, opt->value, len); - *optlen = len; - break; - } - - return 0; -notSupported: - GUSI_ASSERT_CLIENT(false, ("getsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIOTUdpSocket::setsockopt(int level, int optname, void *optval, socklen_t optlen) -{ - int result = GUSIOTSocket::setsockopt(level, optname, optval, optlen); - - if (!result || errno != EOPNOTSUPP - || GUSIOTMInetOptions::DoSetSockOpt(&result, fEndpoint, level, optname, optval, optlen) - ) - return result; - - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(TIPAddMulticast) ]; - TOption* opt = (TOption*)optBuffer; - char val; - - optReq.flags = T_NEGOTIATE; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = INET_IP; - opt->name = optname; - - int len; - switch (level) { - case SOL_SOCKET: - switch (optname) { - case SO_BROADCAST: - len = 4; - break; - default: - goto notSupported; - } - break; - case IPPROTO_IP: - switch (optname) { - case IP_HDRINCL: - case IP_RCVDSTADDR: - case IP_MULTICAST_IF: - len = 4; - break; - case IP_MULTICAST_TTL: - case IP_MULTICAST_LOOP: - val = *reinterpret_cast(optval) != 0; - optval = &val; - len = 1; - break; - case IP_ADD_MEMBERSHIP: - case IP_DROP_MEMBERSHIP: - len = 8; - break; - default: - goto notSupported; - } - break; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - memcpy(opt->value, optval, len); - - return GUSISetMacError(OTOptionManagement(fEndpoint, &optReq, &optReq)); -notSupported: - GUSI_ASSERT_CLIENT(false, ("setsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIOTUdpSocket::ioctl(unsigned int request, va_list arg) -{ - int result; - - if (GUSIOTMInetOptions::DoIoctl(&result, request, arg)) - return result; - else - return GUSIOTSocket::ioctl(request, arg); -} -// \section{Implementation of Open Transport Internet hooks} -// -// -// = -void GUSIwithOTTcpSockets() -{ - gGUSIInetFactories.AddFactory(SOCK_STREAM, 0, GUSIOTTcpFactory::Instance()); - GUSIOTNetDB::Instantiate(); -} - -void GUSIwithOTUdpSockets() -{ - gGUSIInetFactories.AddFactory(SOCK_DGRAM, 0, GUSIOTUdpFactory::Instance()); - GUSIOTNetDB::Instantiate(); -} - -void GUSIwithOTInetSockets() -{ - GUSIwithOTTcpSockets(); - GUSIwithOTUdpSockets(); -} diff --git a/GUSI/src/tangled/GUSIOTNetDB.cp b/GUSI/src/tangled/GUSIOTNetDB.cp deleted file mode 100755 index 9fd47c2..0000000 --- a/GUSI/src/tangled/GUSIOTNetDB.cp +++ /dev/null @@ -1,231 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIOTNetDB.h" -#include "GUSIOTInet.h" - -#include -#include -#include -#include - -#if UNIVERSAL_INTERFACES_VERSION < 0x0340 -#undef AF_INET -#endif -#undef IP_OPTIONS -#undef IP_TOS -#undef IP_TTL -#undef IP_HDRINCL -#undef IP_MULTICAST_IF -#undef IP_MULTICAST_TTL -#undef IP_MULTICAST_LOOP -#undef IP_ADD_MEMBERSHIP -#undef IP_DROP_MEMBERSHIP - -#include - -// = -inline uint32_t CompleteMask(OTEventCode code) -{ - return 1 << (code & 0x1F); -} - -pascal void GUSIOTNetDBNotify( - GUSIOTNetDB * netdb, OTEventCode code, OTResult result, void *cookie) -{ - GUSI_MESSAGE(("GUSIOTNetDBNotify %08x %d\n", code, result)); - GUSIContext * context = netdb->fCreationContext; - - switch (code & 0x7F000000L) { - case 0: - netdb->fEvent |= code; - result = 0; - break; - case kPRIVATEEVENT: - case kCOMPLETEEVENT: - if (!(code & 0x00FFFFE0)) - netdb->fCompletion |= CompleteMask(code); - switch (code) { - case T_OPENCOMPLETE: - netdb->fSvc = static_cast(cookie); - break; - case T_DNRSTRINGTOADDRCOMPLETE: - case T_DNRADDRTONAMECOMPLETE: - context = static_cast(cookie)[-1]; - break; - } - break; - default: - switch (code) { - case kOTProviderWillClose: - case kOTProviderIsClosed: - netdb->fCreationContext = nil; // Close & reopen - break; - default: - result = 0; - break; - } - break; - } - if (result) - netdb->fAsyncError = result; - context->Wakeup(); -} -// = -GUSIOTNetDB::GUSIOTNetDB() -{ - // = - fEvent = 0; - fCompletion = 0; - fAsyncError = 0; - fSvc = 0; - fCreationContext = 0; -} -// The Open Transport DNR code is installed by calling [[Instantiate]], which initializes -// the singleton instance of [[GUSINetDB]]. -// -// = -void GUSIOTNetDB::Instantiate() -{ - if (!sInstance) - sInstance = new GUSIOTNetDB; -} -// = -bool GUSIOTNetDB::Resolver() -{ - if (!fCreationContext) { - if (fSvc) { - OTCloseProvider(fSvc); - fSvc = nil; - } - fCreationContext = GUSIContext::Current(); - if (!GUSIOTFactory::Initialize()) - return false; - fAsyncError = 0; - OSStatus syncError = OTAsyncOpenInternetServices( - kDefaultInternetServicesPath, - 0, - reinterpret_cast(GUSIOTNetDBNotify), - this); - if (!syncError) - while (!fAsyncError && !(fCompletion & CompleteMask(T_OPENCOMPLETE))) - GUSIContext::Yield(kGUSIBlock); - } - return fSvc != 0; -} -// Naturally, Open Transport keeps its host data in different structures than the socket -// standard. -// -// = -static void CopyHost(InetHostInfo & otHost, GUSIhostent & unixHost) -{ - size_t len = strlen(otHost.name); - len = (len+4) & ~3; - - unixHost.Alloc(len+kMaxHostAddrs*4); - strcpy(unixHost.h_name, otHost.name); - unixHost.h_aliases[0] = NULL; // Aliases not supported - unixHost.h_addrtype = AF_INET; - unixHost.h_length = 4; - - int addrs = 0; - for (int i=0; i= -hostent * GUSIOTNetDB::gethostbyname(const char * name) -{ - // = - if (!Resolver()) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - if (!strcmp(name, "localhost")) { - long ipaddr = gethostid(); - if (ipaddr) - return gethostbyaddr((char *) &ipaddr, sizeof(in_addr), AF_INET); - return GUSISetHostError(HOST_NOT_FOUND), static_cast(nil); - } - // = - struct { - GUSIContext * fContext; - InetHostInfo fInfo; - } otHost; - GUSIhostent & unixHost = *fHost; - otHost.fContext = GUSIContext::Current(); - fCompletion &= ~CompleteMask(T_DNRSTRINGTOADDRCOMPLETE); - fAsyncError = 0; - OSStatus syncError = OTInetStringToAddress(fSvc, const_cast(name), &otHost.fInfo); - if (syncError) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - while (!fAsyncError && !(fCompletion & CompleteMask(T_DNRSTRINGTOADDRCOMPLETE))) - GUSIContext::Yield(kGUSIBlock); - if (fAsyncError) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - - CopyHost(otHost.fInfo, unixHost); - - return &unixHost; -} -// = -hostent * GUSIOTNetDB::gethostbyaddr(const void * addrP, size_t len, int) -{ - // = - if (!Resolver()) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - // = - struct { - GUSIContext * fContext; - InetHostInfo fInfo; - } otHost; - GUSIhostent & unixHost = *fHost; - otHost.fContext = GUSIContext::Current(); - - InetHost addr = *(InetHost *)addrP; - if (addr == 0x7F000001) - addr = static_cast(gethostid()); - - fCompletion &= ~CompleteMask(T_DNRADDRTONAMECOMPLETE); - fAsyncError = 0; - OSStatus syncError = OTInetAddressToName(fSvc, addr, otHost.fInfo.name); - if (syncError) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - while (!fAsyncError && !(fCompletion & CompleteMask(T_DNRADDRTONAMECOMPLETE))) - GUSIContext::Yield(kGUSIBlock); - if (fAsyncError) - return GUSISetHostError(NO_RECOVERY), static_cast(nil); - - memset(otHost.fInfo.addrs, 0, kMaxHostAddrs*4); - otHost.fInfo.addrs[0] = addr; - // Apparently, Open Transport likes appaending an extra [['.']] to the domain name. - // - // = - len = strlen(otHost.fInfo.name); - if (otHost.fInfo.name[len-1] == '.') - otHost.fInfo.name[len-1] = 0; - CopyHost(otHost.fInfo, unixHost); - - return &unixHost; -} -// = -char * GUSIOTNetDB::inet_ntoa(in_addr inaddr) -{ - GUSIhostent & unixHost = *fHost; - GUSI_sprintf(unixHost.fAddrString, "%d.%d.%d.%d", - (inaddr.s_addr >> 24) & 0xFF, - (inaddr.s_addr >> 16) & 0xFF, - (inaddr.s_addr >> 8) & 0xFF, - inaddr.s_addr & 0xFF); - return unixHost.fAddrString; -} -// = -long GUSIOTNetDB::gethostid() -{ - if (!Resolver()) - return GUSISetHostError(NO_RECOVERY), 0; - InetInterfaceInfo info; - OTInetGetInterfaceInfo(&info, kDefaultInetInterface); - - return static_cast(info.fAddress); -} diff --git a/GUSI/src/tangled/GUSIOpenTransport.cp b/GUSI/src/tangled/GUSIOpenTransport.cp deleted file mode 100755 index f8c9334..0000000 --- a/GUSI/src/tangled/GUSIOpenTransport.cp +++ /dev/null @@ -1,1115 +0,0 @@ -// = -#define GUSI_MESSAGE_LEVEL 1 - -#include "GUSIInternal.h" -#include "GUSIOpenTransport.h" -#include "GUSIDiag.h" -#include "GUSITimer.h" - -#include -#include - -#include -#include - -GUSI_USING_STD_NAMESPACE - -// = -inline uint32_t CompleteMask(OTEventCode code) -{ - return 1 << (code & 0x1F); -} - -pascal void GUSIOTNotify( - GUSIOTSocket * sock, OTEventCode code, OTResult result, void *cookie) -{ - GUSI_MESSAGE1(("GUSIOTNotify %08x %d\n", code, result)); - switch (code & 0x7f000000L) { - case 0: - sock->fNewEvent |= code; - result = 0; - break; - case kCOMPLETEEVENT: - if (!(code & 0x00FFFFE0)) - sock->fNewCompletion |= CompleteMask(code); - if (code == T_OPENCOMPLETE) - sock->fEndpoint = static_cast(cookie); - break; - default: - if (code != kOTProviderWillClose - && code != kOTProviderIsClosed) - result = 0; - else if (!result) { - result = kENETDOWNErr; - } - } - sock->SetAsyncMacError(result); - sock->Wakeup(); -} -// = -bool GUSIOTFactory::sOK = false; - -bool GUSIOTFactory::Initialize() -{ - if (!sOK) - sOK = !InitOpenTransport(); - return sOK; -} -// = -GUSISocket * GUSIOTStreamFactory::socket(int domain, int type, int protocol) -{ - GUSIOTStrategy * strategy = Strategy(domain, type, protocol); - if (Initialize() && strategy) - return new GUSIOTStreamSocket(strategy); - else - return static_cast(0); -} -// = -GUSISocket * GUSIOTDatagramFactory::socket(int domain, int type, int protocol) -{ - GUSIOTStrategy * strategy = Strategy(domain, type, protocol); - if (Initialize() && strategy) - return new GUSIOTDatagramSocket(strategy); - else - return static_cast(0); -} -// = -OTConfiguration * GUSIOTStrategy::CreateConfiguration() -{ - if (!fConfig) - fConfig = OTCreateConfiguration(ConfigPath()); - - return OTCloneConfiguration(fConfig); -} - -GUSIOTStrategy::~GUSIOTStrategy() -{ - if (fConfig) - OTDestroyConfiguration(fConfig); -} -// While you might have to override this for sophisticated addresses, this should do for most. -// -// = -int GUSIOTStrategy::CopyAddress(const TNetbuf & from, TNetbuf & to) -{ - memcpy(to.buf, from.buf, to.len = from.len); - - return 0; -} -// = -void GUSIOTSocket::MopupEvents() -{ - { - Lock lock(fEndpoint); - - fEvent |= (fCurEvent = fNewEvent); - fCompletion |= (fCurCompletion = fNewCompletion); - fNewEvent = 0; - fNewCompletion = 0; - } - - if (fCurEvent & T_UDERR) { - GUSIOTTUDErr * udErr = new (fEndpoint) GUSIOTTUDErr; - - if (!OTRcvUDErr(fEndpoint, udErr) && udErr) - SetAsyncMacError(udErr->error); - - delete udErr; - } - if ((fCurEvent & (T_DISCONNECT | T_ORDREL)) && !(fEvent & T_LISTEN)) { - fReadShutdown = true; - } -} -// = -GUSIOTSocket::GUSIOTSocket(GUSIOTStrategy * strategy) -{ - // = - fNewEvent = 0; - fEvent = 0; - fNewCompletion = 0; - fCompletion = 0; - // = - fStrategy = strategy; - fEndpoint = nil; - fLinger.l_onoff = false; - fLinger.l_linger= 0; - // = - fSockName = nil; - SetAsyncMacError( - OTAsyncOpenEndpoint( - fStrategy->CreateConfiguration(), - 0, fStrategy->EndpointInfo(), - reinterpret_cast(GUSIOTNotify), - this)); - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_OPENCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - if (!fEndpoint) - GUSISetPosixError(GetAsyncError()); -} -// = -void GUSIOTSocket::close() -{ - if (OTGetEndpointState(fEndpoint) != T_IDLE) { - // Under desperate circumstances, we are prepared to employ quite a bit of - // violence to disconnect the socket. - // - // = - fCompletion &= ~(CompleteMask(T_DISCONNECTCOMPLETE)); - GUSIOTTCall * call = new (fEndpoint, 0) GUSIOTTCall; - fAsyncError = 0; - SetAsyncMacError(OTSndDisconnect(fEndpoint, call)); - delete call; - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_DISCONNECTCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - fAsyncError = 0; - } - - Unbind(); - OTCloseProvider(fEndpoint); - fEvent = 0; - - GUSISocket::close(); -} - -GUSIOTSocket::~GUSIOTSocket() -{ - delete fSockName; -} -// = -int GUSIOTSocket::bind(void * name, socklen_t namelen) -{ - if (fSockName) - return GUSISetPosixError(EINVAL); - - int res = -1; - GUSIOTTBind * inName = new (fEndpoint) GUSIOTTBind; - if (!inName) - return GUSISetPosixError(ENOMEM); - if (inName->Pack(fStrategy, name, namelen)) - goto freeInName; - inName->qlen = 0; - - res = BindToAddress(inName); -freeInName: - delete inName; - - return res; -} -// = -int GUSIOTSocket::BindToAddress(GUSIOTTBind * addr) -{ - fSockName = new (fEndpoint) GUSIOTTBind; - if (!fSockName) - return GUSISetPosixError(ENOMEM); - fCompletion &= ~CompleteMask(T_BINDCOMPLETE); - fAsyncError = 0; - SetAsyncMacError(OTBind(fEndpoint, addr, fSockName)); - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_BINDCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - if (GUSISetPosixError(GetAsyncError())) { - delete fSockName; - fSockName = nil; - - return -1; - } else - return 0; -} -// = -void GUSIOTSocket::Unbind() -{ - fCompletion &= ~(CompleteMask(T_BINDCOMPLETE) | CompleteMask(T_UNBINDCOMPLETE)); - fAsyncError = 0; - SetAsyncMacError(OTUnbind(fEndpoint)); - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_UNBINDCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - fAsyncError = 0; -} -// = -int GUSIOTSocket::getsockname(void * name, socklen_t * namelen) -{ - int res; - - if (!fSockName) - BindToAddress(nil); - - if (fStrategy->EndpointInfo()->flags & T_XPG4_1) { - GUSIOTTBind * otname = new (fEndpoint) GUSIOTTBind; - if (!otname) - return GUSISetPosixError(ENOMEM); - - fCompletion &= ~CompleteMask(T_GETPROTADDRCOMPLETE); - fAsyncError = 0; - SetAsyncMacError(OTGetProtAddress(fEndpoint, otname, nil)); - - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_GETPROTADDRCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - - res = fAsyncError - ? GUSISetPosixError(GetAsyncError()) - : otname->Unpack(fStrategy, name, namelen); - - delete otname; - } else - res = fSockName->Unpack(fStrategy, name, namelen); - - return res; -} -// = -int GUSIOTSocket::shutdown(int how) -{ - if (!GUSI_SASSERT_CLIENT(how >= 0 && how < 3, "shutdown: 0,1, or 2\n")) - return GUSISetPosixError(EINVAL); - - switch (how) { - case SHUT_RD: - case SHUT_RDWR: - Unbind(); - } - - GUSISMState::Shutdown(how); - - return 0; -} -// = -int GUSIOTSocket::fcntl(int cmd, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoFcntl(&result, cmd, arg)) - return result; - - GUSI_ASSERT_CLIENT(false, ("fcntl: illegal request %d\n", cmd)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIOTSocket::ioctl(unsigned int request, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoIoctl(&result, request, arg)) - return result; - if (request == FIONREAD) { - size_t res; - if (OTCountDataBytes(fEndpoint, &res)) - res = 0; - *va_arg(arg, size_t *) = res; - return 0; - } - - GUSI_ASSERT_CLIENT(false, ("ioctl: illegal request %d\n", request)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -bool GUSIOTSocket::pre_select(bool wantRead, bool wantWrite, bool wantExcept) -{ - size_t sz; - - if (wantRead && OTCountDataBytes(fEndpoint, &sz) == kOTNoDataErr) - fEvent &= ~(T_DATA|T_EXDATA); - - return GUSISocket::pre_select(wantRead, wantWrite, wantExcept); -} -// = -int GUSIOTSocket::getsockopt(int level, int optname, void *optval, socklen_t * optlen) -{ - int result; - - MopupEvents(); - - if (GUSISMAsyncError::DoGetSockOpt(&result, level, optname, optval, optlen)) - return result; - - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(struct linger) ]; - TOption* opt = (TOption*)optBuffer; - int len; - - optReq.flags = T_CURRENT; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = XTI_GENERIC; - opt->name = optname; - - switch (level) { - case SOL_SOCKET: - switch (optname) { - case SO_KEEPALIVE: - len = sizeof(struct t_kpalive); - break; - case SO_DEBUG: - case SO_RCVBUF: - case SO_SNDBUF: - case SO_RCVLOWAT: - case SO_SNDLOWAT: - len = 4; - break; - case SO_LINGER: - memcpy(optval, &fLinger, sizeof(struct linger)); - - return 0; - default: - goto notSupported; - } - break; - case IPPROTO_TCP: - switch (optname) { - case TCP_KEEPALIVE: - opt->name = OPT_KEEPALIVE; - len = sizeof(struct t_kpalive); - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - if (GUSISetMacError(OTOptionManagement(fEndpoint, &optReq, &optReq))) - return -1; - switch (optname) { - case TCP_KEEPALIVE: - if (level == IPPROTO_TCP) - *(int *)optval = reinterpret_cast(opt->value)->kp_timeout*60; - else - *(int *)optval = reinterpret_cast(opt->value)->kp_onoff; - *optlen = 4; - break; - default: - memcpy(optval, opt->value, len); - *optlen = len; - } - - return 0; -notSupported: - GUSI_ASSERT_CLIENT(false, ("getsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIOTSocket::setsockopt(int level, int optname, void *optval, socklen_t) -{ - MopupEvents(); - - TOptMgmt optReq; - UInt8 optBuffer[ kOTOptionHeaderSize + sizeof(struct linger) ]; - TOption* opt = (TOption*)optBuffer; - t_kpalive kpal = {1, 120}; - int len; - - optReq.flags = T_NEGOTIATE; - optReq.opt.buf = (UInt8*) optBuffer; - - opt->level = INET_IP; - opt->name = optname; - - switch (level) { - case SOL_SOCKET: - switch (optname) { - case SO_KEEPALIVE: - len = sizeof(struct t_kpalive); - kpal.kp_onoff = *reinterpret_cast(optval); - optval = &kpal; - break; - case SO_DEBUG: - case SO_RCVBUF: - case SO_SNDBUF: - case SO_RCVLOWAT: - case SO_SNDLOWAT: - len = 4; - break; - case SO_LINGER: - memcpy(&fLinger, optval, sizeof(struct linger)); - - return 0; - default: - goto notSupported; - } - break; - case IPPROTO_TCP: - switch (optname) { - case TCP_KEEPALIVE: - len = sizeof(struct t_kpalive); - kpal.kp_timeout = (*reinterpret_cast(optval) + 30) / 60; - optval = &kpal; - break; - default: - goto notSupported; - } - break; - default: - goto notSupported; - } - optReq.opt.len = opt->len = kOTOptionHeaderSize+len; - memcpy(opt->value, optval, len); - - return GUSISetMacError(OTOptionManagement(fEndpoint, &optReq, &optReq)); -notSupported: - GUSI_ASSERT_CLIENT(false, ("setsockopt: illegal request %d\n", optname)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -bool GUSIOTSocket::Supports(ConfigOption config) -{ - return config == kSocketCalls; -} -// \section{Implementation of [[GUSIOTStreamSocket]]} -// -// [[GUSIOTStreamSocket]]s have to be connected and send data in a -// continuous stream. -// -// = -GUSIOTStreamSocket::GUSIOTStreamSocket(GUSIOTStrategy * strategy) - : GUSIOTSocket(strategy) -{ - // = - fPeerName = nil; - // = - fNextListener = nil; -} -// = -GUSIOTSocket * GUSIOTStreamSocket::Clone() -{ - return new GUSIOTStreamSocket(fStrategy); -} -// = -void GUSIOTStreamSocket::close() -{ - if (fLinger.l_onoff && !fLinger.l_linger) { - GUSIOTSocket::close(); - } else { - OTSndOrderlyDisconnect(fEndpoint); - - if (fLinger.l_onoff) { - if (fBlocking) { - // = - GUSITimer lingerer; - - lingerer.Sleep(fLinger.l_linger*1000+1); - - AddContext(); - MopupEvents(); - while (OTGetEndpointState(fEndpoint) > T_IDLE) - if (fLinger.l_onoff && lingerer.Expired()) { - break; - } else { - // If there is still pending data, we'll have to read it before the disconnect - // succeeds. - // - // = - char discard[256]; - OTFlags otflags; - while (OTRcv(fEndpoint, discard, 256, &otflags) >= 0) - ; - MopupEvents(); - if (GUSIContext::Yield(kGUSIBlock)) - break; - } - RemoveContext(); - GUSIOTSocket::close(); - - return; - } else { - fDeadline = LMGetTicks()+fLinger.l_linger*60; - } - } else { - fDeadline = LMGetTicks()+3600; - } - if (!Close(LMGetTicks())) - GUSIProcess::Instance()->QueueForClose(this); - } -} -// = -GUSIOTStreamSocket::~GUSIOTStreamSocket() -{ - delete fPeerName; -} -// = -bool GUSIOTStreamSocket::Close(UInt32 now) -{ - // If there is still pending data, we'll have to read it before the disconnect - // succeeds. - // - // = - char discard[256]; - OTFlags otflags; - while (OTRcv(fEndpoint, discard, 256, &otflags) >= 0) - ; - MopupEvents(); - if (now < fDeadline && OTGetEndpointState(fEndpoint) > T_IDLE) { - return false; - } else { - GUSIOTSocket::close(); - - return true; - } -} -// = -void GUSIOTStreamSocket::MopupEvents() -{ - GUSIOTSocket::MopupEvents(); - - if (fCurEvent & T_CONNECT) { - GUSI_MESSAGE(("Connect\n")); - OTRcvConnect(fEndpoint, fPeerName); - fEvent |= T_GODATA; - } - if (fCurEvent & T_ORDREL) { - OTRcvOrderlyDisconnect(fEndpoint); - GUSI_MESSAGE(("Orderly Disconnect\n")); - } - if (fCurEvent & T_DISCONNECT) { - GUSIOTTDiscon * discon = new (fEndpoint) GUSIOTTDiscon; - - OTRcvDisconnect(fEndpoint, discon); - if (discon) { - GUSI_MESSAGE(("Disconnect %d\n", XTI2OSStatus(discon->reason))); - SetAsyncMacError(XTI2OSStatus(discon->reason)); - - delete discon; - } else { - GUSI_MESSAGE(("Disconnect\n")); - } - } -} -// = -int GUSIOTStreamSocket::listen(int queueLength) -{ - Unbind(); - // For some weird reason, BSD multiplies queue lengths with a fudge factor. - // - // = - if (queueLength < 1) - queueLength = 1; - else if (queueLength > 4) - queueLength = 8; - else - queueLength = ((queueLength * 3) >> 1) + 1; - fSockName->qlen = queueLength; - fAsyncError = 0; - SetAsyncMacError(OTBind(fEndpoint, fSockName, nil)); - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_BINDCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - - return GUSISetPosixError(GetAsyncError()); -} -// = -int GUSIOTStreamSocket::getpeername(void * name, socklen_t * namelen) -{ - MopupEvents(); - - if (!fPeerName) - return GUSISetPosixError(ENOTCONN); - return fPeerName->Unpack(fStrategy, name, namelen); -} -// = -GUSISocket * GUSIOTStreamSocket::accept(void * address, socklen_t * addrlen) -{ - MopupEvents(); - - bool mustListen = false; - for (;;) { - if (mustListen || !fNextListener) { - // = - GUSIOTTCall * call = new (fEndpoint) GUSIOTTCall; - if (!call) - return GUSISetPosixError(ENOMEM), static_cast(0); - OTResult err; - bool signal = false; - AddContext(); - for (;;) { - err = OTListen(fEndpoint, call); - if (!fBlocking || (err != kOTNoDataErr)) - break; - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - } - RemoveContext(); -// <[[return]] an appropriate error if [[GUSIOTSocket::accept]] failed>= -if (signal) - return GUSISetPosixError(EINTR), static_cast(0); -if (err) { - delete call; - - if (err==kOTNoDataErr) - GUSISetPosixError(EWOULDBLOCK); - else - GUSISetMacError(err); - - return static_cast(0); -} - GUSIOTStreamSocket * candidate = dynamic_cast(Clone()); - candidate->fPeerName = call; - candidate->fNextListener = fNextListener; - fNextListener = candidate; - GUSI_MESSAGE(("GUSIOTStreamSocket::accept queued %08x\n", candidate)); - mustListen = false; - } - if (fNextListener) { - // = - GUSIOTStreamSocket * sock = fNextListener; - fCompletion &= ~(CompleteMask(T_ACCEPTCOMPLETE)); - fAsyncError = 0; - SetAsyncMacError(OTAccept(fEndpoint, sock->fEndpoint, sock->fPeerName)); - AddContext(); - MopupEvents(); - while (!fAsyncError && !(fCompletion & CompleteMask(T_ACCEPTCOMPLETE))) { - GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - switch (int error = GetAsyncError()) { - case ELOOK: - switch (OTLook(fEndpoint)) { - case T_LISTEN: // Another connection has arrived - mustListen = true; - GUSI_MESSAGE(("GUSIOTStreamSocket::accept T_LISTEN\n")); - continue; - case T_DISCONNECT: // Peer disconnected already - GUSI_MESSAGE(("GUSIOTStreamSocket::accept T_DISCONNECT\n")); - goto deleteCandidate; - } - break; - case 0: - GUSI_MESSAGE(("GUSIOTStreamSocket::accept accepted %08x\n", sock)); - fNextListener = sock->fNextListener; - sock->fNextListener = nil; - - sock->getpeername(address, addrlen); - sock->fSockName = new (fEndpoint) GUSIOTTBind; - sock->fEvent |= T_GODATA; /* Ready to write */ - if (sock->fSockName && !fSockName->Copy(fStrategy, sock->fSockName)) - return sock; - else - delete sock; - break; - default: - deleteCandidate: - GUSI_MESSAGE(("GUSIOTStreamSocket::accept async error %d\n", error)); - fNextListener = sock->fNextListener; - - delete sock; - } - } - } -} -// = -int GUSIOTStreamSocket::connect(void * address, socklen_t addrlen) -{ - MopupEvents(); - OTResult res = 0; - - GUSI_MESSAGE(("Connecting...\n")); - switch (OTGetEndpointState(fEndpoint)) { - case T_OUTCON: - if (!fBlocking) - return GUSISetPosixError(EALREADY); - break; - case T_UNBND: - if (BindToAddress(nil)) - return -1; - // Fall through - case T_IDLE: - fReadShutdown = false; - fWriteShutdown = false; - fPeerName = new (fEndpoint) GUSIOTTCall; - if (!fPeerName) - return GUSISetPosixError(GetAsyncError()); - if (fPeerName->Pack(fStrategy, address, addrlen, true)) - goto freePeerName; - fEvent &= ~T_CONNECT; - res = OTConnect(fEndpoint, fPeerName, nil); - MopupEvents(); - break; - default: - return GUSISetPosixError(EISCONN); - } - if (!fBlocking && !(fEvent & (T_CONNECT|T_DISCONNECT))) - return GUSISetPosixError(EINPROGRESS); - { - bool signal = false; - AddContext(); - MopupEvents(); - while (!signal && !(fEvent & (T_CONNECT|T_DISCONNECT))) { - signal = GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - } - RemoveContext(); - if (signal) - return GUSISetPosixError(EINTR); - } - if (fEvent & T_CONNECT) - return 0; - fEvent &= ~T_DISCONNECT; - GUSISetPosixError(GetAsyncError()); -freePeerName: - delete fPeerName; - fPeerName = nil; - - return -1; -} -// = -ssize_t GUSIOTStreamSocket::recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen) -{ - MopupEvents(); - OTFlags otflags; - uint16_t exp = fEvent & T_EXDATA; - fEvent ^= exp; - - AddContextInScope scope(this); - - OTResult res = OTRcv(fEndpoint, buffer.Buffer(), buffer.Length(), &otflags); - if (res < 0 && fReadShutdown) - return 0; - if (res == kOTNoDataErr) { - if (GUSISetPosixError(GetAsyncError())) - return -1; - fEvent &= ~(T_DATA|T_EXDATA); - if (!fBlocking) - return GUSISetPosixError(EWOULDBLOCK); - bool signal = false; - MopupEvents(); - while (res == kOTNoDataErr && !(res = fAsyncError)) { - signal = GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - if (signal) - break; - res = OTRcv(fEndpoint, buffer.Buffer(), buffer.Length(), &otflags); - } - if (signal) - return GUSISetPosixError(EINTR); - } - if (res < 0) - return GUSISetMacError(res); - else - buffer.SetLength(res); - if (from) - fPeerName->Unpack(fStrategy, from, fromlen); - // When the [[T_EXDATA]] event arrives, we might first get some non-expedited data - // [[!(otflags & T_EXPEDITED)]] and then a packet of expedited data [[otflags & T_EXPEDITED]], - // possibly with the [[T_MORE]] flag set (although that should not happen in TCP/IP). We - // therefore don't reset [[T_EXDATA]] until we have seen a packet with [[T_EXPEDITED]] set - // and [[T_MORE]] not set. - // - // = - if (exp && (otflags & (T_EXPEDITED|T_MORE)) != T_EXPEDITED) - fEvent |= exp; - return res; -} -// = -ssize_t GUSIOTStreamSocket::sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t tolen) -{ - MopupEvents(); - if (GUSISetPosixError(GetAsyncError())) - return -1; - long done= 0; - char * buf = static_cast(buffer.Buffer()); - long len = buffer.Length(); - - AddContextInScope scope(this); - - while (len) { - OTResult res = OTSnd(fEndpoint, buf, len, 0); - if (res <= 0) - if (res == kOTFlowErr) { - fEvent &= ~T_GODATA; - if (!fBlocking) - return done ? done : GUSISetPosixError(EWOULDBLOCK); - bool signal = GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - if (signal) - return done ? done : GUSISetPosixError(EINTR); - } else - return GUSISetMacError(res); - else { - buf += res; - len -= res; - done+= res; - } - } - return buffer.Length(); -} -// = -bool GUSIOTStreamSocket::select(bool * canRead, bool * canWrite, bool * except) -{ - MopupEvents(); - - size_t sz; - bool res = false; - OTResult state = OTGetEndpointState(fEndpoint); - - if (canRead) { - if (*canRead = - fReadShutdown // EOF - || fAsyncError // Asynchronous error - || fEvent & T_DATA // Data available - || state == T_INCON // Connection pending - || fNextListener // Connection pending - ) - res = true; - } - if (canWrite) { - if (fWriteShutdown || fAsyncError) { - res = *canWrite = true; - } else { - switch (state) { - case T_DATAXFER: - case T_INREL: - if (*canWrite = (fEvent & T_GODATA) != 0) - res = true; - break; - default: - *canWrite = false; - } - } - } - if (except) { - if (*except = (fEvent & T_EXDATA) != 0) - res = true; - } - return res; -} -// = -int GUSIOTStreamSocket::shutdown(int how) -{ - switch (how) { - case SHUT_WR: - case SHUT_RDWR: - OTSndOrderlyDisconnect(fEndpoint); - } - - return GUSIOTSocket::shutdown(how); -} -// \section{Implementation of [[GUSIOTDatagramSocket]]} -// -// [[GUSIOTDatagramSocket]]s don't need to be connected. -// -// = -GUSIOTDatagramSocket::GUSIOTDatagramSocket(GUSIOTStrategy * strategy) - : GUSIOTSocket(strategy) -{ - // = - fPeerName = nil; -} -// = -GUSIOTSocket * GUSIOTDatagramSocket::Clone() -{ - return new GUSIOTDatagramSocket(fStrategy); -} -// = -GUSIOTDatagramSocket::~GUSIOTDatagramSocket() -{ - delete fPeerName; -} -// = -int GUSIOTDatagramSocket::BindIfUnbound() -{ - if (OTGetEndpointState(fEndpoint) == T_UNBND) - return BindToAddress(nil); - return 0; -} -// = -int GUSIOTDatagramSocket::getpeername(void * name, socklen_t * namelen) -{ - if (!fPeerName) - return GUSISetPosixError(ENOTCONN); - return fPeerName->Unpack(fStrategy, name, namelen); -} -// = -int GUSIOTDatagramSocket::connect(void * address, socklen_t addrlen) -{ - MopupEvents(); - if (BindIfUnbound()) - return -1; - if (!fPeerName) { - fPeerName = new (fEndpoint) GUSIOTTBind; - if (!fPeerName) - return GUSISetPosixError(ENOMEM); - } - if (fPeerName->Pack(fStrategy, address, addrlen, true)) { - delete fPeerName; - fPeerName = nil; - - return -1; - } - return 0; -} -// = -ssize_t GUSIOTDatagramSocket::recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen) -{ - AddContextInScope scope(this); - - MopupEvents(); - GUSIOTTUnitData * data = new (fEndpoint, T_ADDR|T_OPT) GUSIOTTUnitData; - if (!data) - return GUSISetPosixError(ENOMEM); - data->udata.len = data->udata.maxlen = buffer.Length(); - data->udata.buf = static_cast(buffer.Buffer()); -retry: - OTFlags otflags; - OTResult res; - while ((res = OTRcvUData(fEndpoint, data, &otflags)) == kOTNoDataErr) { - if (GUSISetPosixError(GetAsyncError())) - res = -1; - else if (fReadShutdown) - res = 0; - else if (!fBlocking) - res = GUSISetPosixError(EWOULDBLOCK); - else { - bool signal = GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - if (signal) - return GUSISetPosixError(EINTR); - continue; - } - goto killDataAndReturn; - } - if (res < 0) { - if (fReadShutdown) { - res = 0; - } else { - GUSISetMacError(res); - res = -1; - } - } else { - // If we called [[connect]] on the socket, we want to restrict peer addresses. - // - // = - if (fPeerName) - if (memcmp( - fPeerName->addr.buf, data->addr.buf, - min(fPeerName->addr.len, data->addr.len)) - ) - goto retry; // No match - if (from) - data->Unpack(fStrategy, from, fromlen); - } - if (res >= 0) { - res = buffer.SetLength(data->udata.len); - // Open Transport requires one to read the entire datagram, so if there was a rest, - // we use a temporary buffer. This part may be called recursively. - // - // = - if (otflags & T_MORE) { - char * buf = new char[1024]; - recvfrom(GUSIScatterer(buf, 1024), 0, nil, nil); - } - } -killDataAndReturn: - data->udata.buf = nil; - delete data; - return res; -} -// = -ssize_t GUSIOTDatagramSocket::sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t tolen) -{ - MopupEvents(); - if (GUSISetPosixError(GetAsyncError())) - return -1; - if (!to && !fPeerName) - return GUSISetPosixError(ENOTCONN); - auto_ptr data(new (fEndpoint, to ? T_ADDR|T_OPT : T_OPT) GUSIOTTUnitData); - if (!data.get()) - return GUSISetPosixError(ENOMEM); - if (to) { - if (data->Pack(fStrategy, to, tolen, true)) - return -1; - } else if (fPeerName) { - data->addr = fPeerName->addr; - } - data->udata.len = data->udata.maxlen = buffer.Length(); - data->udata.buf = static_cast(buffer.Buffer()); - - AddContextInScope scope(this); - OTResult res; - int error = 0; - while ((res = OTSndUData(fEndpoint, data.get())) == kOTFlowErr) { - if (!fBlocking) { - error = EWOULDBLOCK; - - break; - } - bool signal = GUSIContext::Yield(kGUSIBlock); - MopupEvents(); - if (signal) { - error = EINTR; - - break; - } - } - data->udata.buf = nil; - if (!to) - data->addr.buf = nil; - if (error) - return GUSISetPosixError(error); - else if (res < 0) - return GUSISetMacError(res); - else - res = data->udata.len; - - return res; -} -// = -bool GUSIOTDatagramSocket::select(bool * canRead, bool * canWrite, bool * except) -{ - MopupEvents(); - bool res = false; - OTResult state = OTGetEndpointState(fEndpoint); - - if (canRead) { - if (*canRead = fAsyncError || fEvent & T_DATA) - res = true; - } - if (canWrite) - switch (state) { - case T_IDLE: - case T_DATAXFER: - case T_INREL: - *canWrite = true; - res = true; - break; - default: - *canWrite = fAsyncError != 0; - } - if (except) - *except = false; - - return res; -} diff --git a/GUSI/src/tangled/GUSIPOSIX.cp b/GUSI/src/tangled/GUSIPOSIX.cp deleted file mode 100755 index 0025d3b..0000000 --- a/GUSI/src/tangled/GUSIPOSIX.cp +++ /dev/null @@ -1,1215 +0,0 @@ -// We try to distinguish between functions mentioned in the POSIX.1 standard, -// BSD functions which later became part of UNIX 98, and a few MPW specific -// functions. -// -// = -#include "GUSIInternal.h" -#include "GUSIPOSIX.h" -#include "GUSISocket.h" -#include "GUSIFactory.h" -#include "GUSIDevice.h" -#include "GUSIDescriptor.h" -#include "GUSIPipe.h" -#include "GUSIConfig.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" -#include "GUSINetDB.h" -#include "GUSITimer.h" - -#include - -// \section{Implementation of POSIX wrappers} -// -// [[pipe]] is in fact a special case of [[socketpair]], but we bypass the domain -// registry because pipe sockets are not installed as a domain. -// -// = -int pipe(int * fd) -{ - GUSIErrorSaver saveError; - GUSISocketFactory * factory = GUSIPipeFactory::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISocket * sock[2]; - - if (!factory->socketpair(0, 0, 0, sock)) { - if ((fd[0] = table->InstallSocket(sock[0])) > -1) - if ((fd[1] = table->InstallSocket(sock[1])) > -1) { - shutdown(fd[0], 1); - shutdown(fd[1], 0); - - return 0; - } else - table->RemoveSocket(fd[0]); - sock[0]->close(); - sock[1]->close(); - } - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} -// [[fsync]] synchronizes a socket -// -// = -int fsync(int s) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->fsync(); -} -// [[close]] closes one file descriptor associated with a socket and deletes the -// socket if this was the last desriptor. -// -// = -int close(int s) -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - return table->RemoveSocket(s); -} -// = -ssize_t read(int s, void *buffer, size_t buflen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->read(buffer, buflen); -} -// = -static ssize_t HandleWriteErrors(ssize_t retval) -{ - if (retval == -1) - switch (errno) { - case EINTR: - case EWOULDBLOCK: - case EINPROGRESS: - case EALREADY: - break; - default: - GUSIConfiguration::Instance()->BrokenPipe(); - break; - } - - return retval; -} - -ssize_t write(int s, const void *buffer, size_t buflen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return HandleWriteErrors(sock->write(buffer, buflen)); -} -// All requests to [[fcntl]] except for [[F_DUPFD]] get dispatched to the socket. -// -// = -int fcntl(int s, int cmd, ...) -{ - va_list arglist; - va_start(arglist, cmd); - - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - if (cmd == F_DUPFD) { - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - return table->InstallSocket(sock, va_arg(arglist, int)); - } else - return sock->fcntl(cmd, arglist); -} -// [[dup]] and [[dup2]] are slight variations of the preceding. -// -// = -int dup(int s) -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return table->InstallSocket(sock); -} - -int dup2(int s, int s1) -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - table->RemoveSocket(s1); - return table->InstallSocket(sock, s1); -} -// = -int fstat(int s, struct stat * buf) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->fstat(buf); -} -// MacOS soon will work with 64 bit file offsets, so [[off_t]] is defined as a -// 64 bit integer. -// -// = -off_t lseek(int s, off_t offset, int whence) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->lseek(offset, whence); -} -// We also should define [[ttyname]] but that will have to wait. -// -// = -int isatty(int s) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->isatty(); -} -// Sleeping is simple, computing the rest time is not. For convenience, we also -// special case sleep(0) as a yield. -// -// = -u_int sleep(u_int seconds) -{ - if (!seconds) { - GUSIContext::Yield(kGUSIYield); - - return 0; - } - GUSITime start(GUSITime::Now()); - GUSITimer * timer = new GUSITimer; - GUSIContext::CreateCurrent()->ClearWakeups(); - timer->Sleep(GUSITime(static_cast(seconds), GUSITime::seconds).Get(GUSITime::msecs)); - GUSIContext::Yield(kGUSIBlock); - delete timer; - - seconds -= (GUSITime::Now() - start).Get(GUSITime::seconds); - - return (seconds & 0x80000000) ? 0 : seconds; -} -// The next calls also need the services of [[GUSIDeviceRegistry]]. [[open]] used -// both the [[GUSIDeviceRegistry]] and the [[GUSIDescriptorTable]]. -// -// = -int open(const char * path, int mode, ...) -{ - GUSIErrorSaver saveError; - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISocket * sock; - int fd; - - if (sock = factory->open(path, mode)) { - if ((fd = table->InstallSocket(sock)) > -1) - return fd; - sock->close(); - } - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} -// [[creat]] is just a special case for [[open]]. -// -// = -int creat(const char * path, ...) -{ - return open(path, O_WRONLY | O_TRUNC | O_CREAT); -} -// [[remove]] remove a file. -// -// = -int remove(const char * path) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->remove(path); -} -// [[unlink]] is the same as [[remove]]. -// -// = -int unlink(const char * path) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->remove(path); -} -// [[rename]] renames a file. -// -// = -int rename(const char * oldname, const char * newname) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->rename(oldname, newname); -} -// [[stat]] and [[lstat]], which ultimately resolve to the same function, -// return information about the status of a file. -// -// = -int stat(const char * path, struct stat * buf) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->stat(path, buf, false); -} - -int lstat(const char * path, struct stat * buf) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->stat(path, buf, true); -} -// [[chmod]] changes file protection flags as well as this is possible under MacOS. -// -// = -int chmod(const char * path, mode_t mode) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->chmod(path, mode); -} -// [[utime]] modifies a file's modification time. -// -// = -int utime(const char * path, const utimbuf * times) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->utime(path, times); -} -// [[access]] checks the access permissions for a file. -// -// = -int access(const char * path, int mode) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->access(path, mode); -} -// [[mkdir]] and [[rmdir]] create and delete a directory, respectively. -// -// = -int mkdir(const char * path, ...) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->mkdir(path); -} - -int rmdir(const char * path) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->rmdir(path); -} -// [[opendir]] returns an instance of a derived class of [[GUSIDirectory]]. -// -// = -typedef GUSIDirectory * GUSIDirPtr; - -DIR * opendir(const char * path) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - GUSIDirectory * dir = factory->opendir(path); - - return dir ? reinterpret_cast(new GUSIDirPtr(dir)) : 0; -} -// The other directory functions then dispatch on the [[GUSIDirectory]] -// without needing the [[GUSIDeviceRegistry]]. [[readdir]] reads the next -// directory entry. -// -// = -dirent * readdir(DIR * dir) -{ - return GUSIDirPtr(*dir)->readdir(); -} -// [[telldir]] saves the current directory position, [[seekdir]] sets it, rewinddir -// sets it to the beginning. -// -// = -long telldir(DIR * dir) -{ - return GUSIDirPtr(*dir)->telldir(); -} - -void seekdir(DIR * dir, long pos) -{ - GUSIDirPtr(*dir)->seekdir(pos); -} - -void rewinddir(DIR * dir) -{ - GUSIDirPtr(*dir)->seekdir(1); -} -// [[closedir]] closes the directory stream. -// -// = -int closedir(DIR * dir) -{ - delete GUSIDirPtr(*dir); - delete dir; - - return 0; -} -// [[chdir]] changes the default directory. -// -// = -int chdir(const char * dir) -{ - GUSIFileSpec directory(dir); - - if (directory.Error()) - return GUSISetMacError(directory.Error()); - else if (!directory.Exists()) - return GUSISetPosixError(ENOENT); - - (++directory).SetDefaultDirectory(); - - return 0; -} -// [[getcwd]] returns the path to the default directory. -// -// = -char *getcwd(char * buf, size_t size) -{ - GUSIFileSpec cwd; - char * res; - - if (cwd.GetDefaultDirectory()) - return GUSISetMacError(cwd.Error()), static_cast(nil); - - res = (--cwd).FullPath(); - - if (size < strlen(res)+1) - return GUSISetPosixError(size > 0 ? ERANGE : EINVAL), - static_cast(nil); - if (!buf && !(buf = (char *) malloc(size))) - return GUSISetPosixError(ENOMEM), static_cast(nil); - - strcpy(buf, res); - - return buf; -} -// [[time]] returns the time in seconds since 1904. The MSL version uses 1970; the -// present version conforms more to my Mac traditionalistic outlook. You will see an -// unpleasant number of [[reinterpret_cast]] expressions in the following routines -// because some of our compilers want [[time_t]] to be [[long]] and some want it to be -// [[unsigned long]]. -// -// = -time_t time(time_t * timer) -{ - time_t t; - - if (!timer) - timer = &t; - - GetDateTime(reinterpret_cast(timer)); - - return *timer; -} -// [[gettimeofday]] returns a somewhat more accurate time than [[time]]. -// -// = -int gettimeofday(struct timeval * tv, struct timezone * tz) -{ - *tv = (timeval)GUSITime::Now(); - if (tz) - *tz = GUSITime::Zone(); - - return 0; -} -// [[localtime]] returns the local time in a broken down record, [[gmtime]] does the -// same with UTC time. Our versions measure from 1904 and are thread safe. -// -// = -extern "C" void GUSIKillTM(void * t) -{ - delete reinterpret_cast(t); -} - -static tm * get_tm() -{ - static GUSISpecificData sTM; - - return sTM.get(); -} - -struct tm * localtime(const time_t * timer) -{ - tm * t = get_tm(); - *t = GUSITime(static_cast(*timer), GUSITime::seconds); - t->tm_isdst = GUSITime::Zone().tz_dsttime != 0; - return t; -} - -struct tm * gmtime(const time_t * timer) -{ - tm * t = get_tm(); - *t = GUSITime(static_cast(*timer), GUSITime::seconds).Local2GMTime(); - t->tm_isdst = 0; - return t; -} -// [[mktime]] parses a [[struct tm]]. -// -// = -time_t mktime(struct tm *timeptr) -{ - return static_cast(GUSITime(*timeptr).UGet(GUSITime::seconds)); -} -// \section{Implementation of Socket wrappers} -// -// [[getdtablesize]] returns the size of the descriptor table. -// -// = -int getdtablesize() -{ - return GUSIDescriptorTable::SIZE; -} -// [[socket]] creates a socket and installs it in the descriptor table. -// -// = -int socket(int domain, int type, int protocol) -{ - GUSIErrorSaver saveError; - GUSISocketFactory * factory = GUSISocketDomainRegistry::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISocket * sock; - int fd; - - if (sock = factory->socket(domain, type, protocol)) { - if ((fd = table->InstallSocket(sock)) > -1) - return fd; - sock->close(); - } - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} -// [[socketpair]] works similar to [[socket]], although the opportunity for problems -// is a bit greater. -// -// = -int socketpair(int domain, int type, int protocol, int * sv) -{ - GUSIErrorSaver saveError; - GUSISocketFactory * factory = GUSISocketDomainRegistry::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISocket * sock[2]; - - if (!factory->socketpair(domain, type, protocol, sock)) { - if ((sv[0] = table->InstallSocket(sock[0])) > -1) - if ((sv[1] = table->InstallSocket(sock[1])) > -1) - return 0; - else - table->RemoveSocket(sv[0]); - sock[0]->close(); - sock[1]->close(); - } - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} -// [[bind]] binds a socket to a name. -// -// = -int bind(int s, const struct sockaddr *name, socklen_t namelen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - return sock->bind((void *) name, namelen); -} -// [[connect]] connects a socket to a named peer. -// -// = -int connect(int s, const struct sockaddr *addr, socklen_t addrlen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - return sock->connect((void *) addr, addrlen); -} -// [[listen]] puts a socket in passive mode. -// -// = -int listen(int s, int qlen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - return sock->listen(qlen); -} -// [[accept]] accepts a connection from another socket. -// -// = -int accept(int s, struct sockaddr *addr, socklen_t *addrlen) -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - if (sock = sock->accept(addr, addrlen)) - if ((s = table->InstallSocket(sock)) != -1) - return s; - else - sock->close(); - - return -1; -} -// = -ssize_t readv(int s, const struct iovec *iov, int count) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->read(GUSIScatterer(iov, count)); -} -// = -ssize_t recv(int s, void *buffer, size_t buflen, int flags) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - socklen_t fromlen = 0; - - return sock->recvfrom(buffer, buflen, flags, nil, &fromlen); -} -// = -ssize_t recvfrom( - int s, void *buffer, size_t buflen, int flags, struct sockaddr *from, socklen_t *fromlen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->recvfrom(buffer, buflen, flags, from, fromlen); -} -// = -ssize_t recvmsg(int s, struct msghdr *msg, int flags) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->recvmsg(msg, flags); -} -// = -ssize_t writev(int s, const struct iovec *iov, int count) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return HandleWriteErrors(sock->write(GUSIGatherer(iov, count))); -} -// = -ssize_t send(int s, const void *buffer, size_t buflen, int flags) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return HandleWriteErrors(sock->sendto(buffer, buflen, flags, nil, 0)); -} -// = -ssize_t sendto( - int s, const void *buffer, size_t buflen, int flags, const struct sockaddr *to, socklen_t tolen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return HandleWriteErrors(sock->sendto(buffer, buflen, flags, to, tolen)); -} -// = -ssize_t sendmsg(int s, const struct msghdr *msg, int flags) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return HandleWriteErrors(sock->sendmsg(msg, flags)); -} -// [[select]] is quite complex, so we break it up. [[select_once]] polls all -// file descriptors once. -// -// = -static int select_once(int width, - fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - fd_set *readres, fd_set *writeres, fd_set *exceptres) -{ - bool r, w, e; - bool * canRead; - bool * canWrite; - bool * canExcept; - int count = 0; - - for (int s = 0; s < width ; ++s) { - canRead = (readfds && FD_ISSET(s,readfds)) ? &r : nil; - canWrite = (writefds && FD_ISSET(s,writefds)) ? &w : nil; - canExcept = (exceptfds && FD_ISSET(s,exceptfds)) ? &e : nil; - if (canRead || canWrite || canExcept) { - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!GUSI_ASSERT_EXTERNAL(sock, ("Socket %d closed in select\n", s))) - return count ? count : -1; - - r = w = e = false; - if (sock->select(canRead, canWrite, canExcept)) - count += (canRead && *canRead)+(canWrite && *canWrite)+(canExcept && *canExcept); - if (r) - FD_SET(s,readres); - if (w) - FD_SET(s,writeres); - if (e) - FD_SET(s,exceptres); - } - } - - return count; -} -// [[select_sleep]] sleeps as long as [[canSleep]] allows. -// -// = -static bool select_sleep(bool canSleep) -{ - if (canSleep) { - return GUSIContext::Yield(kGUSIBlock); - } else { - return GUSIContext::Yield(kGUSIPoll); - } -} -// [[select_forever]] keeps calling [[select_once]] until one of the file -// descriptors triggers. -// -// = -static int select_forever(bool canSleep, int width, - fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - fd_set *readres, fd_set *writeres, fd_set *exceptres) -{ - int count; - - for (;;) { - count = - select_once(width, - readfds, writefds, exceptfds, - readres, writeres, exceptres); - if (count) - break; - if (select_sleep(canSleep)) - return GUSISetPosixError(EINTR); - } - - return count; -} -// [[select_timed]] keeps calling [[select_once]] until one of the file -// descriptors triggers or the timer runs out. -// -// = -static int select_timed(bool canSleep, int width, - fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - fd_set *readres, fd_set *writeres, fd_set *exceptres, - struct timeval *timeout) -{ - int count; - GUSITimer timer; - - timer.MicroSleep(GUSITime(*timeout).Get(GUSITime::usecs)); - for (;;) { - count = - select_once(width, - readfds, writefds, exceptfds, - readres, writeres, exceptres); - if (count || timer.Expired()) - break; - if (select_sleep(canSleep)) - return GUSISetPosixError(EINTR); - } - - return count; -} -// Even so, [[select]] is still a heavyweight. -// -// = -int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -{ - bool canSleep = true; - int count = 0; - fd_set readres; FD_ZERO(&readres); - fd_set writeres; FD_ZERO(&writeres); - fd_set exceptres; FD_ZERO(&exceptres); - - // = - for (int s = 0; s < width ; ++s) - if ( (readfds && FD_ISSET(s,readfds)) - || (writefds && FD_ISSET(s,writefds)) - || (exceptfds && FD_ISSET(s,exceptfds)) - ) - if (!GUSIDescriptorTable::LookupSocket(s)) - return -1; - // = - for (int s = 0; s < width ; ++s) - if (GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s)) { - bool r = readfds && FD_ISSET(s,readfds); - bool w = writefds && FD_ISSET(s,writefds); - bool e = exceptfds && FD_ISSET(s,exceptfds); - - if (r || w || e) - canSleep = sock->pre_select(r, w, e) && canSleep; - } - if (!timeout) { - count = - select_forever(canSleep, width, - readfds, writefds, exceptfds, - &readres, &writeres, &exceptres); - } else if (timeout->tv_sec || timeout->tv_usec) { - count = - select_timed(canSleep, width, - readfds, writefds, exceptfds, - &readres, &writeres, &exceptres, - timeout); - } else { - count = - select_once(width, - readfds, writefds, exceptfds, - &readres, &writeres, &exceptres); - GUSIContext::Yield(kGUSIYield); - } - // This loop is pretty much guaranteed to set [[errno]] to [[EBADF]], so we - // save the actual error code and restore it (this is harmless if no error - // occurred). - // - // = - int saveErrno = errno; - for (int s = 0; s < width ; ++s) - if (GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s)) { - bool r = readfds && FD_ISSET(s,readfds); - bool w = writefds && FD_ISSET(s,writefds); - bool e = exceptfds && FD_ISSET(s,exceptfds); - - if (r || w || e) - sock->post_select(r, w, e); - } - errno = saveErrno; - // When copying back descriptor sets, we have to be careful not to copy more - // words than covered by [[width]], because Perl depends on that by allocating - // fake [[fd_sets]]. I personally think that is a bad idea, but staying - // compatible doesn't cost too much. - // - // = - int nwords = ((width+31) >> 3) & ~3; - if (readfds) - memcpy(readfds, &readres, nwords); - if (writefds) - memcpy(writefds, &writeres, nwords); - if (exceptfds) - memcpy(exceptfds, &exceptres, nwords); - - return count; -} -// = -int getsockname(int s, struct sockaddr *name, socklen_t *namelen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->getsockname(name, namelen); -} - -int getpeername(int s, struct sockaddr *name, socklen_t *namelen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->getpeername(name, namelen); -} -// = -int shutdown(int s, int how) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->shutdown(how); -} -// Bit of trivia: [[ioctl]] is actually not a POSIX function. -// -// = -int ioctl(int s, unsigned long request, ...) -{ - va_list arglist; - va_start(arglist, request); - - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->ioctl(request, arglist); -} -// The length argument should eventually become a [[socklen_t]]. -// -// = -int getsockopt(int s, int level, int optname, void *optval, socklen_t * optlen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->getsockopt(level, optname, optval, optlen); -} -// = -int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock->setsockopt(level, optname, (void *) optval, optlen); -} -// = -int ftruncate(int s, off_t offset) -{ - // Many of the other routines are quite stereotypical: They translate their file - // descriptor argument to a [[GUSISocket]] and dispatch the call to it. - // - // = - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!sock) - return -1; - - return sock ? sock->ftruncate(offset) : -1; -} -// [[truncate]] is implemented in terms of [[ftruncate]]. -// -// = -int truncate(const char * path, off_t offset) -{ - int fd = open(path, O_RDWR); - if (fd < 0) - return fd; - - int res = ftruncate(fd, offset); - - close(fd); - - return res; -} -// While [[sleep]] is a POSIX function, [[usleep]] is not. -// -// = -int usleep(u_int useconds) -{ - if (!useconds) { - GUSIContext::Yield(kGUSIYield); - - return 0; - } - GUSITimer * timer = new GUSITimer; - GUSIContext::CreateCurrent()->ClearWakeups(); - timer->MicroSleep(useconds); - GUSIContext::Yield(kGUSIBlock); - delete timer; - - return 0; -} -// [[symlink]] creates a symbolic link to a file. -// -// = -int symlink(const char * path, const char * linkto) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->symlink(path, linkto); -} -// [[readlink]] reads the contents of a symbolic link. -// -// = -int readlink(const char * path, char * buf, int bufsize) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->readlink(path, buf, bufsize); -} -// [[inet_aton]] and [[inet_addr]] convert an address string to an internet address. -// -// = -int inet_aton(const char * addr, struct in_addr * ina) -{ - in_addr_t a = inet_addr(addr); - - if (a == INADDR_NONE) - return 0; - if (ina) - ina->s_addr = a; - - return 1; -} -// = -in_addr_t inet_addr(const char * addr) -{ - return GUSINetDB::Instance()->inet_addr(addr); -} -// = -char *inet_ntoa(in_addr addr) -{ - return GUSINetDB::Instance()->inet_ntoa(addr); -} -// = -long gethostid() -{ - return GUSINetDB::Instance()->gethostid(); -} -// = -int gethostname(char *machname, int buflen) -{ - return GUSINetDB::Instance()->gethostname(machname, buflen); -} -// = -void setprotoent(int stayopen) -{ - GUSINetDB::Instance()->setprotoent(stayopen); -} -// = -void setservent(int stayopen) -{ - GUSINetDB::Instance()->setservent(stayopen); -} -// = -void endprotoent() -{ - GUSINetDB::Instance()->endprotoent(); -} -// = -void endservent() -{ - GUSINetDB::Instance()->endservent(); -} -// = -hostent *gethostbyaddr(const void * addr, size_t size, int family) -{ - return GUSINetDB::Instance()->gethostbyaddr(addr, size, family); -} -// = -hostent *gethostbyname(const char * name) -{ - return GUSINetDB::Instance()->gethostbyname(name); -} -// = -protoent *getprotobyname(const char * name) -{ - return GUSINetDB::Instance()->getprotobyname(name); -} -// = -protoent *getprotobynumber(int proto) -{ - return GUSINetDB::Instance()->getprotobynumber(proto); -} -// = -protoent *getprotoent() -{ - return GUSINetDB::Instance()->getprotoent(); -} -// = -servent *getservbyname(const char * name, const char * proto) -{ - return GUSINetDB::Instance()->getservbyname(name, proto); -} -// = -servent *getservbyport(int port, const char * proto) -{ - return GUSINetDB::Instance()->getservbyport(port, proto); -} -// = -servent *getservent() -{ - return GUSINetDB::Instance()->getservent(); -} -// \section{Implementation of MPW wrappers} -// -// [[fgetfileinfo]] and [[fsetfileinfo]] manipulate the MacOS type/creator codes. -// -// = -int fgetfileinfo(const char * path, OSType * creator, OSType * type) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->fgetfileinfo(path, creator, type); -} - -void fsetfileinfo(const char * path, OSType creator, OSType type) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - factory->fsetfileinfo(path, creator, type); -} -// [[faccess]] manipulates MPW properties of files. -// -// = -int faccess(const char * path, unsigned * cmd, void * arg) -{ - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - - return factory->faccess(path, cmd, arg); -} diff --git a/GUSI/src/tangled/GUSIPPC.cp b/GUSI/src/tangled/GUSIPPC.cp deleted file mode 100755 index 89de422..0000000 --- a/GUSI/src/tangled/GUSIPPC.cp +++ /dev/null @@ -1,791 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIPPC.h" -#include "GUSIBasics.h" -#include "GUSIBuffer.h" -#include "GUSISocketMixins.h" - -#include - -#include - -GUSI_USING_STD_NAMESPACE - -// \section{Definition of [[GUSIPPCSocket]]} -// -// A [[GUSIPPCSocket]] is implemented with the usual read and write -// buffers. -// -// = -class GUSIPPCSocket : - public GUSISocket, - protected GUSISMBlocking, - protected GUSISMState, - protected GUSISMInputBuffer, - protected GUSISMOutputBuffer -{ -public: - GUSIPPCSocket(); - virtual ~GUSIPPCSocket(); - // [[bind]] is absolutely required for all forms of PPC sockets. - // - // = - virtual int bind(void * addr, socklen_t namelen); - // [[connect]] opens a connection actively. - // - // = - virtual int connect(void * address, socklen_t addrlen); - // Most of the dirty work of [[listen]] is already handled in [[GUSIPPCListen]]. - // - // = - virtual int listen(int queueLength); - // [[accept]] also is able to delegate most of the hard work to [[GUSIPPCListen]]. - // - // = - virtual GUSISocket * accept(void *from, socklen_t *fromlen); - // = - virtual bool Supports(ConfigOption config); - // [[recvfrom]] reads from [[fInputBuffer]]. - // - // = - virtual ssize_t recvfrom(const GUSIScatterer & buffer, int, void * from, socklen_t * fromlen); - // [[sendto]] writes to [[fOutputBuffer]]. As opposed to reads, writes have to - // be executed fully. This leads to a problem when a nonblocking write wants to - // write more data than the total length of the buffer. In this case, GUSI disregards - // the nonblocking flag. - // - // = - virtual ssize_t sendto(const GUSIGatherer & buffer, int flags, const void * to, socklen_t); - // [[select]] checks for various conditions on the socket. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - // [[fcntl]] handles the blocking support. - // - // = - virtual int fcntl(int cmd, va_list arg); - // [[ioctl]] deals with blocking support and with [[FIONREAD]]. - // - // = - virtual int ioctl(unsigned int request, va_list arg); - // = - virtual int shutdown(int how); -protected: - // \section{Implementation of [[GUSIPPCSocket]]} - // - // The implementation of [[GUSIPPCSocket]] is similar to many other socket classes. - // Let's start, once more, with the interrupt level routines. - // - // \subsection{Interrupt level routines for [[GUSIPPCSocket]]} - // - // Both [[GUSIPPCSendDone]] and [[GUSIPPCRecvDone]] are always called with the - // same [[TCPiopb]] in a [[GUSIPPCSocket]] so they can easily find out the address - // of the socket itself. [[GUSIPPCSend]] and [[GUSIPPCRecv]] set up send and receive - // calls. - // - // = - OSErr fAsyncError; - PPCParamBlockRec fSendPB; - PPCParamBlockRec fRecvPB; - friend void GUSIPPCSend(GUSIPPCSocket * sock); - friend void GUSIPPCRecv(GUSIPPCSocket * sock); - friend void GUSIPPCSendDone(PPCParamBlockPtr pb); - friend void GUSIPPCRecvDone(PPCParamBlockPtr pb); - static PPCCompUPP sSendProc; - static PPCCompUPP sRecvProc; - // For listens it is necessary to build a backlog if the interrupt level gets opens - // faster than the high level routines can accept them. - // - // = - struct Listener { - PPCSessRefNum fSession; - LocationNameRec fLocation; - PPCPortRec fPort; - bool fBusy; - }; - Listener * fListeners; - bool fRestartListen; - char fNumListeners; - char fCurListener; - char fNextListener; - friend void GUSIPPCListenDone(PPCParamBlockPtr pb); - friend void GUSIPPCListen(GUSIPPCSocket * sock); - static PPCCompUPP sListenProc; - // [[SetupListener]] prepares a [[Listener]]. - // - // = - void SetupListener(Listener & listener); - // Some functions simply need to wake up the socket again. These are always called - // on [[fSendPB]], because [[fRecvPB]] might be in use by a [[PPCInform]] call. - // - // = - friend void GUSIPPCDone(PPCParamBlockPtr pb); - static PPCCompUPP sDoneProc; - // \subsection{High level interface for [[GUSIPPCSocket]]} - // - // - // = - LocationNameRec fLocation; - PPCPortRec fPort; - LocationNameRec fPeerLoc; - PPCPortRec fPeerPort; - // The port reference number is shared between a listener and all of its - // clients, so we cannot simply close it at any time and have to store it - // in a shared data structure. - // - // = - struct PortRef { - short fRefCount; - PPCPortRefNum fPort; - - PortRef(PPCPortRefNum port) : fRefCount(1), fPort(port) {} - }; - PortRef * fPortRef; - // [[accept]] uses a special constructor of [[GUSIPPCSocket]] which constructs - // a socket directly from a [[Listener]]. - // - // = - GUSIPPCSocket(GUSIPPCSocket * orig, Listener & listener); -}; -// \section{Implementation of [[GUSIPPCFactory]]} -// -// To use PPC sockets, you need to call [[GUSIwithPPCSockets]] from your [[GUSISetupFactories]] routine. -// -// = -extern "C" void GUSIwithPPCSockets() -{ - GUSISocketDomainRegistry::Instance()->AddFactory(AF_PPC, GUSIPPCFactory::Instance()); -} -// = -GUSISocketFactory * GUSIPPCFactory::sInstance = nil; -// = -GUSISocket * GUSIPPCFactory::socket(int, int, int) -{ - return new GUSIPPCSocket; -} -// The UPPs for the completion procedures are set up the first time a socket -// is constructed. -// -// = -PPCCompUPP GUSIPPCSocket::sSendProc = 0; -PPCCompUPP GUSIPPCSocket::sRecvProc = 0; -// = -PPCCompUPP GUSIPPCSocket::sListenProc = 0; -// = -void GUSIPPCSocket::SetupListener(Listener & listener) -{ - listener.fBusy = false; -} -// = -PPCCompUPP GUSIPPCSocket::sDoneProc = 0; -// The constructors have to initialize a rather large number of data fields. -// -// = -GUSIPPCSocket::GUSIPPCSocket() -{ - // = - if (!sSendProc) - sSendProc = NewPPCCompProc(reinterpret_cast(GUSIPPCSendDone)); - if (!sRecvProc) - sRecvProc = NewPPCCompProc(reinterpret_cast(GUSIPPCRecvDone)); - // = - fListeners = nil; - fRestartListen = true; - fNumListeners = 0; - fCurListener = 0; - fNextListener = 0; - if (!sListenProc) - sListenProc = NewPPCCompProc(reinterpret_cast(GUSIPPCListenDone)); - // = - if (!sDoneProc) - sDoneProc = NewPPCCompProc(reinterpret_cast(GUSIPPCDone)); -} -// = -int GUSIPPCSocket::bind(void * addr, socklen_t namelen) -{ - struct sockaddr_ppc *name = (struct sockaddr_ppc *)addr; - // The address to be passed must be up to a minimal standard of decency. - // For instance, the host address must be either the real IP number of - // our host or one of the two legitimate pseudo-addresses for - // [["localhost"]]. - // - // = - if (!GUSI_ASSERT_CLIENT( - namelen >= sizeof(struct sockaddr_ppc), - ("bind: address len %d < %d\n", namelen, sizeof(struct sockaddr_ppc))) - ) - return GUSISetPosixError(EINVAL); - if (!GUSI_ASSERT_CLIENT( - name->sppc_family == AF_PPC, - ("bind: family %d != %d\n", name->sppc_family, AF_PPC)) - ) - return GUSISetPosixError(EAFNOSUPPORT); - if (!GUSI_SASSERT_CLIENT(fState==Unbound, "bind: Socket already bound\n")) - return GUSISetPosixError(EINVAL); - fPort = name->sppc_port; - fLocation = name->sppc_location; - - PPCOpenPBRec & openParam = fSendPB.openParam; - openParam.ioCompletion = sDoneProc; - openParam.serviceType = ppcServiceRealTime; - openParam.resFlag = 0; - openParam.portName = &fPort; - openParam.locationName = &fLocation; - openParam.networkVisible= true; - PPCOpenAsync(&openParam); - AddContext(); - while (fSendPB.openParam.ioResult == 1) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - - switch (fSendPB.openParam.ioResult) { - case noErr: - fPortRef = new PortRef(openParam.portRefNum); - fState = Unconnected; - return 0; - case noGlobalsErr: - return GUSISetPosixError(ENOMEM); - case portNameExistsErr: - case nbpDuplicate: - return GUSISetPosixError(EADDRINUSE); - case nameTypeErr: - case badReqErr: - case badPortNameErr: - case badLocNameErr: - default: - return GUSISetPosixError(EINVAL); - } -} -// = -int GUSIPPCSocket::connect(void * address, socklen_t addrlen) -{ - sockaddr_ppc * addr = (sockaddr_ppc *) address; - - // = - if (!GUSI_CASSERT_CLIENT(addrlen >= int(sizeof(sockaddr_ppc)))) - return GUSISetPosixError(EINVAL); - if (!GUSI_CASSERT_CLIENT(addr->sppc_family == AF_PPC)) - return GUSISetPosixError(EAFNOSUPPORT); - switch (fState) { - case Unbound: - return GUSISetPosixError(EINVAL); // Must be bound before connecting - case Unconnected: - break; // Go ahead - default: - return GUSISetPosixError(EISCONN); // Already connected in some form - } - - fPeerPort = addr->sppc_port; - fPeerLoc = addr->sppc_location; - - PPCStartPBRec & startParam = fSendPB.startParam; - startParam.portRefNum = fPortRef->fPort; - startParam.resFlag = 0; - startParam.portName = &fPeerPort; - startParam.locationName = &fPeerLoc; - startParam.userData = 0; - startParam.userRefNum = 0; - - Boolean guest; - Str32 uname; - uname[0] = 0; - - switch (StartSecureSession(&startParam, uname, true, true, &guest, (StringPtr) "\p")) { - case userCanceledErr: - return GUSISetPosixError(EINTR); - default: - return GUSISetPosixError(EINVAL); - case noErr: - fState = Connected; - - PPCWritePBRec & writeParam = fSendPB.writeParam; - writeParam.ioCompletion = sSendProc; - - PPCReadPBRec & readParam = fRecvPB.readParam; - readParam.ioCompletion = sRecvProc; - readParam.sessRefNum = writeParam.sessRefNum; - - GUSIPPCSend(this); - GUSIPPCRecv(this); - - return 0; - } -} -// = -int GUSIPPCSocket::listen(int queueLength) -{ - // = - if (!GUSI_CASSERT_CLIENT(fState <= Unconnected)) - return GUSISetPosixError(EISCONN); - if (!GUSI_CASSERT_CLIENT(fState != Unbound)) - return GUSISetPosixError(EINVAL); - // For some weird reason, BSD multiplies queue lengths with a fudge factor. - // - // = - if (queueLength < 1) - queueLength = 1; - else if (queueLength > 4) - queueLength = 8; - else - queueLength = ((queueLength * 3) >> 1) + 1; - - fInputBuffer.SwitchBuffer(0); - fOutputBuffer.SwitchBuffer(0); - fState = Listening; - fListeners = new Listener[fNumListeners = queueLength]; - while (queueLength--) - SetupListener(fListeners[queueLength]); - - GUSIPPCListen(this); - - return 0; -} -// = -GUSISocket * GUSIPPCSocket::accept(void *from, socklen_t *fromlen) -{ - GUSIPPCSocket * sock; - - // = - if (!GUSI_CASSERT_CLIENT(fState == Listening)) { - GUSISetPosixError(ENOTCONN); - return nil; - } - // Listener slots are filled one by one, so we simply check whether the next listener - // block has been filled yet. - // - // = - if (!fListeners[fNextListener].fBusy && !fReadShutdown) { - if (!fBlocking) { - GUSISetPosixError(EWOULDBLOCK); - return nil; - } - bool signal = false; - AddContext(); - while (!fListeners[fNextListener].fBusy && !fReadShutdown) { - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - } - RemoveContext(); - if (!fListeners[fNextListener].fBusy && signal) - return GUSISetPosixError(EINTR), static_cast(0); - } - if (!fListeners[fNextListener].fBusy && fReadShutdown) - return GUSISetPosixError(ESHUTDOWN), static_cast(0); - - sock = new GUSIPPCSocket(this, fListeners[fNextListener]); - - SetupListener(fListeners[fNextListener]); - fNextListener = (fNextListener+1) % fNumListeners; - - if (fRestartListen) - GUSIPPCListen(this); - - if (sock && from) - sock->getpeername(from, fromlen); - - return sock; -} -// = -GUSIPPCSocket::GUSIPPCSocket(GUSIPPCSocket * orig, Listener & listener) -{ - // = - if (!sSendProc) - sSendProc = NewPPCCompProc(reinterpret_cast(GUSIPPCSendDone)); - if (!sRecvProc) - sRecvProc = NewPPCCompProc(reinterpret_cast(GUSIPPCRecvDone)); - // = - fListeners = nil; - fRestartListen = true; - fNumListeners = 0; - fCurListener = 0; - fNextListener = 0; - if (!sListenProc) - sListenProc = NewPPCCompProc(reinterpret_cast(GUSIPPCListenDone)); - // = - if (!sDoneProc) - sDoneProc = NewPPCCompProc(reinterpret_cast(GUSIPPCDone)); - fLocation = orig->fLocation; - fPort = orig->fPort; - fPeerLoc = listener.fLocation; - fPeerPort = listener.fPort; - fPortRef = orig->fPortRef; - ++fPortRef->fRefCount; - fState = Connected; - - PPCWritePBRec & writeParam = fSendPB.writeParam; - writeParam.ioCompletion = sSendProc; - writeParam.sessRefNum = listener.fSession; - - PPCReadPBRec & readParam = fRecvPB.readParam; - readParam.ioCompletion = sRecvProc; - readParam.sessRefNum = listener.fSession; - - GUSIPPCSend(this); - GUSIPPCRecv(this); -} -// = -bool GUSIPPCSocket::Supports(ConfigOption config) -{ - return config == kSocketCalls; -} -// = -ssize_t GUSIPPCSocket::recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen) -{ - if (from) - getpeername(from, fromlen); - - // = - if (fReadShutdown&& !fInputBuffer.Valid()) - return 0; - switch (fState) { - case Unbound: - case Unconnected: - case Listening: - return GUSISetPosixError(ENOTCONN); - case Closing: - case Connecting: - case Connected: - break; - } - // The socket needs to be in [[Connected]] or [[Closing]] state and the input buffer needs to be - // nonempty before a read can succeed. - // - // = - if (!fReadShutdown - && (fState == Connecting || fState == Connected || fState == Closing) - && !fInputBuffer.Valid() - ) { - if (!fBlocking) - return GUSISetPosixError(EWOULDBLOCK); - bool signal = false; - AddContext(); - while (!fReadShutdown - && (fState == Connecting || fState == Connected || fState == Closing) - && !fInputBuffer.Valid() - ) - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - RemoveContext(); - if (signal && !fInputBuffer.Valid()) - return GUSISetPosixError(EINTR); - } - - size_t len = buffer.Length(); - if (flags & MSG_PEEK) - fInputBuffer.Peek(buffer, len); - else - fInputBuffer.Consume(buffer, len); - - return (int)len; -} -// = -ssize_t GUSIPPCSocket::sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t) -{ - // = - if (fWriteShutdown) - return GUSISetPosixError(ESHUTDOWN); - - if (!GUSI_SASSERT_CLIENT(!to, "Can't sendto() on a stream socket")) - return GUSISetPosixError(EOPNOTSUPP); - switch (fState) { - case Unbound: - case Unconnected: - case Listening: - return GUSISetPosixError(ENOTCONN); - case Closing: - case Connecting: - case Connected: - break; - } - - if (!fBlocking && !fOutputBuffer.Free()) - return GUSISetPosixError(EAGAIN); - - size_t rest = buffer.Length(); - size_t offset = 0; - while (rest) { - size_t len = rest; - bool signal = false; - // = - if (!fBlocking && !fOutputBuffer.Free()) - break; - if (!fWriteShutdown && (fState == Connecting || fState == Connected) && !fOutputBuffer.Free()) { - AddContext(); - while (!fWriteShutdown - && (fState == Connecting || fState == Connected) - && !fOutputBuffer.Free() - ) - signal = GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - } - if (signal || (fWriteShutdown && !fOutputBuffer.Free())) - if (offset) - break; - else - return GUSISetPosixError(signal ? EINTR : ESHUTDOWN); - fOutputBuffer.Produce(buffer, len, offset); - rest -= len; - } - - return offset; -} -// = -bool GUSIPPCSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = fReadShutdown || - (fState == Listening - ? fListeners[fNextListener].fBusy - : fInputBuffer.Valid() > 0 - ) - ) - cond = true; - if (canWrite) - if (*canWrite = fWriteShutdown || fOutputBuffer.Free()) - cond = true; - - return cond; -} -// = -int GUSIPPCSocket::fcntl(int cmd, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoFcntl(&result, cmd, arg)) - return result; - - GUSI_ASSERT_CLIENT(false, ("fcntl: illegal request %d\n", cmd)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIPPCSocket::ioctl(unsigned int request, va_list arg) -{ - int result; - - if (GUSISMBlocking::DoIoctl(&result, request, arg) - || GUSISMInputBuffer::DoIoctl(&result, request, arg) - ) - return result; - - GUSI_ASSERT_CLIENT(false, ("ioctl: illegal request %d\n", request)); - - return GUSISetPosixError(EOPNOTSUPP); -} -// = -int GUSIPPCSocket::shutdown(int how) -{ - if (!GUSI_SASSERT_CLIENT(how >= 0 && how < 3, "shutdown: 0,1, or 2\n")) - return GUSISetPosixError(EINVAL); - - GUSISMState::Shutdown(how); - fOutputBuffer.Lock(); - fOutputBuffer.Release(); - - return 0; -} -// = -GUSIPPCSocket::~GUSIPPCSocket() -{ - switch (fState) { - case Listening: - shutdown(2); - // = - fInputBuffer.Lock(); - for (int i = 0; ifRefCount) { - fSendPB.closeParam.ioCompletion = sDoneProc; - fSendPB.closeParam.portRefNum = fPortRef->fPort; - PPCCloseAsync(&fSendPB.closeParam); - AddContext(); - while (fSendPB.closeParam.ioResult == 1) - GUSIContext::Yield(kGUSIBlock); - RemoveContext(); - delete fPortRef; - } -} -// [[GUSIPPCSendDone]] does all its work between [[fSendPB]] and [[fOutputBuffer]]. -// If a send fails, the whole send buffer is cleared. -// -// = -void GUSIPPCSendDone(PPCParamBlockPtr pb) -{ - GUSIPPCSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIPPCSocket, fSendPB)); - if (sock->fOutputBuffer.Locked()) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIPPCSendDone), pb); - else { - PPCWritePBRec & writeParam = pb->writeParam; - - sock->fOutputBuffer.ClearDefer(); - sock->fOutputBuffer.FreeBuffer(writeParam.bufferPtr, writeParam.actualLength); - if (writeParam.ioResult) { - for (long valid; valid = sock->fOutputBuffer.Valid(); ) - sock->fOutputBuffer.FreeBuffer(nil, valid); - sock->fWriteShutdown = true; - } - GUSIPPCSend(sock); - sock->Wakeup(); - } -} -// [[GUSIPPCSend]] starts a PPC write call if there is data to send and otherwise -// sets itself up as the deferred procedure of the output buffer (and thus is -// guaranteed to be called the next time data is deposited in the buffer again). -// If all data has been delivered and a shutdown is requested, send one. -// -// = -void GUSIPPCSend(GUSIPPCSocket * sock) -{ - size_t valid = sock->fOutputBuffer.Valid(); - - sock->fOutputBuffer.ClearDefer(); - if (!valid) { - if (!sock->fWriteShutdown) - sock->fOutputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIPPCSend), sock); - else if (sock->fState == GUSIPPCSocket::Connected) - sock->fState = GUSIPPCSocket::Closing; - } else { - PPCWritePBRec & writeParam = sock->fSendPB.writeParam; - valid = min(valid, min((size_t)65535, sock->fOutputBuffer.Size() >> 1)); - - writeParam.bufferPtr = - reinterpret_cast(sock->fOutputBuffer.ConsumeBuffer(valid)); - writeParam.bufferLength = (Size) valid; - writeParam.more = false; - writeParam.userData = 0; - writeParam.blockCreator = 'GU·I'; - writeParam.blockType = 'strm'; - - PPCWriteAsync(&writeParam); - } -} -// [[GUSIPPCRecvDone]] does all its work between [[fRecvPB]] and [[fInputBuffer]]. -// -// = -void GUSIPPCRecvDone(PPCParamBlockPtr pb) -{ - GUSIPPCSocket * sock = - reinterpret_cast((char *)pb-offsetof(GUSIPPCSocket, fRecvPB)); - if (sock->fInputBuffer.Locked()) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIPPCRecvDone), pb); - else { - PPCReadPBRec & readParam = pb->readParam; - sock->fInputBuffer.ClearDefer(); - switch (readParam.ioResult) { - case noErr: - sock->fInputBuffer.ValidBuffer(readParam.bufferPtr, readParam.actualLength); - GUSIPPCRecv(sock); - break; - default: - sock->fReadShutdown = true; - break; - } - sock->Wakeup(); - } -} -// [[GUSIPPCRecv]] starts a PPC receive call if there is room left and otherwise -// sets itself up as the deferred procedure of the output buffer (and thus is -// guaranteed to be called the next time there is free space in the buffer again. -// -// = -void GUSIPPCRecv(GUSIPPCSocket * sock) -{ - size_t free = sock->fInputBuffer.Free(); - if (!free) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIPPCRecv), sock); - else { - PPCReadPBRec & readParam = sock->fRecvPB.readParam; - - sock->fInputBuffer.ClearDefer(); - free = min(free, min((size_t)65535, sock->fInputBuffer.Size() >> 1)); - - readParam.ioCompletion = sock->sRecvProc; - readParam.bufferPtr = - reinterpret_cast(sock->fInputBuffer.ProduceBuffer(free)); - readParam.bufferLength = free; - - PPCReadAsync(&readParam); - } -} -// [[GUSIPPCListenDone]] saves the connection parameters and starts the -// next passive open, if possible. Blocking on [[fInputBuffer]] is somewhat -// bizarre; we're not actually using the buffer, just its lock. The only -// times this lock is used is when the socket is shutting down. -// -// = -void GUSIPPCListenDone(PPCParamBlockPtr pb) -{ - GUSIPPCSocket * sock = - (GUSIPPCSocket *)((char *)pb-offsetof(GUSIPPCSocket, fRecvPB)); - if (!(sock->fAsyncError = pb->informParam.ioResult)) { - GUSIPPCSocket::Listener & listener = sock->fListeners[sock->fCurListener]; - listener.fSession = pb->informParam.sessRefNum; - listener.fBusy = true; - sock->fCurListener = (sock->fCurListener+1) % sock->fNumListeners; - } - sock->Wakeup(); - if (!sock->fAsyncError) - if (sock->fInputBuffer.Locked()) - sock->fInputBuffer.Defer(GUSIRingBuffer::Deferred(GUSIPPCListenDone), pb); - else { - sock->fInputBuffer.ClearDefer(); - GUSIPPCListen(sock); - } -} -// [[GUSIPPCListen]] initiates a passive open. -// -// = -void GUSIPPCListen(GUSIPPCSocket * sock) -{ - if (sock->fReadShutdown) - return; - if (sock->fRestartListen = sock->fListeners[sock->fCurListener].fBusy) - return; - PPCInformPBRec & informParam = sock->fRecvPB.informParam; - GUSIPPCSocket::Listener & listener = sock->fListeners[sock->fCurListener]; - informParam.ioCompletion = GUSIPPCSocket::sListenProc; - informParam.portRefNum = sock->fPortRef->fPort; - informParam.autoAccept = true; - informParam.portName = &listener.fPort; - informParam.locationName = &listener.fLocation; - informParam.userName = nil; - - PPCInformAsync(&informParam); -} -// = -void GUSIPPCDone(PPCParamBlockPtr pb) -{ - GUSIPPCSocket * sock = - (GUSIPPCSocket *)((char *)pb-offsetof(GUSIPPCSocket, fSendPB)); - sock->fAsyncError = pb->endParam.ioResult; - sock->Wakeup(); -} diff --git a/GUSI/src/tangled/GUSIPThread.cp b/GUSI/src/tangled/GUSIPThread.cp deleted file mode 100755 index 81a9030..0000000 --- a/GUSI/src/tangled/GUSIPThread.cp +++ /dev/null @@ -1,348 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSITimer.h" -#include "GUSIPThread.h" - -#include -#include - -// \section{PThread Attribute Management} -// -// On creation of a thread, we can specify various attributes via a thread -// attribute. -// -// = -struct GUSIPThreadAttr { - size_t fStackSize; - enum { - detached = 1 << 0 - }; - int fFlags; - - static GUSIPThreadAttr sDefault; - static pthread_attr_t sDefaultAttr; -}; -// By default, we give threads 20K of stack space. -// -// = -GUSIPThreadAttr GUSIPThreadAttr::sDefault = { 20480, 0 }; -pthread_attr_t GUSIPThreadAttr::sDefaultAttr = &GUSIPThreadAttr::sDefault; -// = -int pthread_attr_init(pthread_attr_t * attr) -{ - return (*attr = new GUSIPThreadAttr(GUSIPThreadAttr::sDefault)) - ? 0 : ENOMEM; -} -// = -int pthread_attr_destroy(pthread_attr_t * attr) -{ - delete *attr; - *attr = nil; - - return 0; -} -// = -int pthread_attr_getdetachstate(const pthread_attr_t * attr, int * state) -{ - *state = - (attr[0]->fFlags & GUSIPThreadAttr::detached) - ? PTHREAD_CREATE_JOINABLE - : PTHREAD_CREATE_DETACHED; - - return 0; -} - -int pthread_attr_setdetachstate(pthread_attr_t * attr, int state) -{ - if (state == PTHREAD_CREATE_JOINABLE) - attr[0]->fFlags &= ~GUSIPThreadAttr::detached; - else - attr[0]->fFlags |= GUSIPThreadAttr::detached; - - return 0; -} -// = -int pthread_attr_getstacksize(const pthread_attr_t * attr, size_t * size) -{ - *size = attr[0]->fStackSize; - - return 0; -} - -int pthread_attr_setstacksize(pthread_attr_t * attr, size_t size) -{ - attr[0]->fStackSize = size; - - return 0; -} -// = -struct CreateArg { - GUSIPThreadProc fRealProc; - void * fRealArg; - - CreateArg(GUSIPThreadProc realProc, void * realArg) - : fRealProc(realProc), fRealArg(realArg) {} -}; - -static pascal void * GUSIThreadEntryProcWrapper(CreateArg * arg) -{ - CreateArg fixedArg = *arg; - - delete arg; - return fixedArg.fRealProc(fixedArg.fRealArg); -} -// = -int pthread_create( - pthread_t * thread, - const pthread_attr_t * attr, GUSIPThreadProc proc, void * arg) -{ - if (!attr) - attr = &GUSIPThreadAttr::sDefaultAttr; - - GUSIContext::Setup(true); - *thread = static_cast( - GUSIContextFactory::Instance()->CreateContext( - reinterpret_cast(GUSIThreadEntryProcWrapper), - new CreateArg(proc, arg), - attr[0]->fStackSize)); - switch (thread[0]->Error()) { - case noErr: - if (attr[0]->fFlags & GUSIPThreadAttr::detached) - thread[0]->Detach(); - return 0; - default: - thread[0]->Liquidate(); - *thread = nil; - - return ENOMEM; // Most likely candidate for error - } -} -// = -int pthread_detach(pthread_t thread) -{ - thread->Detach(); - - return 0; -} -// = -int pthread_join(pthread_t thread, void **value) -{ - if (thread->Done(true)) { - if (value) - *value = thread->Result(); - thread->Liquidate(); - - return 0; - } else - return ESRCH; -} -// = -int pthread_exit(void *value) -{ - DisposeThread(GUSIContext::Current()->ID(), value, false); - - return 0; // Not reached -} -// = -int pthread_key_create(pthread_key_t * key, GUSIPThreadKeyDestructor destructor) -{ - return (*key = new GUSIPThreadKey(destructor)) ? 0 : ENOMEM; -} -// = -int pthread_key_delete(pthread_key_t key) -{ - delete key; - - return 0; -} -// = -void * pthread_getspecific(pthread_key_t key) -{ - return GUSIContext::CreateCurrent(true)->GetSpecific(key); -} -// = -int pthread_setspecific(pthread_key_t key, void * value) -{ - GUSIContext::CreateCurrent(true)->SetSpecific(key, value); - - return 0; -} -// = -int pthread_mutexattr_init(pthread_mutexattr_t *) -{ - return 0; -} - -int pthread_mutexattr_destroy(pthread_mutexattr_t *) -{ - return 0; -} -// = -int pthread_mutex_init(pthread_mutex_t * mutex, const pthread_mutexattr_t *) -{ - *mutex = new GUSIPThreadMutex; - - return 0; -} - -int pthread_mutex_destroy(pthread_mutex_t * mutex) -{ - delete *mutex; - *mutex = 0; - - return 0; -} -// = -int pthread_mutex_lock(pthread_mutex_t * mutex) -{ - if (!*mutex) - pthread_mutex_init(mutex, NULL); - mutex[0]->push(GUSIContext::CreateCurrent(true)); - while (mutex[0]->front() != GUSIContext::Current()) - GUSIContext::Yield(kGUSIBlock); - return 0; -} -// = -int pthread_mutex_trylock(pthread_mutex_t * mutex) -{ - if (!*mutex) - pthread_mutex_init(mutex, NULL); - if (mutex[0]->empty() || mutex[0]->front() == GUSIContext::CreateCurrent(true)) { - mutex[0]->push(GUSIContext::Current()); - - return 0; - } else { - bool wasPolling = mutex[0]->fPolling; - mutex[0]->fPolling = true; - GUSIContext::Yield(wasPolling ? kGUSIYield : kGUSIPoll); - - return EBUSY; - } -} -// = -int pthread_mutex_unlock(pthread_mutex_t * mutex) -{ - if (!*mutex || mutex[0]->front() != GUSIContext::CreateCurrent(true)) - return EPERM; // We don't hold that lock - mutex[0]->pop(); - if (GUSIContext * new_boss = mutex[0]->front()) - new_boss->Wakeup(); - if (mutex[0]->fPolling) { - mutex[0]->fPolling = false; - GUSIContext::Yield(kGUSIYield); - } - return 0; -} -// = -int pthread_condattr_init(pthread_condattr_t *) -{ - return 0; -} - -int pthread_condattr_destroy(pthread_condattr_t *) -{ - return 0; -} -// = -int pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t *) -{ - *cond = new GUSIPThreadCond; - - return 0; -} - -int pthread_cond_destroy(pthread_cond_t * cond) -{ - pthread_cond_broadcast(cond); - - delete *cond; - *cond = 0; - - return 0; -} -// = -int pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) -{ - if (!*mutex || mutex[0]->front() != GUSIContext::CreateCurrent(true)) - return EPERM; // We don't hold that lock - mutex[0]->pop(); - if (GUSIContext * new_boss = mutex[0]->front()) - new_boss->Wakeup(); - if (!*cond) - pthread_cond_init(cond, NULL); - cond[0]->push(GUSIContext::Current()); - GUSIContext::Yield(kGUSIBlock); - if (*cond) - cond[0]->remove(GUSIContext::Current()); - return pthread_mutex_lock(mutex); -} -// = -int pthread_cond_timedwait( - pthread_cond_t * cond, - pthread_mutex_t * mutex, - const struct timespec * patience) -{ - GUSITimer timer; - if (!*mutex || mutex[0]->front() != GUSIContext::CreateCurrent(true)) - return EPERM; // We don't hold that lock - mutex[0]->pop(); - if (GUSIContext * new_boss = mutex[0]->front()) - new_boss->Wakeup(); - if (!*cond) - pthread_cond_init(cond, NULL); - cond[0]->push(GUSIContext::Current()); - GUSITime interval = GUSITime(*patience)-GUSITime::Now(); - GUSIContext::Current()->ClearWakeups(); - timer.MicroSleep(interval.Get(GUSITime::usecs)); - GUSIContext::Yield(kGUSIBlock); - if (*cond) - cond[0]->remove(GUSIContext::Current()); - int result = pthread_mutex_lock(mutex); - return timer.Expired() ? ETIMEDOUT : result; -} -// = -int pthread_cond_signal(pthread_cond_t * cond) -{ - if (!*cond) - return 0; - - if (GUSIContext * hey = cond[0]->front()) - hey->Wakeup(); - return 0; -} -// = -int pthread_cond_broadcast(pthread_cond_t * cond) -{ - if (!*cond) - return 0; - - cond[0]->Wakeup(); - - return 0; -} -// = -pthread_t pthread_self() -{ - return static_cast(GUSIContext::CreateCurrent(true)); -} -// = -int pthread_equal(pthread_t t1, pthread_t t2) -{ - return t1 == t2; -} -// = -int pthread_once(pthread_once_t * once_block, GUSIPThreadOnceProc proc) -{ - if (!*once_block) { - *once_block = 1; - proc(); - } - return 0; -} -// = -int sched_yield() -{ - GUSIContext::Yield(kGUSIYield); - - return 0; -} diff --git a/GUSI/src/tangled/GUSIPipe.cp b/GUSI/src/tangled/GUSIPipe.cp deleted file mode 100755 index a77b1c6..0000000 --- a/GUSI/src/tangled/GUSIPipe.cp +++ /dev/null @@ -1,214 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSIPipe.h" -#include "GUSIBasics.h" -#include "GUSIBuffer.h" - -#include - -// \section{Definition of [[GUSIPipeSocket]]} -// -// A [[GUSIPipeSocket]] is implemented with a simple [[GUSIBuffer]]. -// -// = -class GUSIPipeSocket : public GUSISocket { -public: - GUSIPipeSocket(); - virtual ~GUSIPipeSocket(); - // Currently we only implement the simple calls. - // - // = - virtual bool Supports(ConfigOption config); - // = - virtual ssize_t read(const GUSIScatterer & buffer); - // = - virtual ssize_t write(const GUSIGatherer & buffer); - // Of course, we also have [[select]]. [[canWrite]] will be sort of unsatisfactory, - // since it says nothing about the size of [[write]] possible. - // - // = - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - // Some similar functions are necessary for [[shutdown]]. - // - // = - virtual int shutdown(int how); - // Each [[GUSIPipeSocket]] has a peer which is set with [[SetPeer]]. - // - // = - void SetPeer(GUSIPipeSocket * peer); -protected: - // \section{Implementation of [[GUSIPipeSocket]]} - // - // - // = - GUSIRingBuffer fBuffer; - bool fWriteShutdown; - bool fBlocking; - GUSIPipeSocket * fPeer; - // = - void WakeupPeer(); - // Since there is currently no data, the simplest strategy won't work and - // we need something a bit more elaborate. - // - // = - bool Eof() { return !fPeer || fPeer->fWriteShutdown; } - // = - bool Shutdown() { return !fPeer || fWriteShutdown; } -}; -// We don't have much to do with peers except setting them and waking them up. -// -// = -inline void GUSIPipeSocket::SetPeer(GUSIPipeSocket * peer) { fPeer = peer; } -// \section{Implementation of [[GUSIPipeFactory]]} -// -// Normally, you use [[GUSIPipeFactory]] only via [[pipe]], in which case you don't -// need to initialize anything. If you want to use it via [[socketpair]], however, -// you need to call [[GUSIwithLocalSockets]] from your [[GUSISetupFactories]] routine. -// -// = -extern "C" void GUSIwithLocalSockets() -{ - GUSISocketDomainRegistry::Instance()->AddFactory(AF_LOCAL, GUSIPipeFactory::Instance()); -} -// = -GUSISocketFactory * GUSIPipeFactory::sInstance = nil; -// [[GUSIPipeFactory]] is odd in that [[socket]] is not meaningful. -// -// = -GUSISocket * GUSIPipeFactory::socket(int, int, int) -{ - return GUSISetPosixError(EOPNOTSUPP), static_cast(nil); -} -// [[socketpair]] is meaningful, however. -// -// = -int GUSIPipeFactory::socketpair(int, int, int, GUSISocket * s[2]) -{ - GUSIErrorSaver saveError; - GUSIPipeSocket * sock[2]; - - if (s[0] = sock[0] = new GUSIPipeSocket) - if (s[1] = sock[1] = new GUSIPipeSocket) { - sock[0]->SetPeer(sock[1]); - sock[1]->SetPeer(sock[0]); - - return 0; - } else - s[0]->close(); - - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} -// = -GUSIPipeSocket::GUSIPipeSocket() - : fBuffer(8192), fWriteShutdown(false), fBlocking(true), fPeer(nil) -{ -} -// = -void GUSIPipeSocket::WakeupPeer() -{ - if (fPeer) - fPeer->Wakeup(); -} -// = -bool GUSIPipeSocket::Supports(ConfigOption config) -{ - return config == kSimpleCalls; -} -// = -ssize_t GUSIPipeSocket::read(const GUSIScatterer & buffer) -{ - size_t len = buffer.Length(); - - if (!fBuffer.Valid()) { - // = - if (Eof()) - return 0; - if (!fBlocking) - return GUSISetPosixError(EWOULDBLOCK); - bool signal = false; - AddContext(); - do { - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - } while (!Eof() && !fBuffer.Valid()); - RemoveContext(); - if (signal) - return GUSISetPosixError(EINTR); - } - fBuffer.Consume(buffer, len); - WakeupPeer(); - - return (int) len; -} -// = -ssize_t GUSIPipeSocket::write(const GUSIGatherer & buffer) -{ - size_t buflen = buffer.Length(); - size_t len; - size_t offset = 0; - -restart: - if (Shutdown()) - return GUSISetPosixError(EPIPE); - if (fPeer->fBuffer.Free() < buflen) { - // This could get painful. We write a portion and then wait for free buffer space. - // - // = - if (!fBlocking && !fPeer->fBuffer.Free()) - return offset ? (int) offset : GUSISetPosixError(EWOULDBLOCK); - len = buflen; - fPeer->fBuffer.Produce(buffer, len, offset); - buflen -= len; - WakeupPeer(); - bool signal = false; - AddContext(); - while (!Shutdown() && !fPeer->fBuffer.Free()) { - if (signal = GUSIContext::Yield(kGUSIBlock)) - break; - } - RemoveContext(); - if (signal) - return offset ? (int) offset : GUSISetPosixError(EINTR); - goto restart; - } - fPeer->fBuffer.Produce(buffer, buflen, offset); - WakeupPeer(); - - return (size_t) buffer.Length(); -} -// = -bool GUSIPipeSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = Eof() || fBuffer.Valid()) - cond = true; - if (canWrite) - if (*canWrite = Shutdown() || fPeer->fBuffer.Free()) - cond = true; - - return cond; -} -// When we're destroyed, we sever the links to our peer. -// -// = -GUSIPipeSocket::~GUSIPipeSocket() -{ - if (fPeer) - fPeer->fPeer = nil; - WakeupPeer(); -} -// = -int GUSIPipeSocket::shutdown(int how) -{ - if (how) // write - fWriteShutdown = true; - if (!(how & 1)) // read - if (fPeer) - fPeer->fWriteShutdown = true; - - return 0; -} diff --git a/GUSI/src/tangled/GUSISIOUX.cp b/GUSI/src/tangled/GUSISIOUX.cp deleted file mode 100755 index 9044a7a..0000000 --- a/GUSI/src/tangled/GUSISIOUX.cp +++ /dev/null @@ -1,218 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSISIOUX.h" -#include "GUSIDevice.h" -#include "GUSIDescriptor.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" - -#include - -#include -#include -#include -#include -#include - -// \section{Definition of [[GUSISIOUXSocket]]} -// -// A [[GUSISIOUXSocket]] is another singleton class: There is only one SIOUX -// console per application. -// -// -// = -class GUSISIOUXSocket : public GUSISocket { -public: - ~GUSISIOUXSocket(); - - // Some member functions are fairly trivial wrappers. - // - // = - ssize_t read(const GUSIScatterer & buffer); - // = - ssize_t write(const GUSIGatherer & buffer); - // = - virtual int ioctl(unsigned int request, va_list arg); - // Since we know we're running on a pseudodevice, we can pass on that fact. - // - // = - virtual int fstat(struct stat * buf); - // And we also know we're a TTY. - // - // = - virtual int isatty(); - // [[select]] requires a walk of the event queue. - // - // = - bool select(bool * canRead, bool * canWrite, bool *); - - static GUSISIOUXSocket * Instance(); -private: - static GUSISIOUXSocket * sInstance; - - GUSISIOUXSocket(); -}; -// \section{Definition of [[GUSISIOUXDevice]]} -// -// A [[GUSISIOUXDevice]] is a singleton class supporting the standard [[open]] -// operation. -// -// = -class GUSISIOUXDevice : public GUSIDevice { -public: - static GUSISIOUXDevice * Instance(); - - // [[GUSISIOUXDevice]] is prepared to handle an [[open]] on a limited set of names. - // - // = - virtual bool Want(GUSIFileToken & file); - // [[open]] returns the sole instance of [[GUSISIOUXSocket]]. - // - // = - virtual GUSISocket * open(GUSIFileToken &, int flags); -private: - GUSISIOUXDevice() {} - - static GUSISIOUXDevice * sInstance; -}; -// \section{Implementation of [[GUSISIOUXSocket]]} -// -// A [[GUSISIOUXSocket]] is a dataless wrapper for the SIOUX -// library. To protect the sole instance from ever being deleted -// again, we artificially raise its reference count. -// -// = -GUSISIOUXSocket * GUSISIOUXSocket::sInstance; - -GUSISIOUXSocket * GUSISIOUXSocket::Instance() -{ - if (!sInstance) - if (sInstance = new GUSISIOUXSocket) - sInstance->AddReference(); - - return sInstance; -} -// On construction, we make sure to install the SIOUX event handler for all -// relevant elements. -// -// = -// This declaration lies about the return type -extern "C" void SIOUXHandleOneEvent(EventRecord *userevent); - -GUSISIOUXSocket::GUSISIOUXSocket() -{ - InstallConsole(0); - GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent); -} -GUSISIOUXSocket::~GUSISIOUXSocket() -{ - RemoveConsole(); -} -// = -ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer) -{ - GUSIStdioFlush(); - return buffer.SetLength( - ReadCharsFromConsole((char *) buffer.Buffer(), (int)buffer.Length())); -} -// = -ssize_t GUSISIOUXSocket::write(const GUSIGatherer & buffer) -{ - return WriteCharsToConsole((char *) buffer.Buffer(), (int)buffer.Length()); -} -// = -int GUSISIOUXSocket::ioctl(unsigned int request, va_list) -{ - switch (request) { - case FIOINTERACTIVE: - return 0; - default: - return GUSISetPosixError(EOPNOTSUPP); - } -} -// = -int GUSISIOUXSocket::fstat(struct stat * buf) -{ - GUSISocket::fstat(buf); - buf->st_mode = S_IFCHR | 0666; - - return 0; -} -// = -int GUSISIOUXSocket::isatty() -{ - return 1; -} -// = -static bool input_pending() -{ - QHdrPtr eventQueue = LMGetEventQueue(); - EvQElPtr element = (EvQElPtr)eventQueue->qHead; - - // now, count the number of pending keyDown events. - while (element != nil) { - if (element->evtQWhat == keyDown || element->evtQWhat == autoKey) - return true; - element = (EvQElPtr)element->qLink; - } - - return false; -} - -bool GUSISIOUXSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = input_pending()) - cond = true; - if (canWrite) - cond = *canWrite = true; - - return cond; -} -// \section{Implementation of [[GUSISIOUXDevice]]} -// -// [[GUSISIOUXDevice]] is a singleton class. -// -// = -GUSISIOUXDevice * GUSISIOUXDevice::sInstance; -// = -GUSISIOUXDevice * GUSISIOUXDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSISIOUXDevice(); - return sInstance; -} -// = -bool GUSISIOUXDevice::Want(GUSIFileToken & file) -{ - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - return file.IsDevice() && (file.StrStdStream(file.Path()) > -1); - default: - return false; - } -} -// = -GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int) -{ - return GUSISIOUXSocket::Instance(); -} -// A SIOUX application connects to the three standard descriptors on startup. -// -// = -void GUSISetupConsoleDescriptors() -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISIOUXSocket * SIOUX = GUSISIOUXSocket::Instance(); - - table->InstallSocket(SIOUX); - table->InstallSocket(SIOUX); - table->InstallSocket(SIOUX); -} diff --git a/GUSI/src/tangled/GUSISIOW.cp b/GUSI/src/tangled/GUSISIOW.cp deleted file mode 100755 index 3d36bd9..0000000 --- a/GUSI/src/tangled/GUSISIOW.cp +++ /dev/null @@ -1,75 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSISIOW.h" -#include "GUSIBasics.h" -#include "GUSIDescriptor.h" - -#include -#include - -extern "C" { -// The activate and suspend/resume handlers are very similar and both ultimately call -// [[_DoActivate]]. For reasons that I don't quite remember anymore, we are a bit more -// conservative about treating the current port than SIOW itself is. -// -// = -void _DoActivate(WindowPtr win, int activate); -// As a slight extra complication, not all OS events are suspend/resume events. -// -// = -void _DoIdle(); -// The update handler similarly calls [[_DoUpdate]]. -// -// = -void _DoUpdate(WindowPtr win); -} - -// = -static void GUSIDoActivate(WindowPtr win, bool activate) -{ - GrafPtr port; - GetPort(&port); - if (win) - SetPort(win); - _DoActivate(win, activate); - SetPort(port); -} - -static void GUSISIOWActivate(EventRecord * ev) -{ - GUSIDoActivate(reinterpret_cast(ev->message), ev->modifiers & activeFlag); -} -// = -static void GUSISIOWSusRes(EventRecord * ev) -{ - switch ((ev->message >> 24) & 0xFF) { - case suspendResumeMessage: - GUSIDoActivate(FrontWindow(), ev->message & resumeFlag); - break; - case mouseMovedMessage: - _DoIdle(); - break; - } -} -// = -static void GUSISIOWUpdate(EventRecord * ev) -{ - _DoUpdate((WindowPtr) ev->message); -} -// This is one of the rare occasions where overriding [[GUSIDefaultConsole]] makes sense. This way, we can -// reuse the MPW version of [[GUSISetupConsoleDescriptors]]. -// -// = -static void GUSISetupSIOW() -{ - GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)GUSISIOWUpdate); - GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)GUSISIOWActivate); - GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)GUSISIOWSusRes); -} - -void GUSIDefaultSetupConsole() -{ - GUSISetupConsoleDescriptors(); - GUSISetupSIOW(); - GUSISetupConsoleStdio(); -} diff --git a/GUSI/src/tangled/GUSISfio.cp b/GUSI/src/tangled/GUSISfio.cp deleted file mode 100755 index 47235de..0000000 --- a/GUSI/src/tangled/GUSISfio.cp +++ /dev/null @@ -1,71 +0,0 @@ -// = -#ifdef __MWERKS__ -#define __cstdio__ 1 -#else -#define __STDIO__ 1 -#endif - -#include "GUSIInternal.h" -#include -#include "GUSIBasics.h" -#include "GUSIDescriptor.h" - -// \section{Implementation of internal GUSI functions for Sfio} -// -// [[GUSISfioFlushClose]] was adapted from the Sfio internal [[_sfall]] function. -// -// = -static int GUSISfioFlushClose(bool close) -{ - reg Sfpool_t *p, *next; - reg Sfio_t* f; - reg int n, rv; - reg int nsync, count, loop; -#define MAXLOOP 3 - - for(loop = 0; loop < MAXLOOP; ++loop) - { rv = nsync = count = 0; - for(p = &_Sfpool; p; p = next) - { /* find the next legitimate pool */ - for(next = p->next; next; next = next->next) - if(next->n_sf > 0) - break; - - /* walk the streams for _Sfpool only */ - for(n = 0; n < ((p == &_Sfpool) ? p->n_sf : 1); ++n) - { count += 1; - f = p->sf[n]; - - if(f->flags&SF_STRING ) - goto did_sync; - if(SFFROZEN(f)) - continue; - if( (close ? sfclose(f) : sfsync(f)) < 0) - rv = -1; - - did_sync: - nsync += 1; - } - } - - if(nsync == count) - break; - } - return rv; -} - -void GUSIStdioClose() { GUSISfioFlushClose(true); } -void GUSIStdioFlush() { GUSISfioFlushClose(false); } -// Sfio already does everything to get started, no need for us to get in the act. -// -// = -void GUSISetupConsoleStdio() -{ -} -// We need to use the sfio function for string formatting, not the stdio version. -// -// = -int GUSI_vsprintf(char * s, const char * format, va_list args) -{ - return sfvsprintf(s, 4096, format, args); -} diff --git a/GUSI/src/tangled/GUSISignal.cp b/GUSI/src/tangled/GUSISignal.cp deleted file mode 100755 index af2ed71..0000000 --- a/GUSI/src/tangled/GUSISignal.cp +++ /dev/null @@ -1,594 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSISignal.h" -#include "GUSIDiag.h" -#include "GUSITimer.h" -#include "GUSIPThread.h" - -#include -#include -#include - -GUSI_USING_STD_NAMESPACE - -// = -GUSISigContext::GUSISigContext(const GUSISigContext * parent) - : fPending(0), fBlocked(parent ? parent->fBlocked : 0) -{ -} - -GUSISigContext::~GUSISigContext() -{ -} -// = -inline sigset_t SigMask(int signal) { return 1 << (signal-1); } - -sigset_t GUSISigContext::CantBlock() -{ - return SigMask(SIGKILL) - | SigMask(SIGSTOP) - | SigMask(SIGILL) - | SigMask(SIGFPE) - | SigMask(SIGSEGV); -} -// [[GetBlocked]] and [[SetBlocked]] take care of the rest. -// -// = -sigset_t GUSISigContext::GetBlocked() const -{ - return fBlocked; -} - -void GUSISigContext::SetBlocked(sigset_t sigs) -{ - fBlocked = sigs & ~CantBlock(); -} -// [[Pending]] and [[Post]] deal with signals pending against a thread (as a result of -// [[pthread_kill]]). -// -// = -sigset_t GUSISigContext::Pending() const -{ - return fPending; -} - -void GUSISigContext::ClearPending(sigset_t clear) -{ - fPending &= ~clear; -} - -void GUSISigContext::Post(int sig) -{ - sigaddset(&fPending, sig); -} -// [[Raise]] initiates a series of signal executions and returns [[true]] if any of these should -// interrupt a slow system call. -// -// = -sigset_t GUSISigContext::Pending(GUSISigProcess * proc) const -{ - return proc->Pending() | Pending(); -} - -sigset_t GUSISigContext::Ready(GUSISigProcess * proc) -{ - return Pending(proc) & ~GetBlocked(); -} - -bool GUSISigContext::Raise(GUSISigProcess * proc, bool allSigs) -{ - bool interrupt = false; - - for (;;) { - sigset_t todo = Ready(proc); - - if (!todo) - return interrupt; - - proc->ClearPending(todo); - ClearPending(todo); - - for (int sig = 1; todo; ++sig) - if (sigismember(&todo, sig)) { - sigdelset(&todo, sig); - interrupt = proc->Raise(sig, this) || interrupt || allSigs; - } - } -} -// = -GUSISigProcess::GUSISigProcess() - : fPending(0) -{ - memset(&fAction, 0, sizeof(fAction)); -} - -GUSISigProcess::~GUSISigProcess() -{ -} -// [[GetAction]] returns a signal action. -// -// = -struct sigaction & GUSISigProcess::GetAction(int sig) -{ - return fAction[sig-1]; -} -// = -bool GUSISigProcess::CantCatch(int sig) -{ - return (sig == SIGKILL) - || (sig == SIGSTOP); -} - -bool GUSISigProcess::CantIgnore(int sig) -{ - return (sig == SIGKILL) - || (sig == SIGSTOP); -} - -int GUSISigProcess::SetAction(int sig, const struct sigaction & act) -{ - if (act.sa_handler == SIG_IGN) { - if (CantIgnore(sig)) - return GUSISetPosixError(EINVAL); - sigdelset(&fPending, sig); - } else if (act.sa_handler != SIG_DFL) { - if (CantCatch(sig)) - return GUSISetPosixError(EINVAL); - } - fAction[sig-1] = act; - - return 0; -} -// [[Pending]] and [[Post]] deal with signals pending against a process (as a result of -// [[kill]] or [[raise]]). -// -// = -sigset_t GUSISigProcess::Pending() const -{ - return fPending; -} - -void GUSISigProcess::ClearPending(sigset_t clear) -{ - fPending &= ~clear; -} - -void GUSISigProcess::Post(int sig) -{ - sigaddset(&fPending, sig); - // To wake up contexts, we make two passes: In the first pass, we look for contexts which have the signal - // unblocked. If we don't find any, we wake up all contexts in the hope that one of them is waiting in a - // [[sigwait]]. This corresponds more or less to the typical nonthreaded and threaded models of thread - // handling, respectively. - // - // = - sigset_t sigmask = SigMask(sig); - bool found = false; - for (GUSIContextQueue::iterator context = GUSIContext::begin(); - context != GUSIContext::end(); - ++context - ) - if (!(context->SigContext()->GetBlocked() & sigmask)) { - context->Wakeup(); - found = true; - } - if (!found) - for (GUSIContextQueue::iterator context = GUSIContext::begin(); - context != GUSIContext::end(); - ++context - ) - context->Wakeup(); -} -// [[Raise]], finally, is the function for which the whole rest of the engine exists. -// -// = -bool GUSISigProcess::Raise(int sig, GUSISigContext * context) -{ - struct sigaction & act = GetAction(sig); - - if (act.sa_handler == SIG_IGN) - return false; // Ignore signal - else if (act.sa_handler == SIG_DFL) - return DefaultAction(sig, act) && !(act.sa_flags & SA_RESTART); - - // Executing an user defined signal handler involves a rather complicated dance of blocking and - // unblocking signals. - // - // = - __sig_handler handler = act.sa_handler; - sigset_t blockset= act.sa_mask; - - if (act.sa_flags & SA_RESETHAND) - act.sa_handler = SIG_DFL; - else if (!(act.sa_flags & SA_NODEFER)) - sigaddset(&blockset, sig); - - sigset_t blocksave = context->GetBlocked(); - context->SetBlocked(blocksave | blockset); - (*handler)(sig); - sigset_t blocknew = context->GetBlocked(); - context->SetBlocked(blocksave | (blocknew & ~blockset)); - - return !(act.sa_flags & SA_RESTART); -} -// = -extern "C" void _exit(int status); - -bool GUSISigProcess::DefaultAction(int sig, const struct sigaction &) -{ - switch (sig) { - case SIGCHLD: - case SIGCONT: - case SIGSTOP: - case SIGTSTP: - case SIGTTIN: - case SIGTTOU: - break; // Ignore - default: - _exit(1); - } - - return false; -} -// \section{Implementation of the signal handling engine} -// -// The [[GUSISigFactory]] is a straighforward overridable singleton. -// -// = -static auto_ptr sGUSISigFactory; - -GUSISigFactory * GUSISigFactory::Instance() -{ - if (!sGUSISigFactory.get()) - SetInstance(new GUSISigFactory); - - return sGUSISigFactory.get(); -} - -void GUSISigFactory::SetInstance(GUSISigFactory * instance) -{ - sGUSISigFactory = auto_ptr(instance); -} - -GUSISigFactory::~GUSISigFactory() -{ -} -// To support more signals, override these creators to make them return subclasses of the required -// classes. -// -// = -GUSISigProcess * GUSISigFactory::CreateSigProcess() -{ - return new GUSISigProcess; -} - -GUSISigContext * GUSISigFactory::CreateSigContext(const GUSISigContext * parent) -{ - return new GUSISigContext(parent); -} - -// First of all, we define out of line versions of the signal set manipulators, giving them the -// added benefit of a range check. -// -// = -int (sigaddset)(sigset_t *set, int signo) -{ - // \section{Definition of the signal handling POSIX functions} - // - // A considerable number of POSIX functions is concerned with signal handling. Many of them - // can profit from range checking on signal numbers. Additionally, we have to remap some of - // the signals. - // - // = - if (!GUSI_CASSERT_CLIENT(signo>0 && signo= - if (!GUSI_CASSERT_CLIENT(signo>0 && signo= - if (!GUSI_CASSERT_CLIENT(signo>0 && signo= -int raise(int signo) -{ - // \section{Definition of the signal handling POSIX functions} - // - // A considerable number of POSIX functions is concerned with signal handling. Many of them - // can profit from range checking on signal numbers. Additionally, we have to remap some of - // the signals. - // - // = - if (!GUSI_CASSERT_CLIENT(signo>0 && signoSigProcess()->Post(signo); - - return 0; -} -// [[pthread_kill]] posts a signal against the specified thread. -// -// = -int pthread_kill(pthread_t thread, int signo) -{ - if (!signo) - return thread ? 0 : ESRCH; - // = - if (!GUSI_CASSERT_CLIENT(signo>0 && signoSigContext()->Post(signo); - thread->Wakeup(); - - return 0; -} -// [[sigaction]] manipulates the signal action table. -// -// = -int sigaction(int signo, const struct sigaction * act, struct sigaction * oact) -{ - // \section{Definition of the signal handling POSIX functions} - // - // A considerable number of POSIX functions is concerned with signal handling. Many of them - // can profit from range checking on signal numbers. Additionally, we have to remap some of - // the signals. - // - // = - if (!GUSI_CASSERT_CLIENT(signo>0 && signoSigProcess(); - if (oact) - *oact = proc->GetAction(signo); - if (act) - if (proc->SetAction(signo, *act)) - return -1; - else if (act->sa_handler==SIG_IGN) - GUSIContext::CreateCurrent()->SigContext()->ClearPending(SigMask(signo)); - return 0; -} -// [[signal]] is the historical and rather inconvenient API for [[sigaction]]. -// -// = -__sig_handler signal(int signo, __sig_handler newhandler) -{ - struct sigaction oact; - struct sigaction nact; - - nact.sa_handler = newhandler; - nact.sa_mask = 0; - nact.sa_flags = SA_RESETHAND; - - if (sigaction(signo, &nact, &oact)) - return reinterpret_cast<__sig_handler>(0); - else - return oact.sa_handler; -} -// [[sigpending]] returns the list of pending signals. -// -// = -int sigpending(sigset_t * pending) -{ - if (pending) - *pending = GUSIProcess::Instance()->SigProcess()->Pending() - | GUSIContext::CreateCurrent()->SigContext()->Pending(); - return 0; -} -// [[pthread_sigmask]] and [[sigprocmask]] manipulate the signal mask. -// -// = -int pthread_sigmask(int how, const sigset_t * mask, sigset_t * omask) -{ - GUSISigContext * context = GUSIContext::CreateCurrent(true)->SigContext(); - if (omask) - *omask = context->GetBlocked(); - if (mask) - switch (how) { - case SIG_BLOCK: - context->SetBlocked(context->GetBlocked() | *mask); - break; - case SIG_SETMASK: - context->SetBlocked(*mask); - break; - case SIG_UNBLOCK: - context->SetBlocked(context->GetBlocked() & ~*mask); - break; - default: - return EINVAL; - } - GUSIContext::Raise(); - return 0; -} - -int sigprocmask(int how, const sigset_t * mask, sigset_t * omask) -{ - return GUSISetPosixError(pthread_sigmask(how, mask, omask)); -} -// [[sigsuspend]] waits for a signal to arrive. This is one of the few POSIX functions which always returns -// an error. -// -// = -int sigsuspend(const sigset_t * mask) -{ - GUSISigContext * context = GUSIContext::CreateCurrent()->SigContext(); - sigset_t blocksave = context->GetBlocked(); - context->SetBlocked(*mask); - GUSIContext::SigSuspend(); - sigset_t blocknew = context->GetBlocked(); - context->SetBlocked(blocksave | (blocknew & ~*mask)); - - return GUSISetPosixError(EINTR); -} -// [[pause]] is a simpler (and less useful) form of [[sigsuspend]]. -// -// = -int pause() -{ - GUSIContext::CreateCurrent()->SigSuspend(); - - return GUSISetPosixError(EINTR); -} -// [[sigwait]] waits for a blocked signal. -// -// = -int sigwait(const sigset_t * sigs, int * signo) -{ - if (!GUSI_CASSERT_CLIENT(sigs && signo && !(*sigs & ~GUSIContext::Blocked()))) - return GUSISetPosixError(EINVAL); - GUSIContext::SigWait(*sigs); - const sigset_t cursigs = *sigs & GUSIContext::Pending(); - for (*signo = 1; !sigismember(&cursigs, *signo); ++*signo) - ; - GUSIContext::CreateCurrent()->SigContext()->ClearPending(SigMask(*signo)); - GUSIProcess::Instance()->SigProcess()->ClearPending(SigMask(*signo)); - - return 0; -} -// [[abort]] raises [[SIGABRT]] and calls [[_exit]]. -// -// = -void abort(void) -{ - raise(SIGABRT); - - _exit(2); -} -// [[_exit]] is similar to [[exit]], but doesn't call handlers established with -// [[atexit]]. MPW already has a working implementation for [[_exit]]. -// -// = -#ifdef __MWERKS__ -extern int __aborting; - -extern "C" void _exit(int code) -{ - __aborting = 1; - - exit(code); -} -#endif -// To handle alarms, we define the auxiliary class [[GUSIAlarm]]. -// -// = -class GUSIAlarm : public GUSITimer { -public: - GUSIAlarm(long interval = 0) : GUSITimer(true), fInterval(interval) {} - - virtual void Wakeup(); - long Restart(long interval = 0); -private: - long fInterval; -}; - -void GUSIAlarm::Wakeup() -{ - GUSIProcess::Instance()->SigProcess()->Post(SIGALRM); - if (fInterval) - Sleep(fInterval, true); -} - -long GUSIAlarm::Restart(long interval) -{ - fInterval = interval; - RmvTime(Elem()); - long rest = tmCount; - if (rest < 0) - rest = -rest; - else - rest *= 1000; - tmCount = 0; - tmWakeUp = 0; - tmReserved = 0; - InsXTime(Elem()); - - return rest; -} - -static auto_ptr sGUSIAlarm; -// [[alarm]] raises a SIGALRM after a specified number of seconds has elapsed. -// -// = -unsigned int alarm(unsigned int delay) -{ - unsigned int togo = 0; - - GUSIAlarm * a = sGUSIAlarm.get(); - if (a) - togo = static_cast(a->Restart() / 1000000); - else - sGUSIAlarm = auto_ptr(a = new GUSIAlarm); - if (a && delay) - a->Sleep(delay*1000); - - return togo; -} -// [[ualarm]] provides a finer resolution and optionally offers the possibility to -// generate repeated signals. -// -// = -useconds_t ualarm(useconds_t delay, useconds_t interval) -{ - useconds_t togo = 0; - - GUSIAlarm * a = sGUSIAlarm.get(); - if (a) - togo = static_cast(a->Restart(static_cast(interval))); - else - sGUSIAlarm = auto_ptr(a = new GUSIAlarm(interval)); - if (a && delay) - a->MicroSleep(delay); - - return togo; -} diff --git a/GUSI/src/tangled/GUSISocket.cp b/GUSI/src/tangled/GUSISocket.cp deleted file mode 100755 index 137dff1..0000000 --- a/GUSI/src/tangled/GUSISocket.cp +++ /dev/null @@ -1,393 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSISocket.h" -#include "GUSIDiag.h" -#include "GUSIBuffer.h" - -#include -#include - -// \subsection{I/O Operations} -// -// As mentioned above, there are three variants of each call. If one of them -// is not implemented, the default implementation tries to emulate it with -// first another call. -// -// To simplify filling in a [[msghdr]], we provide an extension class with a -// convenient constructor. -// -// = -struct GUSImsghdr : public msghdr { - GUSImsghdr(const GUSIScattGath & buffer, const void * addr = nil, socklen_t addrlen = 0); -}; -// The constructor of [[GUSImsghdr]] translates a simple buffer into an [[iovec]]. -// -// = -GUSImsghdr::GUSImsghdr(const GUSIScattGath & buffer, const void * addr, socklen_t addrlen) -{ - msg_name = static_cast(const_cast(addr)); - msg_namelen = addrlen; - msg_iov = const_cast(buffer.IOVec()); - msg_iovlen = buffer.Count(); - msg_control = nil; - msg_controllen = 0; -} -// = -GUSISocket::GUSISocket() - : fRefCount(0), fQueue(0), fNextSocket(0), fPrevSocket(0) -{ - GUSIContext::Setup(false); -} - -bool GUSISocket::Supports(ConfigOption) -{ - return false; -} -// = -void GUSISocket::Enqueue(GUSISocket ** queue) -{ - GUSI_MESSAGE(("GUSISocket::Enqueue %08x\n", this)); - Dequeue(); - fQueue = queue; - fPrevSocket = 0; - fNextSocket = *queue; - *queue = this; - if (fNextSocket) - fNextSocket->fPrevSocket = this; -} - -void GUSISocket::Dequeue() -{ - if (!fQueue) - return; - GUSI_MESSAGE(("GUSISocket::Dequeue %08x\n", this)); - if (fPrevSocket) - fPrevSocket->fNextSocket = fNextSocket; - else - *fQueue = fNextSocket; - if (fNextSocket) - fNextSocket->fPrevSocket = fPrevSocket; -} -// The closing mechanism is quite intricate. [[close]] is typically overridden and -// eventually calls through to either this implementation, or to [[Enqueue]]. -// -// = -void GUSISocket::close() -{ - delete this; -} - -void GUSISocket::CheckClose(UInt32 now) -{ - GUSISocket * next = fNextSocket; - - Close(now); - if (next) - next->CheckClose(now); -} - -bool GUSISocket::Close(UInt32) -{ - delete this; - - return true; -} - -GUSISocket::~GUSISocket() -{ - Wakeup(); - Dequeue(); -} -// = -void GUSISocket::AddContext(GUSIContext * context) -{ - fContexts.push_front(context ? context : GUSIContext::Current()); -} - -void GUSISocket::RemoveContext(GUSIContext * context) -{ - fContexts.remove(context ? context : GUSIContext::Current()); -} -// = -int GUSISocket::bind(void *, socklen_t) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::getsockname(void *, socklen_t *) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::getpeername(void *, socklen_t *) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::listen(int) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::connect(void *, socklen_t) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::getsockopt(int, int, void *, socklen_t *) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::setsockopt(int, int, void *, socklen_t ) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::fcntl(int, va_list) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::ioctl(unsigned int, va_list) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::ftruncate(off_t) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -int GUSISocket::shutdown(int) - // \subsection{Operations without plausible default implementations} - // - // Many socket operations by default simply return [[EOPNOTSUPP]]. - // - // = - { - return GUSISetPosixError(EOPNOTSUPP); - } -// [[accept]] behaves similarly to the above, but returns a [[NULL]] pointer, -// not [[-1]]. -// -// = -GUSISocket * GUSISocket::accept(void *, socklen_t *) -{ - return GUSISetPosixError(EOPNOTSUPP), static_cast(nil); -} -// [[lseek]] should, according to the POSIX standard, return [[ESPIPE]] -// rather than [[EOPNOTSUPP]]. -// -// = -off_t GUSISocket::lseek(off_t, int) -{ - return GUSISetPosixError(ESPIPE), -1; -} -// [[fsync]] returns [[EINVAL]] as in BSD. -// -// = -int GUSISocket::fsync() -{ - return GUSISetPosixError(EINVAL); -} -// \subsection{Operations with plausible default implementations} -// -// By default, we assume that a socket is not a console. -// -// = -int GUSISocket::isatty() -{ - return 0; -} -// [[pre_select]] and [[post_select]] often don't have to do anything. By default, -// we assume that a socket can sleep. -// -// = -bool GUSISocket::pre_select(bool, bool, bool) -{ - AddContext(); - - return true; -} - -void GUSISocket::post_select(bool, bool, bool) -{ - RemoveContext(); -} -// [[select]] by default reports that nothing happens (although a socket like this -// is useless for inclusion in a [[select]] statement. -// -// = -bool GUSISocket::select(bool *, bool *, bool *) -{ - return false; -} -// [[read]] tries the more complex calls [[recvfrom]] and [[recvmsg]]. A socket -// family which supports none of the three calls must be very strange indeed. To -// keep implementors honest, an [[assert]] verifies that they don't claim support -// of a call variant and then dispatch to the default implementation anyway. -// -// = -ssize_t GUSISocket::read(const GUSIScatterer & buffer) -{ - GUSI_CASSERT_INTERNAL(!Supports(kSimpleCalls)); - - if (Supports(kSocketCalls)) { - socklen_t fromlen = 0; - - return recvfrom(buffer, 0, nil, &fromlen); - } else if (Supports(kMsgCalls)) { - GUSImsghdr msg(buffer); - - return recvmsg(&msg, 0); - } else - return GUSISetPosixError(EOPNOTSUPP); -} -// [[recvfrom]] can always be translated to [[recvmsg]] and sometimes to -// [[read]]. -// -// = -ssize_t GUSISocket::recvfrom( - const GUSIScatterer & buffer, int flags, void * from, socklen_t * fromlen) -{ - GUSI_CASSERT_INTERNAL(!Supports(kSocketCalls)); - - if (!flags && !from && Supports(kSimpleCalls)) - return read(buffer); - else if (Supports(kMsgCalls)) { - GUSImsghdr msg(buffer, from, *fromlen); - - int result = recvmsg(&msg, flags); - *fromlen = msg.msg_namelen; - - return result; - } else - return GUSISetPosixError(EOPNOTSUPP); -} -// [[recvmsg]] can always (in GUSI) be translated to [[recvfrom]] and sometimes -// to [[read]]. -// -// = -ssize_t GUSISocket::recvmsg(msghdr * msg, int flags) -{ - GUSI_CASSERT_INTERNAL(!Supports(kMsgCalls)); - - if (!flags && !msg->msg_name && Supports(kSimpleCalls)) { - GUSIScatterer scatter(msg->msg_iov, msg->msg_iovlen); - - return scatter.SetLength(read(scatter)); - } else if (Supports(kSocketCalls)) { - GUSIScatterer scatter(msg->msg_iov, msg->msg_iovlen); - - return scatter.SetLength( - recvfrom(scatter, flags, msg->msg_name, &msg->msg_namelen)); - } else - return GUSISetPosixError(EOPNOTSUPP); -} -// = -ssize_t GUSISocket::write(const GUSIGatherer & buffer) -{ - GUSI_CASSERT_INTERNAL(!Supports(kSimpleCalls)); - - if (Supports(kSocketCalls)) - return sendto(buffer, 0, nil, 0); - else if (Supports(kMsgCalls)) { - GUSImsghdr msg(buffer); - - return sendmsg(&msg, 0); - } else - return GUSISetPosixError(EOPNOTSUPP); -} -// = -ssize_t GUSISocket::sendto( - const GUSIGatherer & buffer, int flags, const void * to, socklen_t tolen) -{ - GUSI_CASSERT_INTERNAL(!Supports(kSocketCalls)); - - if (!flags && !to && Supports(kSimpleCalls)) - return write(buffer); - else if (Supports(kMsgCalls)) { - GUSImsghdr msg(buffer, to, tolen); - - return sendmsg(&msg, flags); - } else - return GUSISetPosixError(EOPNOTSUPP); -} -// = -ssize_t GUSISocket::sendmsg(const msghdr * msg, int flags) -{ - GUSI_CASSERT_INTERNAL(!Supports(kMsgCalls)); - - if (!flags && !msg->msg_name && Supports(kSimpleCalls)) { - GUSIGatherer gather(msg->msg_iov, msg->msg_iovlen); - - return write(gather); - } else if (Supports(kSocketCalls)) { - GUSIGatherer gather(msg->msg_iov, msg->msg_iovlen); - - return sendto(gather, flags, msg->msg_name, msg->msg_namelen); - } else - return GUSISetPosixError(EOPNOTSUPP); -} -// [[fstat]] actually has a quite reasonable default. -// -// = -int GUSISocket::fstat(struct stat * buf) -{ - buf->st_dev = 0; - buf->st_ino = 0; - buf->st_mode = S_IFSOCK | 0666 ; - buf->st_nlink = 1; - buf->st_uid = 0; - buf->st_gid = 0; - buf->st_rdev = 0; - buf->st_size = 1; - buf->st_atime = time(NULL); - buf->st_mtime = time(NULL); - buf->st_ctime = time(NULL); - buf->st_blksize = 1; - buf->st_blocks = 1; - - return 0; -} diff --git a/GUSI/src/tangled/GUSISocketMixins.cp b/GUSI/src/tangled/GUSISocketMixins.cp deleted file mode 100755 index ca608eb..0000000 --- a/GUSI/src/tangled/GUSISocketMixins.cp +++ /dev/null @@ -1,5 +0,0 @@ -// Almost all member functions are inline, so this file is mostly a placeholder. -// -// = -#include "GUSIInternal.h" -#include "GUSISocketMixins.h" diff --git a/GUSI/src/tangled/GUSISpecific.cp b/GUSI/src/tangled/GUSISpecific.cp deleted file mode 100755 index b73072b..0000000 --- a/GUSI/src/tangled/GUSISpecific.cp +++ /dev/null @@ -1,91 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSISpecific.h" -#include "GUSIContext.h" -#include "GUSIDiag.h" - -#include - -GUSI_USING_STD_NAMESPACE - -#include - -// \section{Implementation of Thread Specific Variables} -// -// [[GUSISpecific]] is trivial to implement, so we keep all of the members inline. -// -// = -unsigned GUSISpecific::sNextID = 0; -// = -GUSISpecificTable::~GUSISpecificTable() -{ - void * data; - - if (fValues) { - for (unsigned id = 0; id < fAlloc; ++id) - while ((data = fValues[0][id]) && sKeys[0][id]) { - fValues[0][id] = 0; - sKeys[0][id]->Destruct(data); - } - DisposeHandle((Handle)fValues); - } -} -// = -void GUSISpecificTable::SetSpecific(const GUSISpecific * key, void * value) -{ - if (!key) - return; - - if (key->fID >= fAlloc) { - unsigned newAlloc = (key->fID & ~7) + 8; - size_t allocSize = newAlloc*sizeof(void *); - - if (!fValues) - fValues = (void ***)NewHandle(allocSize); - else - SetHandleSize((Handle) fValues, allocSize); - - while (fAlloc < newAlloc) - fValues[0][fAlloc++] = nil; - } - fValues[0][key->fID] = value; -} -// = -void GUSISpecificTable::DeleteSpecific(const GUSISpecific * key) -{ - if (fValues && Valid(key)) { - void * data = fValues[0][key->fID]; - - if (data && sKeys[0][key->fID]) { - fValues[0][key->fID] = nil; - sKeys[0][key->fID]->Destruct(data); - } - } -} -// = -GUSISpecific *** GUSISpecificTable::sKeys = nil; -unsigned GUSISpecificTable::sKeyAlloc = 0; -// = -void GUSISpecificTable::Register(GUSISpecific * key) -{ - if (key->fID >= sKeyAlloc) { - unsigned newAlloc = (key->fID & ~7) + 8; - size_t allocSize = newAlloc*sizeof(GUSISpecific *); - - if (!sKeys) - sKeys = (GUSISpecific ***) NewHandle(allocSize); - else - SetHandleSize((Handle)sKeys, allocSize); - - while (sKeyAlloc < newAlloc) - sKeys[0][sKeyAlloc++] = nil; - } - sKeys[0][key->fID] = key; -} -// Note that this doesn't call any destructors. -// -// = -void GUSISpecificTable::Destruct(GUSISpecific * key) -{ - sKeys[0][key->fID] = nil; -} diff --git a/GUSI/src/tangled/GUSITimer.cp b/GUSI/src/tangled/GUSITimer.cp deleted file mode 100755 index df73b65..0000000 --- a/GUSI/src/tangled/GUSITimer.cp +++ /dev/null @@ -1,344 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSITimer.h" -#include "GUSIDiag.h" -#include "GUSIContext.h" - -#include - -// \section{Implementation of [[GUSITime]]} -// -// The constructors need various multiplicators. -// -// = -#if !TYPE_LONGLONG -GUSITime::GUSITime(int32_t val, Format format) -{ - Construct(S64Set(val), format); -} - -GUSITime::GUSITime(uint32_t val, Format format) -{ - Construct(S64SetU(val), format); -} -#endif - -void GUSITime::Construct(int64_t val, Format format) -{ - switch (format) { - case seconds: - fTime = S64Multiply(val, S64Set(1000000000)); - break; - case ticks: - fTime = S64Multiply(val, S64Set(16666667)); - break; - case msecs: - fTime = S64Multiply(val, S64Set(1000000)); - break; - case usecs: - fTime = S64Multiply(val, S64Set(1000)); - break; - case nsecs: - fTime = val; - break; - } -} -// The struct constructors are simple arithmetic. -// -// = -GUSITime::GUSITime(const timeval & tv) -{ - *this = GUSITime(tv.tv_sec, seconds) + GUSITime(tv.tv_usec, usecs); -} - -GUSITime::GUSITime(const timespec & ts) -{ - *this = GUSITime(ts.tv_sec, seconds) + GUSITime(ts.tv_nsec, nsecs); -} -// The basic get operation is the one returning an [[int64_t]]. -// -// = -int64_t GUSITime::Get64(Format format) -{ - switch (format) { - case seconds: - return S64Div(fTime, S64Set(1000000000)); - case ticks: - return S64Div(fTime, S64Set(16666667)); - case msecs: - return S64Div(fTime, S64Set(1000000)); - case usecs: - return S64Div(fTime, S64Set(1000)); - default: - case nsecs: - return fTime; - } -} -// The struct casts break down the value into seconds and a remainder. For some -// reason, S64Divide is not defined for native functions. -// -// = -time_t GUSITime::Deconstruct(int64_t & rem) -{ -#if TYPE_LONGLONG - rem = S64Mod(fTime, S64Set(1000000000)); - return static_cast(U32SetU(SInt64ToUInt64(S64Div(fTime, S64Set(1000000000))))); -#else - return static_cast(U32SetU(SInt64ToUInt64(S64Divide(fTime, S64Set(1000000000), &rem)))); -#endif -} - -GUSITime::operator timeval() -{ - timeval tv; - int64_t rem; - - tv.tv_sec = Deconstruct(rem); - tv.tv_usec = S32Set(S64Div(rem, S64Set(1000))); - - return tv; -} - -GUSITime::operator timespec() -{ - timespec ts; - int64_t rem; - - ts.tv_sec = Deconstruct(rem); - ts.tv_nsec = S32Set(rem); - - return ts; -} -// We construct a [[struct tm]] via [[LongSecondsToDate]]. -// -// = -GUSITime::operator tm() -{ - tm t; - LongDateRec ldr; - LongDateTime ldt; - - ldt = Get64(seconds); - LongSecondsToDate(&ldt, &ldr); - t.tm_sec = ldr.ld.second; - t.tm_min = ldr.ld.minute; - t.tm_hour = ldr.ld.hour; - t.tm_mday = ldr.ld.day; - t.tm_mon = ldr.ld.month-1; - t.tm_year = ldr.ld.year-1900; - t.tm_wday = ldr.ld.dayOfWeek-1; - t.tm_yday = ldr.ld.dayOfYear-1; - t.tm_isdst = -1; - - return t; -} -// Constructing a [[GUSITime]] from a [[struct tm]] is a bit trickier because -// field values are not guaranteed to be in range and [[LongDateToSeconds]] is -// not infinitely tolerant. -// -// = -GUSITime::GUSITime(const tm & t) -{ - LongDateRec ldr; - LongDateTime ldt; - - ldr.ld.era = 0; - ldr.ld.year = t.tm_year+1900; - ldr.ld.month = t.tm_mon+1; - ldr.ld.day = t.tm_mday ? t.tm_mday : 1; - ldr.ld.hour = t.tm_hour>=0 ? t.tm_hour : 0; - ldr.ld.minute = t.tm_min>=0 ? t.tm_min : 0; - ldr.ld.second = t.tm_sec>=0 ? t.tm_sec : 0; - - LongDateToSeconds(&ldr, &ldt); - if (!t.tm_mday) - ldt = S64Subtract(ldt, S64Set(86400)); - if (t.tm_hour < 0) - ldt = S64Add(ldt, S64Multiply(S64Set(t.tm_hour), S64Set(3600))); - if (t.tm_min < 0) - ldt = S64Add(ldt, S64Multiply(S64Set(t.tm_min), S64Set(60))); - if (t.tm_sec < 0) - ldt = S64Add(ldt, S64Set(t.tm_sec)); - - Construct(ldt, seconds); -} -// To calculate the current time, we need to combine [[GetDateTime]], which gives -// seconds since 1904, with [[Microseconds]], which gives microseconds since startup. -// -// = -int64_t GUSITime::sTimeOffset; -timezone GUSITime::sTimeZone; - -GUSITime GUSITime::Now() -{ - if (S64Not(sTimeOffset)) { - GUSITime s; - GUSITime zone; - GUSITime us; - - { - uint32_t secs; - GetDateTime(&secs); - s = GUSITime(secs, seconds); - } - { - UnsignedWide u; - Microseconds(&u); - us = GUSITime(UInt64ToSInt64(UnsignedWideToUInt64(u)), usecs); - } - { - MachineLocation loc; - ReadLocation(&loc); - int32_t delta = loc.u.gmtDelta & 0x00FFFFFF; - if (delta & 0x00800000) - delta |= 0xFF000000; - zone = GUSITime(delta, seconds); - sTimeZone.tz_minuteswest = zone.Get(seconds) / 60; - sTimeZone.tz_dsttime = (loc.u.gmtDelta & 0xFF000000) != 0; - } - s -= zone; - sTimeOffset = s - us; - - return s; - } else { - UnsignedWide us; - Microseconds(&us); - GUSITime t(UInt64ToSInt64(UnsignedWideToUInt64(us)), usecs); - - return S64Add(int64_t(t), sTimeOffset); - } -} -// The time zone is cached by [[Now]]. -// -// = -timezone & GUSITime::Zone() -{ - Now(); - return sTimeZone; -} - -GUSITime GUSITime::Local2GMTime() -{ - Now(); - - GUSITime zone(static_cast(60*sTimeZone.tz_minuteswest), seconds); - - return *this - zone; -} - -GUSITime GUSITime::GM2LocalTime() -{ - Now(); - - GUSITime zone(static_cast(60*sTimeZone.tz_minuteswest), seconds); - - return *this+zone; -} -// \section{Implementation of [[GUSITimer]]} -// -// [[GUSITimerProc]] wakes up the context. -// -// = -static void GUSITimerProc(TMTask * tm) -{ - GUSITimer * timer = static_cast(tm); - - GUSIProcess::A5Saver saveA5(timer->Context()); - - timer->Wakeup(); -} - -GUSI_COMPLETION_PROC_A1(GUSITimerProc, TMTask) -// The default wakeup action simply wakes up the associated context. -// -// = -void GUSITimer::Wakeup() -{ - Context()->Wakeup(); -} -// When a process terminates, all remaining timers get destroyed. -// -// = -GUSITimer::TimerQueue::~TimerQueue() -{ - GUSIContext::LiquidateAll(); -} - -void GUSIKillTimers(void * timers) -{ - GUSITimer::Queue * q = static_cast(timers); - - while (q->fTimer) - q->fTimer->Kill(); - - delete q; -} -// On constructing the first [[GUSITimer]] in a program, we initialize [[sTimerProc]]. -// -// = -TimerUPP GUSITimer::sTimerProc = (TimerUPP)0; -GUSITimer::TimerQueue GUSITimer::sTimerQueue; - -GUSITimer::GUSITimer(bool wakeup, GUSIContext * context) -{ - if (!context) - context = GUSIContext::CreateCurrent(); - if (wakeup) { - if (!sTimerProc) - sTimerProc = NewTimerProc(reinterpret_cast(GUSITimerProcEntry)); - tmAddr = sTimerProc; - } else - tmAddr = 0; - tmCount = 0; - tmWakeUp = 0; - tmReserved = 0; - InsXTime(Elem()); - fQueue = sTimerQueue.get(context); - fQueue->fContext = context; - fNext = fQueue->fTimer; - fQueue->fTimer = this; -} -// We support both normal timing and drift free timers. -// -// = -void GUSITimer::Sleep(long ms, bool driftFree) -{ - if (!driftFree) - tmWakeUp = 0; - PrimeTime(Elem(), ms); -} -// To reset the timer, we remove it and insert it again. -// -// = -void GUSITimer::Reset() -{ - RmvTime(Elem()); - InsXTime(Elem()); -} -// Upon destruction, we remove the time manager task. The [[fQueue]] element serves as a -// flag so we don't get killed twice. -// -// = -void GUSITimer::Kill() -{ - if (!fQueue) // We are dead already - return; - - RmvTime(Elem()); - GUSITimer ** queue = &fQueue->fTimer; - - while (*queue) - if (*queue == this) { - *queue = fNext; - - break; - } else - queue = &(*queue)->fNext; - fNext = 0; - fQueue = 0; -} - -GUSITimer::~GUSITimer() -{ - Kill(); -} diff --git a/GUSI/test/GUSIConfig_MTINET.cp b/GUSI/test/GUSIConfig_MTINET.cp deleted file mode 100755 index 03498f2..0000000 --- a/GUSI/test/GUSIConfig_MTINET.cp +++ /dev/null @@ -1,80 +0,0 @@ -/**************** BEGIN GUSI CONFIGURATION **************************** - * - * GUSI Configuration section generated by GUSI Configurator - * last modified: Wed Oct 25 23:18:04 2000 - * - * This section will be overwritten by the next run of Configurator. - */ - -#define GUSI_SOURCE -#include -#include - -/* Declarations of Socket Factories */ - -__BEGIN_DECLS -void GUSIwithInetSockets(); -void GUSIwithLocalSockets(); -void GUSIwithMTInetSockets(); -void GUSIwithMTTcpSockets(); -void GUSIwithMTUdpSockets(); -void GUSIwithOTInetSockets(); -void GUSIwithOTTcpSockets(); -void GUSIwithOTUdpSockets(); -void GUSIwithPPCSockets(); -void GUSISetupFactories(); -__END_DECLS - -/* Configure Socket Factories */ - -void GUSISetupFactories() -{ -#ifdef GUSISetupFactories_BeginHook - GUSISetupFactories_BeginHook -#endif - GUSIwithMTInetSockets(); - GUSIwithPPCSockets(); -#ifdef GUSISetupFactories_EndHook - GUSISetupFactories_EndHook -#endif -} - -/* Declarations of File Devices */ - -__BEGIN_DECLS -void GUSIwithDConSockets(); -void GUSIwithNullSockets(); -void GUSISetupDevices(); -__END_DECLS - -/* Configure File Devices */ - -void GUSISetupDevices() -{ -#ifdef GUSISetupDevices_BeginHook - GUSISetupDevices_BeginHook -#endif - GUSIwithNullSockets(); -#ifdef GUSISetupDevices_EndHook - GUSISetupDevices_EndHook -#endif -} - -#ifndef __cplusplus -#error GUSISetupConfig() needs to be written in C++ -#endif - -GUSIConfiguration::FileSuffix sSuffices[] = { - "", '????', '????' -}; - -extern "C" void GUSISetupConfig() -{ - GUSIConfiguration * config = - GUSIConfiguration::CreateInstance(GUSIConfiguration::kNoResource); - - config->ConfigureSuffices( - sizeof(sSuffices)/sizeof(GUSIConfiguration::FileSuffix)-1, sSuffices); -} - -/**************** END GUSI CONFIGURATION *************************/ diff --git a/GUSI/test/GUSIConfig_OTINET.cp b/GUSI/test/GUSIConfig_OTINET.cp deleted file mode 100755 index 71b4de1..0000000 --- a/GUSI/test/GUSIConfig_OTINET.cp +++ /dev/null @@ -1,79 +0,0 @@ -/**************** BEGIN GUSI CONFIGURATION **************************** - * - * GUSI Configuration section generated by GUSI Configurator - * last modified: Tue Jun 29 23:53:41 1999 - * - * This section will be overwritten by the next run of Configurator. - */ - -#define GUSI_SOURCE -#include -#include - -/* Declarations of Socket Factories */ - -__BEGIN_DECLS -void GUSIwithInetSockets(); -void GUSIwithLocalSockets(); -void GUSIwithMTInetSockets(); -void GUSIwithMTTcpSockets(); -void GUSIwithMTUdpSockets(); -void GUSIwithOTInetSockets(); -void GUSIwithOTTcpSockets(); -void GUSIwithOTUdpSockets(); -void GUSIwithPPCSockets(); -void GUSISetupFactories(); -__END_DECLS - -/* Configure Socket Factories */ - -void GUSISetupFactories() -{ -#ifdef GUSISetupFactories_BeginHook - GUSISetupFactories_BeginHook -#endif - GUSIwithOTInetSockets(); -#ifdef GUSISetupFactories_EndHook - GUSISetupFactories_EndHook -#endif -} - -/* Declarations of File Devices */ - -__BEGIN_DECLS -void GUSIwithDConSockets(); -void GUSIwithNullSockets(); -void GUSISetupDevices(); -__END_DECLS - -/* Configure File Devices */ - -void GUSISetupDevices() -{ -#ifdef GUSISetupDevices_BeginHook - GUSISetupDevices_BeginHook -#endif - GUSIwithNullSockets(); -#ifdef GUSISetupDevices_EndHook - GUSISetupDevices_EndHook -#endif -} - -#ifndef __cplusplus -#error GUSISetupConfig() needs to be written in C++ -#endif - -GUSIConfiguration::FileSuffix sSuffices[] = { - "", '????', '????' -}; - -extern "C" void GUSISetupConfig() -{ - GUSIConfiguration * config = - GUSIConfiguration::CreateInstance(GUSIConfiguration::kNoResource); - - config->ConfigureSuffices( - sizeof(sSuffices)/sizeof(GUSIConfiguration::FileSuffix)-1, sSuffices); -} - -/**************** END GUSI CONFIGURATION *************************/ diff --git a/GUSI/test/Makefile.mk b/GUSI/test/Makefile.mk deleted file mode 100755 index c77f630..0000000 Binary files a/GUSI/test/Makefile.mk and /dev/null differ diff --git a/GUSI/test/Makefile.nw b/GUSI/test/Makefile.nw deleted file mode 100755 index dbf2cb5..0000000 Binary files a/GUSI/test/Makefile.nw and /dev/null differ diff --git a/GUSI/test/TestDaytime.nw b/GUSI/test/TestDaytime.nw deleted file mode 100755 index 2f6ca8e..0000000 Binary files a/GUSI/test/TestDaytime.nw and /dev/null differ diff --git a/GUSI/test/TestDuplicate.nw b/GUSI/test/TestDuplicate.nw deleted file mode 100755 index ce1a717..0000000 Binary files a/GUSI/test/TestDuplicate.nw and /dev/null differ diff --git a/GUSI/test/TestFileSpecs.nw b/GUSI/test/TestFileSpecs.nw deleted file mode 100755 index 1557172..0000000 Binary files a/GUSI/test/TestFileSpecs.nw and /dev/null differ diff --git a/GUSI/test/TestHTGet.nw b/GUSI/test/TestHTGet.nw deleted file mode 100755 index 86723b0..0000000 Binary files a/GUSI/test/TestHTGet.nw and /dev/null differ diff --git a/GUSI/test/TestHttpD.nw b/GUSI/test/TestHttpD.nw deleted file mode 100755 index 1fddf97..0000000 Binary files a/GUSI/test/TestHttpD.nw and /dev/null differ diff --git a/GUSI/test/TestMPWFD.nw b/GUSI/test/TestMPWFD.nw deleted file mode 100755 index f5e4e60..0000000 Binary files a/GUSI/test/TestMPWFD.nw and /dev/null differ diff --git a/GUSI/test/TestMSLTee.nw b/GUSI/test/TestMSLTee.nw deleted file mode 100755 index 080fdf5..0000000 Binary files a/GUSI/test/TestMSLTee.nw and /dev/null differ diff --git a/GUSI/test/TestMTTcp.nw b/GUSI/test/TestMTTcp.nw deleted file mode 100755 index 2bceb85..0000000 Binary files a/GUSI/test/TestMTTcp.nw and /dev/null differ diff --git a/GUSI/test/TestMutex.nw b/GUSI/test/TestMutex.nw deleted file mode 100755 index a849b55..0000000 Binary files a/GUSI/test/TestMutex.nw and /dev/null differ diff --git a/GUSI/test/TestPipes.nw b/GUSI/test/TestPipes.nw deleted file mode 100755 index 7493a52..0000000 Binary files a/GUSI/test/TestPipes.nw and /dev/null differ diff --git a/GUSI/test/TestTimers.nw b/GUSI/test/TestTimers.nw deleted file mode 100755 index 5e59ce4..0000000 Binary files a/GUSI/test/TestTimers.nw and /dev/null differ diff --git a/GUSI/test/tangled/TestDaytime.cp b/GUSI/test/tangled/TestDaytime.cp deleted file mode 100755 index 2968230..0000000 --- a/GUSI/test/tangled/TestDaytime.cp +++ /dev/null @@ -1,106 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestDaytime.nw - Test files/UDP with a daytime -// % request -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.5 2000/05/23 07:26:10 neeri -// % Tweak tests -// % -// % Revision 1.4 1999/08/05 05:57:05 neeri -// % Getting ready for 2.0b7 -// % -// % Revision 1.3 1999/05/30 03:07:08 neeri -// % Added timeout since UDP packets can get lost -// % -// % Revision 1.2 1999/03/17 09:05:15 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.1 1998/10/25 11:57:41 neeri -// % Ready to release 2.0a3 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{A Daytime client} -// -// To test UDP, we send a daytime request. In blatant abuse of good programming -// practice, we simply assume that the request won't get lost. -// -// -// = -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// This program does no multithreading, so it just consists of a single loop. -// -//
= -void main(int, char ** argv) -{ - sockaddr_in addr; - addr.sin_family = AF_INET; - hostent * host = gethostbyname(argv[1]); - if (!host) { - cerr << "Host not found: " << h_errno << endl; - - exit(1); - } - memcpy(&addr.sin_addr, host->h_addr, sizeof(in_addr)); - servent * serv = getservbyname("daytime", "udp"); - addr.sin_port = serv ? serv->s_port : 13; - int daytime = socket(AF_INET, SOCK_DGRAM, 0); - - if (sendto(daytime, "hi", 2, 0, (struct sockaddr *)&addr, sizeof(addr)) < 0 ) { - cerr << "Error sending: " << errno << endl; - - exit(1); - } - - fd_set fd_daytime; - FD_ZERO(&fd_daytime); - FD_SET(daytime, &fd_daytime); - timeval tv; - tv.tv_sec = 10; - tv.tv_usec= 0; - - switch (select(32, &fd_daytime, NULL, NULL, &tv)) { - case -1: - cout << "Select Error: " << errno << endl; - - exit(1); - case 0: - cout << "Select Timed Out\n" << endl; - - exit(1); - } - - char buffer[120]; - - if (recv(daytime, buffer, 120, 0) < 0) { - cout << "Read Error: " << errno << endl; - - exit(1); - } else { - *strchr(buffer, '\012') = 0; - - cerr << buffer << endl; - } -} diff --git a/GUSI/test/tangled/TestDuplicate.cp b/GUSI/test/tangled/TestDuplicate.cp deleted file mode 100755 index bfa3f0a..0000000 --- a/GUSI/test/tangled/TestDuplicate.cp +++ /dev/null @@ -1,111 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestDuplicate.nw - Test files with a copy command -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.6 2001/01/17 08:56:10 neeri -// % Spin cursor, write diagnostics to file -// % -// % Revision 1.5 2000/10/16 04:15:27 neeri -// % Use s->close() instead of delete s -// % -// % Revision 1.4 1999/05/30 03:09:34 neeri -// % Added support for MPW compilers -// % -// % Revision 1.3 1999/03/17 09:05:15 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/08/01 21:32:14 neeri -// % About ready for 2.0a1 -// % -// % Revision 1.1 1998/01/25 21:02:53 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{A File Duplicator} -// -// To test file system socket correctness and performance, we try to -// duplicate a file. -// -// -// = -#define GUSI_SOURCE - -#include "GUSIDevice.h" -#include "GUSISocket.h" -#include "GUSIDiag.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -// This program does no multithreading, so it just consists of a single loop. -// -//
= -void main(int, char ** argv) -{ - GUSI_diag_log = "TestDuplicate"; - - long bigbuf = argv[3]?atol(argv[3]):0; - - GUSISocket * src = - GUSIDeviceRegistry::Instance()->open(argv[1], O_RDONLY); - if (!src) { - cerr << "Error opening source file: " << errno << endl; - - exit(1); - } - if (bigbuf && src->setsockopt(SOL_SOCKET, SO_RCVBUF, &bigbuf, sizeof(long)) < 0) - cerr << "setsockopt(src) returned error: " << errno << endl; - GUSISocket * dst = - GUSIDeviceRegistry::Instance()->open(argv[2], O_WRONLY|O_CREAT|O_TRUNC); - if (!dst) { - cerr << "Error opening destination file: " << errno << endl; - - goto killS; - } - if (bigbuf && dst->setsockopt(SOL_SOCKET, SO_SNDBUF, &bigbuf, sizeof(long)) < 0) - cerr << "setsockopt(dst) returned error: " << errno << endl; - - bigbuf = bigbuf ? (bigbuf >> 1) : 4096; - - { - long total = 0; - int len; - char * buffer = new char[bigbuf]; - while (len = src->read(buffer, bigbuf)) { - if (len < 0) { - cout << "Read Error: " << errno << "\n"; - - break; - } - if (dst->write(buffer, len) < 0) { - cout << "Write Error: " << errno << "\n"; - - break; - } - total += len; - SpinCursor(1); - } - cout << "Total read: " << (unsigned long)total << endl; - } - - dst->close(); -killS: - src->close(); - - exit(0); -} diff --git a/GUSI/test/tangled/TestFileSpecs.cp b/GUSI/test/tangled/TestFileSpecs.cp deleted file mode 100755 index 610d573..0000000 --- a/GUSI/test/tangled/TestFileSpecs.cp +++ /dev/null @@ -1,58 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestFileSpecs.nw - Test the GUSIFileSpec class -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.1 1998/01/25 21:02:53 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{Testing the [[GUSIFileSpec]] class} -// -// This is a test program for the [[GUSIFileSpec]] class. -// -// -// = -#define GUSI_SOURCE - -#include "GUSIFileSpec.h" - -#include -#include -#include - -// = -void PrintFileSpec(ostream & s, const GUSIFileSpec & spec) -{ - s << spec->vRefNum << " " << spec->parID << " "; - s.write(reinterpret_cast(spec->name+1), *spec->name); - s << endl; -} -// Currently, we only list the ":" directory. -// -//
= -void main() -{ - GUSIFileSpec dir(":"); - if (dir.Error()) { - cout << "Error constructing: " << dir.Error() << endl; - exit(1); - } - PrintFileSpec(cout, dir); - ++dir; - if (dir.Error()) { - cout << "Error descending: " << dir.Error() << endl; - exit(1); - } - PrintFileSpec(cout, dir); - for (short i = 1; !!dir[i]; ++i) - PrintFileSpec(cout, dir); -} diff --git a/GUSI/test/tangled/TestHTGet.cp b/GUSI/test/tangled/TestHTGet.cp deleted file mode 100755 index c009bc6..0000000 --- a/GUSI/test/tangled/TestHTGet.cp +++ /dev/null @@ -1,151 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestHTGet.nw - Test files/TCP with a HTTP Get -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/07 09:51:19 chombier -// % First Imported. -// % -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.6 2001/01/22 04:30:13 neeri -// % Fix if no output file is specified -// % -// % Revision 1.5 2000/10/16 04:15:27 neeri -// % Use s->close() instead of delete s -// % -// % Revision 1.4 1999/05/30 03:09:34 neeri -// % Added support for MPW compilers -// % -// % Revision 1.3 1999/03/17 09:05:16 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.2 1998/10/11 16:45:27 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.1 1998/01/25 21:02:54 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{A HTTP retriever} -// -// To test TCP and file system correctness and performance, we try to -// write a HTTP page into a file. -// -// -// = -#define GUSI_SOURCE -#define GUSI_INTERNAL - -#include "GUSIFactory.h" -#include "GUSINetDB.h" -#include "GUSIMTNetDB.h" -#include "GUSIMacFile.h" -#include "GUSIDiag.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// This program does no multithreading, so it just consists of a single loop. -// -//
= -void MyIoctl(GUSISocket * s, unsigned long request, ...) -{ - va_list arglist; - va_start(arglist, request); - s->ioctl(request, arglist); - va_end(arglist); -} - -void main(int, char ** argv) -{ - int val; - GUSISocket * f; - GUSISocket * s; - - GUSIMTNetDB::Instantiate(); - - sockaddr_in addr; - addr.sin_family = AF_INET; - hostent * host = GUSINetDB::Instance()->gethostbyname(argv[1]); - if (!host) { - cerr << "Host not found: " << h_errno << endl; - - exit(1); - } - memcpy(&addr.sin_addr, host->h_addr, sizeof(in_addr)); - servent * serv = GUSINetDB::Instance()->getservbyname("http", "tcp"); - addr.sin_port = serv ? serv->s_port : 80; - s = - GUSISocketDomainRegistry::Instance()->socket(AF_INET, SOCK_STREAM, 0); - - val = 1; - s->setsockopt(SOL_SOCKET, SO_KEEPALIVE, (char *)&val, sizeof(u_long)); - s->setsockopt(IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(u_long)); - MyIoctl(s, FIONBIO, &val); - - if (s->connect(&addr, sizeof(addr)) && errno!=EINPROGRESS) { - cerr << "Error connecting: " << errno << endl; - - goto killS; - } - { - bool w; - long ticks = TickCount(); - while (!s->select(nil, &w, nil)) - ; - ticks = TickCount() - ticks; - cerr << "Waiting for " << ticks << " ticks." << endl; - } - val = 0; - MyIoctl(s, FIONBIO, &val); - - s->write("GET ", 4); - s->write(argv[2], strlen(argv[2])); - s->write("\015\012\015\012", 4); - - if (argv[3]) { - if (!(f = GUSIDeviceRegistry::Instance()->open(argv[3], O_WRONLY|O_CREAT|O_TRUNC))) { - cerr << "Error opening file: " << errno << endl; - - goto killS; - } - } else - f = 0; - - int len; - char buffer[8000]; - while (len = s->read(buffer, 8000)) { - if (len < 0) { - cout << "Read Error: " << errno << "\n"; - - break; - } - if (f && f->write(buffer, len) < 0) { - cout << "Write Error: " << errno << "\n"; - - break; - } - } - -killF: - if (f) - f->close(); -killS: - s->close(); - - exit(0); -} diff --git a/GUSI/test/tangled/TestHttpD.cp b/GUSI/test/tangled/TestHttpD.cp deleted file mode 100755 index 19b7265..0000000 --- a/GUSI/test/tangled/TestHttpD.cp +++ /dev/null @@ -1,256 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestHttpD.nw - A primitive HTTP daemon -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.5 1999/06/08 04:31:32 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.4 1999/03/17 09:05:16 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.3 1998/10/25 11:57:42 neeri -// % Ready to release 2.0a3 -// % -// % Revision 1.2 1998/10/11 16:45:28 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.1 1998/08/01 21:32:14 neeri -// % About ready for 2.0a1 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{A primitive HTTP daemon} -// -// This program implements an extremely primitive HTTP daemon. -// -// -// = -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -// The daemon runs until something is written to [[gDone]] and [[gPending]] is 0. -// -// = -int gDone = 0; -int gPending = 0; -pthread_mutex_t gPendingMutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t gPendingCond = PTHREAD_COND_INITIALIZER; -// All our replies use the same header -// -// = -const char * gReplyHeader = - "HTTP/1.0 200 OK\015\012" - "Content-Type: text/plain\015\012\015\012"; -const char * gErrorHeader = - "HTTP/1.0 404 Not Found\015\012" - "Content-Type: text/plain\015\012\015\012"; -// = -void HandleCGI(int socket, char * request) -{ - if (!strcmp(request, "quit")) { - write(socket, gReplyHeader, strlen(gReplyHeader)); - write(socket, "So long.", 8); - pthread_mutex_lock(&gPendingMutex); - write(gDone, "Game Over", 9); - pthread_mutex_unlock(&gPendingMutex); - } else if (!strcmp(request, "slow")) { - write(socket, gReplyHeader, strlen(gReplyHeader)); - for (int i = 0; i<120; ++i) { - char buf[20]; - sprintf(buf, "%d\015\012", i); - write(socket, buf, strlen(buf)); - sleep(1); - } - } -} -// = -void HandleFile(int socket, char * request) -{ - for (char * slash = request; slash = strchr(slash, '/'); ) - *slash = ':'; - FILE * file = fopen(request, "r"); - FILE * sock = fdopen(socket, "w"); - - if (file) { - fputs(gReplyHeader, sock); - // = - int ch; - - while ((ch = fgetc(file)) != EOF) { - fputc(ch, sock); - if (ch == '\015') { - fputc('\012', sock); - if (ferror(sock)) - break; - } - } - } else { - fputs(gErrorHeader, sock); - // = - fputs("Yo! That URL is busted!\015\012", sock); - } - fclose(file); - fclose(sock); -} -// = -extern "C" void * Handler(void * s) -{ - char buffer[1000]; - int size = 999; - char * request; - - int socket = reinterpret_cast(s); - int sz; - bool foundEnd = false; - - for (request = buffer; !foundEnd && (sz = read(socket, request, size)) > 0; ) { - // = - char * in = request; - char * out= request; - bool nl = false; - while (sz--) { - switch (*in) { - case 0x0A: - if (out != request && out[-1] == 0x0D) - break; // Skip - *in = 0x0D; - // Fall through - case 0x0D: - if (nl) { - foundEnd = true; - sz = 0; - } - // Fall through - default: - nl = (*out++ = *in) == 0x0D; - } - ++in; - } - sz = out-request; - request += sz; - size -= sz; - } - - // The technique employed here should definitely not be confused with a real - // WWW server. All we're interested here is demonstrating the I/O library. - // - // = - for (request = strchr(buffer, ' '); isspace(*++request); ) - ; - *strchr(request, ' ') = 0; - // We handle a few special URLs, the rest is translated as files. - // - // = - if (!strncmp(request, "/cgi/", 5)) - HandleCGI(socket, request+5); - else - HandleFile(socket, request); - close(socket); - - pthread_mutex_lock(&gPendingMutex); - --gPending; - pthread_cond_signal(&gPendingCond); - pthread_mutex_unlock(&gPendingMutex); - - return 0; -} -//
= -extern char * GUSI_diag_log; - -void main() -{ - GUSI_diag_log = "TestHTTPd"; - // First we create a listener on port 80. - // - // = - sockaddr_in addr; - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr= 0; - addr.sin_port = 80; - - int listener = socket(AF_INET, SOCK_STREAM, 0); - - bind(listener, (sockaddr *)&addr, sizeof(addr)); - listen(listener, 5); - // To make it possible to wait on either a socket connection or a quit event, we - // transmit the latter on a pipe. Cool, isn't it? - // - // = - int done[2]; - pipe(done); - gDone = done[1]; - // The main event loop is a rather vanilla [[select]] based loop. - // - // = - fd_set fd_interesting; - FD_ZERO(&fd_interesting); - FD_SET(done[0], &fd_interesting); - FD_SET(listener, &fd_interesting); - - for (;;) { - fd_set fd = fd_interesting; - - if (select(32, &fd, NULL, NULL, NULL)) { - if (FD_ISSET(listener, &fd)) { - // Each incoming connection is immediately delegated to a new thread. - // - // = - int client = accept(listener, NULL, NULL); - pthread_t thread; - - pthread_create(&thread, 0, Handler, (void *)client); - pthread_detach(thread); - - pthread_mutex_lock(&gPendingMutex); - ++gPending; - pthread_mutex_unlock(&gPendingMutex); - // Looking up the IP number is quite slow, so we only do that after starting the - // thread. - // - // = - sockaddr_in peer; - socklen_t len = sizeof(sockaddr_in); - - if (getpeername(client, (sockaddr *)&peer, &len)) { - cerr << "getpeername failed: " << h_errno << endl; - } else { - hostent * host = gethostbyaddr(&peer.sin_addr, sizeof(in_addr), AF_INET); - if (host) - GUSI_MESSAGE(("Connection from %s [%s]\n", host->h_name, inet_ntoa(peer.sin_addr))); - else - GUSI_MESSAGE(("Connection from %s\n", inet_ntoa(peer.sin_addr))); - } - } - if (FD_ISSET(done[0], &fd)) - break; - } - } - // Finally, we wait for [[gPending]] to reach zero again, at which point all - // clients will have completed. - // - // = - pthread_mutex_lock(&gPendingMutex); - while (gPending) - pthread_cond_wait(&gPendingCond, &gPendingMutex); - pthread_mutex_unlock(&gPendingMutex); -} diff --git a/GUSI/test/tangled/TestMPWFD.cp b/GUSI/test/tangled/TestMPWFD.cp deleted file mode 100755 index eac7067..0000000 --- a/GUSI/test/tangled/TestMPWFD.cp +++ /dev/null @@ -1,41 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestMPWFD.nw - Test file descriptors with MPW. -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.3 1999/07/19 06:25:14 neeri -// % Getting ready for 2.0b4 -// % -// % Revision 1.2 1999/05/30 03:09:35 neeri -// % Added support for MPW compilers -// % -// % Revision 1.1 1998/08/01 21:32:15 neeri -// % About ready for 2.0a1 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{Testing standard MPW descriptors} -// -// Now we test the standard MPW file descriptors. -// -// = -#include -#include -#include - -//
= -void main(int, char ** argv) -{ - write(1, "Hello, world!\n", 14); - write(2, "Errare humanum est.\n", 20); - - int fd = open("TestMPWFD.out", O_WRONLY|O_CREAT); - write(fd, "See me roar.\n", 13); -} diff --git a/GUSI/test/tangled/TestMSLTee.cp b/GUSI/test/tangled/TestMSLTee.cp deleted file mode 100755 index faeb725..0000000 --- a/GUSI/test/tangled/TestMSLTee.cp +++ /dev/null @@ -1,47 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestMPWFD.nw - Test file descriptors with MPW. -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.2 1999/06/08 04:31:32 neeri -// % Getting ready for 2.0b2 -// % -// % Revision 1.1 1998/08/01 21:32:16 neeri -// % About ready for 2.0a1 -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{Testing MSL based stdio} -// -// Now we test interaction with the MSL stdio library. -// -// = -#include -#include - -//
= -void main(int, char ** argv) -{ - char line[1000]; - FILE * copies[20]; - int copycount = 0; - - while (*++argv) - if (copies[copycount] = fopen(*argv, "w")) - ++copycount; - else - fprintf(stderr, "Couldn't open `%s'\n", *argv); - - while (fgets(line, 1000, stdin)) { - fputs(line, stdout); - for (int i = 0; iclose() instead of delete s -// % -// % Revision 1.8 2000/03/15 07:08:58 neeri -// % New yield model -// % -// % Revision 1.7 1999/08/02 07:03:55 neeri -// % Getting ready for 2.0b6 -// % -// % Revision 1.6 1999/05/30 03:09:35 neeri -// % Added support for MPW compilers -// % -// % Revision 1.5 1999/03/17 09:05:16 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.4 1998/10/11 16:45:28 neeri -// % Ready to release 2.0a2 -// % -// % Revision 1.3 1998/01/25 20:54:00 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.2 1996/12/22 19:57:59 neeri -// % TCP streams work -// % -// % Revision 1.1 1996/12/16 02:12:43 neeri -// % TCP Sockets sort of work -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{Testing the [[GUSIMTTcpSocket]] class} -// -// This is a test program for the [[GUSIMTTcpSocket]] class. Because we lack -// a lot of infrastructure right now, we'll just connect to a hardcoded echo -// port. -// -// -// = -#define GUSI_SOURCE -#define GUSI_INTERNAL - -#include "GUSIMTTcp.h" -#include "GUSIDiag.h" - -#include -#include -#include -#include -#include - -// And so are the producer and consumer threads. -// -// = -pascal void * ProducerThread(void * s) -{ - char buffer[8000]; - GUSISocket * sock = (GUSISocket *) s; - unsigned long written = 0; - int len; - - while (len = read(0, buffer, 8000)) { - if (sock->write(buffer, len) < 0) { - cout << "Write Error: " << errno << "\n"; - - break; - } - written += len; - cout << "Written " << written << " " << TickCount() << "\n"; - } - sock->shutdown(1); - - return (void *) 1; -} -pascal void * ConsumerThread(void * s) -{ - char buffer[9000]; - GUSISocket * sock = (GUSISocket *) s; - unsigned long read = 0; - int len; - - while (len = sock->read(buffer, 9000)) { - if (len < 0) { - cout << "Read Error: " << errno << "\n"; - - break; - } - cout << "Read " << (read += len) << " " << TickCount() << "\n"; - } - - return (void *) 1; -} -pascal void * ListenerThread(void * s) -{ - GUSISocket * sock = (GUSISocket *) s; - GUSISocket * client; - sockaddr_in addr; - socklen_t len = sizeof(addr); - - if (client = sock->accept(&addr, &len)) { - cout << "Accepted " - << hex << addr.sin_addr.s_addr << dec - << ":" << addr.sin_port << " "<< TickCount() << "\n"; - - client->close(); - } - return (void *) 1; -} -// The main program is quite simple. -// -//
= -void main() -{ - GUSISocket * s; - GUSISocket * l; - sockaddr_in addr; - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr= 0x7F000001; // localhost - addr.sin_port = 7; // Echo port - s = - GUSIMTTcpFactory::Instance()->socket(AF_INET, SOCK_STREAM, 0); - - if (s->connect(&addr, sizeof(addr))) { - cerr << "Error connecting: " << errno << endl; - cerr << "You should run MacTCPWatcher during this test" << endl; - - goto killS; - } - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr= 0; - addr.sin_port = 7000; - l = - GUSIMTTcpFactory::Instance()->socket(AF_INET, SOCK_STREAM, 0); - - if (l->bind(&addr, sizeof(addr))) { - cerr << "Error binding: " << errno << endl; - - goto killL; - } - if (l->listen(5)) { - cerr << "Error listening: " << errno << endl; - - goto killL; - } - - { - ThreadID producer; - ThreadID consumer; - ThreadID listener; - void * producerDone = 0; - void * consumerDone = 0; - void * listenerDone = 0; - - GUSINewThread(kCooperativeThread, ProducerThread, (void *) s, 50000, kCreateIfNeeded, &producerDone, &producer); - GUSINewThread(kCooperativeThread, ConsumerThread, (void *) s, 50000, kCreateIfNeeded, &consumerDone, &consumer); - GUSINewThread(kCooperativeThread, ListenerThread, (void *) l, 50000, kCreateIfNeeded, &listenerDone, &listener); - - while (!producerDone || !consumerDone || !listenerDone) { - cout << "Main Yielding " << TickCount() << "\n"; - GUSIContext::Yield(kGUSIPoll); - cout << "Main Back " << TickCount() << "\n"; - } - cout << flush; - } - -killL: - l->close(); -killS: - s->close(); -} diff --git a/GUSI/test/tangled/TestMutex.cp b/GUSI/test/tangled/TestMutex.cp deleted file mode 100755 index 2e8439c..0000000 --- a/GUSI/test/tangled/TestMutex.cp +++ /dev/null @@ -1,132 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestMutex.nw - Test pthreads mutex facilities -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.5 2000/05/23 07:26:10 neeri -// % Tweak tests -// % -// % Revision 1.4 1999/08/02 07:03:55 neeri -// % Getting ready for 2.0b6 -// % -// % Revision 1.3 1999/05/30 03:09:35 neeri -// % Added support for MPW compilers -// % -// % Revision 1.2 1999/03/17 09:05:16 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.1 1998/01/25 21:02:55 neeri -// % Engine implemented, except for signals & scheduling -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{Testing the Pthreads Mutex Facilities} -// -// This program tests mutexes and condition variables. -// -// -// = -#include - -#include -#include -#include -#include -#include -#include -#include - -// We test a mutex and one condition variable. To pretend they make sense, -// we add a global, too. -// -// = -pthread_mutex_t market = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t apple = PTHREAD_COND_INITIALIZER; - -int gApples = 20; -// And so are the piggies and the big bad wolf. -// -// = -extern "C" void * GoToMarket(void * s) -{ - int apples = 0; - - for (int leave = 0; !leave;) { - usleep((rand() % 20) * 10000); - cout << TickCount() << ": Piggie " << (int)s << " goes to market\n"; - pthread_mutex_lock(&market); - cout << TickCount() << ": Piggie " << (int)s << " in market\n"; - if (!(gApples % 7)) { - cout << TickCount() << ": Piggie " << (int)s << " wakes up wolves\n"; - pthread_cond_broadcast(&apple); - } - if (gApples) { - ++apples; - --gApples; - cout << TickCount() << ": Piggie " << (int)s << " got an apple\n"; - } else { - cout << TickCount() << ": Piggie " << (int)s << " got no apple\n"; - leave = 1; - } - cout << TickCount() << ": Piggie " << (int)s << " leaves market.\n"; - pthread_mutex_unlock(&market); - } - cout << TickCount() << ": Piggie " << (int)s << " quits with " - << apples << " apples\n"; - - return 0; -} - -extern "C" void * HuffAndPuff(void * s) -{ - for (int leave = 0; !leave;) { - usleep((rand() % 5) * 10000); - cout << TickCount() << ": Wolf " << (int)s << " starts huffing\n"; - pthread_mutex_lock(&market); - cout << TickCount() << ": Wolf " << (int)s << " starts puffing\n"; - pthread_cond_wait(&apple, &market); - cout << TickCount() << ": Wolf " << (int)s << " stops huffing and puffing with " - << gApples << " apples left\n"; - leave = !gApples; - pthread_mutex_unlock(&market); - } - - return 0; -} -// The main program is quite simple. -// -//
= -void main() -{ - pthread_t piggie1; - pthread_t piggie2; - pthread_t piggie3; - pthread_t wolf1; - pthread_t wolf2; - void * whocares; - - srand(time(NULL)); - - pthread_create(&piggie1, 0, GoToMarket, (void *)1); - pthread_create(&piggie2, 0, GoToMarket, (void *)2); - pthread_create(&piggie3, 0, GoToMarket, (void *)3); - pthread_create(&wolf1, 0, HuffAndPuff, (void *)1); - pthread_create(&wolf2, 0, HuffAndPuff, (void *)2); - - pthread_join(piggie1, &whocares); - pthread_join(piggie2, &whocares); - pthread_join(piggie3, &whocares); - - pthread_cond_broadcast(&apple); - pthread_join(wolf1, &whocares); - pthread_join(wolf2, &whocares); - - cout <= -#define GUSI_SOURCE - -#include "GUSISocket.h" - -#define GUSI_INTERNAL - -#include "GUSIPipe.h" - -#include -#include -#include - -// And so are the producer and consumer threads. -// -// = -pascal void * ProducerThread(void * s) -{ - char buffer[200]; - GUSISocket * sock = (GUSISocket *) s; - unsigned long written = 0; - - while (cin.getline(buffer, 200)) { - int len = strlen(buffer); - if (sock->write(buffer, len) < 0) { - cout << "Write Error: " << errno << "\n"; - - break; - } - cout << "Written " << (written += len) << " " << TickCount() << "\n"; - } - - sock->close(); - - return (void *) 1; -} -pascal void * ConsumerThread(void * s) -{ - char buffer[1000]; - GUSISocket * sock = (GUSISocket *) s; - unsigned long read = 0; - int len; - - while (len = sock->read(buffer, 1000)) { - if (len < 0) { - cout << "Read Error: " << errno << "\n"; - - break; - } - cout << "Read " << (read += len) << " " << TickCount() << "\n"; - } - - sock->close(); - - return (void *) 1; -} -// The main program is quite simple. -// -//
= -void main() -{ - GUSISocket * s[2]; - - GUSIPipeFactory::Instance()->socketpair(0, 0, 0, s); - - ThreadID producer; - ThreadID consumer; - void * producerDone = 0; - void * consumerDone = 0; - - GUSINewThread(kCooperativeThread, ProducerThread, (void *) s[0], 20480, kCreateIfNeeded, &producerDone, &producer); - GUSINewThread(kCooperativeThread, ConsumerThread, (void *) s[1], 20480, kCreateIfNeeded, &consumerDone, &consumer); - - while (!producerDone || !consumerDone) { - cout << "Main Yielding " << TickCount() << "\n"; - GUSIContext::Yield(kGUSIPoll); - cout << "Main Back " << TickCount() << "\n"; - } - cout << flush; -} diff --git a/GUSI/test/tangled/TestTimers.cp b/GUSI/test/tangled/TestTimers.cp deleted file mode 100755 index d44eb55..0000000 --- a/GUSI/test/tangled/TestTimers.cp +++ /dev/null @@ -1,108 +0,0 @@ -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// % Project : GUSI - Grand Unified Socket Interface -// % File : TestTimers.nw - Test the GUSITiimer class -// % Author : Matthias Neeracher -// % Language : C++ -// % -// % $Log$ -// % Revision 1.1.1.1 2001/03/03 21:51:12 chombier -// % Initial import -// % -// % Revision 1.8 2000/03/15 07:08:59 neeri -// % New yield model -// % -// % Revision 1.7 1999/05/30 03:09:36 neeri -// % Added support for MPW compilers -// % -// % Revision 1.6 1999/03/17 09:05:17 neeri -// % Added GUSITimer, expanded docs -// % -// % Revision 1.5 1998/01/25 20:54:02 neeri -// % Engine implemented, except for signals & scheduling -// % -// % Revision 1.4 1997/11/13 21:12:15 neeri -// % Fall 1997 -// % -// % Revision 1.3 1996/11/24 13:00:30 neeri -// % Fix comment leaders -// % -// % Revision 1.2 1996/11/24 12:52:12 neeri -// % Added GUSIPipeSockets -// % -// % Revision 1.1 1996/11/18 00:53:47 neeri -// % TestTimers (basic threading/timer test) works -// % -// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// \documentstyle[noweb]{article} -// \begin{document} -// \section{Testing the [[GUSITimer]] class} -// -// This is a test program for the [[GUSITimer]] class. We test it by solving -// the Hamming Problem: Printing all multiples of 3, 5, and 7, in ascending -// order, without duplicates. We solve this with three threads sleeping 300 -// 500, and 700 milliseconds at a time. -// -// -// = -#define GUSI_SOURCE - -#include "GUSIBasics.h" -#include "GUSIContext.h" -#include "GUSITimer.h" - -#include -#include - -// The only global status we need is [[gLastNumber]], which serves both to eliminate -// duplicates and to terminate the program -// -// = -long gLastNumber = 0; -// And so is the multiplier thread itself. -// -// = -pascal void * MultiplierThread(void * inc) -{ - long cur = 0; - long incr = (long) inc; - - GUSITimer * timer = new GUSITimer(); - - for (;;) { - timer->Sleep(incr*200, true); - GUSIContext::Yield(kGUSIBlock); - cur += incr; - if (gLastNumber > cur) - cout << "Oops... wanted to print " << cur - << " but we are already at " << gLastNumber << "." << endl; - else if (gLastNumber == cur) - ; - else - cout << setw(5) << (gLastNumber = cur) << setw(12) << TickCount() << endl; - } - - return 0; -} -// The main program is quite simple. -// -//
= -void main() -{ - void * dontCare; - ThreadID mul3; - ThreadID mul5; - ThreadID mul7; - - GUSINewThread(kCooperativeThread, MultiplierThread, (void *) 3, 20480, kCreateIfNeeded, &dontCare, &mul3); - GUSINewThread(kCooperativeThread, MultiplierThread, (void *) 5, 20480, kCreateIfNeeded, &dontCare, &mul5); - GUSINewThread(kCooperativeThread, MultiplierThread, (void *) 7, 20480, kCreateIfNeeded, &dontCare, &mul7); - - while (gLastNumber < 50) { - GUSIContext::Yield(kGUSIPoll); - } - - DisposeThread(mul3, 0, false); - DisposeThread(mul5, 0, false); - DisposeThread(mul7, 0, false); -} diff --git a/gmp/.gdbinit b/gmp/.gdbinit deleted file mode 100755 index 647dbd6..0000000 Binary files a/gmp/.gdbinit and /dev/null differ diff --git a/gmp/AUTHORS b/gmp/AUTHORS deleted file mode 100755 index d11ccec..0000000 Binary files a/gmp/AUTHORS and /dev/null differ diff --git a/gmp/COPYING b/gmp/COPYING deleted file mode 100755 index ae4c4e4..0000000 Binary files a/gmp/COPYING and /dev/null differ diff --git a/gmp/COPYING.LIB b/gmp/COPYING.LIB deleted file mode 100755 index bf3b18e..0000000 Binary files a/gmp/COPYING.LIB and /dev/null differ diff --git a/gmp/ChangeLog b/gmp/ChangeLog deleted file mode 100755 index 8b0c820..0000000 Binary files a/gmp/ChangeLog and /dev/null differ diff --git a/gmp/INSTALL b/gmp/INSTALL deleted file mode 100755 index fefd8ba..0000000 Binary files a/gmp/INSTALL and /dev/null differ diff --git a/gmp/MacOS/.cvsignore b/gmp/MacOS/.cvsignore deleted file mode 100644 index 7bd60c1..0000000 --- a/gmp/MacOS/.cvsignore +++ /dev/null @@ -1,4 +0,0 @@ -*Data -libgmp.PPC.nd -libgmp.carb.nd -libs diff --git a/gmp/MacOS/config.h b/gmp/MacOS/config.h deleted file mode 100755 index 064aa89..0000000 --- a/gmp/MacOS/config.h +++ /dev/null @@ -1,2 +0,0 @@ -#include - diff --git a/gmp/MacOS/gmp-mparam.h b/gmp/MacOS/gmp-mparam.h deleted file mode 100755 index b283185..0000000 --- a/gmp/MacOS/gmp-mparam.h +++ /dev/null @@ -1,66 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values are for the 604. Presumably, these should be considerably - different for the 603 and 750 that have much slower multiply - instructions. */ - -/* Generated by tuneup.c, 2000-05-26. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 26 /* tuneup says 20 */ -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 228 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 46 /* tuneup says 44 */ -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 262 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 52 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 86 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 23 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 7 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 53 -#endif diff --git a/gmp/MacOS/gmp.CWPro6.mcp b/gmp/MacOS/gmp.CWPro6.mcp deleted file mode 100644 index ec5566d..0000000 Binary files a/gmp/MacOS/gmp.CWPro6.mcp and /dev/null differ diff --git a/gmp/MacOS/gmp.CWPro7.mcp b/gmp/MacOS/gmp.CWPro7.mcp deleted file mode 100644 index 7fe99fe..0000000 Binary files a/gmp/MacOS/gmp.CWPro7.mcp and /dev/null differ diff --git a/gmp/MacOS/gmp.mcp b/gmp/MacOS/gmp.mcp deleted file mode 100755 index 7f1b0fb..0000000 Binary files a/gmp/MacOS/gmp.mcp and /dev/null differ diff --git a/gmp/MacOS/gmpprefix.h b/gmp/MacOS/gmpprefix.h deleted file mode 100755 index d8c8d3b..0000000 --- a/gmp/MacOS/gmpprefix.h +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include - -#define exit macosexit -#define abort macosabort - -#define malloc lshmalloc -#define calloc lshcalloc -#define realloc lshrealloc -#define free lshfree - -#ifdef __cplusplus -extern "C" { -#endif - -void *lshmalloc(unsigned long size); -void *lshcalloc(unsigned long items, unsigned long size); -void *lshrealloc(void *addr, unsigned long size); -void lshfree(void *addr); - -#ifdef __cplusplus -} -#endif - -#define VERSION "3.1" diff --git a/gmp/MacOS/gmpprefix68k.h b/gmp/MacOS/gmpprefix68k.h deleted file mode 100755 index fb19953..0000000 --- a/gmp/MacOS/gmpprefix68k.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef mc68020 -#define mc68020 1 -#endif - -#define ALLOCA_68K_BUG 1 - -#include "gmpprefix.h" diff --git a/gmp/MacOS/gmpprefixcarb.h b/gmp/MacOS/gmpprefixcarb.h deleted file mode 100644 index 55decfe..0000000 --- a/gmp/MacOS/gmpprefixcarb.h +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "gmpprefixppc.h" diff --git a/gmp/MacOS/gmpprefixppc.h b/gmp/MacOS/gmpprefixppc.h deleted file mode 100755 index 70cc3c0..0000000 --- a/gmp/MacOS/gmpprefixppc.h +++ /dev/null @@ -1 +0,0 @@ -#include "gmpprefix.h" diff --git a/gmp/MacOS/mparam/mparam.mcp b/gmp/MacOS/mparam/mparam.mcp deleted file mode 100755 index 0838b77..0000000 Binary files a/gmp/MacOS/mparam/mparam.mcp and /dev/null differ diff --git a/gmp/MacOS/mparam/mparam.mcp.xml b/gmp/MacOS/mparam/mparam.mcp.xml deleted file mode 100755 index 4b410b8..0000000 Binary files a/gmp/MacOS/mparam/mparam.mcp.xml and /dev/null differ diff --git a/gmp/MacOS/mparam/prefix.h b/gmp/MacOS/mparam/prefix.h deleted file mode 100755 index d807850..0000000 --- a/gmp/MacOS/mparam/prefix.h +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include \ No newline at end of file diff --git a/gmp/Makefile.am b/gmp/Makefile.am deleted file mode 100755 index b9da48f..0000000 Binary files a/gmp/Makefile.am and /dev/null differ diff --git a/gmp/Makefile.in b/gmp/Makefile.in deleted file mode 100755 index d5e71d0..0000000 Binary files a/gmp/Makefile.in and /dev/null differ diff --git a/gmp/NEWS b/gmp/NEWS deleted file mode 100755 index 2176fce..0000000 Binary files a/gmp/NEWS and /dev/null differ diff --git a/gmp/README b/gmp/README deleted file mode 100755 index 8438bb9..0000000 Binary files a/gmp/README and /dev/null differ diff --git a/gmp/acconfig.h b/gmp/acconfig.h deleted file mode 100755 index dfb1b0b..0000000 --- a/gmp/acconfig.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -@TOP@ - -/* Define if a limb is long long. */ -#undef _LONG_LONG_LIMB - -/* Define if we have native implementation of function. */ -#undef HAVE_NATIVE_ -#undef HAVE_NATIVE_mpn_add -#undef HAVE_NATIVE_mpn_add_1 -#undef HAVE_NATIVE_mpn_add_n -#undef HAVE_NATIVE_mpn_add_nc -#undef HAVE_NATIVE_mpn_addmul_1 -#undef HAVE_NATIVE_mpn_addmul_1c -#undef HAVE_NATIVE_mpn_addsub_n -#undef HAVE_NATIVE_mpn_addsub_nc -#undef HAVE_NATIVE_mpn_and_n -#undef HAVE_NATIVE_mpn_andn_n -#undef HAVE_NATIVE_mpn_bdivmod -#undef HAVE_NATIVE_mpn_cmp -#undef HAVE_NATIVE_mpn_com_n -#undef HAVE_NATIVE_mpn_copyd -#undef HAVE_NATIVE_mpn_copyi -#undef HAVE_NATIVE_mpn_divexact_by3c -#undef HAVE_NATIVE_mpn_divrem -#undef HAVE_NATIVE_mpn_divrem_1 -#undef HAVE_NATIVE_mpn_divrem_1c -#undef HAVE_NATIVE_mpn_divrem_2 -#undef HAVE_NATIVE_mpn_divrem_newton -#undef HAVE_NATIVE_mpn_divrem_classic -#undef HAVE_NATIVE_mpn_dump -#undef HAVE_NATIVE_mpn_gcd -#undef HAVE_NATIVE_mpn_gcd_1 -#undef HAVE_NATIVE_mpn_gcdext -#undef HAVE_NATIVE_mpn_get_str -#undef HAVE_NATIVE_mpn_hamdist -#undef HAVE_NATIVE_mpn_invert_limb -#undef HAVE_NATIVE_mpn_ior_n -#undef HAVE_NATIVE_mpn_iorn_n -#undef HAVE_NATIVE_mpn_lshift -#undef HAVE_NATIVE_mpn_mod_1 -#undef HAVE_NATIVE_mpn_mod_1c -#undef HAVE_NATIVE_mpn_mul -#undef HAVE_NATIVE_mpn_mul_1 -#undef HAVE_NATIVE_mpn_mul_1c -#undef HAVE_NATIVE_mpn_mul_basecase -#undef HAVE_NATIVE_mpn_mul_n -#undef HAVE_NATIVE_mpn_nand_n -#undef HAVE_NATIVE_mpn_nior_n -#undef HAVE_NATIVE_mpn_perfect_square_p -#undef HAVE_NATIVE_mpn_popcount -#undef HAVE_NATIVE_mpn_preinv_mod_1 -#undef HAVE_NATIVE_mpn_random2 -#undef HAVE_NATIVE_mpn_random -#undef HAVE_NATIVE_mpn_rawrandom -#undef HAVE_NATIVE_mpn_rshift -#undef HAVE_NATIVE_mpn_scan0 -#undef HAVE_NATIVE_mpn_scan1 -#undef HAVE_NATIVE_mpn_set_str -#undef HAVE_NATIVE_mpn_sqrtrem -#undef HAVE_NATIVE_mpn_sqr_basecase -#undef HAVE_NATIVE_mpn_sub -#undef HAVE_NATIVE_mpn_sub_1 -#undef HAVE_NATIVE_mpn_sub_n -#undef HAVE_NATIVE_mpn_sub_nc -#undef HAVE_NATIVE_mpn_submul_1 -#undef HAVE_NATIVE_mpn_submul_1c -#undef HAVE_NATIVE_mpn_udiv_w_sdiv -#undef HAVE_NATIVE_mpn_umul_ppmm -#undef HAVE_NATIVE_mpn_udiv_qrnnd -#undef HAVE_NATIVE_mpn_xor_n -#undef HAVE_NATIVE_mpn_xnor_n diff --git a/gmp/acinclude.m4 b/gmp/acinclude.m4 deleted file mode 100755 index 92b2224..0000000 Binary files a/gmp/acinclude.m4 and /dev/null differ diff --git a/gmp/aclocal.m4 b/gmp/aclocal.m4 deleted file mode 100755 index dfe1056..0000000 Binary files a/gmp/aclocal.m4 and /dev/null differ diff --git a/gmp/ansi2knr.1 b/gmp/ansi2knr.1 deleted file mode 100755 index 2a2bf53..0000000 Binary files a/gmp/ansi2knr.1 and /dev/null differ diff --git a/gmp/ansi2knr.c b/gmp/ansi2knr.c deleted file mode 100755 index 8142b38..0000000 --- a/gmp/ansi2knr.c +++ /dev/null @@ -1,678 +0,0 @@ -/* Copyright (C) 1989, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. */ - -/*$Id$*/ -/* Convert ANSI C function definitions to K&R ("traditional C") syntax */ - -/* -ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY. No author or distributor accepts responsibility to anyone for the -consequences of using it or for whether it serves any particular purpose or -works at all, unless he says so in writing. Refer to the GNU General Public -License (the "GPL") for full details. - -Everyone is granted permission to copy, modify and redistribute ansi2knr, -but only under the conditions described in the GPL. A copy of this license -is supposed to have been given to you along with ansi2knr so you can know -your rights and responsibilities. It should be in a file named COPYLEFT, -or, if there is no file named COPYLEFT, a file named COPYING. Among other -things, the copyright notice and this notice must be preserved on all -copies. - -We explicitly state here what we believe is already implied by the GPL: if -the ansi2knr program is distributed as a separate set of sources and a -separate executable file which are aggregated on a storage medium together -with another program, this in itself does not bring the other program under -the GPL, nor does the mere fact that such a program or the procedures for -constructing it invoke the ansi2knr executable bring any other part of the -program under the GPL. -*/ - -/* - * Usage: - ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]] - * --filename provides the file name for the #line directive in the output, - * overriding input_file (if present). - * If no input_file is supplied, input is read from stdin. - * If no output_file is supplied, output goes to stdout. - * There are no error messages. - * - * ansi2knr recognizes function definitions by seeing a non-keyword - * identifier at the left margin, followed by a left parenthesis, - * with a right parenthesis as the last character on the line, - * and with a left brace as the first token on the following line - * (ignoring possible intervening comments), except that a line - * consisting of only - * identifier1(identifier2) - * will not be considered a function definition unless identifier2 is - * the word "void", and a line consisting of - * identifier1(identifier2, <>) - * will not be considered a function definition. - * ansi2knr will recognize a multi-line header provided - * that no intervening line ends with a left or right brace or a semicolon. - * These algorithms ignore whitespace and comments, except that - * the function name must be the first thing on the line. - * The following constructs will confuse it: - * - Any other construct that starts at the left margin and - * follows the above syntax (such as a macro or function call). - * - Some macros that tinker with the syntax of function headers. - */ - -/* - * The original and principal author of ansi2knr is L. Peter Deutsch - * . Other authors are noted in the change history - * that follows (in reverse chronological order): - lpd 1999-04-12 added minor fixes from Pavel Roskin - for clean compilation with - gcc -W -Wall - lpd 1999-03-22 added hack to recognize lines consisting of - identifier1(identifier2, xxx) as *not* being procedures - lpd 1999-02-03 made indentation of preprocessor commands consistent - lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an - endless loop; quoted strings within an argument list - confused the parser - lpd 1999-01-24 added a check for write errors on the output, - suggested by Jim Meyering - lpd 1998-11-09 added further hack to recognize identifier(void) - as being a procedure - lpd 1998-10-23 added hack to recognize lines consisting of - identifier1(identifier2) as *not* being procedures - lpd 1997-12-08 made input_file optional; only closes input and/or - output file if not stdin or stdout respectively; prints - usage message on stderr rather than stdout; adds - --filename switch (changes suggested by - ) - lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with - compilers that don't understand void, as suggested by - Tom Lane - lpd 1996-01-15 changed to require that the first non-comment token - on the line following a function header be a left brace, - to reduce sensitivity to macros, as suggested by Tom Lane - - lpd 1995-06-22 removed #ifndefs whose sole purpose was to define - undefined preprocessor symbols as 0; changed all #ifdefs - for configuration symbols to #ifs - lpd 1995-04-05 changed copyright notice to make it clear that - including ansi2knr in a program does not bring the entire - program under the GPL - lpd 1994-12-18 added conditionals for systems where ctype macros - don't handle 8-bit characters properly, suggested by - Francois Pinard ; - removed --varargs switch (this is now the default) - lpd 1994-10-10 removed CONFIG_BROKETS conditional - lpd 1994-07-16 added some conditionals to help GNU `configure', - suggested by Francois Pinard ; - properly erase prototype args in function parameters, - contributed by Jim Avera ; - correct error in writeblanks (it shouldn't erase EOLs) - lpd 1989-xx-xx original version - */ - -/* Most of the conditionals here are to make ansi2knr work with */ -/* or without the GNU configure machinery. */ - -#if HAVE_CONFIG_H -# include -#endif - -#include -#include - -#if HAVE_CONFIG_H - -/* - For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h). - This will define HAVE_CONFIG_H and so, activate the following lines. - */ - -# if STDC_HEADERS || HAVE_STRING_H -# include -# else -# include -# endif - -#else /* not HAVE_CONFIG_H */ - -/* Otherwise do it the hard way */ - -# ifdef BSD -# include -# else -# ifdef VMS - extern int strlen(), strncmp(); -# else -# include -# endif -# endif - -#endif /* not HAVE_CONFIG_H */ - -#if STDC_HEADERS -# include -#else -/* - malloc and free should be declared in stdlib.h, - but if you've got a K&R compiler, they probably aren't. - */ -# ifdef MSDOS -# include -# else -# ifdef VMS - extern char *malloc(); - extern void free(); -# else - extern char *malloc(); - extern int free(); -# endif -# endif - -#endif - -/* Define NULL (for *very* old compilers). */ -#ifndef NULL -# define NULL (0) -#endif - -/* - * The ctype macros don't always handle 8-bit characters correctly. - * Compensate for this here. - */ -#ifdef isascii -# undef HAVE_ISASCII /* just in case */ -# define HAVE_ISASCII 1 -#else -#endif -#if STDC_HEADERS || !HAVE_ISASCII -# define is_ascii(c) 1 -#else -# define is_ascii(c) isascii(c) -#endif - -#define is_space(c) (is_ascii(c) && isspace(c)) -#define is_alpha(c) (is_ascii(c) && isalpha(c)) -#define is_alnum(c) (is_ascii(c) && isalnum(c)) - -/* Scanning macros */ -#define isidchar(ch) (is_alnum(ch) || (ch) == '_') -#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') - -/* Forward references */ -char *skipspace(); -char *scanstring(); -int writeblanks(); -int test1(); -int convert1(); - -/* The main program */ -int -main(argc, argv) - int argc; - char *argv[]; -{ FILE *in = stdin; - FILE *out = stdout; - char *filename = 0; - char *program_name = argv[0]; - char *output_name = 0; -#define bufsize 5000 /* arbitrary size */ - char *buf; - char *line; - char *more; - char *usage = - "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n"; - /* - * In previous versions, ansi2knr recognized a --varargs switch. - * If this switch was supplied, ansi2knr would attempt to convert - * a ... argument to va_alist and va_dcl; if this switch was not - * supplied, ansi2knr would simply drop any such arguments. - * Now, ansi2knr always does this conversion, and we only - * check for this switch for backward compatibility. - */ - int convert_varargs = 1; - int output_error; - - while ( argc > 1 && argv[1][0] == '-' ) { - if ( !strcmp(argv[1], "--varargs") ) { - convert_varargs = 1; - argc--; - argv++; - continue; - } - if ( !strcmp(argv[1], "--filename") && argc > 2 ) { - filename = argv[2]; - argc -= 2; - argv += 2; - continue; - } - fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name, - argv[1]); - fprintf(stderr, usage); - exit(1); - } - switch ( argc ) - { - default: - fprintf(stderr, usage); - exit(0); - case 3: - output_name = argv[2]; - out = fopen(output_name, "w"); - if ( out == NULL ) { - fprintf(stderr, "%s: Cannot open output file %s\n", - program_name, output_name); - exit(1); - } - /* falls through */ - case 2: - in = fopen(argv[1], "r"); - if ( in == NULL ) { - fprintf(stderr, "%s: Cannot open input file %s\n", - program_name, argv[1]); - exit(1); - } - if ( filename == 0 ) - filename = argv[1]; - /* falls through */ - case 1: - break; - } - if ( filename ) - fprintf(out, "#line 1 \"%s\"\n", filename); - buf = malloc(bufsize); - if ( buf == NULL ) - { - fprintf(stderr, "Unable to allocate read buffer!\n"); - exit(1); - } - line = buf; - while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) - { -test: line += strlen(line); - switch ( test1(buf) ) - { - case 2: /* a function header */ - convert1(buf, out, 1, convert_varargs); - break; - case 1: /* a function */ - /* Check for a { at the start of the next line. */ - more = ++line; -f: if ( line >= buf + (bufsize - 1) ) /* overflow check */ - goto wl; - if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL ) - goto wl; - switch ( *skipspace(more, 1) ) - { - case '{': - /* Definitely a function header. */ - convert1(buf, out, 0, convert_varargs); - fputs(more, out); - break; - case 0: - /* The next line was blank or a comment: */ - /* keep scanning for a non-comment. */ - line += strlen(line); - goto f; - default: - /* buf isn't a function header, but */ - /* more might be. */ - fputs(buf, out); - strcpy(buf, more); - line = buf; - goto test; - } - break; - case -1: /* maybe the start of a function */ - if ( line != buf + (bufsize - 1) ) /* overflow check */ - continue; - /* falls through */ - default: /* not a function */ -wl: fputs(buf, out); - break; - } - line = buf; - } - if ( line != buf ) - fputs(buf, out); - free(buf); - if ( output_name ) { - output_error = ferror(out); - output_error |= fclose(out); - } else { /* out == stdout */ - fflush(out); - output_error = ferror(out); - } - if ( output_error ) { - fprintf(stderr, "%s: error writing to %s\n", program_name, - (output_name ? output_name : "stdout")); - exit(1); - } - if ( in != stdin ) - fclose(in); - return 0; -} - -/* Skip over whitespace and comments, in either direction. */ -char * -skipspace(p, dir) - register char *p; - register int dir; /* 1 for forward, -1 for backward */ -{ for ( ; ; ) - { while ( is_space(*p) ) - p += dir; - if ( !(*p == '/' && p[dir] == '*') ) - break; - p += dir; p += dir; - while ( !(*p == '*' && p[dir] == '/') ) - { if ( *p == 0 ) - return p; /* multi-line comment?? */ - p += dir; - } - p += dir; p += dir; - } - return p; -} - -/* Scan over a quoted string, in either direction. */ -char * -scanstring(p, dir) - register char *p; - register int dir; -{ - for (p += dir; ; p += dir) - if (*p == '"' && p[-dir] != '\\') - return p + dir; -} - -/* - * Write blanks over part of a string. - * Don't overwrite end-of-line characters. - */ -int -writeblanks(start, end) - char *start; - char *end; -{ char *p; - for ( p = start; p < end; p++ ) - if ( *p != '\r' && *p != '\n' ) - *p = ' '; - return 0; -} - -/* - * Test whether the string in buf is a function definition. - * The string may contain and/or end with a newline. - * Return as follows: - * 0 - definitely not a function definition; - * 1 - definitely a function definition; - * 2 - definitely a function prototype (NOT USED); - * -1 - may be the beginning of a function definition, - * append another line and look again. - * The reason we don't attempt to convert function prototypes is that - * Ghostscript's declaration-generating macros look too much like - * prototypes, and confuse the algorithms. - */ -int -test1(buf) - char *buf; -{ register char *p = buf; - char *bend; - char *endfn; - int contin; - - if ( !isidfirstchar(*p) ) - return 0; /* no name at left margin */ - bend = skipspace(buf + strlen(buf) - 1, -1); - switch ( *bend ) - { - case ';': contin = 0 /*2*/; break; - case ')': contin = 1; break; - case '{': return 0; /* not a function */ - case '}': return 0; /* not a function */ - default: contin = -1; - } - while ( isidchar(*p) ) - p++; - endfn = p; - p = skipspace(p, 1); - if ( *p++ != '(' ) - return 0; /* not a function */ - p = skipspace(p, 1); - if ( *p == ')' ) - return 0; /* no parameters */ - /* Check that the apparent function name isn't a keyword. */ - /* We only need to check for keywords that could be followed */ - /* by a left parenthesis (which, unfortunately, is most of them). */ - { static char *words[] = - { "asm", "auto", "case", "char", "const", "double", - "extern", "float", "for", "if", "int", "long", - "register", "return", "short", "signed", "sizeof", - "static", "switch", "typedef", "unsigned", - "void", "volatile", "while", 0 - }; - char **key = words; - char *kp; - unsigned len = endfn - buf; - - while ( (kp = *key) != 0 ) - { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) - return 0; /* name is a keyword */ - key++; - } - } - { - char *id = p; - int len; - /* - * Check for identifier1(identifier2) and not - * identifier1(void), or identifier1(identifier2, xxxx). - */ - - while ( isidchar(*p) ) - p++; - len = p - id; - p = skipspace(p, 1); - if (*p == ',' || - (*p == ')' && (len != 4 || strncmp(id, "void", 4))) - ) - return 0; /* not a function */ - } - /* - * If the last significant character was a ), we need to count - * parentheses, because it might be part of a formal parameter - * that is a procedure. - */ - if (contin > 0) { - int level = 0; - - for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1)) - level += (*p == '(' ? 1 : *p == ')' ? -1 : 0); - if (level > 0) - contin = -1; - } - return contin; -} - -/* Convert a recognized function definition or header to K&R syntax. */ -int -convert1(buf, out, header, convert_varargs) - char *buf; - FILE *out; - int header; /* Boolean */ - int convert_varargs; /* Boolean */ -{ char *endfn; - register char *p; - /* - * The breaks table contains pointers to the beginning and end - * of each argument. - */ - char **breaks; - unsigned num_breaks = 2; /* for testing */ - char **btop; - char **bp; - char **ap; - char *vararg = 0; - - /* Pre-ANSI implementations don't agree on whether strchr */ - /* is called strchr or index, so we open-code it here. */ - for ( endfn = buf; *(endfn++) != '('; ) - ; -top: p = endfn; - breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); - if ( breaks == NULL ) - { /* Couldn't allocate break table, give up */ - fprintf(stderr, "Unable to allocate break table!\n"); - fputs(buf, out); - return -1; - } - btop = breaks + num_breaks * 2 - 2; - bp = breaks; - /* Parse the argument list */ - do - { int level = 0; - char *lp = NULL; - char *rp = NULL; - char *end = NULL; - - if ( bp >= btop ) - { /* Filled up break table. */ - /* Allocate a bigger one and start over. */ - free((char *)breaks); - num_breaks <<= 1; - goto top; - } - *bp++ = p; - /* Find the end of the argument */ - for ( ; end == NULL; p++ ) - { switch(*p) - { - case ',': - if ( !level ) end = p; - break; - case '(': - if ( !level ) lp = p; - level++; - break; - case ')': - if ( --level < 0 ) end = p; - else rp = p; - break; - case '/': - if (p[1] == '*') - p = skipspace(p, 1) - 1; - break; - case '"': - p = scanstring(p, 1) - 1; - break; - default: - ; - } - } - /* Erase any embedded prototype parameters. */ - if ( lp && rp ) - writeblanks(lp + 1, rp); - p--; /* back up over terminator */ - /* Find the name being declared. */ - /* This is complicated because of procedure and */ - /* array modifiers. */ - for ( ; ; ) - { p = skipspace(p - 1, -1); - switch ( *p ) - { - case ']': /* skip array dimension(s) */ - case ')': /* skip procedure args OR name */ - { int level = 1; - while ( level ) - switch ( *--p ) - { - case ']': case ')': - level++; - break; - case '[': case '(': - level--; - break; - case '/': - if (p > buf && p[-1] == '*') - p = skipspace(p, -1) + 1; - break; - case '"': - p = scanstring(p, -1) + 1; - break; - default: ; - } - } - if ( *p == '(' && *skipspace(p + 1, 1) == '*' ) - { /* We found the name being declared */ - while ( !isidfirstchar(*p) ) - p = skipspace(p, 1) + 1; - goto found; - } - break; - default: - goto found; - } - } -found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' ) - { if ( convert_varargs ) - { *bp++ = "va_alist"; - vararg = p-2; - } - else - { p++; - if ( bp == breaks + 1 ) /* sole argument */ - writeblanks(breaks[0], p); - else - writeblanks(bp[-1] - 1, p); - bp--; - } - } - else - { while ( isidchar(*p) ) p--; - *bp++ = p+1; - } - p = end; - } - while ( *p++ == ',' ); - *bp = p; - /* Make a special check for 'void' arglist */ - if ( bp == breaks+2 ) - { p = skipspace(breaks[0], 1); - if ( !strncmp(p, "void", 4) ) - { p = skipspace(p+4, 1); - if ( p == breaks[2] - 1 ) - { bp = breaks; /* yup, pretend arglist is empty */ - writeblanks(breaks[0], p + 1); - } - } - } - /* Put out the function name and left parenthesis. */ - p = buf; - while ( p != endfn ) putc(*p, out), p++; - /* Put out the declaration. */ - if ( header ) - { fputs(");", out); - for ( p = breaks[0]; *p; p++ ) - if ( *p == '\r' || *p == '\n' ) - putc(*p, out); - } - else - { for ( ap = breaks+1; ap < bp; ap += 2 ) - { p = *ap; - while ( isidchar(*p) ) - putc(*p, out), p++; - if ( ap < bp - 1 ) - fputs(", ", out); - } - fputs(") ", out); - /* Put out the argument declarations */ - for ( ap = breaks+2; ap <= bp; ap += 2 ) - (*ap)[-1] = ';'; - if ( vararg != 0 ) - { *vararg = 0; - fputs(breaks[0], out); /* any prior args */ - fputs("va_dcl", out); /* the final arg */ - fputs(bp[0], out); - } - else - fputs(breaks[0], out); - } - free((char *)breaks); - return 0; -} diff --git a/gmp/assert.c b/gmp/assert.c deleted file mode 100755 index 65eccfa..0000000 --- a/gmp/assert.c +++ /dev/null @@ -1,52 +0,0 @@ -/* GMP assertion failure handler. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - - -int -#if __STDC__ -__gmp_assert_fail (const char *filename, int linenum, - const char *expr) -#else -__gmp_assert_fail (filename, linenum, expr) -char *filename; -int linenum; -char *expr; -#endif -{ - if (filename != NULL && filename[0] != '\0') - { - fprintf (stderr, "%s:", filename); - if (linenum != -1) - fprintf (stderr, "%d: ", linenum); - } - - fprintf (stderr, "GNU MP assertion failed: %s\n", expr); - abort(); - - /*NOTREACHED*/ - return 0; -} diff --git a/gmp/compat.c b/gmp/compat.c deleted file mode 100755 index 7b38aab..0000000 --- a/gmp/compat.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Old function entrypoints retained for binary compatibility. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - - -/* mpn_divexact_by3 was a function in gmp 3.0, but as of gmp 3.1 it's a - macro calling mpn_divexact_by3c. */ -int -__MPN (divexact_by3) (mp_ptr dst, mp_srcptr src, mp_size_t size) -{ - return mpn_divexact_by3 (dst, src, size); -} - - -/* mpn_divmod_1 was a function in gmp 3.0 and earlier, but marked obsolete - in gmp 2 and 3. As of gmp 3.1 it's a macro calling mpn_divrem_1. */ -int -__MPN (divmod_1) (mp_ptr dst, mp_srcptr src, mp_size_t size, mp_limb_t divisor) -{ - return mpn_divmod_1 (dst, src, size, divisor); -} - - diff --git a/gmp/config.guess b/gmp/config.guess deleted file mode 100755 index b8d5771..0000000 Binary files a/gmp/config.guess and /dev/null differ diff --git a/gmp/config.in b/gmp/config.in deleted file mode 100755 index e8dcbd4..0000000 Binary files a/gmp/config.in and /dev/null differ diff --git a/gmp/config.sub b/gmp/config.sub deleted file mode 100755 index dd1c559..0000000 Binary files a/gmp/config.sub and /dev/null differ diff --git a/gmp/configure b/gmp/configure deleted file mode 100755 index 5d7e010..0000000 Binary files a/gmp/configure and /dev/null differ diff --git a/gmp/configure.in b/gmp/configure.in deleted file mode 100755 index b80479f..0000000 Binary files a/gmp/configure.in and /dev/null differ diff --git a/gmp/demos/Makefile.am b/gmp/demos/Makefile.am deleted file mode 100755 index bb9e47d..0000000 Binary files a/gmp/demos/Makefile.am and /dev/null differ diff --git a/gmp/demos/Makefile.in b/gmp/demos/Makefile.in deleted file mode 100755 index a5d8d38..0000000 Binary files a/gmp/demos/Makefile.in and /dev/null differ diff --git a/gmp/demos/calc.c b/gmp/demos/calc.c deleted file mode 100755 index 46b9e13..0000000 --- a/gmp/demos/calc.c +++ /dev/null @@ -1,1301 +0,0 @@ - -/* A Bison parser, made from calc.y - by GNU Bison version 1.28 */ - -#define YYBISON 1 /* Identify Bison output. */ - -#define EOS 257 -#define BAD 258 -#define HEX 259 -#define DECIMAL 260 -#define QUIT 261 -#define ABS 262 -#define BIN 263 -#define FIB 264 -#define GCD 265 -#define LCM 266 -#define NEXTPRIME 267 -#define POWM 268 -#define ROOT 269 -#define SQRT 270 -#define NUMBER 271 -#define VARIABLE 272 -#define LOR 273 -#define LAND 274 -#define EQ 275 -#define NE 276 -#define LE 277 -#define GE 278 -#define LSHIFT 279 -#define RSHIFT 280 -#define UMINUS 281 - -#line 99 "calc.y" - -#include -#include - -#include "gmp.h" - -#define numberof(x) (sizeof (x) / sizeof ((x)[0])) - - -int ibase = 0; -int obase = 10; - - -/* The stack is a fixed size, which means there's a limit on the nesting - allowed in expressions. A more sophisticated program could let it grow - dynamically. */ - -mpz_t stack[100]; -mpz_ptr sp = stack[0]; - -#define CHECK_OVERFLOW() \ - if (sp >= stack[numberof(stack)]) \ - { \ - fprintf (stderr, \ - "Value stack overflow, too much nesting in expression\n"); \ - YYERROR; \ - } - -#define CHECK_EMPTY() \ - if (sp != stack[0]) \ - { \ - fprintf (stderr, "Oops, expected the value stack to be empty\n"); \ - sp = stack[0]; \ - } - - -mpz_t variable[26]; - -#define CHECK_VARIABLE(var) \ - if ((var) < 0 || (var) >= numberof (variable)) \ - { \ - fprintf (stderr, "Oops, bad variable somehow: %d\n", var); \ - YYERROR; \ - } - - -#define CHECK_UI(name,z) \ - if (! mpz_fits_ulong_p (z)) \ - { \ - fprintf (stderr, \ - "Operand must fit in an \"unsigned long\" for %s\n", name); \ - YYERROR; \ - } - - -#line 155 "calc.y" -typedef union { - char *str; - int var; -} YYSTYPE; -#include - -#ifndef __cplusplus -#ifndef __STDC__ -#define const -#endif -#endif - - - -#define YYFINAL 107 -#define YYFLAG -32768 -#define YYNTBASE 41 - -#define YYTRANSLATE(x) ((unsigned)(x) <= 281 ? yytranslate[x] : 47) - -static const char yytranslate[] = { 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 36, 2, 2, 2, 33, 2, 2, 38, - 39, 31, 29, 40, 30, 2, 32, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 21, - 37, 22, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 35, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 1, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, - 34 -}; - -#if YYDEBUG != 0 -static const short yyprhs[] = { 0, - 0, 2, 5, 8, 12, 15, 16, 18, 22, 24, - 26, 28, 32, 36, 40, 44, 48, 52, 56, 60, - 64, 67, 70, 74, 78, 82, 86, 90, 94, 98, - 102, 107, 114, 119, 124, 129, 134, 143, 150, 155, - 157, 159, 161, 165, 167 -}; - -static const short yyrhs[] = { 43, - 0, 42, 43, 0, 43, 3, 0, 42, 43, 3, - 0, 1, 3, 0, 0, 44, 0, 18, 37, 44, - 0, 5, 0, 6, 0, 7, 0, 38, 44, 39, - 0, 44, 29, 44, 0, 44, 30, 44, 0, 44, - 31, 44, 0, 44, 32, 44, 0, 44, 33, 44, - 0, 44, 35, 44, 0, 44, 27, 44, 0, 44, - 28, 44, 0, 44, 36, 0, 30, 44, 0, 44, - 21, 44, 0, 44, 25, 44, 0, 44, 23, 44, - 0, 44, 24, 44, 0, 44, 26, 44, 0, 44, - 22, 44, 0, 44, 20, 44, 0, 44, 19, 44, - 0, 8, 38, 44, 39, 0, 9, 38, 44, 40, - 44, 39, 0, 10, 38, 44, 39, 0, 11, 38, - 45, 39, 0, 12, 38, 46, 39, 0, 13, 38, - 44, 39, 0, 14, 38, 44, 40, 44, 40, 44, - 39, 0, 15, 38, 44, 40, 44, 39, 0, 16, - 38, 44, 39, 0, 18, 0, 17, 0, 44, 0, - 45, 40, 44, 0, 44, 0, 46, 40, 44, 0 -}; - -#endif - -#if YYDEBUG != 0 -static const short yyrline[] = { 0, - 179, 181, 183, 185, 186, 188, 190, 195, 201, 202, - 203, 208, 210, 211, 212, 213, 214, 215, 217, 219, - 221, 223, 225, 226, 227, 228, 229, 230, 232, 233, - 235, 236, 238, 240, 241, 242, 243, 244, 246, 248, - 254, 264, 266, 268, 270 -}; -#endif - - -#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) - -static const char * const yytname[] = { "$","error","$undefined.","EOS","BAD", -"HEX","DECIMAL","QUIT","ABS","BIN","FIB","GCD","LCM","NEXTPRIME","POWM","ROOT", -"SQRT","NUMBER","VARIABLE","LOR","LAND","'<'","'>'","EQ","NE","LE","GE","LSHIFT", -"RSHIFT","'+'","'-'","'*'","'/'","'%'","UMINUS","'^'","'!'","'='","'('","')'", -"','","top","statements","statement","e","gcdlist","lcmlist", NULL -}; -#endif - -static const short yyr1[] = { 0, - 41, 41, 42, 42, 42, 43, 43, 43, 43, 43, - 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 45, 45, 46, 46 -}; - -static const short yyr2[] = { 0, - 1, 2, 2, 3, 2, 0, 1, 3, 1, 1, - 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 6, 4, 4, 4, 4, 8, 6, 4, 1, - 1, 1, 3, 1, 3 -}; - -static const short yydefact[] = { 0, - 0, 9, 10, 11, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 41, 40, 0, 0, 6, 1, 7, - 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 40, 22, 0, 2, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 21, 0, 0, 0, 42, 0, 44, 0, - 0, 0, 0, 0, 8, 12, 4, 30, 29, 23, - 28, 25, 26, 24, 27, 19, 20, 13, 14, 15, - 16, 17, 18, 31, 0, 33, 34, 0, 35, 0, - 36, 0, 0, 39, 0, 43, 45, 0, 0, 32, - 0, 38, 0, 37, 0, 0, 0 -}; - -static const short yydefgoto[] = { 105, - 18, 19, 20, 58, 60 -}; - -static const short yypact[] = { 37, - 15,-32768,-32768,-32768, -19, -18, 1, 3, 23, 26, - 28, 30, 32,-32768, 34, 92, 92, 81, 62, 368, --32768, 92, 92, 92, 92, 92, 92, 92, 92, 92, - 92,-32768, -33, 200, 70,-32768, 92, 92, 92, 92, - 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, - 92, 92,-32768, 221, 112, 242, 368, -35, 368, -23, - 263, 134, 156, 284, 368,-32768,-32768, 385, 401, 417, - 417, 417, 417, 417, 417, 27, 27, 47, 47, -33, - -33, -33, -33,-32768, 92,-32768,-32768, 92,-32768, 92, --32768, 92, 92,-32768, 305, 368, 368, 178, 326,-32768, - 92,-32768, 347,-32768, 84, 113,-32768 -}; - -static const short yypgoto[] = {-32768, --32768, 63, -16,-32768,-32768 -}; - - -#define YYLAST 453 - - -static const short yytable[] = { 33, - 34, 52, 53, 87, 88, 54, 55, 56, 57, 59, - 61, 62, 63, 64, 65, 89, 90, 21, 22, 23, - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - 78, 79, 80, 81, 82, 83, -6, 1, 24, -6, - 25, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 47, 48, 49, 50, 51, - 26, 52, 53, 27, 36, 28, 16, 29, 95, 30, - 31, 96, 67, 97, 17, 98, 99, 49, 50, 51, - 35, 52, 53, 106, 103, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 5, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 32, - 16, 0, 107, 0, 0, 0, 0, 0, 17, 0, - 0, 16, 0, 0, 0, 0, 0, 0, 0, 17, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51, 0, 52, 53, 0, 0, - 0, 85, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 0, 52, 53, - 0, 0, 0, 92, 37, 38, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, - 52, 53, 0, 0, 0, 93, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 0, 52, 53, 0, 0, 0, 101, 37, 38, - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 0, 52, 53, 0, 0, 66, 37, - 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 0, 52, 53, 0, 0, 84, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51, 0, 52, 53, 0, 0, - 86, 37, 38, 39, 40, 41, 42, 43, 44, 45, - 46, 47, 48, 49, 50, 51, 0, 52, 53, 0, - 0, 91, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 0, 52, 53, - 0, 0, 94, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, 0, 52, - 53, 0, 0, 100, 37, 38, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, - 52, 53, 0, 0, 102, 37, 38, 39, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 0, 52, 53, 0, 0, 104, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 0, 52, 53, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, 0, 52, - 53, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 0, 52, 53,-32768,-32768,-32768, --32768,-32768,-32768, 45, 46, 47, 48, 49, 50, 51, - 0, 52, 53 -}; - -static const short yycheck[] = { 16, - 17, 35, 36, 39, 40, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 39, 40, 3, 38, 38, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51, 52, 0, 1, 38, 3, - 38, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 29, 30, 31, 32, 33, - 38, 35, 36, 38, 3, 38, 30, 38, 85, 38, - 37, 88, 3, 90, 38, 92, 93, 31, 32, 33, - 18, 35, 36, 0, 101, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 8, - 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 30, -1, 0, -1, -1, -1, -1, -1, 38, -1, - -1, 30, -1, -1, -1, -1, -1, -1, -1, 38, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, -1, 35, 36, -1, -1, - -1, 40, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, 35, 36, - -1, -1, -1, 40, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, -1, - 35, 36, -1, -1, -1, 40, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, -1, 35, 36, -1, -1, -1, 40, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, -1, 35, 36, -1, -1, 39, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, -1, 35, 36, -1, -1, 39, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, -1, 35, 36, -1, -1, - 39, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, -1, 35, 36, -1, - -1, 39, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, 35, 36, - -1, -1, 39, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, -1, 35, - 36, -1, -1, 39, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, -1, - 35, 36, -1, -1, 39, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - -1, 35, 36, -1, -1, 39, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, -1, 35, 36, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, -1, 35, - 36, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, -1, 35, 36, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - -1, 35, 36 -}; -/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ -#line 3 "/usr/share/misc/bison.simple" -/* This file comes from bison-1.28. */ - -/* Skeleton output parser for bison, - Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. - - 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, or (at your option) - any later version. - - This program 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 should 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. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* This is the parser code that is written into each bison parser - when the %semantic_parser declaration is not specified in the grammar. - It was written by Richard Stallman by simplifying the hairy parser - used when %semantic_parser is specified. */ - -#ifndef YYSTACK_USE_ALLOCA -#ifdef alloca -#define YYSTACK_USE_ALLOCA -#else /* alloca not defined */ -#ifdef __GNUC__ -#define YYSTACK_USE_ALLOCA -#define alloca __builtin_alloca -#else /* not GNU C. */ -#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) -#define YYSTACK_USE_ALLOCA -#include -#else /* not sparc */ -/* We think this test detects Watcom and Microsoft C. */ -/* This used to test MSDOS, but that is a bad idea - since that symbol is in the user namespace. */ -#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) -#if 0 /* No need for malloc.h, which pollutes the namespace; - instead, just don't use alloca. */ -#include -#endif -#else /* not MSDOS, or __TURBOC__ */ -#if defined(_AIX) -/* I don't know what this was needed for, but it pollutes the namespace. - So I turned it off. rms, 2 May 1997. */ -/* #include */ - #pragma alloca -#define YYSTACK_USE_ALLOCA -#else /* not MSDOS, or __TURBOC__, or _AIX */ -#if 0 -#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, - and on HPUX 10. Eventually we can turn this on. */ -#define YYSTACK_USE_ALLOCA -#define alloca __builtin_alloca -#endif /* __hpux */ -#endif -#endif /* not _AIX */ -#endif /* not MSDOS, or __TURBOC__ */ -#endif /* not sparc */ -#endif /* not GNU C */ -#endif /* alloca not defined */ -#endif /* YYSTACK_USE_ALLOCA not defined */ - -#ifdef YYSTACK_USE_ALLOCA -#define YYSTACK_ALLOC alloca -#else -#define YYSTACK_ALLOC malloc -#endif - -/* Note: there must be only one dollar sign in this file. - It is replaced by the list of actions, each action - as one case of the switch. */ - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY -2 -#define YYEOF 0 -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 -/* Like YYERROR except do call yyerror. - This remains here temporarily to ease the - transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ -#define YYFAIL goto yyerrlab -#define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(token, value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { yychar = (token), yylval = (value); \ - yychar1 = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ - goto yybackup; \ - } \ - else \ - { yyerror ("syntax error: cannot back up"); YYERROR; } \ -while (0) - -#define YYTERROR 1 -#define YYERRCODE 256 - -#ifndef YYPURE -#define YYLEX yylex() -#endif - -#ifdef YYPURE -#ifdef YYLSP_NEEDED -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval, &yylloc) -#endif -#else /* not YYLSP_NEEDED */ -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval) -#endif -#endif /* not YYLSP_NEEDED */ -#endif - -/* If nonreentrant, generate the variables here */ - -#ifndef YYPURE - -int yychar; /* the lookahead symbol */ -YYSTYPE yylval; /* the semantic value of the */ - /* lookahead symbol */ - -#ifdef YYLSP_NEEDED -YYLTYPE yylloc; /* location data for the lookahead */ - /* symbol */ -#endif - -int yynerrs; /* number of parse errors so far */ -#endif /* not YYPURE */ - -#if YYDEBUG != 0 -int yydebug; /* nonzero means print parse trace */ -/* Since this is uninitialized, it does not stop multiple parsers - from coexisting. */ -#endif - -/* YYINITDEPTH indicates the initial size of the parser's stacks */ - -#ifndef YYINITDEPTH -#define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH is the maximum size the stacks can grow to - (effective only if the built-in stack extension method is used). */ - -#if YYMAXDEPTH == 0 -#undef YYMAXDEPTH -#endif - -#ifndef YYMAXDEPTH -#define YYMAXDEPTH 10000 -#endif - -/* Define __yy_memcpy. Note that the size argument - should be passed with type unsigned int, because that is what the non-GCC - definitions require. With GCC, __builtin_memcpy takes an arg - of type size_t, but it can handle unsigned int. */ - -#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ -#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) -#else /* not GNU C or C++ */ -#ifndef __cplusplus - -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (to, from, count) - char *to; - char *from; - unsigned int count; -{ - register char *f = from; - register char *t = to; - register int i = count; - - while (i-- > 0) - *t++ = *f++; -} - -#else /* __cplusplus */ - -/* This is the most reliable way to avoid incompatibilities - in available built-in functions on various systems. */ -static void -__yy_memcpy (char *to, char *from, unsigned int count) -{ - register char *t = to; - register char *f = from; - register int i = count; - - while (i-- > 0) - *t++ = *f++; -} - -#endif -#endif - -#line 217 "/usr/share/misc/bison.simple" - -/* The user can define YYPARSE_PARAM as the name of an argument to be passed - into yyparse. The argument should have type void *. - It should actually point to an object. - Grammar actions can access the variable by casting it - to the proper pointer type. */ - -#ifdef YYPARSE_PARAM -#ifdef __cplusplus -#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM -#define YYPARSE_PARAM_DECL -#else /* not __cplusplus */ -#define YYPARSE_PARAM_ARG YYPARSE_PARAM -#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; -#endif /* not __cplusplus */ -#else /* not YYPARSE_PARAM */ -#define YYPARSE_PARAM_ARG -#define YYPARSE_PARAM_DECL -#endif /* not YYPARSE_PARAM */ - -/* Prevent warning if -Wstrict-prototypes. */ -#ifdef __GNUC__ -#ifdef YYPARSE_PARAM -int yyparse (void *); -#else -int yyparse (void); -#endif -#endif - -int -yyparse(YYPARSE_PARAM_ARG) - YYPARSE_PARAM_DECL -{ - register int yystate; - register int yyn; - register short *yyssp; - register YYSTYPE *yyvsp; - int yyerrstatus; /* number of tokens to shift before error messages enabled */ - int yychar1 = 0; /* lookahead token as an internal (translated) token number */ - - short yyssa[YYINITDEPTH]; /* the state stack */ - YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ - - short *yyss = yyssa; /* refer to the stacks thru separate pointers */ - YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ - -#ifdef YYLSP_NEEDED - YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; - -#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) -#else -#define YYPOPSTACK (yyvsp--, yyssp--) -#endif - - int yystacksize = YYINITDEPTH; - int yyfree_stacks = 0; - -#ifdef YYPURE - int yychar; - YYSTYPE yylval; - int yynerrs; -#ifdef YYLSP_NEEDED - YYLTYPE yylloc; -#endif -#endif - - YYSTYPE yyval; /* the variable used to return */ - /* semantic values from the action */ - /* routines */ - - int yylen; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Starting parse\n"); -#endif - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss - 1; - yyvsp = yyvs; -#ifdef YYLSP_NEEDED - yylsp = yyls; -#endif - -/* Push a new state, which is found in yystate . */ -/* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. */ -yynewstate: - - *++yyssp = yystate; - - if (yyssp >= yyss + yystacksize - 1) - { - /* Give user a chance to reallocate the stack */ - /* Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; -#ifdef YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; -#endif - - /* Get the current used size of the three stacks, in elements. */ - int size = yyssp - yyss + 1; - -#ifdef yyoverflow - /* Each stack pointer address is followed by the size of - the data in use in that stack, in bytes. */ -#ifdef YYLSP_NEEDED - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yyls1, size * sizeof (*yylsp), - &yystacksize); -#else - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yystacksize); -#endif - - yyss = yyss1; yyvs = yyvs1; -#ifdef YYLSP_NEEDED - yyls = yyls1; -#endif -#else /* no yyoverflow */ - /* Extend the stack our own way. */ - if (yystacksize >= YYMAXDEPTH) - { - yyerror("parser stack overflow"); - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 2; - } - yystacksize *= 2; - if (yystacksize > YYMAXDEPTH) - yystacksize = YYMAXDEPTH; -#ifndef YYSTACK_USE_ALLOCA - yyfree_stacks = 1; -#endif - yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); - __yy_memcpy ((char *)yyss, (char *)yyss1, - size * (unsigned int) sizeof (*yyssp)); - yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); - __yy_memcpy ((char *)yyvs, (char *)yyvs1, - size * (unsigned int) sizeof (*yyvsp)); -#ifdef YYLSP_NEEDED - yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); - __yy_memcpy ((char *)yyls, (char *)yyls1, - size * (unsigned int) sizeof (*yylsp)); -#endif -#endif /* no yyoverflow */ - - yyssp = yyss + size - 1; - yyvsp = yyvs + size - 1; -#ifdef YYLSP_NEEDED - yylsp = yyls + size - 1; -#endif - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Stack size increased to %d\n", yystacksize); -#endif - - if (yyssp >= yyss + yystacksize - 1) - YYABORT; - } - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Entering state %d\n", yystate); -#endif - - goto yybackup; - yybackup: - -/* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ -/* yyresume: */ - - /* First try to decide what to do without reference to lookahead token. */ - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* yychar is either YYEMPTY or YYEOF - or a valid token in external form. */ - - if (yychar == YYEMPTY) - { -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Reading a token: "); -#endif - yychar = YYLEX; - } - - /* Convert token to internal form (in yychar1) for indexing tables with */ - - if (yychar <= 0) /* This means end of input. */ - { - yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Now at end of input.\n"); -#endif - } - else - { - yychar1 = YYTRANSLATE(yychar); - -#if YYDEBUG != 0 - if (yydebug) - { - fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); - /* Give the individual parser a way to print the precise meaning - of a token, for further debugging info. */ -#ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); -#endif - fprintf (stderr, ")\n"); - } -#endif - } - - yyn += yychar1; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) - goto yydefault; - - yyn = yytable[yyn]; - - /* yyn is what to do for this token type in this state. - Negative => reduce, -yyn is rule number. - Positive => shift, yyn is new state. - New state is final state => don't bother to shift, - just return success. - 0, or most negative number => error. */ - - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrlab; - - if (yyn == YYFINAL) - YYACCEPT; - - /* Shift the lookahead token. */ - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); -#endif - - /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - /* count tokens shifted since error; after three, turn off error status. */ - if (yyerrstatus) yyerrstatus--; - - yystate = yyn; - goto yynewstate; - -/* Do the default action for the current state. */ -yydefault: - - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - -/* Do a reduction. yyn is the number of a rule to reduce with. */ -yyreduce: - yylen = yyr2[yyn]; - if (yylen > 0) - yyval = yyvsp[1-yylen]; /* implement default value of the action */ - -#if YYDEBUG != 0 - if (yydebug) - { - int i; - - fprintf (stderr, "Reducing via rule %d (line %d), ", - yyn, yyrline[yyn]); - - /* Print the symbols being reduced, and their result. */ - for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) - fprintf (stderr, "%s ", yytname[yyrhs[i]]); - fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); - } -#endif - - - switch (yyn) { - -case 5: -#line 186 "calc.y" -{ sp = stack[0]; yyerrok; ; - break;} -case 7: -#line 190 "calc.y" -{ - mpz_out_str (stdout, obase, sp); putchar ('\n'); - sp--; - CHECK_EMPTY (); - ; - break;} -case 8: -#line 195 "calc.y" -{ - CHECK_VARIABLE (yyvsp[-2].var); - mpz_swap (variable[yyvsp[-2].var], sp); - sp--; - CHECK_EMPTY (); - ; - break;} -case 9: -#line 201 "calc.y" -{ ibase = 16; obase = -16; ; - break;} -case 10: -#line 202 "calc.y" -{ ibase = 0; obase = 10; ; - break;} -case 11: -#line 203 "calc.y" -{ exit (0); ; - break;} -case 13: -#line 210 "calc.y" -{ sp--; mpz_add (sp, sp, sp+1); ; - break;} -case 14: -#line 211 "calc.y" -{ sp--; mpz_sub (sp, sp, sp+1); ; - break;} -case 15: -#line 212 "calc.y" -{ sp--; mpz_mul (sp, sp, sp+1); ; - break;} -case 16: -#line 213 "calc.y" -{ sp--; mpz_fdiv_q (sp, sp, sp+1); ; - break;} -case 17: -#line 214 "calc.y" -{ sp--; mpz_fdiv_r (sp, sp, sp+1); ; - break;} -case 18: -#line 215 "calc.y" -{ CHECK_UI ("exponentiation", sp); - sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); ; - break;} -case 19: -#line 217 "calc.y" -{ CHECK_UI ("lshift", sp); - sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); ; - break;} -case 20: -#line 219 "calc.y" -{ CHECK_UI ("rshift", sp); - sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); ; - break;} -case 21: -#line 221 "calc.y" -{ CHECK_UI ("factorial", sp); - mpz_fac_ui (sp, mpz_get_ui (sp)); ; - break;} -case 22: -#line 223 "calc.y" -{ mpz_neg (sp, sp); ; - break;} -case 23: -#line 225 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) < 0); ; - break;} -case 24: -#line 226 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); ; - break;} -case 25: -#line 227 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); ; - break;} -case 26: -#line 228 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); ; - break;} -case 27: -#line 229 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); ; - break;} -case 28: -#line 230 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) > 0); ; - break;} -case 29: -#line 232 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); ; - break;} -case 30: -#line 233 "calc.y" -{ sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); ; - break;} -case 31: -#line 235 "calc.y" -{ mpz_abs (sp, sp); ; - break;} -case 32: -#line 236 "calc.y" -{ sp--; CHECK_UI ("binomial", sp+1); - mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); ; - break;} -case 33: -#line 238 "calc.y" -{ CHECK_UI ("fibonacci", sp); - mpz_fib_ui (sp, mpz_get_ui (sp)); ; - break;} -case 36: -#line 242 "calc.y" -{ mpz_nextprime (sp, sp); ; - break;} -case 37: -#line 243 "calc.y" -{ sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); ; - break;} -case 38: -#line 244 "calc.y" -{ sp--; CHECK_UI ("nth-root", sp+1); - mpz_root (sp, sp, mpz_get_ui (sp+1)); ; - break;} -case 39: -#line 246 "calc.y" -{ mpz_sqrt (sp, sp); ; - break;} -case 40: -#line 248 "calc.y" -{ - sp++; - CHECK_OVERFLOW (); - CHECK_VARIABLE (yyvsp[0].var); - mpz_set (sp, variable[yyvsp[0].var]); - ; - break;} -case 41: -#line 254 "calc.y" -{ - sp++; - CHECK_OVERFLOW (); - if (mpz_set_str (sp, yyvsp[0].str, ibase) != 0) - { - fprintf (stderr, "Invalid number: %s\n", yyvsp[0].str); - YYERROR; - } - ; - break;} -case 43: -#line 266 "calc.y" -{ sp--; mpz_gcd (sp, sp, sp+1); ; - break;} -case 45: -#line 270 "calc.y" -{ sp--; mpz_lcm (sp, sp, sp+1); ; - break;} -} - /* the action file gets copied in in place of this dollarsign */ -#line 543 "/usr/share/misc/bison.simple" - - yyvsp -= yylen; - yyssp -= yylen; -#ifdef YYLSP_NEEDED - yylsp -= yylen; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif - - *++yyvsp = yyval; - -#ifdef YYLSP_NEEDED - yylsp++; - if (yylen == 0) - { - yylsp->first_line = yylloc.first_line; - yylsp->first_column = yylloc.first_column; - yylsp->last_line = (yylsp-1)->last_line; - yylsp->last_column = (yylsp-1)->last_column; - yylsp->text = 0; - } - else - { - yylsp->last_line = (yylsp+yylen-1)->last_line; - yylsp->last_column = (yylsp+yylen-1)->last_column; - } -#endif - - /* Now "shift" the result of the reduction. - Determine what state that goes to, - based on the state we popped back to - and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTBASE] + *yyssp; - if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTBASE]; - - goto yynewstate; - -yyerrlab: /* here on detecting error */ - - if (! yyerrstatus) - /* If not already recovering from an error, report this error. */ - { - ++yynerrs; - -#ifdef YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (yyn > YYFLAG && yyn < YYLAST) - { - int size = 0; - char *msg; - int x, count; - - count = 0; - /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - size += strlen(yytname[x]) + 15, count++; - msg = (char *) malloc(size + 15); - if (msg != 0) - { - strcpy(msg, "parse error"); - - if (count < 5) - { - count = 0; - for (x = (yyn < 0 ? -yyn : 0); - x < (sizeof(yytname) / sizeof(char *)); x++) - if (yycheck[x + yyn] == x) - { - strcat(msg, count == 0 ? ", expecting `" : " or `"); - strcat(msg, yytname[x]); - strcat(msg, "'"); - count++; - } - } - yyerror(msg); - free(msg); - } - else - yyerror ("parse error; also virtual memory exceeded"); - } - else -#endif /* YYERROR_VERBOSE */ - yyerror("parse error"); - } - - goto yyerrlab1; -yyerrlab1: /* here on error raised explicitly by an action */ - - if (yyerrstatus == 3) - { - /* if just tried and failed to reuse lookahead token after an error, discard it. */ - - /* return failure if at end of input */ - if (yychar == YYEOF) - YYABORT; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); -#endif - - yychar = YYEMPTY; - } - - /* Else will try to reuse lookahead token - after shifting the error token. */ - - yyerrstatus = 3; /* Each real token shifted decrements this */ - - goto yyerrhandle; - -yyerrdefault: /* current state does not do anything special for the error token. */ - -#if 0 - /* This is wrong; only states that explicitly want error tokens - should shift them. */ - yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ - if (yyn) goto yydefault; -#endif - -yyerrpop: /* pop the current state because it cannot handle the error token */ - - if (yyssp == yyss) YYABORT; - yyvsp--; - yystate = *--yyssp; -#ifdef YYLSP_NEEDED - yylsp--; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "Error: state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif - -yyerrhandle: - - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yyerrdefault; - - yyn += YYTERROR; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) - goto yyerrdefault; - - yyn = yytable[yyn]; - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrpop; - yyn = -yyn; - goto yyreduce; - } - else if (yyn == 0) - goto yyerrpop; - - if (yyn == YYFINAL) - YYACCEPT; - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting error token, "); -#endif - - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif - - yystate = yyn; - goto yynewstate; - - yyacceptlab: - /* YYACCEPT comes here. */ - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 0; - - yyabortlab: - /* YYABORT comes here. */ - if (yyfree_stacks) - { - free (yyss); - free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif - } - return 1; -} -#line 272 "calc.y" - - -yyerror (char *s) -{ - fprintf (stderr, "%s\n", s); -} - -int -main (void) -{ - int i; - - for (i = 0; i < numberof (variable); i++) - mpz_init (variable[i]); - - for (i = 0; i < numberof (stack); i++) - mpz_init (stack[i]); - - return yyparse (); -} diff --git a/gmp/demos/calc.h b/gmp/demos/calc.h deleted file mode 100755 index 98e745a..0000000 --- a/gmp/demos/calc.h +++ /dev/null @@ -1,32 +0,0 @@ -typedef union { - char *str; - int var; -} YYSTYPE; -#define EOS 257 -#define BAD 258 -#define HEX 259 -#define DECIMAL 260 -#define QUIT 261 -#define ABS 262 -#define BIN 263 -#define FIB 264 -#define GCD 265 -#define LCM 266 -#define NEXTPRIME 267 -#define POWM 268 -#define ROOT 269 -#define SQRT 270 -#define NUMBER 271 -#define VARIABLE 272 -#define LOR 273 -#define LAND 274 -#define EQ 275 -#define NE 276 -#define LE 277 -#define GE 278 -#define LSHIFT 279 -#define RSHIFT 280 -#define UMINUS 281 - - -extern YYSTYPE yylval; diff --git a/gmp/demos/calc.y b/gmp/demos/calc.y deleted file mode 100755 index d8637ae..0000000 Binary files a/gmp/demos/calc.y and /dev/null differ diff --git a/gmp/demos/calclex.c b/gmp/demos/calclex.c deleted file mode 100755 index d782c90..0000000 --- a/gmp/demos/calclex.c +++ /dev/null @@ -1,1671 +0,0 @@ -#line 2 "calclex.c" -/* A lexical scanner generated by flex */ - -/* Scanner skeleton version: - * $FreeBSD: src/usr.bin/lex/skel.c,v 1.2.2.1 1999/08/29 15:29:33 peter Exp $ - */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 - -#include - - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - -#include -#include - -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_PROTOS -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include -#include -#define YY_USE_CONST -#define YY_USE_PROTOS -#endif - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - - -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto -#else -#define YY_PROTO(proto) () -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#define YY_BUF_SIZE 16384 - -typedef struct yy_buffer_state *YY_BUFFER_STATE; - -extern int yyleng; -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * yyless( 5 ); - * else - * do_something_else(); - * - * Prior to using the do-while the compiler would get upset at the - * "else" because it interpreted the "if" statement as being all - * done when it reached the ';' after the yyless() call. - */ - -/* Return all but the first 'n' matched characters back to the input stream. */ - -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yytext_ptr ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ -typedef unsigned int yy_size_t; - - -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - }; - -static YY_BUFFER_STATE yy_current_buffer = 0; - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - */ -#define YY_CURRENT_BUFFER yy_current_buffer - - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; - -static int yy_n_chars; /* number of characters read into yy_ch_buf */ - - -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart YY_PROTO(( FILE *input_file )); - -void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); -void yy_load_buffer_state YY_PROTO(( void )); -YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); -void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); -void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); -void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) - -YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); -YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); - -static void *yy_flex_alloc YY_PROTO(( yy_size_t )); -static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); -static void yy_flex_free YY_PROTO(( void * )); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) - -typedef unsigned char YY_CHAR; -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; -typedef int yy_state_type; -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state YY_PROTO(( void )); -static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); -static int yy_get_next_buffer YY_PROTO(( void )); -static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 19 -#define YY_END_OF_BUFFER 20 -static yyconst short int yy_accept[39] = - { 0, - 0, 0, 20, 18, 1, 2, 7, 6, 7, 18, - 16, 16, 2, 7, 7, 7, 16, 17, 18, 18, - 11, 6, 5, 6, 14, 16, 0, 12, 8, 10, - 9, 13, 16, 17, 3, 15, 4, 0 - } ; - -static yyconst int yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 1, 5, 1, 6, 7, 1, 6, - 6, 6, 6, 6, 6, 1, 6, 8, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 1, 10, 11, - 12, 13, 1, 1, 14, 14, 14, 14, 14, 14, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 16, 15, 15, - 1, 17, 1, 6, 1, 1, 15, 15, 15, 15, - - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, - 15, 15, 1, 18, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst int yy_meta[19] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, - 1, 1, 1, 2, 3, 2, 1, 1 - } ; - -static yyconst short int yy_base[43] = - { 0, - 0, 0, 39, 49, 49, 49, 26, 16, 49, 30, - 20, 19, 49, 9, 22, 10, 9, 0, 29, 13, - 49, 23, 49, 24, 49, 0, 0, 49, 49, 49, - 49, 49, 13, 0, 49, 49, 49, 49, 41, 28, - 43, 45 - } ; - -static yyconst short int yy_def[43] = - { 0, - 38, 1, 38, 38, 38, 38, 38, 39, 38, 38, - 40, 40, 38, 38, 38, 38, 41, 42, 38, 38, - 38, 39, 38, 39, 38, 12, 12, 38, 38, 38, - 38, 38, 41, 42, 38, 38, 38, 0, 38, 38, - 38, 38 - } ; - -static yyconst short int yy_nxt[68] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 18, 19, 20, 23, 28, - 29, 31, 32, 34, 34, 23, 37, 34, 34, 26, - 36, 35, 24, 30, 38, 27, 25, 21, 38, 24, - 24, 22, 22, 22, 33, 33, 34, 34, 3, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - 38, 38, 38, 38, 38, 38, 38 - } ; - -static yyconst short int yy_chk[68] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 8, 14, - 14, 16, 16, 17, 17, 22, 24, 33, 33, 40, - 20, 19, 8, 15, 12, 11, 10, 7, 3, 22, - 24, 39, 39, 39, 41, 41, 42, 42, 38, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - 38, 38, 38, 38, 38, 38, 38 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "calclex.l" -#define INITIAL 0 -/* Lexical analyzer for calc.y. */ -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -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 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 should 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. -*/ -#line 24 "calclex.l" -#include "calc.h" - -#define numberof(x) (sizeof (x) / sizeof ((x)[0])) -#line 411 "calclex.c" - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap YY_PROTO(( void )); -#else -extern int yywrap YY_PROTO(( void )); -#endif -#endif - -#ifndef YY_NO_UNPUT -static void yyunput YY_PROTO(( int c, char *buf_ptr )); -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen YY_PROTO(( yyconst char * )); -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus -static int yyinput YY_PROTO(( void )); -#else -static int input YY_PROTO(( void )); -#endif -#endif - -#if YY_STACK_USED -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int *yy_start_stack = 0; -#ifndef YY_NO_PUSH_STATE -static void yy_push_state YY_PROTO(( int new_state )); -#endif -#ifndef YY_NO_POP_STATE -static void yy_pop_state YY_PROTO(( void )); -#endif -#ifndef YY_NO_TOP_STATE -static int yy_top_state YY_PROTO(( void )); -#endif - -#else -#define YY_NO_PUSH_STATE 1 -#define YY_NO_POP_STATE 1 -#define YY_NO_TOP_STATE 1 -#endif - -#ifdef YY_MALLOC_DECL -YY_MALLOC_DECL -#else -#if __STDC__ -#ifndef __cplusplus -#include -#endif -#else -/* Just try to get by without declaring the routines. This will fail - * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) - * or sizeof(void*) != sizeof(int). - */ -#endif -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ - -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( yy_current_buffer->yy_is_interactive ) \ - { \ - int c = '*', n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL int yylex YY_PROTO(( void )) -#endif - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -YY_DECL - { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 29 "calclex.l" - - -#line 565 "calclex.c" - - if ( yy_init ) - { - yy_init = 0; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yy_start ) - yy_start = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! yy_current_buffer ) - yy_current_buffer = - yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_load_buffer_state(); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yy_start; -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 39 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 49 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - - -do_action: /* This label is used only to access EOF actions. */ - - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yy_hold_char; - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 31 "calclex.l" -{ /* white space is skipped */ } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 33 "calclex.l" -{ /* semicolon or newline separates statements */ - return EOS; } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 35 "calclex.l" -{ /* escaped newlines are skipped */ } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 38 "calclex.l" -{ - /* comment through to escaped newline is skipped */ } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 40 "calclex.l" -{ /* comment through to newline is a separator */ - return EOS; } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 42 "calclex.l" -{ /* comment through to EOF skipped */ } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 45 "calclex.l" -{ return yytext[0]; } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 46 "calclex.l" -{ return LE; } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 47 "calclex.l" -{ return GE; } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 48 "calclex.l" -{ return EQ; } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 49 "calclex.l" -{ return NE; } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 50 "calclex.l" -{ return LSHIFT; } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 51 "calclex.l" -{ return RSHIFT; } - YY_BREAK -case 14: -YY_RULE_SETUP -#line 52 "calclex.l" -{ return LAND; } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 53 "calclex.l" -{ return LOR; } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 55 "calclex.l" -{ - yylval.str = yytext; - return NUMBER; } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 59 "calclex.l" -{ - static struct { - char *name; - int value; - } table[] = { - { "abs", ABS }, - { "bin", BIN }, - { "decimal", DECIMAL }, - { "fib", FIB }, - { "hex", HEX }, - { "gcd", GCD }, - { "lcm", LCM }, - { "nextprime", NEXTPRIME }, - { "powm", POWM }, - { "quit", QUIT }, - { "root", ROOT }, - { "sqrt", SQRT }, - }; - int i; - - for (i = 0; i < numberof (table); i++) - if (strcmp (yytext, table[i].name) == 0) - return table[i].value; - - if (yytext[0] >= 'a' && yytext[0] <= 'z' && yytext[1] == '\0') - { - yylval.var = yytext[0] - 'a'; - return VARIABLE; - } - - return BAD; -} - YY_BREAK -case 18: -YY_RULE_SETUP -#line 92 "calclex.l" -{ return BAD; } - YY_BREAK -case 19: -YY_RULE_SETUP -#line 94 "calclex.l" -ECHO; - YY_BREAK -#line 779 "calclex.c" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between yy_current_buffer and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yy_n_chars = yy_current_buffer->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yy_c_buf_p; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer() ) - { - case EOB_ACT_END_OF_FILE: - { - yy_did_buffer_switch_on_eof = 0; - - if ( yywrap() ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = - yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yy_c_buf_p = - &yy_current_buffer->yy_ch_buf[yy_n_chars]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of yylex */ - - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ - -static int yy_get_next_buffer() - { - register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr; - register int number_to_move, i; - int ret_val; - - if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( yy_current_buffer->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - yy_current_buffer->yy_n_chars = yy_n_chars = 0; - - else - { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ -#ifdef YY_USES_REJECT - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); -#else - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = yy_current_buffer; - - int yy_c_buf_p_offset = - (int) (yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yy_flex_realloc( (void *) b->yy_ch_buf, - b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = yy_current_buffer->yy_buf_size - - number_to_move - 1; -#endif - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read ); - - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - if ( yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - yy_n_chars += number_to_move; - yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; - - return ret_val; - } - - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -static yy_state_type yy_get_previous_state() - { - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = yy_start; - - for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 39 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; - } - - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - -#ifdef YY_USE_PROTOS -static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) -#else -static yy_state_type yy_try_NUL_trans( yy_current_state ) -yy_state_type yy_current_state; -#endif - { - register int yy_is_jam; - register char *yy_cp = yy_c_buf_p; - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 39 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 38); - - return yy_is_jam ? 0 : yy_current_state; - } - - -#ifndef YY_NO_UNPUT -#ifdef YY_USE_PROTOS -static void yyunput( int c, register char *yy_bp ) -#else -static void yyunput( c, yy_bp ) -int c; -register char *yy_bp; -#endif - { - register char *yy_cp = yy_c_buf_p; - - /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = yy_n_chars + 2; - register char *dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; - register char *source = - &yy_current_buffer->yy_ch_buf[number_to_move]; - - while ( source > yy_current_buffer->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - yy_current_buffer->yy_n_chars = - yy_n_chars = yy_current_buffer->yy_buf_size; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; - } -#endif /* ifndef YY_NO_UNPUT */ - - -#ifdef __cplusplus -static int yyinput() -#else -static int input() -#endif - { - int c; - - *yy_c_buf_p = yy_hold_char; - - if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - /* This was really a NUL. */ - *yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = yy_c_buf_p - yytext_ptr; - ++yy_c_buf_p; - - switch ( yy_get_next_buffer() ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /* fall through */ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap() ) - return EOF; - - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ - yy_hold_char = *++yy_c_buf_p; - - - return c; - } - - -#ifdef YY_USE_PROTOS -void yyrestart( FILE *input_file ) -#else -void yyrestart( input_file ) -FILE *input_file; -#endif - { - if ( ! yy_current_buffer ) - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_init_buffer( yy_current_buffer, input_file ); - yy_load_buffer_state(); - } - - -#ifdef YY_USE_PROTOS -void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -#else -void yy_switch_to_buffer( new_buffer ) -YY_BUFFER_STATE new_buffer; -#endif - { - if ( yy_current_buffer == new_buffer ) - return; - - if ( yy_current_buffer ) - { - /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - yy_current_buffer = new_buffer; - yy_load_buffer_state(); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yy_did_buffer_switch_on_eof = 1; - } - - -#ifdef YY_USE_PROTOS -void yy_load_buffer_state( void ) -#else -void yy_load_buffer_state() -#endif - { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; - } - - -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) -#else -YY_BUFFER_STATE yy_create_buffer( file, size ) -FILE *file; -int size; -#endif - { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; - } - - -#ifdef YY_USE_PROTOS -void yy_delete_buffer( YY_BUFFER_STATE b ) -#else -void yy_delete_buffer( b ) -YY_BUFFER_STATE b; -#endif - { - if ( ! b ) - return; - - if ( b == yy_current_buffer ) - yy_current_buffer = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yy_flex_free( (void *) b->yy_ch_buf ); - - yy_flex_free( (void *) b ); - } - - -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO(( int )); -#endif -#endif - -#ifdef YY_USE_PROTOS -void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) -#else -void yy_init_buffer( b, file ) -YY_BUFFER_STATE b; -FILE *file; -#endif - - - { - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - -#if YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; -#else -#if YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; -#else - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; -#endif -#endif - } - - -#ifdef YY_USE_PROTOS -void yy_flush_buffer( YY_BUFFER_STATE b ) -#else -void yy_flush_buffer( b ) -YY_BUFFER_STATE b; -#endif - - { - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == yy_current_buffer ) - yy_load_buffer_state(); - } - - -#ifndef YY_NO_SCAN_BUFFER -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) -#else -YY_BUFFER_STATE yy_scan_buffer( base, size ) -char *base; -yy_size_t size; -#endif - { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b ); - - return b; - } -#endif - - -#ifndef YY_NO_SCAN_STRING -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) -#else -YY_BUFFER_STATE yy_scan_string( yy_str ) -yyconst char *yy_str; -#endif - { - int len; - for ( len = 0; yy_str[len]; ++len ) - ; - - return yy_scan_bytes( yy_str, len ); - } -#endif - - -#ifndef YY_NO_SCAN_BYTES -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) -#else -YY_BUFFER_STATE yy_scan_bytes( bytes, len ) -yyconst char *bytes; -int len; -#endif - { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yy_flex_alloc( n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; - - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; - } -#endif - - -#ifndef YY_NO_PUSH_STATE -#ifdef YY_USE_PROTOS -static void yy_push_state( int new_state ) -#else -static void yy_push_state( new_state ) -int new_state; -#endif - { - if ( yy_start_stack_ptr >= yy_start_stack_depth ) - { - yy_size_t new_size; - - yy_start_stack_depth += YY_START_STACK_INCR; - new_size = yy_start_stack_depth * sizeof( int ); - - if ( ! yy_start_stack ) - yy_start_stack = (int *) yy_flex_alloc( new_size ); - - else - yy_start_stack = (int *) yy_flex_realloc( - (void *) yy_start_stack, new_size ); - - if ( ! yy_start_stack ) - YY_FATAL_ERROR( - "out of memory expanding start-condition stack" ); - } - - yy_start_stack[yy_start_stack_ptr++] = YY_START; - - BEGIN(new_state); - } -#endif - - -#ifndef YY_NO_POP_STATE -static void yy_pop_state() - { - if ( --yy_start_stack_ptr < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN(yy_start_stack[yy_start_stack_ptr]); - } -#endif - - -#ifndef YY_NO_TOP_STATE -static int yy_top_state() - { - return yy_start_stack[yy_start_stack_ptr - 1]; - } -#endif - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -#ifdef YY_USE_PROTOS -static void yy_fatal_error( yyconst char msg[] ) -#else -static void yy_fatal_error( msg ) -char msg[]; -#endif - { - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); - } - - - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ - } \ - while ( 0 ) - - -/* Internal utility routines. */ - -#ifndef yytext_ptr -#ifdef YY_USE_PROTOS -static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) -#else -static void yy_flex_strncpy( s1, s2, n ) -char *s1; -yyconst char *s2; -int n; -#endif - { - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; - } -#endif - -#ifdef YY_NEED_STRLEN -#ifdef YY_USE_PROTOS -static int yy_flex_strlen( yyconst char *s ) -#else -static int yy_flex_strlen( s ) -yyconst char *s; -#endif - { - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; - } -#endif - - -#ifdef YY_USE_PROTOS -static void *yy_flex_alloc( yy_size_t size ) -#else -static void *yy_flex_alloc( size ) -yy_size_t size; -#endif - { - return (void *) malloc( size ); - } - -#ifdef YY_USE_PROTOS -static void *yy_flex_realloc( void *ptr, yy_size_t size ) -#else -static void *yy_flex_realloc( ptr, size ) -void *ptr; -yy_size_t size; -#endif - { - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); - } - -#ifdef YY_USE_PROTOS -static void yy_flex_free( void *ptr ) -#else -static void yy_flex_free( ptr ) -void *ptr; -#endif - { - free( ptr ); - } - -#if YY_MAIN -int main() - { - yylex(); - return 0; - } -#endif -#line 94 "calclex.l" - - -int -yywrap () -{ - return 1; -} diff --git a/gmp/demos/calclex.l b/gmp/demos/calclex.l deleted file mode 100755 index b874d0a..0000000 Binary files a/gmp/demos/calclex.l and /dev/null differ diff --git a/gmp/demos/factorize.c b/gmp/demos/factorize.c deleted file mode 100755 index d776e6b..0000000 --- a/gmp/demos/factorize.c +++ /dev/null @@ -1,363 +0,0 @@ -/* Factoring with Pollard's rho method. - - Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - - 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, or (at your option) any - later version. - - This program 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 should have received a copy of the GNU General Public License along - with this program; see the file COPYING. If not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -#include -#include -#include - -#include "gmp.h" - -int flag_verbose = 0; - -static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6}; - -#if defined (__hpux) || defined (__alpha) || defined (__svr4__) || defined (__SVR4) -/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */ -long mrand48 (); -static long -random () -{ - return mrand48 (); -} -#else -/* Glibc stdlib.h has "int32_t random();" which, on i386 at least, conflicts - with a redeclaration as "long". */ -#ifndef __GLIBC__ -long random (); -#endif -#endif - -void -factor_using_division (mpz_t t, unsigned int limit) -{ - mpz_t q, r; - unsigned long int f; - int ai; - unsigned *addv = add; - unsigned int failures; - - if (flag_verbose) - { - printf ("[trial division (%u)] ", limit); - fflush (stdout); - } - - mpz_init (q); - mpz_init (r); - - f = mpz_scan1 (t, 0); - mpz_div_2exp (t, t, f); - while (f) - { - printf ("2 "); - fflush (stdout); - --f; - } - - for (;;) - { - mpz_tdiv_qr_ui (q, r, t, 3); - if (mpz_cmp_ui (r, 0) != 0) - break; - mpz_set (t, q); - printf ("3 "); - fflush (stdout); - } - - for (;;) - { - mpz_tdiv_qr_ui (q, r, t, 5); - if (mpz_cmp_ui (r, 0) != 0) - break; - mpz_set (t, q); - printf ("5 "); - fflush (stdout); - } - - failures = 0; - f = 7; - ai = 0; - while (mpz_cmp_ui (t, 1) != 0) - { - mpz_tdiv_qr_ui (q, r, t, f); - if (mpz_cmp_ui (r, 0) != 0) - { - f += addv[ai]; - if (mpz_cmp_ui (q, f) < 0) - break; - ai = (ai + 1) & 7; - failures++; - if (failures > limit) - break; - } - else - { - mpz_swap (t, q); - printf ("%lu ", f); - fflush (stdout); - failures = 0; - } - } - - mpz_clear (q); - mpz_clear (r); -} - -void -factor_using_division_2kp (mpz_t t, unsigned int limit, unsigned long p) -{ - mpz_t r; - mpz_t f; - unsigned int k; - - mpz_init (r); - mpz_init_set_ui (f, 2 * p); - mpz_add_ui (f, f, 1); - for (k = 1; k < limit; k++) - { - mpz_tdiv_r (r, t, f); - while (mpz_cmp_ui (r, 0) == 0) - { - mpz_tdiv_q (t, t, f); - mpz_tdiv_r (r, t, f); - mpz_out_str (stdout, 10, f); - fflush (stdout); - fputc (' ', stdout); - } - mpz_add_ui (f, f, 2 * p); - } - - mpz_clear (f); - mpz_clear (r); -} - -void -factor_using_pollard_rho (mpz_t n, int a_int, unsigned long p) -{ - mpz_t x, x1, y, P; - mpz_t a; - mpz_t g; - mpz_t t1, t2; - int k, l, c, i; - - if (flag_verbose) - { - printf ("[pollard-rho (%d)] ", a_int); - fflush (stdout); - } - - mpz_init (g); - mpz_init (t1); - mpz_init (t2); - - mpz_init_set_si (a, a_int); - mpz_init_set_si (y, 2); - mpz_init_set_si (x, 2); - mpz_init_set_si (x1, 2); - k = 1; - l = 1; - mpz_init_set_ui (P, 1); - c = 0; - - while (mpz_cmp_ui (n, 1) != 0) - { -S2: - if (p != 0) - { - mpz_powm_ui (x, x, p, n); mpz_add (x, x, a); - } - else - { - mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n); - } - mpz_sub (t1, x1, x); mpz_mul (t2, P, t1); mpz_mod (P, t2, n); - c++; - if (c == 20) - { - c = 0; - mpz_gcd (g, P, n); - if (mpz_cmp_ui (g, 1) != 0) - goto S4; - mpz_set (y, x); - } -S3: - k--; - if (k != 0) - goto S2; - - mpz_gcd (g, P, n); - if (mpz_cmp_ui (g, 1) != 0) - goto S4; - - mpz_set (x1, x); - k = l; - l = 2 * l; - for (i = 0; i < k; i++) - { - if (p != 0) - { - mpz_powm_ui (x, x, p, n); mpz_add (x, x, a); - } - else - { - mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n); - } - } - mpz_set (y, x); - c = 0; - goto S2; -S4: - do - { - if (p != 0) - { - mpz_powm_ui (y, y, p, n); mpz_add (y, y, a); - } - else - { - mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n); - } - mpz_sub (t1, x1, y); mpz_gcd (g, t1, n); - } - while (mpz_cmp_ui (g, 1) == 0); - - if (!mpz_probab_prime_p (g, 3)) - { - do - a_int = random (); - while (a_int == -2 || a_int == 0); - - if (flag_verbose) - { - printf ("[composite factor--restarting pollard-rho] "); - fflush (stdout); - } - factor_using_pollard_rho (g, a_int, p); - break; - } - else - { - mpz_out_str (stdout, 10, g); - fflush (stdout); - fputc (' ', stdout); - } - mpz_div (n, n, g); - mpz_mod (x, x, n); - mpz_mod (x1, x1, n); - mpz_mod (y, y, n); - if (mpz_probab_prime_p (n, 3)) - { - mpz_out_str (stdout, 10, n); - fflush (stdout); - fputc (' ', stdout); - break; - } - } - - mpz_clear (g); - mpz_clear (P); - mpz_clear (t2); - mpz_clear (t1); - mpz_clear (a); - mpz_clear (x1); - mpz_clear (x); - mpz_clear (y); -} - -void -factor (mpz_t t, unsigned long p) -{ - unsigned int division_limit; - - /* Set the trial division limit according the size of t. */ - division_limit = mpz_sizeinbase (t, 2); - if (division_limit > 1000) - division_limit = 1000 * 1000; - else - division_limit = division_limit * division_limit; - - if (p != 0) - factor_using_division_2kp (t, division_limit / 10, p); - else - factor_using_division (t, division_limit); - - if (mpz_cmp_ui (t, 1) != 0) - { - if (flag_verbose) - { - printf ("[is number prime?] "); - fflush (stdout); - } - if (mpz_probab_prime_p (t, 3)) - mpz_out_str (stdout, 10, t); - else - factor_using_pollard_rho (t, 1, p); - } -} - -main (int argc, char *argv[]) -{ - mpz_t t; - unsigned long p; - int i; - - if (argc > 1 && !strcmp (argv[1], "-v")) - { - flag_verbose = 1; - argv++; - argc--; - } - - p = 0; - for (i = 1; i < argc; i++) - { - if (!strncmp (argv[i], "-Mp", 3)) - { - p = atoi (argv[i] + 3); - mpz_init_set_ui (t, 1); - mpz_mul_2exp (t, t, p); - mpz_sub_ui (t, t, 1); - } - else if (!strncmp (argv[i], "-2kp", 4)) - { - p = atoi (argv[i] + 4); - continue; - } - else - { - mpz_init_set_str (t, argv[i], 0); - } - - if (mpz_cmp_ui (t, 0) == 0) - puts ("-"); - else - { - factor (t, p); - puts (""); - } - } - exit (0); -} - -void -dmp (mpz_t x) -{ - mpz_out_str (stdout, 10, x); - puts (""); -} diff --git a/gmp/demos/isprime.c b/gmp/demos/isprime.c deleted file mode 100755 index c31ba5b..0000000 --- a/gmp/demos/isprime.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Classify numbers as probable primes, primes or composites. - With -q return true if the folowing argument is a (probable) prime. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -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 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 should 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. */ - -#include -#include "gmp.h" - -char *progname; - -main (int argc, char **argv) -{ - mpz_t n; - int i; - - progname = argv[0]; - - if (argc < 2) - print_usage_and_exit (); - - mpz_init (n); - - if (argc == 3 && strcmp (argv[1], "-q") == 0) - { - if (mpz_set_str (n, argv[2], 0) != 0) - print_usage_and_exit (); - exit (mpz_probab_prime_p (n, 5) == 0); - } - - for (i = 1; i < argc; i++) - { - int class; - if (mpz_set_str (n, argv[i], 0) != 0) - print_usage_and_exit (); - class = mpz_probab_prime_p (n, 5); - mpz_out_str (stdout, 10, n); - if (class == 0) - puts (" is composite"); - else if (class == 1) - puts (" is a probable prime"); - else /* class == 2 */ - puts (" is a prime"); - } - exit (0); -} - -print_usage_and_exit () -{ - fprintf (stderr, "usage: %s -q nnn\n", progname); - fprintf (stderr, "usage: %s nnn ...\n", progname); - exit (-1); -} diff --git a/gmp/demos/pexpr.c b/gmp/demos/pexpr.c deleted file mode 100755 index c7d6ab4..0000000 --- a/gmp/demos/pexpr.c +++ /dev/null @@ -1,1206 +0,0 @@ -/* Program for computing integer expressions using the GNU Multiple Precision - Arithmetic Library. - -Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc. - -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 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 should 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 expressions evaluator works by building an expression tree (using a - recursive descent parser) which is then evaluated. The expression tree is - useful since we want to optimize certain expressions (like a^b % c). - - Usage: pexpr [options] expr ... - (Assuming you called the executable `pexpr' of course.) - - Command line options: - - -b print output in binary - -o print output in octal - -d print output in decimal (the default) - -x print output in hexadecimal - - print output in base NUM - -t print timing information - -html output html - -nosplit do not split long lines each 60th digit -*/ - -/* Define LIMIT_RESOURCE_USAGE if you want to make sure the program doesn't - use up extensive resources (cpu, memory). Useful for the GMP demo on the - GMP web site, since we cannot load the server too much. */ - -#ifdef LIMIT_RESOURCE_USAGE -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include - -#include "gmp.h" - -/* GMP version 1.x compatibility. */ -#if ! (__GNU_MP_VERSION >= 2) -typedef MP_INT __mpz_struct; -typedef __mpz_struct mpz_t[1]; -typedef __mpz_struct *mpz_ptr; -#define mpz_fdiv_q mpz_div -#define mpz_fdiv_r mpz_mod -#define mpz_tdiv_q_2exp mpz_div_2exp -#define mpz_sgn(Z) ((Z)->size < 0 ? -1 : (Z)->size > 0) -#endif - -/* GMP version 2.0 compatibility. */ -#if ! (__GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1) -#define mpz_swap(a,b) \ - do { __mpz_struct __t; __t = *a; *a = *b; *b = __t;} while (0) -#endif - -jmp_buf errjmpbuf; - -enum op_t {NOP, LIT, NEG, NOT, PLUS, MINUS, MULT, DIV, MOD, REM, INVMOD, POW, - AND, IOR, XOR, SLL, SRA, POPCNT, HAMDIST, GCD, LCM, SQRT, ROOT, FAC, - LOG, LOG2, FERMAT, MERSENNE, FIBONACCI}; - -/* Type for the expression tree. */ -struct expr -{ - enum op_t op; - union - { - struct {struct expr *lhs, *rhs;} ops; - mpz_t val; - } operands; -}; - -typedef struct expr *expr_t; - -void cleanup_and_exit (int); - -char *skipspace (char *); -void makeexp (expr_t *, enum op_t, expr_t, expr_t); -void free_expr (expr_t); -char *expr (char *, expr_t *); -char *term (char *, expr_t *); -char *power (char *, expr_t *); -char *factor (char *, expr_t *); -int match (char *, char *); -int matchp (char *, char *); -int cputime (void); - -void mpz_eval_expr (mpz_ptr, expr_t); -void mpz_eval_mod_expr (mpz_ptr, expr_t, mpz_ptr); - -char *error; -int flag_print = 1; -int print_timing = 0; -int flag_html = 0; -int flag_splitup_output = 0; -char *newline = ""; - -#ifdef _AIX -#define sigaltstack sigstack -#endif - -#if !defined(_WIN32) && !defined(__DJGPP__) -void -setup_error_handler () -{ - struct sigaction act; - struct sigaltstack sigstk; - - /* Set up a stack for signal handling. A typical cause of error is stack - overflow, and in such situation a signal can not be delivered on the - overflown stack. */ - sigstk.ss_sp = malloc (SIGSTKSZ); -#ifndef _AIX - sigstk.ss_size = SIGSTKSZ; - sigstk.ss_flags = 0; -#endif /* ! _AIX */ - -#ifndef _UNICOS - if (sigaltstack (&sigstk, 0) < 0) - perror("sigaltstack"); -#endif - - /* Initialize structure for sigaction (called below). */ - act.sa_handler = cleanup_and_exit; - sigemptyset (&(act.sa_mask)); - act.sa_flags = SA_ONSTACK; - -#ifdef LIMIT_RESOURCE_USAGE - { - struct rlimit limit; - - limit.rlim_cur = limit.rlim_max = 0; - setrlimit (RLIMIT_CORE, &limit); - - limit.rlim_cur = 3; - limit.rlim_max = 4; - setrlimit (RLIMIT_CPU, &limit); - - limit.rlim_cur = limit.rlim_max = 4 * 1024 * 1024; - setrlimit (RLIMIT_DATA, &limit); - - getrlimit (RLIMIT_STACK, &limit); - limit.rlim_cur = 1 * 1024 * 1024; - setrlimit (RLIMIT_STACK, &limit); - - sigaction (SIGXCPU, &act, 0); - } -#endif /* LIMIT_RESOURCE_USAGE */ - - sigaction (SIGILL, &act, 0); - sigaction (SIGSEGV, &act, 0); - sigaction (SIGBUS, &act, 0); - sigaction (SIGFPE, &act, 0); -} -#endif /* ! _WIN32 && ! __DJGPP__ */ - -main (int argc, char **argv) -{ - struct expr *e; - int i; - mpz_t r; - int errcode = 0; - char *str; - int base = 10; - -#if !defined(_WIN32) && !defined(__DJGPP__) - setup_error_handler (); -#endif - - mpz_init (r); - - while (argc > 1 && argv[1][0] == '-') - { - char *arg = argv[1]; - - if (arg[1] >= '0' && arg[1] <= '9') - break; - - if (arg[1] == 't') - print_timing = 1; - else if (arg[1] == 'b' && arg[2] >= '0' && arg[2] <= '9') - { - base = atoi (arg + 2); - if (base < 2 || base > 36) - { - fprintf (stderr, "error: invalid output base\n"); - exit (-1); - } - } - else if (arg[1] == 'b' && arg[2] == 0) - base = 2; - else if (arg[1] == 'x' && arg[2] == 0) - base = 16; - else if (arg[1] == 'o' && arg[2] == 0) - base = 8; - else if (arg[1] == 'd' && arg[2] == 0) - base = 10; - else if (strcmp (arg, "-html") == 0) - { - flag_html = 1; - newline = "
"; - } - else if (strcmp (arg, "-split") == 0) - { - flag_splitup_output = 1; - } - else if (strcmp (arg, "-noprint") == 0) - { - flag_print = 0; - } - else - { - fprintf (stderr, "error: unknown option `%s'\n", arg); - exit (-1); - } - argv++; - argc--; - } - - for (i = 1; i < argc; i++) - { - int s; - int jmpval; - - /* Set up error handler for parsing expression. */ - jmpval = setjmp (errjmpbuf); - if (jmpval != 0) - { - fprintf (stderr, "error: %s%s\n", error, newline); - fprintf (stderr, " %s%s\n", argv[i], newline); - if (! flag_html) - { - /* ??? Dunno how to align expression position with arrow in - HTML ??? */ - fprintf (stderr, " "); - for (s = jmpval - (long) argv[i]; --s >= 0; ) - putc (' ', stderr); - fprintf (stderr, "^\n"); - } - - errcode |= 1; - continue; - } - - str = expr (argv[i], &e); - - if (str[0] != 0) - { - fprintf (stderr, - "error: garbage where end of expression expected%s\n", - newline); - fprintf (stderr, " %s%s\n", argv[i], newline); - if (! flag_html) - { - /* ??? Dunno how to align expression position with arrow in - HTML ??? */ - fprintf (stderr, " "); - for (s = str - argv[i]; --s; ) - putc (' ', stderr); - fprintf (stderr, "^\n"); - } - - errcode |= 1; - free_expr (e); - continue; - } - - /* Set up error handler for evaluating expression. */ - if (setjmp (errjmpbuf)) - { - fprintf (stderr, "error: %s%s\n", error, newline); - fprintf (stderr, " %s%s\n", argv[i], newline); - if (! flag_html) - { - /* ??? Dunno how to align expression position with arrow in - HTML ??? */ - fprintf (stderr, " "); - for (s = str - argv[i]; --s >= 0; ) - putc (' ', stderr); - fprintf (stderr, "^\n"); - } - - errcode |= 2; - continue; - } - - { - int t0; - - if (print_timing) - t0 = cputime (); - - mpz_eval_expr (r, e); - - if (print_timing) - printf ("computation took %d ms%s\n", cputime () - t0, newline); - } - - if (flag_print) - { - size_t out_len; - char *tmp, *s; - int t0; - - out_len = mpz_sizeinbase (r, base) + 1; - tmp = malloc (out_len); - - if (print_timing) - t0 = cputime (); - - if (print_timing) - /* Print first half of message... */ - printf ("output conversion "); - - mpz_get_str (tmp, -base, r); - - if (print_timing) - /* ...print 2nd half of message unless we caught a time limit - and therefore longjmp'ed */ - printf ("took %d ms%s\n", cputime () - t0, newline); - - out_len = strlen (tmp); - if (flag_splitup_output) - { - for (s = tmp; out_len > 60; s += 60) - { - fwrite (s, 1, 60, stdout); - printf ("%s\n", newline); - out_len -= 60; - } - - fwrite (s, 1, out_len, stdout); - } - else - { - fwrite (tmp, 1, out_len, stdout); - } - - free (tmp); - printf ("%s\n", newline); - } - else - { - printf ("result is approximately %ld digits%s\n", - (long) mpz_sizeinbase (r, 10), newline); - } - - free_expr (e); - } - - exit (errcode); -} - -char * -expr (char *str, expr_t *e) -{ - expr_t e2; - - str = skipspace (str); - if (str[0] == '+') - { - str = term (str + 1, e); - } - else if (str[0] == '-') - { - str = term (str + 1, e); - makeexp (e, NEG, *e, NULL); - } - else if (str[0] == '~') - { - str = term (str + 1, e); - makeexp (e, NOT, *e, NULL); - } - else - { - str = term (str, e); - } - - for (;;) - { - str = skipspace (str); - switch (str[0]) - { - case 'p': - if (match ("plus", str)) - { - str = term (str + 4, &e2); - makeexp (e, PLUS, *e, e2); - } - else - return str; - break; - case 'm': - if (match ("minus", str)) - { - str = term (str + 5, &e2); - makeexp (e, MINUS, *e, e2); - } - else - return str; - break; - case '+': - str = term (str + 1, &e2); - makeexp (e, PLUS, *e, e2); - break; - case '-': - str = term (str + 1, &e2); - makeexp (e, MINUS, *e, e2); - break; - default: - return str; - } - } -} - -char * -term (char *str, expr_t *e) -{ - expr_t e2; - - str = power (str, e); - for (;;) - { - str = skipspace (str); - switch (str[0]) - { - case 'm': - if (match ("mul", str)) - { - str = power (str + 3, &e2); - makeexp (e, MULT, *e, e2); - break; - } - if (match ("mod", str)) - { - str = power (str + 3, &e2); - makeexp (e, MOD, *e, e2); - break; - } - return str; - case 'd': - if (match ("div", str)) - { - str = power (str + 3, &e2); - makeexp (e, DIV, *e, e2); - break; - } - return str; - case 'r': - if (match ("rem", str)) - { - str = power (str + 3, &e2); - makeexp (e, REM, *e, e2); - break; - } - return str; - case 'i': - if (match ("invmod", str)) - { - str = power (str + 6, &e2); - makeexp (e, REM, *e, e2); - break; - } - return str; - case 't': - if (match ("times", str)) - { - str = power (str + 5, &e2); - makeexp (e, MULT, *e, e2); - break; - } - if (match ("thru", str)) - { - str = power (str + 4, &e2); - makeexp (e, DIV, *e, e2); - break; - } - if (match ("through", str)) - { - str = power (str + 7, &e2); - makeexp (e, DIV, *e, e2); - break; - } - return str; - case '*': - str = power (str + 1, &e2); - makeexp (e, MULT, *e, e2); - break; - case '/': - str = power (str + 1, &e2); - makeexp (e, DIV, *e, e2); - break; - case '%': - str = power (str + 1, &e2); - makeexp (e, MOD, *e, e2); - break; - default: - return str; - } - } -} - -char * -power (char *str, expr_t *e) -{ - expr_t e2; - - str = factor (str, e); - while (str[0] == '!') - { - str++; - makeexp (e, FAC, *e, NULL); - } - str = skipspace (str); - if (str[0] == '^') - { - str = power (str + 1, &e2); - makeexp (e, POW, *e, e2); - } - return str; -} - -int -match (char *s, char *str) -{ - char *ostr = str; - int i; - - for (i = 0; s[i] != 0; i++) - { - if (str[i] != s[i]) - return 0; - } - str = skipspace (str + i); - return str - ostr; -} - -int -matchp (char *s, char *str) -{ - char *ostr = str; - int i; - - for (i = 0; s[i] != 0; i++) - { - if (str[i] != s[i]) - return 0; - } - str = skipspace (str + i); - if (str[0] == '(') - return str - ostr + 1; - return 0; -} - -struct functions -{ - char *spelling; - enum op_t op; - int arity; /* 1 or 2 means real arity; 0 means arbitrary. */ -}; - -struct functions fns[] = -{ - {"sqrt", SQRT, 1}, -#if __GNU_MP_VERSION >= 2 - {"root", ROOT, 2}, - {"popc", POPCNT, 1}, -#endif - {"gcd", GCD, 0}, -#if __GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1 - {"lcm", LCM, 0}, -#endif - {"and", AND, 0}, - {"ior", IOR, 0}, -#if __GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1 - {"xor", XOR, 0}, -#endif - {"plus", PLUS, 0}, - {"minus", MINUS, 2}, - {"mul", MULT, 0}, - {"div", DIV, 2}, - {"mod", MOD, 2}, - {"rem", REM, 2}, -#if __GNU_MP_VERSION >= 2 - {"invmod", INVMOD, 2}, -#endif - {"log", LOG, 2}, - {"log2", LOG2, 1}, - {"F", FERMAT, 1}, - {"M", MERSENNE, 1}, - {"fib", FIBONACCI, 1}, - {"Fib", FIBONACCI, 1}, - {"", NOP, 0} -}; - -char * -factor (char *str, expr_t *e) -{ - expr_t e1, e2; - - str = skipspace (str); - - if (isalpha (str[0])) - { - int i; - int cnt; - - for (i = 0; fns[i].op != NOP; i++) - { - if (fns[i].arity == 1) - { - cnt = matchp (fns[i].spelling, str); - if (cnt != 0) - { - str = expr (str + cnt, &e1); - str = skipspace (str); - if (str[0] != ')') - { - error = "expected `)'"; - longjmp (errjmpbuf, (int) (long) str); - } - makeexp (e, fns[i].op, e1, NULL); - return str + 1; - } - } - } - - for (i = 0; fns[i].op != NOP; i++) - { - if (fns[i].arity != 1) - { - cnt = matchp (fns[i].spelling, str); - if (cnt != 0) - { - str = expr (str + cnt, &e1); - str = skipspace (str); - - if (str[0] != ',') - { - error = "expected `,' and another operand"; - longjmp (errjmpbuf, (int) (long) str); - } - - str = skipspace (str + 1); - str = expr (str, &e2); - str = skipspace (str); - - if (fns[i].arity == 0) - { - while (str[0] == ',') - { - makeexp (&e1, fns[i].op, e1, e2); - str = skipspace (str + 1); - str = expr (str, &e2); - str = skipspace (str); - } - } - - if (str[0] != ')') - { - error = "expected `)'"; - longjmp (errjmpbuf, (int) (long) str); - } - - makeexp (e, fns[i].op, e1, e2); - return str + 1; - } - } - } - } - - if (str[0] == '(') - { - str = expr (str + 1, e); - str = skipspace (str); - if (str[0] != ')') - { - error = "expected `)'"; - longjmp (errjmpbuf, (int) (long) str); - } - str++; - } - else if (str[0] >= '0' && str[0] <= '9') - { - expr_t res; - char *s, *sc; - - res = malloc (sizeof (struct expr)); - res -> op = LIT; - mpz_init (res->operands.val); - - s = str; - while (isalnum (str[0])) - str++; - sc = malloc (str - s + 1); - memcpy (sc, s, str - s); - sc[str - s] = 0; - - mpz_set_str (res->operands.val, sc, 0); - *e = res; - free (sc); - } - else - { - error = "operand expected"; - longjmp (errjmpbuf, (int) (long) str); - } - return str; -} - -char * -skipspace (char *str) -{ - while (str[0] == ' ') - str++; - return str; -} - -/* Make a new expression with operation OP and right hand side - RHS and left hand side lhs. Put the result in R. */ -void -makeexp (expr_t *r, enum op_t op, expr_t lhs, expr_t rhs) -{ - expr_t res; - res = malloc (sizeof (struct expr)); - res -> op = op; - res -> operands.ops.lhs = lhs; - res -> operands.ops.rhs = rhs; - *r = res; - return; -} - -/* Free the memory used by expression E. */ -void -free_expr (expr_t e) -{ - if (e->op != LIT) - { - free_expr (e->operands.ops.lhs); - if (e->operands.ops.rhs != NULL) - free_expr (e->operands.ops.rhs); - } - else - { - mpz_clear (e->operands.val); - } -} - -/* Evaluate the expression E and put the result in R. */ -void -mpz_eval_expr (mpz_ptr r, expr_t e) -{ - mpz_t lhs, rhs; - - switch (e->op) - { - case LIT: - mpz_set (r, e->operands.val); - return; - case PLUS: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_add (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; - case MINUS: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_sub (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; - case MULT: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_mul (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; - case DIV: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_fdiv_q (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; - case MOD: - mpz_init (rhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_abs (rhs, rhs); - mpz_eval_mod_expr (r, e->operands.ops.lhs, rhs); - mpz_clear (rhs); - return; - case REM: - /* Check if lhs operand is POW expression and optimize for that case. */ - if (e->operands.ops.lhs->op == POW) - { - mpz_t powlhs, powrhs; - mpz_init (powlhs); - mpz_init (powrhs); - mpz_init (rhs); - mpz_eval_expr (powlhs, e->operands.ops.lhs->operands.ops.lhs); - mpz_eval_expr (powrhs, e->operands.ops.lhs->operands.ops.rhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_powm (r, powlhs, powrhs, rhs); - if (mpz_cmp_si (rhs, 0L) < 0) - mpz_neg (r, r); - mpz_clear (powlhs); - mpz_clear (powrhs); - mpz_clear (rhs); - return; - } - - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_fdiv_r (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; -#if __GNU_MP_VERSION >= 2 - case INVMOD: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_invert (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; -#endif - case POW: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - if (mpz_cmp_si (rhs, 0L) == 0) - /* x^0 is 1 */ - mpz_set_ui (r, 1L); - else if (mpz_cmp_si (lhs, 0L) == 0) - /* 0^y (where y != 0) is 0 */ - mpz_set_ui (r, 0L); - else if (mpz_cmp_ui (lhs, 1L) == 0) - /* 1^y is 1 */ - mpz_set_ui (r, 1L); - else if (mpz_cmp_si (lhs, -1L) == 0) - /* (-1)^y just depends on whether y is even or odd */ - mpz_set_si (r, (mpz_get_ui (rhs) & 1) ? -1L : 1L); - else if (mpz_cmp_si (rhs, 0L) < 0) - /* x^(-n) is 0 */ - mpz_set_ui (r, 0L); - else - { - unsigned long int cnt; - unsigned long int y; - /* error if exponent does not fit into an unsigned long int. */ - if (mpz_cmp_ui (rhs, ~(unsigned long int) 0) > 0) - goto pow_err; - - y = mpz_get_ui (rhs); - /* x^y == (x/(2^c))^y * 2^(c*y) */ -#if __GNU_MP_VERSION >= 2 - cnt = mpz_scan1 (lhs, 0); -#else - cnt = 0; -#endif - if (cnt != 0) - { - if (y * cnt / cnt != y) - goto pow_err; - mpz_tdiv_q_2exp (lhs, lhs, cnt); - mpz_pow_ui (r, lhs, y); - mpz_mul_2exp (r, r, y * cnt); - } - else - mpz_pow_ui (r, lhs, y); - } - mpz_clear (lhs); mpz_clear (rhs); - return; - pow_err: - error = "result of `pow' operator too large"; - mpz_clear (lhs); mpz_clear (rhs); - longjmp (errjmpbuf, 1); - case GCD: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_gcd (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; -#if __GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1 - case LCM: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_lcm (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; -#endif - case AND: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_and (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; - case IOR: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_ior (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; -#if __GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1 - case XOR: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_xor (r, lhs, rhs); - mpz_clear (lhs); mpz_clear (rhs); - return; -#endif - case NEG: - mpz_eval_expr (r, e->operands.ops.lhs); - mpz_neg (r, r); - return; - case NOT: - mpz_eval_expr (r, e->operands.ops.lhs); - mpz_com (r, r); - return; - case SQRT: - mpz_init (lhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - if (mpz_sgn (lhs) < 0) - { - error = "cannot take square root of negative numbers"; - mpz_clear (lhs); - longjmp (errjmpbuf, 1); - } - mpz_sqrt (r, lhs); - return; -#if __GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1 - case ROOT: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - if (mpz_sgn (rhs) <= 0) - { - error = "cannot take non-positive root orders"; - mpz_clear (lhs); mpz_clear (rhs); - longjmp (errjmpbuf, 1); - } - if (mpz_sgn (lhs) < 0 && (mpz_get_ui (rhs) & 1) == 0) - { - error = "cannot take even root orders of negative numbers"; - mpz_clear (lhs); mpz_clear (rhs); - longjmp (errjmpbuf, 1); - } - - { - unsigned long int nth = mpz_get_ui (rhs); - if (mpz_cmp_ui (rhs, ~(unsigned long int) 0) > 0) - { - /* If we are asked to take an awfully large root order, cheat and - ask for the largest order we can pass to mpz_root. This saves - some error prone special cases. */ - nth = ~(unsigned long int) 0; - } - mpz_root (r, lhs, nth); - } - mpz_clear (lhs); mpz_clear (rhs); - return; -#endif - case FAC: - mpz_eval_expr (r, e->operands.ops.lhs); - if (mpz_size (r) > 1) - { - error = "result of `!' operator too large"; - longjmp (errjmpbuf, 1); - } - mpz_fac_ui (r, mpz_get_ui (r)); - return; -#if __GNU_MP_VERSION >= 2 - case POPCNT: - mpz_eval_expr (r, e->operands.ops.lhs); - { unsigned long int cnt; - cnt = mpz_popcount (r); - mpz_set_ui (r, cnt); - } - return; -#endif - case LOG2: - mpz_eval_expr (r, e->operands.ops.lhs); - { unsigned long int cnt; - if (mpz_sgn (r) <= 0) - { - error = "logarithm of non-positive number"; - longjmp (errjmpbuf, 1); - } - cnt = mpz_sizeinbase (r, 2); - mpz_set_ui (r, cnt - 1); - } - return; - case LOG: - { unsigned long int cnt; - mpz_init (lhs); mpz_init (rhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - mpz_eval_expr (rhs, e->operands.ops.rhs); - if (mpz_sgn (lhs) <= 0) - { - error = "logarithm of non-positive number"; - mpz_clear (lhs); mpz_clear (rhs); - longjmp (errjmpbuf, 1); - } - if (mpz_cmp_ui (rhs, 256) >= 0) - { - error = "logarithm base too large"; - mpz_clear (lhs); mpz_clear (rhs); - longjmp (errjmpbuf, 1); - } - cnt = mpz_sizeinbase (lhs, mpz_get_ui (rhs)); - mpz_set_ui (r, cnt - 1); - mpz_clear (lhs); mpz_clear (rhs); - } - return; - case FERMAT: - { - unsigned long int t; - mpz_init (lhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - t = (unsigned long int) 1 << mpz_get_ui (lhs); - if (mpz_cmp_ui (lhs, ~(unsigned long int) 0) > 0 || t == 0) - { - error = "too large Mersenne number index"; - mpz_clear (lhs); - longjmp (errjmpbuf, 1); - } - mpz_set_ui (r, 1); - mpz_mul_2exp (r, r, t); - mpz_add_ui (r, r, 1); - mpz_clear (lhs); - } - return; - case MERSENNE: - mpz_init (lhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - if (mpz_cmp_ui (lhs, ~(unsigned long int) 0) > 0) - { - error = "too large Mersenne number index"; - mpz_clear (lhs); - longjmp (errjmpbuf, 1); - } - mpz_set_ui (r, 1); - mpz_mul_2exp (r, r, mpz_get_ui (lhs)); - mpz_sub_ui (r, r, 1); - mpz_clear (lhs); - return; - case FIBONACCI: - { mpz_t t; - unsigned long int n, i; - mpz_init (lhs); - mpz_eval_expr (lhs, e->operands.ops.lhs); - if (mpz_sgn (lhs) <= 0 || mpz_cmp_si (lhs, 1000000000) > 0) - { - error = "Fibonacci index out of range"; - mpz_clear (lhs); - longjmp (errjmpbuf, 1); - } - n = mpz_get_ui (lhs); - mpz_clear (lhs); - -#if __GNU_MP_VERSION > 2 || __GNU_MP_VERSION_MINOR >= 1 - mpz_fib_ui (r, n); -#else - mpz_init_set_ui (t, 1); - mpz_set_ui (r, 1); - - if (n <= 2) - mpz_set_ui (r, 1); - else - { - for (i = 3; i <= n; i++) - { - mpz_add (t, t, r); - mpz_swap (t, r); - } - } - mpz_clear (t); -#endif - } - return; - default: - abort (); - } -} - -/* Evaluate the expression E modulo MOD and put the result in R. */ -void -mpz_eval_mod_expr (mpz_ptr r, expr_t e, mpz_ptr mod) -{ - mpz_t lhs, rhs; - - switch (e->op) - { - case POW: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_mod_expr (lhs, e->operands.ops.lhs, mod); - mpz_eval_expr (rhs, e->operands.ops.rhs); - mpz_powm (r, lhs, rhs, mod); - mpz_clear (lhs); mpz_clear (rhs); - return; - case PLUS: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_mod_expr (lhs, e->operands.ops.lhs, mod); - mpz_eval_mod_expr (rhs, e->operands.ops.rhs, mod); - mpz_add (r, lhs, rhs); - if (mpz_cmp_si (r, 0L) < 0) - mpz_add (r, r, mod); - else if (mpz_cmp (r, mod) >= 0) - mpz_sub (r, r, mod); - mpz_clear (lhs); mpz_clear (rhs); - return; - case MINUS: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_mod_expr (lhs, e->operands.ops.lhs, mod); - mpz_eval_mod_expr (rhs, e->operands.ops.rhs, mod); - mpz_sub (r, lhs, rhs); - if (mpz_cmp_si (r, 0L) < 0) - mpz_add (r, r, mod); - else if (mpz_cmp (r, mod) >= 0) - mpz_sub (r, r, mod); - mpz_clear (lhs); mpz_clear (rhs); - return; - case MULT: - mpz_init (lhs); mpz_init (rhs); - mpz_eval_mod_expr (lhs, e->operands.ops.lhs, mod); - mpz_eval_mod_expr (rhs, e->operands.ops.rhs, mod); - mpz_mul (r, lhs, rhs); - mpz_mod (r, r, mod); - mpz_clear (lhs); mpz_clear (rhs); - return; - default: - mpz_init (lhs); - mpz_eval_expr (lhs, e); - mpz_mod (r, lhs, mod); - mpz_clear (lhs); - return; - } -} - -void -cleanup_and_exit (int sig) -{ -#ifdef LIMIT_RESOURCE_USAGE - if (sig == SIGXCPU) - printf ("expression took too long time to evaluate%s\n", newline); - else if (sig == SIGFPE) - printf ("divide by zero%s\n", newline); - else -#endif - printf ("expression required too much memory to evaluate%s\n", newline); - exit (-2); -} - -/* Return user CPU time measured in milliseconds. */ - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#endif diff --git a/gmp/demos/primes.c b/gmp/demos/primes.c deleted file mode 100755 index d19c3f7..0000000 --- a/gmp/demos/primes.c +++ /dev/null @@ -1,145 +0,0 @@ -/* List and count primes. - -Copyright (C) 2000 Free Software Foundation, Inc. - -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 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 should 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. */ - -#include -#include -#include "gmp.h" - -/* Sieve table size */ -#define ST_SIZE 30000 -/* Largest prime to sieve with */ -#define MAX_S_PRIME 1000 - -main (int argc, char **argv) -{ - char *progname = argv[0]; - mpz_t r0, r1; /* range */ - mpz_t cur; - unsigned char *st; - unsigned long i, ii; - unsigned long nprimes = 0; - unsigned long last; - int flag_print = 1; - int flag_count = 0; - - st = malloc (ST_SIZE); - - while (argc != 1) - { - if (strcmp (argv[1], "-c") == 0) - { - flag_count = 1; - argv++; - argc--; - } - else if (strcmp (argv[1], "-p") == 0) - { - flag_print = 2; - argv++; - argc--; - } - else - break; - } - - if (flag_count) - flag_print--; /* clear unless an explicit -p */ - - mpz_init (r0); - mpz_init (r1); - mpz_init (cur); - - if (argc == 2) - { - mpz_set_ui (r0, 2); - mpz_set_str (r1, argv[1], 0); - } - else if (argc == 3) - { - mpz_set_str (r0, argv[1], 0); - if (argv[2][0] == '+') - { - mpz_set_str (r1, argv[2] + 1, 0); - mpz_add (r1, r1, r0); - } - else - mpz_set_str (r1, argv[2], 0); - } - else - { - fprintf (stderr, "usage: %s [-c] [-g] [from [+]]to\n", progname); - exit (1); - } - - if (mpz_cmp_ui (r0, 2) < 0) - mpz_set_ui (r0, 2); - - if ((mpz_get_ui (r0) & 1) == 0) - { - if (mpz_cmp_ui (r0, 2) == 0) - { - if (flag_print) - puts ("2"); - nprimes++; - } - mpz_add_ui (r0, r0, 1); - } - - mpz_set (cur, r0); - - while (mpz_cmp (cur, r1) <= 0) - { - memset (st, 1, ST_SIZE); - for (i = 3; i < MAX_S_PRIME; i += 2) - { - unsigned long start; - start = mpz_tdiv_ui (cur, i); - if (start != 0) - start = i - start; - - if (mpz_cmp_ui (cur, i - start) == 0) - start += i; - for (ii = start; ii < ST_SIZE; ii += i) - st[ii] = 0; - } - last = 0; - for (ii = 0; ii < ST_SIZE; ii += 2) - { - if (st[ii] != 0) - { - mpz_add_ui (cur, cur, ii - last); - last = ii; - if (mpz_cmp (cur, r1) > 0) - goto done; - if (mpz_probab_prime_p (cur, 3)) - { - nprimes++; - if (flag_print) - { - mpz_out_str (stdout, 10, cur); puts (""); - } - } - } - } - mpz_add_ui (cur, cur, ST_SIZE - last); - } - done: - if (flag_count) - printf ("Pi(interval) = %lu\n", nprimes); - - exit (0); -} diff --git a/gmp/demos/qcn.c b/gmp/demos/qcn.c deleted file mode 100755 index 7449803..0000000 --- a/gmp/demos/qcn.c +++ /dev/null @@ -1,151 +0,0 @@ -/* Use mpz_kronecker_ui() to calculate an estimate for the quadratic - class number h(d), for a given negative fundamental discriminant, using - Dirichlet's analytic formula. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -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 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 should 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. */ - - -/* Usage: qcn ... - - A fundamental discriminant means one of the form D or 4*D with D - square-free. Each argument is checked to see it's congruent to 0 or 1 - mod 4 (as all discriminants must be), and that it's negative, but there's - no check on D being square-free. - - This program is a bit of a toy, there are better methods for calculating - the class number and class group structure. - - Reference: - - Daniel Shanks, "Class Number, A Theory of Factorization, and Genera", - Proc. Symp. Pure Math., vol 20, 1970, pages 415-440. - -*/ - -#include -#include - -#include "gmp.h" - - -/* A simple but slow primality test. */ -int -prime_p (unsigned long n) -{ - unsigned long i, limit; - - if (n == 2) - return 1; - if (n < 2 || !(n&1)) - return 0; - - limit = (unsigned long) floor (sqrt ((double) n)); - for (i = 3; i <= limit; i+=2) - if ((n % i) == 0) - return 0; - - return 1; -} - - -/* The formula is as follows, with d < 0. - - w * sqrt(-d) inf p - h(d) = ------------ * product -------- - 2 * pi p=2 p - (d/p) - - - (d/p) is the Kronecker symbol and the product is over primes p. w is 6 - when d=-3, 4 when d=-4, or 2 otherwise. - - Calculating the product up to p=infinity would take a long time, so for - the estimate primes up to 132,000 are used. Shanks found this giving an - accuracy of about 1 part in 1000, in normal cases. */ - -double -qcn_estimate (mpz_t d) -{ -#define P_LIMIT 132000 - - double h; - unsigned long p; - - /* p=2 */ - h = sqrt (-mpz_get_d (d)) / M_PI - * 2.0 / (2.0 - mpz_kronecker_ui (d, 2)); - - if (mpz_cmp_si (d, -3) == 0) h *= 3; - else if (mpz_cmp_si (d, -4) == 0) h *= 2; - - for (p = 3; p < P_LIMIT; p += 2) - if (prime_p (p)) - h *= (double) p / (double) (p - mpz_kronecker_ui (d, p)); - - return h; -} - - -void -qcn_str (char *num) -{ - mpz_t z; - - mpz_init_set_str (z, num, 0); - - if (mpz_sgn (z) >= 0) - { - mpz_out_str (stdout, 0, z); - printf (" is not supported (negatives only)\n"); - } - else if (mpz_fdiv_ui (z, 4) != 0 && mpz_fdiv_ui (z, 4) != 1) - { - mpz_out_str (stdout, 0, z); - printf (" is not a discriminant (must == 0 or 1 mod 4)\n"); - } - else - { - printf ("h("); - mpz_out_str (stdout, 0, z); - printf (") approx %.1f\n", qcn_estimate (z)); - } - mpz_clear (z); -} - - -int -main (int argc, char *argv[]) -{ - int i; - - if (argc < 2) - { - qcn_str ("-85702502803"); /* is 16259 */ - qcn_str ("-328878692999"); /* is 1499699 */ - qcn_str ("-928185925902146563"); /* is 52739552 */ - qcn_str ("-84148631888752647283"); /* is 496652272 */ - } - else - { - for (i = 1; i < argc; i++) - qcn_str (argv[i]); - } - - return 0; -} diff --git a/gmp/depcomp b/gmp/depcomp deleted file mode 100755 index a6f57c5..0000000 Binary files a/gmp/depcomp and /dev/null differ diff --git a/gmp/doc/assembly_code b/gmp/doc/assembly_code deleted file mode 100755 index 785625d..0000000 Binary files a/gmp/doc/assembly_code and /dev/null differ diff --git a/gmp/doc/configuration b/gmp/doc/configuration deleted file mode 100755 index 094da7b..0000000 Binary files a/gmp/doc/configuration and /dev/null differ diff --git a/gmp/doc/isa_abi_headache b/gmp/doc/isa_abi_headache deleted file mode 100755 index db92d07..0000000 Binary files a/gmp/doc/isa_abi_headache and /dev/null differ diff --git a/gmp/doc/multiplication b/gmp/doc/multiplication deleted file mode 100755 index 6c4bdd6..0000000 Binary files a/gmp/doc/multiplication and /dev/null differ diff --git a/gmp/doc/projects.html b/gmp/doc/projects.html deleted file mode 100755 index 416e50a..0000000 --- a/gmp/doc/projects.html +++ /dev/null @@ -1,194 +0,0 @@ - - - - - GMP Development Projects - - - - -
-

- GMP Development Projects -

-
- - - An up-to-date version of this file is available at - http://www.swox.com/gmp/projects.html. - - -

This file lists projects suitable for volunteers. Please see the - tasks file for smaller tasks. - -

If you want to work on any of the projects below, please let tege@swox.com - know. If you want to help with a project that already somebody else is - working on, please talk to that person too, tege@swox.com can put you in - touch. (There are no email addresses of volunteers below, due to spamming - problems.) - -

    -
  • C++ wrapper - -

    A C++ wrapper for GMP is highly desirable. Several people have started - writing one, but nobody has so far finished it. For a wrapper to be useful, - one needs to pay attention to efficiency. - -

      -
    1. Write arithmetic functions for direct applications of most - elementary C++ types. This might be necessary to avoid - ambiguities, but it is also desirable from an efficiency - standpoint. -
    2. Avoid running constructors/destructors when not necessary. - For example, implement a += b by directly applying mpz_add. -
    - -

  • Faster multiplication - -

    The current multiplication code uses Karatsuba, 3-way Toom-Cook, - or Fermat FFT. Several new developments are desirable: - -

      -
    1. Handle multiplication of operands with different digit count - better than today. We now split the operands in a very - inefficient way, see mpn/generic/mul.c. - -
    2. Consider N-way Toom-Cook. See Knuth's Seminumerical - Algorithms for details on the method. Code implementing it - exists. This is asymptotically inferior to FFTs, but is finer - grained. A toom-4 might fit in between toom-3 and the FFTs - (or it might not). - -
    3. It's possible CPU dependent effects like cache locality will - have a greater impact on speed than algorithmic improvements. - -
    - - -

  • Assembly routines - -

    Write new and tune existing assembly routines. The programs in mpn/tests - and the tune/speed.c program are useful for testing and timing the routines - you write. See the README files in those directories for more information. - -

    Please make sure your new routines are fast for these three situations: -

      -
    1. Operands that fit into the cache. -
    2. Small operands of less than, say, 10 limbs. -
    3. Huge operands that does not fit into the cache. -
    - -

    The most important routines are mpn_addmul_1, mpn_mul_basecase and - mpn_sqr_basecase. The latter two don't exist for all machines, while - mpn_addmul_1 exists for almost all machines. - -

    Standard techniques for these routines are unrolling, software - pipelining, and specialization for common operand values. For machines with - poor integer multiplication, it is often possible to improve the performance - using floating-point operations, or SIMD operations such as MMX or Sun's VIS. - -

    Using floating-point operations is interesting but somewhat tricky. - Since IEEE double has 53 bit of mantissa, one has to split the operands in - small prices, so that no result is greater than 2^53. For 32-bit computers, - splitting one operand into 16-bit pieces works. For 64-bit machines, one - operand can be split into 21-bit pieces and the other into 32-bit pieces. (A - 64-bit operand can be split into just three 21-bit pieces if one allows the - split operands to be negative!) - - -

  • Faster extended GCD - -

    We currently have extended GCD based on Lehmer's method. - But the binary method can quite easily be improved for bignums - in a similar way Lehmer improved Euclid's algorithm. The result should - beat Lehmer's method by about a factor of 2. Furthermore, the multiprecision - step of Lehmer's method and the binary method will be identical, so the - current code can mostly be reused. It should be possible to share code - between GCD and GCDEXT, and probably with Jacobi symbols too. - -

  • Math functions for the mpf layer - -

    Implement the functions of math.h for the GMP mpf layer! Check the book - "Pi and the AGM" by Borwein and Borwein for ideas how to do this. These - functions are desirable: acos, acosh, asin, asinh, atan, atanh, atan2, cos, - cosh, exp, log, log10, pow, sin, sinh, tan, tanh. - -

  • Faster sqrt - -

    The current code for computing square roots use a Newton iteration that - rely on division. It is possible to avoid using division by computing - 1/sqrt(A) using this formula: -

    -                                    2
    -                   x   = x  (3 - A x )/2.
    -                    i+1   i         i  
    - The final result is then computed without division using, -
    -                     sqrt(A) = A x .
    -                                  n  
    - The resulting code should be substantially faster than the current code. - -

  • Nth root - -

    Implement, at the mpn level, a routine for computing the nth root of a - number. The routine should use Newton's method, preferably without using - division. - -

    If the routine becomes fast enough, perhaps square roots could be computed - using this function. - -

  • More random number generators - -

    Implement some more pseudo random number generator algorithms. - Today there's only Linear Congruential. - - -

  • Test Suite - -

    Add a test suite for old bugs. These tests wouldn't loop or use - random numbers, but just test for specific bugs found in the - past. - -

    More importantly, improve the random number controls for test - collections: - -

      -
    1. Use the new random number framework. -
    2. Have every test accept a seed parameter. -
    3. Allow `make check' to set the seed parameter. -
    4. Add more tests for important, now untested functions. -
    - -

    With this in place, it should be possible to rid GMP of - practically all bugs by having some dedicated GMP test machines - running "make check" with ever increasing seeds (and - periodically updating to the latest GMP). - -

    If a few more ASSERTs were sprinkled through the code, running - some tests with --enable-assert might be useful, though not a - substitute for tests on the normal build. - -

    An important feature of any random tests will be to record the - seeds used, and perhaps to snapshot operands before performing - each test, so any problem exposed can be reproduced. - -

- -
- - - - - - -
- - Please send comments about this page to - tege@swox.com.
- Copyright (C) 1999, 2000 Torbjörn Granlund. -
-
-
- - - diff --git a/gmp/doc/tasks.html b/gmp/doc/tasks.html deleted file mode 100755 index c549bf1..0000000 --- a/gmp/doc/tasks.html +++ /dev/null @@ -1,379 +0,0 @@ - - - - - GMP Itemized Development Tasks - - - - -
-

- GMP Itemized Development Tasks -

-
- - - An up-to-date html version of this file is available at - http://www.swox.com/gmp/tasks.html. - - -

This file lists itemized GMP development tasks. Not all the tasks - listed here are suitable for volunteers, but many of them are. - Please see the projects file for more - sizeable projects. - -

Correctness and Completeness

-
    -
  • HPUX 10.20 assembler requires a `.LEVEL 1.1' directive for accepting the - new instructions. Unfortunately, the HPUX 9 assembler as well as earlier - assemblers reject that directive. How very clever of HP! We will have to - pass assembler options, and make sure it works with new and old systems - and GNU assembler. -
  • The various reuse.c tests need to force reallocation by calling - _mpz_realloc with a small (1 limb) size. -
  • One reuse case is missing from mpX/tests/reuse.c: mpz_XXX(a,a,a). -
  • When printing mpf_t numbers with exponents > 2^53 on machines with 64-bit - mp_exp_t, the precision of - __mp_bases[base].chars_per_bit_exactly is insufficient and - mpf_get_str aborts. Detect and compensate. -
  • Fix mpz_get_si to work properly for MIPS N32 ABI (and other - machines that use long long for storing limbs.) -
  • Make the string reading functions allow the `0x' prefix when the base is - explicitly 16. They currently only allow that prefix when the base is - unspecified. -
  • In the development sources, we return abs(a%b) in the - mpz_*_ui division routines. Perhaps make them return the - real remainder instead? Changes return type to signed long int. -
  • mpf_eq is not always correct, when one operand is - 1000000000... and the other operand is 0111111111..., i.e., extremely - close. There is a special case in mpf_sub for this - situation; put similar code in mpf_eq. -
  • mpf_eq doesn't implement what gmp.texi specifies. It should not use just - whole limbs, but partial limbs. -
  • Install Alpha assembly changes (prec/gmp-alpha-patches). -
  • NeXT has problems with newlines in asm strings in longlong.h. Also, - __builtin_constant_p is unavailable? Same problem with MacOS - X. -
  • Shut up SGI's compiler by declaring dump_abort in - mp?/tests/*.c. -
  • mpz_get_si returns 0x80000000 for -0x100000000. -
- - - -

Machine Independent Optimization

-
    -
  • In hundreds of places in the code, we invoke count_leading_zeros and then - check if the returned count is zero. Instead check the most significant - bit of the operand, and avoid invoking count_leading_zeros if - the bit is set. This is an optimization on all machines, and significant - on machines with slow count_leading_zeros. -
  • In a couple of places count_trailing_zeros is used - on more or less uniformly distributed numbers. For some CPUs - count_trailing_zeros is slow and it's probably worth - handling the frequently occurring 0 to 2 trailing zeros cases specially. -
  • Change all places that use udiv_qrnnd for inverting limbs to - instead use invert_limb. -
  • Reorganize longlong.h so that we can inline the operations even for the - system compiler. When there is no such compiler feature, make calls to - stub functions. Write such stub functions for as many machines as - possible. -
  • Rewrite umul_ppmm to use floating-point for generating the - most significant limb (if BITS_PER_MP_LIMB <= 52 bits). - (Peter Montgomery has some ideas on this subject.) -
  • Improve the default umul_ppmm code in longlong.h: Add partial - products with fewer operations. -
  • Write new mpn_get_str and mpn_set_str running in - the sub O(n^2) range, using some divide-and-conquer approach, preferably - without using division. -
  • Copy tricky code for converting a limb from development version of - mpn_get_str to mpf/get_str. (Talk to Torbjörn about this.) -
  • Consider inlining these functions: mpz_size, - mpz_set_ui, mpz_set_q, mpz_clear, - mpz_init, mpz_get_ui, mpz_scan0, - mpz_scan1, mpz_getlimbn, - mpz_init_set_ui, mpz_perfect_square_p, - mpz_popcount, mpf_size, - mpf_get_prec, mpf_set_prec_raw, - mpf_set_ui, mpf_init, mpf_init2, - mpf_clear, mpf_set_si. -
  • mpz_powm and mpz_powm_ui aren't very - fast on one or two limb moduli, due to a lot of function call - overheads. These could perhaps be handled as special cases. -
  • mpz_powm and mpz_powm_ui want better - algorithm selection, and the latter should use REDC. Both could - change to use an mpn_powm and mpn_redc. -
  • mpn_gcd might be able to be sped up on small to - moderate sizes by improving find_a, possibly just by - providing an alternate implementation for CPUs with slowish - count_leading_zeros. -
  • Implement a cache localized evaluate and interpolate for the - toom3 USE_MORE_MPN code. The necessary - right-to-left mpn_divexact_by3c exists. -
  • mpn_mul_basecase on NxM with big N but small M could try for - better cache locality by taking N piece by piece. The current code could - be left available for CPUs without caching. Depending how karatsuba etc - is applied to unequal size operands it might be possible to assume M is - always smallish. -
- - -

Machine Dependent Optimization

-
    -
  • Run the `tune' utility for more compiler/CPU combinations. We would like - to have gmp-mparam.h files in practically every implementation specific - mpn subdirectory, and repeat each *_THRESHOLD for gcc and the system - compiler. See the `tune' top-level directory for more information. -
  • Alpha: Rewrite mpn_addmul_1, mpn_submul_1, and - mpn_mul_1 for the 21264. On 21264, they should run at 4, 3, - and 3 cycles/limb respectively, if the code is unrolled properly. (Ask - Torbjörn for his xm.s and xam.s skeleton files.) -
  • Alpha: Rewrite mpn_addmul_1, mpn_submul_1, and - mpn_mul_1 for the 21164. This should use both integer - multiplies and floating-point multiplies. For the floating-point - operations, the single-limb multiplier should be split into three 21-bit - chunks. -
  • UltraSPARC: Rewrite 64-bit mpn_addmul_1, - mpn_submul_1, and mpn_mul_1. Should use - floating-point operations, and split the invariant single-limb multiplier - into 21-bit chunks. Should give about 18 cycles/limb, but the pipeline - will become very deep. (Torbjörn has C code that is useful as a starting - point.) -
  • UltraSPARC: Rewrite mpn_lshift and mpn_rshift. - Should give 2 cycles/limb. (Torbjörn has code that just needs to be - finished.) -
  • SPARC32/V9: Find out why the speed of mpn_addmul_1 - and the other multiplies varies so much on successive sizes. -
  • PA64: Improve mpn_addmul_1, mpn_submul_1, and - mpn_mul_1. The current development code runs at 11 - cycles/limb, which is already very good. But it should be possible to - saturate the cache, which will happen at 7.5 cycles/limb. -
  • Sparc & SparcV8: Enable umul.asm for native cc. The generic - longlong.h umul_ppmm is suspected to be causing sqr_basecase to - be slower than mul_basecase. -
  • UltraSPARC: Write umul_ppmm. Important in particular for - mpn_sqr_basecase. Using four "mulx"s either - with an asm block or via the generic C code is about 90 cycles. -
  • Implement mpn_mul_basecase and mpn_sqr_basecase - for important machines. Helping the generic sqr_basecase.c with an - mpn_sqr_diagonal might be enough for some of the RISCs. -
  • POWER2/POWER2SC: Schedule mpn_lshift/mpn_rshift. - Will bring time from 1.75 to 1.25 cycles/limb. -
  • X86: Optimize non-MMX mpn_lshift for shifts by 1. (See Pentium code.) -
  • Alpha: Optimize count_leading_zeros. -
  • Alpha: Optimize udiv_qrnnd. (Ask Torbjörn for the file - test-udiv-preinv.c as a starting point.) -
  • R10000/R12000: Rewrite mpn_add_n and mpn_sub_n. - It should just require 3 cycles/limb, but the current code propagates - carry poorly. The trick is to add carry-in later than we do now, - decreasing the number of operations used to generate carry-out from 4 to - to 3. -
  • PPC32: Try using fewer registers in the current mpn_lshift. - The pipeline is now extremely deep, perhaps unnecessarily deep. Also, r5 - is unused. (Ask Torbjörn for a copy of the current code.) -
  • PPC32: Write mpn_rshift based on new mpn_lshift. -
  • PPC32: Rewrite mpn_add_n and mpn_sub_n. Should - run at just 3.25 cycles/limb. (Ask for xxx-add_n.s as a starting point.) -
  • Fujitsu VPP: Vectorize main functions, perhaps in assembly language. -
  • Fujitsu VPP: Write mpn_mul_basecase and - mpn_sqr_basecase. This should use a "vertical multiplication - method", to avoid carry propagation. splitting one of the operands in - 11-bit chunks. -
  • Cray: Vectorize main functions, perhaps in assembly language. -
  • Cray: Write mpn_mul_basecase and - mpn_sqr_basecase. Same comment applies to this as to the - same functions for Fujitsu VPP. -
  • Improve count_leading_zeros for 64-bit machines: - -
    -  if ((x >> W_TYPE_SIZE-W_TYPE_SIZE/2) == 0) { x <<= W_TYPE_SIZE/2; cnt += W_TYPE_SIZE/2}
    -  if ((x >> W_TYPE_SIZE-W_TYPE_SIZE/4) == 0) { x <<= W_TYPE_SIZE/4; cnt += W_TYPE_SIZE/4}
    -  ... 
    - -
- -

New Functionality

-
    -
  • mpz_get_nth_ui. Return the nth word (not necessarily the nth limb). -
  • Maybe add mpz_crr (Chinese Remainder Reconstruction). -
  • Let `0b' and `0B' mean binary input everywhere. -
  • Add mpq_set_f for assignment from mpf_t - (cf. mpq_set_d). -
  • Maybe make mpz_init (and mpq_init) do lazy - allocation. Set ALLOC(var) to 0, and have - mpz_realloc special-handle that case. Update functions that - rely on a single limb (like mpz_set_ui, - mpz_[tfc]div_r_ui, and others). -
  • Add mpf_out_raw and mpf_inp_raw. Make sure - format is portable between 32-bit and 64-bit machines, and between - little-endian and big-endian machines. -
  • Handle numeric exceptions: Call an error handler, and/or set - gmp_errno. -
  • Implement gmp_fprintf, gmp_sprintf, and - gmp_snprintf. Think about some sort of wrapper - around printf so it and its several variants don't - have to be completely reimplemented. -
  • Implement some mpq input and output functions. -
  • Implement a full precision mpz_kronecker, leave - mpz_jacobi for compatibility. -
  • Make the mpn logops and copys available in gmp.h. Since they can - be either library functions or inlines, gmp.h would need to be - generated from a gmp.in based on what's in the library. gmp.h - would still be compiler-independent though. -
  • Make versions of mpz_set_str etc taking string - lengths rather than null-terminators. -
  • Consider changing the thresholds to apply the simpler algorithm when - "<=" rather than "<", so a threshold can - be set to MP_SIZE_T_MAX to get only the simpler code (the - compiler will know size <= MP_SIZE_T_MAX is always true). -
  • mpz_cdiv_q_2exp and mpz_cdiv_r_2exp - could be implemented to match the corresponding tdiv and fdiv. - Maybe some code sharing is possible. -
- - -

Configuration

- -
    -
  • Improve config.guess. We want to recognize the processor very - accurately, more accurately than other GNU packages. - config.guess does not currently make the distinctions we would - like it to do and a --target often needs to be set explicitly. - - For example, "sparc" is not very useful as a machine architecture - denotation. We want to distinguish old 32-bit SPARC without - multiply support from newer 32-bit SPARC with such support. We - want to recognize a SuperSPARC, since its implementation of the - UDIV instruction is not complete, and will trap to the OS kernel - for certain operands. And we want to recognize 64-bit capable - SPARC processors as such. While the assembly routines can use - 64-bit operations on all 64-bit SPARC processors, one can not use - 64-bit limbs under all operating system. E.g., Solaris 2.5 and - 2.6 doesn't preserve the upper 32 bits of most processor - registers. For SPARC we therefore sometimes need to choose GMP - configuration depending both on processor and operating system. - -
  • Remember to make sure config.sub accepts any output from config.guess. - -
  • Find out whether there's an alloca available and how to use it. - AC_FUNC_ALLOCA has various system dependencies covered, but we - don't want its alloca.c replacement. (One thing current cpp - tests don't cover: HPUX 10 C compiler supports alloca, but - cannot find any symbol to test in order to know if we're on - HPUX 10. Damn.) -
  • Identify Mips processor under Irix: `hinv -c processor'. - config.guess should say mips2, mips3, and mips4. -
  • Identify Alpha processor under OSF: "/usr/sbin/sizer -c". - Unfortunately, sizer is not available before some revision of - Dec Unix 4.0, and it also returns some rather cryptic names for - processors. Perhaps the implver and - amask assembly instructions are better, but that - doesn't differentiate between ev5 and ev56. -
  • Identify Sparc processors. config.guess should say supersparc, - microsparc, ultrasparc1, ultrasparc2, etc. -
  • Identify HPPA processors similarly. -
  • Get lots of information about a Solaris system: prtconf -vp -
  • For some target machines and some compilers, specific options - are needed (sparcv8/gcc needs -mv8, sparcv8/cc needs -cg92, - Irix64/cc needs -64, Irix32/cc might need -n32, etc). Some are - set already, add more, see configure.in. -
  • Options to be passed to the assembler (via the compiler, using - whatever syntax the compiler uses for passing options to the - assembler). -
  • On Solaris 7, check if gcc supports native v9 64-bit - arithmetic. If not compile using "cc -fast -xarch=v9". - (Problem: -fast requires that we link with -fast too, which - might not be very good. Pass "-xO4 -xtarget=native" instead?) -
  • Extend the "optional" compiler arguments to choose the first - that works from from a set, so when gcc gets athlon support it - can try -mcpu=athlon, -mcpu=pentiumpro, or -mcpu=i486, - whichever works. -
  • Detect gcc >=2.96 and enable -march=pentiumpro for relevant - x86s. (A bug in gcc 2.95.2 prevents it being used - unconditionally.) -
  • Build multiple variants of the library under certain systems. - An example is -n32, -o32, and -64 on Irix. -
  • There's a few filenames that don't fit in 14 chars, if this - matters. -
  • Enable support for FORTRAN versions of mpn files (eg. for - mpn/cray/mulww.f). Add "f" to the mpn path searching, run AC_PROG_F77 if - such a file is found. Automake will generate some of what's needed in the - makefiles, but libtool doesn't know fortran and so rules like the current - ".asm.lo" will be needed. -
  • Only run GMP_PROG_M4 if it's needed, ie. if there's .asm files - selected from the mpn path. This might help say a generic C - build on weird systems. -
- -

In general, getting the exact right configuration, passing the -exact right options to the compiler, etc, might mean that the GMP -performance more than doubles. - -

When testing, make sure to test at least the following for all out -target machines: (1) Both gcc and cc (and c89). (2) Both 32-bit mode -and 64-bit mode (such as -n32 vs -64 under Irix). (3) Both the system -`make' and GNU `make'. (4) With and without GNU binutils. - - -

Miscellaneous

-
    - -
  • Work on the way we build the library. We now do it building - convenience libraries but then listing all the object files a - second time in the top level Makefile.am. -
  • Get rid of mp[zq]/sub.c, and instead define a compile parameter to - mp[zq]/add.c to decide whether it will add or subtract. Will decrease - redundancy. Similarly in other places. -
  • Make mpz_div and mpz_divmod use rounding - analogous to mpz_mod. Document, and list as an - incompatibility. -
  • Maybe make mpz_pow_ui.c more like mpz/ui_pow_ui.c, or write new - mpn/generic/pow_ui. -
  • Make mpz_invert call mpn_gcdext directly. -
  • Make a build option to enable execution profiling with gprof. In - particular look at getting the right mcount call at - the start of each assembler subroutine (for important targets at - least). -
- - -

Aids to Debugging

-
    -
  • Make an option for stack-alloc.c to call malloc - separately for each TMP_ALLOC block, so a redzoning - malloc debugger could be used during development. -
  • Add ASSERTs at the start of each user-visible - mpz/mpq/mpf function to check the validity of each - mp?_t parameter, in particular to check they've been - mp?_inited. This might catch elementary mistakes in - user programs. Care would need to be taken over - MPZ_TMP_INITed variables used internally. -
- - -

Documentation

-
    -
  • Document conventions, like that unsigned long int is used for - bit counts/ranges, and that mp_size_t is used for limb counts. -
  • mpz_inp_str (etc) doesn't say when it stops reading digits. -
- -
- - - - - - -
- - Please send comments about this page to - tege@swox.com.
- Copyright (C) 1999, 2000 Torbjörn Granlund. -
-
-
- - - diff --git a/gmp/errno.c b/gmp/errno.c deleted file mode 100755 index 7dd223c..0000000 --- a/gmp/errno.c +++ /dev/null @@ -1,26 +0,0 @@ -/* gmp_errno -- The largest and most complex file in GMP. - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#include "gmp.h" -#include "gmp-impl.h" - -int gmp_errno = 0; diff --git a/gmp/extract-dbl.c b/gmp/extract-dbl.c deleted file mode 100755 index 2d70d9a..0000000 --- a/gmp/extract-dbl.c +++ /dev/null @@ -1,187 +0,0 @@ -/* __gmp_extract_double -- convert from double to array of mp_limb_t. - -Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#ifdef XDEBUG -#undef _GMP_IEEE_FLOATS -#endif - -#ifndef _GMP_IEEE_FLOATS -#define _GMP_IEEE_FLOATS 0 -#endif - -/* Extract a non-negative double in d. */ - -int -#if __STDC__ -__gmp_extract_double (mp_ptr rp, double d) -#else -__gmp_extract_double (rp, d) - mp_ptr rp; - double d; -#endif -{ - long exp; - unsigned sc; - mp_limb_t manh, manl; - - /* BUGS - - 1. Should handle Inf and NaN in IEEE specific code. - 2. Handle Inf and NaN also in default code, to avoid hangs. - 3. Generalize to handle all BITS_PER_MP_LIMB >= 32. - 4. This lits is incomplete and misspelled. - */ - - if (d == 0.0) - { - rp[0] = 0; - rp[1] = 0; -#if BITS_PER_MP_LIMB == 32 - rp[2] = 0; -#endif - return 0; - } - -#if _GMP_IEEE_FLOATS - { -#if defined (__alpha) && __GNUC__ == 2 && __GNUC_MINOR__ == 8 - /* Work around alpha-specific bug in GCC 2.8.x. */ - volatile -#endif - union ieee_double_extract x; - x.d = d; - exp = x.s.exp; -#if BITS_PER_MP_LIMB == 64 - manl = (((mp_limb_t) 1 << 63) - | ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11)); - if (exp == 0) - { - /* Denormalized number. Don't try to be clever about this, - since it is not an important case to make fast. */ - exp = 1; - do - { - manl = manl << 1; - exp--; - } - while ((mp_limb_signed_t) manl >= 0); - } -#else - manh = ((mp_limb_t) 1 << 31) | (x.s.manh << 11) | (x.s.manl >> 21); - manl = x.s.manl << 11; - if (exp == 0) - { - /* Denormalized number. Don't try to be clever about this, - since it is not an important case to make fast. */ - exp = 1; - do - { - manh = (manh << 1) | (manl >> 31); - manl = manl << 1; - exp--; - } - while ((mp_limb_signed_t) manh >= 0); - } -#endif - exp -= 1022; /* Remove IEEE bias. */ - } -#else - { - /* Unknown (or known to be non-IEEE) double format. */ - exp = 0; - if (d >= 1.0) - { - if (d * 0.5 == d) - abort (); - - while (d >= 32768.0) - { - d *= (1.0 / 65536.0); - exp += 16; - } - while (d >= 1.0) - { - d *= 0.5; - exp += 1; - } - } - else if (d < 0.5) - { - while (d < (1.0 / 65536.0)) - { - d *= 65536.0; - exp -= 16; - } - while (d < 0.5) - { - d *= 2.0; - exp -= 1; - } - } - - d *= MP_BASE_AS_DOUBLE; -#if BITS_PER_MP_LIMB == 64 - manl = d; -#else - manh = d; - manl = (d - manh) * MP_BASE_AS_DOUBLE; -#endif - } -#endif - - sc = (unsigned) exp % BITS_PER_MP_LIMB; - - /* We add something here to get rounding right. */ - exp = (exp + 2048) / BITS_PER_MP_LIMB - 2048 / BITS_PER_MP_LIMB + 1; - -#if BITS_PER_MP_LIMB == 64 - if (sc != 0) - { - rp[1] = manl >> (BITS_PER_MP_LIMB - sc); - rp[0] = manl << sc; - } - else - { - rp[1] = manl; - rp[0] = 0; - exp--; - } -#else - if (sc != 0) - { - rp[2] = manh >> (BITS_PER_MP_LIMB - sc); - rp[1] = (manl >> (BITS_PER_MP_LIMB - sc)) | (manh << sc); - rp[0] = manl << sc; - } - else - { - rp[2] = manh; - rp[1] = manl; - rp[0] = 0; - exp--; - } -#endif - - return exp; -} diff --git a/gmp/gmp-impl.h b/gmp/gmp-impl.h deleted file mode 100755 index 1a4403a..0000000 --- a/gmp/gmp-impl.h +++ /dev/null @@ -1,1082 +0,0 @@ -/* Include file for internal GNU MP types and definitions. - - THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND ARE ALMOST CERTAIN TO - BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE GNU MP RELEASES. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "config.h" -#include "gmp-mparam.h" -/* #include "longlong.h" */ - -/* When using gcc, make sure to use its builtin alloca. */ -#if ! defined (alloca) && defined (__GNUC__) -#define alloca __builtin_alloca -#define HAVE_ALLOCA -#endif - -/* When using cc, do whatever necessary to allow use of alloca. For many - machines, this means including alloca.h. IBM's compilers need a #pragma - in "each module that needs to use alloca". */ -#if ! defined (alloca) -/* We need lots of variants for MIPS, to cover all versions and perversions - of OSes for MIPS. */ -#if defined (__mips) || defined (MIPSEL) || defined (MIPSEB) \ - || defined (_MIPSEL) || defined (_MIPSEB) || defined (__sgi) \ - || defined (__alpha) || defined (__sparc) || defined (sparc) \ - || defined (__ksr__) -#include -#define HAVE_ALLOCA -#endif -#if defined (_IBMR2) -#pragma alloca -#define HAVE_ALLOCA -#endif -#if defined (__DECC) -#define alloca(x) __ALLOCA(x) -#define HAVE_ALLOCA -#endif -#endif - -#if defined (alloca) -#define HAVE_ALLOCA -#endif - -#if ! defined (HAVE_ALLOCA) || USE_STACK_ALLOC -#include "stack-alloc.h" -#elif defined(__MWERKS__) && !defined(powerc) -inline asm long GetSP() { - move.l sp,d0 -} -#define ALLOCA_START(x) register long x = GetSP() -#define ALLOCA_FREE(x) asm { move.l x,sp } -#define TMP_DECL(m) ALLOCA_START(m) -#define TMP_ALLOC(x) alloca(x) -#define TMP_MARK(m) -#define TMP_FREE(m) ALLOCA_FREE(m) -#else -#define TMP_DECL(m) -#define TMP_ALLOC(x) alloca(x) -#define TMP_MARK(m) -#define TMP_FREE(m) -#endif - -/* Allocating various types. */ -#define TMP_ALLOC_TYPE(n,type) ((type *) TMP_ALLOC ((n) * sizeof (type))) -#define TMP_ALLOC_LIMBS(n) TMP_ALLOC_TYPE(n,mp_limb_t) -#define TMP_ALLOC_MP_PTRS(n) TMP_ALLOC_TYPE(n,mp_ptr) - - -#if ! defined (__GNUC__) /* FIXME: Test for C++ compilers here, - __DECC understands __inline */ -#define inline /* Empty */ -#endif - -#define ABS(x) (x >= 0 ? x : -x) -#define MIN(l,o) ((l) < (o) ? (l) : (o)) -#define MAX(h,i) ((h) > (i) ? (h) : (i)) -#define numberof(x) (sizeof (x) / sizeof ((x)[0])) - -/* Field access macros. */ -#define SIZ(x) ((x)->_mp_size) -#define ABSIZ(x) ABS (SIZ (x)) -#define PTR(x) ((x)->_mp_d) -#define LIMBS(x) ((x)->_mp_d) -#define EXP(x) ((x)->_mp_exp) -#define PREC(x) ((x)->_mp_prec) -#define ALLOC(x) ((x)->_mp_alloc) - -/* Extra casts because shorts are promoted to ints by "~" and "<<". "-1" - rather than "1" in SIGNED_TYPE_MIN avoids warnings from some compilers - about arithmetic overflow. */ -#define UNSIGNED_TYPE_MAX(type) ((type) ~ (type) 0) -#define UNSIGNED_TYPE_HIGHBIT(type) ((type) ~ (UNSIGNED_TYPE_MAX(type) >> 1)) -#define SIGNED_TYPE_MIN(type) (((type) -1) << (8*sizeof(type)-1)) -#define SIGNED_TYPE_MAX(type) ((type) ~ SIGNED_TYPE_MIN(type)) -#define SIGNED_TYPE_HIGHBIT(type) SIGNED_TYPE_MIN(type) - -#define MP_LIMB_T_MAX UNSIGNED_TYPE_MAX (mp_limb_t) -#define MP_LIMB_T_HIGHBIT UNSIGNED_TYPE_HIGHBIT (mp_limb_t) - -#define MP_SIZE_T_MAX SIGNED_TYPE_MAX (mp_size_t) - -#ifndef ULONG_MAX -#define ULONG_MAX UNSIGNED_TYPE_MAX (unsigned long) -#endif -#define ULONG_HIGHBIT UNSIGNED_TYPE_HIGHBIT (unsigned long) -#define LONG_HIGHBIT SIGNED_TYPE_HIGHBIT (long) -#ifndef LONG_MAX -#define LONG_MAX SIGNED_TYPE_MAX (long) -#endif - -#ifndef USHORT_MAX -#define USHORT_MAX UNSIGNED_TYPE_MAX (unsigned short) -#endif -#define USHORT_HIGHBIT UNSIGNED_TYPE_HIGHBIT (unsigned short) -#define SHORT_HIGHBIT SIGNED_TYPE_HIGHBIT (short) -#ifndef SHORT_MAX -#define SHORT_MAX SIGNED_TYPE_MAX (short) -#endif - - -/* Swap macros. */ - -#define MP_LIMB_T_SWAP(x, y) \ - do { \ - mp_limb_t __mp_limb_t_swap__tmp = (x); \ - (x) = (y); \ - (y) = __mp_limb_t_swap__tmp; \ - } while (0) -#define MP_SIZE_T_SWAP(x, y) \ - do { \ - mp_size_t __mp_size_t_swap__tmp = (x); \ - (x) = (y); \ - (y) = __mp_size_t_swap__tmp; \ - } while (0) - -#define MP_PTR_SWAP(x, y) \ - do { \ - mp_ptr __mp_ptr_swap__tmp = (x); \ - (x) = (y); \ - (y) = __mp_ptr_swap__tmp; \ - } while (0) -#define MP_SRCPTR_SWAP(x, y) \ - do { \ - mp_srcptr __mp_srcptr_swap__tmp = (x); \ - (x) = (y); \ - (y) = __mp_srcptr_swap__tmp; \ - } while (0) - -#define MPN_PTR_SWAP(xp,xs, yp,ys) \ - do { \ - MP_PTR_SWAP (xp, yp); \ - MP_SIZE_T_SWAP (xs, ys); \ - } while(0) -#define MPN_SRCPTR_SWAP(xp,xs, yp,ys) \ - do { \ - MP_SRCPTR_SWAP (xp, yp); \ - MP_SIZE_T_SWAP (xs, ys); \ - } while(0) - -#define MPZ_PTR_SWAP(x, y) \ - do { \ - mpz_ptr __mpz_ptr_swap__tmp = (x); \ - (x) = (y); \ - (y) = __mpz_ptr_swap__tmp; \ - } while (0) -#define MPZ_SRCPTR_SWAP(x, y) \ - do { \ - mpz_srcptr __mpz_srcptr_swap__tmp = (x); \ - (x) = (y); \ - (y) = __mpz_srcptr_swap__tmp; \ - } while (0) - - -#if defined (__cplusplus) -extern "C" { -#endif - -/* FIXME: These are purely internal, so do a search and replace to change - them to __gmp forms, rather than using these macros. */ -#define _mp_allocate_func __gmp_allocate_func -#define _mp_reallocate_func __gmp_reallocate_func -#define _mp_free_func __gmp_free_func -#define _mp_default_allocate __gmp_default_allocate -#define _mp_default_reallocate __gmp_default_reallocate -#define _mp_default_free __gmp_default_free - -extern void * (*_mp_allocate_func) _PROTO ((size_t)); -extern void * (*_mp_reallocate_func) _PROTO ((void *, size_t, size_t)); -extern void (*_mp_free_func) _PROTO ((void *, size_t)); - -void *_mp_default_allocate _PROTO ((size_t)); -void *_mp_default_reallocate _PROTO ((void *, size_t, size_t)); -void _mp_default_free _PROTO ((void *, size_t)); - -#define _MP_ALLOCATE_FUNC_TYPE(n,type) \ - ((type *) (*_mp_allocate_func) ((n) * sizeof (type))) -#define _MP_ALLOCATE_FUNC_LIMBS(n) _MP_ALLOCATE_FUNC_TYPE(n,mp_limb_t) - -#define _MP_FREE_FUNC_TYPE(p,n,type) (*_mp_free_func) (p, (n) * sizeof (type)) -#define _MP_FREE_FUNC_LIMBS(p,n) _MP_FREE_FUNC_TYPE(p,n,mp_limb_t) - - -#if (__STDC__-0) || defined (__cplusplus) - -#else - -#define const /* Empty */ -#define signed /* Empty */ - -#endif - -#if defined (__GNUC__) && defined (__i386__) -#if 0 /* check that these actually improve things */ -#define MPN_COPY_INCR(DST, SRC, N) \ - __asm__ ("cld\n\trep\n\tmovsl" : : \ - "D" (DST), "S" (SRC), "c" (N) : \ - "cx", "di", "si", "memory") -#define MPN_COPY_DECR(DST, SRC, N) \ - __asm__ ("std\n\trep\n\tmovsl" : : \ - "D" ((DST) + (N) - 1), "S" ((SRC) + (N) - 1), "c" (N) : \ - "cx", "di", "si", "memory") -#define MPN_NORMALIZE_NOT_ZERO(P, N) \ - do { \ - __asm__ ("std\n\trepe\n\tscasl" : "=c" (N) : \ - "a" (0), "D" ((P) + (N) - 1), "0" (N) : \ - "cx", "di"); \ - (N)++; \ - } while (0) -#endif -#endif - -#if HAVE_NATIVE_mpn_copyi -#define mpn_copyi __MPN(copyi) -void mpn_copyi _PROTO ((mp_ptr, mp_srcptr, mp_size_t)); -#endif - -/* Remap names of internal mpn functions. */ -#define __clz_tab __MPN(clz_tab) -#define mpn_udiv_w_sdiv __MPN(udiv_w_sdiv) -#define mpn_reciprocal __MPN(reciprocal) - -#define mpn_sb_divrem_mn __MPN(sb_divrem_mn) -#define mpn_bz_divrem_n __MPN(bz_divrem_n) -#define mpn_tdiv_qr __MPN(tdiv_qr) -/* #define mpn_tdiv_q __MPN(tdiv_q) */ - -#define mpn_kara_mul_n __MPN(kara_mul_n) -void mpn_kara_mul_n _PROTO((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_ptr)); - -#define mpn_kara_sqr_n __MPN(kara_sqr_n) -void mpn_kara_sqr_n _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_ptr)); - -#define mpn_toom3_mul_n __MPN(toom3_mul_n) -void mpn_toom3_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t,mp_ptr)); - -#define mpn_toom3_sqr_n __MPN(toom3_sqr_n) -void mpn_toom3_sqr_n _PROTO((mp_ptr, mp_srcptr, mp_size_t, mp_ptr)); - -#define mpn_fft_best_k __MPN(fft_best_k) -int mpn_fft_best_k _PROTO ((mp_size_t n, int sqr)); - -#define mpn_mul_fft __MPN(mul_fft) -void mpn_mul_fft _PROTO ((mp_ptr op, mp_size_t pl, - mp_srcptr n, mp_size_t nl, - mp_srcptr m, mp_size_t ml, - int k)); - -#define mpn_mul_fft_full __MPN(mul_fft_full) -void mpn_mul_fft_full _PROTO ((mp_ptr op, - mp_srcptr n, mp_size_t nl, - mp_srcptr m, mp_size_t ml)); - -#define mpn_fft_next_size __MPN(fft_next_size) -mp_size_t mpn_fft_next_size _PROTO ((mp_size_t pl, int k)); - -mp_limb_t mpn_sb_divrem_mn _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)); -mp_limb_t mpn_bz_divrem_n _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)); -void mpn_tdiv_qr _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); -/* void mpn_tdiv_q _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); */ - -/* Copy NLIMBS *limbs* from SRC to DST, NLIMBS==0 allowed. */ -#ifndef MPN_COPY_INCR -#if HAVE_NATIVE_mpn_copyi -#define MPN_COPY_INCR(DST, SRC, NLIMBS) mpn_copyi (DST, SRC, NLIMBS) -#else -#define MPN_COPY_INCR(DST, SRC, NLIMBS) \ - do { \ - mp_size_t __i; \ - for (__i = 0; __i < (NLIMBS); __i++) \ - (DST)[__i] = (SRC)[__i]; \ - } while (0) -#endif -#endif - -#if HAVE_NATIVE_mpn_copyd -#define mpn_copyd __MPN(copyd) -void mpn_copyd _PROTO ((mp_ptr, mp_srcptr, mp_size_t)); -#endif - -/* NLIMBS==0 allowed */ -#ifndef MPN_COPY_DECR -#if HAVE_NATIVE_mpn_copyd -#define MPN_COPY_DECR(DST, SRC, NLIMBS) mpn_copyd (DST, SRC, NLIMBS) -#else -#define MPN_COPY_DECR(DST, SRC, NLIMBS) \ - do { \ - mp_size_t __i; \ - for (__i = (NLIMBS) - 1; __i >= 0; __i--) \ - (DST)[__i] = (SRC)[__i]; \ - } while (0) -#endif -#endif - -/* Define MPN_COPY for vector computers. Since #pragma cannot be in a macro, - rely on function inlining. */ -#if defined (_CRAY) || defined (__uxp__) -static inline void -_MPN_COPY (d, s, n) mp_ptr d; mp_srcptr s; mp_size_t n; -{ - int i; /* Faster for Cray with plain int */ -#pragma _CRI ivdep /* Cray PVP systems */ -#pragma loop noalias d,s /* Fujitsu VPP systems */ - for (i = 0; i < n; i++) - d[i] = s[i]; -} -#define MPN_COPY _MPN_COPY -#endif - -#ifndef MPN_COPY -#define MPN_COPY MPN_COPY_INCR -#endif - -/* Zero NLIMBS *limbs* AT DST. */ -#ifndef MPN_ZERO -#define MPN_ZERO(DST, NLIMBS) \ - do { \ - mp_size_t __i; \ - for (__i = 0; __i < (NLIMBS); __i++) \ - (DST)[__i] = 0; \ - } while (0) -#endif - -#ifndef MPN_NORMALIZE -#define MPN_NORMALIZE(DST, NLIMBS) \ - do { \ - while (NLIMBS > 0) \ - { \ - if ((DST)[(NLIMBS) - 1] != 0) \ - break; \ - NLIMBS--; \ - } \ - } while (0) -#endif -#ifndef MPN_NORMALIZE_NOT_ZERO -#define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \ - do { \ - while (1) \ - { \ - if ((DST)[(NLIMBS) - 1] != 0) \ - break; \ - NLIMBS--; \ - } \ - } while (0) -#endif - -/* Strip least significant zero limbs from ptr,size by incrementing ptr and - decrementing size. The number in ptr,size must be non-zero, ie. size!=0 - and somewhere a non-zero limb. */ -#define MPN_STRIP_LOW_ZEROS_NOT_ZERO(ptr, size) \ - do \ - { \ - ASSERT ((size) != 0); \ - while ((ptr)[0] == 0) \ - { \ - (ptr)++; \ - (size)--; \ - ASSERT (size >= 0); \ - } \ - } \ - while (0) - -/* Initialize X of type mpz_t with space for NLIMBS limbs. X should be a - temporary variable; it will be automatically cleared out at function - return. We use __x here to make it possible to accept both mpz_ptr and - mpz_t arguments. */ -#define MPZ_TMP_INIT(X, NLIMBS) \ - do { \ - mpz_ptr __x = (X); \ - __x->_mp_alloc = (NLIMBS); \ - __x->_mp_d = (mp_ptr) TMP_ALLOC ((NLIMBS) * BYTES_PER_MP_LIMB); \ - } while (0) - -/* Realloc for an mpz_t WHAT if it has less thann NEEDED limbs. */ -#define MPZ_REALLOC(what,needed) \ - do { \ - if ((needed) > ALLOC (what)) \ - _mpz_realloc (what, needed); \ - } while (0) - -/* If KARATSUBA_MUL_THRESHOLD is not already defined, define it to a - value which is good on most machines. */ -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 32 -#endif - -/* If TOOM3_MUL_THRESHOLD is not already defined, define it to a - value which is good on most machines. */ -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 256 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD (2*KARATSUBA_MUL_THRESHOLD) -#endif - -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD (2*TOOM3_MUL_THRESHOLD) -#endif - -/* First k to use for an FFT modF multiply. A modF FFT is an order - log(2^k)/log(2^(k-1)) algorithm, so k=3 is merely 1.5 like karatsuba, - whereas k=4 is 1.33 which is faster than toom3 at 1.485. */ -#define FFT_FIRST_K 4 - -/* Threshold at which FFT should be used to do a modF NxN -> N multiply. */ -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD (TOOM3_MUL_THRESHOLD * 3) -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD (TOOM3_SQR_THRESHOLD * 3) -#endif - -/* Threshold at which FFT should be used to do an NxN -> 2N multiply. This - will be a size where FFT is using k=7 or k=8, since an FFT-k used for an - NxN->2N multiply and not recursing into itself is an order - log(2^k)/log(2^(k-2)) algorithm, so it'll be at least k=7 at 1.39 which - is the first better than toom3. */ -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD (FFT_MODF_MUL_THRESHOLD * 10) -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD (FFT_MODF_SQR_THRESHOLD * 10) -#endif - -/* Table of thresholds for successive modF FFT "k"s. The first entry is - where FFT_FIRST_K+1 should be used, the second FFT_FIRST_K+2, - etc. See mpn_fft_best_k(). */ -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE \ - { TOOM3_MUL_THRESHOLD * 4, /* k=5 */ \ - TOOM3_MUL_THRESHOLD * 8, /* k=6 */ \ - TOOM3_MUL_THRESHOLD * 16, /* k=7 */ \ - TOOM3_MUL_THRESHOLD * 32, /* k=8 */ \ - TOOM3_MUL_THRESHOLD * 96, /* k=9 */ \ - TOOM3_MUL_THRESHOLD * 288, /* k=10 */ \ - 0 } -#endif -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE \ - { TOOM3_SQR_THRESHOLD * 4, /* k=5 */ \ - TOOM3_SQR_THRESHOLD * 8, /* k=6 */ \ - TOOM3_SQR_THRESHOLD * 16, /* k=7 */ \ - TOOM3_SQR_THRESHOLD * 32, /* k=8 */ \ - TOOM3_SQR_THRESHOLD * 96, /* k=9 */ \ - TOOM3_SQR_THRESHOLD * 288, /* k=10 */ \ - 0 } -#endif - -#ifndef FFT_TABLE_ATTRS -#define FFT_TABLE_ATTRS static const -#endif - -#define MPN_FFT_TABLE_SIZE 16 - - -/* Return non-zero if xp,xsize and yp,ysize overlap. - If xp+xsize<=yp there's no overlap, or if yp+ysize<=xp there's no - overlap. If both these are false, there's an overlap. */ -#define MPN_OVERLAP_P(xp, xsize, yp, ysize) \ - ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp)) - - -/* ASSERT() is a private assertion checking scheme, similar to . - ASSERT() does the check only if WANT_ASSERT is selected, ASSERT_ALWAYS() - does it always. Generally assertions are meant for development, but - might help when looking for a problem later too. - - ASSERT_NOCARRY() uses ASSERT() to check the expression is zero, but if - assertion checking is disabled, the expression is still evaluated. This - is meant for use with routines like mpn_add_n() where the return value - represents a carry or whatever that shouldn't occur. For example, - ASSERT_NOCARRY (mpn_add_n (rp, s1p, s2p, size)); */ - -#ifdef __LINE__ -#define ASSERT_LINE __LINE__ -#else -#define ASSERT_LINE -1 -#endif - -#ifdef __FILE__ -#define ASSERT_FILE __FILE__ -#else -#define ASSERT_FILE "" -#endif - -int __gmp_assert_fail _PROTO((const char *filename, int linenum, - const char *expr)); - -#if HAVE_STRINGIZE -#define ASSERT_FAIL(expr) __gmp_assert_fail (ASSERT_FILE, ASSERT_LINE, #expr) -#else -#define ASSERT_FAIL(expr) __gmp_assert_fail (ASSERT_FILE, ASSERT_LINE, "expr") -#endif - -#if HAVE_VOID -#define CAST_TO_VOID (void) -#else -#define CAST_TO_VOID -#endif - -#define ASSERT_ALWAYS(expr) ((expr) ? 0 : ASSERT_FAIL (expr)) - -#if WANT_ASSERT -#define ASSERT(expr) ASSERT_ALWAYS (expr) -#define ASSERT_NOCARRY(expr) ASSERT_ALWAYS ((expr) == 0) - -#else -#define ASSERT(expr) (CAST_TO_VOID 0) -#define ASSERT_NOCARRY(expr) (expr) -#endif - - -#if HAVE_NATIVE_mpn_com_n -#define mpn_com_n __MPN(com_n) -void mpn_com_n _PROTO ((mp_ptr, mp_srcptr, mp_size_t)); -#else -#define mpn_com_n(d,s,n) \ - do \ - { \ - mp_ptr __d = (d); \ - mp_srcptr __s = (s); \ - mp_size_t __n = (n); \ - do \ - *__d++ = *__s++; \ - while (--__n); \ - } \ - while (0) -#endif - -#define MPN_LOGOPS_N_INLINE(d,s1,s2,n,dop,op,s2op) \ - do \ - { \ - mp_ptr __d = (d); \ - mp_srcptr __s1 = (s1); \ - mp_srcptr __s2 = (s2); \ - mp_size_t __n = (n); \ - do \ - *__d++ = dop (*__s1++ op s2op *__s2++); \ - while (--__n); \ - } \ - while (0) - -#if HAVE_NATIVE_mpn_and_n -#define mpn_and_n __MPN(and_n) -void mpn_and_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_and_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,&, ) -#endif - -#if HAVE_NATIVE_mpn_andn_n -#define mpn_andn_n __MPN(andn_n) -void mpn_andn_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_andn_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,&,~) -#endif - -#if HAVE_NATIVE_mpn_nand_n -#define mpn_nand_n __MPN(nand_n) -void mpn_nand_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_nand_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n,~,&, ) -#endif - -#if HAVE_NATIVE_mpn_ior_n -#define mpn_ior_n __MPN(ior_n) -void mpn_ior_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_ior_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,|, ) -#endif - -#if HAVE_NATIVE_mpn_iorn_n -#define mpn_iorn_n __MPN(iorn_n) -void mpn_iorn_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_iorn_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,|,~) -#endif - -#if HAVE_NATIVE_mpn_nior_n -#define mpn_nior_n __MPN(nior_n) -void mpn_nior_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_nior_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n,~,|, ) -#endif - -#if HAVE_NATIVE_mpn_xor_n -#define mpn_xor_n __MPN(xor_n) -void mpn_xor_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_xor_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,^, ) -#endif - -#if HAVE_NATIVE_mpn_xnor_n -#define mpn_xnor_n __MPN(xnor_n) -void mpn_xnor_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -#else -#define mpn_xnor_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n,~,^, ) -#endif - -/* Structure for conversion between internal binary format and - strings in base 2..36. */ -struct bases -{ - /* Number of digits in the conversion base that always fits in an mp_limb_t. - For example, for base 10 on a machine where a mp_limb_t has 32 bits this - is 9, since 10**9 is the largest number that fits into a mp_limb_t. */ - int chars_per_limb; - - /* log(2)/log(conversion_base) */ - double chars_per_bit_exactly; - - /* base**chars_per_limb, i.e. the biggest number that fits a word, built by - factors of base. Exception: For 2, 4, 8, etc, big_base is log2(base), - i.e. the number of bits used to represent each digit in the base. */ - mp_limb_t big_base; - - /* A BITS_PER_MP_LIMB bit approximation to 1/big_base, represented as a - fixed-point number. Instead of dividing by big_base an application can - choose to multiply by big_base_inverted. */ - mp_limb_t big_base_inverted; -}; - -#define __mp_bases __MPN(mp_bases) -extern const struct bases __mp_bases[]; -extern mp_size_t __gmp_default_fp_limb_precision; - -#if defined (__i386__) -#define TARGET_REGISTER_STARVED 1 -#else -#define TARGET_REGISTER_STARVED 0 -#endif - -/* Use a library function for invert_limb, if available. */ -#if ! defined (invert_limb) && HAVE_NATIVE_mpn_invert_limb -#define mpn_invert_limb __MPN(invert_limb) -mp_limb_t mpn_invert_limb _PROTO ((mp_limb_t)); -#define invert_limb(invxl,xl) (invxl = __MPN(invert_limb) (xl)) -#endif - -#ifndef invert_limb -#define invert_limb(invxl,xl) \ - do { \ - mp_limb_t dummy; \ - if (xl << 1 == 0) \ - invxl = ~(mp_limb_t) 0; \ - else \ - udiv_qrnnd (invxl, dummy, -xl, 0, xl); \ - } while (0) -#endif - -/* Divide the two-limb number in (NH,,NL) by D, with DI being the largest - limb not larger than (2**(2*BITS_PER_MP_LIMB))/D - (2**BITS_PER_MP_LIMB). - If this would yield overflow, DI should be the largest possible number - (i.e., only ones). For correct operation, the most significant bit of D - has to be set. Put the quotient in Q and the remainder in R. */ -#define udiv_qrnnd_preinv(q, r, nh, nl, d, di) \ - do { \ - mp_limb_t _q, _ql, _r; \ - mp_limb_t _xh, _xl; \ - umul_ppmm (_q, _ql, (nh), (di)); \ - _q += (nh); /* DI is 2**BITS_PER_MP_LIMB too small */\ - umul_ppmm (_xh, _xl, _q, (d)); \ - sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \ - if (_xh != 0) \ - { \ - sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \ - _q += 1; \ - if (_xh != 0) \ - { \ - sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \ - _q += 1; \ - } \ - } \ - if (_r >= (d)) \ - { \ - _r -= (d); \ - _q += 1; \ - } \ - (r) = _r; \ - (q) = _q; \ - } while (0) -/* Like udiv_qrnnd_preinv, but for for any value D. DNORM is D shifted left - so that its most significant bit is set. LGUP is ceil(log2(D)). */ -#define udiv_qrnnd_preinv2gen(q, r, nh, nl, d, di, dnorm, lgup) \ - do { \ - mp_limb_t _n2, _n10, _n1, _nadj, _q1; \ - mp_limb_t _xh, _xl; \ - _n2 = ((nh) << (BITS_PER_MP_LIMB - (lgup))) + ((nl) >> 1 >> (l - 1));\ - _n10 = (nl) << (BITS_PER_MP_LIMB - (lgup)); \ - _n1 = ((mp_limb_signed_t) _n10 >> (BITS_PER_MP_LIMB - 1)); \ - _nadj = _n10 + (_n1 & (dnorm)); \ - umul_ppmm (_xh, _xl, di, _n2 - _n1); \ - add_ssaaaa (_xh, _xl, _xh, _xl, 0, _nadj); \ - _q1 = ~(_n2 + _xh); \ - umul_ppmm (_xh, _xl, _q1, d); \ - add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \ - _xh -= (d); \ - (r) = _xl + ((d) & _xh); \ - (q) = _xh - _q1; \ - } while (0) -/* Exactly like udiv_qrnnd_preinv, but branch-free. It is not clear which - version to use. */ -#define udiv_qrnnd_preinv2norm(q, r, nh, nl, d, di) \ - do { \ - mp_limb_t _n2, _n10, _n1, _nadj, _q1; \ - mp_limb_t _xh, _xl; \ - _n2 = (nh); \ - _n10 = (nl); \ - _n1 = ((mp_limb_signed_t) _n10 >> (BITS_PER_MP_LIMB - 1)); \ - _nadj = _n10 + (_n1 & (d)); \ - umul_ppmm (_xh, _xl, di, _n2 - _n1); \ - add_ssaaaa (_xh, _xl, _xh, _xl, 0, _nadj); \ - _q1 = ~(_n2 + _xh); \ - umul_ppmm (_xh, _xl, _q1, d); \ - add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \ - _xh -= (d); \ - (r) = _xl + ((d) & _xh); \ - (q) = _xh - _q1; \ - } while (0) - - -/* modlimb_invert() sets "inv" to the multiplicative inverse of "n" modulo - 2^BITS_PER_MP_LIMB, ie. so that inv*n == 1 mod 2^BITS_PER_MP_LIMB. - "n" must be odd (otherwise such an inverse doesn't exist). - - This is not to be confused with invert_limb(), which is completely - different. - - The table lookup gives an inverse with the low 8 bits valid, and each - multiply step doubles the number of bits. See Jebelean's exact division - paper, end of section 4 (reference in gmp.texi). */ - -#define modlimb_invert_table __gmp_modlimb_invert_table -extern const unsigned char modlimb_invert_table[128]; - -#if BITS_PER_MP_LIMB <= 32 -#define modlimb_invert(inv,n) \ - do { \ - mp_limb_t __n = (n); \ - mp_limb_t __inv; \ - ASSERT ((__n & 1) == 1); \ - __inv = modlimb_invert_table[(__n&0xFF)/2]; /* 8 */ \ - __inv = 2 * __inv - __inv * __inv * __n; /* 16 */ \ - __inv = 2 * __inv - __inv * __inv * __n; /* 32 */ \ - ASSERT (__inv * __n == 1); \ - (inv) = __inv; \ - } while (0) -#endif - -#if BITS_PER_MP_LIMB > 32 && BITS_PER_MP_LIMB <= 64 -#define modlimb_invert(inv,n) \ - do { \ - mp_limb_t __n = (n); \ - mp_limb_t __inv; \ - ASSERT ((__n & 1) == 1); \ - __inv = modlimb_invert_table[(__n&0xFF)/2]; /* 8 */ \ - __inv = 2 * __inv - __inv * __inv * __n; /* 16 */ \ - __inv = 2 * __inv - __inv * __inv * __n; /* 32 */ \ - __inv = 2 * __inv - __inv * __inv * __n; /* 64 */ \ - ASSERT (__inv * __n == 1); \ - (inv) = __inv; \ - } while (0) -#endif - - -/* The `mode' attribute was introduced in GCC 2.2, but we can only distinguish - between GCC 2 releases from 2.5, since __GNUC_MINOR__ wasn't introduced - until then. */ -#if (__GNUC__ - 0 > 2 || defined (__GNUC_MINOR__)) && ! defined (__APPLE_CC__) -/* Define stuff for longlong.h. */ -typedef unsigned int UQItype __attribute__ ((mode (QI))); -typedef int SItype __attribute__ ((mode (SI))); -typedef unsigned int USItype __attribute__ ((mode (SI))); -typedef int DItype __attribute__ ((mode (DI))); -typedef unsigned int UDItype __attribute__ ((mode (DI))); -#else -typedef unsigned char UQItype; -typedef long SItype; -typedef unsigned long USItype; -#if defined _LONGLONG || defined _LONG_LONG_LIMB -typedef long long int DItype; -typedef unsigned long long int UDItype; -#else /* Assume `long' gives us a wide enough type. Needed for hppa2.0w. */ -typedef long int DItype; -typedef unsigned long int UDItype; -#endif -#endif - -typedef mp_limb_t UWtype; -typedef unsigned int UHWtype; -#define W_TYPE_SIZE BITS_PER_MP_LIMB - -/* Define ieee_double_extract and _GMP_IEEE_FLOATS. */ - -#if (defined (__arm__) && (defined (__ARMWEL__) || defined (__linux__))) -/* Special case for little endian ARM since floats remain in big-endian. */ -#define _GMP_IEEE_FLOATS 1 -union ieee_double_extract -{ - struct - { - unsigned int manh:20; - unsigned int exp:11; - unsigned int sig:1; - unsigned int manl:32; - } s; - double d; -}; -#else -#if defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__) \ - || defined (__alpha) \ - || defined (__clipper__) \ - || defined (__cris) \ - || defined (__i386__) \ - || defined (__i860__) \ - || defined (__i960__) \ - || defined (MIPSEL) || defined (_MIPSEL) \ - || defined (__ns32000__) \ - || defined (__WINNT) || defined (_WIN32) -#define _GMP_IEEE_FLOATS 1 -union ieee_double_extract -{ - struct - { - unsigned int manl:32; - unsigned int manh:20; - unsigned int exp:11; - unsigned int sig:1; - } s; - double d; -}; -#else /* Need this as an #else since the tests aren't made exclusive. */ -#if defined (_BIG_ENDIAN) || defined (__BIG_ENDIAN__) \ - || defined (__a29k__) || defined (_AM29K) \ - || defined (__arm__) \ - || (defined (__convex__) && defined (_IEEE_FLOAT_)) \ - || defined (_CRAYMPP) \ - || defined (__i370__) || defined (__mvs__) \ - || defined (__mc68000__) || defined (__mc68020__) || defined (__m68k__)\ - || defined(mc68020) \ - || defined (__m88000__) \ - || defined (MIPSEB) || defined (_MIPSEB) \ - || defined (__hppa) || defined (__hppa__) \ - || defined (__pyr__) \ - || defined (__ibm032__) \ - || defined (_IBMR2) || defined (_ARCH_PPC) \ - || defined (__sh__) \ - || defined (__sparc) || defined (sparc) \ - || defined (__we32k__) -#define _GMP_IEEE_FLOATS 1 -union ieee_double_extract -{ - struct - { - unsigned int sig:1; - unsigned int exp:11; - unsigned int manh:20; - unsigned int manl:32; - } s; - double d; -}; -#endif -#endif -#endif - -/* Using "(2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))" doesn't work on - SunOS 4.1.4 native /usr/ucb/cc (K&R), it comes out as -4294967296.0, - presumably due to treating the mp_limb_t constant as signed rather than - unsigned. */ -#define MP_BASE_AS_DOUBLE (4.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 2))) -#if BITS_PER_MP_LIMB == 64 -#define LIMBS_PER_DOUBLE 2 -#else -#define LIMBS_PER_DOUBLE 3 -#endif - -double __gmp_scale2 _PROTO ((double, int)); -int __gmp_extract_double _PROTO ((mp_ptr, double)); - -extern int __gmp_junk; -extern const int __gmp_0; -#define GMP_ERROR(code) (gmp_errno |= (code), __gmp_junk = 10/__gmp_0) -#define DIVIDE_BY_ZERO GMP_ERROR(GMP_ERROR_DIVISION_BY_ZERO) -#define SQRT_OF_NEGATIVE GMP_ERROR(GMP_ERROR_SQRT_OF_NEGATIVE) - -#if defined _LONG_LONG_LIMB -#if defined (__STDC__) -#define CNST_LIMB(C) C##LL -#else -#define CNST_LIMB(C) C/**/LL -#endif -#else /* not _LONG_LONG_LIMB */ -#if defined (__STDC__) -#define CNST_LIMB(C) C##L -#else -#define CNST_LIMB(C) C/**/L -#endif -#endif /* _LONG_LONG_LIMB */ - -/*** Stuff used by mpn/generic/prefsqr.c and mpn/generic/next_prime.c ***/ -#if BITS_PER_MP_LIMB == 32 -#define PP 0xC0CFD797L /* 3 x 5 x 7 x 11 x 13 x ... x 29 */ -#define PP_INVERTED 0x53E5645CL -#define PP_MAXPRIME 29 -#define PP_MASK 0x208A28A8L -#endif - -#if BITS_PER_MP_LIMB == 64 -#define PP CNST_LIMB(0xE221F97C30E94E1D) /* 3 x 5 x 7 x 11 x 13 x ... x 53 */ -#define PP_INVERTED CNST_LIMB(0x21CFE6CFC938B36B) -#define PP_MAXPRIME 53 -#define PP_MASK CNST_LIMB(0x208A20A08A28A8) -#endif - - -/* BIT1 means a result value in bit 1 (second least significant bit), with a - zero bit representing +1 and a one bit representing -1. Bits other than - bit 1 are garbage. - - JACOBI_TWOS_U_BIT1 and JACOBI_RECIP_UU_BIT1 are used in mpn_jacobi_base - and their speed is important. Expressions are used rather than - conditionals to accumulate sign changes, which effectively means XORs - instead of conditional JUMPs. */ - -/* (a/0), with a signed; is 1 if a=+/-1, 0 otherwise */ -#define JACOBI_S0(a) \ - (((a) == 1) | ((a) == -1)) - -/* (a/0), with a unsigned; is 1 if a=+/-1, 0 otherwise */ -#define JACOBI_U0(a) \ - ((a) == 1) - -/* (a/0), with a an mpz_t; is 1 if a=+/-1, 0 otherwise - An mpz_t always has at least one limb of allocated space, so the fetch of - the low limb is valid. */ -#define JACOBI_Z0(a) \ - (((SIZ(a) == 1) | (SIZ(a) == -1)) & (PTR(a)[0] == 1)) - -/* Convert a bit1 to +1 or -1. */ -#define JACOBI_BIT1_TO_PN(result_bit1) \ - (1 - ((result_bit1) & 2)) - -/* (2/b), with b unsigned and odd; - is (-1)^((b^2-1)/8) which is 1 if b==1,7mod8 or -1 if b==3,5mod8 and - hence obtained from (b>>1)^b */ -#define JACOBI_TWO_U_BIT1(b) \ - (ASSERT (b & 1), (((b) >> 1) ^ (b))) - -/* (2/b)^twos, with b unsigned and odd */ -#define JACOBI_TWOS_U_BIT1(twos, b) \ - (((twos) << 1) & JACOBI_TWO_U_BIT1 (b)) - -/* (2/b)^twos, with b unsigned and odd */ -#define JACOBI_TWOS_U(twos, b) \ - (JACOBI_BIT1_TO_PN (JACOBI_TWOS_U_BIT1 (twos, b))) - -/* (a/b) effect due to sign of a: signed/unsigned, b odd; - is (-1)^((b-1)/2) if a<0, or +1 if a>=0 */ -#define JACOBI_ASGN_SU_BIT1(a, b) \ - ((((a) < 0) << 1) & (b)) - -/* (a/b) effect due to sign of b: signed/mpz; - is -1 if a and b both negative, +1 otherwise */ -#define JACOBI_BSGN_SZ_BIT1(a, b) \ - ((((a) < 0) & (SIZ(b) < 0)) << 1) - -/* (a/b) effect due to sign of b: mpz/signed */ -#define JACOBI_BSGN_ZS_BIT1(a, b) \ - JACOBI_BSGN_SZ_BIT1(b, a) - -/* (a/b) reciprocity to switch to (b/a), a,b both unsigned and odd. - Is (-1)^((a-1)*(b-1)/4), which means +1 if either a,b==1mod4 or -1 if - both a,b==3mod4, achieved in bit 1 by a&b. No ASSERT()s about a,b odd - because this is used in a couple of places with only bit 1 of a or b - valid. */ -#define JACOBI_RECIP_UU_BIT1(a, b) \ - ((a) & (b)) - - -/* For testing and debugging. */ -#define MPZ_CHECK_FORMAT(z) \ - (ASSERT_ALWAYS (SIZ(z) == 0 || PTR(z)[ABSIZ(z) - 1] != 0), \ - ASSERT_ALWAYS (ALLOC(z) >= ABSIZ(z))) -#define MPZ_PROVOKE_REALLOC(z) \ - do { ALLOC(z) = ABSIZ(z); } while (0) - - -#if TUNE_PROGRAM_BUILD -/* Some extras wanted when recompiling some .c files for use by the tune - program. Not part of a normal build. */ - -extern mp_size_t mul_threshold[]; -extern mp_size_t fft_modf_mul_threshold; -extern mp_size_t sqr_threshold[]; -extern mp_size_t fft_modf_sqr_threshold; -extern mp_size_t bz_threshold[]; -extern mp_size_t fib_threshold[]; -extern mp_size_t powm_threshold[]; -extern mp_size_t gcd_accel_threshold[]; -extern mp_size_t gcdext_threshold[]; - -#undef KARATSUBA_MUL_THRESHOLD -#undef TOOM3_MUL_THRESHOLD -#undef FFT_MUL_TABLE -#undef FFT_MUL_THRESHOLD -#undef FFT_MODF_MUL_THRESHOLD -#undef KARATSUBA_SQR_THRESHOLD -#undef TOOM3_SQR_THRESHOLD -#undef FFT_SQR_TABLE -#undef FFT_SQR_THRESHOLD -#undef FFT_MODF_SQR_THRESHOLD -#undef BZ_THRESHOLD -#undef FIB_THRESHOLD -#undef POWM_THRESHOLD -#undef GCD_ACCEL_THRESHOLD -#undef GCDEXT_THRESHOLD - -#define KARATSUBA_MUL_THRESHOLD mul_threshold[0] -#define TOOM3_MUL_THRESHOLD mul_threshold[1] -#define FFT_MUL_TABLE 0 -#define FFT_MUL_THRESHOLD mul_threshold[2] -#define FFT_MODF_MUL_THRESHOLD fft_modf_mul_threshold -#define KARATSUBA_SQR_THRESHOLD sqr_threshold[0] -#define TOOM3_SQR_THRESHOLD sqr_threshold[1] -#define FFT_SQR_TABLE 0 -#define FFT_SQR_THRESHOLD sqr_threshold[2] -#define FFT_MODF_SQR_THRESHOLD fft_modf_sqr_threshold -#define BZ_THRESHOLD bz_threshold[0] -#define FIB_THRESHOLD fib_threshold[0] -#define POWM_THRESHOLD powm_threshold[0] -#define GCD_ACCEL_THRESHOLD gcd_accel_threshold[0] -#define GCDEXT_THRESHOLD gcdext_threshold[0] - -#define TOOM3_MUL_THRESHOLD_LIMIT 700 - -#undef FFT_TABLE_ATTRS -#define FFT_TABLE_ATTRS -extern mp_size_t mpn_fft_table[2][MPN_FFT_TABLE_SIZE]; - -#endif /* TUNE_PROGRAM_BUILD */ - -#if defined (__cplusplus) -} -#endif diff --git a/gmp/gmp.h b/gmp/gmp.h deleted file mode 100755 index eac9b42..0000000 --- a/gmp/gmp.h +++ /dev/null @@ -1,1073 +0,0 @@ -/* gmp.h -- Definitions for GNU multiple precision functions. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#ifndef __GMP_H__ - -#ifndef __GNU_MP__ /* to allow inclusion of both gmp.h and mp.h */ -#define __GNU_MP__ 2 -#define __need_size_t -#include -#undef __need_size_t - -#if defined (__mips) && defined (_ABIN32) -/* Force the use of 64-bit limbs for all 64-bit MIPS CPUs if ABI permits. */ -#define _LONG_LONG_LIMB -#endif - -#if (__STDC__-0) || defined (__cplusplus) -#define __gmp_const const -#define __gmp_signed signed -#else -#define __gmp_const -#define __gmp_signed -#endif - -#if defined (__GNUC__) -#define __gmp_inline __inline__ -#else -#define __gmp_inline -#endif - -#ifndef _EXTERN_INLINE -#ifdef __GNUC__ -#define _EXTERN_INLINE extern __inline__ -#else -#define _EXTERN_INLINE static -#endif -#endif - -#ifdef _SHORT_LIMB -typedef unsigned int mp_limb_t; -typedef int mp_limb_signed_t; -#else -#ifdef _LONG_LONG_LIMB -typedef unsigned long long int mp_limb_t; -typedef long long int mp_limb_signed_t; -#else -typedef unsigned long int mp_limb_t; -typedef long int mp_limb_signed_t; -#endif -#endif - -typedef mp_limb_t * mp_ptr; -typedef __gmp_const mp_limb_t * mp_srcptr; -#if defined (_CRAY) && ! defined (_CRAYMPP) -/* plain `int' is much faster (48 bits) */ -typedef int mp_size_t; -typedef int mp_exp_t; -#else -typedef long int mp_size_t; -typedef long int mp_exp_t; -#endif - -typedef struct -{ - int _mp_alloc; /* Number of *limbs* allocated and pointed - to by the _mp_d field. */ - int _mp_size; /* abs(_mp_size) is the number of limbs the - last field points to. If _mp_size is - negative this is a negative number. */ - mp_limb_t *_mp_d; /* Pointer to the limbs. */ -} __mpz_struct; -#endif /* __GNU_MP__ */ - -typedef __mpz_struct MP_INT; -typedef __mpz_struct mpz_t[1]; - -typedef struct -{ - __mpz_struct _mp_num; - __mpz_struct _mp_den; -} __mpq_struct; - -typedef __mpq_struct MP_RAT; -typedef __mpq_struct mpq_t[1]; - -typedef struct -{ - int _mp_prec; /* Max precision, in number of `mp_limb_t's. - Set by mpf_init and modified by - mpf_set_prec. The area pointed to by the - _mp_d field contains `prec' + 1 limbs. */ - int _mp_size; /* abs(_mp_size) is the number of limbs the - last field points to. If _mp_size is - negative this is a negative number. */ - mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */ - mp_limb_t *_mp_d; /* Pointer to the limbs. */ -} __mpf_struct; - -/* typedef __mpf_struct MP_FLOAT; */ -typedef __mpf_struct mpf_t[1]; - -/* Available random number generation algorithms. */ -typedef enum -{ - GMP_RAND_ALG_DEFAULT = 0, - GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */ -} gmp_randalg_t; - -/* Linear congruential data struct. */ -typedef struct { - mpz_t a; /* Multiplier. */ - unsigned long int c; /* Adder. */ - mpz_t m; /* Modulus (valid only if m2exp == 0). */ - unsigned long int m2exp; /* If != 0, modulus is 2 ^ m2exp. */ -} __gmp_randata_lc; - -/* Random state struct. */ -typedef struct -{ - mpz_t seed; /* Current seed. */ - gmp_randalg_t alg; /* Algorithm used. */ - union { /* Algorithm specific data. */ - __gmp_randata_lc *lc; /* Linear congruential. */ - } algdata; -} __gmp_randstate_struct; -typedef __gmp_randstate_struct gmp_randstate_t[1]; - -/* Types for function declarations in gmp files. */ -/* ??? Should not pollute user name space with these ??? */ -typedef __gmp_const __mpz_struct *mpz_srcptr; -typedef __mpz_struct *mpz_ptr; -typedef __gmp_const __mpf_struct *mpf_srcptr; -typedef __mpf_struct *mpf_ptr; -typedef __gmp_const __mpq_struct *mpq_srcptr; -typedef __mpq_struct *mpq_ptr; - -#ifndef _PROTO -#if (__STDC__-0) || defined (__cplusplus) -#define _PROTO(x) x -#else -#define _PROTO(x) () -#endif -#endif - -#ifndef __MPN -/* Really use `defined (__STDC__)' here; we want it to be true for Sun C */ -#if defined (__STDC__) || defined (__cplusplus) -#define __MPN(x) __gmpn_##x -#else -#define __MPN(x) __gmpn_/**/x -#endif -#endif - -#if defined (FILE) || defined (H_STDIO) || defined (_H_STDIO) \ - || defined (_STDIO_H) || defined (_STDIO_H_) || defined (__STDIO_H__) \ - || defined (_STDIO_INCLUDED) || defined (__dj_include_stdio_h_) -#define _GMP_H_HAVE_FILE 1 -#endif - -#if defined (__cplusplus) -extern "C" { -#endif - -#define mp_set_memory_functions __gmp_set_memory_functions -void mp_set_memory_functions _PROTO ((void *(*) (size_t), - void *(*) (void *, size_t, size_t), - void (*) (void *, size_t))); - -#define mp_bits_per_limb __gmp_bits_per_limb -extern __gmp_const int mp_bits_per_limb; - -#if defined (__cplusplus) -} -#endif - - -/**************** Random number routines. ****************/ - -#define _gmp_rand __gmp_rand -#define gmp_randinit __gmp_randinit -#define gmp_randinit_lc __gmp_randinit_lc -#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp -#define gmp_randseed __gmp_randseed -#define gmp_randseed_ui __gmp_randseed_ui -#define gmp_randclear __gmp_randclear - -#if defined (__cplusplus) -extern "C" { -#endif - -void _gmp_rand _PROTO ((mp_ptr, gmp_randstate_t, unsigned long int)); -void gmp_randinit _PROTO ((gmp_randstate_t, gmp_randalg_t, ...)); -void gmp_randinit_lc _PROTO ((gmp_randstate_t, mpz_t, unsigned long int, - mpz_t)); -void gmp_randinit_lc_2exp _PROTO ((gmp_randstate_t, mpz_t, unsigned long int, - unsigned long int)); -void gmp_randseed _PROTO ((gmp_randstate_t, mpz_t)); -void gmp_randseed_ui _PROTO ((gmp_randstate_t, unsigned long int)); -void gmp_randclear _PROTO ((gmp_randstate_t)); - -#if defined (__cplusplus) -} -#endif - -/**************** Integer (i.e. Z) routines. ****************/ - -#define _mpz_realloc __gmpz_realloc -#define mpz_realloc __gmpz_realloc -#define mpz_abs __gmpz_abs -#define mpz_add __gmpz_add -#define mpz_add_ui __gmpz_add_ui -#define mpz_addmul_ui __gmpz_addmul_ui -#define mpz_and __gmpz_and -#define mpz_array_init __gmpz_array_init -#define mpz_bin_ui __gmpz_bin_ui -#define mpz_bin_uiui __gmpz_bin_uiui -#define mpz_cdiv_q __gmpz_cdiv_q -#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui -#define mpz_cdiv_qr __gmpz_cdiv_qr -#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui -#define mpz_cdiv_r __gmpz_cdiv_r -#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui -#define mpz_cdiv_ui __gmpz_cdiv_ui -#define mpz_clear __gmpz_clear -#define mpz_clrbit __gmpz_clrbit -#define mpz_cmp __gmpz_cmp -#define _mpz_cmp_si __gmpz_cmp_si -#define _mpz_cmp_ui __gmpz_cmp_ui -#define mpz_cmpabs __gmpz_cmpabs -#define mpz_cmpabs_ui __gmpz_cmpabs_ui -#define mpz_com __gmpz_com -#define mpz_divexact __gmpz_divexact -#define mpz_dump __gmpz_dump -#define mpz_fac_ui __gmpz_fac_ui -#define mpz_fdiv_q __gmpz_fdiv_q -#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp -#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui -#define mpz_fdiv_qr __gmpz_fdiv_qr -#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui -#define mpz_fdiv_r __gmpz_fdiv_r -#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp -#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui -#define mpz_fdiv_ui __gmpz_fdiv_ui -#define mpz_fib_ui __gmpz_fib_ui -#define mpz_fits_sint_p __gmpz_fits_sint_p -#define mpz_fits_slong_p __gmpz_fits_slong_p -#define mpz_fits_sshort_p __gmpz_fits_sshort_p -#define mpz_fits_uint_p __gmpz_fits_uint_p -#define mpz_fits_ulong_p __gmpz_fits_ulong_p -#define mpz_fits_ushort_p __gmpz_fits_ushort_p -#define mpz_gcd __gmpz_gcd -#define mpz_gcd_ui __gmpz_gcd_ui -#define mpz_gcdext __gmpz_gcdext -#define mpz_get_d __gmpz_get_d -#define mpz_get_si __gmpz_get_si -#define mpz_get_str __gmpz_get_str -#define mpz_get_ui __gmpz_get_ui -#define mpz_getlimbn __gmpz_getlimbn -#define mpz_hamdist __gmpz_hamdist -#define mpz_init __gmpz_init -#define mpz_inp_binary __gmpz_inp_binary -#define mpz_inp_raw __gmpz_inp_raw -#define mpz_inp_str __gmpz_inp_str -#define mpz_init_set __gmpz_init_set -#define mpz_init_set_d __gmpz_init_set_d -#define mpz_init_set_si __gmpz_init_set_si -#define mpz_init_set_str __gmpz_init_set_str -#define mpz_init_set_ui __gmpz_init_set_ui -#define mpz_invert __gmpz_invert -#define mpz_ior __gmpz_ior -#define mpz_jacobi __gmpz_jacobi -#define mpz_lcm __gmpz_lcm -#define mpz_legendre __gmpz_legendre -#define mpz_mod __gmpz_mod -#define mpz_mul __gmpz_mul -#define mpz_mul_2exp __gmpz_mul_2exp -#define mpz_neg __gmpz_neg -#define mpz_nextprime __gmpz_nextprime -#define mpz_out_binary __gmpz_out_binary -#define mpz_out_raw __gmpz_out_raw -#define mpz_out_str __gmpz_out_str -#define mpz_perfect_power_p __gmpz_perfect_power_p -#define mpz_perfect_square_p __gmpz_perfect_square_p -#define mpz_popcount __gmpz_popcount -#define mpz_pow_ui __gmpz_pow_ui -#define mpz_powm __gmpz_powm -#define mpz_powm_ui __gmpz_powm_ui -#define mpz_probab_prime_p __gmpz_probab_prime_p -#define mpz_random __gmpz_random -#define mpz_random2 __gmpz_random2 -#define mpz_remove __gmpz_remove -#define mpz_root __gmpz_root -#define mpz_rrandomb __gmpz_rrandomb -#define mpz_scan0 __gmpz_scan0 -#define mpz_scan1 __gmpz_scan1 -#define mpz_set __gmpz_set -#define mpz_set_d __gmpz_set_d -#define mpz_set_f __gmpz_set_f -#define mpz_set_q __gmpz_set_q -#define mpz_set_si __gmpz_set_si -#define mpz_set_str __gmpz_set_str -#define mpz_set_ui __gmpz_set_ui -#define mpz_setbit __gmpz_setbit -#define mpz_size __gmpz_size -#define mpz_sizeinbase __gmpz_sizeinbase -#define mpz_sqrt __gmpz_sqrt -#define mpz_sqrtrem __gmpz_sqrtrem -#define mpz_sub __gmpz_sub -#define mpz_sub_ui __gmpz_sub_ui -#define mpz_swap __gmpz_swap -#define mpz_tdiv_ui __gmpz_tdiv_ui -#define mpz_tdiv_q __gmpz_tdiv_q -#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp -#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui -#define mpz_tdiv_qr __gmpz_tdiv_qr -#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui -#define mpz_tdiv_r __gmpz_tdiv_r -#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp -#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui -#define mpz_tstbit __gmpz_tstbit -#define mpz_ui_pow_ui __gmpz_ui_pow_ui -#define mpz_urandomb __gmpz_urandomb -#define mpz_urandomm __gmpz_urandomm -#define mpz_xor __gmpz_xor -#define mpz_eor __gmpz_xor - -#if defined (__cplusplus) -extern "C" { -#endif -void *_mpz_realloc _PROTO ((mpz_ptr, mp_size_t)); - -void mpz_abs _PROTO ((mpz_ptr, mpz_srcptr)); -void mpz_add _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_add_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_addmul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_and _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_array_init _PROTO ((mpz_ptr, mp_size_t, mp_size_t)); -void mpz_bin_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_bin_uiui _PROTO ((mpz_ptr, unsigned long int, unsigned long int)); -void mpz_cdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -unsigned long int mpz_cdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_cdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); -unsigned long int mpz_cdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_cdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -unsigned long int mpz_cdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -unsigned long int mpz_cdiv_ui _PROTO ((mpz_srcptr, unsigned long int)); -void mpz_clear _PROTO ((mpz_ptr)); -void mpz_clrbit _PROTO ((mpz_ptr, unsigned long int)); -int mpz_cmp _PROTO ((mpz_srcptr, mpz_srcptr)); -int _mpz_cmp_si _PROTO ((mpz_srcptr, signed long int)); -int _mpz_cmp_ui _PROTO ((mpz_srcptr, unsigned long int)); -int mpz_cmpabs _PROTO ((mpz_srcptr, mpz_srcptr)); -int mpz_cmpabs_ui _PROTO ((mpz_srcptr, unsigned long int)); -void mpz_com _PROTO ((mpz_ptr, mpz_srcptr)); -void mpz_divexact _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_dump _PROTO ((mpz_srcptr)); -void mpz_fac_ui _PROTO ((mpz_ptr, unsigned long int)); -void mpz_fdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_fdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -unsigned long int mpz_fdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_fdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); -unsigned long int mpz_fdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_fdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_fdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -unsigned long int mpz_fdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -unsigned long int mpz_fdiv_ui _PROTO ((mpz_srcptr, unsigned long int)); -void mpz_fib_ui _PROTO ((mpz_ptr, unsigned long int)); -int mpz_fits_sint_p _PROTO ((mpz_srcptr)); -int mpz_fits_slong_p _PROTO ((mpz_srcptr)); -int mpz_fits_sshort_p _PROTO ((mpz_srcptr)); -int mpz_fits_uint_p _PROTO ((mpz_srcptr)); -int mpz_fits_ulong_p _PROTO ((mpz_srcptr)); -int mpz_fits_ushort_p _PROTO ((mpz_srcptr)); -void mpz_gcd _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -unsigned long int mpz_gcd_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_gcdext _PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); -double mpz_get_d _PROTO ((mpz_srcptr)); -/* signed */ long int mpz_get_si _PROTO ((mpz_srcptr)); -char *mpz_get_str _PROTO ((char *, int, mpz_srcptr)); -unsigned long int mpz_get_ui _PROTO ((mpz_srcptr)); -mp_limb_t mpz_getlimbn _PROTO ((mpz_srcptr, mp_size_t)); -unsigned long int mpz_hamdist _PROTO ((mpz_srcptr, mpz_srcptr)); -void mpz_init _PROTO ((mpz_ptr)); -#ifdef _GMP_H_HAVE_FILE -size_t mpz_inp_binary _PROTO ((mpz_ptr, FILE *)); -size_t mpz_inp_raw _PROTO ((mpz_ptr, FILE *)); -size_t mpz_inp_str _PROTO ((mpz_ptr, FILE *, int)); -#endif -void mpz_init_set _PROTO ((mpz_ptr, mpz_srcptr)); -void mpz_init_set_d _PROTO ((mpz_ptr, double)); -void mpz_init_set_si _PROTO ((mpz_ptr, signed long int)); -int mpz_init_set_str _PROTO ((mpz_ptr, __gmp_const char *, int)); -void mpz_init_set_ui _PROTO ((mpz_ptr, unsigned long int)); -int mpz_invert _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_ior _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -int mpz_jacobi _PROTO ((mpz_srcptr, mpz_srcptr)); - -#define mpz_kronecker_si __gmpz_kronecker_si -int mpz_kronecker_si _PROTO ((mpz_srcptr, long)); - -#define mpz_kronecker_ui __gmpz_kronecker_ui -int mpz_kronecker_ui _PROTO ((mpz_srcptr, unsigned long)); - -#define mpz_si_kronecker __gmpz_si_kronecker -int mpz_si_kronecker _PROTO ((long, mpz_srcptr)); - -#define mpz_ui_kronecker __gmpz_ui_kronecker -int mpz_ui_kronecker _PROTO ((unsigned long, mpz_srcptr)); - -void mpz_lcm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -int mpz_legendre _PROTO ((mpz_srcptr, mpz_srcptr)); -void mpz_mod _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_mul _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_mul_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); - -#define mpz_mul_si __gmpz_mul_si -void mpz_mul_si _PROTO ((mpz_ptr, mpz_srcptr, long int)); - -#define mpz_mul_ui __gmpz_mul_ui -void mpz_mul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); - -void mpz_neg _PROTO ((mpz_ptr, mpz_srcptr)); -void mpz_nextprime _PROTO ((mpz_ptr, mpz_srcptr)); -#ifdef _GMP_H_HAVE_FILE -size_t mpz_out_binary _PROTO ((FILE *, mpz_srcptr)); -size_t mpz_out_raw _PROTO ((FILE *, mpz_srcptr)); -size_t mpz_out_str _PROTO ((FILE *, int, mpz_srcptr)); -#endif -int mpz_perfect_power_p _PROTO ((mpz_srcptr)); -int mpz_perfect_square_p _PROTO ((mpz_srcptr)); -unsigned long int mpz_popcount _PROTO ((mpz_srcptr)); -void mpz_pow_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_powm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr)); -void mpz_powm_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr)); -int mpz_probab_prime_p _PROTO ((mpz_srcptr, int)); -void mpz_random _PROTO ((mpz_ptr, mp_size_t)); -void mpz_random2 _PROTO ((mpz_ptr, mp_size_t)); -unsigned long int mpz_remove _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -int mpz_root _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_rrandomb _PROTO ((mpz_ptr, gmp_randstate_t, unsigned long int)); -unsigned long int mpz_scan0 _PROTO ((mpz_srcptr, unsigned long int)); -unsigned long int mpz_scan1 _PROTO ((mpz_srcptr, unsigned long int)); -void mpz_set _PROTO ((mpz_ptr, mpz_srcptr)); -void mpz_set_d _PROTO ((mpz_ptr, double)); -void mpz_set_f _PROTO ((mpz_ptr, mpf_srcptr)); -void mpz_set_q _PROTO ((mpz_ptr, mpq_srcptr)); -void mpz_set_si _PROTO ((mpz_ptr, signed long int)); -int mpz_set_str _PROTO ((mpz_ptr, __gmp_const char *, int)); -void mpz_set_ui _PROTO ((mpz_ptr, unsigned long int)); -void mpz_setbit _PROTO ((mpz_ptr, unsigned long int)); -size_t mpz_size _PROTO ((mpz_srcptr)); -size_t mpz_sizeinbase _PROTO ((mpz_srcptr, int)); -void mpz_sqrt _PROTO ((mpz_ptr, mpz_srcptr)); -void mpz_sqrtrem _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr)); -void mpz_sub _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_sub_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_swap _PROTO ((mpz_ptr, mpz_ptr)); -void mpz_tdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_tdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -unsigned long int mpz_tdiv_ui _PROTO ((mpz_srcptr, unsigned long int)); -unsigned long int mpz_tdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_tdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); -unsigned long int mpz_tdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); -void mpz_tdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -void mpz_tdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -unsigned long int mpz_tdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -int mpz_tstbit _PROTO ((mpz_srcptr, unsigned long int)); -void mpz_ui_pow_ui _PROTO ((mpz_ptr, unsigned long int, unsigned long int)); -void mpz_urandomb _PROTO ((mpz_t, gmp_randstate_t, unsigned long int)); -void mpz_urandomm _PROTO ((mpz_t, gmp_randstate_t, mpz_t)); -void mpz_xor _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -#if defined (__cplusplus) -} -#endif - -/**************** Rational (i.e. Q) routines. ****************/ - -#define mpq_init __gmpq_init -#define mpq_clear __gmpq_clear -#define mpq_set __gmpq_set -#define mpq_set_ui __gmpq_set_ui -#define mpq_set_si __gmpq_set_si -#define mpq_set_z __gmpq_set_z -#define mpq_add __gmpq_add -#define mpq_sub __gmpq_sub -#define mpq_mul __gmpq_mul -#define mpq_div __gmpq_div -#define mpq_neg __gmpq_neg -#define mpq_cmp __gmpq_cmp -#define _mpq_cmp_ui __gmpq_cmp_ui -#define mpq_equal __gmpq_equal -#define mpq_inv __gmpq_inv -#define mpq_set_num __gmpq_set_num -#define mpq_set_den __gmpq_set_den -#define mpq_get_num __gmpq_get_num -#define mpq_get_den __gmpq_get_den -#define mpq_get_d __gmpq_get_d -#define mpq_set_d __gmpq_set_d -#define mpq_canonicalize __gmpq_canonicalize - -#if defined (__cplusplus) -extern "C" { -#endif -void mpq_init _PROTO ((mpq_ptr)); -void mpq_clear _PROTO ((mpq_ptr)); -void mpq_set _PROTO ((mpq_ptr, mpq_srcptr)); -void mpq_set_ui _PROTO ((mpq_ptr, unsigned long int, unsigned long int)); -void mpq_set_si _PROTO ((mpq_ptr, signed long int, unsigned long int)); -void mpq_set_z _PROTO ((mpq_ptr, mpz_srcptr)); -void mpq_add _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); -void mpq_sub _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); -void mpq_mul _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); -void mpq_div _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); -void mpq_neg _PROTO ((mpq_ptr, mpq_srcptr)); -int mpq_cmp _PROTO ((mpq_srcptr, mpq_srcptr)); -int _mpq_cmp_ui _PROTO ((mpq_srcptr, unsigned long int, unsigned long int)); -int mpq_equal _PROTO ((mpq_srcptr, mpq_srcptr)); -void mpq_inv _PROTO ((mpq_ptr, mpq_srcptr)); -void mpq_set_num _PROTO ((mpq_ptr, mpz_srcptr)); -void mpq_set_den _PROTO ((mpq_ptr, mpz_srcptr)); -void mpq_get_num _PROTO ((mpz_ptr, mpq_srcptr)); -void mpq_get_den _PROTO ((mpz_ptr, mpq_srcptr)); -double mpq_get_d _PROTO ((mpq_srcptr)); -void mpq_set_d _PROTO ((mpq_ptr, double)); -void mpq_canonicalize _PROTO ((mpq_ptr)); - -#define mpq_swap __gmpq_swap -void mpq_swap _PROTO ((mpq_ptr, mpq_ptr)); - -#ifdef _GMP_H_HAVE_FILE -#define mpq_out_str __gmpq_out_str -size_t mpq_out_str _PROTO ((FILE *, int, mpq_srcptr)); -#endif - -#if defined (__cplusplus) -} -#endif - -/**************** Float (i.e. F) routines. ****************/ - -#define mpf_abs __gmpf_abs -#define mpf_add __gmpf_add -#define mpf_add_ui __gmpf_add_ui -#define mpf_ceil __gmpf_ceil -#define mpf_clear __gmpf_clear -#define mpf_cmp __gmpf_cmp -#define mpf_cmp_si __gmpf_cmp_si -#define mpf_cmp_ui __gmpf_cmp_ui -#define mpf_div __gmpf_div -#define mpf_div_2exp __gmpf_div_2exp -#define mpf_div_ui __gmpf_div_ui -#define mpf_dump __gmpf_dump -#define mpf_floor __gmpf_floor -#define mpf_eq __gmpf_eq -#define mpf_get_d __gmpf_get_d -#define mpf_get_prec __gmpf_get_prec -#define mpf_get_str __gmpf_get_str -#define mpf_init __gmpf_init -#define mpf_init2 __gmpf_init2 -#define mpf_inp_str __gmpf_inp_str -#define mpf_init_set __gmpf_init_set -#define mpf_init_set_d __gmpf_init_set_d -#define mpf_init_set_si __gmpf_init_set_si -#define mpf_init_set_str __gmpf_init_set_str -#define mpf_init_set_ui __gmpf_init_set_ui -#define mpf_mul __gmpf_mul -#define mpf_mul_2exp __gmpf_mul_2exp -#define mpf_mul_ui __gmpf_mul_ui -#define mpf_neg __gmpf_neg -#define mpf_out_str __gmpf_out_str -#define mpf_pow_ui __gmpf_pow_ui -#define mpf_random2 __gmpf_random2 -#define mpf_reldiff __gmpf_reldiff -#define mpf_set __gmpf_set -#define mpf_set_d __gmpf_set_d -#define mpf_set_default_prec __gmpf_set_default_prec -#define mpf_set_prec __gmpf_set_prec -#define mpf_set_prec_raw __gmpf_set_prec_raw -#define mpf_set_q __gmpf_set_q -#define mpf_set_si __gmpf_set_si -#define mpf_set_str __gmpf_set_str -#define mpf_set_ui __gmpf_set_ui -#define mpf_set_z __gmpf_set_z -#define mpf_size __gmpf_size -#define mpf_sqrt __gmpf_sqrt -#define mpf_sqrt_ui __gmpf_sqrt_ui -#define mpf_sub __gmpf_sub -#define mpf_sub_ui __gmpf_sub_ui -#define mpf_trunc __gmpf_trunc -#define mpf_ui_div __gmpf_ui_div -#define mpf_ui_sub __gmpf_ui_sub -#define mpf_urandomb __gmpf_urandomb - -#if defined (__cplusplus) -extern "C" { -#endif -void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_add _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); -void mpf_add_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_ceil _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_clear _PROTO ((mpf_ptr)); -int mpf_cmp _PROTO ((mpf_srcptr, mpf_srcptr)); -int mpf_cmp_si _PROTO ((mpf_srcptr, signed long int)); -int mpf_cmp_ui _PROTO ((mpf_srcptr, unsigned long int)); -void mpf_div _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); -void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_div_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_dump _PROTO ((mpf_srcptr)); -int mpf_eq _PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int)); -void mpf_floor _PROTO ((mpf_ptr, mpf_srcptr)); -double mpf_get_d _PROTO ((mpf_srcptr)); -unsigned long int mpf_get_prec _PROTO ((mpf_srcptr)); -char *mpf_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr)); -void mpf_init _PROTO ((mpf_ptr)); -void mpf_init2 _PROTO ((mpf_ptr, unsigned long int)); -#ifdef _GMP_H_HAVE_FILE -size_t mpf_inp_str _PROTO ((mpf_ptr, FILE *, int)); -#endif -void mpf_init_set _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_init_set_d _PROTO ((mpf_ptr, double)); -void mpf_init_set_si _PROTO ((mpf_ptr, signed long int)); -int mpf_init_set_str _PROTO ((mpf_ptr, __gmp_const char *, int)); -void mpf_init_set_ui _PROTO ((mpf_ptr, unsigned long int)); -void mpf_mul _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); -void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_mul_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr)); -#ifdef _GMP_H_HAVE_FILE -size_t mpf_out_str _PROTO ((FILE *, int, size_t, mpf_srcptr)); -#endif -void mpf_pow_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_random2 _PROTO ((mpf_ptr, mp_size_t, mp_exp_t)); -void mpf_reldiff _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); -void mpf_set _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_set_d _PROTO ((mpf_ptr, double)); -void mpf_set_default_prec _PROTO ((unsigned long int)); -void mpf_set_prec _PROTO ((mpf_ptr, unsigned long int)); -void mpf_set_prec_raw _PROTO ((mpf_ptr, unsigned long int)); -void mpf_set_q _PROTO ((mpf_ptr, mpq_srcptr)); -void mpf_set_si _PROTO ((mpf_ptr, signed long int)); -int mpf_set_str _PROTO ((mpf_ptr, __gmp_const char *, int)); -void mpf_set_ui _PROTO ((mpf_ptr, unsigned long int)); -void mpf_set_z _PROTO ((mpf_ptr, mpz_srcptr)); -size_t mpf_size _PROTO ((mpf_srcptr)); -void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_sqrt_ui _PROTO ((mpf_ptr, unsigned long int)); -void mpf_sub _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); -void mpf_sub_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); -void mpf_trunc _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_ui_div _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr)); -void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr)); -void mpf_urandomb _PROTO ((mpf_t, gmp_randstate_t, unsigned long int)); - -#define mpf_swap __gmpf_swap -void mpf_swap _PROTO ((mpf_ptr, mpf_ptr)); - -#if defined (__cplusplus) -} -#endif -/************ Low level positive-integer (i.e. N) routines. ************/ - -/* This is ugly, but we need to make user calls reach the prefixed function. */ -#define mpn_add __MPN(add) -#define mpn_add_1 __MPN(add_1) -#define mpn_add_n __MPN(add_n) -#define mpn_add_nc __MPN(add_nc) -#define mpn_addmul_1 __MPN(addmul_1) -#define mpn_addsub_n __MPN(addsub_n) -#define mpn_addsub_nc __MPN(addsub_nc) -/* #define mpn_and_n __MPN(and_n) */ -/* #define mpn_andn_n __MPN(andn_n) */ -#define mpn_bdivmod __MPN(bdivmod) -#define mpn_cmp __MPN(cmp) -/* #define mpn_com_n __MPN(com_n) */ -#define mpn_copyd __MPN(copyd) -#define mpn_copyi __MPN(copyi) -#define mpn_divrem __MPN(divrem) -#define mpn_divrem_1 __MPN(divrem_1) -#define mpn_divrem_2 __MPN(divrem_2) -#define mpn_dump __MPN(dump) -#define mpn_gcd __MPN(gcd) -#define mpn_gcd_1 __MPN(gcd_1) -#define mpn_gcdext __MPN(gcdext) -#define mpn_get_str __MPN(get_str) -#define mpn_hamdist __MPN(hamdist) -#define mpn_invert_limb __MPN(invert_limb) -/* #define mpn_ior_n __MPN(ior_n) */ -/* #define mpn_iorn_n __MPN(iorn_n) */ -/* #define mpn_kara_mul_n __MPN(kara_mul_n) internal */ -/* #define mpn_kara_sqr_n __MPN(kara_sqr_n) internal */ -#define mpn_lshift __MPN(lshift) -#define mpn_lshiftc __MPN(lshiftc) -#define mpn_mod_1 __MPN(mod_1) -#define mpn_mul __MPN(mul) -#define mpn_mul_1 __MPN(mul_1) -#define mpn_mul_basecase __MPN(mul_basecase) -#define mpn_mul_n __MPN(mul_n) -#define mpn_perfect_square_p __MPN(perfect_square_p) -#define mpn_popcount __MPN(popcount) -#define mpn_preinv_mod_1 __MPN(preinv_mod_1) -/* #define mpn_nand_n __MPN(nand_n) */ -/* #define mpn_nior_n __MPN(nior_n) */ -#define mpn_random __MPN(random) -#define mpn_random2 __MPN(random2) -#define mpn_rshift __MPN(rshift) -#define mpn_rshiftc __MPN(rshiftc) -#define mpn_scan0 __MPN(scan0) -#define mpn_scan1 __MPN(scan1) -#define mpn_set_str __MPN(set_str) -#define mpn_sqr_basecase __MPN(sqr_basecase) -#define mpn_sqr_n __MPN(sqr_n) -#define mpn_sqrtrem __MPN(sqrtrem) -#define mpn_sub __MPN(sub) -#define mpn_sub_1 __MPN(sub_1) -#define mpn_sub_n __MPN(sub_n) -#define mpn_sub_nc __MPN(sub_nc) -#define mpn_submul_1 __MPN(submul_1) -/* #define mpn_toom3_mul_n __MPN(toom3_mul_n) internal */ -/* #define mpn_toom3_sqr_n __MPN(toom3_sqr_n) internal */ -/* #define mpn_xnor_n __MPN(xnor_n) */ -/* #define mpn_xor_n __MPN(xor_n) */ - -#if defined (__cplusplus) -extern "C" { -#endif -mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); -mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); -mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -mp_limb_t mpn_add_nc _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_limb_t)); - -mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); - -#define mpn_addmul_1c __MPN(addmul_1c) -mp_limb_t mpn_addmul_1c _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)); - -mp_limb_t mpn_addsub_n _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int)); -int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)); - -#define mpn_divexact_by3(dst, src, size) mpn_divexact_by3c (dst, src, size, 0) - -#define mpn_divexact_by3c __MPN(divexact_by3c) -mp_limb_t mpn_divexact_by3c _PROTO ((mp_ptr dst, mp_srcptr src, - mp_size_t size, mp_limb_t carry)); - -#define mpn_divmod_1(qp,np,nsize,dlimb) mpn_divrem_1 (qp,0,np,nsize,dlimb) - -mp_limb_t mpn_divrem _PROTO((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)); - -mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)); - -#define mpn_divrem_1c __MPN(divrem_1c) -mp_limb_t mpn_divrem_1c _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, - mp_limb_t, mp_limb_t)); - -mp_limb_t mpn_divrem_2 _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr)); -void mpn_dump _PROTO ((mp_srcptr, mp_size_t)); -mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); -mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)); -mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); -size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t)); -unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)); - -#define mpn_jacobi_base __MPN(jacobi_base) -int mpn_jacobi_base _PROTO ((mp_limb_t a, mp_limb_t b, int result_bit1)); - -mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); -mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)); - -#define mpn_mod_1c __MPN(mod_1c) -mp_limb_t mpn_mod_1c _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)); - -#define mpn_mod_1_rshift __MPN(mod_1_rshift) -mp_limb_t mpn_mod_1_rshift _PROTO ((mp_srcptr, mp_size_t, unsigned,mp_limb_t)); - -mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); -mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); - -#define mpn_mul_1c __MPN(mul_1c) -mp_limb_t mpn_mul_1c _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)); - -void mpn_mul_basecase _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); -void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t)); -unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t)); -mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)); -void mpn_random _PROTO ((mp_ptr, mp_size_t)); -void mpn_random2 _PROTO ((mp_ptr, mp_size_t)); -mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); -unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int)); -unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int)); -mp_size_t mpn_set_str _PROTO ((mp_ptr, __gmp_const unsigned char *, size_t, int)); -void mpn_sqr_n _PROTO ((mp_ptr, mp_srcptr, mp_size_t)); -void mpn_sqr_basecase _PROTO ((mp_ptr, mp_srcptr, mp_size_t)); -mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)); -mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); -mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); -mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); -mp_limb_t mpn_sub_nc _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_limb_t)); -mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); - -#define mpn_submul_1c __MPN(submul_1c) -mp_limb_t mpn_submul_1c _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)); - -#if defined (__cplusplus) -} -#endif - -#define mpn_incr_u(p,incr) \ - do { mp_limb_t __x; mp_ptr __p = p; \ - __x = *__p + incr; \ - *__p = __x; \ - if (__x < incr) \ - while (++(*(++__p)) == 0) \ - ; \ - } while (0) - -#define mpn_decr_u(p,incr) \ - do { mp_limb_t __x; mp_ptr __p = p; \ - __x = *__p; \ - *__p = __x - incr; \ - if (__x < incr) \ - while ((*(++__p))-- == 0) \ - ; \ - } while (0) - -#if defined (__GNUC__) || defined (_FORCE_INLINES) -_EXTERN_INLINE mp_limb_t -#if (__STDC__-0) || defined (__cplusplus) -mpn_add_1 (register mp_ptr res_ptr, - register mp_srcptr s1_ptr, - register mp_size_t s1_size, - register mp_limb_t s2_limb) -#else -mpn_add_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_size_t s1_size; - register mp_limb_t s2_limb; -#endif -{ - register mp_limb_t x; - - x = *s1_ptr++; - s2_limb = x + s2_limb; - *res_ptr++ = s2_limb; - if (s2_limb < x) - { - while (--s1_size != 0) - { - x = *s1_ptr++ + 1; - *res_ptr++ = x; - if (x != 0) - goto fin; - } - - return 1; - } - - fin: - if (res_ptr != s1_ptr) - { - mp_size_t i; - for (i = 0; i < s1_size - 1; i++) - res_ptr[i] = s1_ptr[i]; - } - return 0; -} - -_EXTERN_INLINE mp_limb_t -#if (__STDC__-0) || defined (__cplusplus) -mpn_add (register mp_ptr res_ptr, - register mp_srcptr s1_ptr, - register mp_size_t s1_size, - register mp_srcptr s2_ptr, - register mp_size_t s2_size) -#else -mpn_add (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_size_t s1_size; - register mp_srcptr s2_ptr; - register mp_size_t s2_size; -#endif -{ - mp_limb_t cy_limb = 0; - - if (s2_size != 0) - cy_limb = mpn_add_n (res_ptr, s1_ptr, s2_ptr, s2_size); - - if (s1_size - s2_size != 0) - cy_limb = mpn_add_1 (res_ptr + s2_size, - s1_ptr + s2_size, - s1_size - s2_size, - cy_limb); - return cy_limb; -} - -_EXTERN_INLINE mp_limb_t -#if (__STDC__-0) || defined (__cplusplus) -mpn_sub_1 (register mp_ptr res_ptr, - register mp_srcptr s1_ptr, - register mp_size_t s1_size, - register mp_limb_t s2_limb) -#else -mpn_sub_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_size_t s1_size; - register mp_limb_t s2_limb; -#endif -{ - register mp_limb_t x; - - x = *s1_ptr++; - s2_limb = x - s2_limb; - *res_ptr++ = s2_limb; - if (s2_limb > x) - { - while (--s1_size != 0) - { - x = *s1_ptr++; - *res_ptr++ = x - 1; - if (x != 0) - goto fin; - } - - return 1; - } - - fin: - if (res_ptr != s1_ptr) - { - mp_size_t i; - for (i = 0; i < s1_size - 1; i++) - res_ptr[i] = s1_ptr[i]; - } - return 0; -} - -_EXTERN_INLINE mp_limb_t -#if (__STDC__-0) || defined (__cplusplus) -mpn_sub (register mp_ptr res_ptr, - register mp_srcptr s1_ptr, - register mp_size_t s1_size, - register mp_srcptr s2_ptr, - register mp_size_t s2_size) -#else -mpn_sub (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_size_t s1_size; - register mp_srcptr s2_ptr; - register mp_size_t s2_size; -#endif -{ - mp_limb_t cy_limb = 0; - - if (s2_size != 0) - cy_limb = mpn_sub_n (res_ptr, s1_ptr, s2_ptr, s2_size); - - if (s1_size - s2_size != 0) - cy_limb = mpn_sub_1 (res_ptr + s2_size, - s1_ptr + s2_size, - s1_size - s2_size, - cy_limb); - return cy_limb; -} -#endif /* __GNUC__ */ - -/* Allow faster testing for negative, zero, and positive. */ -#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0) -#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0) -#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0) - -/* When using GCC, optimize certain common comparisons. */ -#if defined (__GNUC__) -#define mpz_cmp_ui(Z,UI) \ - (__builtin_constant_p (UI) && (UI) == 0 \ - ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI)) -#define mpz_cmp_si(Z,SI) \ - (__builtin_constant_p (SI) && (SI) == 0 ? mpz_sgn (Z) \ - : __builtin_constant_p (SI) && (SI) > 0 \ - ? _mpz_cmp_ui (Z, (unsigned long int) SI) \ - : _mpz_cmp_si (Z,SI)) -#define mpq_cmp_ui(Q,NUI,DUI) \ - (__builtin_constant_p (NUI) && (NUI) == 0 \ - ? mpq_sgn (Q) : _mpq_cmp_ui (Q,NUI,DUI)) -#else -#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI) -#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI) -#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI) -#endif - - -/* Using "&" rather than "&&" means these can come out branch-free. Every - mpz_t has at least one limb allocated, so fetching the low limb is always - allowed. */ -#define mpz_odd_p(z) ((int) ((z)->_mp_size != 0) & (int) (z)->_mp_d[0]) -#define mpz_even_p(z) (! mpz_odd_p (z)) - - -/* Allow direct user access to numerator and denominator of a mpq_t object. */ -#define mpq_numref(Q) (&((Q)->_mp_num)) -#define mpq_denref(Q) (&((Q)->_mp_den)) - - -/* Compatibility with GMP 2 and earlier. */ -#define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize) - -/* Compatibility with GMP 1. */ -#define mpz_mdiv mpz_fdiv_q -#define mpz_mdivmod mpz_fdiv_qr -#define mpz_mmod mpz_fdiv_r -#define mpz_mdiv_ui mpz_fdiv_q_ui -#define mpz_mdivmod_ui(q,r,n,d) \ - ((r == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d)) -#define mpz_mmod_ui(r,n,d) \ - ((r == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d)) - -/* Useful synonyms, but not quite compatible with GMP 1. */ -#define mpz_div mpz_fdiv_q -#define mpz_divmod mpz_fdiv_qr -#define mpz_div_ui mpz_fdiv_q_ui -#define mpz_divmod_ui mpz_fdiv_qr_ui -#define mpz_mod_ui mpz_fdiv_r_ui -#define mpz_div_2exp mpz_fdiv_q_2exp -#define mpz_mod_2exp mpz_fdiv_r_2exp - -#define gmp_errno __gmp_errno -extern int gmp_errno; - -enum -{ - GMP_ERROR_NONE = 0, - GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, - GMP_ERROR_DIVISION_BY_ZERO = 2, - GMP_ERROR_SQRT_OF_NEGATIVE = 4, - GMP_ERROR_INVALID_ARGUMENT = 8, - GMP_ERROR_ALLOCATE = 16, - GMP_ERROR_BAD_STRING = 32, - GMP_ERROR_UNUSED_ERROR -}; - -/* Note: major version number is in mp.h too */ -#define __GNU_MP_VERSION 3 -#define __GNU_MP_VERSION_MINOR 1 -#define __GNU_MP_VERSION_PATCHLEVEL 0 - -#define gmp_version __gmp_version -extern __gmp_const char *gmp_version; - -#define __GMP_H__ -#endif /* __GMP_H__ */ diff --git a/gmp/gmp.info b/gmp/gmp.info deleted file mode 100755 index 5364111..0000000 Binary files a/gmp/gmp.info and /dev/null differ diff --git a/gmp/gmp.info-1 b/gmp/gmp.info-1 deleted file mode 100755 index 0d3ab98..0000000 Binary files a/gmp/gmp.info-1 and /dev/null differ diff --git a/gmp/gmp.info-2 b/gmp/gmp.info-2 deleted file mode 100755 index f4e8919..0000000 Binary files a/gmp/gmp.info-2 and /dev/null differ diff --git a/gmp/gmp.info-3 b/gmp/gmp.info-3 deleted file mode 100755 index c4b11b6..0000000 Binary files a/gmp/gmp.info-3 and /dev/null differ diff --git a/gmp/gmp.info-4 b/gmp/gmp.info-4 deleted file mode 100755 index 2df2f69..0000000 Binary files a/gmp/gmp.info-4 and /dev/null differ diff --git a/gmp/gmp.texi b/gmp/gmp.texi deleted file mode 100755 index d727e82..0000000 Binary files a/gmp/gmp.texi and /dev/null differ diff --git a/gmp/insert-dbl.c b/gmp/insert-dbl.c deleted file mode 100755 index dc88a56..0000000 --- a/gmp/insert-dbl.c +++ /dev/null @@ -1,98 +0,0 @@ -/* __gmp_insert_double -- convert from array of mp_limb_t to double. - -Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#ifdef XDEBUG -#undef _GMP_IEEE_FLOATS -#endif - -#ifndef _GMP_IEEE_FLOATS -#define _GMP_IEEE_FLOATS 0 -#endif - -double -#if __STDC__ -__gmp_scale2 (double d, int exp) -#else -__gmp_scale2 (d, exp) - double d; - int exp; -#endif -{ -#if _GMP_IEEE_FLOATS - { -#if defined (__alpha) && __GNUC__ == 2 && __GNUC_MINOR__ == 8 - /* Work around alpha-specific bug in GCC 2.8.x. */ - volatile -#endif - union ieee_double_extract x; - x.d = d; - exp += x.s.exp; - x.s.exp = exp; - if (exp >= 2047) - { - /* Return +-infinity */ - x.s.exp = 2047; - x.s.manl = x.s.manh = 0; - } - else if (exp < 1) - { - x.s.exp = 1; /* smallest exponent (biased) */ - /* Divide result by 2 until we have scaled it to the right IEEE - denormalized number, but stop if it becomes zero. */ - while (exp < 1 && x.d != 0) - { - x.d *= 0.5; - exp++; - } - } - return x.d; - } -#else - { - double factor, r; - - factor = 2.0; - if (exp < 0) - { - factor = 0.5; - exp = -exp; - } - r = d; - if (exp != 0) - { - if ((exp & 1) != 0) - r *= factor; - exp >>= 1; - while (exp != 0) - { - factor *= factor; - if ((exp & 1) != 0) - r *= factor; - exp >>= 1; - } - } - return r; - } -#endif -} diff --git a/gmp/install-sh b/gmp/install-sh deleted file mode 100755 index 4c0394c..0000000 Binary files a/gmp/install-sh and /dev/null differ diff --git a/gmp/longlong.h b/gmp/longlong.h deleted file mode 100755 index 9869e01..0000000 --- a/gmp/longlong.h +++ /dev/null @@ -1,1347 +0,0 @@ -/* longlong.h -- definitions for mixed size 32/64 bit arithmetic. - -Copyright (C) 1991, 1992, 1993, 1994, 1996, 1997, 1999, 2000 Free Software -Foundation, Inc. - -This file is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -This 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 Lesser General Public -License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this file; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* You have to define the following before including this file: - - UWtype -- An unsigned type, default type for operations (typically a "word") - UHWtype -- An unsigned type, at least half the size of UWtype. - UDWtype -- An unsigned type, at least twice as large a UWtype - W_TYPE_SIZE -- size in bits of UWtype - - SItype, USItype -- Signed and unsigned 32 bit types. - DItype, UDItype -- Signed and unsigned 64 bit types. - - On a 32 bit machine UWtype should typically be USItype; - on a 64 bit machine, UWtype should typically be UDItype. -*/ - -#define __BITS4 (W_TYPE_SIZE / 4) -#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2)) -#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1)) -#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2)) - -/* This is used to make sure no undesirable sharing between different libraries - that use this file takes place. */ -#ifndef __MPN -#define __MPN(x) __##x -#endif - -#ifndef _PROTO -#if (__STDC__-0) || defined (__cplusplus) -#define _PROTO(x) x -#else -#define _PROTO(x) () -#endif -#endif - -/* Define auxiliary asm macros. - - 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two - UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype - word product in HIGH_PROD and LOW_PROD. - - 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a - UDWtype product. This is just a variant of umul_ppmm. - - 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator, - denominator) divides a UDWtype, composed by the UWtype integers - HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient - in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less - than DENOMINATOR for correct operation. If, in addition, the most - significant bit of DENOMINATOR must be 1, then the pre-processor symbol - UDIV_NEEDS_NORMALIZATION is defined to 1. - - 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator, - denominator). Like udiv_qrnnd but the numbers are signed. The quotient - is rounded towards 0. - - 5) count_leading_zeros(count, x) counts the number of zero-bits from the - msb to the first non-zero bit in the UWtype X. This is the number of - steps X needs to be shifted left to set the msb. Undefined for X == 0, - unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value. - - 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts - from the least significant end. - - 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1, - high_addend_2, low_addend_2) adds two UWtype integers, composed by - HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2 - respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow - (i.e. carry out) is not stored anywhere, and is lost. - - 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend, - high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers, - composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and - LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE - and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere, - and is lost. - - If any of these macros are left undefined for a particular CPU, - C macros are used. */ - -/* The CPUs come in alphabetical order below. - - Please add support for more CPUs here, or improve the current support - for the CPUs below! */ - -#if defined (__alpha) && W_TYPE_SIZE == 64 -#if defined (__GNUC__) -#define umul_ppmm(ph, pl, m0, m1) \ - do { \ - UDItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("umulh %r1,%2,%0" \ - : "=r" (ph) \ - : "%rJ" (m0), "rI" (m1)); \ - (pl) = __m0 * __m1; \ - } while (0) -#define UMUL_TIME 18 -#ifndef LONGLONG_STANDALONE -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { UDItype __di; \ - __di = __MPN(invert_limb) (d); \ - udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \ - } while (0) -#define UDIV_NEEDS_NORMALIZATION 1 -#define UDIV_TIME 220 -long __MPN(count_leading_zeros) (); -#define count_leading_zeros(count, x) \ - ((count) = __MPN(count_leading_zeros) (x)) -#endif /* LONGLONG_STANDALONE */ -#else /* ! __GNUC__ */ -#include -#define umul_ppmm(ph, pl, m0, m1) \ - do { \ - UDItype __m0 = (m0), __m1 = (m1); \ - (ph) = __UMULH (m0, m1); \ - (pl) = __m0 * __m1; \ - } while (0) -#endif -#endif /* __alpha */ - -#if defined (__hppa) && W_TYPE_SIZE == 64 -/* We put the result pointer parameter last here, since it makes passing - of the other parameters more efficient. */ -#ifndef LONGLONG_STANDALONE -#define umul_ppmm(wh, wl, u, v) \ - do { \ - UDItype __p0; \ - (wh) = __MPN(umul_ppmm) (u, v, &__p0); \ - (wl) = __p0; \ - } while (0) -extern UDItype __MPN(umul_ppmm) _PROTO ((UDItype, UDItype, UDItype *)); -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { UDItype __r; \ - (q) = __MPN(udiv_qrnnd) (n1, n0, d, &__r); \ - (r) = __r; \ - } while (0) -extern UDItype __MPN(udiv_qrnnd) _PROTO ((UDItype, UDItype, UDItype, UDItype *)); -#define UMUL_TIME 8 -#define UDIV_TIME 60 -#endif /* LONGLONG_STANDALONE */ -#endif /* hppa */ - -#if defined (__ia64) && W_TYPE_SIZE == 64 -#if defined (__GNUC__) -#define umul_ppmm(ph, pl, m0, m1) \ - do { \ - UDItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("xma.hu %0 = %1, %2, f0" \ - : "=e" (ph) \ - : "e" (m0), "e" (m1)); \ - (pl) = __m0 * __m1; \ - } while (0) -#endif -#endif - - -#if defined (__GNUC__) && !defined (NO_ASM) - -/* We sometimes need to clobber "cc" with gcc2, but that would not be - understood by gcc1. Use cpp to avoid major code duplication. */ -#if __GNUC__ < 2 -#define __CLOBBER_CC -#define __AND_CLOBBER_CC -#else /* __GNUC__ >= 2 */ -#define __CLOBBER_CC : "cc" -#define __AND_CLOBBER_CC , "cc" -#endif /* __GNUC__ < 2 */ - -#if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("add %1,%4,%5\n\taddc %0,%2,%3" \ - : "=r" (sh), "=&r" (sl) \ - : "%r" (ah), "rI" (bh), "%r" (al), "rI" (bl)) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("sub %1,%4,%5\n\tsubc %0,%2,%3" \ - : "=r" (sh), "=&r" (sl) \ - : "r" (ah), "rI" (bh), "r" (al), "rI" (bl)) -#define umul_ppmm(xh, xl, m0, m1) \ - do { \ - USItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("multiplu %0,%1,%2" \ - : "=r" (xl) \ - : "r" (__m0), "r" (__m1)); \ - __asm__ ("multmu %0,%1,%2" \ - : "=r" (xh) \ - : "r" (__m0), "r" (__m1)); \ - } while (0) -#define udiv_qrnnd(q, r, n1, n0, d) \ - __asm__ ("dividu %0,%3,%4" \ - : "=r" (q), "=q" (r) \ - : "1" (n1), "r" (n0), "r" (d)) -#define count_leading_zeros(count, x) \ - __asm__ ("clz %0,%1" \ - : "=r" (count) \ - : "r" (x)) -#define COUNT_LEADING_ZEROS_0 32 -#endif /* __a29k__ */ - -#if defined (__arm__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3" \ - : "=r" (sh), "=&r" (sl) \ - : "%r" (ah), "rI" (bh), "%r" (al), "rI" (bl)) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3" \ - : "=r" (sh), "=&r" (sl) \ - : "r" (ah), "rI" (bh), "r" (al), "rI" (bl)) -#if 1 || defined (__arm_m__) /* `M' series has widening multiply support */ -#define umul_ppmm(xh, xl, a, b) \ - __asm__ ("umull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b)) -#define smul_ppmm(xh, xl, a, b) \ - __asm__ ("smull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b)) -#define UMUL_TIME 5 -#else -#define umul_ppmm(xh, xl, a, b) \ - __asm__ ("%@ Inlined umul_ppmm - mov %|r0, %2, lsr #16 - mov %|r2, %3, lsr #16 - bic %|r1, %2, %|r0, lsl #16 - bic %|r2, %3, %|r2, lsl #16 - mul %1, %|r1, %|r2 - mul %|r2, %|r0, %|r2 - mul %|r1, %0, %|r1 - mul %0, %|r0, %0 - adds %|r1, %|r2, %|r1 - addcs %0, %0, #65536 - adds %1, %1, %|r1, lsl #16 - adc %0, %0, %|r1, lsr #16" \ - : "=&r" (xh), "=r" (xl) \ - : "r" (a), "r" (b) \ - : "r0", "r1", "r2") -#define UMUL_TIME 20 -#endif -#define UDIV_TIME 100 -#endif /* __arm__ */ - -#if defined (__clipper__) && W_TYPE_SIZE == 32 -#define umul_ppmm(w1, w0, u, v) \ - ({union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __x; \ - __asm__ ("mulwux %2,%0" \ - : "=r" (__x.__ll) \ - : "%0" ((USItype)(u)), "r" ((USItype)(v))); \ - (w1) = __x.__i.__h; (w0) = __x.__i.__l;}) -#define smul_ppmm(w1, w0, u, v) \ - ({union {DItype __ll; \ - struct {SItype __l, __h;} __i; \ - } __x; \ - __asm__ ("mulwx %2,%0" \ - : "=r" (__x.__ll) \ - : "%0" ((SItype)(u)), "r" ((SItype)(v))); \ - (w1) = __x.__i.__h; (w0) = __x.__i.__l;}) -#define __umulsidi3(u, v) \ - ({UDItype __w; \ - __asm__ ("mulwux %2,%0" \ - : "=r" (__w) : "%0" ((USItype)(u)), "r" ((USItype)(v))); \ - __w; }) -#endif /* __clipper__ */ - -/* Fujitsu vector computers. */ -#if defined (__uxp__) && W_TYPE_SIZE == 32 -#define umul_ppmm(ph, pl, u, v) \ - do { \ - union {UDItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __asm__ ("mult.lu %1,%2,%0" : "=r" (__x.__ll) : "%r" (u), "rK" (v));\ - (ph) = __x.__i.__h; \ - (pl) = __x.__i.__l; \ - } while (0) -#define smul_ppmm(ph, pl, u, v) \ - do { \ - union {UDItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __asm__ ("mult.l %1,%2,%0" : "=r" (__x.__ll) : "%r" (u), "rK" (v)); \ - (ph) = __x.__i.__h; \ - (pl) = __x.__i.__l; \ - } while (0) -#endif - -#if defined (__gmicro__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("add.w %5,%1\n\taddx %3,%0" \ - : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \ - : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "%1" ((USItype)(al)), "g" ((USItype)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("sub.w %5,%1\n\tsubx %3,%0" \ - : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \ - : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "1" ((USItype)(al)), "g" ((USItype)(bl))) -#define umul_ppmm(ph, pl, m0, m1) \ - __asm__ ("mulx %3,%0,%1" \ - : "=g" ((USItype)(ph)), "=r" ((USItype)(pl)) \ - : "%0" ((USItype)(m0)), "g" ((USItype)(m1))) -#define udiv_qrnnd(q, r, nh, nl, d) \ - __asm__ ("divx %4,%0,%1" \ - : "=g" ((USItype)(q)), "=r" ((USItype)(r)) \ - : "1" ((USItype)(nh)), "0" ((USItype)(nl)), "g" ((USItype)(d))) -#define count_leading_zeros(count, x) \ - __asm__ ("bsch/1 %1,%0" \ - : "=g" (count) : "g" ((USItype)(x)), "0" ((USItype)0)) -#endif - -#if defined (__hppa) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0" \ - : "=r" (sh), "=&r" (sl) \ - : "%rM" (ah), "rM" (bh), "%rM" (al), "rM" (bl)) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0" \ - : "=r" (sh), "=&r" (sl) \ - : "rM" (ah), "rM" (bh), "rM" (al), "rM" (bl)) -#if defined (_PA_RISC1_1) -#define umul_ppmm(wh, wl, u, v) \ - do { \ - union {UDItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __asm__ ("xmpyu %1,%2,%0" : "=*f" (__x.__ll) : "*f" (u), "*f" (v)); \ - (wh) = __x.__i.__h; \ - (wl) = __x.__i.__l; \ - } while (0) -#define UMUL_TIME 8 -#define UDIV_TIME 60 -#else -#define UMUL_TIME 40 -#define UDIV_TIME 80 -#endif -#ifndef LONGLONG_STANDALONE -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { USItype __r; \ - (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \ - (r) = __r; \ - } while (0) -extern USItype __MPN(udiv_qrnnd) _PROTO ((USItype *, USItype, USItype, USItype)); -#endif /* LONGLONG_STANDALONE */ -#define count_leading_zeros(count, x) \ - do { \ - USItype __tmp; \ - __asm__ ( \ - "ldi 1,%0 - extru,= %1,15,16,%%r0 ; Bits 31..16 zero? - extru,tr %1,15,16,%1 ; No. Shift down, skip add. - ldo 16(%0),%0 ; Yes. Perform add. - extru,= %1,23,8,%%r0 ; Bits 15..8 zero? - extru,tr %1,23,8,%1 ; No. Shift down, skip add. - ldo 8(%0),%0 ; Yes. Perform add. - extru,= %1,27,4,%%r0 ; Bits 7..4 zero? - extru,tr %1,27,4,%1 ; No. Shift down, skip add. - ldo 4(%0),%0 ; Yes. Perform add. - extru,= %1,29,2,%%r0 ; Bits 3..2 zero? - extru,tr %1,29,2,%1 ; No. Shift down, skip add. - ldo 2(%0),%0 ; Yes. Perform add. - extru %1,30,1,%1 ; Extract bit 1. - sub %0,%1,%0 ; Subtract it. - " : "=r" (count), "=r" (__tmp) : "1" (x)); \ - } while (0) -#endif /* hppa */ - -#if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32 -#define smul_ppmm(xh, xl, m0, m1) \ - do { \ - union {DItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __asm__ ("mr %0,%3" \ - : "=r" (__x.__i.__h), "=r" (__x.__i.__l) \ - : "%1" (m0), "r" (m1)); \ - (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ - } while (0) -#define sdiv_qrnnd(q, r, n1, n0, d) \ - do { \ - union {DItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __x.__i.__h = n1; __x.__i.__l = n0; \ - __asm__ ("dr %0,%2" \ - : "=r" (__x.__ll) \ - : "0" (__x.__ll), "r" (d)); \ - (q) = __x.__i.__l; (r) = __x.__i.__h; \ - } while (0) -#endif - -#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("addl %5,%1\n\tadcl %3,%0" \ - : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \ - : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "%1" ((USItype)(al)), "g" ((USItype)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ - : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \ - : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "1" ((USItype)(al)), "g" ((USItype)(bl))) -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mull %3" \ - : "=a" (w0), "=d" (w1) \ - : "%0" ((USItype)(u)), "rm" ((USItype)(v))) -#define udiv_qrnnd(q, r, n1, n0, d) \ - __asm__ ("divl %4" \ - : "=a" (q), "=d" (r) \ - : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "rm" ((USItype)(d))) -#define count_leading_zeros(count, x) \ - do { \ - USItype __cbtmp; \ - __asm__ ("bsrl %1,%0" : "=r" (__cbtmp) : "rm" ((USItype)(x))); \ - (count) = __cbtmp ^ 31; \ - } while (0) -#define count_trailing_zeros(count, x) \ - __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x))) -#ifndef UMUL_TIME -#define UMUL_TIME 10 -#endif -#ifndef UDIV_TIME -#define UDIV_TIME 40 -#endif -#endif /* 80x86 */ - -#if defined (__i860__) && W_TYPE_SIZE == 32 -#define rshift_rhlc(r,h,l,c) \ - __asm__ ("shr %3,r0,r0\;shrd %1,%2,%0" \ - "=r" (r) : "r" (h), "r" (l), "rn" (c)) -#endif /* i860 */ - -#if defined (__i960__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("cmpo 1,0\;addc %5,%4,%1\;addc %3,%2,%0" \ - : "=r" (sh), "=&r" (sl) \ - : "%dI" (ah), "dI" (bh), "%dI" (al), "dI" (bl)) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("cmpo 0,0\;subc %5,%4,%1\;subc %3,%2,%0" \ - : "=r" (sh), "=&r" (sl) \ - : "dI" (ah), "dI" (bh), "dI" (al), "dI" (bl)) -#define umul_ppmm(w1, w0, u, v) \ - ({union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __x; \ - __asm__ ("emul %2,%1,%0" \ - : "=d" (__x.__ll) : "%dI" (u), "dI" (v)); \ - (w1) = __x.__i.__h; (w0) = __x.__i.__l;}) -#define __umulsidi3(u, v) \ - ({UDItype __w; \ - __asm__ ("emul %2,%1,%0" : "=d" (__w) : "%dI" (u), "dI" (v)); \ - __w; }) -#define udiv_qrnnd(q, r, nh, nl, d) \ - do { \ - union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __nn; \ - __nn.__i.__h = (nh); __nn.__i.__l = (nl); \ - __asm__ ("ediv %d,%n,%0" \ - : "=d" (__rq.__ll) : "dI" (__nn.__ll), "dI" (d)); \ - (r) = __rq.__i.__l; (q) = __rq.__i.__h; \ - } while (0) -#define count_leading_zeros(count, x) \ - do { \ - USItype __cbtmp; \ - __asm__ ("scanbit %1,%0" : "=r" (__cbtmp) : "r" (x)); \ - (count) = __cbtmp ^ 31; \ - } while (0) -#define COUNT_LEADING_ZEROS_0 (-32) /* sic */ -#if defined (__i960mx) /* what is the proper symbol to test??? */ -#define rshift_rhlc(r,h,l,c) \ - do { \ - union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __nn; \ - __nn.__i.__h = (h); __nn.__i.__l = (l); \ - __asm__ ("shre %2,%1,%0" : "=d" (r) : "dI" (__nn.__ll), "dI" (c)); \ - } -#endif /* i960mx */ -#endif /* i960 */ - -#if (defined (__mc68000__) || defined (__mc68020__) || defined(mc68020) \ - || defined (__m68k__) || defined (__mc5200__) || defined (__mc5206e__) \ - || defined (__mc5307__)) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0" \ - : "=d" ((USItype)(sh)), "=&d" ((USItype)(sl)) \ - : "%0" ((USItype)(ah)), "d" ((USItype)(bh)), \ - "%1" ((USItype)(al)), "g" ((USItype)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0" \ - : "=d" ((USItype)(sh)), "=&d" ((USItype)(sl)) \ - : "0" ((USItype)(ah)), "d" ((USItype)(bh)), \ - "1" ((USItype)(al)), "g" ((USItype)(bl))) -/* The '020, '030, '040 and CPU32 have 32x32->64 and 64/32->32q-32r. */ -#if defined (__mc68020__) || defined(mc68020) \ - || defined (__mc68030__) || defined (mc68030) \ - || defined (__mc68040__) || defined (mc68040) \ - || defined (__mc68332__) || defined (mc68332) \ - || defined (__NeXT__) -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mulu%.l %3,%1:%0" \ - : "=d" ((USItype)(w0)), "=d" ((USItype)(w1)) \ - : "%0" ((USItype)(u)), "dmi" ((USItype)(v))) -#define UMUL_TIME 45 -#define udiv_qrnnd(q, r, n1, n0, d) \ - __asm__ ("divu%.l %4,%1:%0" \ - : "=d" ((USItype)(q)), "=d" ((USItype)(r)) \ - : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d))) -#define UDIV_TIME 90 -#define sdiv_qrnnd(q, r, n1, n0, d) \ - __asm__ ("divs%.l %4,%1:%0" \ - : "=d" ((USItype)(q)), "=d" ((USItype)(r)) \ - : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d))) -#else /* for other 68k family members use 16x16->32 multiplication */ -#define umul_ppmm(xh, xl, a, b) \ - do { USItype __umul_tmp1, __umul_tmp2; \ - __asm__ ("| Inlined umul_ppmm - move%.l %5,%3 - move%.l %2,%0 - move%.w %3,%1 - swap %3 - swap %0 - mulu%.w %2,%1 - mulu%.w %3,%0 - mulu%.w %2,%3 - swap %2 - mulu%.w %5,%2 - add%.l %3,%2 - jcc 1f - add%.l %#0x10000,%0 -1: move%.l %2,%3 - clr%.w %2 - swap %2 - swap %3 - clr%.w %3 - add%.l %3,%1 - addx%.l %2,%0 - | End inlined umul_ppmm" \ - : "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)), \ - "=d" (__umul_tmp1), "=&d" (__umul_tmp2) \ - : "%2" ((USItype)(a)), "d" ((USItype)(b))); \ - } while (0) -#define UMUL_TIME 100 -#define UDIV_TIME 400 -#endif /* not mc68020 */ -/* The '020, '030, '040 and '060 have bitfield insns. */ -#if defined (__mc68020__) || defined (mc68020) \ - || defined (__mc68030__) || defined (mc68030) \ - || defined (__mc68040__) || defined (mc68040) \ - || defined (__mc68060__) || defined (mc68060) \ - || defined (__NeXT__) -#define count_leading_zeros(count, x) \ - __asm__ ("bfffo %1{%b2:%b2},%0" \ - : "=d" ((USItype) (count)) \ - : "od" ((USItype) (x)), "n" (0)) -#define COUNT_LEADING_ZEROS_0 32 -#endif -#endif /* mc68000 */ - -#if defined (__m88000__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3" \ - : "=r" (sh), "=&r" (sl) \ - : "%rJ" (ah), "rJ" (bh), "%rJ" (al), "rJ" (bl)) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3" \ - : "=r" (sh), "=&r" (sl) \ - : "rJ" (ah), "rJ" (bh), "rJ" (al), "rJ" (bl)) -#define count_leading_zeros(count, x) \ - do { \ - USItype __cbtmp; \ - __asm__ ("ff1 %0,%1" : "=r" (__cbtmp) : "r" (x)); \ - (count) = __cbtmp ^ 31; \ - } while (0) -#define COUNT_LEADING_ZEROS_0 63 /* sic */ -#if defined (__m88110__) -#define umul_ppmm(wh, wl, u, v) \ - do { \ - union {UDItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __asm__ ("mulu.d %0,%1,%2" : "=r" (__x.__ll) : "r" (u), "r" (v)); \ - (wh) = __x.__i.__h; \ - (wl) = __x.__i.__l; \ - } while (0) -#define udiv_qrnnd(q, r, n1, n0, d) \ - ({union {UDItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x, __q; \ - __x.__i.__h = (n1); __x.__i.__l = (n0); \ - __asm__ ("divu.d %0,%1,%2" \ - : "=r" (__q.__ll) : "r" (__x.__ll), "r" (d)); \ - (r) = (n0) - __q.__l * (d); (q) = __q.__l; }) -#define UMUL_TIME 5 -#define UDIV_TIME 25 -#else -#define UMUL_TIME 17 -#define UDIV_TIME 150 -#endif /* __m88110__ */ -#endif /* __m88000__ */ - -#if defined (__mips) && W_TYPE_SIZE == 32 -#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7 -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v)) -#else -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("multu %2,%3\n\tmflo %0\n\tmfhi %1" \ - : "=d" (w0), "=d" (w1) : "d" (u), "d" (v)) -#endif -#define UMUL_TIME 10 -#define UDIV_TIME 100 -#endif /* __mips */ - -#if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64 -#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7 -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("dmultu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v)) -#else -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("dmultu %2,%3\n\tmflo %0\n\tmfhi %1" \ - : "=d" (w0), "=d" (w1) : "d" (u), "d" (v)) -#endif -#define UMUL_TIME 20 -#define UDIV_TIME 140 -#endif /* __mips */ - -#if defined (__ns32000__) && W_TYPE_SIZE == 32 -#define umul_ppmm(w1, w0, u, v) \ - ({union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __x; \ - __asm__ ("meid %2,%0" \ - : "=g" (__x.__ll) \ - : "%0" ((USItype)(u)), "g" ((USItype)(v))); \ - (w1) = __x.__i.__h; (w0) = __x.__i.__l;}) -#define __umulsidi3(u, v) \ - ({UDItype __w; \ - __asm__ ("meid %2,%0" \ - : "=g" (__w) \ - : "%0" ((USItype)(u)), "g" ((USItype)(v))); \ - __w; }) -#define udiv_qrnnd(q, r, n1, n0, d) \ - ({union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __x; \ - __x.__i.__h = (n1); __x.__i.__l = (n0); \ - __asm__ ("deid %2,%0" \ - : "=g" (__x.__ll) \ - : "0" (__x.__ll), "g" ((USItype)(d))); \ - (r) = __x.__i.__l; (q) = __x.__i.__h; }) -#define count_trailing_zeros(count,x) \ - do { \ - __asm__ ("ffsd %2,%0" \ - : "=r" ((USItype) (count)) \ - : "0" ((USItype) 0), "r" ((USItype) (x))); \ - } while (0) -#endif /* __ns32000__ */ - -/* We should test _IBMR2 here when we add assembly support for the system - vendor compilers. */ -#if (defined (_ARCH_PPC) || defined (_ARCH_PWR) || defined (__powerpc__)) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - do { \ - if (__builtin_constant_p (bh) && (bh) == 0) \ - __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "%r" (ah), "%r" (al), "rI" (bl));\ - else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ - __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "%r" (ah), "%r" (al), "rI" (bl));\ - else \ - __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \ - : "=r" (sh), "=&r" (sl) \ - : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \ - } while (0) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - do { \ - if (__builtin_constant_p (ah) && (ah) == 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ - else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ - else if (__builtin_constant_p (bh) && (bh) == 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ - else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ - else \ - __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \ - : "=r" (sh), "=&r" (sl) \ - : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \ - } while (0) -#define count_leading_zeros(count, x) \ - __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x)) -#define COUNT_LEADING_ZEROS_0 32 -#if defined (_ARCH_PPC) || defined (__powerpc__) -#define umul_ppmm(ph, pl, m0, m1) \ - do { \ - USItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ - (pl) = __m0 * __m1; \ - } while (0) -#define UMUL_TIME 15 -#define smul_ppmm(ph, pl, m0, m1) \ - do { \ - SItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ - (pl) = __m0 * __m1; \ - } while (0) -#define SMUL_TIME 14 -#define UDIV_TIME 120 -#else -#define UMUL_TIME 8 -#define smul_ppmm(xh, xl, m0, m1) \ - __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1)) -#define SMUL_TIME 4 -#define sdiv_qrnnd(q, r, nh, nl, d) \ - __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d)) -#define UDIV_TIME 100 -#endif -#endif /* 32-bit POWER architecture variants. */ - -/* We should test _IBMR2 here when we add assembly support for the system - vendor compilers. */ -#if (defined (_ARCH_PPC) || defined (__powerpc__)) && W_TYPE_SIZE == 64 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - do { \ - if (__builtin_constant_p (bh) && (bh) == 0) \ - __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "%r" (ah), "%r" (al), "rI" (bl));\ - else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \ - __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "%r" (ah), "%r" (al), "rI" (bl));\ - else \ - __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \ - : "=r" (sh), "=&r" (sl) \ - : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \ - } while (0) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - do { \ - if (__builtin_constant_p (ah) && (ah) == 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ - else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ - else if (__builtin_constant_p (bh) && (bh) == 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ - else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \ - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \ - : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ - else \ - __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \ - : "=r" (sh), "=&r" (sl) \ - : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \ - } while (0) -#define count_leading_zeros(count, x) \ - __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x)) -#define COUNT_LEADING_ZEROS_0 64 -#define umul_ppmm(ph, pl, m0, m1) \ - do { \ - UDItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ - (pl) = __m0 * __m1; \ - } while (0) -#define UMUL_TIME 15 -#define smul_ppmm(ph, pl, m0, m1) \ - do { \ - DItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ - (pl) = __m0 * __m1; \ - } while (0) -#define SMUL_TIME 14 /* ??? */ -#define UDIV_TIME 120 /* ??? */ -#endif /* 64-bit PowerPC. */ - -#if defined (__pyr__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("addw %5,%1\n\taddwc %3,%0" \ - : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \ - : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "%1" ((USItype)(al)), "g" ((USItype)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subw %5,%1\n\tsubwb %3,%0" \ - : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \ - : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "1" ((USItype)(al)), "g" ((USItype)(bl))) -/* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */ -#define umul_ppmm(w1, w0, u, v) \ - ({union {UDItype __ll; \ - struct {USItype __h, __l;} __i; \ - } __x; \ - __asm__ ("movw %1,%R0\n\tuemul %2,%0" \ - : "=&r" (__x.__ll) \ - : "g" ((USItype) (u)), "g" ((USItype)(v))); \ - (w1) = __x.__i.__h; (w0) = __x.__i.__l;}) -#endif /* __pyr__ */ - -#if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("a %1,%5\n\tae %0,%3" \ - : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \ - : "%0" ((USItype)(ah)), "r" ((USItype)(bh)), \ - "%1" ((USItype)(al)), "r" ((USItype)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("s %1,%5\n\tse %0,%3" \ - : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \ - : "0" ((USItype)(ah)), "r" ((USItype)(bh)), \ - "1" ((USItype)(al)), "r" ((USItype)(bl))) -#define smul_ppmm(ph, pl, m0, m1) \ - __asm__ ( \ - "s r2,r2 - mts r10,%2 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - m r2,%3 - cas %0,r2,r0 - mfs r10,%1" \ - : "=r" ((USItype)(ph)), "=r" ((USItype)(pl)) \ - : "%r" ((USItype)(m0)), "r" ((USItype)(m1)) \ - : "r2"); \ -#define UMUL_TIME 20 -#define UDIV_TIME 200 -#define count_leading_zeros(count, x) \ - do { \ - if ((x) >= 0x10000) \ - __asm__ ("clz %0,%1" \ - : "=r" ((USItype)(count)) : "r" ((USItype)(x) >> 16)); \ - else \ - { \ - __asm__ ("clz %0,%1" \ - : "=r" ((USItype)(count)) : "r" ((USItype)(x))); \ - (count) += 16; \ - } \ - } while (0) -#endif /* RT/ROMP */ - -#if defined (__sh2__) && W_TYPE_SIZE == 32 -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0" \ - : "=r" (w1), "=r" (w0) : "r" (u), "r" (v) : "macl", "mach") -#define UMUL_TIME 5 -#endif - -#if defined (__sparc__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0" \ - : "=r" (sh), "=&r" (sl) \ - : "%rJ" (ah), "rI" (bh),"%rJ" (al), "rI" (bl) \ - __CLOBBER_CC) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0" \ - : "=r" (sh), "=&r" (sl) \ - : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl) \ - __CLOBBER_CC) -#if defined (__sparc_v9__) || defined (__sparcv9) -/* Perhaps we should use floating-point operations here? */ -#if 0 -/* Triggers a bug making mpz/tests/t-gcd.c fail. - Perhaps we simply need explicitly zero-extend the inputs? */ -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mulx %2,%3,%%g1; srl %%g1,0,%1; srlx %%g1,32,%0" : \ - "=r" (w1), "=r" (w0) : "r" (u), "r" (v) : "g1") -#else -/* Use v8 umul until above bug is fixed. */ -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v)) -#endif -/* Use a plain v8 divide for v9. */ -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { \ - USItype __q; \ - __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \ - : "=r" (__q) : "r" (n1), "r" (n0), "r" (d)); \ - (r) = (n0) - __q * (d); \ - (q) = __q; \ - } while (0) -#else -#if defined (__sparc_v8__) -/* Don't match immediate range because, 1) it is not often useful, - 2) the 'I' flag thinks of the range as a 13 bit signed interval, - while we want to match a 13 bit interval, sign extended to 32 bits, - but INTERPRETED AS UNSIGNED. */ -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v)) -#define UMUL_TIME 5 -#ifndef SUPERSPARC /* SuperSPARC's udiv only handles 53 bit dividends */ -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { \ - USItype __q; \ - __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \ - : "=r" (__q) : "r" (n1), "r" (n0), "r" (d)); \ - (r) = (n0) - __q * (d); \ - (q) = __q; \ - } while (0) -#define UDIV_TIME 25 -#else -#define UDIV_TIME 60 /* SuperSPARC timing */ -#endif /* SUPERSPARC */ -#else /* ! __sparc_v8__ */ -#if defined (__sparclite__) -/* This has hardware multiply but not divide. It also has two additional - instructions scan (ffs from high bit) and divscc. */ -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v)) -#define UMUL_TIME 5 -#define udiv_qrnnd(q, r, n1, n0, d) \ - __asm__ ("! Inlined udiv_qrnnd - wr %%g0,%2,%%y ! Not a delayed write for sparclite - tst %%g0 - divscc %3,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%%g1 - divscc %%g1,%4,%0 - rd %%y,%1 - bl,a 1f - add %1,%4,%1 -1: ! End of inline udiv_qrnnd" \ - : "=r" (q), "=r" (r) : "r" (n1), "r" (n0), "rI" (d) - : "%g1" __AND_CLOBBER_CC) -#define UDIV_TIME 37 -#define count_leading_zeros(count, x) \ - __asm__ ("scan %1,0,%0" : "=r" (x) : "r" (count)) -/* Early sparclites return 63 for an argument of 0, but they warn that future - implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0 - undefined. */ -#endif /* __sparclite__ */ -#endif /* __sparc_v8__ */ -#endif /* __sparc_v9__ */ -/* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */ -#ifndef umul_ppmm -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("! Inlined umul_ppmm - wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr - sra %3,31,%%g2 ! Don't move this insn - and %2,%%g2,%%g2 ! Don't move this insn - andcc %%g0,0,%%g1 ! Don't move this insn - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,%3,%%g1 - mulscc %%g1,0,%%g1 - add %%g1,%%g2,%0 - rd %%y,%1" \ - : "=r" (w1), "=r" (w0) : "%rI" (u), "r" (v) \ - : "%g1", "%g2" __AND_CLOBBER_CC) -#define UMUL_TIME 39 /* 39 instructions */ -#endif -#ifndef udiv_qrnnd -#ifndef LONGLONG_STANDALONE -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { USItype __r; \ - (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \ - (r) = __r; \ - } while (0) -extern USItype __MPN(udiv_qrnnd) _PROTO ((USItype *, USItype, USItype, USItype)); -#ifndef UDIV_TIME -#define UDIV_TIME 140 -#endif -#endif /* LONGLONG_STANDALONE */ -#endif /* udiv_qrnnd */ -#endif /* __sparc__ */ - -#if defined (__vax__) && W_TYPE_SIZE == 32 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("addl2 %5,%1\n\tadwc %3,%0" \ - : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \ - : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "%1" ((USItype)(al)), "g" ((USItype)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subl2 %5,%1\n\tsbwc %3,%0" \ - : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \ - : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \ - "1" ((USItype)(al)), "g" ((USItype)(bl))) -#define smul_ppmm(xh, xl, m0, m1) \ - do { \ - union {UDItype __ll; \ - struct {USItype __l, __h;} __i; \ - } __x; \ - USItype __m0 = (m0), __m1 = (m1); \ - __asm__ ("emul %1,%2,$0,%0" \ - : "=g" (__x.__ll) : "g" (__m0), "g" (__m1)); \ - (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ - } while (0) -#define sdiv_qrnnd(q, r, n1, n0, d) \ - do { \ - union {DItype __ll; \ - struct {SItype __l, __h;} __i; \ - } __x; \ - __x.__i.__h = n1; __x.__i.__l = n0; \ - __asm__ ("ediv %3,%2,%0,%1" \ - : "=g" (q), "=g" (r) : "g" (__x.__ll), "g" (d)); \ - } while (0) -#endif /* __vax__ */ - -#if defined (__z8000__) && W_TYPE_SIZE == 16 -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \ - : "=r" ((unsigned int)(sh)), "=&r" ((unsigned int)(sl)) \ - : "%0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)), \ - "%1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl))) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \ - : "=r" ((unsigned int)(sh)), "=&r" ((unsigned int)(sl)) \ - : "0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)), \ - "1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl))) -#define umul_ppmm(xh, xl, m0, m1) \ - do { \ - union {long int __ll; \ - struct {unsigned int __h, __l;} __i; \ - } __x; \ - unsigned int __m0 = (m0), __m1 = (m1); \ - __asm__ ("mult %S0,%H3" \ - : "=r" (__x.__i.__h), "=r" (__x.__i.__l) \ - : "%1" (m0), "rQR" (m1)); \ - (xh) = __x.__i.__h; (xl) = __x.__i.__l; \ - (xh) += ((((signed int) __m0 >> 15) & __m1) \ - + (((signed int) __m1 >> 15) & __m0)); \ - } while (0) -#endif /* __z8000__ */ - -#endif /* __GNUC__ */ - - -#if !defined (umul_ppmm) && defined (__umulsidi3) -#define umul_ppmm(ph, pl, m0, m1) \ - { \ - UDWtype __ll = __umulsidi3 (m0, m1); \ - ph = (UWtype) (__ll >> W_TYPE_SIZE); \ - pl = (UWtype) __ll; \ - } -#endif - -#if !defined (__umulsidi3) -#define __umulsidi3(u, v) \ - ({UWtype __hi, __lo; \ - umul_ppmm (__hi, __lo, u, v); \ - ((UDWtype) __hi << W_TYPE_SIZE) | __lo; }) -#endif - - -/* Note the prototypes are under !define(umul_ppmm) etc too, since the HPPA - versions above are different and we don't want to conflict. */ - -#if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm -#define mpn_umul_ppmm __MPN(umul_ppmm) -extern mp_limb_t mpn_umul_ppmm _PROTO ((mp_limb_t *, mp_limb_t, mp_limb_t)); -#define umul_ppmm(wh, wl, u, v) \ - do { \ - mp_limb_t __umul_ppmm__p0; \ - (wh) = __MPN(umul_ppmm) (&__umul_ppmm__p0, \ - (mp_limb_t) (u), (mp_limb_t) (v)); \ - (wl) = __umul_ppmm__p0; \ - } while (0) -#endif - -#if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd -#define mpn_udiv_qrnnd __MPN(udiv_qrnnd) -extern mp_limb_t mpn_udiv_qrnnd _PROTO ((mp_limb_t *, - mp_limb_t, mp_limb_t, mp_limb_t)); -#define udiv_qrnnd(q, r, n1, n0, d) \ - do { \ - mp_limb_t __udiv_qrnnd__r; \ - (q) = mpn_udiv_qrnnd (&__udiv_qrnnd__r, \ - (mp_limb_t) (n1), (mp_limb_t) (n0), (mp_limb_t) d); \ - (r) = __udiv_qrnnd__r; \ - } while (0) -#endif - - -/* If this machine has no inline assembler, use C macros. */ - -#if !defined (add_ssaaaa) -#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ - do { \ - UWtype __x; \ - __x = (al) + (bl); \ - (sh) = (ah) + (bh) + (__x < (al)); \ - (sl) = __x; \ - } while (0) -#endif - -#if !defined (sub_ddmmss) -#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - do { \ - UWtype __x; \ - __x = (al) - (bl); \ - (sh) = (ah) - (bh) - (__x > (al)); \ - (sl) = __x; \ - } while (0) -#endif - -/* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of - smul_ppmm. */ -#if !defined (umul_ppmm) && defined (smul_ppmm) -#define umul_ppmm(w1, w0, u, v) \ - do { \ - UWtype __w1; \ - UWtype __xm0 = (u), __xm1 = (v); \ - smul_ppmm (__w1, w0, __xm0, __xm1); \ - (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \ - + (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \ - } while (0) -#endif - -/* If we still don't have umul_ppmm, define it using plain C. */ -#if !defined (umul_ppmm) -#define umul_ppmm(w1, w0, u, v) \ - do { \ - UWtype __x0, __x1, __x2, __x3; \ - UHWtype __ul, __vl, __uh, __vh; \ - UWtype __u = (u), __v = (v); \ - \ - __ul = __ll_lowpart (__u); \ - __uh = __ll_highpart (__u); \ - __vl = __ll_lowpart (__v); \ - __vh = __ll_highpart (__v); \ - \ - __x0 = (UWtype) __ul * __vl; \ - __x1 = (UWtype) __ul * __vh; \ - __x2 = (UWtype) __uh * __vl; \ - __x3 = (UWtype) __uh * __vh; \ - \ - __x1 += __ll_highpart (__x0);/* this can't give carry */ \ - __x1 += __x2; /* but this indeed can */ \ - if (__x1 < __x2) /* did we get it? */ \ - __x3 += __ll_B; /* yes, add it in the proper pos. */ \ - \ - (w1) = __x3 + __ll_highpart (__x1); \ - (w0) = (__x1 << W_TYPE_SIZE/2) + __ll_lowpart (__x0); \ - } while (0) -#endif - -/* If we don't have smul_ppmm, define it using umul_ppmm (which surely will - exist in one form or another. */ -#if !defined (smul_ppmm) -#define smul_ppmm(w1, w0, u, v) \ - do { \ - UWtype __w1; \ - UWtype __xm0 = (u), __xm1 = (v); \ - umul_ppmm (__w1, w0, __xm0, __xm1); \ - (w1) = __w1 - (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \ - - (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \ - } while (0) -#endif - -/* Define this unconditionally, so it can be used for debugging. */ -#define __udiv_qrnnd_c(q, r, n1, n0, d) \ - do { \ - UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \ - __d1 = __ll_highpart (d); \ - __d0 = __ll_lowpart (d); \ - \ - __q1 = (n1) / __d1; \ - __r1 = (n1) - __q1 * __d1; \ - __m = (UWtype) __q1 * __d0; \ - __r1 = __r1 * __ll_B | __ll_highpart (n0); \ - if (__r1 < __m) \ - { \ - __q1--, __r1 += (d); \ - if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\ - if (__r1 < __m) \ - __q1--, __r1 += (d); \ - } \ - __r1 -= __m; \ - \ - __q0 = __r1 / __d1; \ - __r0 = __r1 - __q0 * __d1; \ - __m = (UWtype) __q0 * __d0; \ - __r0 = __r0 * __ll_B | __ll_lowpart (n0); \ - if (__r0 < __m) \ - { \ - __q0--, __r0 += (d); \ - if (__r0 >= (d)) \ - if (__r0 < __m) \ - __q0--, __r0 += (d); \ - } \ - __r0 -= __m; \ - \ - (q) = (UWtype) __q1 * __ll_B | __q0; \ - (r) = __r0; \ - } while (0) - -/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through - __udiv_w_sdiv (defined in libgcc or elsewhere). */ -#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd) -#define udiv_qrnnd(q, r, nh, nl, d) \ - do { \ - UWtype __r; \ - (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \ - (r) = __r; \ - } while (0) -#endif - -/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */ -#if !defined (udiv_qrnnd) -#define UDIV_NEEDS_NORMALIZATION 1 -#define udiv_qrnnd __udiv_qrnnd_c -#endif - -#if !defined (count_leading_zeros) -extern -#if __STDC__ -const -#endif -unsigned char __clz_tab[]; -#define count_leading_zeros(count, x) \ - do { \ - UWtype __xr = (x); \ - UWtype __a; \ - \ - if (W_TYPE_SIZE <= 32) \ - { \ - __a = __xr < ((UWtype) 1 << 2*__BITS4) \ - ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \ - : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4);\ - } \ - else \ - { \ - for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \ - if (((__xr >> __a) & 0xff) != 0) \ - break; \ - } \ - \ - (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \ - } while (0) -/* This version gives a well-defined value for zero. */ -#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE -#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB -#endif - -#if !defined (count_trailing_zeros) -/* Define count_trailing_zeros using count_leading_zeros. The latter might be - defined in asm, but if it is not, the C version above is good enough. */ -#define count_trailing_zeros(count, x) \ - do { \ - UWtype __ctz_x = (x); \ - UWtype __ctz_c; \ - count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \ - (count) = W_TYPE_SIZE - 1 - __ctz_c; \ - } while (0) -#endif - -#ifndef UDIV_NEEDS_NORMALIZATION -#define UDIV_NEEDS_NORMALIZATION 0 -#endif - -/* Give defaults for UMUL_TIME and UDIV_TIME. */ -#ifndef UMUL_TIME -#define UMUL_TIME 1 -#endif - -#ifndef UDIV_TIME -#define UDIV_TIME UMUL_TIME -#endif - -/* count_trailing_zeros is often on the slow side, so make that the default */ -#ifndef COUNT_TRAILING_ZEROS_TIME -#define COUNT_TRAILING_ZEROS_TIME 15 /* cycles */ -#endif - - diff --git a/gmp/ltconfig b/gmp/ltconfig deleted file mode 100755 index 9e67ae3..0000000 Binary files a/gmp/ltconfig and /dev/null differ diff --git a/gmp/ltmain.sh b/gmp/ltmain.sh deleted file mode 100755 index 74c10dc..0000000 Binary files a/gmp/ltmain.sh and /dev/null differ diff --git a/gmp/macos.1/Makefile.in b/gmp/macos.1/Makefile.in deleted file mode 100755 index b40bf3a..0000000 Binary files a/gmp/macos.1/Makefile.in and /dev/null differ diff --git a/gmp/macos.1/README b/gmp/macos.1/README deleted file mode 100755 index 1396377..0000000 Binary files a/gmp/macos.1/README and /dev/null differ diff --git a/gmp/macos.1/configure b/gmp/macos.1/configure deleted file mode 100755 index 41be302..0000000 Binary files a/gmp/macos.1/configure and /dev/null differ diff --git a/gmp/macos.1/unix2mac b/gmp/macos.1/unix2mac deleted file mode 100755 index 7944842..0000000 Binary files a/gmp/macos.1/unix2mac and /dev/null differ diff --git a/gmp/mdate-sh b/gmp/mdate-sh deleted file mode 100755 index 5177717..0000000 Binary files a/gmp/mdate-sh and /dev/null differ diff --git a/gmp/memory.c b/gmp/memory.c deleted file mode 100755 index 9df440c..0000000 --- a/gmp/memory.c +++ /dev/null @@ -1,160 +0,0 @@ -/* Memory allocation routines. - -Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include /* for malloc, realloc, free */ - -#include "gmp.h" -#include "gmp-impl.h" - -#ifdef __NeXT__ -#define static -#endif - - -void * (*_mp_allocate_func) _PROTO ((size_t)) = _mp_default_allocate; -void * (*_mp_reallocate_func) _PROTO ((void *, size_t, size_t)) - = _mp_default_reallocate; -void (*_mp_free_func) _PROTO ((void *, size_t)) = _mp_default_free; - - -/* Default allocation functions. In case of failure to allocate/reallocate - an error message is written to stderr and the program aborts. */ - -void * -#if __STDC__ -_mp_default_allocate (size_t size) -#else -_mp_default_allocate (size) - size_t size; -#endif -{ - void *ret; -#ifdef DEBUG - size_t req_size = size; - size += 2 * BYTES_PER_MP_LIMB; -#endif - ret = malloc (size); - if (ret == 0) - { - perror ("cannot allocate in gmp"); - abort (); - } - -#ifdef DEBUG - { - mp_ptr p = ret; - p++; - p[-1] = (0xdeadbeef << 31) + 0xdeafdeed; - if (req_size % BYTES_PER_MP_LIMB == 0) - p[req_size / BYTES_PER_MP_LIMB] = ~((0xdeadbeef << 31) + 0xdeafdeed); - ret = p; - } -#endif - return ret; -} - -void * -#if __STDC__ -_mp_default_reallocate (void *oldptr, size_t old_size, size_t new_size) -#else -_mp_default_reallocate (oldptr, old_size, new_size) - void *oldptr; - size_t old_size; - size_t new_size; -#endif -{ - void *ret; - -#ifdef DEBUG - size_t req_size = new_size; - - if (old_size != 0) - { - mp_ptr p = oldptr; - if (p[-1] != (0xdeadbeef << 31) + 0xdeafdeed) - { - fprintf (stderr, "gmp: (realloc) data clobbered before allocation block\n"); - abort (); - } - if (old_size % BYTES_PER_MP_LIMB == 0) - if (p[old_size / BYTES_PER_MP_LIMB] != ~((0xdeadbeef << 31) + 0xdeafdeed)) - { - fprintf (stderr, "gmp: (realloc) data clobbered after allocation block\n"); - abort (); - } - oldptr = p - 1; - } - - new_size += 2 * BYTES_PER_MP_LIMB; -#endif - - ret = realloc (oldptr, new_size); - if (ret == 0) - { - perror ("cannot allocate in gmp"); - abort (); - } - -#ifdef DEBUG - { - mp_ptr p = ret; - p++; - p[-1] = (0xdeadbeef << 31) + 0xdeafdeed; - if (req_size % BYTES_PER_MP_LIMB == 0) - p[req_size / BYTES_PER_MP_LIMB] = ~((0xdeadbeef << 31) + 0xdeafdeed); - ret = p; - } -#endif - return ret; -} - -void -#if __STDC__ -_mp_default_free (void *blk_ptr, size_t blk_size) -#else -_mp_default_free (blk_ptr, blk_size) - void *blk_ptr; - size_t blk_size; -#endif -{ -#ifdef DEBUG - { - mp_ptr p = blk_ptr; - if (blk_size != 0) - { - if (p[-1] != (0xdeadbeef << 31) + 0xdeafdeed) - { - fprintf (stderr, "gmp: (free) data clobbered before allocation block\n"); - abort (); - } - if (blk_size % BYTES_PER_MP_LIMB == 0) - if (p[blk_size / BYTES_PER_MP_LIMB] != ~((0xdeadbeef << 31) + 0xdeafdeed)) - { - fprintf (stderr, "gmp: (free) data clobbered after allocation block\n"); - abort (); - } - } - blk_ptr = p - 1; - } -#endif - free (blk_ptr); -} diff --git a/gmp/missing b/gmp/missing deleted file mode 100755 index 6334ade..0000000 Binary files a/gmp/missing and /dev/null differ diff --git a/gmp/mkinstalldirs b/gmp/mkinstalldirs deleted file mode 100755 index 460d696..0000000 Binary files a/gmp/mkinstalldirs and /dev/null differ diff --git a/gmp/mp.h b/gmp/mp.h deleted file mode 100755 index 774e6e5..0000000 --- a/gmp/mp.h +++ /dev/null @@ -1,123 +0,0 @@ -/* mp.h -- Definitions for Berkeley compatible multiple precision functions. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#ifndef __MP_H__ - -#ifndef __GNU_MP__ /* to allow inclusion of both gmp.h and mp.h */ -#define __GNU_MP__ 3 -#define __need_size_t -#include -#undef __need_size_t - -#if defined (__STDC__) || defined (__cplusplus) -#define __gmp_const const -#else -#define __gmp_const -#endif - -#if defined (__GNUC__) -#define __gmp_inline __inline__ -#else -#define __gmp_inline -#endif - -#ifndef _EXTERN_INLINE -#ifdef __GNUC__ -#define _EXTERN_INLINE extern __inline__ -#else -#define _EXTERN_INLINE static -#endif -#endif - -#ifdef _SHORT_LIMB -typedef unsigned int mp_limb_t; -typedef int mp_limb_signed_t; -#else -#ifdef _LONG_LONG_LIMB -typedef unsigned long long int mp_limb_t; -typedef long long int mp_limb_signed_t; -#else -typedef unsigned long int mp_limb_t; -typedef long int mp_limb_signed_t; -#endif -#endif - -typedef mp_limb_t * mp_ptr; -typedef __gmp_const mp_limb_t * mp_srcptr; -typedef int mp_size_t; -typedef long int mp_exp_t; - -typedef struct -{ - int _mp_alloc; /* Number of *limbs* allocated and pointed - to by the D field. */ - int _mp_size; /* abs(SIZE) is the number of limbs - the last field points to. If SIZE - is negative this is a negative - number. */ - mp_limb_t *_mp_d; /* Pointer to the limbs. */ -} __mpz_struct; -#endif /* __GNU_MP__ */ - -/* User-visible types. */ -typedef __mpz_struct MINT; - - -#ifndef _PROTO -#if (__STDC__-0) || defined (__cplusplus) -#define _PROTO(x) x -#else -#define _PROTO(x) () -#endif -#endif - -#if defined (__cplusplus) -extern "C" { -#endif - -void mp_set_memory_functions _PROTO ((void *(*) (size_t), - void *(*) (void *, size_t, size_t), - void (*) (void *, size_t))); -MINT *itom _PROTO ((signed short int)); -MINT *xtom _PROTO ((const char *)); -void move _PROTO ((const MINT *, MINT *)); -void madd _PROTO ((const MINT *, const MINT *, MINT *)); -void msub _PROTO ((const MINT *, const MINT *, MINT *)); -void mult _PROTO ((const MINT *, const MINT *, MINT *)); -void mdiv _PROTO ((const MINT *, const MINT *, MINT *, MINT *)); -void sdiv _PROTO ((const MINT *, signed short int, MINT *, signed short int *)); -void msqrt _PROTO ((const MINT *, MINT *, MINT *)); -void pow _PROTO ((const MINT *, const MINT *, const MINT *, MINT *)); -void rpow _PROTO ((const MINT *, signed short int, MINT *)); -void gcd _PROTO ((const MINT *, const MINT *, MINT *)); -int mcmp _PROTO ((const MINT *, const MINT *)); -void min _PROTO ((MINT *)); -void mout _PROTO ((const MINT *)); -char *mtox _PROTO ((const MINT *)); -void mfree _PROTO ((MINT *)); - -#if defined (__cplusplus) -} -#endif - -#define __MP_H__ -#endif /* __MP_H__ */ diff --git a/gmp/mp_bpl.c b/gmp/mp_bpl.c deleted file mode 100755 index df8b03e..0000000 --- a/gmp/mp_bpl.c +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" - -const int mp_bits_per_limb = BITS_PER_MP_LIMB; -const int __gmp_0 = 0; -int __gmp_junk; diff --git a/gmp/mp_clz_tab.c b/gmp/mp_clz_tab.c deleted file mode 100755 index 1bbd1d6..0000000 --- a/gmp/mp_clz_tab.c +++ /dev/null @@ -1,36 +0,0 @@ -/* __clz_tab -- support for longlong.h - -Copyright (C) 1991, 1993, 1994, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -const -unsigned char __clz_tab[] = -{ - 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, - 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, -}; diff --git a/gmp/mp_minv_tab.c b/gmp/mp_minv_tab.c deleted file mode 100755 index 4afff85..0000000 --- a/gmp/mp_minv_tab.c +++ /dev/null @@ -1,50 +0,0 @@ -/* A table of data supporting modlimb_invert(). - - THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND MAY CHANGE - INCOMPATIBLY OR DISAPPEAR IN A FUTURE GNU MP RELEASE. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - - -/* modlimb_invert_table[i] is the multiplicative inverse of 2*i+1 mod 256, - ie. (modlimb_invert_table[i] * (2*i+1)) % 256 == 1 */ - -const unsigned char modlimb_invert_table[128] = { - 0x01, 0xAB, 0xCD, 0xB7, 0x39, 0xA3, 0xC5, 0xEF, - 0xF1, 0x1B, 0x3D, 0xA7, 0x29, 0x13, 0x35, 0xDF, - 0xE1, 0x8B, 0xAD, 0x97, 0x19, 0x83, 0xA5, 0xCF, - 0xD1, 0xFB, 0x1D, 0x87, 0x09, 0xF3, 0x15, 0xBF, - 0xC1, 0x6B, 0x8D, 0x77, 0xF9, 0x63, 0x85, 0xAF, - 0xB1, 0xDB, 0xFD, 0x67, 0xE9, 0xD3, 0xF5, 0x9F, - 0xA1, 0x4B, 0x6D, 0x57, 0xD9, 0x43, 0x65, 0x8F, - 0x91, 0xBB, 0xDD, 0x47, 0xC9, 0xB3, 0xD5, 0x7F, - 0x81, 0x2B, 0x4D, 0x37, 0xB9, 0x23, 0x45, 0x6F, - 0x71, 0x9B, 0xBD, 0x27, 0xA9, 0x93, 0xB5, 0x5F, - 0x61, 0x0B, 0x2D, 0x17, 0x99, 0x03, 0x25, 0x4F, - 0x51, 0x7B, 0x9D, 0x07, 0x89, 0x73, 0x95, 0x3F, - 0x41, 0xEB, 0x0D, 0xF7, 0x79, 0xE3, 0x05, 0x2F, - 0x31, 0x5B, 0x7D, 0xE7, 0x69, 0x53, 0x75, 0x1F, - 0x21, 0xCB, 0xED, 0xD7, 0x59, 0xC3, 0xE5, 0x0F, - 0x11, 0x3B, 0x5D, 0xC7, 0x49, 0x33, 0x55, 0xFF -}; diff --git a/gmp/mp_set_fns.c b/gmp/mp_set_fns.c deleted file mode 100755 index 55d4d9d..0000000 --- a/gmp/mp_set_fns.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mp_set_memory_functions -- Set the allocate, reallocate, and free functions - for use by the mp package. - -Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mp_set_memory_functions (void *(*alloc_func) (size_t), - void *(*realloc_func) (void *, size_t, size_t), - void (*free_func) (void *, size_t)) -#else -mp_set_memory_functions (alloc_func, realloc_func, free_func) - void *(*alloc_func) (); - void *(*realloc_func) (); - void (*free_func) (); -#endif -{ - if (alloc_func == 0) - alloc_func = _mp_default_allocate; - if (realloc_func == 0) - realloc_func = _mp_default_reallocate; - if (free_func == 0) - free_func = _mp_default_free; - - _mp_allocate_func = alloc_func; - _mp_reallocate_func = realloc_func; - _mp_free_func = free_func; -} diff --git a/gmp/mpbsd/Makefile.am b/gmp/mpbsd/Makefile.am deleted file mode 100755 index 3c02017..0000000 Binary files a/gmp/mpbsd/Makefile.am and /dev/null differ diff --git a/gmp/mpbsd/Makefile.in b/gmp/mpbsd/Makefile.in deleted file mode 100755 index ca3529a..0000000 Binary files a/gmp/mpbsd/Makefile.in and /dev/null differ diff --git a/gmp/mpbsd/itom.c b/gmp/mpbsd/itom.c deleted file mode 100755 index 40ccf00..0000000 --- a/gmp/mpbsd/itom.c +++ /dev/null @@ -1,54 +0,0 @@ -/* itom -- BSD compatible allocate and initiate a MINT. - -Copyright (C) 1991, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -MINT * -#if __STDC__ -itom (signed short int n) -#else -itom (n) - short int n; -#endif -{ - MINT *x; - mp_ptr xp; - - x = (MINT *) (*_mp_allocate_func) (sizeof (MINT)); - x->_mp_alloc = 1; - x->_mp_d = xp = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - if (n > 0) - { - x->_mp_size = 1; - xp[0] = n; - } - else if (n < 0) - { - x->_mp_size = -1; - xp[0] = (unsigned short) -n; - } - else - x->_mp_size = 0; - - return x; -} diff --git a/gmp/mpbsd/mfree.c b/gmp/mpbsd/mfree.c deleted file mode 100755 index 6a93c85..0000000 --- a/gmp/mpbsd/mfree.c +++ /dev/null @@ -1,36 +0,0 @@ -/* mfree -- BSD compatible mfree. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mfree (MINT *m) -#else -mfree (m) - MINT *m; -#endif -{ - (*_mp_free_func) (m->_mp_d, m->_mp_alloc * BYTES_PER_MP_LIMB); - (*_mp_free_func) (m, sizeof (MINT)); -} diff --git a/gmp/mpbsd/min.c b/gmp/mpbsd/min.c deleted file mode 100755 index 88078e8..0000000 --- a/gmp/mpbsd/min.c +++ /dev/null @@ -1,114 +0,0 @@ -/* min(MINT) -- Do decimal input from standard input and store result in - MINT. - -Copyright (C) 1991, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -static int -#if __STDC__ -digit_value_in_base (int c, int base) -#else -digit_value_in_base (c, base) - int c; - int base; -#endif -{ - int digit; - - if (isdigit (c)) - digit = c - '0'; - else if (islower (c)) - digit = c - 'a' + 10; - else if (isupper (c)) - digit = c - 'A' + 10; - else - return -1; - - if (digit < base) - return digit; - return -1; -} - -void -#if __STDC__ -min (MINT *dest) -#else -min (dest) - MINT *dest; -#endif -{ - char *str; - size_t alloc_size, str_size; - int c; - int negative; - mp_size_t dest_size; - - alloc_size = 100; - str = (char *) (*_mp_allocate_func) (alloc_size); - str_size = 0; - - /* Skip whitespace. */ - do - c = getc (stdin); - while (isspace (c)); - - negative = 0; - if (c == '-') - { - negative = 1; - c = getc (stdin); - } - - if (digit_value_in_base (c, 10) < 0) - return; /* error if no digits */ - - for (;;) - { - int dig; - if (str_size >= alloc_size) - { - size_t old_alloc_size = alloc_size; - alloc_size = alloc_size * 3 / 2; - str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); - } - dig = digit_value_in_base (c, 10); - if (dig < 0) - break; - str[str_size++] = dig; - c = getc (stdin); - } - - ungetc (c, stdin); - - dest_size = str_size / __mp_bases[10].chars_per_limb + 1; - if (dest->_mp_alloc < dest_size) - _mp_realloc (dest, dest_size); - - dest_size = mpn_set_str (dest->_mp_d, (unsigned char *) str, str_size, 10); - dest->_mp_size = negative ? -dest_size : dest_size; - - (*_mp_free_func) (str, alloc_size); - return; -} diff --git a/gmp/mpbsd/mout.c b/gmp/mpbsd/mout.c deleted file mode 100755 index 96b7022..0000000 --- a/gmp/mpbsd/mout.c +++ /dev/null @@ -1,97 +0,0 @@ -/* mout(MINT) -- Do decimal output of MINT to standard output. - -Copyright (C) 1991, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mout (const MINT *x) -#else -mout (x) - const MINT *x; -#endif -{ - mp_ptr xp; - mp_size_t x_size = x->_mp_size; - unsigned char *str; - size_t str_size; - char *num_to_text; - int i; - TMP_DECL (marker); - - if (x_size == 0) - { - fputc ('0', stdout); - return; - } - if (x_size < 0) - { - fputc ('-', stdout); - x_size = -x_size; - } - - TMP_MARK (marker); - str_size = ((size_t) (x_size * BITS_PER_MP_LIMB - * __mp_bases[10].chars_per_bit_exactly)) + 3; - str = (unsigned char *) TMP_ALLOC (str_size); - - /* Move the number to convert into temporary space, since mpn_get_str - clobbers its argument + needs one extra high limb.... */ - xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (xp, x->_mp_d, x_size); - - str_size = mpn_get_str (str, 10, xp, x_size); - - /* mpn_get_str might make some leading zeros. Skip them. */ - while (*str == 0) - { - str_size--; - str++; - } - - /* Translate to printable chars. */ - for (i = 0; i < str_size; i++) - str[i] = "0123456789"[str[i]]; - str[str_size] = 0; - - str_size = strlen ((char *) str); - if (str_size % 10 != 0) - { - fwrite (str, 1, str_size % 10, stdout); - str += str_size % 10; - str_size -= str_size % 10; - if (str_size != 0) - fputc (' ', stdout); - } - for (i = 0; i < str_size; i += 10) - { - fwrite (str, 1, 10, stdout); - str += 10; - if (i + 10 < str_size) - fputc (' ', stdout); - } - fputc ('\n', stdout); - TMP_FREE (marker); -} diff --git a/gmp/mpbsd/move.c b/gmp/mpbsd/move.c deleted file mode 100755 index d486057..0000000 --- a/gmp/mpbsd/move.c +++ /dev/null @@ -1,46 +0,0 @@ -/* move -- BSD compatible assignment. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -move (const MINT *u, MINT *w) -#else -move (u, w) - const MINT *u; - MINT *w; -#endif -{ - mp_size_t usize; - mp_size_t abs_usize; - - usize = u->_mp_size; - abs_usize = ABS (usize); - - if (w->_mp_alloc < abs_usize) - _mp_realloc (w, abs_usize); - - w->_mp_size = usize; - MPN_COPY (w->_mp_d, u->_mp_d, abs_usize); -} diff --git a/gmp/mpbsd/mtox.c b/gmp/mpbsd/mtox.c deleted file mode 100755 index 5d5a82c..0000000 --- a/gmp/mpbsd/mtox.c +++ /dev/null @@ -1,81 +0,0 @@ -/* mtox -- Convert OPERAND to hexadecimal and return a malloc'ed string - with the result of the conversion. - -Copyright (C) 1991, 1994, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -char * -#if __STDC__ -mtox (const MINT *x) -#else -mtox (x) - const MINT *x; -#endif -{ - mp_ptr xp; - mp_size_t xsize = x->_mp_size; - mp_size_t xsign; - unsigned char *str, *s; - size_t str_size, i; - int zeros; - char *num_to_text; - TMP_DECL (marker); - - if (xsize == 0) - { - str = (unsigned char *) (*_mp_allocate_func) (2); - str[0] = '0'; - str[1] = 0; - return (char *) str; - } - xsign = xsize; - if (xsize < 0) - xsize = -xsize; - - TMP_MARK (marker); - str_size = ((size_t) (xsize * BITS_PER_MP_LIMB - * __mp_bases[16].chars_per_bit_exactly)) + 3; - str = (unsigned char *) (*_mp_allocate_func) (str_size); - s = str; - - if (xsign < 0) - *s++ = '-'; - - /* Move the number to convert into temporary space, since mpn_get_str - clobbers its argument + needs one extra high limb.... */ - xp = (mp_ptr) TMP_ALLOC ((xsize + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (xp, x->_mp_d, xsize); - - str_size = mpn_get_str (s, 16, xp, xsize); - - /* mpn_get_str might make some leading zeros. Skip them. */ - for (zeros = 0; s[zeros] == 0; zeros++) - str_size--; - - /* Translate to printable chars and move string down. */ - for (i = 0; i < str_size; i++) - s[i] = "0123456789abcdef"[s[zeros + i]]; - s[str_size] = 0; - - return (char *) str; -} diff --git a/gmp/mpbsd/sdiv.c b/gmp/mpbsd/sdiv.c deleted file mode 100755 index 9e95cc9..0000000 --- a/gmp/mpbsd/sdiv.c +++ /dev/null @@ -1,77 +0,0 @@ -/* sdiv -- Divide a MINT by a short integer. Produce a MINT quotient - and a short remainder. - -Copyright (C) 1991, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -sdiv (const MINT *dividend, signed short int divisor_short, MINT *quot, short *rem_ptr) -#else -sdiv (dividend, divisor_short, quot, rem_ptr) - const MINT *dividend; - short int divisor_short; - MINT *quot; - short *rem_ptr; -#endif -{ - mp_size_t sign_dividend; - signed long int sign_divisor; - mp_size_t dividend_size, quot_size; - mp_ptr dividend_ptr, quot_ptr; - mp_limb_t divisor_limb; - mp_limb_t remainder_limb; - - sign_dividend = dividend->_mp_size; - dividend_size = ABS (dividend->_mp_size); - - if (dividend_size == 0) - { - quot->_mp_size = 0; - *rem_ptr = 0; - return; - } - - sign_divisor = divisor_short; - divisor_limb = (unsigned short) ABS (divisor_short); - - /* No need for temporary allocation and copying even if QUOT == DIVIDEND - as the divisor is just one limb, and thus no intermediate remainders - need to be stored. */ - - if (quot->_mp_alloc < dividend_size) - _mp_realloc (quot, dividend_size); - - quot_ptr = quot->_mp_d; - dividend_ptr = dividend->_mp_d; - - remainder_limb = mpn_divmod_1 (quot_ptr, - dividend_ptr, dividend_size, divisor_limb); - - *rem_ptr = sign_dividend >= 0 ? remainder_limb : -remainder_limb; - /* The quotient is DIVIDEND_SIZE limbs, but the most significant - might be zero. Set QUOT_SIZE properly. */ - quot_size = dividend_size - (quot_ptr[dividend_size - 1] == 0); - quot->_mp_size = (sign_divisor ^ sign_dividend) >= 0 ? quot_size : -quot_size; -} diff --git a/gmp/mpbsd/tests/Makefile.am b/gmp/mpbsd/tests/Makefile.am deleted file mode 100755 index e907c9e..0000000 Binary files a/gmp/mpbsd/tests/Makefile.am and /dev/null differ diff --git a/gmp/mpbsd/tests/Makefile.in b/gmp/mpbsd/tests/Makefile.in deleted file mode 100755 index 4e4f69d..0000000 Binary files a/gmp/mpbsd/tests/Makefile.in and /dev/null differ diff --git a/gmp/mpbsd/tests/allfuns.c b/gmp/mpbsd/tests/allfuns.c deleted file mode 100755 index ce40c7d..0000000 --- a/gmp/mpbsd/tests/allfuns.c +++ /dev/null @@ -1,58 +0,0 @@ -/* A test program doing nothing really, just linking to all the BSD MP - functions that're supposed to exist. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "mp.h" - -int -main (int argc, char *argv[]) -{ - MINT *a, *b, *c, *d; - short h; - - a = itom (123); - b = xtom ("DEADBEEF"); - c = itom (0); - d = itom (0); - move (a, b); - madd (a, b, c); - msub (a, b, c); - mult (a, b, c); - mdiv (b, a, c, d); - sdiv (b, 2, c, &h); - msqrt (a, c, d); - pow (b, a, a, c); - rpow (a, 3, c); - gcd (a, b, c); - mcmp (a, b); - if (argc > 1) - { - min (c); - mout (a); - } - mtox (b); - - mfree(a); - - exit (0); -} diff --git a/gmp/mpbsd/tests/dummy.c b/gmp/mpbsd/tests/dummy.c deleted file mode 100755 index 280c500..0000000 --- a/gmp/mpbsd/tests/dummy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* A dummy do-nothing test program, which always passes. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -int -main () -{ - exit (0); -} diff --git a/gmp/mpbsd/tests/t-misc.c b/gmp/mpbsd/tests/t-misc.c deleted file mode 100755 index 69d5810..0000000 --- a/gmp/mpbsd/tests/t-misc.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Exercise various mpbsd functions. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mp.h" - -#define SGN(x) ((x) < 0 ? -1 : (x) == 0 ? 0 : 1) - - -void -check_itom (void) -{ - static const struct { - short m; - mp_size_t want_size; - mp_limb_t want_limb; - } data[] = { - - { 0L, 0 }, - { 1L, 1, 1 }, - { -1L, -1, 1 }, - - { SHORT_MAX, 1, SHORT_MAX }, - { -SHORT_MAX, -1, SHORT_MAX }, - - { SHORT_HIGHBIT, -1, USHORT_HIGHBIT }, - }; - - MINT *m; - int i; - - for (i = 0; i < numberof (data); i++) - { - m = itom (data[i].m); - if (m->_mp_size != data[i].want_size - || (m->_mp_size != 0 && m->_mp_d[0] != data[i].want_limb)) - { - printf ("itom wrong on data[%d]\n", i); - abort(); - } - mfree (m); - } -} - - -int -main (void) -{ - check_itom (); - - exit (0); -} diff --git a/gmp/mpbsd/xtom.c b/gmp/mpbsd/xtom.c deleted file mode 100755 index dd5ec19..0000000 --- a/gmp/mpbsd/xtom.c +++ /dev/null @@ -1,116 +0,0 @@ -/* xtom -- convert a hexadecimal string to a MINT, and return a pointer to - the MINT. - -Copyright (C) 1991, 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "mp.h" -#include "gmp.h" -#include "gmp-impl.h" - -static int -#if __STDC__ -digit_value_in_base (int c, int base) -#else -digit_value_in_base (c, base) - int c; - int base; -#endif -{ - int digit; - - if (isdigit (c)) - digit = c - '0'; - else if (islower (c)) - digit = c - 'a' + 10; - else if (isupper (c)) - digit = c - 'A' + 10; - else - return -1; - - if (digit < base) - return digit; - return -1; -} - -MINT * -#if __STDC__ -xtom (const char *str) -#else -xtom (str) - const char *str; -#endif -{ - size_t str_size; - char *s, *begs; - size_t i; - mp_size_t xsize; - int c; - int negative; - MINT *x = (MINT *) (*_mp_allocate_func) (sizeof (MINT)); - TMP_DECL (marker); - - /* Skip whitespace. */ - do - c = *str++; - while (isspace (c)); - - negative = 0; - if (c == '-') - { - negative = 1; - c = *str++; - } - - if (digit_value_in_base (c, 16) < 0) - return 0; /* error if no digits */ - - TMP_MARK (marker); - str_size = strlen (str - 1); - s = begs = (char *) TMP_ALLOC (str_size + 1); - - for (i = 0; i < str_size; i++) - { - if (!isspace (c)) - { - int dig = digit_value_in_base (c, 16); - if (dig < 0) - { - TMP_FREE (marker); - return 0; - } - *s++ = dig; - } - c = *str++; - } - - str_size = s - begs; - - xsize = str_size / __mp_bases[16].chars_per_limb + 1; - x->_mp_alloc = xsize; - x->_mp_d = (mp_ptr) (*_mp_allocate_func) (xsize * BYTES_PER_MP_LIMB); - - xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, 16); - x->_mp_size = negative ? -xsize : xsize; - - TMP_FREE (marker); - return x; -} diff --git a/gmp/mpf/Makefile.am b/gmp/mpf/Makefile.am deleted file mode 100755 index 6064fc8..0000000 Binary files a/gmp/mpf/Makefile.am and /dev/null differ diff --git a/gmp/mpf/Makefile.in b/gmp/mpf/Makefile.in deleted file mode 100755 index 0c3ecf0..0000000 Binary files a/gmp/mpf/Makefile.in and /dev/null differ diff --git a/gmp/mpf/README b/gmp/mpf/README deleted file mode 100755 index c0485fb..0000000 Binary files a/gmp/mpf/README and /dev/null differ diff --git a/gmp/mpf/abs.c b/gmp/mpf/abs.c deleted file mode 100755 index b069f84..0000000 --- a/gmp/mpf/abs.c +++ /dev/null @@ -1,56 +0,0 @@ -/* mpf_abs -- Compute the absolute value of a float. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_abs (mpf_ptr r, mpf_srcptr u) -#else -mpf_abs (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_size_t size; - - size = ABS (u->_mp_size); - if (r != u) - { - mp_size_t prec; - mp_ptr rp, up; - - prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */ - rp = r->_mp_d; - up = u->_mp_d; - - if (size > prec) - { - up += size - prec; - size = prec; - } - - MPN_COPY (rp, up, size); - r->_mp_exp = u->_mp_exp; - } - r->_mp_size = size; -} diff --git a/gmp/mpf/add.c b/gmp/mpf/add.c deleted file mode 100755 index 2d9cad6..0000000 --- a/gmp/mpf/add.c +++ /dev/null @@ -1,180 +0,0 @@ -/* mpf_add -- Add two floats. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_add (mpf_ptr r, mpf_srcptr u, mpf_srcptr v) -#else -mpf_add (r, u, v) - mpf_ptr r; - mpf_srcptr u; - mpf_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_ptr rp, tp; - mp_size_t usize, vsize, rsize; - mp_size_t prec; - mp_exp_t uexp; - mp_size_t ediff; - mp_limb_t cy; - int negate; - TMP_DECL (marker); - - usize = u->_mp_size; - vsize = v->_mp_size; - - /* Handle special cases that don't work in generic code below. */ - if (usize == 0) - { - mpf_set (r, v); - return; - } - if (vsize == 0) - { - mpf_set (r, u); - return; - } - - /* If signs of U and V are different, perform subtraction. */ - if ((usize ^ vsize) < 0) - { - __mpf_struct v_negated; - v_negated._mp_size = -vsize; - v_negated._mp_exp = v->_mp_exp; - v_negated._mp_d = v->_mp_d; - mpf_sub (r, u, &v_negated); - return; - } - - TMP_MARK (marker); - - /* Signs are now known to be the same. */ - negate = usize < 0; - - /* Make U be the operand with the largest exponent. */ - if (u->_mp_exp < v->_mp_exp) - { - mpf_srcptr t; - t = u; u = v; v = t; - usize = u->_mp_size; - vsize = v->_mp_size; - } - - usize = ABS (usize); - vsize = ABS (vsize); - up = u->_mp_d; - vp = v->_mp_d; - rp = r->_mp_d; - prec = r->_mp_prec; - uexp = u->_mp_exp; - ediff = u->_mp_exp - v->_mp_exp; - - /* If U extends beyond PREC, ignore the part that does. */ - if (usize > prec) - { - up += usize - prec; - usize = prec; - } - - /* If V extends beyond PREC, ignore the part that does. - Note that this may make vsize negative. */ - if (vsize + ediff > prec) - { - vp += vsize + ediff - prec; - vsize = prec - ediff; - } - -#if 0 - /* Locate the least significant non-zero limb in (the needed parts - of) U and V, to simplify the code below. */ - while (up[0] == 0) - up++, usize--; - while (vp[0] == 0) - vp++, vsize--; -#endif - - /* Allocate temp space for the result. Allocate - just vsize + ediff later??? */ - tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB); - - if (ediff >= prec) - { - /* V completely cancelled. */ - if (tp != up) - MPN_COPY (rp, up, usize); - rsize = usize; - } - else - { - /* uuuu | uuuu | uuuu | uuuu | uuuu */ - /* vvvvvvv | vv | vvvvv | v | vv */ - - if (usize > ediff) - { - /* U and V partially overlaps. */ - if (vsize + ediff <= usize) - { - /* uuuu */ - /* v */ - mp_size_t size; - size = usize - ediff - vsize; - MPN_COPY (tp, up, size); - cy = mpn_add (tp + size, up + size, usize - size, vp, vsize); - rsize = usize; - } - else - { - /* uuuu */ - /* vvvvv */ - mp_size_t size; - size = vsize + ediff - usize; - MPN_COPY (tp, vp, size); - cy = mpn_add (tp + size, up, usize, vp + size, usize - ediff); - rsize = vsize + ediff; - } - } - else - { - /* uuuu */ - /* vv */ - mp_size_t size; - size = vsize + ediff - usize; - MPN_COPY (tp, vp, vsize); - MPN_ZERO (tp + vsize, ediff - usize); - MPN_COPY (tp + size, up, usize); - cy = 0; - rsize = size + usize; - } - - MPN_COPY (rp, tp, rsize); - rp[rsize] = cy; - rsize += cy; - uexp += cy; - } - - r->_mp_size = negate ? -rsize : rsize; - r->_mp_exp = uexp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/add_ui.c b/gmp/mpf/add_ui.c deleted file mode 100755 index aa485e6..0000000 --- a/gmp/mpf/add_ui.c +++ /dev/null @@ -1,151 +0,0 @@ -/* mpf_add_ui -- Add a float and an unsigned integer. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_add_ui (mpf_ptr sum, mpf_srcptr u, unsigned long int v) -#else -mpf_add_ui (sum, u, v) - mpf_ptr sum; - mpf_srcptr u; - unsigned long int v; -#endif -{ - mp_srcptr up = u->_mp_d; - mp_ptr sump = sum->_mp_d; - mp_size_t usize, sumsize; - mp_size_t prec = sum->_mp_prec; - mp_exp_t uexp = u->_mp_exp; - - usize = u->_mp_size; - if (usize <= 0) - { - if (usize == 0) - { - mpf_set_ui (sum, v); - return; - } - else - { - __mpf_struct u_negated; - u_negated._mp_size = -usize; - u_negated._mp_exp = u->_mp_exp; - u_negated._mp_d = u->_mp_d; - mpf_sub_ui (sum, &u_negated, v); - sum->_mp_size = -(sum->_mp_size); - return; - } - } - - if (v == 0) - { - sum_is_u: - if (u != sum) - { - sumsize = MIN (usize, prec + 1); - MPN_COPY (sum->_mp_d, up + usize - sumsize, sumsize); - sum->_mp_size = sumsize; - sum->_mp_exp = u->_mp_exp; - } - return; - } - - if (uexp > 0) - { - /* U >= 1. */ - if (uexp > prec) - { - /* U >> V, V is not part of final result. */ - goto sum_is_u; - } - else - { - /* U's "limb point" is somewhere between the first limb - and the PREC:th limb. - Both U and V are part of the final result. */ - if (uexp > usize) - { - /* uuuuuu0000. */ - /* + v. */ - /* We begin with moving U to the top of SUM, to handle - samevar(U,SUM). */ - MPN_COPY_DECR (sump + uexp - usize, up, usize); - sump[0] = v; - MPN_ZERO (sump + 1, uexp - usize - 1); -#if 0 /* What is this??? */ - if (sum == u) - MPN_COPY (sum->_mp_d, sump, uexp); -#endif - sum->_mp_size = uexp; - sum->_mp_exp = uexp; - } - else - { - /* uuuuuu.uuuu */ - /* + v. */ - mp_limb_t cy_limb; - if (usize > prec) - { - /* Ignore excess limbs in U. */ - up += usize - prec; - usize -= usize - prec; /* Eq. usize = prec */ - } - if (sump != up) - MPN_COPY (sump, up, usize - uexp); - cy_limb = mpn_add_1 (sump + usize - uexp, up + usize - uexp, - uexp, (mp_limb_t) v); - sump[usize] = cy_limb; - sum->_mp_size = usize + cy_limb; - sum->_mp_exp = uexp + cy_limb; - } - } - } - else - { - /* U < 1, so V > U for sure. */ - /* v. */ - /* .0000uuuu */ - if ((-uexp) >= prec) - { - sump[0] = v; - sum->_mp_size = 1; - sum->_mp_exp = 1; - } - else - { - if (usize + (-uexp) + 1 > prec) - { - /* Ignore excess limbs in U. */ - up += usize + (-uexp) + 1 - prec; - usize -= usize + (-uexp) + 1 - prec; - } - if (sump != up) - MPN_COPY (sump, up, usize); - MPN_ZERO (sump + usize, -uexp); - sump[usize + (-uexp)] = v; - sum->_mp_size = usize + (-uexp) + 1; - sum->_mp_exp = 1; - } - } -} diff --git a/gmp/mpf/clear.c b/gmp/mpf/clear.c deleted file mode 100755 index 3370e2c..0000000 --- a/gmp/mpf/clear.c +++ /dev/null @@ -1,35 +0,0 @@ -/* mpf_clear -- de-allocate the space occupied by the dynamic digit space of - an integer. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_clear (mpf_ptr m) -#else -mpf_clear (m) - mpf_ptr m; -#endif -{ - (*_mp_free_func) (m->_mp_d, (m->_mp_prec + 1) * BYTES_PER_MP_LIMB); -} diff --git a/gmp/mpf/cmp.c b/gmp/mpf/cmp.c deleted file mode 100755 index 750614e..0000000 --- a/gmp/mpf/cmp.c +++ /dev/null @@ -1,114 +0,0 @@ -/* mpf_cmp -- Compare two floats. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpf_cmp (mpf_srcptr u, mpf_srcptr v) -#else -mpf_cmp (u, v) - mpf_srcptr u; - mpf_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_size_t usize, vsize; - mp_exp_t uexp, vexp; - int cmp; - int usign; - - uexp = u->_mp_exp; - vexp = v->_mp_exp; - - usize = u->_mp_size; - vsize = v->_mp_size; - - /* 1. Are the signs different? */ - if ((usize ^ vsize) >= 0) - { - /* U and V are both non-negative or both negative. */ - if (usize == 0) - /* vsize >= 0 */ - return -(vsize != 0); - if (vsize == 0) - /* usize >= 0 */ - return usize != 0; - /* Fall out. */ - } - else - { - /* Either U or V is negative, but not both. */ - return usize >= 0 ? 1 : -1; - } - - /* U and V have the same sign and are both non-zero. */ - - usign = usize >= 0 ? 1 : -1; - - /* 2. Are the exponents different? */ - if (uexp > vexp) - return usign; - if (uexp < vexp) - return -usign; - - usize = ABS (usize); - vsize = ABS (vsize); - - up = u->_mp_d; - vp = v->_mp_d; - -#define STRICT_MPF_NORMALIZATION 0 -#if ! STRICT_MPF_NORMALIZATION - /* Ignore zeroes at the low end of U and V. */ - while (up[0] == 0) - { - up++; - usize--; - } - while (vp[0] == 0) - { - vp++; - vsize--; - } -#endif - - if (usize > vsize) - { - cmp = mpn_cmp (up + usize - vsize, vp, vsize); - if (cmp == 0) - return usign; - } - else if (vsize > usize) - { - cmp = mpn_cmp (up, vp + vsize - usize, usize); - if (cmp == 0) - return -usign; - } - else - { - cmp = mpn_cmp (up, vp, usize); - if (cmp == 0) - return 0; - } - return cmp > 0 ? usign : -usign; -} diff --git a/gmp/mpf/cmp_si.c b/gmp/mpf/cmp_si.c deleted file mode 100755 index 8d5d2d1..0000000 --- a/gmp/mpf/cmp_si.c +++ /dev/null @@ -1,98 +0,0 @@ -/* mpf_cmp_si -- Compare a float with a signed integer. - -Copyright (C) 1993, 1994, 1995, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpf_cmp_si (mpf_srcptr u, long int vslimb) -#else -mpf_cmp_si (u, vslimb) - mpf_srcptr u; - long int vslimb; -#endif -{ - mp_srcptr up; - mp_size_t usize; - mp_exp_t uexp; - int usign; - - uexp = u->_mp_exp; - usize = u->_mp_size; - - /* 1. Are the signs different? */ - if ((usize < 0) == (vslimb < 0)) /* don't use xor, type size may differ */ - { - /* U and V are both non-negative or both negative. */ - if (usize == 0) - /* vslimb >= 0 */ - return -(vslimb != 0); - if (vslimb == 0) - /* usize >= 0 */ - return usize != 0; - /* Fall out. */ - } - else - { - /* Either U or V is negative, but not both. */ - return usize >= 0 ? 1 : -1; - } - - /* U and V have the same sign and are both non-zero. */ - - usign = usize >= 0 ? 1 : -1; - - /* 2. Are the exponents different (V's exponent == 1)? */ - if (uexp > 1) - return usign; - if (uexp < 1) - return -usign; - - usize = ABS (usize); - vslimb = ABS (vslimb); - - up = u->_mp_d; - - /* 3. Compare the most significant mantissa limb with V. */ - if (up[usize - 1] > (unsigned long) vslimb) - return usign; - else if (up[usize - 1] < (unsigned long) vslimb) - return -usign; - -#define STRICT_MPF_NORMALIZATION 0 -#if ! STRICT_MPF_NORMALIZATION - /* Ignore zeroes at the low end of U. */ - while (*up == 0) - { - up++; - usize--; - } -#endif - - /* 4. Now, if the number of limbs are different, we have a difference - since we have made sure the trailing limbs are not zero. */ - if (usize > 1) - return usign; - - /* Wow, we got zero even if we tried hard to avoid it. */ - return 0; -} diff --git a/gmp/mpf/cmp_ui.c b/gmp/mpf/cmp_ui.c deleted file mode 100755 index 5d97460..0000000 --- a/gmp/mpf/cmp_ui.c +++ /dev/null @@ -1,80 +0,0 @@ -/* mpf_cmp_ui -- Compare a float with an unsigned integer. - -Copyright (C) 1993, 1994, 1995, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpf_cmp_ui (mpf_srcptr u, unsigned long int vlimb) -#else -mpf_cmp_ui (u, vlimb) - mpf_srcptr u; - unsigned long int vlimb; -#endif -{ - mp_srcptr up; - mp_size_t usize; - mp_exp_t uexp; - - uexp = u->_mp_exp; - usize = u->_mp_size; - - /* 1. Is U negative? */ - if (usize < 0) - return -1; - /* We rely on usize being non-negative in the code that follows. */ - - if (vlimb == 0) - return usize != 0; - - /* 2. Are the exponents different (V's exponent == 1)? */ - if (uexp > 1) - return 1; - if (uexp < 1) - return -1; - - up = u->_mp_d; - - /* 3. Compare the most significant mantissa limb with V. */ - if (up[usize - 1] > vlimb) - return 1; - else if (up[usize - 1] < vlimb) - return -1; - -#define STRICT_MPF_NORMALIZATION 0 -#if ! STRICT_MPF_NORMALIZATION - /* Ignore zeroes at the low end of U. */ - while (*up == 0) - { - up++; - usize--; - } -#endif - - /* 4. Now, if the number of limbs are different, we have a difference - since we have made sure the trailing limbs are not zero. */ - if (usize > 1) - return 1; - - /* Wow, we got zero even if we tried hard to avoid it. */ - return 0; -} diff --git a/gmp/mpf/div.c b/gmp/mpf/div.c deleted file mode 100755 index 00c5e51..0000000 --- a/gmp/mpf/div.c +++ /dev/null @@ -1,145 +0,0 @@ -/* mpf_div -- Divide two floats. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpf_div (mpf_ptr r, mpf_srcptr u, mpf_srcptr v) -#else -mpf_div (r, u, v) - mpf_ptr r; - mpf_srcptr u; - mpf_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_ptr rp, tp, rtp; - mp_size_t usize, vsize; - mp_size_t rsize, tsize; - mp_size_t sign_quotient; - mp_size_t prec; - unsigned normalization_steps; - mp_limb_t q_limb; - mp_exp_t rexp; - TMP_DECL (marker); - - usize = u->_mp_size; - vsize = v->_mp_size; - sign_quotient = usize ^ vsize; - usize = ABS (usize); - vsize = ABS (vsize); - prec = r->_mp_prec; - - if (vsize == 0) - DIVIDE_BY_ZERO; - - if (usize == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - TMP_MARK (marker); - rexp = u->_mp_exp - v->_mp_exp; - - rp = r->_mp_d; - up = u->_mp_d; - vp = v->_mp_d; - - if (vsize > prec) - { - vp += vsize - prec; - vsize = prec; - } - - tsize = vsize + prec; - tp = (mp_ptr) TMP_ALLOC ((tsize + 1) * BYTES_PER_MP_LIMB); - - if (usize > tsize) - { - up += usize - tsize; - usize = tsize; - rtp = tp; - } - else - { - MPN_ZERO (tp, tsize - usize); - rtp = tp + (tsize - usize); - } - - count_leading_zeros (normalization_steps, vp[vsize - 1]); - - /* Normalize the divisor and the dividend. */ - if (normalization_steps != 0) - { - mp_ptr tmp; - mp_limb_t nlimb; - - /* Shift up the divisor setting the most significant bit of - the most significant limb. Use temporary storage not to clobber - the original contents of the divisor. */ - tmp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - mpn_lshift (tmp, vp, vsize, normalization_steps); - vp = tmp; - - /* Shift up the dividend, possibly introducing a new most - significant word. Move the shifted dividend in the remainder - at the same time. */ - nlimb = mpn_lshift (rtp, up, usize, normalization_steps); - if (nlimb != 0) - { - rtp[usize] = nlimb; - tsize++; - rexp++; - } - } - else - { - /* The divisor is already normalized, as required. - Copy it to temporary space if it overlaps with the quotient. */ - if (vp - rp <= tsize - vsize) - { - mp_ptr tmp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - MPN_COPY (tmp, vp, vsize); - vp = (mp_srcptr) tmp; - } - - /* Move the dividend to the remainder. */ - MPN_COPY (rtp, up, usize); - } - - q_limb = mpn_divmod (rp, tp, tsize, vp, vsize); - rsize = tsize - vsize; - if (q_limb) - { - rp[rsize] = q_limb; - rsize++; - rexp++; - } - - r->_mp_size = sign_quotient >= 0 ? rsize : -rsize; - r->_mp_exp = rexp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/div_2exp.c b/gmp/mpf/div_2exp.c deleted file mode 100755 index 2f20755..0000000 --- a/gmp/mpf/div_2exp.c +++ /dev/null @@ -1,93 +0,0 @@ -/* mpf_div_2exp -- Divide a float by 2^n. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_div_2exp (mpf_ptr r, mpf_srcptr u, unsigned long int exp) -#else -mpf_div_2exp (r, u, exp) - mpf_ptr r; - mpf_srcptr u; - unsigned long int exp; -#endif -{ - mp_srcptr up; - mp_ptr rp = r->_mp_d; - mp_size_t usize; - mp_size_t abs_usize; - mp_size_t prec = r->_mp_prec; - mp_exp_t uexp = u->_mp_exp; - - usize = u->_mp_size; - - if (usize == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - abs_usize = ABS (usize); - up = u->_mp_d; - - if (exp % BITS_PER_MP_LIMB == 0) - { - prec++; /* retain more precision here as we don't need - to account for carry-out here */ - if (abs_usize > prec) - { - up += abs_usize - prec; - abs_usize = prec; - } - if (rp != up) - MPN_COPY_INCR (rp, up, abs_usize); - r->_mp_exp = uexp - exp / BITS_PER_MP_LIMB; - } - else - { - mp_limb_t cy_limb; - mp_size_t adj; - if (abs_usize > prec) - { - up += abs_usize - prec; - abs_usize = prec; - /* Use mpn_rshift since mpn_lshift operates downwards, and we - therefore would clobber part of U before using that part, in case - R is the same variable as U. */ - cy_limb = mpn_rshift (rp + 1, up, abs_usize, exp % BITS_PER_MP_LIMB); - rp[0] = cy_limb; - adj = rp[abs_usize] != 0; - } - else - { - cy_limb = mpn_lshift (rp, up, abs_usize, (-exp) % BITS_PER_MP_LIMB); - rp[abs_usize] = cy_limb; - adj = cy_limb != 0; - } - - abs_usize += adj; - r->_mp_exp = uexp - exp / BITS_PER_MP_LIMB - 1 + adj; - } - r->_mp_size = usize >= 0 ? abs_usize : -abs_usize; -} diff --git a/gmp/mpf/div_ui.c b/gmp/mpf/div_ui.c deleted file mode 100755 index 515c14f..0000000 --- a/gmp/mpf/div_ui.c +++ /dev/null @@ -1,92 +0,0 @@ -/* mpf_div_ui -- Divide a float with an unsigned integer. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpf_div_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v) -#else -mpf_div_ui (r, u, v) - mpf_ptr r; - mpf_srcptr u; - unsigned long int v; -#endif -{ - mp_srcptr up; - mp_ptr rp, tp, rtp; - mp_size_t usize; - mp_size_t rsize, tsize; - mp_size_t sign_quotient; - mp_size_t prec; - mp_limb_t q_limb; - mp_exp_t rexp; - TMP_DECL (marker); - - usize = u->_mp_size; - sign_quotient = usize; - usize = ABS (usize); - prec = r->_mp_prec; - - if (v == 0) - DIVIDE_BY_ZERO; - - if (usize == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - TMP_MARK (marker); - - rp = r->_mp_d; - up = u->_mp_d; - - tsize = 1 + prec; - tp = (mp_ptr) TMP_ALLOC ((tsize + 1) * BYTES_PER_MP_LIMB); - - if (usize > tsize) - { - up += usize - tsize; - usize = tsize; - rtp = tp; - } - else - { - MPN_ZERO (tp, tsize - usize); - rtp = tp + (tsize - usize); - } - - /* Move the dividend to the remainder. */ - MPN_COPY (rtp, up, usize); - - mpn_divmod_1 (rp, tp, tsize, (mp_limb_t) v); - q_limb = rp[tsize - 1]; - - rsize = tsize - (q_limb == 0); - rexp = u->_mp_exp - (q_limb == 0); - r->_mp_size = sign_quotient >= 0 ? rsize : -rsize; - r->_mp_exp = rexp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/dump.c b/gmp/mpf/dump.c deleted file mode 100755 index bebef7c..0000000 --- a/gmp/mpf/dump.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mpf_dump -- Dump a float to stdout. - - THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS NOT SAFE TO - CALL THIS FUNCTION DIRECTLY. IN FACT, IT IS ALMOST GUARANTEED THAT THIS - FUNCTION WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. - - -Copyright (C) 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_dump (mpf_srcptr u) -#else -mpf_dump (u) - mpf_srcptr u; -#endif -{ - mp_exp_t exp; - char *str; - - str = mpf_get_str (0, &exp, 10, 0, u); - if (str[0] == '-') - printf ("-0.%se%ld\n", str + 1, exp); - else - printf ("0.%se%ld\n", str, exp); - (*_mp_free_func) (str, 0);/* ??? broken alloc interface, pass what size ??? */ -} diff --git a/gmp/mpf/eq.c b/gmp/mpf/eq.c deleted file mode 100755 index e12be7b..0000000 --- a/gmp/mpf/eq.c +++ /dev/null @@ -1,121 +0,0 @@ -/* mpf_eq -- Compare two floats up to a specified bit #. - -Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits) -#else -mpf_eq (u, v, n_bits) - mpf_srcptr u; - mpf_srcptr v; - unsigned long int n_bits; -#endif -{ - mp_srcptr up, vp; - mp_size_t usize, vsize, size, i; - mp_exp_t uexp, vexp; - int usign; - - uexp = u->_mp_exp; - vexp = v->_mp_exp; - - usize = u->_mp_size; - vsize = v->_mp_size; - - /* 1. Are the signs different? */ - if ((usize ^ vsize) >= 0) - { - /* U and V are both non-negative or both negative. */ - if (usize == 0) - return vsize == 0; - if (vsize == 0) - return 0; - - /* Fall out. */ - } - else - { - /* Either U or V is negative, but not both. */ - return 0; - } - - /* U and V have the same sign and are both non-zero. */ - - usign = usize >= 0 ? 1 : -1; - - /* 2. Are the exponents different? */ - if (uexp > vexp) - return 0; /* ??? handle (uexp = vexp + 1) */ - if (vexp > uexp) - return 0; /* ??? handle (vexp = uexp + 1) */ - - usize = ABS (usize); - vsize = ABS (vsize); - - up = u->_mp_d; - vp = v->_mp_d; - - /* Ignore zeroes at the low end of U and V. */ - while (up[0] == 0) - { - up++; - usize--; - } - while (vp[0] == 0) - { - vp++; - vsize--; - } - - if (usize > vsize) - { - if (vsize * BITS_PER_MP_LIMB < n_bits) - return 0; /* surely too different */ - size = vsize; - } - else if (vsize > usize) - { - if (usize * BITS_PER_MP_LIMB < n_bits) - return 0; /* surely too different */ - size = usize; - } - else - { - size = usize; - } - - if (size > (n_bits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB) - size = (n_bits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - - up += usize - size; - vp += vsize - size; - - for (i = size - 1; i >= 0; i--) - { - if (up[i] != vp[i]) - return 0; - } - - return 1; -} diff --git a/gmp/mpf/get_d.c b/gmp/mpf/get_d.c deleted file mode 100755 index 4352803..0000000 --- a/gmp/mpf/get_d.c +++ /dev/null @@ -1,54 +0,0 @@ -/* double mpf_get_d (mpf_t src) -- Return the double approximation to SRC. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -double -#if __STDC__ -mpf_get_d (mpf_srcptr src) -#else -mpf_get_d (src) - mpf_srcptr src; -#endif -{ - double res; - mp_size_t size, i, n_limbs_to_use; - int negative; - mp_ptr qp; - - size = SIZ(src); - if (size == 0) - return 0.0; - - negative = size < 0; - size = ABS (size); - qp = PTR(src); - - res = qp[size - 1]; - n_limbs_to_use = MIN (LIMBS_PER_DOUBLE, size); - for (i = 2; i <= n_limbs_to_use; i++) - res = res * MP_BASE_AS_DOUBLE + qp[size - i]; - - res = __gmp_scale2 (res, (EXP(src) - n_limbs_to_use) * BITS_PER_MP_LIMB); - - return negative ? -res : res; -} diff --git a/gmp/mpf/get_prc.c b/gmp/mpf/get_prc.c deleted file mode 100755 index 9e7d5f9..0000000 --- a/gmp/mpf/get_prc.c +++ /dev/null @@ -1,34 +0,0 @@ -/* mpf_get_prec(x) -- Return the precision in bits of x. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpf_get_prec (mpf_srcptr x) -#else -mpf_get_prec (x) - mpf_srcptr x; -#endif -{ - return (unsigned long int) x->_mp_prec * BITS_PER_MP_LIMB - BITS_PER_MP_LIMB; -} diff --git a/gmp/mpf/get_str.c b/gmp/mpf/get_str.c deleted file mode 100755 index a9c6551..0000000 --- a/gmp/mpf/get_str.c +++ /dev/null @@ -1,431 +0,0 @@ -/* mpf_get_str (digit_ptr, exp, base, n_digits, a) -- Convert the floating - point number A to a base BASE number and store N_DIGITS raw digits at - DIGIT_PTR, and the base BASE exponent in the word pointed to by EXP. For - example, the number 3.1416 would be returned as "31416" in DIGIT_PTR and - 1 in EXP. - -Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* - The conversion routine works like this: - - 1. If U >= 1, compute U' = U / base**n, where n is chosen such that U' is - the largest number smaller than 1. - 2. Else, if U < 1, compute U' = U * base**n, where n is chosen such that U' - is the largest number smaller than 1. - 3. Convert U' (by repeatedly multiplying it by base). This process can - easily be interrupted when the needed number of digits are generated. -*/ - -char * -#if __STDC__ -mpf_get_str (char *digit_ptr, mp_exp_t *exp, int base, size_t n_digits, mpf_srcptr u) -#else -mpf_get_str (digit_ptr, exp, base, n_digits, u) - char *digit_ptr; - mp_exp_t *exp; - int base; - size_t n_digits; - mpf_srcptr u; -#endif -{ - mp_ptr up; - mp_size_t usize; - mp_exp_t uexp; - mp_size_t prec; - unsigned char *str; - char *num_to_text; - mp_ptr rp; - mp_size_t rsize; - mp_limb_t big_base; - size_t digits_computed_so_far; - int dig_per_u; - unsigned char *tstr; - mp_exp_t exp_in_base; - int cnt; - TMP_DECL (marker); - - TMP_MARK (marker); - usize = u->_mp_size; - uexp = u->_mp_exp; - prec = u->_mp_prec + 1; - - if (base >= 0) - { - if (base == 0) - base = 10; - num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz"; - } - else - { - base = -base; - num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - } - - /* Don't compute more digits than U can accurately represent. - Also, if 0 digits were requested, give *exactly* as many digits - as can be accurately represented. */ - { - size_t max_digits = 2 + (size_t) (((prec - 2) * BITS_PER_MP_LIMB) - * __mp_bases[base].chars_per_bit_exactly); - if (n_digits == 0 || n_digits > max_digits) - n_digits = max_digits; -#if 0 -/* This seems to work, but check it better before enabling it. */ - else - /* Limit the computation precision if only a limited digits are - desired. We could probably decrease both this, and avoid the +1 - for setting prec above. */ - prec = 2 + (mp_size_t) - (n_digits / (BITS_PER_MP_LIMB * __mp_bases[base].chars_per_bit_exactly)); -#endif - } - - if (digit_ptr == 0) - { - /* We didn't get a string from the user. Allocate one (and return - a pointer to it) with space for `-' and terminating null. */ - digit_ptr = (char *) (*_mp_allocate_func) (n_digits + 2); - } - - if (usize == 0) - { - *exp = 0; - *digit_ptr = 0; - return digit_ptr; - } - - str = (unsigned char *) digit_ptr; - - if (usize < 0) - { - *digit_ptr = '-'; - str++; - usize = -usize; - } - - up = PTR (u); - - if (uexp > 0) - { - /* U >= 1. Compute U' = U / base**n, where n is chosen such that U' < 1. */ - mp_size_t ralloc; - mp_ptr tp; - int i; - - /* Limit the number of digits to develop for small integers. */ -#if 0 - if (exp_in_base < n_digits) - n_digits = exp_in_base; -#endif - - count_leading_zeros (cnt, up[usize - 1]); - exp_in_base = (((double) uexp * BITS_PER_MP_LIMB - cnt) - * __mp_bases[base].chars_per_bit_exactly); - exp_in_base += 1; - - ralloc = (prec + 1) * 2; - rp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - tp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - - rp[0] = base; - rsize = 1; - count_leading_zeros (cnt, exp_in_base); - for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--) - { - mpn_mul_n (tp, rp, rp, rsize); - rsize = 2 * rsize; - rsize -= tp[rsize - 1] == 0; - - if (rsize > prec) - { - MPN_COPY (rp, tp + rsize - prec, prec + 1); - rsize = prec; - } - else - MP_PTR_SWAP (rp, tp); - - if (((exp_in_base >> i) & 1) != 0) - { - mp_limb_t cy; - cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base); - rp[rsize] = cy; - rsize += cy != 0; - } - } - - count_leading_zeros (cnt, rp[rsize - 1]); - if (cnt != 0) - { - mpn_lshift (rp, rp, rsize, cnt); - - if (usize < rsize) - { - /* Pad out U to the size of R while shifting it. - (Reuse temporary space at tp.) */ - mp_limb_t cy; - - MPN_ZERO (tp, rsize - usize); - cy = mpn_lshift (tp + rsize - usize, up, usize, cnt); - up = tp; - usize = rsize; - if (cy) - up[usize++] = cy; - ASSERT_ALWAYS (usize <= ralloc); /* sufficient space? */ - } - else - { - /* Copy U to temporary space. */ - /* FIXME: Allocate more space for tp above, and reuse it here. */ - mp_limb_t cy; - mp_ptr tup = (mp_ptr) TMP_ALLOC ((usize + 1) * BYTES_PER_MP_LIMB); - - cy = mpn_lshift (tup, up, usize, cnt); - up = tup; - if (cy) - up[usize++] = cy; - } - } - else - { - if (usize < rsize) - { - /* Pad out U to the size of R. (Reuse temporary space at tp.) */ - MPN_ZERO (tp, rsize - usize); - MPN_COPY (tp + rsize - usize, up, usize); - up = tp; - usize = rsize; - } - else - { - /* Copy U to temporary space. */ - mp_ptr tmp = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB); - MPN_COPY (tmp, up, usize); - up = tmp; - } - } - - { - mp_ptr qp; - qp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB); - mpn_divrem (qp, prec - (usize - rsize), up, usize, rp, rsize); - rsize = prec; - rp = qp; - } - } - else - { - /* U < 1. Compute U' = U * base**n, where n is chosen such that U' is - the greatest number that still satisfies U' < 1. */ - mp_size_t ralloc; - mp_ptr tp; - int i; - - uexp = -uexp; - count_leading_zeros (cnt, up[usize - 1]); - exp_in_base = (((double) uexp * BITS_PER_MP_LIMB + cnt - 1) - * __mp_bases[base].chars_per_bit_exactly); - if (exp_in_base < 0) - exp_in_base = 0; - - if (exp_in_base != 0) - { - ralloc = (prec + 1) * 2; - rp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - tp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - - rp[0] = base; - rsize = 1; - count_leading_zeros (cnt, exp_in_base); - for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--) - { - mpn_mul_n (tp, rp, rp, rsize); - rsize = 2 * rsize; - rsize -= tp[rsize - 1] == 0; - if (rsize > prec) - { - MPN_COPY (rp, tp + rsize - prec, prec + 1); - rsize = prec; - } - else - MP_PTR_SWAP (rp, tp); - - if (((exp_in_base >> i) & 1) != 0) - { - mp_limb_t cy; - cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base); - rp[rsize] = cy; - rsize += cy != 0; - } - } - - { - mp_limb_t cy; - tp = (mp_ptr) TMP_ALLOC ((rsize + usize) * BYTES_PER_MP_LIMB); - if (rsize > usize) - cy = mpn_mul (tp, rp, rsize, up, usize); - else - cy = mpn_mul (tp, up, usize, rp, rsize); - rsize += usize; - rsize -= cy == 0; - rp = tp; - } - exp_in_base = -exp_in_base; - } - else - { - rp = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB); - MPN_COPY (rp, up, usize); - rsize = usize; - } - } - - big_base = __mp_bases[base].big_base; - dig_per_u = __mp_bases[base].chars_per_limb; - - /* Hack for correctly (although not optimally) converting to bases that are - powers of 2. If we deem it important, we could handle powers of 2 by - shifting and masking (just like mpn_get_str). */ - if (big_base < 10) /* logarithm of base when power of two */ - { - int logbase = big_base; - if (dig_per_u * logbase == BITS_PER_MP_LIMB) - dig_per_u--; - big_base = (mp_limb_t) 1 << (dig_per_u * logbase); - /* fall out to general code... */ - } - - /* Now that we have normalized the number, develop the digits, essentially by - multiplying it by BASE. We initially develop at least 3 extra digits, - since the two leading digits might become zero, and we need one extra for - rounding the output properly. */ - - /* Allocate temporary digit space. We can't put digits directly in the user - area, since we generate more digits than requested. (We allocate - BITS_PER_MP_LIMB extra bytes because of the digit block nature of the - conversion.) */ - tstr = (unsigned char *) TMP_ALLOC (n_digits + BITS_PER_MP_LIMB + 3); - - for (digits_computed_so_far = 0; digits_computed_so_far < n_digits + 3; - digits_computed_so_far += dig_per_u) - { - mp_limb_t cy; - /* For speed: skip trailing zeroes. */ - if (rp[0] == 0) - { - rp++; - rsize--; - if (rsize == 0) - { - n_digits = digits_computed_so_far; - break; - } - } - - cy = mpn_mul_1 (rp, rp, rsize, big_base); - - ASSERT_ALWAYS (! (digits_computed_so_far == 0 && cy == 0)); - - /* Convert N1 from BIG_BASE to a string of digits in BASE - using single precision operations. */ - { - int i; - unsigned char *s = tstr + digits_computed_so_far + dig_per_u; - for (i = dig_per_u - 1; i >= 0; i--) - { - *--s = cy % base; - cy /= base; - } - } - } - - /* We can have at most two leading 0. Remove them. */ - if (tstr[0] == 0) - { - tstr++; - digits_computed_so_far--; - exp_in_base--; - - if (tstr[0] == 0) - { - tstr++; - digits_computed_so_far--; - exp_in_base--; - - if (tstr[0] == 0) - abort (); - } - } - - { - size_t i; - - /* We should normally have computed too many digits. Round the result - at the point indicated by n_digits. */ - if (digits_computed_so_far > n_digits) - { - /* Round the result. */ - if (tstr[n_digits] * 2 >= base) - { - digits_computed_so_far = n_digits; - for (i = n_digits - 1;; i--) - { - unsigned int x; - x = ++(tstr[i]); - if (x != base) - break; - digits_computed_so_far--; - if (i == 0) - { - /* We had something like `9999999...9d', where 2*d >= base. - This rounds up to `1', increasing the exponent. */ - tstr[0] = 1; - digits_computed_so_far = 1; - exp_in_base++; - break; - } - } - } - } - - /* We might have fewer digits than requested as a result of rounding above, - (i.e. 0.999999 => 1.0) or because we have a number that simply doesn't - need many digits in this base (i.e., 0.125 in base 10). */ - if (n_digits > digits_computed_so_far) - n_digits = digits_computed_so_far; - - /* Remove trailing 0. There can be many zeros. */ - while (n_digits != 0 && tstr[n_digits - 1] == 0) - n_digits--; - - /* Translate to ascii and null-terminate. */ - for (i = 0; i < n_digits; i++) - *str++ = num_to_text[tstr[i]]; - } - *str = 0; - *exp = exp_in_base; - TMP_FREE (marker); - return digit_ptr; -} diff --git a/gmp/mpf/init.c b/gmp/mpf/init.c deleted file mode 100755 index d558a43..0000000 --- a/gmp/mpf/init.c +++ /dev/null @@ -1,38 +0,0 @@ -/* mpf_init() -- Make a new multiple precision number with value 0. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_init (mpf_ptr r) -#else -mpf_init (r) - mpf_ptr r; -#endif -{ - mp_size_t prec = __gmp_default_fp_limb_precision; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - r->_mp_size = 0; - r->_mp_exp = 0; -} diff --git a/gmp/mpf/init2.c b/gmp/mpf/init2.c deleted file mode 100755 index 16e6090..0000000 --- a/gmp/mpf/init2.c +++ /dev/null @@ -1,41 +0,0 @@ -/* mpf_init2() -- Make a new multiple precision number with value 0. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_init2 (mpf_ptr r, unsigned long int prec_in_bits) -#else -mpf_init2 (r, prec_in_bits) - mpf_ptr r; - unsigned long int prec_in_bits; -#endif -{ - mp_size_t prec; - - prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - r->_mp_size = 0; - r->_mp_exp = 0; -} diff --git a/gmp/mpf/inp_str.c b/gmp/mpf/inp_str.c deleted file mode 100755 index 4d18162..0000000 --- a/gmp/mpf/inp_str.c +++ /dev/null @@ -1,89 +0,0 @@ -/* mpf_inp_str(dest_float, stream, base) -- Input a number in base - BASE from stdio stream STREAM and store the result in DEST_FLOAT. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpf_inp_str (mpf_ptr rop, FILE *stream, int base) -#else -mpf_inp_str (rop, stream, base) - mpf_ptr rop; - FILE *stream; - int base; -#endif -{ - char *str; - size_t alloc_size, str_size; - int c; - size_t retval; - size_t nread; - - if (stream == 0) - stream = stdin; - - alloc_size = 100; - str = (char *) (*_mp_allocate_func) (alloc_size); - str_size = 0; - nread = 0; - - /* Skip whitespace. */ - do - { - c = getc (stream); - nread++; - } - while (isspace (c)); - - for (;;) - { - if (str_size >= alloc_size) - { - size_t old_alloc_size = alloc_size; - alloc_size = alloc_size * 3 / 2; - str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); - } - if (c == EOF || isspace (c)) - break; - str[str_size++] = c; - c = getc (stream); - } - ungetc (c, stream); - - if (str_size >= alloc_size) - { - size_t old_alloc_size = alloc_size; - alloc_size = alloc_size * 3 / 2; - str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); - } - str[str_size] = 0; - - retval = mpf_set_str (rop, str, base); - if (retval == -1) - return 0; /* error */ - - (*_mp_free_func) (str, alloc_size); - return str_size + nread; -} diff --git a/gmp/mpf/integer.c b/gmp/mpf/integer.c deleted file mode 100755 index b4cb219..0000000 --- a/gmp/mpf/integer.c +++ /dev/null @@ -1,149 +0,0 @@ -/* mpf_trunc, mpf_floor, mpf_ceil -- Assign a float from another float while - rounding it to an integer. - -Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - - -#if defined (OPERATION_floor) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_floor -#define MPF_FLOOR 1 -#define MPF_CEIL 0 - -#elif defined (OPERATION_ceil) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_ceil -#define MPF_CEIL 1 -#define MPF_FLOOR 0 - -#elif defined (OPERATION_trunc) -#define FUNC_NAME mpf_trunc - -#else -Error, error, unrecognised OPERATION -#endif - - -#ifdef _MPF_FLOOR_OR_CEIL -static int -#if __STDC__ -mpn_zero_p (mp_ptr p, mp_size_t n) -#else -mpn_zero_p (p, n) - mp_ptr p; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - { - if (p[i] != 0) - return 0; - } - - return 1; -} -#endif - -void -#if __STDC__ -FUNC_NAME (mpf_ptr r, mpf_srcptr u) -#else -FUNC_NAME (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_ptr rp, up; - mp_size_t size, asize; - mp_size_t prec; - mp_size_t ignored_n; - mp_exp_t exp; - - size = u->_mp_size; - rp = r->_mp_d; - exp = u->_mp_exp; - - /* Single out the case where |u| < 1. */ - if (exp <= 0) - { -#ifdef _MPF_FLOOR_OR_CEIL - if ((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - { - rp[0] = 1; - r->_mp_size = MPF_FLOOR ? -1 : 1; - r->_mp_exp = 1; - return; - } -#endif - r->_mp_size = 0; - return; - } - - prec = r->_mp_prec /* + 1 */; - asize = ABS (size); - -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = 0; -#endif - up = u->_mp_d; - - if (asize > prec) - { -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = asize - prec; -#endif - up += asize - prec; - asize = prec; - } - - if (asize > exp) - { - long diff = asize - exp; -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n += diff; -#endif - up += diff; - asize = exp; - } - -#ifdef _MPF_FLOOR_OR_CEIL - if (((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - && ! mpn_zero_p (up - ignored_n, ignored_n)) - { - mp_limb_t cy; - cy = mpn_add_1 (rp, up, asize, (mp_limb_t) 1); - if (cy != 0) - { - rp[asize++] = cy; - exp++; - } - } - else -#endif - MPN_COPY_INCR (rp, up, asize); - - r->_mp_exp = exp; - r->_mp_size = size >= 0 ? asize : -asize; -} diff --git a/gmp/mpf/integerceil.c b/gmp/mpf/integerceil.c deleted file mode 100755 index f9b43d8..0000000 --- a/gmp/mpf/integerceil.c +++ /dev/null @@ -1,150 +0,0 @@ -/* mpf_trunc, mpf_floor, mpf_ceil -- Assign a float from another float while - rounding it to an integer. - -Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#define OPERATION_ceil - -#if defined (OPERATION_floor) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_floor -#define MPF_FLOOR 1 -#define MPF_CEIL 0 - -#elif defined (OPERATION_ceil) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_ceil -#define MPF_CEIL 1 -#define MPF_FLOOR 0 - -#elif defined (OPERATION_trunc) -#define FUNC_NAME mpf_trunc - -#else -Error, error, unrecognised OPERATION -#endif - - -#ifdef _MPF_FLOOR_OR_CEIL -static int -#if __STDC__ -mpn_zero_p (mp_ptr p, mp_size_t n) -#else -mpn_zero_p (p, n) - mp_ptr p; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - { - if (p[i] != 0) - return 0; - } - - return 1; -} -#endif - -void -#if __STDC__ -FUNC_NAME (mpf_ptr r, mpf_srcptr u) -#else -FUNC_NAME (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_ptr rp, up; - mp_size_t size, asize; - mp_size_t prec; - mp_size_t ignored_n; - mp_exp_t exp; - - size = u->_mp_size; - rp = r->_mp_d; - exp = u->_mp_exp; - - /* Single out the case where |u| < 1. */ - if (exp <= 0) - { -#ifdef _MPF_FLOOR_OR_CEIL - if ((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - { - rp[0] = 1; - r->_mp_size = MPF_FLOOR ? -1 : 1; - r->_mp_exp = 1; - return; - } -#endif - r->_mp_size = 0; - return; - } - - prec = r->_mp_prec /* + 1 */; - asize = ABS (size); - -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = 0; -#endif - up = u->_mp_d; - - if (asize > prec) - { -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = asize - prec; -#endif - up += asize - prec; - asize = prec; - } - - if (asize > exp) - { - long diff = asize - exp; -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n += diff; -#endif - up += diff; - asize = exp; - } - -#ifdef _MPF_FLOOR_OR_CEIL - if (((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - && ! mpn_zero_p (up - ignored_n, ignored_n)) - { - mp_limb_t cy; - cy = mpn_add_1 (rp, up, asize, (mp_limb_t) 1); - if (cy != 0) - { - rp[asize++] = cy; - exp++; - } - } - else -#endif - MPN_COPY_INCR (rp, up, asize); - - r->_mp_exp = exp; - r->_mp_size = size >= 0 ? asize : -asize; -} diff --git a/gmp/mpf/integerfloor.c b/gmp/mpf/integerfloor.c deleted file mode 100755 index 0a45509..0000000 --- a/gmp/mpf/integerfloor.c +++ /dev/null @@ -1,151 +0,0 @@ -/* mpf_trunc, mpf_floor, mpf_ceil -- Assign a float from another float while - rounding it to an integer. - -Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - - -#define OPERATION_floor - -#if defined (OPERATION_floor) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_floor -#define MPF_FLOOR 1 -#define MPF_CEIL 0 - -#elif defined (OPERATION_ceil) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_ceil -#define MPF_CEIL 1 -#define MPF_FLOOR 0 - -#elif defined (OPERATION_trunc) -#define FUNC_NAME mpf_trunc - -#else -Error, error, unrecognised OPERATION -#endif - - -#ifdef _MPF_FLOOR_OR_CEIL -static int -#if __STDC__ -mpn_zero_p (mp_ptr p, mp_size_t n) -#else -mpn_zero_p (p, n) - mp_ptr p; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - { - if (p[i] != 0) - return 0; - } - - return 1; -} -#endif - -void -#if __STDC__ -FUNC_NAME (mpf_ptr r, mpf_srcptr u) -#else -FUNC_NAME (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_ptr rp, up; - mp_size_t size, asize; - mp_size_t prec; - mp_size_t ignored_n; - mp_exp_t exp; - - size = u->_mp_size; - rp = r->_mp_d; - exp = u->_mp_exp; - - /* Single out the case where |u| < 1. */ - if (exp <= 0) - { -#ifdef _MPF_FLOOR_OR_CEIL - if ((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - { - rp[0] = 1; - r->_mp_size = MPF_FLOOR ? -1 : 1; - r->_mp_exp = 1; - return; - } -#endif - r->_mp_size = 0; - return; - } - - prec = r->_mp_prec /* + 1 */; - asize = ABS (size); - -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = 0; -#endif - up = u->_mp_d; - - if (asize > prec) - { -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = asize - prec; -#endif - up += asize - prec; - asize = prec; - } - - if (asize > exp) - { - long diff = asize - exp; -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n += diff; -#endif - up += diff; - asize = exp; - } - -#ifdef _MPF_FLOOR_OR_CEIL - if (((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - && ! mpn_zero_p (up - ignored_n, ignored_n)) - { - mp_limb_t cy; - cy = mpn_add_1 (rp, up, asize, (mp_limb_t) 1); - if (cy != 0) - { - rp[asize++] = cy; - exp++; - } - } - else -#endif - MPN_COPY_INCR (rp, up, asize); - - r->_mp_exp = exp; - r->_mp_size = size >= 0 ? asize : -asize; -} diff --git a/gmp/mpf/integertrunc.c b/gmp/mpf/integertrunc.c deleted file mode 100755 index f25d438..0000000 --- a/gmp/mpf/integertrunc.c +++ /dev/null @@ -1,151 +0,0 @@ -/* mpf_trunc, mpf_floor, mpf_ceil -- Assign a float from another float while - rounding it to an integer. - -Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - - -#define OPERATION_trunc - -#if defined (OPERATION_floor) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_floor -#define MPF_FLOOR 1 -#define MPF_CEIL 0 - -#elif defined (OPERATION_ceil) -#define _MPF_FLOOR_OR_CEIL -#define FUNC_NAME mpf_ceil -#define MPF_CEIL 1 -#define MPF_FLOOR 0 - -#elif defined (OPERATION_trunc) -#define FUNC_NAME mpf_trunc - -#else -Error, error, unrecognised OPERATION -#endif - - -#ifdef _MPF_FLOOR_OR_CEIL -static int -#if __STDC__ -mpn_zero_p (mp_ptr p, mp_size_t n) -#else -mpn_zero_p (p, n) - mp_ptr p; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - { - if (p[i] != 0) - return 0; - } - - return 1; -} -#endif - -void -#if __STDC__ -FUNC_NAME (mpf_ptr r, mpf_srcptr u) -#else -FUNC_NAME (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_ptr rp, up; - mp_size_t size, asize; - mp_size_t prec; - mp_size_t ignored_n; - mp_exp_t exp; - - size = u->_mp_size; - rp = r->_mp_d; - exp = u->_mp_exp; - - /* Single out the case where |u| < 1. */ - if (exp <= 0) - { -#ifdef _MPF_FLOOR_OR_CEIL - if ((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - { - rp[0] = 1; - r->_mp_size = MPF_FLOOR ? -1 : 1; - r->_mp_exp = 1; - return; - } -#endif - r->_mp_size = 0; - return; - } - - prec = r->_mp_prec /* + 1 */; - asize = ABS (size); - -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = 0; -#endif - up = u->_mp_d; - - if (asize > prec) - { -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n = asize - prec; -#endif - up += asize - prec; - asize = prec; - } - - if (asize > exp) - { - long diff = asize - exp; -#ifdef _MPF_FLOOR_OR_CEIL - ignored_n += diff; -#endif - up += diff; - asize = exp; - } - -#ifdef _MPF_FLOOR_OR_CEIL - if (((MPF_FLOOR && size < 0) || (MPF_CEIL && size >= 0)) - && ! mpn_zero_p (up - ignored_n, ignored_n)) - { - mp_limb_t cy; - cy = mpn_add_1 (rp, up, asize, (mp_limb_t) 1); - if (cy != 0) - { - rp[asize++] = cy; - exp++; - } - } - else -#endif - MPN_COPY_INCR (rp, up, asize); - - r->_mp_exp = exp; - r->_mp_size = size >= 0 ? asize : -asize; -} diff --git a/gmp/mpf/iset.c b/gmp/mpf/iset.c deleted file mode 100755 index 9a91b5d..0000000 --- a/gmp/mpf/iset.c +++ /dev/null @@ -1,59 +0,0 @@ -/* mpf_init_set -- Initialize a float and assign it from another float. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_init_set (mpf_ptr r, mpf_srcptr s) -#else -mpf_init_set (r, s) - mpf_ptr r; - mpf_srcptr s; -#endif -{ - mp_ptr rp, sp; - mp_size_t ssize, size; - mp_size_t prec; - - prec = __gmp_default_fp_limb_precision; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - - prec++; /* lie not to lose precision in assignment */ - ssize = s->_mp_size; - size = ABS (ssize); - - rp = r->_mp_d; - sp = s->_mp_d; - - if (size > prec) - { - sp += size - prec; - size = prec; - } - - MPN_COPY (rp, sp, size); - - r->_mp_exp = s->_mp_exp; - r->_mp_size = ssize >= 0 ? size : -size; -} diff --git a/gmp/mpf/iset_d.c b/gmp/mpf/iset_d.c deleted file mode 100755 index fec390e..0000000 --- a/gmp/mpf/iset_d.c +++ /dev/null @@ -1,39 +0,0 @@ -/* mpf_init_set_d -- Initialize a float and assign it from a double. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_init_set_d (mpf_ptr r, double val) -#else -mpf_init_set_d (r, val) - mpf_ptr r; - double val; -#endif -{ - mp_size_t prec = __gmp_default_fp_limb_precision; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - - mpf_set_d (r, val); -} diff --git a/gmp/mpf/iset_si.c b/gmp/mpf/iset_si.c deleted file mode 100755 index 3c18e9d..0000000 --- a/gmp/mpf/iset_si.c +++ /dev/null @@ -1,55 +0,0 @@ -/* mpf_init_set_si() -- Initialize a float and assign it from a signed int. - -Copyright (C) 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_init_set_si (mpf_ptr r, long int val) -#else -mpf_init_set_si (r, val) - mpf_ptr r; - long int val; -#endif -{ - mp_size_t prec = __gmp_default_fp_limb_precision; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - - if (val > 0) - { - r->_mp_d[0] = val; - r->_mp_size = 1; - r->_mp_exp = 1; - } - else if (val < 0) - { - r->_mp_d[0] = (unsigned long) -val; - r->_mp_size = -1; - r->_mp_exp = 1; - } - else - { - r->_mp_size = 0; - r->_mp_exp = 0; - } -} diff --git a/gmp/mpf/iset_str.c b/gmp/mpf/iset_str.c deleted file mode 100755 index 7aefc57..0000000 --- a/gmp/mpf/iset_str.c +++ /dev/null @@ -1,42 +0,0 @@ -/* mpf_init_set_str -- Initialize a float and assign it from a string. - -Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpf_init_set_str (mpf_ptr r, const char *s, int base) -#else -mpf_init_set_str (r, s, base) - mpf_ptr r; - const char *s; - int base; -#endif -{ - mp_size_t prec = __gmp_default_fp_limb_precision; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - r->_mp_size = 0; - r->_mp_exp = 0; - - return mpf_set_str (r, s, base); -} diff --git a/gmp/mpf/iset_ui.c b/gmp/mpf/iset_ui.c deleted file mode 100755 index 5817d40..0000000 --- a/gmp/mpf/iset_ui.c +++ /dev/null @@ -1,40 +0,0 @@ -/* mpf_init_set_ui() -- Initialize a float and assign it from an unsigned int. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_init_set_ui (mpf_ptr r, unsigned long int val) -#else -mpf_init_set_ui (r, val) - mpf_ptr r; - unsigned long int val; -#endif -{ - mp_size_t prec = __gmp_default_fp_limb_precision; - r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB); - r->_mp_prec = prec; - r->_mp_d[0] = val; - r->_mp_size = val != 0; - r->_mp_exp = val != 0; -} diff --git a/gmp/mpf/mul.c b/gmp/mpf/mul.c deleted file mode 100755 index 1e52187..0000000 --- a/gmp/mpf/mul.c +++ /dev/null @@ -1,94 +0,0 @@ -/* mpf_mul -- Multiply two floats. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_mul (mpf_ptr r, mpf_srcptr u, mpf_srcptr v) -#else -mpf_mul (r, u, v) - mpf_ptr r; - mpf_srcptr u; - mpf_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_size_t usize, vsize; - mp_size_t sign_product; - mp_size_t prec = r->_mp_prec; - TMP_DECL (marker); - - TMP_MARK (marker); - usize = u->_mp_size; - vsize = v->_mp_size; - sign_product = usize ^ vsize; - - usize = ABS (usize); - vsize = ABS (vsize); - - up = u->_mp_d; - vp = v->_mp_d; - if (usize > prec) - { - up += usize - prec; - usize = prec; - } - if (vsize > prec) - { - vp += vsize - prec; - vsize = prec; - } - - if (usize == 0 || vsize == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; /* ??? */ - } - else - { - mp_size_t rsize; - mp_limb_t cy_limb; - mp_ptr rp, tp; - mp_size_t adj; - - rsize = usize + vsize; - tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB); - cy_limb = (usize >= vsize - ? mpn_mul (tp, up, usize, vp, vsize) - : mpn_mul (tp, vp, vsize, up, usize)); - - adj = cy_limb == 0; - rsize -= adj; - prec++; - if (rsize > prec) - { - tp += rsize - prec; - rsize = prec; - } - rp = r->_mp_d; - MPN_COPY (rp, tp, rsize); - r->_mp_exp = u->_mp_exp + v->_mp_exp - adj; - r->_mp_size = sign_product >= 0 ? rsize : -rsize; - } - TMP_FREE (marker); -} diff --git a/gmp/mpf/mul_2exp.c b/gmp/mpf/mul_2exp.c deleted file mode 100755 index 5ec2af7..0000000 --- a/gmp/mpf/mul_2exp.c +++ /dev/null @@ -1,93 +0,0 @@ -/* mpf_mul_2exp -- Multiply a float by 2^n. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_mul_2exp (mpf_ptr r, mpf_srcptr u, unsigned long int exp) -#else -mpf_mul_2exp (r, u, exp) - mpf_ptr r; - mpf_srcptr u; - unsigned long int exp; -#endif -{ - mp_srcptr up; - mp_ptr rp = r->_mp_d; - mp_size_t usize; - mp_size_t abs_usize; - mp_size_t prec = r->_mp_prec; - mp_exp_t uexp = u->_mp_exp; - - usize = u->_mp_size; - - if (usize == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - abs_usize = ABS (usize); - up = u->_mp_d; - - if (exp % BITS_PER_MP_LIMB == 0) - { - prec++; /* retain more precision here as we don't need - to account for carry-out here */ - if (abs_usize > prec) - { - up += abs_usize - prec; - abs_usize = prec; - } - if (rp != up) - MPN_COPY_INCR (rp, up, abs_usize); - r->_mp_exp = uexp + exp / BITS_PER_MP_LIMB; - } - else - { - mp_limb_t cy_limb; - mp_size_t adj; - if (abs_usize > prec) - { - up += abs_usize - prec; - abs_usize = prec; - /* Use mpn_rshift since mpn_lshift operates downwards, and we - therefore would clobber part of U before using that part, in case - R is the same variable as U. */ - cy_limb = mpn_rshift (rp + 1, up, abs_usize, (-exp) % BITS_PER_MP_LIMB); - rp[0] = cy_limb; - adj = rp[abs_usize] != 0; - } - else - { - cy_limb = mpn_lshift (rp, up, abs_usize, exp % BITS_PER_MP_LIMB); - rp[abs_usize] = cy_limb; - adj = cy_limb != 0; - } - - abs_usize += adj; - r->_mp_exp = uexp + exp / BITS_PER_MP_LIMB + adj; - } - r->_mp_size = usize >= 0 ? abs_usize : -abs_usize; -} diff --git a/gmp/mpf/mul_ui.c b/gmp/mpf/mul_ui.c deleted file mode 100755 index ba909c9..0000000 --- a/gmp/mpf/mul_ui.c +++ /dev/null @@ -1,74 +0,0 @@ -/* mpf_mul_ui -- Multiply a float and an unsigned integer. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_mul_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v) -#else -mpf_mul_ui (r, u, v) - mpf_ptr r; - mpf_srcptr u; - unsigned long int v; -#endif -{ - mp_srcptr up; - mp_size_t usize; - mp_size_t size; - mp_size_t prec = r->_mp_prec; - mp_limb_t cy_limb; - mp_ptr rp; - - usize = u->_mp_size; - size = ABS (usize); - - rp = r->_mp_d; - up = u->_mp_d; - if (size > prec) - { - up += size - prec; - size = prec; - } - -#if 0 - /* Since we can do it at almost no cost, remove zero limbs at low end of - result. */ - if (up[0] == 0) - up++, size--; -#endif - - if (size == 0 || v == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; /* ??? */ - } - else - { - cy_limb = mpn_mul_1 (rp, up, size, (mp_limb_t) v); - rp[size] = cy_limb; - cy_limb = cy_limb != 0; - r->_mp_exp = u->_mp_exp + cy_limb; - size += cy_limb; - r->_mp_size = usize >= 0 ? size : -size; - } -} diff --git a/gmp/mpf/neg.c b/gmp/mpf/neg.c deleted file mode 100755 index b5e7de1..0000000 --- a/gmp/mpf/neg.c +++ /dev/null @@ -1,59 +0,0 @@ -/* mpf_neg -- Negate a float. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_neg (mpf_ptr r, mpf_srcptr u) -#else -mpf_neg (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_size_t size; - - size = -u->_mp_size; - if (r != u) - { - mp_size_t prec; - mp_size_t asize; - mp_ptr rp, up; - - prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */ - asize = ABS (size); - rp = r->_mp_d; - up = u->_mp_d; - - if (asize > prec) - { - up += asize - prec; - asize = prec; - } - - MPN_COPY (rp, up, asize); - r->_mp_exp = u->_mp_exp; - size = size >= 0 ? asize : -asize; - } - r->_mp_size = size; -} diff --git a/gmp/mpf/out_str.c b/gmp/mpf/out_str.c deleted file mode 100755 index 96424e2..0000000 --- a/gmp/mpf/out_str.c +++ /dev/null @@ -1,91 +0,0 @@ -/* mpf_out_str (stream, base, n_digits, op) -- Print N_DIGITS digits from - the float OP to STREAM in base BASE. Return the number of characters - written, or 0 if an error occurred. - -Copyright (C) 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpf_out_str (FILE *stream, int base, size_t n_digits, mpf_srcptr op) -#else -mpf_out_str (stream, base, n_digits, op) - FILE *stream; - int base; - size_t n_digits; - mpf_srcptr op; -#endif -{ - char *str; - mp_exp_t exp; - size_t written; - TMP_DECL (marker); - - TMP_MARK (marker); - - if (base == 0) - base = 10; - if (n_digits == 0) - n_digits = (((op->_mp_prec - 1) * BITS_PER_MP_LIMB) - * __mp_bases[base].chars_per_bit_exactly); - - if (stream == 0) - stream = stdout; - - str = (char *) TMP_ALLOC (n_digits + 2); /* extra for minus sign and \0 */ - - mpf_get_str (str, &exp, base, n_digits, op); - n_digits = strlen (str); - - written = 0; - - /* Write sign */ - if (str[0] == '-') - { - str++; - fputc ('-', stream); - written = 1; - n_digits--; - } - - fwrite ("0.", 1, 2, stream); - written += 2; - - /* Write mantissa */ - { - size_t fwret; - fwret = fwrite (str, 1, n_digits, stream); - written += fwret; - } - - /* Write exponent */ - { - int fpret; - fpret = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), exp); - written += fpret; - } - - TMP_FREE (marker); - return ferror (stream) ? 0 : written; -} diff --git a/gmp/mpf/pow_ui.c b/gmp/mpf/pow_ui.c deleted file mode 100755 index 20433e2..0000000 --- a/gmp/mpf/pow_ui.c +++ /dev/null @@ -1,52 +0,0 @@ -/* mpf_pow_ui -- Compute b^e. - -Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_pow_ui (mpf_ptr r, mpf_srcptr b, unsigned long int e) -#else -mpf_pow_ui (r, b, e) - mpf_ptr r; - mpf_srcptr b; - unsigned long int e; -#endif -{ - mpf_t b2; - unsigned long int e2; - - mpf_init2 (b2, mpf_get_prec (r)); - mpf_set (b2, b); - mpf_set_ui (r, 1); - - if ((e & 1) != 0) - mpf_set (r, b2); - for (e2 = e >> 1; e2 != 0; e2 >>= 1) - { - mpf_mul (b2, b2, b2); - if ((e2 & 1) != 0) - mpf_mul (r, r, b2); - } - - mpf_clear (b2); -} diff --git a/gmp/mpf/random2.c b/gmp/mpf/random2.c deleted file mode 100755 index 22269ce..0000000 --- a/gmp/mpf/random2.c +++ /dev/null @@ -1,65 +0,0 @@ -/* mpf_random2 -- Generate a positive random mpf_t of specified size, with - long runs of consecutive ones and zeros in the binary representation. - Intended for testing of other MP routines. - -Copyright (C) 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (__hpux) || defined (__alpha) || defined (__svr4__) || defined (__SVR4) -/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */ -long mrand48 (); -static inline long -random () -{ - return mrand48 (); -} -#else -long random (); -#endif - -void -#if __STDC__ -mpf_random2 (mpf_ptr x, mp_size_t size, mp_exp_t exp) -#else -mpf_random2 (x, size, exp) - mpf_ptr x; - mp_size_t size; - mp_exp_t exp; -#endif -{ - mp_size_t asize; - mp_size_t prec = x->_mp_prec; - - asize = ABS (size); - if (asize != 0) - { - if (asize > prec + 1) - asize = prec + 1; - - mpn_random2 (x->_mp_d, asize); - } - - if (exp != 0) - exp = random () % (2 * exp) - exp; - x->_mp_exp = asize == 0 ? 0 : exp; - x->_mp_size = size < 0 ? -asize : asize; -} diff --git a/gmp/mpf/reldiff.c b/gmp/mpf/reldiff.c deleted file mode 100755 index a3c6f2e..0000000 --- a/gmp/mpf/reldiff.c +++ /dev/null @@ -1,52 +0,0 @@ -/* mpf_reldiff -- Generate the relative difference of two floats. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_reldiff (mpf_t rdiff, mpf_srcptr x, mpf_srcptr y) -#else -mpf_reldiff (rdiff, x, y) - mpf_t rdiff; - mpf_srcptr x; - mpf_srcptr y; -#endif -{ - if (mpf_cmp_ui (x, 0) == 0) - { - mpf_set_ui (rdiff, (unsigned long int) (mpf_sgn (y) != 0)); - } - else - { - mpf_t d; - mp_limb_t tmp_limb[2]; - - d->_mp_prec = 1; - d->_mp_d = tmp_limb; - - mpf_sub (d, x, y); - mpf_abs (d, d); - mpf_div (rdiff, d, x); - } -} - diff --git a/gmp/mpf/set.c b/gmp/mpf/set.c deleted file mode 100755 index 681fd23..0000000 --- a/gmp/mpf/set.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpf_set -- Assign a float from another float. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set (mpf_ptr r, mpf_srcptr u) -#else -mpf_set (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_ptr rp, up; - mp_size_t size, asize; - mp_size_t prec; - - prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */ - size = u->_mp_size; - asize = ABS (size); - rp = r->_mp_d; - up = u->_mp_d; - - if (asize > prec) - { - up += asize - prec; - asize = prec; - } - - MPN_COPY (rp, up, asize); - r->_mp_exp = u->_mp_exp; - r->_mp_size = size >= 0 ? asize : -asize; -} diff --git a/gmp/mpf/set_d.c b/gmp/mpf/set_d.c deleted file mode 100755 index 41b8a9c..0000000 --- a/gmp/mpf/set_d.c +++ /dev/null @@ -1,47 +0,0 @@ -/* mpf_set_d -- Assign a float from a IEEE double. - -Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set_d (mpf_ptr r, double d) -#else -mpf_set_d (r, d) - mpf_ptr r; - double d; -#endif -{ - int negative; - - if (d == 0) - { - SIZ(r) = 0; - EXP(r) = 0; - return; - } - negative = d < 0; - d = ABS (d); - - EXP(r) = __gmp_extract_double (PTR(r), d); - SIZ(r) = negative ? -LIMBS_PER_DOUBLE : LIMBS_PER_DOUBLE; -} diff --git a/gmp/mpf/set_dfl_prec.c b/gmp/mpf/set_dfl_prec.c deleted file mode 100755 index 60069c0..0000000 --- a/gmp/mpf/set_dfl_prec.c +++ /dev/null @@ -1,40 +0,0 @@ -/* mpf_set_default_prec -- - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_size_t __gmp_default_fp_limb_precision - = (53 + 2 * BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - -void -#if __STDC__ -mpf_set_default_prec (unsigned long int prec_in_bits) -#else -mpf_set_default_prec (prec_in_bits) - unsigned long int prec_in_bits; -#endif -{ - mp_size_t prec; - - prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB; - __gmp_default_fp_limb_precision = prec; -} diff --git a/gmp/mpf/set_prc.c b/gmp/mpf/set_prc.c deleted file mode 100755 index 08e9201..0000000 --- a/gmp/mpf/set_prc.c +++ /dev/null @@ -1,57 +0,0 @@ -/* mpf_set_prec(x) -- Change the precision of x. - -Copyright (C) 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set_prec (mpf_ptr x, unsigned long int prec_in_bits) -#else -mpf_set_prec (x, prec_in_bits) - mpf_ptr x; - unsigned long int prec_in_bits; -#endif -{ - mp_size_t prec; - mp_size_t size = ABS (x->_mp_size); - - prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB; - - /* We want the most significant limbs, so move the limbs down if we are - about to truncate the value. */ - if (size > prec + 1) - { - mp_size_t offset = size - (prec + 1); - mp_ptr xp = x->_mp_d; - - MPN_COPY_INCR (xp, xp + offset, prec + 1); - } - - x->_mp_d = (mp_ptr) (*_mp_reallocate_func) - (x->_mp_d, - (x->_mp_prec + 1) * BYTES_PER_MP_LIMB, (prec + 1) * BYTES_PER_MP_LIMB); - x->_mp_prec = prec; - - /* If the precision decreased, truncate the number. */ - if (size > prec + 1) - x->_mp_size = x->_mp_size >= 0 ? (prec + 1) : -(prec + 1); -} diff --git a/gmp/mpf/set_prc_raw.c b/gmp/mpf/set_prc_raw.c deleted file mode 100755 index 4b63a4f..0000000 --- a/gmp/mpf/set_prc_raw.c +++ /dev/null @@ -1,39 +0,0 @@ -/* mpf_set_prec_raw(x,bits) -- Change the precision of x without changing - allocation. For proper operation, the original precision need to be reset - sooner or later. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set_prec_raw (mpf_ptr x, unsigned long int prec_in_bits) -#else -mpf_set_prec_raw (x, prec_in_bits) - mpf_ptr x; - unsigned long int prec_in_bits; -#endif -{ - mp_size_t prec; - prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB; - x->_mp_prec = prec; -} diff --git a/gmp/mpf/set_q.c b/gmp/mpf/set_q.c deleted file mode 100755 index fa7f572..0000000 --- a/gmp/mpf/set_q.c +++ /dev/null @@ -1,149 +0,0 @@ -/* mpf_set_q (mpf_t rop, mpq_t op) -- Convert the rational op to the float rop. - -Copyright (C) 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpf_set_q (mpf_t r, mpq_srcptr q) -#else -mpf_set_q (r, q) - mpf_t r; - mpq_srcptr q; -#endif -{ - mp_ptr np, dp; - mp_ptr rp; - mp_size_t nsize, dsize; - mp_size_t qsize, rsize; - mp_size_t sign_quotient; - unsigned normalization_steps; - mp_limb_t qlimb; - mp_ptr qp; - mp_size_t prec; - mp_exp_t exp; - TMP_DECL (marker); - - nsize = SIZ (&q->_mp_num); - dsize = SIZ (&q->_mp_den); - - if (nsize == 0) - { - SIZ (r) = 0; - EXP (r) = 0; - return; - } - - prec = PREC (r) + 1; - - TMP_MARK (marker); - - qp = PTR (r); - - sign_quotient = nsize ^ dsize; - nsize = ABS (nsize); - dsize = ABS (dsize); - np = PTR (&q->_mp_num); - dp = PTR (&q->_mp_den); - - exp = nsize - dsize; - - if (nsize > prec) - { - np += nsize - prec; - nsize = prec; - } - if (dsize > prec) - { - dp += dsize - prec; - dsize = prec; - } - - rsize = MAX (nsize, dsize); - rp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB); - - count_leading_zeros (normalization_steps, dp[dsize - 1]); - - /* Normalize the denominator, i.e. make its most significant bit set by - shifting it NORMALIZATION_STEPS bits to the left. Also shift the - numerator the same number of steps (to keep the quotient the same!). */ - if (normalization_steps != 0) - { - mp_ptr tp; - mp_limb_t nlimb; - - /* Shift up the denominator setting the most significant bit of - the most significant limb. Use temporary storage not to clobber - the original contents of the denominator. */ - tp = (mp_ptr) TMP_ALLOC (dsize * BYTES_PER_MP_LIMB); - mpn_lshift (tp, dp, dsize, normalization_steps); - dp = tp; - - if (rsize != nsize) - { - MPN_ZERO (rp, rsize - nsize); - nlimb = mpn_lshift (rp + (rsize - nsize), - np, nsize, normalization_steps); - } - else - { - nlimb = mpn_lshift (rp, np, rsize, normalization_steps); - } - if (nlimb != 0) - { - rp[rsize] = nlimb; - exp++; - /* Don't just increase rsize, chop off rp at the low end instead. */ - if (rsize == prec) - rp++; - else - rsize++; - } - } - else - { - if (rsize != nsize) - { - MPN_ZERO (rp, rsize - nsize); - MPN_COPY (rp + (rsize - nsize), np, nsize); - } - else - { - MPN_COPY (rp, np, rsize); - } - } - - qlimb = mpn_divrem (qp, prec - 1 - (rsize - dsize), rp, rsize, dp, dsize); - qsize = prec - 1; - if (qlimb) - { - qp[qsize] = qlimb; - qsize++; - exp++; - } - - EXP (r) = exp; - SIZ (r) = sign_quotient >= 0 ? qsize : -qsize; - - TMP_FREE (marker); -} diff --git a/gmp/mpf/set_si.c b/gmp/mpf/set_si.c deleted file mode 100755 index 9aa70ba..0000000 --- a/gmp/mpf/set_si.c +++ /dev/null @@ -1,51 +0,0 @@ -/* mpf_set_si() -- Assign a float from a signed int. - -Copyright (C) 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set_si (mpf_ptr x, long int val) -#else -mpf_set_si (x, val) - mpf_ptr x; - long int val; -#endif -{ - if (val > 0) - { - x->_mp_d[0] = val; - x->_mp_size = 1; - x->_mp_exp = 1; - } - else if (val < 0) - { - x->_mp_d[0] = (unsigned long) -val; - x->_mp_size = -1; - x->_mp_exp = 1; - } - else - { - x->_mp_size = 0; - x->_mp_exp = 0; - } -} diff --git a/gmp/mpf/set_str.c b/gmp/mpf/set_str.c deleted file mode 100755 index e6f2fdc..0000000 --- a/gmp/mpf/set_str.c +++ /dev/null @@ -1,322 +0,0 @@ -/* mpf_set_str (dest, string, base) -- Convert the string STRING - in base BASE to a float in dest. If BASE is zero, the leading characters - of STRING is used to figure out the base. - -Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -long int strtol _PROTO ((const char *, char **ptr, int)); - -static int -#if __STDC__ -digit_value_in_base (int c, int base) -#else -digit_value_in_base (c, base) - int c; - int base; -#endif -{ - int digit; - - if (isdigit (c)) - digit = c - '0'; - else if (islower (c)) - digit = c - 'a' + 10; - else if (isupper (c)) - digit = c - 'A' + 10; - else - return -1; - - if (digit < base) - return digit; - return -1; -} - -int -#if __STDC__ -mpf_set_str (mpf_ptr x, const char *str, int base) -#else -mpf_set_str (x, str, base) - mpf_ptr x; - char *str; - int base; -#endif -{ - size_t str_size; - char *s, *begs; - size_t i; - mp_size_t xsize; - int c; - int negative; - char *dotpos = 0; - int expflag; - int decimal_exponent_flag; - TMP_DECL (marker); - - TMP_MARK (marker); - - c = *str; - - /* Skip whitespace. */ - while (isspace (c)) - c = *++str; - - negative = 0; - if (c == '-') - { - negative = 1; - c = *++str; - } - - decimal_exponent_flag = base < 0; - base = ABS (base); - - if (digit_value_in_base (c, base == 0 ? 10 : base) < 0 - && (c != '.' || digit_value_in_base (str[1], base == 0 ? 10 : base) < 0)) - return -1; /* error if no digits */ - - /* If BASE is 0, try to find out the base by looking at the initial - characters. */ - if (base == 0) - { - base = 10; -#if 0 - if (c == '0') - { - base = 8; - if (str[1] == 'x' || str[1] == 'X') - { - base = 16; - str += 2; - c = *str; - } - } -#endif - } - - expflag = 0; - str_size = strlen (str); - for (i = 0; i < str_size; i++) - { - c = str[i]; - if (c == '@' || (base <= 10 && (c == 'e' || c == 'E'))) - { - expflag = 1; - str_size = i; - break; - } - - } - - s = begs = (char *) TMP_ALLOC (str_size + 1); - - for (i = 0; i < str_size; i++) - { - c = *str; - if (!isspace (c)) - { - int dig; - - if (c == '.') - { - if (dotpos != 0) - { - TMP_FREE (marker); - return -1; - } - dotpos = s; - } - else - { - dig = digit_value_in_base (c, base); - if (dig < 0) - { - TMP_FREE (marker); - return -1; - } - *s++ = dig; - } - } - c = *++str; - } - - str_size = s - begs; - - xsize = str_size / __mp_bases[base].chars_per_limb + 2; - { - long exp_in_base; - mp_size_t ralloc, rsize, msize; - int cnt, i; - mp_ptr mp, tp, rp; - mp_exp_t exp_in_limbs; - mp_size_t prec = x->_mp_prec + 1; - int divflag; - mp_size_t madj, radj; - - mp = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB); - msize = mpn_set_str (mp, (unsigned char *) begs, str_size, base); - - if (msize == 0) - { - x->_mp_size = 0; - x->_mp_exp = 0; - TMP_FREE (marker); - return 0; - } - - madj = 0; - /* Ignore excess limbs in MP,MSIZE. */ - if (msize > prec) - { - madj = msize - prec; - mp += msize - prec; - msize = prec; - } - - if (expflag != 0) - exp_in_base = strtol (str + 1, (char **) 0, - decimal_exponent_flag ? 10 : base); - else - exp_in_base = 0; - if (dotpos != 0) - exp_in_base -= s - dotpos; - divflag = exp_in_base < 0; - exp_in_base = ABS (exp_in_base); - - if (exp_in_base == 0) - { - MPN_COPY (x->_mp_d, mp, msize); - x->_mp_size = negative ? -msize : msize; - x->_mp_exp = msize + madj; - TMP_FREE (marker); - return 0; - } - - radj = 0; /* counts number of ignored low limbs in r */ - - ralloc = 2 * (prec + 1); - rp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - tp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - - rp[0] = base; - rsize = 1; - count_leading_zeros (cnt, exp_in_base); - for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--) - { - mpn_mul_n (tp, rp, rp, rsize); - rsize = 2 * rsize; - rsize -= tp[rsize - 1] == 0; - radj <<= 1; - - if (rsize > prec) - { - radj += rsize - prec; - MPN_COPY_INCR (rp, tp + rsize - prec, prec); - rsize = prec; - } - else - MP_PTR_SWAP (rp, tp); - - if (((exp_in_base >> i) & 1) != 0) - { - mp_limb_t cy; - cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base); - rp[rsize] = cy; - rsize += cy != 0; - } - } - - if (rsize > prec) - { - radj += rsize - prec; - rp += rsize - prec; - rsize = prec; - } - - if (divflag) - { - mp_ptr qp; - mp_limb_t qlimb; - if (msize < rsize) - { - /* Pad out MP,MSIZE for current divrem semantics. */ - mp_ptr tmp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB); - MPN_ZERO (tmp, rsize - msize); - MPN_COPY (tmp + rsize - msize, mp, msize); - mp = tmp; - madj -= rsize - msize; - msize = rsize; - } - count_leading_zeros (cnt, rp[rsize - 1]); - if (cnt != 0) - { - mp_limb_t cy; - mpn_lshift (rp, rp, rsize, cnt); - cy = mpn_lshift (mp, mp, msize, cnt); - if (cy) - mp[msize++] = cy; - } - - qp = (mp_ptr) TMP_ALLOC ((prec + 1) * BYTES_PER_MP_LIMB); - qlimb = mpn_divrem (qp, prec - (msize - rsize), mp, msize, rp, rsize); - tp = qp; - exp_in_limbs = qlimb + (msize - rsize) + (madj - radj); - rsize = prec; - if (qlimb != 0) - { - tp[prec] = qlimb; - /* Skip the least significant limb not to overrun the destination - variable. */ - tp++; - } - } - else - { - tp = (mp_ptr) TMP_ALLOC ((rsize + msize) * BYTES_PER_MP_LIMB); - if (rsize > msize) - mpn_mul (tp, rp, rsize, mp, msize); - else - mpn_mul (tp, mp, msize, rp, rsize); - rsize += msize; - rsize -= tp[rsize - 1] == 0; - exp_in_limbs = rsize + madj + radj; - - if (rsize > prec) - { - tp += rsize - prec; - rsize = prec; - exp_in_limbs += 0; - } - } - - MPN_COPY (x->_mp_d, tp, rsize); - x->_mp_size = negative ? -rsize : rsize; - x->_mp_exp = exp_in_limbs; - TMP_FREE (marker); - return 0; - } -} diff --git a/gmp/mpf/set_ui.c b/gmp/mpf/set_ui.c deleted file mode 100755 index 5d492fa..0000000 --- a/gmp/mpf/set_ui.c +++ /dev/null @@ -1,45 +0,0 @@ -/* mpf_set_ui() -- Assign a float from an unsigned int. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set_ui (mpf_ptr x, unsigned long int val) -#else -mpf_set_ui (x, val) - mpf_ptr x; - unsigned long int val; -#endif -{ - if (val != 0) - { - x->_mp_d[0] = val; - x->_mp_size = 1; - x->_mp_exp = 1; - } - else - { - x->_mp_size = 0; - x->_mp_exp = 0; - } -} diff --git a/gmp/mpf/set_z.c b/gmp/mpf/set_z.c deleted file mode 100755 index f417b2e..0000000 --- a/gmp/mpf/set_z.c +++ /dev/null @@ -1,54 +0,0 @@ -/* mpf_set_z -- Assign a float from an integer. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_set_z (mpf_ptr r, mpz_srcptr u) -#else -mpf_set_z (r, u) - mpf_ptr r; - mpz_srcptr u; -#endif -{ - mp_ptr rp, up; - mp_size_t size, asize; - mp_size_t prec; - - prec = PREC (r) + 1; - size = SIZ (u); - asize = ABS (size); - rp = PTR (r); - up = PTR (u); - - EXP (r) = asize; - - if (asize > prec) - { - up += asize - prec; - asize = prec; - } - - MPN_COPY (rp, up, asize); - SIZ (r) = size >= 0 ? asize : -asize; -} diff --git a/gmp/mpf/size.c b/gmp/mpf/size.c deleted file mode 100755 index 7d7adc6..0000000 --- a/gmp/mpf/size.c +++ /dev/null @@ -1,35 +0,0 @@ -/* mpf_size(x) -- return the number of limbs currently used by the - value of the float X. - -Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpf_size (mpf_srcptr x) -#else -mpf_size (x) - mpf_srcptr x; -#endif -{ - return ABS (x->_mp_size); -} diff --git a/gmp/mpf/sqrt.c b/gmp/mpf/sqrt.c deleted file mode 100755 index efdd154..0000000 --- a/gmp/mpf/sqrt.c +++ /dev/null @@ -1,77 +0,0 @@ -/* mpf_sqrt -- Compute the square root of a float. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_sqrt (mpf_ptr r, mpf_srcptr u) -#else -mpf_sqrt (r, u) - mpf_ptr r; - mpf_srcptr u; -#endif -{ - mp_size_t usize; - mp_ptr up, tp; - mp_size_t prec; - mp_exp_t tsize, rexp; - TMP_DECL (marker); - - usize = u->_mp_size; - if (usize <= 0) - { - if (usize < 0) - SQRT_OF_NEGATIVE; - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - TMP_MARK (marker); - - prec = r->_mp_prec; - rexp = (u->_mp_exp + 1) >> 1; /* round towards -inf */ - tsize = 2 * prec + (u->_mp_exp & 1); - - up = u->_mp_d; - tp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB); - - if (usize > tsize) - { - up += usize - tsize; - usize = tsize; - MPN_COPY (tp, up, tsize); - } - else - { - MPN_ZERO (tp, tsize - usize); - MPN_COPY (tp + (tsize - usize), up, usize); - } - - mpn_sqrtrem (r->_mp_d, NULL, tp, tsize); - - r->_mp_size = (tsize + 1) / 2; - r->_mp_exp = rexp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/sqrt_ui.c b/gmp/mpf/sqrt_ui.c deleted file mode 100755 index 2c69193..0000000 --- a/gmp/mpf/sqrt_ui.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpf_sqrt_ui -- Compute the square root of an unsigned integer. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_sqrt_ui (mpf_ptr r, unsigned long int u) -#else -mpf_sqrt_ui (r, u) - mpf_ptr r; - unsigned long int u; -#endif -{ - mp_size_t rsize; - mp_ptr tp; - mp_size_t prec; - TMP_DECL (marker); - - if (u == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - TMP_MARK (marker); - - prec = r->_mp_prec; - rsize = 2 * prec + 1; - - tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB); - - MPN_ZERO (tp, rsize - 1); - tp[rsize - 1] = u; - - mpn_sqrtrem (r->_mp_d, NULL, tp, rsize); - - r->_mp_size = prec + 1; - r->_mp_exp = 1; - TMP_FREE (marker); -} diff --git a/gmp/mpf/sub.c b/gmp/mpf/sub.c deleted file mode 100755 index 2cd7edf..0000000 --- a/gmp/mpf/sub.c +++ /dev/null @@ -1,412 +0,0 @@ -/* mpf_sub -- Subtract two floats. - -Copyright (C) 1993, 1994, 1995, 1996, 1999, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_sub (mpf_ptr r, mpf_srcptr u, mpf_srcptr v) -#else -mpf_sub (r, u, v) - mpf_ptr r; - mpf_srcptr u; - mpf_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_ptr rp, tp; - mp_size_t usize, vsize, rsize; - mp_size_t prec; - mp_exp_t exp; - mp_size_t ediff; - int negate; - TMP_DECL (marker); - - usize = u->_mp_size; - vsize = v->_mp_size; - - /* Handle special cases that don't work in generic code below. */ - if (usize == 0) - { - mpf_neg (r, v); - return; - } - if (vsize == 0) - { - mpf_set (r, u); - return; - } - - /* If signs of U and V are different, perform addition. */ - if ((usize ^ vsize) < 0) - { - __mpf_struct v_negated; - v_negated._mp_size = -vsize; - v_negated._mp_exp = v->_mp_exp; - v_negated._mp_d = v->_mp_d; - mpf_add (r, u, &v_negated); - return; - } - - TMP_MARK (marker); - - /* Signs are now known to be the same. */ - negate = usize < 0; - - /* Make U be the operand with the largest exponent. */ - if (u->_mp_exp < v->_mp_exp) - { - mpf_srcptr t; - t = u; u = v; v = t; - negate ^= 1; - usize = u->_mp_size; - vsize = v->_mp_size; - } - - usize = ABS (usize); - vsize = ABS (vsize); - up = u->_mp_d; - vp = v->_mp_d; - rp = r->_mp_d; - prec = r->_mp_prec + 1; - exp = u->_mp_exp; - ediff = u->_mp_exp - v->_mp_exp; - - /* If ediff is 0 or 1, we might have a situation where the operands are - extremely close. We need to scan the operands from the most significant - end ignore the initial parts that are equal. */ - if (ediff <= 1) - { - if (ediff == 0) - { - /* Skip leading limbs in U and V that are equal. */ - if (up[usize - 1] == vp[vsize - 1]) - { - /* This loop normally exits immediately. Optimize for that. */ - do - { - usize--; - vsize--; - exp--; - - if (usize == 0) - { - if (vsize > prec) - { - vp += vsize - prec; - vsize = prec; - } - rsize = vsize; - tp = (mp_ptr) vp; - negate ^= 1; - goto normalize; - } - if (vsize == 0) - { - if (usize > prec) - { - up += usize - prec; - usize = prec; - } - rsize = usize; - tp = (mp_ptr) up; - goto normalize; - } - } - while (up[usize - 1] == vp[vsize - 1]); - } - - if (up[usize - 1] < vp[vsize - 1]) - { - /* For simplicity, swap U and V. Note that since the loop above - wouldn't have exited unless up[usize - 1] and vp[vsize - 1] - were non-equal, this if-statement catches all cases where U - is smaller than V. */ - MPN_SRCPTR_SWAP (up,usize, vp,vsize); - negate ^= 1; - /* negating ediff not necessary since it is 0. */ - } - - /* Check for - x+1 00000000 ... - x ffffffff ... */ - if (up[usize - 1] != vp[vsize - 1] + 1) - goto general_case; - usize--; - vsize--; - exp--; - } - else /* ediff == 1 */ - { - /* Check for - 1 00000000 ... - 0 ffffffff ... */ - - if (up[usize - 1] != 1 || vp[vsize - 1] != ~(mp_limb_t) 0 - || (usize >= 2 && up[usize - 2] != 0)) - goto general_case; - - usize--; - exp--; - } - - /* Skip sequences of 00000000/ffffffff */ - while (vsize != 0 && usize != 0 && up[usize - 1] == 0 - && vp[vsize - 1] == ~(mp_limb_t) 0) - { - usize--; - vsize--; - exp--; - } - - if (usize == 0) - { - while (vsize != 0 && vp[vsize - 1] == ~(mp_limb_t) 0) - { - vsize--; - exp--; - } - } - - if (usize > prec - 1) - { - up += usize - (prec - 1); - usize = prec - 1; - } - if (vsize > prec - 1) - { - vp += vsize - (prec - 1); - vsize = prec - 1; - } - - tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB); - { - mp_limb_t cy_limb; - if (vsize == 0) - { - mp_size_t size, i; - size = usize; - for (i = 0; i < size; i++) - tp[i] = up[i]; - tp[size] = 1; - rsize = size + 1; - exp++; - goto normalize; - } - if (usize == 0) - { - mp_size_t size, i; - size = vsize; - for (i = 0; i < size; i++) - tp[i] = ~vp[i]; - cy_limb = 1 - mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1); - rsize = vsize; - if (cy_limb == 0) - { - tp[rsize] = 1; - rsize++; - exp++; - } - goto normalize; - } - if (usize >= vsize) - { - /* uuuu */ - /* vv */ - mp_size_t size; - size = usize - vsize; - MPN_COPY (tp, up, size); - cy_limb = mpn_sub_n (tp + size, up + size, vp, vsize); - rsize = usize; - } - else /* (usize < vsize) */ - { - /* uuuu */ - /* vvvvvvv */ - mp_size_t size, i; - size = vsize - usize; - for (i = 0; i < size; i++) - tp[i] = ~vp[i]; - cy_limb = mpn_sub_n (tp + size, up, vp + size, usize); - cy_limb+= mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); - cy_limb-= mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1); - rsize = vsize; - } - if (cy_limb == 0) - { - tp[rsize] = 1; - rsize++; - exp++; - } - goto normalize; - } - } - -general_case: - /* If U extends beyond PREC, ignore the part that does. */ - if (usize > prec) - { - up += usize - prec; - usize = prec; - } - - /* If V extends beyond PREC, ignore the part that does. - Note that this may make vsize negative. */ - if (vsize + ediff > prec) - { - vp += vsize + ediff - prec; - vsize = prec - ediff; - } - - /* Allocate temp space for the result. Allocate - just vsize + ediff later??? */ - tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB); - - if (ediff >= prec) - { - /* V completely cancelled. */ - if (tp != up) - MPN_COPY (rp, up, usize); - rsize = usize; - } - else - { - /* Locate the least significant non-zero limb in (the needed - parts of) U and V, to simplify the code below. */ - for (;;) - { - if (vsize == 0) - { - MPN_COPY (rp, up, usize); - rsize = usize; - goto done; - } - if (vp[0] != 0) - break; - vp++, vsize--; - } - for (;;) - { - if (usize == 0) - { - MPN_COPY (rp, vp, vsize); - rsize = vsize; - negate ^= 1; - goto done; - } - if (up[0] != 0) - break; - up++, usize--; - } - - /* uuuu | uuuu | uuuu | uuuu | uuuu */ - /* vvvvvvv | vv | vvvvv | v | vv */ - - if (usize > ediff) - { - /* U and V partially overlaps. */ - if (ediff == 0) - { - /* Have to compare the leading limbs of u and v - to determine whether to compute u - v or v - u. */ - if (usize >= vsize) - { - /* uuuu */ - /* vv */ - mp_size_t size; - size = usize - vsize; - MPN_COPY (tp, up, size); - mpn_sub_n (tp + size, up + size, vp, vsize); - rsize = usize; - } - else /* (usize < vsize) */ - { - /* uuuu */ - /* vvvvvvv */ - mp_size_t size, i; - size = vsize - usize; - tp[0] = -vp[0]; - for (i = 1; i < size; i++) - tp[i] = ~vp[i]; - mpn_sub_n (tp + size, up, vp + size, usize); - mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); - rsize = vsize; - } - } - else - { - if (vsize + ediff <= usize) - { - /* uuuu */ - /* v */ - mp_size_t size; - size = usize - ediff - vsize; - MPN_COPY (tp, up, size); - mpn_sub (tp + size, up + size, usize - size, vp, vsize); - rsize = usize; - } - else - { - /* uuuu */ - /* vvvvv */ - mp_size_t size, i; - size = vsize + ediff - usize; - tp[0] = -vp[0]; - for (i = 1; i < size; i++) - tp[i] = ~vp[i]; - mpn_sub (tp + size, up, usize, vp + size, usize - ediff); - mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); - rsize = vsize + ediff; - } - } - } - else - { - /* uuuu */ - /* vv */ - mp_size_t size, i; - size = vsize + ediff - usize; - tp[0] = -vp[0]; - for (i = 1; i < vsize; i++) - tp[i] = ~vp[i]; - for (i = vsize; i < size; i++) - tp[i] = ~(mp_limb_t) 0; - mpn_sub_1 (tp + size, up, usize, (mp_limb_t) 1); - rsize = size + usize; - } - - normalize: - /* Full normalize. Optimize later. */ - while (rsize != 0 && tp[rsize - 1] == 0) - { - rsize--; - exp--; - } - MPN_COPY (rp, tp, rsize); - } - - done: - r->_mp_size = negate ? -rsize : rsize; - r->_mp_exp = exp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/sub_ui.c b/gmp/mpf/sub_ui.c deleted file mode 100755 index 769231e..0000000 --- a/gmp/mpf/sub_ui.c +++ /dev/null @@ -1,49 +0,0 @@ -/* mpf_sub_ui -- Subtract an unsigned integer from a float. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_sub_ui (mpf_ptr sum, mpf_srcptr u, unsigned long int v) -#else -mpf_sub_ui (sum, u, v) - mpf_ptr sum; - mpf_srcptr u; - unsigned long int v; -#endif -{ - __mpf_struct vv; - mp_limb_t vl; - - if (v == 0) - { - mpf_set (sum, u); - return; - } - - vl = v; - vv._mp_size = 1; - vv._mp_d = &vl; - vv._mp_exp = 1; - mpf_sub (sum, u, &vv); -} diff --git a/gmp/mpf/swap.c b/gmp/mpf/swap.c deleted file mode 100755 index bc20c39..0000000 --- a/gmp/mpf/swap.c +++ /dev/null @@ -1,58 +0,0 @@ -/* mpf_swap (U, V) -- Swap U and V. - -Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_swap (mpf_ptr u, mpf_ptr v) -#else -mpf_swap (u, v) - mpf_ptr u; - mpf_ptr v; -#endif -{ - mp_ptr up, vp; - mp_size_t usize, vsize; - mp_size_t uprec, vprec; - mp_exp_t uexp, vexp; - - uprec = u->_mp_prec; - vprec = v->_mp_prec; - v->_mp_prec = uprec; - u->_mp_prec = vprec; - - usize = u->_mp_size; - vsize = v->_mp_size; - v->_mp_size = usize; - u->_mp_size = vsize; - - uexp = u->_mp_exp; - vexp = v->_mp_exp; - v->_mp_exp = uexp; - u->_mp_exp = vexp; - - up = u->_mp_d; - vp = v->_mp_d; - v->_mp_d = up; - u->_mp_d = vp; -} diff --git a/gmp/mpf/tests/Makefile.am b/gmp/mpf/tests/Makefile.am deleted file mode 100755 index c4b9548..0000000 Binary files a/gmp/mpf/tests/Makefile.am and /dev/null differ diff --git a/gmp/mpf/tests/Makefile.in b/gmp/mpf/tests/Makefile.in deleted file mode 100755 index 8e7d419..0000000 Binary files a/gmp/mpf/tests/Makefile.in and /dev/null differ diff --git a/gmp/mpf/tests/ref.c b/gmp/mpf/tests/ref.c deleted file mode 100755 index c1f712f..0000000 --- a/gmp/mpf/tests/ref.c +++ /dev/null @@ -1,203 +0,0 @@ -/* Reference floating point routines. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#if __STDC__ -void ref_mpf_add (mpf_t, const mpf_t, const mpf_t); -void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t); -#else -void ref_mpf_add (); -void ref_mpf_sub (); -#endif - -void -#if __STDC__ -ref_mpf_add (mpf_t w, const mpf_t u, const mpf_t v) -#else -ref_mpf_add (w, u, v) - mpf_t w; - const mpf_t u; - const mpf_t v; -#endif -{ - mp_size_t hi, lo, size; - mp_ptr ut, vt, wt; - int neg; - mp_exp_t exp; - mp_limb_t cy; - TMP_DECL (mark); - - TMP_MARK (mark); - - if (SIZ (u) == 0) - { - size = ABSIZ (v); - wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB); - MPN_COPY (wt, PTR (v), size); - exp = EXP (v); - neg = SIZ (v) < 0; - goto done; - } - if (SIZ (v) == 0) - { - size = ABSIZ (u); - wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB); - MPN_COPY (wt, PTR (u), size); - exp = EXP (u); - neg = SIZ (u) < 0; - goto done; - } - if ((SIZ (u) ^ SIZ (v)) < 0) - { - mpf_t tmp; - SIZ (tmp) = -SIZ (v); - EXP (tmp) = EXP (v); - PTR (tmp) = PTR (v); - ref_mpf_sub (w, u, tmp); - return; - } - neg = SIZ (u) < 0; - - /* Compute the significance of the hi and lo end of the result. */ - hi = MAX (EXP (u), EXP (v)); - lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v)); - size = hi - lo; - ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - MPN_ZERO (ut, size); - MPN_ZERO (vt, size); - {int off; - off = size + (EXP (u) - hi) - ABSIZ (u); - MPN_COPY (ut + off, PTR (u), ABSIZ (u)); - off = size + (EXP (v) - hi) - ABSIZ (v); - MPN_COPY (vt + off, PTR (v), ABSIZ (v)); - } - - cy = mpn_add_n (wt, ut, vt, size); - wt[size] = cy; - size += cy; - exp = hi + cy; - -done: - if (size > PREC (w)) - { - wt += size - PREC (w); - size = PREC (w); - } - MPN_COPY (PTR (w), wt, size); - SIZ (w) = neg == 0 ? size : -size; - EXP (w) = exp; - TMP_FREE (mark); -} - -void -#if __STDC__ -ref_mpf_sub (mpf_t w, const mpf_t u, const mpf_t v) -#else -ref_mpf_sub (w, u, v) - mpf_t w; - const mpf_t u; - const mpf_t v; -#endif -{ - mp_size_t hi, lo, size; - mp_ptr ut, vt, wt; - int neg; - mp_exp_t exp; - TMP_DECL (mark); - - TMP_MARK (mark); - - if (SIZ (u) == 0) - { - size = ABSIZ (v); - wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB); - MPN_COPY (wt, PTR (v), size); - exp = EXP (v); - neg = SIZ (v) > 0; - goto done; - } - if (SIZ (v) == 0) - { - size = ABSIZ (u); - wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB); - MPN_COPY (wt, PTR (u), size); - exp = EXP (u); - neg = SIZ (u) < 0; - goto done; - } - if ((SIZ (u) ^ SIZ (v)) < 0) - { - mpf_t tmp; - SIZ (tmp) = -SIZ (v); - EXP (tmp) = EXP (v); - PTR (tmp) = PTR (v); - ref_mpf_add (w, u, tmp); - if (SIZ (u) < 0) - mpf_neg (w, w); - return; - } - neg = SIZ (u) < 0; - - /* Compute the significance of the hi and lo end of the result. */ - hi = MAX (EXP (u), EXP (v)); - lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v)); - size = hi - lo; - ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - MPN_ZERO (ut, size); - MPN_ZERO (vt, size); - {int off; - off = size + (EXP (u) - hi) - ABSIZ (u); - MPN_COPY (ut + off, PTR (u), ABSIZ (u)); - off = size + (EXP (v) - hi) - ABSIZ (v); - MPN_COPY (vt + off, PTR (v), ABSIZ (v)); - } - - if (mpn_cmp (ut, vt, size) >= 0) - mpn_sub_n (wt, ut, vt, size); - else - { - mpn_sub_n (wt, vt, ut, size); - neg ^= 1; - } - exp = hi; - while (size != 0 && wt[size - 1] == 0) - { - size--; - exp--; - } - -done: - if (size > PREC (w)) - { - wt += size - PREC (w); - size = PREC (w); - } - MPN_COPY (PTR (w), wt, size); - SIZ (w) = neg == 0 ? size : -size; - EXP (w) = exp; - TMP_FREE (mark); -} diff --git a/gmp/mpf/tests/reuse.c b/gmp/mpf/tests/reuse.c deleted file mode 100755 index fa8d89e..0000000 --- a/gmp/mpf/tests/reuse.c +++ /dev/null @@ -1,205 +0,0 @@ -/* Test that routines allow reusing a source variable as destination. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 16 -#endif - -#ifndef EXPO -#define EXPO 32 -#endif - -#if __STDC__ -typedef void (*dss_func) (mpf_ptr, mpf_srcptr, mpf_srcptr); -#else -typedef void (*dss_func) (); -#endif - -dss_func dss_funcs[] = -{ - mpf_div, mpf_add, mpf_mul, mpf_sub, -}; - -char *dss_func_names[] = -{ - "mpf_div", "mpf_add", "mpf_mul", "mpf_sub", -}; - -#if __STDC__ -typedef void (*dsi_func) (mpf_ptr, mpf_srcptr, unsigned long int); -#else -typedef void (*dsi_func) (); -#endif - -dsi_func dsi_funcs[] = -{ - mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui, - mpf_mul_2exp, mpf_div_2exp -}; - -char *dsi_func_names[] = -{ - "mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui", - "mpf_mul_2exp", "mpf_div_2exp" -}; - -#if __STDC__ -typedef void (*dis_func) (mpf_ptr, unsigned long int, mpf_srcptr); -#else -typedef void (*dis_func) (); -#endif - -dis_func dis_funcs[] = -{ - mpf_ui_div, mpf_ui_sub, -}; - -char *dis_func_names[] = -{ - "mpf_ui_div", "mpf_ui_sub", -}; - -main (argc, argv) - int argc; - char **argv; -{ - int i; - int pass, reps = 100000; - mpf_t in1, in2, out1; - unsigned long int in1i, in2i; - mpf_t res1, res2, res3; - mp_size_t bprec = 100; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init (in1); - mpf_init (in2); - mpf_init (out1); - mpf_init (res1); - mpf_init (res2); - mpf_init (res3); - - for (pass = 1; pass <= reps; pass++) - { - mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO); - mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO); - - for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++) - { - /* Don't divide by 0. */ - if (i == 0 && mpf_cmp_ui (in2, 0) == 0) - continue; - - (dss_funcs[i]) (res1, in1, in2); - - mpf_set (out1, in1); - (dss_funcs[i]) (out1, out1, in2); - mpf_set (res2, out1); - - mpf_set (out1, in2); - (dss_funcs[i]) (out1, in1, out1); - mpf_set (res3, out1); - - if (mpf_cmp (res1, res2) != 0) - dump_abort (dss_func_names[i], res1, res2); - if (mpf_cmp (res1, res3) != 0) - dump_abort (dss_func_names[i], res1, res3); - } - - in2i = urandom (); - for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++) - { - /* Don't divide by 0. */ - if (strcmp (dsi_func_names[i], "mpf_div_ui") == 0 && in2i == 0) - continue; - - (dsi_funcs[i]) (res1, in1, in2i); - - mpf_set (out1, in1); - (dsi_funcs[i]) (out1, out1, in2i); - mpf_set (res2, out1); - - if (mpf_cmp (res1, res2) != 0) - dump_abort (dsi_func_names[i], res1, res2); - } - - in1i = urandom (); - for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++) - { - /* Don't divide by 0. */ - if (strcmp (dis_func_names[i], "mpf_ui_div") == 0 - && mpf_cmp_ui (in2, 0) == 0) - continue; - - (dis_funcs[i]) (res1, in1i, in2); - - mpf_set (out1, in2); - (dis_funcs[i]) (out1, in1i, out1); - mpf_set (res2, out1); - - if (mpf_cmp (res1, res2) != 0) - dump_abort (dis_func_names[i], res1, res2); - } - - } - - exit (0); -} - -dump_abort (name, res1, res2) - char *name; - mpf_t res1, res2; -{ - printf ("failure in %s:\n", name); - oo (res1); - oo (res2); - abort (); -} - -oo (x) - mpf_t x; -{ - mp_size_t i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} - -#if 0 -void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr)); -void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr)); -#endif diff --git a/gmp/mpf/tests/t-add.c b/gmp/mpf/tests/t-add.c deleted file mode 100755 index 3c309fc..0000000 --- a/gmp/mpf/tests/t-add.c +++ /dev/null @@ -1,117 +0,0 @@ -/* Test mpf_add. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 16 -#endif - -#if __STDC__ -void ref_mpf_add (mpf_t, const mpf_t, const mpf_t); -void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t); -#else -void ref_mpf_add (); -void ref_mpf_sub (); -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mp_size_t size; - mp_exp_t exp; - int reps = 100000; - int i; - mpf_t u, v, w, wref; - mp_size_t bprec = 100; - mpf_t rerr, max_rerr, limit_rerr; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init_set_ui (limit_rerr, 1); - mpf_div_2exp (limit_rerr, limit_rerr, bprec); -#if VERBOSE - mpf_dump (limit_rerr); -#endif - mpf_init (rerr); - mpf_init_set_ui (max_rerr, 0); - - mpf_init (u); - mpf_init (v); - mpf_init (w); - mpf_init (wref); - for (i = 0; i < reps; i++) - { - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % SIZE; - mpf_random2 (u, size, exp); - - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % SIZE; - mpf_random2 (v, size, exp); - - mpf_add (w, u, v); - ref_mpf_add (wref, u, v); - - mpf_reldiff (rerr, w, wref); - if (mpf_cmp (rerr, max_rerr) > 0) - { - mpf_set (max_rerr, rerr); -#if VERBOSE - mpf_dump (max_rerr); -#endif - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf ("wref = "); mpf_dump (wref); - printf (" w = "); mpf_dump (w); - abort (); - } - } - } - - exit (0); -} - -oo (x) - mpf_t x; -{ - mp_size_t i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} diff --git a/gmp/mpf/tests/t-conv.c b/gmp/mpf/tests/t-conv.c deleted file mode 100755 index 52d7e51..0000000 --- a/gmp/mpf/tests/t-conv.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Test mpf_get_str and mpf_set_str. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 10 -#endif - -#ifndef EXPO -#define EXPO 20 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpf_t x, y; - int reps = 20000; - int i; - mp_size_t bprec = 100; - mpf_t d, rerr, max_rerr, limit_rerr; - char *str; - mp_exp_t bexp; - long size, exp; - int base; - char buf[SIZE * BITS_PER_MP_LIMB + 5]; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init_set_ui (limit_rerr, 1); - mpf_div_2exp (limit_rerr, limit_rerr, bprec); -#if VERBOSE - mpf_dump (limit_rerr); -#endif - mpf_init (rerr); - mpf_init_set_ui (max_rerr, 0); - - mpf_init (x); - mpf_init (y); - mpf_init (d); - - for (i = 0; i < reps; i++) - { - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % EXPO; - mpf_random2 (x, size, exp); - - base = urandom () % 35 + 2; - - str = mpf_get_str (0, &bexp, base, 0, x); - - if (str[0] == '-') - sprintf (buf, "-0.%s@%ld", str + 1, bexp); - else - sprintf (buf, "0.%s@%ld", str, bexp); - - mpf_set_str (y, buf, -base); - (*_mp_free_func) (str, 0); - - mpf_reldiff (rerr, x, y); - if (mpf_cmp (rerr, max_rerr) > 0) - { - mpf_set (max_rerr, rerr); -#if VERBOSE - mpf_dump (max_rerr); -#endif - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR after %d tests\n", i); - printf ("base = %d\n", base); - printf (" x = "); mpf_dump (x); - printf (" y = "); mpf_dump (y); - abort (); - } - } - } - - exit (0); -} - -oo (x) - mpf_t x; -{ - int i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} diff --git a/gmp/mpf/tests/t-dm2exp.c b/gmp/mpf/tests/t-dm2exp.c deleted file mode 100755 index 5e609bc..0000000 --- a/gmp/mpf/tests/t-dm2exp.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Test mpf_div, mpf_div_2exp, mpf_mul_2exp. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - int reps = 500000; - int i; - mpf_t u, v, w1, w2, w3; - mp_size_t bprec = 100; - mpf_t rerr, limit_rerr; - mp_size_t un; - mp_exp_t ue; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init (rerr); - mpf_init (limit_rerr); - - mpf_init (u); - mpf_init (v); - mpf_init (w1); - mpf_init (w2); - mpf_init (w3); - - for (i = 0; i < reps; i++) - { - unsigned long int res_prec; - unsigned long int pow2; - - res_prec = urandom () % (bprec + 100); - mpf_set_prec (w1, res_prec); - mpf_set_prec (w2, res_prec); - mpf_set_prec (w3, res_prec); - - mpf_set_ui (limit_rerr, 1); - mpf_div_2exp (limit_rerr, limit_rerr, res_prec); - - pow2 = urandom () % 0x10000; - mpf_set_ui (v, 1); - mpf_mul_2exp (v, v, pow2); - - un = urandom () % (2 * SIZE) - SIZE; - ue = urandom () % SIZE; - mpf_random2 (u, un, ue); - - mpf_div_2exp (w1, u, pow2); - mpf_div (w2, u, v); - mpf_reldiff (rerr, w1, w2); - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR in mpf_div or mpf_div_2exp after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf (" w1 = "); mpf_dump (w1); - printf (" w2 = "); mpf_dump (w2); - abort (); - } - mpf_mul_2exp (w3, w1, pow2); - mpf_reldiff (rerr, u, w3); - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR in mpf_mul_2exp after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf (" w1 = "); mpf_dump (w1); - printf (" w3 = "); mpf_dump (w3); - abort (); - } - } - - exit (0); -} - -oo (x) - mpf_t x; -{ - mp_size_t i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} diff --git a/gmp/mpf/tests/t-get_d.c b/gmp/mpf/tests/t-get_d.c deleted file mode 100755 index 91d5a65..0000000 --- a/gmp/mpf/tests/t-get_d.c +++ /dev/null @@ -1,61 +0,0 @@ -/* Test mpf_get_d and mpf_set_d. - - Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc. - - This file is part of the GNU MP Library. - - The GNU MP Library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - The GNU MP Library 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. - - You should have received a copy of the GNU Lesser General Public License - along with the GNU MP Library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. */ - -#include "gmp.h" - -#ifdef __vax__ -#define LOW_BOUND 1e-38 -#define HIGH_BOUND 8e37 -#else -#define LOW_BOUND 1e-300 -#define HIGH_BOUND 1e300 -#endif - -int -#if __STDC__ -main (int argc, char **argv) -#else -main (argc, argv) - int argc; - char **argv; -#endif -{ - double d, e, r; - mpf_t u, v; - - mpf_init (u); - mpf_init (v); - - mpf_set_d (u, LOW_BOUND); - for (d = 2.0 * LOW_BOUND; d < HIGH_BOUND; d *= 1.01) - { - mpf_set_d (v, d); - if (mpf_cmp (u, v) >= 0) - abort (); - e = mpf_get_d (v); - r = e/d; - if (r < 0.99999999999999 | r > 1.00000000000001) - abort (); - mpf_set (u, v); - } - - exit (0); -} diff --git a/gmp/mpf/tests/t-misc.c b/gmp/mpf/tests/t-misc.c deleted file mode 100755 index 8d79cb7..0000000 --- a/gmp/mpf/tests/t-misc.c +++ /dev/null @@ -1,155 +0,0 @@ -/* Exercise various mpf functions. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#define SGN(x) ((x) < 0 ? -1 : (x) == 0 ? 0 : 1) - - -void -check_mpf_set_si (void) -{ - static const struct { - long x; - mp_size_t want_size; - mp_limb_t want_limb; - } data[] = { - - { 0L, 0 }, - { 1L, 1, 1 }, - { -1L, -1, 1 }, - - { LONG_MAX, 1, LONG_MAX }, - { -LONG_MAX, -1, LONG_MAX }, - - { LONG_HIGHBIT, -1, ULONG_HIGHBIT }, - }; - - mpf_t x; - int i; - - mpf_init (x); - for (i = 0; i < numberof (data); i++) - { - mpf_init (x); - mpf_set_si (x, data[i].x); - if (x->_mp_size != data[i].want_size - || (x->_mp_size != 0 && x->_mp_d[0] != data[i].want_limb) - || (x->_mp_exp != (data[i].x != 0))) - { - printf ("mpf_set_si wrong on data[%d]\n", i); - abort(); - } - mpf_clear (x); - - mpf_init_set_si (x, data[i].x); - if (x->_mp_size != data[i].want_size - || (x->_mp_size != 0 && x->_mp_d[0] != data[i].want_limb) - || (x->_mp_exp != (data[i].x != 0))) - { - printf ("mpf_init_set_si wrong on data[%d]\n", i); - abort(); - } - mpf_clear (x); - } -} - - -void -check_mpf_cmp_si (void) -{ - static const struct { - int a_base; - const char *a; - const char *b; - int want; - } data[] = { - { 10, "0", "1", -1 }, - { 10, "0", "0", 0 }, - { 10, "0", "-1", 1 }, - - { 10, "1", "1", 0 }, - { 10, "1", "0", 1 }, - { 10, "1", "-1", 1 }, - - { 10, "-1", "1", -1 }, - { 10, "-1", "0", -1 }, - { 10, "-1", "-1", 0 }, - - { 16, "0", "-0x80000000", 1 }, - { 16, "80000000", "-0x80000000", 1 }, - { 16, "80000001", "-0x80000000", 1 }, - { 16, "-80000000", "-0x80000000", 0 }, - { 16, "-80000001", "-0x80000000", -1 }, - - { 16, "0", "-0x8000000000000000", 1 }, - { 16, "8000000000000000", "-0x8000000000000000", 1 }, - { 16, "8000000000000001", "-0x8000000000000000", 1 }, - { 16, "-8000000000000000", "-0x8000000000000000", 0 }, - { 16, "-8000000000000001", "-0x8000000000000000", -1 }, - }; - - mpf_t a; - mpz_t bz; - long b; - int got; - int i; - - mpf_init (a); - mpz_init (bz); - for (i = 0; i < numberof (data); i++) - { - mpf_set_str (a, data[i].a, data[i].a_base); - mpz_set_str (bz, data[i].b, 0); - - if (mpz_fits_slong_p (bz)) - { - b = mpz_get_si (bz); - got = mpf_cmp_si (a, b); - if (SGN (got) != data[i].want) - { - printf ("mpf_cmp_si wrong on data[%d]\n", i); - printf (" a="); mpf_out_str (stdout, 10, 0, a); - printf (" (%s)\n", data[i].a); - printf (" b=%ld (%s)\n", b, data[i].b); - printf (" got=%d\n", got); - printf (" want=%d\n", data[i].want); - abort(); - } - } - } - - mpf_clear (a); - mpz_clear (bz); -} - - -int -main (void) -{ - check_mpf_set_si (); - check_mpf_cmp_si (); - exit (0); -} diff --git a/gmp/mpf/tests/t-muldiv.c b/gmp/mpf/tests/t-muldiv.c deleted file mode 100755 index 7665d99..0000000 --- a/gmp/mpf/tests/t-muldiv.c +++ /dev/null @@ -1,161 +0,0 @@ -/* Test mpf_mul, mpf_div, mpf_ui_div, and mpf_div_ui. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mp_size_t size; - mp_exp_t exp; - int reps = 100000; - int i; - mpf_t u, v, w, x; - mp_size_t bprec = SIZE * BITS_PER_MP_LIMB; - mpf_t rerr, limit_rerr; - mp_limb_t ulimb, vlimb; - int single_flag; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init (rerr); - mpf_init (limit_rerr); - - mpf_init (u); - mpf_init (v); - mpf_init (w); - mpf_init (x); - - for (i = 0; i < reps; i++) - { - mp_size_t res_prec; - - res_prec = urandom () % bprec + 1; - mpf_set_prec (w, res_prec); - mpf_set_prec (x, res_prec); - - mpf_set_ui (limit_rerr, 1); - mpf_div_2exp (limit_rerr, limit_rerr, res_prec - 1); - - single_flag = 0; - - if ((urandom () & 1) != 0) - { - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % SIZE; - mpf_random2 (u, size, exp); - } - else - { - ulimb = urandom (); - mpf_set_ui (u, ulimb); - single_flag = 1; - } - - if ((urandom () & 1) != 0) - { - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % SIZE; - mpf_random2 (v, size, exp); - } - else - { - vlimb = urandom (); - mpf_set_ui (v, vlimb); - single_flag = 2; - } - - if (mpf_sgn (v) == 0) - continue; - - mpf_div (w, u, v); - mpf_mul (x, w, v); - mpf_reldiff (rerr, u, x); - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR in mpf_mul or mpf_div after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf (" x = "); mpf_dump (x); - printf (" w = "); mpf_dump (w); - abort (); - } - - if (single_flag == 2) - { - mpf_div_ui (x, u, vlimb); - mpf_reldiff (rerr, w, x); - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR in mpf_div or mpf_div_ui after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf (" x = "); mpf_dump (x); - printf (" w = "); mpf_dump (w); - abort (); - } - } - - if (single_flag == 1) - { - mpf_ui_div (x, ulimb, v); - mpf_reldiff (rerr, w, x); - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR in mpf_div or mpf_ui_div after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf (" x = "); mpf_dump (x); - printf (" w = "); mpf_dump (w); - abort (); - } - } - } - - exit (0); -} - -oo (x) - mpf_t x; -{ - mp_size_t i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} diff --git a/gmp/mpf/tests/t-sqrt.c b/gmp/mpf/tests/t-sqrt.c deleted file mode 100755 index 7567151..0000000 --- a/gmp/mpf/tests/t-sqrt.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Test mpf_sqrt, mpf_mul. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mp_size_t size; - mp_exp_t exp; - int reps = 100000; - int i; - mpf_t x, y, y2; - mp_size_t bprec = 100; - mpf_t rerr, max_rerr, limit_rerr; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init_set_ui (limit_rerr, 1); - mpf_div_2exp (limit_rerr, limit_rerr, bprec); -#if VERBOSE - mpf_dump (limit_rerr); -#endif - mpf_init (rerr); - mpf_init_set_ui (max_rerr, 0); - - mpf_init (x); - mpf_init (y); - mpf_init (y2); - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE; - exp = urandom () % SIZE; - mpf_random2 (x, size, exp); - - mpf_sqrt (y, x); - mpf_mul (y2, y, y); - - mpf_reldiff (rerr, x, y2); - if (mpf_cmp (rerr, max_rerr) > 0) - { - mpf_set (max_rerr, rerr); -#if VERBOSE - mpf_dump (max_rerr); -#endif - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR after %d tests\n", i); - printf (" x = "); mpf_dump (x); - printf (" y = "); mpf_dump (y); - printf (" y2 = "); mpf_dump (y2); - abort (); - } - } - } - - exit (0); -} - -oo (x) - mpf_t x; -{ - mp_size_t i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} diff --git a/gmp/mpf/tests/t-sub.c b/gmp/mpf/tests/t-sub.c deleted file mode 100755 index ff99458..0000000 --- a/gmp/mpf/tests/t-sub.c +++ /dev/null @@ -1,122 +0,0 @@ -/* Test mpf_sub. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 16 -#endif - -#if __STDC__ -void ref_mpf_add (mpf_t, const mpf_t, const mpf_t); -void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t); -#else -void ref_mpf_add (); -void ref_mpf_sub (); -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mp_size_t size; - mp_exp_t exp; - int reps = 500000; - int i; - mpf_t u, v, w, wref; - mp_size_t bprec = 100; - mpf_t rerr, max_rerr, limit_rerr; - - if (argc > 1) - { - reps = strtol (argv[1], 0, 0); - if (argc > 2) - bprec = strtol (argv[2], 0, 0); - } - - mpf_set_default_prec (bprec); - - mpf_init_set_ui (limit_rerr, 1); - mpf_div_2exp (limit_rerr, limit_rerr, bprec); -#if VERBOSE - mpf_dump (limit_rerr); -#endif - mpf_init (rerr); - mpf_init_set_ui (max_rerr, 0); - - mpf_init (u); - mpf_init (v); - mpf_init (w); - mpf_init (wref); - for (i = 0; i < reps; i++) - { - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % SIZE; - mpf_random2 (u, size, exp); - - size = urandom () % (2 * SIZE) - SIZE; - exp = urandom () % SIZE; - mpf_random2 (v, size, exp); - - if ((urandom () & 1) != 0) - mpf_add_ui (u, v, 1); - else if ((urandom () & 1) != 0) - mpf_sub_ui (u, v, 1); - - mpf_sub (w, u, v); - ref_mpf_sub (wref, u, v); - - mpf_reldiff (rerr, w, wref); - if (mpf_cmp (rerr, max_rerr) > 0) - { - mpf_set (max_rerr, rerr); -#if VERBOSE - mpf_dump (max_rerr); -#endif - if (mpf_cmp (rerr, limit_rerr) > 0) - { - printf ("ERROR after %d tests\n", i); - printf (" u = "); mpf_dump (u); - printf (" v = "); mpf_dump (v); - printf ("wref = "); mpf_dump (wref); - printf (" w = "); mpf_dump (w); - abort (); - } - } - } - - exit (0); -} - -oo (x) - mpf_t x; -{ - mp_size_t i; - printf (" exp = %ld\n", x->_mp_exp); - printf ("size = %d\n", x->_mp_size); - for (i = ABS (x->_mp_size) - 1; i >= 0; i--) - printf ("%08lX ", x->_mp_d[i]); - printf ("\n"); - mpf_dump (x); -} diff --git a/gmp/mpf/ui_div.c b/gmp/mpf/ui_div.c deleted file mode 100755 index 11dc801..0000000 --- a/gmp/mpf/ui_div.c +++ /dev/null @@ -1,132 +0,0 @@ -/* mpf_ui_div -- Divide an unsigned integer with a float. - -Copyright (C) 1993, 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpf_ui_div (mpf_ptr r, unsigned long int u, mpf_srcptr v) -#else -mpf_ui_div (r, u, v) - mpf_ptr r; - unsigned long int u; - mpf_srcptr v; -#endif -{ - mp_srcptr vp; - mp_ptr rp, tp; - mp_size_t vsize; - mp_size_t rsize, tsize; - mp_size_t sign_quotient; - mp_size_t prec; - unsigned normalization_steps; - mp_limb_t q_limb; - mp_exp_t rexp; - TMP_DECL (marker); - - vsize = v->_mp_size; - sign_quotient = vsize; - vsize = ABS (vsize); - prec = r->_mp_prec; - - if (vsize == 0) - DIVIDE_BY_ZERO; - - if (u == 0) - { - r->_mp_size = 0; - r->_mp_exp = 0; - return; - } - - TMP_MARK (marker); - rexp = 1 - v->_mp_exp; - - rp = r->_mp_d; - vp = v->_mp_d; - - if (vsize > prec) - { - vp += vsize - prec; - vsize = prec; - } - - tsize = vsize + prec; - tp = (mp_ptr) TMP_ALLOC ((tsize + 1) * BYTES_PER_MP_LIMB); - MPN_ZERO (tp, tsize); - - count_leading_zeros (normalization_steps, vp[vsize - 1]); - - /* Normalize the divisor and the dividend. */ - if (normalization_steps != 0) - { - mp_ptr tmp; - mp_limb_t dividend_high, dividend_low; - - /* Shift up the divisor setting the most significant bit of - the most significant limb. Use temporary storage not to clobber - the original contents of the divisor. */ - tmp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - mpn_lshift (tmp, vp, vsize, normalization_steps); - vp = tmp; - - /* Shift up the dividend, possibly introducing a new most - significant word. */ - dividend_high = (mp_limb_t) u >> (BITS_PER_MP_LIMB - normalization_steps); - dividend_low = (mp_limb_t) u << normalization_steps; - - tp[tsize - 1] = dividend_low; - if (dividend_high != 0) - { - tp[tsize] = dividend_high; - tsize++; - rexp++; - } - } - else - { - /* The divisor is already normalized, as required. - Copy it to temporary space if it overlaps with the quotient. */ - if (vp - rp <= tsize - vsize) - { - mp_ptr tmp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - MPN_COPY (tmp, vp, vsize); - vp = (mp_srcptr) tmp; - } - - tp[tsize - 1] = u; - } - - q_limb = mpn_divmod (rp, tp, tsize, vp, vsize); - rsize = tsize - vsize; - if (q_limb) - { - rp[rsize] = q_limb; - rsize++; - rexp++; - } - - r->_mp_size = sign_quotient >= 0 ? rsize : -rsize; - r->_mp_exp = rexp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/ui_sub.c b/gmp/mpf/ui_sub.c deleted file mode 100755 index 3219fab..0000000 --- a/gmp/mpf/ui_sub.c +++ /dev/null @@ -1,334 +0,0 @@ -/* mpf_ui_sub -- Subtract a float from an unsigned long int. - -Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_ui_sub (mpf_ptr r, unsigned long int u, mpf_srcptr v) -#else -mpf_ui_sub (r, u, v) - mpf_ptr r; - unsigned long int u; - mpf_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_ptr rp, tp; - mp_size_t usize, vsize, rsize; - mp_size_t prec; - mp_exp_t uexp; - mp_size_t ediff; - int negate; - mp_limb_t ulimb; - TMP_DECL (marker); - - vsize = v->_mp_size; - - /* Handle special cases that don't work in generic code below. */ - if (u == 0) - { - mpf_neg (r, v); - return; - } - if (vsize == 0) - { - mpf_set_ui (r, u); - return; - } - - /* If signs of U and V are different, perform addition. */ - if (vsize < 0) - { - __mpf_struct v_negated; - v_negated._mp_size = -vsize; - v_negated._mp_exp = v->_mp_exp; - v_negated._mp_d = v->_mp_d; - mpf_add_ui (r, &v_negated, u); - return; - } - - TMP_MARK (marker); - - /* Signs are now known to be the same. */ - - ulimb = u; - /* Make U be the operand with the largest exponent. */ - if (1 < v->_mp_exp) - { - negate = 1; - usize = ABS (vsize); - vsize = 1; - up = v->_mp_d; - vp = &ulimb; - rp = r->_mp_d; - prec = r->_mp_prec + 1; - uexp = v->_mp_exp; - ediff = uexp - 1; - } - else - { - negate = 0; - usize = 1; - vsize = ABS (vsize); - up = &ulimb; - vp = v->_mp_d; - rp = r->_mp_d; - prec = r->_mp_prec; - uexp = 1; - ediff = 1 - v->_mp_exp; - } - - /* Ignore leading limbs in U and V that are equal. Doing - this helps increase the precision of the result. */ - if (ediff == 0) - { - /* This loop normally exits immediately. Optimize for that. */ - for (;;) - { - usize--; - vsize--; - if (up[usize] != vp[vsize]) - break; - uexp--; - if (usize == 0) - goto Lu0; - if (vsize == 0) - goto Lv0; - } - usize++; - vsize++; - /* Note that either operand (but not both operands) might now have - leading zero limbs. It matters only that U is unnormalized if - vsize is now zero, and vice versa. And it is only in that case - that we have to adjust uexp. */ - if (vsize == 0) - Lv0: - while (usize != 0 && up[usize - 1] == 0) - usize--, uexp--; - if (usize == 0) - Lu0: - while (vsize != 0 && vp[vsize - 1] == 0) - vsize--, uexp--; - } - - /* If U extends beyond PREC, ignore the part that does. */ - if (usize > prec) - { - up += usize - prec; - usize = prec; - } - - /* If V extends beyond PREC, ignore the part that does. - Note that this may make vsize negative. */ - if (vsize + ediff > prec) - { - vp += vsize + ediff - prec; - vsize = prec - ediff; - } - - /* Allocate temp space for the result. Allocate - just vsize + ediff later??? */ - tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB); - - if (ediff >= prec) - { - /* V completely cancelled. */ - if (tp != up) - MPN_COPY (rp, up, usize); - rsize = usize; - } - else - { - /* Locate the least significant non-zero limb in (the needed - parts of) U and V, to simplify the code below. */ - for (;;) - { - if (vsize == 0) - { - MPN_COPY (rp, up, usize); - rsize = usize; - goto done; - } - if (vp[0] != 0) - break; - vp++, vsize--; - } - for (;;) - { - if (usize == 0) - { - MPN_COPY (rp, vp, vsize); - rsize = vsize; - negate ^= 1; - goto done; - } - if (up[0] != 0) - break; - up++, usize--; - } - - /* uuuu | uuuu | uuuu | uuuu | uuuu */ - /* vvvvvvv | vv | vvvvv | v | vv */ - - if (usize > ediff) - { - /* U and V partially overlaps. */ - if (ediff == 0) - { - /* Have to compare the leading limbs of u and v - to determine whether to compute u - v or v - u. */ - if (usize > vsize) - { - /* uuuu */ - /* vv */ - int cmp; - cmp = mpn_cmp (up + usize - vsize, vp, vsize); - if (cmp >= 0) - { - mp_size_t size; - size = usize - vsize; - MPN_COPY (tp, up, size); - mpn_sub_n (tp + size, up + size, vp, vsize); - rsize = usize; - } - else - { - /* vv */ /* Swap U and V. */ - /* uuuu */ - mp_size_t size, i; - size = usize - vsize; - tp[0] = -up[0]; - for (i = 1; i < size; i++) - tp[i] = ~up[i]; - mpn_sub_n (tp + size, vp, up + size, vsize); - mpn_sub_1 (tp + size, tp + size, vsize, (mp_limb_t) 1); - negate ^= 1; - rsize = usize; - } - } - else if (usize < vsize) - { - /* uuuu */ - /* vvvvvvv */ - int cmp; - cmp = mpn_cmp (up, vp + vsize - usize, usize); - if (cmp > 0) - { - mp_size_t size, i; - size = vsize - usize; - tp[0] = -vp[0]; - for (i = 1; i < size; i++) - tp[i] = ~vp[i]; - mpn_sub_n (tp + size, up, vp + size, usize); - mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); - rsize = vsize; - } - else - { - /* vvvvvvv */ /* Swap U and V. */ - /* uuuu */ - /* This is the only place we can get 0.0. */ - mp_size_t size; - size = vsize - usize; - MPN_COPY (tp, vp, size); - mpn_sub_n (tp + size, vp + size, up, usize); - negate ^= 1; - rsize = vsize; - } - } - else - { - /* uuuu */ - /* vvvv */ - int cmp; - cmp = mpn_cmp (up, vp + vsize - usize, usize); - if (cmp > 0) - { - mpn_sub_n (tp, up, vp, usize); - rsize = usize; - } - else - { - mpn_sub_n (tp, vp, up, usize); - negate ^= 1; - rsize = usize; - /* can give zero */ - } - } - } - else - { - if (vsize + ediff <= usize) - { - /* uuuu */ - /* v */ - mp_size_t size; - size = usize - ediff - vsize; - MPN_COPY (tp, up, size); - mpn_sub (tp + size, up + size, usize - size, vp, vsize); - rsize = usize; - } - else - { - /* uuuu */ - /* vvvvv */ - mp_size_t size, i; - size = vsize + ediff - usize; - tp[0] = -vp[0]; - for (i = 1; i < size; i++) - tp[i] = ~vp[i]; - mpn_sub (tp + size, up, usize, vp + size, usize - ediff); - mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); - rsize = vsize + ediff; - } - } - } - else - { - /* uuuu */ - /* vv */ - mp_size_t size, i; - size = vsize + ediff - usize; - tp[0] = -vp[0]; - for (i = 1; i < vsize; i++) - tp[i] = ~vp[i]; - for (i = vsize; i < size; i++) - tp[i] = ~(mp_limb_t) 0; - mpn_sub_1 (tp + size, up, usize, (mp_limb_t) 1); - rsize = size + usize; - } - - /* Full normalize. Optimize later. */ - while (rsize != 0 && tp[rsize - 1] == 0) - { - rsize--; - uexp--; - } - MPN_COPY (rp, tp, rsize); - } - - done: - r->_mp_size = negate ? -rsize : rsize; - r->_mp_exp = uexp; - TMP_FREE (marker); -} diff --git a/gmp/mpf/urandomb.c b/gmp/mpf/urandomb.c deleted file mode 100755 index db4c0f9..0000000 --- a/gmp/mpf/urandomb.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpf_urandomb (rop, state, nbits) -- Generate a uniform pseudorandom - real number between 0 (inclusive) and 1 (exclusive) of size NBITS, - using STATE as the random state previously initialized by a call to - gmp_randinit(). - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpf_urandomb (mpf_t rop, gmp_randstate_t rstate, unsigned long int nbits) -#else -mpf_urandomb (rop, rstate, nbits) - mpf_t rop; - gmp_randstate_t rstate; - unsigned long int nbits; -#endif -{ - mp_ptr rp; - mp_size_t nlimbs; - mp_exp_t exp; - - rp = PTR (rop); - nlimbs = (nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - - _gmp_rand (rp, rstate, nbits); - - /* If nbits isn't a multiple of BITS_PER_MP_LIMB, shift up. */ - if (nlimbs != 0) - { - if (nbits % BITS_PER_MP_LIMB != 0) - mpn_lshift (rp, rp, nlimbs, - BITS_PER_MP_LIMB - nbits % BITS_PER_MP_LIMB); - } - - exp = 0; - while (nlimbs != 0 && rp[nlimbs - 1] == 0) - { - nlimbs--; - exp--; - } - EXP (rop) = exp; - SIZ (rop) = nlimbs; - -} diff --git a/gmp/mpfr/Makefile.am b/gmp/mpfr/Makefile.am deleted file mode 100755 index 20f9dc3..0000000 Binary files a/gmp/mpfr/Makefile.am and /dev/null differ diff --git a/gmp/mpfr/Makefile.in b/gmp/mpfr/Makefile.in deleted file mode 100755 index e41ede9..0000000 Binary files a/gmp/mpfr/Makefile.in and /dev/null differ diff --git a/gmp/mpfr/README b/gmp/mpfr/README deleted file mode 100755 index 79b4a5d..0000000 Binary files a/gmp/mpfr/README and /dev/null differ diff --git a/gmp/mpfr/add.c b/gmp/mpfr/add.c deleted file mode 100755 index c9bebe4..0000000 --- a/gmp/mpfr/add.c +++ /dev/null @@ -1,404 +0,0 @@ -/* mpfr_add -- add two floating-point numbers - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -extern void mpfr_sub1 _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - unsigned char, int)); - -#define ONE ((mp_limb_t) 1) - -/* signs of b and c are supposed equal, - diff_exp is the difference between the exponents of b and c, - which is supposed >= 0 */ - -void -#if __STDC__ -mpfr_add1(mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, - unsigned char rnd_mode, int diff_exp) -#else -mpfr_add1(a, b, c, rnd_mode, diff_exp) - mpfr_ptr a; - mpfr_srcptr b; - mpfr_srcptr c; - unsigned char rnd_mode; - int diff_exp; -#endif -{ - mp_limb_t *ap, *bp, *cp, cc, c2, c3=0; unsigned int an,bn,cn; int sh,dif,k; - TMP_DECL(marker); - - TMP_MARK(marker); - ap = MANT(a); - bp = MANT(b); - cp = MANT(c); - if (ap == bp) { - bp = (mp_ptr) TMP_ALLOC(ABSSIZE(b) * BYTES_PER_MP_LIMB); - MPN_COPY (bp, ap, ABSSIZE(b)); - if (ap == cp) { cp = bp; } - } - else if (ap == cp) - { - cp = (mp_ptr) TMP_ALLOC (ABSSIZE(c) * BYTES_PER_MP_LIMB); - MPN_COPY(cp, ap, ABSSIZE(c)); - } - - an = (PREC(a)-1)/mp_bits_per_limb+1; /* number of significant limbs of a */ - - sh = an*mp_bits_per_limb-PREC(a); /* non-significant bits in low limb */ - bn = (PREC(b)-1)/mp_bits_per_limb+1; /* number of significant limbs of b */ - EXP(a) = EXP(b); - - if (SIGN(a)!=SIGN(b)) CHANGE_SIGN(a); - - /* case 1: diff_exp>=prec(a), i.e. c only affects the last bit - through rounding */ - dif = PREC(a)-diff_exp; - - if (dif<=0) { - - /* diff_exp>=PREC(a): c does not overlap with a */ - /* either PREC(b)<=PREC(a), and we can copy the mantissa of b directly - into that of a, or PREC(b)>PREC(a) and we have to round b+c */ - - if (PREC(b)<=PREC(a)) { - - MPN_COPY(ap+(an-bn), bp, bn); - /* fill low significant limbs with zero */ - - for (bp=ap;bn PREC(a), no change */ - - if (diff_exp==PREC(a)) { - - /* if c is not zero, then as it is normalized, we have to add - one to the lsb of a if c>1/2, or c=1/2 and lsb(a)=1 (round to - even) */ - - if (NOTZERO(c)) { - - /* c is not zero */ - /* check whether mant(c)=1/2 or not */ - - cc = *cp - (ONE<<(mp_bits_per_limb-1)); - if (cc==0) { - bp = cp+(PREC(c)-1)/mp_bits_per_limb; - while (cpPREC(a) : we have to round b+c */ - k=bn-an; - - /* first copy the 'an' most significant limbs of b to a */ - MPN_COPY(ap, bp+k, an); - if (rnd_mode==GMP_RNDN) { - - /* to nearest */ - /* first check whether the truncated bits from b are 1/2*lsb(a) */ - - if (sh) { - cc = *ap & ((ONE<0) goto add_one_ulp; /* trunc(b)>1/2*lsb(a) -> round up */ - else if (cc==0) { - - while (k>1 && cc==0) cc=bp[--k]; - - /* now if the truncated part of b = 1/2*lsb(a), check whether c=0 */ - if (NOTZERO(c) || (*ap & (ONE< round down, i.e. do nothing */ - } - else if ((ISNONNEG(b) && rnd_mode==GMP_RNDU) || - (ISNEG(b) && rnd_mode==GMP_RNDD)) { - - /* first check whether trunc(b)+c is zero or not */ - if (sh) { - cc = *ap & ((ONE<1) cc=bp[--k]; - if (cc || NOTZERO(c)) goto add_one_ulp; - } - - /* in the other cases (round to zero, or up/down with sign -/+), - nothing to do, since b and c don't overlap, there can't be any - carry */ - - } - } - else { - /* diff_exp < PREC(a) : c overlaps with a by dif bits */ - /* first copy upper part of c into a (after shift) */ - unsigned char overlap; - - k = (dif-1)/mp_bits_per_limb + 1; /* only the highest k limbs from c - have to be considered */ - cn = (PREC(c)-1)/mp_bits_per_limb + 1; - MPN_ZERO(ap+k, an-k); /* do it now otherwise ap[k] may be destroyed - in case dif<0 */ - - if (dif<=PREC(c)) { - /* c has to be truncated */ - dif = dif % mp_bits_per_limb; - dif = (dif) ? mp_bits_per_limb-dif-sh : -sh; - - /* we have to shift by dif bits to the right */ - - if (dif>0) mpn_rshift(ap, cp+(cn-k), k, dif); - else if (dif<0) { - ap[k] = mpn_lshift(ap, cp+(cn-k), k, -dif); - - /* put the non-significant bits in low limb for further rounding */ - - if (cn >= k+1) - ap[0] += cp[cn-k-1]>>(mp_bits_per_limb+dif); - } - else MPN_COPY(ap, cp+(cn-k), k); - overlap=1; - } - else { - - /* c is not truncated, but we have to fill low limbs with 0 */ - - k = diff_exp/mp_bits_per_limb; - overlap = diff_exp%mp_bits_per_limb; - - /* warning: a shift of zero bit is not allowed */ - MPN_ZERO(ap, an-k-cn); - if (overlap) { - cc=mpn_rshift(ap+(an-k-cn), cp, cn, overlap); - if (an-k-cn>0) ap[an-k-cn-1]=cc; - } - else MPN_COPY(ap+(an-k-cn), cp, cn); - overlap=0; - } - - /* here overlap=1 iff ulp(c) PREC(a): we have to truncate b */ - cc = mpn_add_n(ap, ap, bp+(bn-an), an); - - if (cc) { - - /* shift one bit to the right */ - - c3 = (ap[0]&1) && (PREC(a)%mp_bits_per_limb==0); - mpn_rshift(ap, ap, an, 1); - ap[an-1] += ONE<<(mp_bits_per_limb-1); - EXP(a)++; - } - - /* remains to do the rounding */ - - if (rnd_mode==GMP_RNDN) { - - /* to nearest */ - - int kc; - - /* four cases: overlap = - (0) PREC(b) > PREC(a) and diff_exp+PREC(c) <= PREC(a) - (1) PREC(b) > PREC(a) and diff_exp+PREC(c) > PREC(a) - (2) PREC(b) <= PREC(a) and diff_exp+PREC(c) <= PREC(a) - (3) PREC(b) <= PREC(a) and diff_exp+PREC(c) > PREC(a) */ - - switch (overlap) - { - case 1: /* both b and c to round */ - kc = cn-k; /* remains kc limbs from c */ - k = bn-an; /* remains k limbs from b */ - - /* truncate last bits and store the difference with 1/2*ulp in cc */ - - cc = *ap & ((ONE<>dif)); - if (cc==0 || cc==-1) cc=c2; - } - if ((long)cc>0) goto add_one_ulp; - else if ((long)cc<-1) - { TMP_FREE(marker); return; /* the carry can be at most 1 */ } - else if (kc==0) goto round_b; - - /* else round c: go through */ - - case 3: /* only c to round */ - bp=cp; k=cn-k; goto to_nearest; - - case 0: /* only b to round */ - round_b: - k=bn-an; dif=0; goto to_nearest; - - /* otherwise the result is exact: nothing to do */ - } - } - else if ((ISNONNEG(b) && rnd_mode==GMP_RNDU) || - (ISNEG(b) && rnd_mode==GMP_RNDD)) { - cc = *ap & ((ONE<>dif)); - } - if (cc) goto add_one_ulp; - else if (kc==0) goto round_b2; - /* else round c: go through */ - case 3: /* only c to round */ - while (kc) if (cp[--kc]) goto add_one_ulp; - /* if dif>0 : remains to check last dif bits from c */ - if (dif>0 && (cp[0]<<(mp_bits_per_limb-dif))) goto add_one_ulp; - break; - case 0: /* only b to round */ - round_b2: - k=bn-an; - while (k) if (bp[--k]) goto add_one_ulp; - /* otherwise the result is exact: nothing to do */ - } - } - } - /* else nothing to do: round towards zero, i.e. truncate last sh bits */ - else - *ap &= ~((ONE<c2) goto add_one_ulp; /* trunc(b)>1/2*lsb(a) -> round up */ - else if (cc==c2) { - cc=0; while (k && cc==0) cc=bp[--k]; - /* special case of rouding c shifted to the right */ - if (cc==0 && dif>0) cc=cp[0]<<(mp_bits_per_limb-dif); - /* now if the truncated part of b = 1/2*lsb(a), check whether c=0 */ - if (cc || (*ap & (ONE<0) mpfr_sub1(a, b, c, rnd_mode, diff_exp); - else { /* diff_exp=0 */ - diff_exp = mpfr_cmp3(b,c,-1); - /* if b>0 and diff_exp>0 or b<0 and diff_exp<0: abs(b) > abs(c) */ - if (diff_exp==0) SET_ZERO(a); - else if (diff_exp*SIGN(b)>0) mpfr_sub1(a, b, c, rnd_mode, 0); - else mpfr_sub1(a, c, b, rnd_mode, 0); - } - } - else /* signs are equal, it's an addition */ - if (diff_exp<0) mpfr_add1(a, c, b, rnd_mode, -diff_exp); - else mpfr_add1(a, b, c, rnd_mode, diff_exp); -} - diff --git a/gmp/mpfr/add_ulp.c b/gmp/mpfr/add_ulp.c deleted file mode 100755 index 7a8fa61..0000000 --- a/gmp/mpfr/add_ulp.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpfr_add_one_ulp, mpfr_sub_one_ulp -- add/subtract one unit in last place - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -/* sets x to x+sign(x)*2^(EXP(x)-PREC(x)) */ -int -#if __STDC__ -mpfr_add_one_ulp(mpfr_ptr x) -#else -mpfr_add_one_ulp(x) - mpfr_ptr x; -#endif -{ - int xn, sh; mp_limb_t *xp; - - xn = 1 + (PREC(x)-1)/BITS_PER_MP_LIMB; - sh = xn*BITS_PER_MP_LIMB - PREC(x); - xp = MANT(x); - if (mpn_add_1(xp, xp, xn, (mp_limb_t)1<> (BITS_PER_MP_LIMB-1) == 0) { - /* was an exact power of two: not normalized any more */ - EXP(x)--; - mpn_lshift(xp, xp, xn, 1); - *xp |= ((mp_limb_t)1 << sh); - } - return 0; -} diff --git a/gmp/mpfr/agm.c b/gmp/mpfr/agm.c deleted file mode 100755 index e4c7009..0000000 --- a/gmp/mpfr/agm.c +++ /dev/null @@ -1,172 +0,0 @@ -/* mpfr_agm -- arithmetic-geometric mean of two floating-point numbers - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - - -/*Memory gestion */ -#define MON_INIT(xp, x, p, s) xp = (mp_ptr) TMP_ALLOC(s*BYTES_PER_MP_LIMB); x -> _mp_prec = p; x -> _mp_d = xp; x -> _mp_size = s; x -> _mp_exp = 0; - - - - -void -#ifdef __STDC__ -mpfr_agm(mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, unsigned char rnd_mode) -#else -mpfr_agm(r, a, b, rnd_mode) - mpfr_ptr r; - mpfr_srcptr a; - mpfr_srcptr b; - unsigned char rnd_mode; -#endif -{ - int s, p, q, go_on; - double uo, vo; - mp_limb_t *up, *vp, *tmpp, *tmpup, *tmpvp, *ap, *bp; - mpfr_t u, v, tmp, tmpu, tmpv, a, b; - TMP_DECL(marker1); - TMP_DECL(marker2); - - - /* If a or b is NaN, the result is NaN */ - if (FLAG_NAN(op1) || FLAG_NAN(op2)) - { SET_NAN(r); return; } - - - /* If a or b is negative, the result is NaN */ - if ((SIGN(op1)<0)||(SIGN(op2)<0)) - { SET_NAN(r); return; } - - - - /* If a or b is 0, the result is 0 */ - if ((SIGN(op1)==0)||(SIGN(op2)==0)) - { SET_ZERO(r); - return; - } - - /* precision of the following calculus */ - q = PREC(r); - p = q + 15; - - - /* Initialisations */ - go_on=1; - - TMP_MARK(marker1); - s=(p-1)/BITS_PER_MP_LIMB+1; - MON_INIT(ap, a, p, s); - MON_INIT(bp, b, p, s); - TMP_MARK(marker2); - MON_INIT(up, u, p, s); - MON_INIT(vp, v, p, s); - MON_INIT(tmpup, tmpu, p, s); - MON_INIT(tmpvp, tmpv, p, s); - MON_INIT(tmpp, tmp, p, s); - - - - /* b and a will be the 2 operands but I want b>= a */ - if (mpfr_cmp(op1,op2) > 0) { - mpfr_set(b,op1,GMP_RNDN); mpfr_set(a,op2,GMP_RNDN); - } - else { - mpfr_set(b,op2,GMP_RNDN); mpfr_set(a,op1,GMP_RNDN); - } - - vo=mpfr_get_d(b); - uo=mpfr_get_d(a); - - mpfr_set(u,a,GMP_RNDN); - mpfr_set(v,b,GMP_RNDN); - - - /* Main loop */ - - while (go_on) { - int err, eq, can_round; - - eq=0; - - err=ceil((3.0/2.0*log((double)p)/log(2.0)+1.0)*exp(-(double)p*log(2.0))+3.0*exp(-2.0*(double)p*uo*log(2.0)/(vo-uo))); - if(p-err-3<=q) { - p=q+err+4; - err=ceil((3.0/2.0*log((double)p)/log(2.0)+1.0)*exp(-(double)p*log(2.0))+3.0*exp(-2.0*(double)p*uo*log(2.0)/(vo-uo))); - } - - /* Calculus of un and vn */ - while (eq<=p-2) { - mpfr_mul(tmp,u,v,GMP_RNDN); - mpfr_sqrt(tmpu,tmp,GMP_RNDN); - mpfr_add(tmp,u,v,GMP_RNDN); - mpfr_div_2exp(tmpv,tmp,1,GMP_RNDN); - mpfr_set(u,tmpu,GMP_RNDN); - mpfr_set(v,tmpv,GMP_RNDN); - if (mpfr_cmp(v,u)>=0) - eq=mpfr_cmp2(v,u); - else - eq=mpfr_cmp2(u,v); - } - - /* printf("avant can_round %i bits faux\n v : ",err+3); - mpfr_print_raw(v); printf("\n u : "); - mpfr_print_raw(u);printf("\n");*/ - - - /* Roundability of the result */ - can_round=mpfr_can_round(v,p-err-3,GMP_RNDN,rnd_mode,q); - - if (can_round) - go_on=0; - - else { - go_on=1; - p+=5; - TMP_FREE(marker2); - TMP_MARK(marker2); - s=(p-1)/BITS_PER_MP_LIMB+1; - MON_INIT(up, u, p, s); - MON_INIT(vp, v, p, s); - MON_INIT(tmpup, tmpu, p, s); - MON_INIT(tmpvp, tmpv, p, s); - MON_INIT(tmpp, tmp, p, s); - mpfr_set(u,a,GMP_RNDN); - mpfr_set(v,b,GMP_RNDN); - } - } - /* End of while */ - - /* Setting of the result */ - - mpfr_set(r,v,rnd_mode); - - - /* Let's clean */ - TMP_FREE(marker1); - - return ; -} - diff --git a/gmp/mpfr/clear.c b/gmp/mpfr/clear.c deleted file mode 100755 index 371c1a7..0000000 --- a/gmp/mpfr/clear.c +++ /dev/null @@ -1,36 +0,0 @@ -/* mpfr_clear -- free the memory space allocated for a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_clear (mpfr_ptr m) -#else -mpfr_clear (m) - mpfr_ptr m; -#endif -{ - (*_mp_free_func) (m->_mp_d, ((m->_mp_prec>>3) + 1)); -} diff --git a/gmp/mpfr/cmp.c b/gmp/mpfr/cmp.c deleted file mode 100755 index b64506b..0000000 --- a/gmp/mpfr/cmp.c +++ /dev/null @@ -1,219 +0,0 @@ -/* mpfr_cmp -- compare two floating-point numbers - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* returns 0 iff b = c - a positive value iff b > c - a negative value iff b < c - -More precisely, in case b and c are of same sign, the absolute value -of the result is one plus the absolute difference between the exponents -of b and c, i.e. one plus the number of bits shifts to align b and c -(this value is useful in mpfr_sub). - -*/ - -/* #define DEBUG */ - -/* compares b and sign(s)*c */ -int -#if __STDC__ -mpfr_cmp3 ( mpfr_srcptr b, mpfr_srcptr c, long int s) -#else -mpfr_cmp3(b, c, s) - mpfr_srcptr b; - mpfr_srcptr c; - long int s; -#endif -{ - long int diff_exp; - unsigned long bn, cn; - mp_limb_t *bp, *cp; - - if (!NOTZERO(b) && !NOTZERO(c)) { return 0; } - s = s*SIGN(b)*SIGN(c); - if (s<0) return(SIGN(b)); - - /* now signs are equal */ - - diff_exp = EXP(b)-EXP(c); - s = (SIGN(b)>0) ? 1 : -1; - - if (diff_exp>0) return(s*(1+diff_exp)); - else if (diff_exp<0) return(s*(-1+diff_exp)); - /* both signs and exponents are equal */ - - bn = (PREC(b)-1)/mp_bits_per_limb+1; - cn = (PREC(c)-1)/mp_bits_per_limb+1; - bp = MANT(b); cp = MANT(c); - - while (bn && cn) { - if (bp[--bn] != cp[--cn]) - return((bp[bn]>cp[cn]) ? s : -s); - } - - if (bn) { while (bn) if (bp[--bn]) return(s); } - else if (cn) while (cn) if (cp[--cn]) return(-s); - - return 0; -} - -/* returns the number of cancelled bits when one subtracts abs(c) from abs(b). - Assumes b>=c, which implies EXP(b)>=EXP(c). - if b=c, returns prec(b). -*/ -int -#if __STDC__ -mpfr_cmp2 ( mpfr_srcptr b, mpfr_srcptr c ) -#else -mpfr_cmp2(b, c) - mpfr_srcptr b; - mpfr_srcptr c; -#endif -{ - long int d, bn, cn, k, z; - mp_limb_t *bp, *cp, t, u=0, cc=0; - -#ifdef DEBUG - printf("b="); mpfr_print_raw(b); putchar('\n'); - printf("c="); mpfr_print_raw(c); putchar('\n'); -#endif - if (NOTZERO(c)==0) return (NOTZERO(b)) ? 0 : PREC(b); - d = EXP(b)-EXP(c); - k = 0; /* result can be d or d+1 if d>1, or >= d otherwise */ - /* k is the number of identical bits in the high part, - then z is the number of possibly cancelled bits */ -#ifdef DEBUG - if (d<0) { printf("assumption EXP(b)>d; - } - else { /* d=0 */ - while (bn>=0 && cn>=0 && (cc=(bp[bn--]-cp[cn--]))==0) { - k+=mp_bits_per_limb; - } - - if (cc==0) { /* either bn<0 or cn<0 */ - while (bn>=0 && (cc=bp[bn--])==0) k+=mp_bits_per_limb; - } - /* now bn<0 or cc<>0 */ - if (cc==0 && bn<0) return(PREC(b)); - } - - /* the first non-zero limb difference is cc, and the number - of cancelled bits in the upper limbs is k */ - - count_leading_zeros(u, cc); - k += u; - - if (cc != (1<<(mp_bits_per_limb-u-1))) return k; - - /* now cc is an exact power of two */ - if (cc != 1) - /* We just need to compare the following limbs */ - /* until two of them differ. The result is either k or k+1. */ - { - /* First flush all the unmatched limbs of b ; they all have to - be 0 in order for the process to go on */ - while (bn >= 0) - { - if (cn < 0) { return k; } - t = bp[bn--]; - if (d < mp_bits_per_limb) - { - if (d) - { - u = cp[cn--] << (mp_bits_per_limb - d); - if (cn >= 0) u+=(cp[cn]>>d); - } - else u = cp[cn--]; - - if (t > u || (t == u && cn < 0)) return k; - if (t < u) return k+1; - } - else - if (t) return k; else d -= mp_bits_per_limb; - } - - /* bn < 0; if some limb of c is nonzero, return k+1, otherwise return k*/ - - if (cn>=0 && (cp[cn--] << (mp_bits_per_limb - d))) { return k+1; } - - while (cn >= 0) - if (cp[cn--]) return k+1; - return k; - } - - /* cc = 1. Too bad. */ - z = 0; /* number of possibly cancelled bits - 1 */ - /* thus result is either k if low(b) >= low(c) - or k+z+1 if low(b) < low(c) */ - if (d > mp_bits_per_limb) { return k; } - - while (bn >= 0) - { - if (cn < 0) { return k; } - - if (d) - { - u = cp[cn--] << (mp_bits_per_limb - d); - if (cn >= 0) u+=(cp[cn]>>d); - } - else u = cp[cn--]; - - /* bp[bn--] > cp[cn--] : no borrow possible, k unchanged - bp[bn--] = cp[cn--] : need to consider next limbs - bp[bn--] < cp[cn--] : borrow - */ - if ((cc = bp[bn--]) != u) { - if (cc>u) return k; - else { count_leading_zeros(u, cc-u); return k + 1 + z + u; } - } - else z += mp_bits_per_limb; - } - - if (cn >= 0) - count_leading_zeros(cc, ~(cp[cn--] << (mp_bits_per_limb - d))); - else { cc = 0; } - - k += cc; - if (cc < d) return k; - - while (cn >= 0 && !~cp[cn--]) { z += mp_bits_per_limb; } - if (cn >= 0) { count_leading_zeros(cc, ~cp[cn--]); return (k + z + cc); } - - return k; /* We **need** that the nonsignificant limbs of c are set - to zero there */ -} diff --git a/gmp/mpfr/cmp_ui.c b/gmp/mpfr/cmp_ui.c deleted file mode 100755 index 48217a5..0000000 --- a/gmp/mpfr/cmp_ui.c +++ /dev/null @@ -1,116 +0,0 @@ -/* mpfr_cmp_ui -- compare a floating-point number with a machine integer - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* returns a positive value if b>i*2^f, - a negative value if b0 */ - e = EXP(b); /* 2^(e-1) <= b < 2^e */ - if (e>f+mp_bits_per_limb) return 1; - - c = (mp_limb_t) i; - count_leading_zeros(k, c); - k = f+mp_bits_per_limb - k; /* 2^(k-1) <= i*2^f < 2^k */ - if (k!=e) return (e-k); - - /* now k=e */ - c <<= (f+mp_bits_per_limb-k); - bn = (PREC(b)-1)/mp_bits_per_limb; - bp = MANT(b) + bn; - if (*bp>c) return 1; - else if (*bp=0) - if (*--bp) return 1; - return 0; - } -} - -/* returns a positive value if b>i*2^f, - a negative value if bf+mp_bits_per_limb) return si; - - c = (mp_limb_t) ((i<0) ? -i : i); - count_leading_zeros(k, c); - k = f+mp_bits_per_limb - k; /* 2^(k-1) <= i*2^f < 2^k */ - if (k!=e) return (si*(e-k)); - - /* now k=e */ - c <<= (f+mp_bits_per_limb-k); - bn = (PREC(b)-1)/mp_bits_per_limb; - bp = MANT(b) + bn; - if (*bp>c) return si; - else if (*bp=0) - if (*--bp) return si; - return 0; - } -} - diff --git a/gmp/mpfr/div.c b/gmp/mpfr/div.c deleted file mode 100755 index ee14756..0000000 --- a/gmp/mpfr/div.c +++ /dev/null @@ -1,247 +0,0 @@ -/* mpfr_div -- divide two floating-point numbers - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" -#include "longlong.h" - -/* #define DEBUG */ - -void -mpfr_div (mpfr_ptr r, mpfr_srcptr u, mpfr_srcptr v, unsigned char rnd_mode) -{ - mp_srcptr up, vp; - mp_ptr rp, tp, tp0, tmp; - mp_size_t usize, vsize, rrsize; - mp_size_t rsize; - mp_size_t sign_quotient; - mp_size_t prec, err; - mp_limb_t q_limb; - mp_exp_t rexp; - long k, mult, vn; - unsigned long cc = 0, rw, nw; - char can_round = 0; - TMP_DECL (marker); - - if (FLAG_NAN(u) || FLAG_NAN(v)) { SET_NAN(r); return; } - - usize = (PREC(u) - 1)/BITS_PER_MP_LIMB + 1; - vsize = (PREC(v) - 1)/BITS_PER_MP_LIMB + 1; - sign_quotient = (SIGN(u) == SIGN(v) ? 1 : -1); - prec = PREC(r); - - if (!NOTZERO(u)) { SET_ZERO(r); return; } - - if (!NOTZERO(v)) - vsize = 1 / v->_mp_d[vsize - 1]; /* Gestion des infinis ? */ - - if (!NOTZERO(v)) - { - r->_mp_exp = 0; - MPN_ZERO(r->_mp_d, r->_mp_size); - return; - } - - up = u->_mp_d; - vp = v->_mp_d; - -#ifdef DEBUG - printf("Entering division : "); - for(k = usize - 1; k >= 0; k--) { printf("%lu ", up[k]); } - printf(" by "); - for(k = vsize - 1; k >= 0; k--) { printf("%lu ", vp[k]); } - printf(".\n"); -#endif - - /* Compare the mantissas */ - mult = mpn_cmp(up, vp, (usize > vsize ? vsize : usize)); - if (mult == 0 && vsize > usize) - { - vn = vsize - usize; - while (vn >= 0) if (vp[vn--]) { mult = 1; break; } - /* On peut diagnostiquer ici pour pas cher le cas u = v */ - } - else { mult = (mult < 0 ? 1 : 0); } - - rsize = (PREC(r) + 3)/BITS_PER_MP_LIMB + 1; - rrsize = PREC(r)/BITS_PER_MP_LIMB + 1; - /* Three extra bits are needed in order to get the quotient with enough - precision ; take one extra bit for rrsize in order to solve more - easily the problem of rounding to nearest. */ - - /* ATTENTION, USIZE DOIT RESTER > A VSIZE !!!!!!!! */ - - do - { - TMP_MARK (marker); - - rexp = u->_mp_exp - v->_mp_exp; - - err = rsize*BITS_PER_MP_LIMB; - if (rsize < vsize) { err-=2; } - if (rsize < usize) { err--; } - if (err > rrsize * BITS_PER_MP_LIMB) - { err = rrsize * BITS_PER_MP_LIMB; } - - tp0 = (mp_ptr) TMP_ALLOC ((rsize+rrsize) * BYTES_PER_MP_LIMB); - /* fill by zero rrsize low limbs of t */ - MPN_ZERO(tp0, rrsize); tp = tp0 + rrsize; - tmp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB); - rp = (mp_ptr) TMP_ALLOC (rrsize * BYTES_PER_MP_LIMB); - - if (vsize >= rsize) { - MPN_COPY (tmp, vp + vsize - rsize, rsize); - } - else { - MPN_COPY (tmp + rsize - vsize, vp, vsize); - MPN_ZERO (tmp, rsize - vsize); - } - - if (usize >= rsize) { - MPN_COPY (tp, up + usize - rsize, rsize); - } - else { - MPN_COPY (tp + rsize - usize, up, usize); - MPN_ZERO (tp, rsize - usize); - } - - /* Do the real job */ - -#ifdef DEBUG - printf("Dividing : "); - for(k = rsize - 1; k >= 0; k--) { printf("%lu ", tp[k]); } - printf(" by "); - for(k = rsize - 1; k >= 0; k--) { printf("%lu ", tmp[k]); } - printf(".\n"); -#endif - - q_limb = (rsize==rrsize) /* use Burnikel-Ziegler algorithm */ - ? mpn_divrem_n (rp, tp0, tmp, rsize) - : mpn_divrem (rp, 0, tp0, rsize+rrsize, tmp, rsize); - tp = tp0; /* location of remainder */ - -#ifdef DEBUG - printf("The result is : \n"); - printf("Quotient : "); - for(k = rrsize - 1; k >= 0; k--) { printf("%lu ", rp[k]); } - printf("Remainder : "); - for(k = rsize - 1; k >= 0; k--) { printf("%lu ", tp[k]); } - printf("(q_limb = %lu)\n", q_limb); -#endif - - /* msb-normalize the result */ - - if (q_limb) - { - count_leading_zeros(k, q_limb); - mpn_rshift(rp, rp, rrsize, BITS_PER_MP_LIMB - k); - rp[rrsize - 1] |= (q_limb << k); - rexp += BITS_PER_MP_LIMB - k; - } - else - { - count_leading_zeros(k, rp[rrsize - 1]); - if (k) { mpn_lshift(rp, rp, rrsize, k); } - rexp -= k; - } - - can_round = (mpfr_can_round_raw(rp, rrsize, sign_quotient, err, - GMP_RNDN, rnd_mode, PREC(r)) - || (usize == rsize && vsize == rsize && - mpfr_can_round_raw(rp, rrsize, sign_quotient, err, - GMP_RNDZ, rnd_mode, PREC(r)))); - - /* If we used all the limbs of both the dividend and the divisor, - then we have the correct RNDZ rounding */ - - if (!can_round && (rsize < usize || rsize < vsize)) - { -#ifdef DEBUG - printf("Increasing the precision.\n"); -#endif - printf("#"); - TMP_FREE(marker); - } - } - while (!can_round && (rsize < usize || rsize < vsize) - && (rsize++) && (rrsize++)); - - /* ON PEUT PROBABLEMENT SE DEBROUILLER DES QUE rsize >= vsize */ - /* MAIS IL FAUT AJOUTER LE BOUT QUI MANQUE DE usize A rsize */ - - if (can_round) - { - cc = mpfr_round_raw(rp, rp, err, (sign_quotient == -1 ? 1 : 0), - PREC(r), rnd_mode); - rrsize = (PREC(r) - 1)/BITS_PER_MP_LIMB + 1; - } - else - /* Use the remainder to find out the correct rounding */ - /* Note that at this point the division has been done */ - /* EXACTLY. */ - if ((rnd_mode == GMP_RNDD && sign_quotient == -1) - || (rnd_mode == GMP_RNDU && sign_quotient == 1) - || (rnd_mode == GMP_RNDN)) - { - /* We cannot round, so that the last bits of the quotient - have to be zero; just look if the remainder is nonzero */ - k = rsize - 1; - while (k >= 0) { if (tp[k]) break; k--; } - if (k >= 0) - cc = mpn_add_1(rp, rp, rrsize, (mp_limb_t)1 << (BITS_PER_MP_LIMB - - (PREC(r) & - (BITS_PER_MP_LIMB - 1)))); - else - if (rnd_mode == GMP_RNDN) /* even rounding */ - { - rw = (PREC(r) + 1) & (BITS_PER_MP_LIMB - 1); - if (rw) { rw = BITS_PER_MP_LIMB - rw; nw = 0; } else nw = 1; - if ((rw ? (rp[nw] >> (rw + 1)) & 1 : - (rp[nw] >> (BITS_PER_MP_LIMB - 1)) & 1)) - { - cc = mpn_add_1(rp + nw, rp + nw, rrsize, - ((mp_limb_t)1) << rw); - } - } - /* cas 0111111 */ - } - - if (sign_quotient != SIGN(r)) { CHANGE_SIGN(r); } - r->_mp_exp = rexp; - - if (cc) { - mpn_rshift(rp, rp, rrsize, 1); - rp[rrsize-1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - r->_mp_exp++; - } - - rsize = rrsize; - rrsize = (PREC(r) - 1)/BITS_PER_MP_LIMB + 1; - MPN_COPY(r->_mp_d, rp + rsize - rrsize, rrsize); - MANT(r) [0] &= ~(((mp_limb_t)1 << (BITS_PER_MP_LIMB - - (PREC(r) & (BITS_PER_MP_LIMB - 1)))) - 1) ; - - TMP_FREE (marker); -} diff --git a/gmp/mpfr/div_2exp.c b/gmp/mpfr/div_2exp.c deleted file mode 100755 index e7602db..0000000 --- a/gmp/mpfr/div_2exp.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpfr_div_2exp -- divide a floating-point number by a power of two - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_div_2exp(mpfr_ptr y, mpfr_srcptr x, unsigned long int n, unsigned char rnd_mode) -#else -mpfr_div_2exp(y, x, n, rnd_mode) - mpfr_ptr y; - mpfr_srcptr x; - unsigned long int n; - unsigned char rnd_mode; -#endif -{ - /* Important particular case */ - if (y != x) mpfr_set(y, x, rnd_mode); - EXP(y) -= n; - return; -} - diff --git a/gmp/mpfr/div_ui.c b/gmp/mpfr/div_ui.c deleted file mode 100755 index 4b8573b..0000000 --- a/gmp/mpfr/div_ui.c +++ /dev/null @@ -1,135 +0,0 @@ -/* mpfr_div_ui -- divide a floating-point number by a machine integer - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* #define DEBUG */ - -/* returns 0 if result exact, non-zero otherwise */ -int -#ifdef __STDC__ -mpfr_div_ui(mpfr_ptr y, mpfr_srcptr x, unsigned long u, unsigned char rnd_mode) -#else -mpfr_div_ui(y, x, u, rnd_mode) - mpfr_ptr y; - mpfr_srcptr x; - unsigned long u; - unsigned char rnd_mode; -#endif -{ - int xn, yn, dif, sh, i; mp_limb_t *xp, *yp, *tmp, c, d; - TMP_DECL(marker); - - if (FLAG_NAN(x)) { SET_NAN(y); return 1; } - if (u==0) { printf("infinity\n"); return 1; } - - TMP_MARK(marker); - xn = (PREC(x)-1)/BITS_PER_MP_LIMB + 1; - yn = (PREC(y)-1)/BITS_PER_MP_LIMB + 1; - - xp = MANT(x); - yp = MANT(y); - EXP(y) = EXP(x); - if (SIGN(x)!=SIGN(y)) CHANGE_SIGN(y); - - dif = yn+1-xn; -#ifdef DEBUG - printf("dif=%d u=%lu xn=%d\n",dif,u,xn); - printf("x="); mpfr_print_raw(x); putchar('\n'); -#endif - - /* we need to store yn+1 = xn + dif limbs of the quotient */ - if (ABSSIZE(y)>=yn+1) tmp=yp; - else tmp=(mp_limb_t *)TMP_ALLOC((yn+1)*BYTES_PER_MP_LIMB); - - c = (mp_limb_t) u; - if (dif>=0) { - /* patch for bug in mpn_divrem_1 */ -#if (UDIV_NEEDS_NORMALIZATION==1) - count_leading_zeros(sh, c); - c <<= sh; - EXP(y) += sh; -#endif - c = mpn_divrem_1(tmp, dif, xp, xn, c); - } - else /* dif < 0 i.e. xn > yn */ - c = mpn_divrem_1(tmp, 0, xp-dif, yn, c); - - if (tmp[yn]==0) { tmp--; sh=0; EXP(y) -= mp_bits_per_limb; } - /* shift left to normalize */ - count_leading_zeros(sh, tmp[yn]); - if (sh) { - mpn_lshift(yp, tmp+1, yn, sh); - yp[0] += tmp[0] >> (BITS_PER_MP_LIMB-sh); - EXP(y) -= sh; - } - else MPN_COPY(yp, tmp+1, yn); -#ifdef DEBUG -printf("y="); mpfr_print_raw(y); putchar('\n'); -#endif - - sh = yn*BITS_PER_MP_LIMB - PREC(y); - /* it remains sh bits in less significant limb of y */ - - d = *yp & (((mp_limb_t)1 << sh) - 1); - *yp ^= d; /* set to zero lowest sh bits */ - - TMP_FREE(marker); - if ((c | d)==0) { - for (i=0; i<-dif && xp[i]==0; i++); - if (i>=-dif) return 0; /* result is exact */ - } - - switch (rnd_mode) { - case GMP_RNDZ: - return 1; /* result is inexact */ - case GMP_RNDU: - if (SIGN(y)>0) mpfr_add_one_ulp(y); - return 1; /* result is inexact */ - case GMP_RNDD: - if (SIGN(y)<0) mpfr_add_one_ulp(y); - return 1; /* result is inexact */ - case GMP_RNDN: - if (d < ((mp_limb_t)1 << (sh-1))) return 1; - else if (d > ((mp_limb_t)1 << (sh-1))) { - mpfr_add_one_ulp(y); - } - else { /* d = (mp_limb_t)1 << (sh-1) */ - if (c) mpfr_add_one_ulp(y); - else { - for (i=0; i<-dif && xp[i]==0; i++); - if (i<-dif) mpfr_add_one_ulp(y); - else { /* exactly in the middle */ - if (*yp & ((mp_limb_t)1 << sh)) mpfr_add_one_ulp(y); - } - } - } - return 1; - } - return 0; /* to prevent warning from gcc */ -} - - - diff --git a/gmp/mpfr/exp.c b/gmp/mpfr/exp.c deleted file mode 100755 index c3ec218..0000000 --- a/gmp/mpfr/exp.c +++ /dev/null @@ -1,176 +0,0 @@ -/* mpfr_exp -- exponential of a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -/* #define DEBUG */ - -#define LOG2 0.69314718055994528622 /* log(2) rounded to zero on 53 bits */ - -/* use Brent's formula exp(x) = (1+r+r^2/2!+r^3/3!+...)^(2^K)*2^n - where x = n*log(2)+(2^K)*r - number of operations = O(K+prec(r)/K) -*/ -int -#if __STDC__ -mpfr_exp(mpfr_ptr y, mpfr_srcptr x, unsigned char rnd_mode) -#else -mpfr_exp(y, x, rnd_mode) - mpfr_ptr y; - mpfr_srcptr x; - unsigned char rnd_mode; -#endif -{ - int n, expx, K, precy, q, k, l, expr, err; - mpfr_t r, s, t; - - if (FLAG_NAN(x)) { SET_NAN(y); return 1; } - if (!NOTZERO(x)) { mpfr_set_ui(y, 1, GMP_RNDN); return 0; } - - expx = EXP(x); - precy = PREC(y); -#ifdef DEBUG - printf("EXP(x)=%d\n",expx); -#endif - - /* if x > (2^31-1)*ln(2), then exp(x) > 2^(2^31-1) i.e. gives +infinity */ - if (expx > 30) { - if (SIGN(x)>0) { printf("+infinity"); return 1; } - else { SET_ZERO(y); return 1; } - } - - /* if x < 2^(-precy), then exp(x) i.e. gives 1 +/- 1 ulp(1) */ - if (expx < -precy) { int signx = SIGN(x); - mpfr_set_ui(y, 1, rnd_mode); - if (signx>0 && rnd_mode==GMP_RNDU) mpfr_add_one_ulp(y); - else if (signx<0 && (rnd_mode==GMP_RNDD || rnd_mode==GMP_RNDZ)) - mpfr_sub_one_ulp(y); - return 1; } - - n = (int) floor(mpfr_get_d(x)/LOG2); - - K = (int) sqrt( (double) precy ); - l = (precy-1)/K + 1; - err = K + (int) ceil(log(2.0*(double)l+18.0)/LOG2); - /* add K extra bits, i.e. failure probability <= 1/2^K = O(1/precy) */ - q = precy + err + K + 3; - mpfr_init2(r, q); mpfr_init2(s, q); mpfr_init2(t, q); - /* the algorithm consists in computing an upper bound of exp(x) using - a precision of q bits, and see if we can round to PREC(y) taking - into account the maximal error. Otherwise we increase q. */ - do { -#ifdef DEBUG - printf("n=%d K=%d l=%d q=%d\n",n,K,l,q); -#endif - - /* if n<0, we have to get an upper bound of log(2) - in order to get an upper bound of r = x-n*log(2) */ - mpfr_log2(s, (n>=0) ? GMP_RNDZ : GMP_RNDU); -#ifdef DEBUG - printf("n=%d log(2)=",n); mpfr_print_raw(s); putchar('\n'); -#endif - mpfr_mul_ui(r, s, (n<0) ? -n : n, (n>=0) ? GMP_RNDZ : GMP_RNDU); - if (n<0) mpfr_neg(r, r, GMP_RNDD); - /* r = floor(n*log(2)) */ - -#ifdef DEBUG - printf("x=%1.20e\n",mpfr_get_d(x)); - printf(" ="); mpfr_print_raw(x); putchar('\n'); - printf("r=%1.20e\n",mpfr_get_d(r)); - printf(" ="); mpfr_print_raw(r); putchar('\n'); -#endif - mpfr_sub(r, x, r, GMP_RNDU); - if (SIGN(r)<0) { /* initial approximation n was too large */ - n--; - mpfr_mul_ui(r, s, (n<0) ? -n : n, GMP_RNDZ); - if (n<0) mpfr_neg(r, r, GMP_RNDD); - mpfr_sub(r, x, r, GMP_RNDU); - } -#ifdef DEBUG - printf("x-r=%1.20e\n",mpfr_get_d(r)); - printf(" ="); mpfr_print_raw(r); putchar('\n'); - if (SIGN(r)<0) { fprintf(stderr,"Error in mpfr_exp: r<0\n"); exit(1); } -#endif - mpfr_div_2exp(r, r, K, GMP_RNDU); /* r = (x-n*log(2))/2^K */ - mpfr_set_ui(s, 1, GMP_RNDU); - mpfr_set_ui(t, 1, GMP_RNDU); - - l = 1; expr = EXP(r); - do { - mpfr_mul(t, t, r, GMP_RNDU); - mpfr_div_ui(t, t, l, GMP_RNDU); - mpfr_add(s, s, t, GMP_RNDU); -#ifdef DEBUG - printf("l=%d t=%1.20e\n",l,mpfr_get_d(t)); - printf("s=%1.20e\n",mpfr_get_d(s)); -#endif - l++; - } while (EXP(t)+expr > -q); -#ifdef DEBUG - printf("l=%d q=%d (K+l)*q^2=%1.3e\n", l, q, (K+l)*(double)q*q); -#endif - - /* add 2 ulp to take into account rest of summation */ - mpfr_add_one_ulp(s); - mpfr_add_one_ulp(s); - - for (k=0;k0) mpfr_mul_2exp(s, s, n, GMP_RNDU); - else mpfr_div_2exp(s, s, -n, GMP_RNDU); - - /* error is at most 2^K*(2l+18) ulp */ - l = 2*l+17; k=0; while (l) { k++; l >>= 1; } - /* now k = ceil(log(2l+18)/log(2)) */ - K += k; -#ifdef DEBUG - printf("after mult. by 2^n:\n"); - if (EXP(s)>-1024) printf("s=%1.20e\n",mpfr_get_d(s)); - printf(" ="); mpfr_print_raw(s); putchar('\n'); - printf("err=%d bits\n", K); -#endif - - l = mpfr_can_round(s, q-K, GMP_RNDU, rnd_mode, precy); - if (l==0) { -#ifdef DEBUG - printf("not enough precision, use %d\n", q+BITS_PER_MP_LIMB); - printf("q=%d q-K=%d precy=%d\n",q,q-K,precy); -#endif - q += BITS_PER_MP_LIMB; - mpfr_set_prec(r, q); mpfr_set_prec(s, q); mpfr_set_prec(t, q); - } - } while (l==0); - - mpfr_set(y, s, rnd_mode); - - mpfr_clear(r); mpfr_clear(s); mpfr_clear(t); - return 1; -} - diff --git a/gmp/mpfr/get_str.c b/gmp/mpfr/get_str.c deleted file mode 100755 index e100b30..0000000 --- a/gmp/mpfr/get_str.c +++ /dev/null @@ -1,207 +0,0 @@ -/* mpfr_get_str -- output a floating-point number to a string - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* - Convert op to a string in base 'base' with 'n' digits and writes the - mantissa in 'str', the exponent in 'expptr'. - The result is rounded wrt 'rnd_mode'. - - For op = 3.1416 we get str = "31416" and expptr=1. - */ -#if __STDC__ -char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, - mpfr_srcptr op, unsigned char rnd_mode) -#else -char *mpfr_get_str(str, expptr, base, n, op, rnd_mode) - char *str; - mp_exp_t *expptr; - int base; - size_t n; - mpfr_srcptr op; - unsigned char rnd_mode; -#endif -{ - double d; long e, q, div, p, err, prec, sh; mpfr_t a, b; mpz_t bz; - char *str0; unsigned char rnd1; int f, pow2, ok=0, neg; - - if (base<2 || 36 0, then base = 2^pow2 */ - - /* first determines the exponent */ - e = EXP(op); - d = fabs(mpfr_get_d2(op, 0)); - /* the absolute value of op is between 1/2*2^e and 2^e */ - /* the output exponent f is such that base^(f-1) <= |op| < base^f - i.e. f = 1 + floor(log(|op|)/log(base)) - = 1 + floor((log(|m|)+e*log(2))/log(base)) */ - f = 1 + (int) floor((log(d)+(double)e*log(2.0))/log((double)base)); - if (n==0) { - /* performs exact rounding, i.e. returns y such that for rnd_mode=RNDN - for example, we have: - y*base^(f-n) <= x*2^(e-p) < (x+1)*2^(e-p) <= (y+1)*base^(f-n) - which implies 2^(EXP(op)-PREC(op)) <= base^(f-n) - */ - n = f + (int) ceil(((double)PREC(op)-e)*log(2.0)/log((double)base)); - } - /* now the first n digits of the mantissa are obtained from - rnd(op*base^(n-f)) */ - prec = (long) ceil((double)n*log((double)base)/log(2.0)); - err = 5; - q = prec+err; - /* one has to use at least q bits */ - q = (((q-1)/BITS_PER_MP_LIMB)+1)*BITS_PER_MP_LIMB; - mpfr_init2(a,q); mpfr_init2(b,q); - - do { - p = n-f; if ((div=(p<0))) p=-p; - rnd1 = rnd_mode; - if (div) { - /* if div we divide by base^p so we have to invert the rounding mode */ - switch (rnd1) { - case GMP_RNDN: rnd1=GMP_RNDN; break; - case GMP_RNDZ: rnd1=GMP_RNDU; break; - case GMP_RNDU: rnd1=GMP_RNDZ; break; - case GMP_RNDD: rnd1=GMP_RNDZ; break; - } - } - - if (pow2) { - if (div) mpfr_div_2exp(b, op, pow2*p, rnd_mode); - else mpfr_mul_2exp(b, op, pow2*p, rnd_mode); - } - else { - /* compute base^p with q bits and rounding towards zero */ - mpfr_set_prec(b, q); - if (p==0) { mpfr_set(b, op, rnd_mode); mpfr_set_ui(a, 1, rnd_mode); } - else { - mpfr_set_prec(a, q); - mpfr_ui_pow_ui(a, base, p, rnd1); - if (div) { - mpfr_set_ui(b, 1, rnd_mode); - mpfr_div(a, b, a, rnd_mode); - } - /* now a is an approximation by default of 1/base^(f-n) */ - mpfr_mul(b, op, a, rnd_mode); - } - } - if (neg) CHANGE_SIGN(b); /* put b positive */ - - if (q>2*prec+BITS_PER_MP_LIMB) { - /* happens when just in the middle between two digits */ - n--; q-=BITS_PER_MP_LIMB; - if (n==0) { - fprintf(stderr, "cannot determine leading digit\n"); exit(1); - } - } - ok = pow2 || mpfr_can_round(b, q-err, rnd_mode, rnd_mode, prec); - - if (ok) { - if (pow2) { - sh = e-PREC(op) + pow2*(n-f); /* error at most 2^e */ - ok = mpfr_can_round(b, EXP(b)-sh-1, rnd_mode, rnd_mode, n*pow2); - } - else { - /* check that value is the same at distance 2^(e-PREC(op))/base^(f-n) - in opposite from rounding direction */ - if (e>=PREC(op)) mpfr_mul_2exp(a, a, e-PREC(op), rnd_mode); - else mpfr_div_2exp(a, a, PREC(op)-e, rnd_mode); - if (rnd_mode==GMP_RNDN) { - mpfr_div_2exp(a, a, 2, rnd_mode); - mpfr_sub(b, b, a, rnd_mode); /* b - a/2 */ - mpfr_mul_2exp(a, a, 2, rnd_mode); - mpfr_add(a, b, a, rnd_mode); /* b + a/2 */ - } - else if ((rnd_mode==GMP_RNDU && neg==0) || (rnd_mode==GMP_RNDD && neg)) - mpfr_sub(a, b, a, rnd_mode); - else mpfr_add(a, b, a, rnd_mode); - /* check that a and b are rounded similarly */ - prec=EXP(b); - if (EXP(a) != prec) ok=0; - else { - mpfr_round(b, rnd_mode, prec); - mpfr_round(a, rnd_mode, prec); - if (mpfr_cmp(a, b)) ok=0; - } - } - if (ok==0) { /* n is too large */ - n--; - if (n==0) { - fprintf(stderr, "cannot determine leading digit\n"); exit(1); - } - q -= BITS_PER_MP_LIMB; - } - } - } while (ok==0 && (q+=BITS_PER_MP_LIMB) ); - if (neg) - switch (rnd_mode) { - case GMP_RNDU: rnd_mode=GMP_RNDZ; break; - case GMP_RNDD: rnd_mode=GMP_RNDU; break; - } - - prec=EXP(b); /* may have changed due to rounding */ - - /* now the mantissa is the integer part of b */ - mpz_init(bz); q=1+(prec-1)/BITS_PER_MP_LIMB; - _mpz_realloc(bz, q); - sh = prec%BITS_PER_MP_LIMB; - e = 1 + (PREC(b)-1)/BITS_PER_MP_LIMB-q; - if (sh) mpn_rshift(PTR(bz), MANT(b)+e, q, BITS_PER_MP_LIMB-sh); - else MPN_COPY(PTR(bz), MANT(b)+e, q); - bz->_mp_size=q; - - /* computes the number of characters needed */ - q = neg + n + 2; /* n+1 may not be enough for 100000... */ - if (str==NULL) str0=str=(*_mp_allocate_func)(q); - if (neg) *str++='-'; - mpz_get_str(str, base, bz); /* n digits of mantissa */ - if (strlen(str)==n+1) f++; /* possible due to rounding */ - *expptr = f; - mpfr_clear(a); mpfr_clear(b); mpz_clear(bz); - return str0; -} - diff --git a/gmp/mpfr/init.c b/gmp/mpfr/init.c deleted file mode 100755 index e416511..0000000 --- a/gmp/mpfr/init.c +++ /dev/null @@ -1,49 +0,0 @@ -/* mpfr_init -- initialize a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_init2 (mpfr_t x, unsigned long int p) -#else -mpfr_init2 (x, p) - mpfr_t x; - unsigned long int p; -#endif -{ - unsigned long xsize; - - if (p==0) { - printf("*** cannot initialize mpfr with precision 0\n"); exit(1); - } - - xsize = (p - 1)/BITS_PER_MP_LIMB + 1; - - x -> _mp_prec = p; - x -> _mp_d = (mp_ptr) (*_mp_allocate_func) - (xsize * BYTES_PER_MP_LIMB); - x -> _mp_size = xsize; - x -> _mp_exp = 0; /* avoids uninitialized memory reads for zero */ -} diff --git a/gmp/mpfr/karadiv.c b/gmp/mpfr/karadiv.c deleted file mode 100755 index 94db053..0000000 --- a/gmp/mpfr/karadiv.c +++ /dev/null @@ -1,137 +0,0 @@ -/* mpn_divrem_n -- Karatsuba division in 2*K(n) limb operations - -Copyright (C) 1999-2000 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* -[1] Fast Recursive Division, by Christoph Burnikel and Joachim Ziegler, - Technical report MPI-I-98-1-022, october 1998, - cf http://www.mpi-sb.mpg.de/~ziegler/TechRep.ps.gz. - Implemented by Paul Zimmermann, 1999. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -extern void mpn_divrem_n2 (mp_limb_t *, mp_limb_t *, mp_limb_t *, mp_size_t, mp_limb_t *); -extern void mpn_divrem_3by2 (mp_limb_t *, mp_limb_t *, mp_limb_t *, mp_size_t, mp_limb_t *); - -/* mpn_divrem_n(n) calls 2*mul(n/2)+2*div(n/2), thus to be faster then - div(n)=4*div(n/2), we need mul(n/2) to be faster than the classic way, - i.e. n/2 >= KARATSUBA_MUL_THRESHOLD */ - -#define DIV_LIMIT (7*KARATSUBA_MUL_THRESHOLD) - -static void mpn_decr(mp_limb_t *Q) -{ - while ((*Q++)-- == 0); -} - -/* implements algorithm of page 8 in [1]: divides (A,2n) by (B,n) and puts the - quotient in (Q,n), the remainder in (A,n). - Returns most significant limb of the quotient, which is 0 or 1. -*/ -mp_limb_t -mpn_divrem_n(mp_limb_t *Q, mp_limb_t *A, mp_limb_t *B, mp_size_t n) -{ - if (n=0) { - cc=1; - mpn_sub_n(A+n, A+n, B, n); - } - if (n%2) { - /* divide (2n-2) most significant limbs from A by those (n-1) from B */ - mpn_divrem_n(Q+1, A+2, B+1, n-1); - /* now (Q+1, n-1) contains the quotient of (A+2,2n-2) by (B+1,n-1) - and (A+2, n-1) contains the remainder */ - if (mpn_sub_1(A+n, A+n, 1, mpn_submul_1(A+1, Q+1, n-1, B[0]))) { - /* quotient two large */ - mpn_decr(Q+1); - if (mpn_add_n(A+1, A+1, B, n)==0) { - mpn_decr(Q+1); mpn_add_n(A+1, A+1, B, n); - } - } - /* now divide (A,n+1) by (B,n) */ - mpn_divrem(Q, 0, A, n+1, B, n); - } - else { - mp_limb_t *tmp; int n2=n/2; - TMP_DECL (marker); - - TMP_MARK (marker); - tmp = (mp_limb_t*) TMP_ALLOC(n*sizeof(mp_limb_t)); - mpn_divrem_3by2(Q+n2, A+n2, B, n2, tmp); - mpn_divrem_3by2(Q, A, B, n2, tmp); - TMP_FREE (marker); - } - return cc; - } -} - -/* inner procedure, with no memory allocation - assumes mpn_cmp(A+n, B, n) < 0 -*/ -void mpn_divrem_n2(mp_limb_t *Q, mp_limb_t *A, mp_limb_t *B, mp_size_t n, - mp_limb_t *tmp) -{ - if (n%2) { - /* divide (2n-2) most significant limbs from A by those (n-1) from B */ - mpn_divrem_n2(Q+1, A+2, B+1, n-1, tmp); - /* now (Q+1, n-1) contains the quotient of (A+2,2n-2) by (B+1,n-1) - and (A+2, n-1) contains the remainder */ - if (mpn_sub_1(A+n, A+n, 1, mpn_submul_1(A+1, Q+1, n-1, B[0]))) { - /* quotient two large */ - mpn_decr(Q+1); - if (mpn_add_n(A+1, A+1, B, n)==0) { /* still too large */ - mpn_decr(Q+1); mpn_add_n(A+1, A+1, B, n); - } - } - /* now divide (A,n+1) by (B,n) */ - mpn_divrem(Q, 0, A, n+1, B, n); - } - else { - int n2=n/2; - mpn_divrem_3by2(Q+n2, A+n2, B, n2, tmp); - mpn_divrem_3by2(Q, A, B, n2, tmp); - } -} - -/* divides (A,3n) by (B,2n) and puts the quotient in (Q,n), - the remainder in (A,2n) */ -void -mpn_divrem_3by2(mp_limb_t *Q, mp_limb_t *A, mp_limb_t *B, - mp_size_t n, mp_limb_t *tmp) -{ - int twon = n+n; - - if (n= nn */ - MPN_COPY(r, op+nn, nn); /* copy a_1 */ - tmp = mpn_rshift(r, r, nn+rn, 1); - if (r[nn+rn-1]==0) rn--; - q = (mp_limb_t*) TMP_ALLOC(2*(sn+1)*sizeof(mp_limb_t)); - if (nn+rn < 2*sn) MPN_ZERO(r+nn+rn, 2*sn-nn-rn); - qn = sn; if (mpn_cmp(r+sn, s+nn, sn)>=0) { - q[qn++]=1; mpn_sub_n(r+sn, r+sn, s+nn, sn); - } -#if 0 - mpn_divrem(q, 0, r, 2*sn, s+nn, sn); -#else - mpn_divrem_n(q, r, s+nn, sn); -#endif - while (qn>nn && q[qn-1]==0) qn--; - MPN_COPY(s, q, nn); - if (nn+rn > 2*sn) { - tmp=mpn_add_n(s+sn, s+sn, q+sn, nn+rn-2*sn); - if (tmp) mpn_add_1(s+nn+rn-sn, s+nn+rn-sn, (n+1)/2-nn-rn+sn, tmp); - } - /* multiply remainder by two and add low bit of a_1 */ - rrn = nn+sn; /* size of output remainder */ - rrn += mpn_lshift(r+nn, r, sn, 1); - r[nn] |= (op[nn] & 1); - sn += nn; - if (qn>nn) { - MPN_COPY(r, s+nn, qn-nn); /* save the qn-nn limbs from s */ - MPN_COPY(s+nn, q+nn, qn-nn); /* replace by those of q */ - } - mpn_mul_n(q, s, s, qn); - if (qn>nn) { /* restore the limbs from s, adding them to those of q */ - mp_limb_t cy; - - cy = mpn_add_n(s+nn, s+nn, r, qn-nn); - if (qnsn)) { - if (rrn>sn) rrn=sn; - else { - /* one shift and one add is faster than two add's */ - r[sn] = mpn_lshift(q, s, sn, 1) + mpn_add_n(r, r, q, sn) - - mpn_sub_1(r, r, sn, 1) - 1; - rrn = sn + r[sn]; - mpn_sub_1(s, s, sn, 1); - } - } - else if (rrn>sn) r[sn]=1; - TMP_FREE (marker); - MPN_NORMALIZE(r, rrn); - return rrn; - } -} diff --git a/gmp/mpfr/log.c b/gmp/mpfr/log.c deleted file mode 100755 index 06f5dad..0000000 --- a/gmp/mpfr/log.c +++ /dev/null @@ -1,150 +0,0 @@ -/* mpfr_log -- natural logarithm of a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - - - /* The computation of log(a) is done using the formula : - if we want p bits of the result, - pi - log(a) ~ ------------ - m log 2 - 2 AG(1,4/s) - - where s = x 2^m > 2^(p/2) - - More precisely, if F(x) = int(1/sqrt(1-(1-x^2)*sin(t)^2), t=0..PI/2), - then for s>=1.26 we have log(s) < F(4/s) < log(s)*(1+4/s^2) - from which we deduce pi/2/AG(1,4/s)*(1-4/s^2) < log(s) < pi/2/AG(1,4/s) - so the relative error 4/s^2 is < 4/2^p i.e. 4 ulps. - */ - - -#define MON_INIT(xp, x, p, s) xp = (mp_ptr) TMP_ALLOC(s*BYTES_PER_MP_LIMB); x -> _mp_prec = p; x -> _mp_d = xp; x -> _mp_size = s; x -> _mp_exp = 0; - -/* #define DEBUG */ - -int -#if __STDC__ -mpfr_log(mpfr_ptr r, mpfr_srcptr a, unsigned char rnd_mode) -#else -mpfr_log(r, a, rnd_mode) - mpfr_ptr r; - mpfr_srcptr a; - unsigned char rnd_mode; -#endif -{ - int p, m, q, bool, size, cancel; - mpfr_t cst, rapport, agm, tmp1, tmp2, s, mm; - mp_limb_t *cstp, *rapportp, *agmp, *tmp1p, *tmp2p, *sp, *mmp; - double ref; - TMP_DECL(marker); - - /* If a is NaN or a is negative or null, the result is NaN */ - if (FLAG_NAN(a) || (SIGN(a)<=0)) - { SET_NAN(r); return 1; } - - /* If a is 1, the result is 0 */ - if (mpfr_cmp_ui_2exp(a,1,0)==0){ - SET_ZERO(r); - return 0; /* only case where the result is exact */ - } - - q=PREC(r); - - ref=mpfr_get_d(a)-1.0; - if (ref<0) - ref=-ref; - - p=q+4; - /* adjust to entire limb */ - if (p%BITS_PER_MP_LIMB) p += BITS_PER_MP_LIMB - (p%BITS_PER_MP_LIMB); - - bool=1; - - while (bool==1) { -#ifdef DEBUG - printf("a="); mpfr_print_raw(a); putchar('\n'); - printf("p=%d\n", p); -#endif - /* Calculus of m (depends on p) */ - m=(int) ceil(((double) p)/2.0) -EXP(a)+1; - - /* All the mpfr_t needed have a precision of p */ - TMP_MARK(marker); - size=(p-1)/BITS_PER_MP_LIMB+1; - MON_INIT(cstp, cst, p, size); - MON_INIT(rapportp, rapport, p, size); - MON_INIT(agmp, agm, p, size); - MON_INIT(tmp1p, tmp1, p, size); - MON_INIT(tmp2p, tmp2, p, size); - MON_INIT(sp, s, p, size); - MON_INIT(mmp, mm, p, size); - - mpfr_set_si(mm,m,GMP_RNDN); /* I have m, supposed exact */ - mpfr_set_si(tmp1,1,GMP_RNDN); /* I have 1, exact */ - mpfr_set_si(tmp2,4,GMP_RNDN); /* I have 4, exact */ - mpfr_mul_2exp(s,a,m,GMP_RNDN); /* I compute s=a*2^m, err <= 1 ulp */ - mpfr_div(rapport,tmp2,s,GMP_RNDN); /* I compute 4/s, err <= 2 ulps */ - mpfr_agm(agm,tmp1,rapport,GMP_RNDN); /* AG(1,4/s), err<=3 ulps */ - mpfr_mul_2exp(tmp1,agm,1,GMP_RNDN); /* 2*AG(1,4/s), still err<=3 ulps */ - mpfr_pi(cst, GMP_RNDN); /* I compute pi, err<=1ulp */ - mpfr_div(tmp2,cst,tmp1,GMP_RNDN); /* pi/2*AG(1,4/s), err<=5ulps */ - mpfr_log2(cst,GMP_RNDN); /* I compute log(2), err<=1ulp */ - mpfr_mul(tmp1,cst,mm,GMP_RNDN); /* I compute m*log(2), err<=2ulps */ - cancel = EXP(tmp2); - mpfr_sub(cst,tmp2,tmp1,GMP_RNDN); /* log(a), err<=7ulps+cancel */ - cancel -= EXP(cst); -#ifdef DEBUG - printf("cancelled bits=%d\n", cancel); - printf("approx="); mpfr_print_raw(cst); putchar('\n'); -#endif - if (cancel<0) cancel=0; - - /* If we can round the result, we set it and go out of the loop */ - - /* we have 7 ulps of error from the above roundings, - 4 ulps from the 4/s^2 second order term, - plus the cancelled bits */ - if (mpfr_can_round(cst,p-cancel-4,GMP_RNDN,rnd_mode,q)==1) { - mpfr_set(r,cst,rnd_mode); -#ifdef DEBUG - printf("result="); mpfr_print_raw(r); putchar('\n'); -#endif - bool=0; - } - /* else we increase the precision */ - else { - p += BITS_PER_MP_LIMB+cancel; - TMP_FREE(marker); - } - - /* We clean */ - TMP_FREE(marker); - - } - return 1; /* result is inexact */ -} - - diff --git a/gmp/mpfr/log2.c b/gmp/mpfr/log2.c deleted file mode 100755 index 151e0e8..0000000 --- a/gmp/mpfr/log2.c +++ /dev/null @@ -1,102 +0,0 @@ -/* mpfr_log2 -- compute natural logarithm of 2 - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -mpfr_t __mpfr_log2; /* stored value of log(2) with rnd_mode=GMP_RNDZ */ -int __mpfr_log2_prec=0; /* precision of stored value */ - -/* set x to log(2) rounded to precision PREC(x) with direction rnd_mode - - use formula log(2) = sum(1/k/2^k, k=1..infinity) - - whence 2^N*log(2) = S(N) + R(N) - - where S(N) = sum(2^(N-k)/k, k=1..N-1) - and R(N) = sum(1/k/2^(k-N), k=N..infinity) < 2/N - - Let S'(N) = sum(floor(2^(N-k)/k), k=1..N-1) - - Then 2^N*log(2)-S'(N) <= N-1+2/N <= N for N>=2. -*/ -void -#if __STDC__ -mpfr_log2(mpfr_ptr x, unsigned char rnd_mode) -#else -mpfr_log2(x, rnd_mode) mpfr_ptr x; unsigned char rnd_mode; -#endif -{ - int N, oldN, k, precx; mpz_t s, t, u; - - precx = PREC(x); - - /* has stored value enough precision ? */ - if (precx <= __mpfr_log2_prec) { - if (rnd_mode==GMP_RNDZ || rnd_mode==GMP_RNDD || - mpfr_can_round(__mpfr_log2, __mpfr_log2_prec, GMP_RNDZ, rnd_mode, precx)) - { - mpfr_set(x, __mpfr_log2, rnd_mode); return; - } - } - - /* need to recompute */ - N=2; - do { - oldN = N; - N = precx + (int)ceil(log((double)N)/log(2.0)); - } while (N != oldN); - mpz_init_set_ui(s,0); - mpz_init(u); - mpz_init_set_ui(t,1); -#if 0 - /* use log(2) = sum(1/k/2^k, k=1..infinity) */ - mpz_mul_2exp(t, t, N); - for (k=1;k - -/* generate a random double using the whole range of possible values, - including denormalized numbers, NaN, infinities, ... */ -double drand() -{ - volatile double d; int *i; - - i = (int*) &d; - i[0] = mrand48(); - i[1] = mrand48(); - return d; -} - -/* returns the number of ulp's between a and b */ -int ulp(a,b) double a,b; -{ - double eps=1.1102230246251565404e-16; /* 2^(-53) */ - if (a==0.0) { - if (b==0.0) return 0; - else if (b<0.0) return 2147483647; - else return -2147483647; - } - b = (a-b)/a; - if (b>0) - return (int) floor(b/eps); - else - return (int) ceil(b/eps); -} - -/* return double m*2^e */ -double dbl(m,e) double m; int e; -{ - if (e>=0) while (e-->0) m *= 2.0; - else while (e++<0) m /= 2.0; - return m; -} diff --git a/gmp/mpfr/mpfr.h b/gmp/mpfr/mpfr.h deleted file mode 100755 index 9f25eba..0000000 --- a/gmp/mpfr/mpfr.h +++ /dev/null @@ -1,204 +0,0 @@ -/* mpfr.h -- Include file for mpfr. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include - -/* Cygnus does not know about *rand48 functions */ -#ifdef __CYGWIN32__ -#define mrand48 rand -#define drand48 rand -#define lrand48 rand -#define srand48 srand -#endif - -/* Definition of rounding modes */ - -#define GMP_RNDN 0 -#define GMP_RNDZ 1 -#define GMP_RNDU 2 -#define GMP_RNDD 3 - -/* Definitions of types and their semantics */ - -typedef struct { - unsigned long int _mp_prec; /* WARNING : for the mpfr type, the precision */ - /* should be understood as the number of BITS,*/ - /* not the number of mp_limb_t's. This means */ - /* that the corresponding number of allocated - limbs is >= ceil(_mp_prec/BITS_PER_MP_LIMB) */ - mp_size_t _mp_size; /* abs(_mp_size) is the number of allocated - limbs the field _mp_d points to. - The sign is that of _mp_size. - The number 0 is such that _mp_d[k-1]=0 - where k = ceil(_mp_prec/BITS_PER_MP_LIMB) */ - mp_exp_t _mp_exp; - mp_limb_t *_mp_d; -} -__mpfr_struct; - -/* - The number represented is - - sign(_mp_size)*(_mp_d[k-1]/B+_mp_d[k-2]/B^2+...+_mp_d[0]/B^k)*2^_mp_exp - - where k=ceil(_mp_prec/BITS_PER_MP_LIMB) and B=2^BITS_PER_MP_LIMB. - - For the msb (most significant bit) normalized representation, we must have - _mp_d[k-1]>=B/2, unless the number is zero (in that case its sign is still - given by sign(_mp_size)). - - We must also have the last k*BITS_PER_MP_LIMB-_mp_prec bits set to zero. -*/ - -typedef __mpfr_struct mpfr_t[1]; -typedef __mpfr_struct *mpfr_ptr; -typedef __gmp_const __mpfr_struct *mpfr_srcptr; - - -/* Prototypes */ - -#ifndef _PROTO -#if defined (__STDC__) || defined (__cplusplus) -#define _PROTO(x) x -#else -#define _PROTO(x) () -#endif -#endif - -/* bit 31 of _mp_size is used for sign, - bit 30 of _mp_size is used for Nan flag, - remaining bits are used to store the number of allocated limbs */ -#define FLAG_NAN(x) (((x)->_mp_size >> 30)&1) -#define SET_NAN(x) ((x)->_mp_size |= (1<<30)) -#define ABSSIZE(x) ((x)->_mp_size & ((1<<30)-1)) -#define SIZE(x) ((x)->_mp_size) -#define EXP(x) ((x)->_mp_exp) -#define MANT(x) ((x)->_mp_d) -#define SIGN(x) (((x)->_mp_size >> 31) ? -1 : 1) -#define ISNONNEG(x) (SIGN(x)>=0) -#define ISNEG(x) (SIGN(x)==-1) -#define CHANGE_SIGN(x) (SIZE(x) = SIZE(x) ^ (1<<31)) -#define PREC(x) ((x)->_mp_prec) -#define NOTZERO(x) (MANT(x)[(PREC(x)-1)/BITS_PER_MP_LIMB]) -#define SET_ZERO(x) (MANT(x)[(PREC(x)-1)/BITS_PER_MP_LIMB] = 0) - -/* reallocates the mantissa of x to q bits and sets the precision to q */ -#define _mpfr_realloc(x, q) { \ - (x)->_mp_d = (mp_ptr) (*_mp_reallocate_func) \ - ((x)->_mp_d, (x)->_mp_prec>>3 + 1, (q)>>3 + 1); \ - (x)->_mp_prec = q; } - -void mpfr_init2 _PROTO ((mpfr_ptr, unsigned long int)); -int mpfr_round_raw _PROTO ((mp_limb_t *, mp_limb_t *, unsigned long, char, - unsigned long, char)); -int mpfr_round_raw2 _PROTO ((mp_limb_t *, unsigned long, char, char, - unsigned long)); -void mpfr_round _PROTO ((mpfr_ptr, char, unsigned long)); -int mpfr_can_round _PROTO ((mpfr_ptr, unsigned long, unsigned char, - unsigned char, unsigned long)); -int mpfr_can_round_raw _PROTO ((mp_limb_t *, unsigned long, int, - unsigned long, - unsigned char, unsigned char, unsigned long)); -void mpfr_set_d _PROTO ((mpfr_ptr, double, unsigned char)); -int mpfr_set_z _PROTO ((mpfr_ptr, mpz_srcptr, unsigned char)); -double mpfr_get_d _PROTO ((mpfr_srcptr)); -double mpfr_get_d2 _PROTO ((mpfr_srcptr, long)); -void mpfr_set_f _PROTO ((mpfr_ptr, mpf_srcptr, char)); -void mpfr_set_si _PROTO ((mpfr_ptr, long, unsigned char)); -void mpfr_set_ui _PROTO ((mpfr_ptr, unsigned long, unsigned char)); -void mpfr_print_raw _PROTO ((mpfr_srcptr)); -void mpfr_random _PROTO ((mpfr_ptr)); -void mpfr_clear _PROTO ((mpfr_ptr)); -void mpfr_set_str_raw _PROTO ((mpfr_ptr, char *)); -void mpfr_get_str_raw _PROTO ((char *, mpfr_srcptr)); -char* mpfr_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpfr_srcptr, unsigned char)); -size_t mpfr_out_str _PROTO ((FILE *, int, size_t, mpfr_srcptr, unsigned char)); -void mpfr_mul _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char)); -void mpfr_pow_ui _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned int, unsigned char)); -void mpfr_ui_pow_ui _PROTO ((mpfr_ptr, unsigned int, unsigned int, unsigned char)); -mp_limb_t mpn_divrem_n _PROTO ((mp_limb_t *, mp_limb_t *, mp_limb_t *, mp_size_t)); -mp_size_t kara_sqrtrem _PROTO ((mp_limb_t *, mp_limb_t *, mp_limb_t *, mp_size_t)); -void mpfr_div _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char)); -void mpfr_agm _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char)); -int mpfr_sqrt _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char)); -void mpfr_add _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char)); -int mpfr_add_one_ulp _PROTO ((mpfr_ptr)); -void mpfr_sub _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, unsigned char)); -void mpfr_set4 _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char, int)); -void mpfr_pi _PROTO ((mpfr_ptr, unsigned char)); -void mpfr_log2 _PROTO ((mpfr_ptr, unsigned char)); -int mpfr_log _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char)); -int mpfr_exp _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char)); -int mpfr_zeta _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned char)); -void mpfr_mul_ui _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long, unsigned char)); -void mpfr_set_machine_rnd_mode _PROTO ((unsigned char)); -int mpfr_cmp3 _PROTO ((mpfr_srcptr, mpfr_srcptr, long int)); -int mpfr_cmp_ui_2exp _PROTO ((mpfr_srcptr, unsigned long int, int)); -int mpfr_cmp_si_2exp _PROTO ((mpfr_srcptr, long int, int)); -int mpfr_cmp2 _PROTO ((mpfr_srcptr, mpfr_srcptr)); -void mpfr_mul_2exp _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int,unsigned char)); -void mpfr_div_2exp _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int,unsigned char)); -void mpfr_set_prec _PROTO((mpfr_ptr, unsigned long int)); -void mpfr_set_default_prec _PROTO((unsigned long int)); -extern mp_size_t __gmp_default_fp_bit_precision; -extern char __gmp_default_rounding_mode; -char * mpfr_print_rnd_mode _PROTO((unsigned char)); -void mpfr_neg _PROTO((mpfr_ptr, mpfr_srcptr, unsigned char)); -int mpfr_sub_one_ulp _PROTO((mpfr_ptr x)); -int mpfr_div_ui _PROTO((mpfr_ptr y, mpfr_srcptr x, unsigned long u, unsigned char rnd_mode)); -unsigned long int mpfr_get_prec _PROTO((mpfr_t x)); - -#define mpfr_init(x) mpfr_init2(x, __gmp_default_fp_bit_precision) -#define mpfr_cmp_ui(b,i) mpfr_cmp_ui_2exp(b,i,0) -#define mpfr_cmp_si(b,i) mpfr_cmp_si_2exp(b,i,0) -#define mpfr_set(a,b,r) mpfr_set4(a,b,r,SIGN(b)) -#define mpfr_cmp(b,c) mpfr_cmp3(b,c,1) - -#if (BITS_PER_MP_LIMB==32) -#define MPFR_LIMBS_PER_DOUBLE 2 -#elif (BITS_PER_MP_LIMB==64) -#define MPFR_LIMBS_PER_DOUBLE 1 -#endif - -/* gmp-2.0.2 had only one threshold for both multiplication and squaring */ -#ifndef KARATSUBA_MUL_THRESHOLD -#ifdef KARATSUBA_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD KARATSUBA_THRESHOLD -#else -#define KARATSUBA_MUL_THRESHOLD 16 -#endif -#endif - -#define mpfr_init_set_si(x, i, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set_si((x), (i), (rnd)); -#define mpfr_init_set_ui(x, i, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set_ui((x), (i), (rnd)); -#define mpfr_init_set_d(x, d, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set_d((x), (d), (rnd)); -#define mpfr_init_set(x, y, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set((x), (y), (rnd)); -#define mpfr_init_set_f(x, y, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set_f((x), (y), (rnd)); -#define mpfr_init_set_str(x, y, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set_str((x), (y), (rnd)); -#define mpfr_init_set_str_raw(x, y, p, rnd) \ - mpfr_init2((x), (p)); mpfr_set_str_raw((x), (y), (rnd)); - diff --git a/gmp/mpfr/mul.c b/gmp/mpfr/mul.c deleted file mode 100755 index c7c3cd3..0000000 --- a/gmp/mpfr/mul.c +++ /dev/null @@ -1,78 +0,0 @@ -/* mpfr_mul -- multiply two floating-point numbers - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -/* Remains to do: -- do not use all bits of b and c when PREC(b)>PREC(a) or PREC(c)>PREC(a) - [current complexity is O(PREC(b)*PREC(c))] -*/ - -void -#if __STDC__ -mpfr_mul(mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, unsigned char rnd_mode) -#else -mpfr_mul(a, b, c, rnd_mode) - mpfr_ptr a; - mpfr_srcptr b; - mpfr_srcptr c; - unsigned char rnd_mode; -#endif -{ - unsigned int bn, cn, an, tn, k; int cc; - mp_limb_t *ap=MANT(a), *bp=MANT(b), *cp=MANT(c), *tmp, b1; - long int sign_product; - TMP_DECL(marker); - - /* deal with NaN and zero */ - if (FLAG_NAN(b) || FLAG_NAN(c)) { SET_NAN(a); return; } - if (!NOTZERO(b) || !NOTZERO(c)) { SET_ZERO(a); return; } - - sign_product = SIGN(b) * SIGN(c); - bn = (PREC(b)-1)/mp_bits_per_limb+1; /* number of significant limbs of b */ - cn = (PREC(c)-1)/mp_bits_per_limb+1; /* number of significant limbs of c */ - tn = (PREC(c)+PREC(b)-1)/mp_bits_per_limb+1; - k = bn+cn; /* effective nb of limbs used by b*c */ - TMP_MARK(marker); - tmp = (mp_limb_t*) TMP_ALLOC(k*BYTES_PER_MP_LIMB); - - /* multiplies two mantissa in temporary allocated space */ - b1 = (bn>=cn) ? mpn_mul(tmp, bp, bn, cp, cn) : mpn_mul(tmp, cp, cn, bp, bn); - - /* now tmp[0]..tmp[k-1] contains the product of both mantissa, - with tmp[k-1]>=2^(mp_bits_per_limb-2) */ - an = (PREC(a)-1)/mp_bits_per_limb+1; /* number of significant limbs of a */ - b1 >>= mp_bits_per_limb-1; /* msb from the product */ - - if (b1==0) mpn_lshift(tmp, tmp, k, 1); - cc = mpfr_round_raw(ap, tmp+bn+cn-tn, - PREC(b)+PREC(c), (sign_product<0), PREC(a), rnd_mode); - if (cc) { /* cc = 1 ==> result is a power of two */ - ap[an-1] = (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - } - EXP(a) = EXP(b) + EXP(c) + b1 - 1 + cc; - if (sign_product * SIGN(a)<0) CHANGE_SIGN(a); - TMP_FREE(marker); - return; -} diff --git a/gmp/mpfr/mul_2exp.c b/gmp/mpfr/mul_2exp.c deleted file mode 100755 index 31dab2a..0000000 --- a/gmp/mpfr/mul_2exp.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpfr_mul_2exp -- multiply a floating-point number by a power of two - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_mul_2exp(mpfr_ptr y, mpfr_srcptr x, unsigned long int n, unsigned char rnd_mode) -#else -mpfr_mul_2exp(y, x, n, rnd_mode) - mpfr_ptr y; - mpfr_srcptr x; - unsigned long int n; - unsigned char rnd_mode; -#endif -{ - /* Important particular case */ - if (y != x) mpfr_set(y, x, rnd_mode); - EXP(y) += n; - return; -} - diff --git a/gmp/mpfr/mul_ui.c b/gmp/mpfr/mul_ui.c deleted file mode 100755 index 83981a8..0000000 --- a/gmp/mpfr/mul_ui.c +++ /dev/null @@ -1,84 +0,0 @@ -/* mpfr_mul_ui -- multiply a floating-point number by a machine integer - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_mul_ui(mpfr_ptr y, mpfr_srcptr x, unsigned long u, unsigned char RND_MODE) -#else -mpfr_mul_ui(y, x, u, RND_MODE) - mpfr_ptr y; - mpfr_srcptr x; - unsigned long u; - unsigned char RND_MODE; -#endif -{ - mp_limb_t carry, *my, *old_my; unsigned long c; - unsigned long xsize, ysize, cnt, dif; - TMP_DECL(marker); - - TMP_MARK(marker); - my = MANT(y); - ysize = (PREC(y)-1)/BITS_PER_MP_LIMB + 1; - xsize = (PREC(x)-1)/BITS_PER_MP_LIMB + 1; - - if (ysize < xsize) { - old_my = my; - my = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB); - dif=0; - } - else dif=ysize-xsize; - - carry = mpn_mul_1(my+dif, MANT(x), xsize, u); - MPN_ZERO(my, dif); - - /* WARNING: count_leading_zeros is undefined for carry=0 */ - if (carry) count_leading_zeros(cnt, carry); - else cnt=BITS_PER_MP_LIMB; - - c = mpfr_round_raw(my, my, PREC(x), (SIGN(x)<0), - PREC(y)-BITS_PER_MP_LIMB+cnt, RND_MODE); - - /* If cnt = 1111111111111 and c = 1 we shall get depressed */ - if (c && (carry == (((mp_limb_t)1) << (BITS_PER_MP_LIMB - cnt)) - 1)) - { - cnt--; - mpn_rshift(my, my, ysize, BITS_PER_MP_LIMB - cnt); - my[ysize - 1] |= ((mp_limb_t) 1) << (BITS_PER_MP_LIMB - 1); - } - else - { - /* Warning: mpn_rshift is undefined for shift=0 */ - if (cnt!=BITS_PER_MP_LIMB) - mpn_rshift(my, my, ysize, BITS_PER_MP_LIMB - cnt); - my[ysize - 1] |= (carry << cnt); - } - EXP(y) = EXP(x) + BITS_PER_MP_LIMB - cnt; - if (ysize < xsize) MPN_COPY(old_my, my, ysize); - /* set sign */ - if (SIGN(y) != SIGN(x)) CHANGE_SIGN(y); - TMP_FREE(marker); -} diff --git a/gmp/mpfr/neg.c b/gmp/mpfr/neg.c deleted file mode 100755 index fff73a6..0000000 --- a/gmp/mpfr/neg.c +++ /dev/null @@ -1,40 +0,0 @@ -/* mpfr_neg -- change the sign of a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_neg(mpfr_ptr a, mpfr_srcptr b, unsigned char rnd_mode) -#else -mpfr_neg(a, b, rnd_mode) - mpfr_ptr a; - mpfr_srcptr b; - unsigned char rnd_mode; -#endif -{ - if (a != b) mpfr_set4(a, b, rnd_mode, -SIGN(b)); - else CHANGE_SIGN(a); - return; -} diff --git a/gmp/mpfr/out_str.c b/gmp/mpfr/out_str.c deleted file mode 100755 index aeaf64b..0000000 --- a/gmp/mpfr/out_str.c +++ /dev/null @@ -1,65 +0,0 @@ -/* mpfr_out_str -- output a floating-point number to a stream - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -size_t -#if __STDC__ -mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, - unsigned char rnd_mode) -#else -mpfr_out_str (stream, base, n_digits, op, rnd_mode) - FILE *stream; - int base; - size_t n_digits; - mpfr_srcptr op; - unsigned char rnd_mode; -#endif -{ - char *s,*s0; size_t l; mp_exp_t e; - - if (FLAG_NAN(op)) { fprintf(stream, "NaN"); return 3; } - if (!NOTZERO(op)) { fprintf(stream, "0"); return 1; } - - s = mpfr_get_str(NULL, &e, base, n_digits, op, rnd_mode); - s0 = s; - /* for op=3.1416 we have s = "31416" and e = 1 */ - - l = strlen(s)+1; - if (*s == '-') fputc(*s++, stream); - - fputc(*s++, stream); e--; /* writes leading digit */ - fputc('.', stream); /* decimal point */ - fputs(s, stream); /* rest of mantissa */ - if (e) { - fputc((base>10) ? '@' : 'e', stream); l++; - sprintf(s, "%ld", e); - l += strlen(s); - fprintf(stream, "%s", s); - } - - (*_mp_free_func)(s0, l); - return l; -} diff --git a/gmp/mpfr/pi.c b/gmp/mpfr/pi.c deleted file mode 100755 index 322a2ab..0000000 --- a/gmp/mpfr/pi.c +++ /dev/null @@ -1,131 +0,0 @@ -/* mpfr_pi -- compute Pi - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* -Set x to the value of Pi to precision PREC(x) rounded to direction rnd_mode. -Use the formula giving the binary representation of Pi found by Simon Plouffe -and the Borwein's brothers: - - infinity 4 2 1 1 - ----- ------- - ------- - ------- - ------- - \ 8 n + 1 8 n + 4 8 n + 5 8 n + 6 - Pi = ) ------------------------------------- - / n - ----- 16 - n = 0 - -i.e. Pi*16^N = S(N) + R(N) where -S(N) = sum(16^(N-n)*(4/(8*n+1)-2/(8*n+4)-1/(8*n+5)-1/(8*n+6)), n=0..N-1) -R(N) = sum((4/(8*n+1)-2/(8*n+4)-1/(8*n+5)-1/(8*n+6))/16^(n-N), n=N..infinity) - -Let f(n) = 4/(8*n+1)-2/(8*n+4)-1/(8*n+5)-1/(8*n+6), we can show easily that -f(n) < 15/(64*n^2), so R(N) < sum(15/(64*n^2)/16^(n-N), n=N..infinity) - < 15/64/N^2*sum(1/16^(n-N), n=N..infinity) - = 1/4/N^2 - -Now let S'(N) = sum(floor(16^(N-n)*(120*n^2+151*n+47), - (512*n^4+1024*n^3+712*n^2+194*n+15)), n=0..N-1) - -S(N)-S'(N) <= sum(1, n=0..N-1) = N - -so Pi*16^N-S'(N) <= N+1 (as 1/4/N^2 < 1) -*/ - -mpfr_t __mpfr_pi; /* stored value of Pi */ -int __mpfr_pi_prec=0; /* precision of stored value */ -char __mpfr_pi_rnd; /* rounding mode of stored value */ - -void -#if __STDC__ -mpfr_pi(mpfr_ptr x, unsigned char rnd_mode) -#else -mpfr_pi(x, rnd_mode) - mpfr_ptr x; - unsigned char rnd_mode; -#endif -{ - int N, oldN, n, prec; mpz_t pi, num, den, d3, d2, tmp; mpfr_t y; - - prec=PREC(x); - - /* has stored value enough precision ? */ - if ((prec==__mpfr_pi_prec && rnd_mode==__mpfr_pi_rnd) || - (prec<=__mpfr_pi_prec && - mpfr_can_round(__mpfr_pi, __mpfr_pi_prec, __mpfr_pi_rnd, rnd_mode, prec))) - { - mpfr_set(x, __mpfr_pi, rnd_mode); return; - } - - /* need to recompute */ - N=1; - do { - oldN = N; - N = (prec+3)/4 + (int)ceil(log((double)N+1.0)/log(2.0)); - } while (N != oldN); - mpz_init(pi); mpz_init(num); mpz_init(den); mpz_init(d3); mpz_init(d2); - mpz_init(tmp); - mpz_set_ui(pi, 0); - mpz_set_ui(num, 16); /* num(-1) */ - mpz_set_ui(den, 21); /* den(-1) */ - mpz_set_si(d3, -2454); - mpz_set_ui(d2, 14736); - /* invariants: num=120*n^2+151*n+47, den=512*n^4+1024*n^3+712*n^2+194*n+15 - d3 = 2048*n^3+400*n-6, d2 = 6144*n^2-6144*n+2448 - */ - for (n=0; n0) mpz_add_ui(d2, d2, 12288*(n-1)); - else mpz_sub_ui(d2, d2, 12288); - /* d3(n) - d3(n-1) = d2 */ - mpz_add(d3, d3, d2); - /* den(n)-den(n-1) = 2048*n^3 + 400n - 6 = d3 */ - mpz_add(den, den, d3); - mpz_mul_2exp(tmp, num, 4*(N-n)); - mpz_fdiv_q(tmp, tmp, den); - mpz_add(pi, pi, tmp); - } - mpfr_set_z(x, pi, rnd_mode); - mpfr_init2(y, mpfr_get_prec(x)); - mpz_add_ui(pi, pi, N+1); - mpfr_set_z(y, pi, rnd_mode); - if (mpfr_cmp(x, y) != 0) { - fprintf(stderr, "does not converge\n"); exit(1); - } - EXP(x) -= 4*N; - mpz_clear(pi); mpz_clear(num); mpz_clear(den); mpz_clear(d3); mpz_clear(d2); - mpz_clear(tmp); mpfr_clear(y); - - /* store computed value */ - if (__mpfr_pi_prec==0) mpfr_init2(__mpfr_pi, prec); - else mpfr_set_prec(__mpfr_pi, prec); - mpfr_set(__mpfr_pi, x, rnd_mode); - __mpfr_pi_prec=prec; - __mpfr_pi_rnd=rnd_mode; -} diff --git a/gmp/mpfr/pow.c b/gmp/mpfr/pow.c deleted file mode 100755 index c53819e..0000000 --- a/gmp/mpfr/pow.c +++ /dev/null @@ -1,67 +0,0 @@ -/* mpfr_pow_ui, mpfr_ui_pow_ui -- compute the power of a floating-point - number or machine integer - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "mpfr.h" - -/* sets x to y^n */ -void -#if __STDC__ -mpfr_pow_ui (mpfr_ptr x, mpfr_srcptr y, unsigned int n, unsigned char rnd) -#else -mpfr_pow_ui (x, y, n, rnd) - mpfr_ptr x; - mpfr_srcptr y; - unsigned int n; - unsigned char rnd; -#endif -{ - int i; - - if (n==0) { mpfr_set_ui(x, 1, rnd); return; } - mpfr_set(x, y, rnd); - for (i=0;(1<=0; i--) { - mpfr_mul(x, x, x, rnd); - if (n & (1<=0; i--) { - mpfr_mul(x, x, x, rnd); - if (n & (1< -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_get_str_raw(char *digit_ptr, mpfr_srcptr x) -#else -mpfr_get_str_raw(digit_ptr, x) - char *digit_ptr; - mpfr_srcptr x; -#endif -{ - mp_limb_t *mx, wd, t; long ex, sx, k, l, p; - - mx = MANT(x); - ex = EXP(x); - p = PREC(x); - - if (SIGN(x) < 0) { *digit_ptr = '-'; digit_ptr++; } - sprintf(digit_ptr, "0."); digit_ptr += 2; - - sx = 1+(p-1)/mp_bits_per_limb; /* number of significant limbs */ - for (k = sx - 1; k >= 0 ; k--) - { - wd = mx[k]; - t = ((mp_limb_t)1) << (BITS_PER_MP_LIMB - 1); - for (l = BITS_PER_MP_LIMB - 1; l>=0; l--) - { - if (wd & t) - { *digit_ptr = '1'; digit_ptr++; } - else - { *digit_ptr = '0'; digit_ptr++; } - t >>= 1; - if (--p==0) { *digit_ptr = '['; digit_ptr++; } - } - } - sprintf(digit_ptr, "]E%ld", ex); -} - -void -#if __STDC__ -mpfr_print_raw(mpfr_srcptr x) -#else -mpfr_print_raw(x) - mpfr_srcptr x; -#endif -{ - char *str; - - if (FLAG_NAN(x)) printf("NaN"); - else if (!NOTZERO(x)) printf("0"); - else { - /* 3 char for sign + 0 + binary point - + ABSSIZE(x) * BITS_PER_MP_LIMB for mantissa - + 2 for brackets in mantissa - + 1 for 'E' - + 11 for exponent (including sign) - = 17 + ABSSIZE(x) * BITS_PER_MP_LIMB - */ - str = (char *) malloc((17 + ABSSIZE(x) * BITS_PER_MP_LIMB)*sizeof(char)); - mpfr_get_str_raw(str, x); - - printf("%s", str); - free(str); - } -} - diff --git a/gmp/mpfr/print_rnd_mode.c b/gmp/mpfr/print_rnd_mode.c deleted file mode 100755 index a7bc1d0..0000000 --- a/gmp/mpfr/print_rnd_mode.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpfr_print_rnd_mode -- convert a given rounding mode to a string - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -char * -#if __STDC__ -mpfr_print_rnd_mode(unsigned char rnd_mode) -#else -mpfr_print_rnd_mode(rnd_mode) - unsigned char rnd_mode; -#endif -{ - switch (rnd_mode) - { - case GMP_RNDD: return("GMP_RNDD"); - case GMP_RNDU: return("GMP_RNDU"); - case GMP_RNDN: return("GMP_RNDN"); - case GMP_RNDZ: return("GMP_RNDZ"); - default: return("unknown rounding mode"); - } -} diff --git a/gmp/mpfr/random.c b/gmp/mpfr/random.c deleted file mode 100755 index e61ddc0..0000000 --- a/gmp/mpfr/random.c +++ /dev/null @@ -1,74 +0,0 @@ -/* mpfr_random -- generate a random floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* Computes a random mpfr in [0, 1[ with precision PREC */ - -extern long random _PROTO((void)); -extern int srandom _PROTO((unsigned int)); - -/* extracted from GNU mpf */ -#if defined (__hpux) || defined (__alpha) -/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */ -#define random mrand48 -#define srandom srand48 -#endif - -void -#if __STDC__ -mpfr_random(mpfr_ptr x) -#else -mpfr_random(x) - mpfr_ptr x; -#endif -{ - mp_limb_t *xp; unsigned long xn, i, cnt, prec=PREC(x); - - xp = MANT(x); - xn = (prec-1)/BITS_PER_MP_LIMB + 1; - - for (i = 0; i < xn; i++) - { - /* random() c/sh/ould be replaced by a homemade random number generator. - Indeed, if on Linux random is a good RNG, this is definitely not - the case in most Un*xes. */ - xp[i] = random(); - } - - count_leading_zeros(cnt, xp[xn - 1]); - if (cnt) mpn_lshift(xp, xp, xn, cnt); - EXP(x) = -cnt; - - cnt = xn*BITS_PER_MP_LIMB - prec; - /* cnt is the number of non significant bits in the low limb */ - xp[0] &= ~((((mp_limb_t)1)< -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -#ifdef Exp -#include "longlong.h" -#endif - -/* returns 0 if round(sign*xp[0..xn-1], prec, rnd) = - round(sign*xp[0..xn-1], prec, GMP_RNDZ), 1 otherwise, - where sign=1 if neg=0, sign=-1 otherwise. - - Does *not* modify anything. -*/ -int -#if __STDC__ -mpfr_round_raw2(mp_limb_t *xp, unsigned long xn, - char neg, char rnd, unsigned long prec) -#else -mpfr_round_raw2(xp, xn, neg, rnd, prec) - mp_limb_t *xp; - unsigned long xn; - char neg; - char rnd; - unsigned long prec; -#endif -{ - unsigned long nw; long wd; char rw; short l; mp_limb_t mask; - - nw = prec / BITS_PER_MP_LIMB; rw = prec & (BITS_PER_MP_LIMB - 1); - if (rw) nw++; - if (rnd==GMP_RNDZ || xn 0 && !xp[wd]); - if (!wd) { return 1; } else return xp[xn - nw] & 1; - } - - return xp[wd]>>(BITS_PER_MP_LIMB - 1); - } - else - if (rw + 1 < BITS_PER_MP_LIMB) - { - if ((xp[wd] & (~mask)) == (((mp_limb_t)1) << (BITS_PER_MP_LIMB - rw - 1))) - do { wd--; } while (wd >= 0 && !xp[wd]); - else return ((xp[wd]>>(BITS_PER_MP_LIMB - rw - 1)) & 1); - - /* first limb was in the middle, and others down to wd+1 were 0 */ - if (wd>=0) return 1; - else - return ((xp[xn - nw] & mask) >> (BITS_PER_MP_LIMB - rw)) & 1; - } - else - /* Modified PZ, 27 May 1999: - rw, i.e. the number of bits stored in xp[xn-nw], is - BITS_PER_MP_LIMB-1, i.e. there is exactly one non significant bit. - We are just halfway iff xp[wd] has its low significant bit - set and all limbs xp[0]...xp[wd-1] are zero */ - { - if (xp[wd] & 1) - do wd--; while (wd >= 0 && !xp[wd]); - return ((wd<0) ? xp[xn-nw]>>1 : xp[xn-nw]) & 1; - } - default: return 0; - } -} - -/* puts in y the value of xp (with precision xprec and sign 1 if negative=0, - -1 otherwise) rounded to precision yprec and direction RND_MODE - Supposes x is not zero nor NaN nor +/- Infinity (i.e. *xp != 0). -*/ -int -#if __STDC__ -mpfr_round_raw(mp_limb_t *y, mp_limb_t *xp, unsigned long xprec, char negative, - unsigned long yprec, char RND_MODE) -#else -mpfr_round_raw(y, xp, xprec, negative, yprec, RND_MODE) - mp_limb_t *y; - mp_limb_t *xp; - unsigned long xprec; - char negative; - unsigned long yprec; - char RND_MODE; -#endif -{ - unsigned long nw, xsize; mp_limb_t mask; - char rw, xrw, carry = 0; - - xsize = (xprec-1)/BITS_PER_MP_LIMB + 1; - xrw = xprec % BITS_PER_MP_LIMB; if (xrw == 0) { xrw = BITS_PER_MP_LIMB; } - -#ifdef Exp - count_leading_zeros(flag, xp[xsize-1]); - yprec += flag; -#endif - - nw = yprec / BITS_PER_MP_LIMB; rw = yprec & (BITS_PER_MP_LIMB - 1); - if (rw) nw++; - /* number of words needed to represent x */ - - mask = ~((((mp_limb_t)1)<<(BITS_PER_MP_LIMB - rw)) - (mp_limb_t)1); - - /* precision is larger than the size of x. No rounding is necessary. - Just add zeroes at the end */ - if (xsize < nw) { - MPN_COPY(y + nw - xsize, xp, xsize); - MPN_ZERO(y, nw - xsize); /* PZ 27 May 99 */ - y[0] &= mask; - return 0; - } - - if (mpfr_round_raw2(xp, xsize, negative, RND_MODE, yprec)) - carry = mpn_add_1(y, xp + xsize - nw, nw, - ((mp_limb_t)1) << (BITS_PER_MP_LIMB - rw)); - else MPN_COPY(y, xp + xsize - nw, nw); - - y[0] &= mask; - return carry; -} - -void -#if __STDC__ -mpfr_round(mpfr_t x, char RND_MODE, unsigned long prec) -#else -mpfr_round(x, RND_MODE, prec) - mpfr_t x; - char RND_MODE; - unsigned long prec; -#endif -{ - mp_limb_t *tmp; int carry; unsigned long nw; - TMP_DECL(marker); - - nw = prec / BITS_PER_MP_LIMB; - if (prec & (BITS_PER_MP_LIMB - 1)) nw++; - TMP_MARK(marker); - tmp = (mp_limb_t *)TMP_ALLOC (nw * BYTES_PER_MP_LIMB); - carry = mpfr_round_raw(tmp, MANT(x), PREC(x), (SIGN(x)<0), prec, RND_MODE); - - if (carry) - { - mpn_rshift(tmp, tmp, nw, 1); - tmp [nw-1] |= (((mp_limb_t)1) << (BITS_PER_MP_LIMB - 1)); - EXP(x)++; - } - - if (SIGN(x)<0) { SIZE(x)=nw; CHANGE_SIGN(x); } else SIZE(x)=nw; - PREC(x) = prec; - MPN_COPY(MANT(x), tmp, nw); - TMP_FREE(marker); -} - -/* hypotheses : BITS_PER_MP_LIMB est une puissance de 2 - dans un test, la premiere partie du && est evaluee d'abord */ - - -/* assuming b is an approximation of x in direction rnd1 - with error at most 2^(EXP(b)-err), returns 1 if one is - able to round exactly x to precision prec with direction rnd2, - and 0 otherwise. - - Side effects: none. -*/ - -int -#if __STDC__ -mpfr_can_round(mpfr_t b, unsigned long err, unsigned char rnd1, - unsigned char rnd2, unsigned long prec) -#else -mpfr_can_round(b, err, rnd1, rnd2, prec) - mpfr_t b; - unsigned long err; - unsigned char rnd1; - unsigned char rnd2; - unsigned long prec; -#endif -{ - return mpfr_can_round_raw(MANT(b), (PREC(b) - 1)/BITS_PER_MP_LIMB + 1, - SIGN(b), err, rnd1, rnd2, prec); -} - -int -#if __STDC__ -mpfr_can_round_raw(mp_limb_t *bp, unsigned long bn, int neg, - unsigned long err, unsigned char rnd1, unsigned char rnd2, - unsigned long prec) -#else -mpfr_can_round_raw(bp, bn, neg, err, rnd1, rnd2, prec) - mp_limb_t *bp; - unsigned long bn; - int neg; - unsigned long err; - unsigned char rnd1; - unsigned char rnd2; - unsigned long prec; -#endif -{ - int k, k1, l, l1, tn; mp_limb_t cc, cc2, *tmp; - TMP_DECL(marker); - - if (err<=prec) return 0; - neg = (neg > 0 ? 0 : 1); - - /* warning: if k = m*BITS_PER_MP_LIMB, consider limb m-1 and not m */ - k = (err-1)/BITS_PER_MP_LIMB; - l = err % BITS_PER_MP_LIMB; if (l) l = BITS_PER_MP_LIMB-l; - /* the error corresponds to bit l in limb k */ - k1 = (prec-1)/BITS_PER_MP_LIMB; - l1 = prec%BITS_PER_MP_LIMB; if (l1) l1 = BITS_PER_MP_LIMB-l1; - - /* the last significant bit is bit l1 in limb k1 */ - - /* don't need to consider the k1 most significant limbs */ - k -= k1; bn -= k1; prec -= k1*BITS_PER_MP_LIMB; k1=0; - - if (rnd1==GMP_RNDU) { if (neg) rnd1=GMP_RNDZ; } - if (rnd1==GMP_RNDD) { if (neg) rnd1=GMP_RNDU; else rnd1=GMP_RNDZ; } - - /* in the sequel, RNDU = towards infinity, RNDZ = towards zero */ - - TMP_MARK(marker); - tn = bn; - k++; /* since we work with k+1 everywhere */ - - switch (rnd1) { - - case GMP_RNDZ: /* b <= x <= b+2^(EXP(b)-err) */ - tmp = (mp_limb_t *)TMP_ALLOC(tn*BYTES_PER_MP_LIMB); - cc = (bp[bn-1]>>l1) & 1; - cc ^= mpfr_round_raw2(bp, bn, neg, rnd2, prec); - - /* now round b+2^(EXP(b)-err) */ - cc2 = mpn_add_1(tmp+bn-k, bp+bn-k, k, (mp_limb_t)1<>l1) & 1; /* gives 0 when carry */ - cc2 ^= mpfr_round_raw2(tmp, bn, neg, rnd2, prec); - - TMP_FREE(marker); - return (cc == cc2); - - case GMP_RNDU: /* b-2^(EXP(b)-err) <= x <= b */ - tmp = (mp_limb_t *)TMP_ALLOC(tn*BYTES_PER_MP_LIMB); - /* first round b */ - cc = (bp[bn-1]>>l1) & 1; - cc ^= mpfr_round_raw2(bp, bn, neg, rnd2, prec); - - /* now round b-2^(EXP(b)-err) */ - cc2 = mpn_sub_1(tmp+bn-k, bp+bn-k, k, (mp_limb_t)1<>l1) & 1; /* gives 1 when carry */ - cc2 ^= mpfr_round_raw2(tmp, bn, neg, rnd2, prec); - - TMP_FREE(marker); - return (cc == cc2); - - case GMP_RNDN: /* b-2^(EXP(b)-err-1) <= x <= b+2^(EXP(b)-err-1) */ - if (l==0) tn++; - tmp = (mp_limb_t *)TMP_ALLOC(tn*BYTES_PER_MP_LIMB); - - /* this case is the same than GMP_RNDZ, except we first have to - subtract 2^(EXP(b)-err-1) from b */ - - if (l) { - l--; /* tn=bn */ - mpn_sub_1(tmp+tn-k, bp+bn-k, k, (mp_limb_t)1<>l1) & 1; - cc ^= mpfr_round_raw2(tmp, tn, neg, rnd2, prec); - - if (l==BITS_PER_MP_LIMB-1) { l=0; k--; } else l++; - - /* round b+2^(EXP(b)-err-1) = b-2^(EXP(b)-err-1) + 2^(EXP(b)-err) */ - cc2 = mpn_add_1(tmp+tn-k, tmp+tn-k, k, (mp_limb_t)1<>l1) & 1; /* gives 0 when carry */ - cc2 ^= mpfr_round_raw2(tmp, tn, neg, rnd2, prec); - - TMP_FREE(marker); - return (cc == cc2); - } - return 0; -} diff --git a/gmp/mpfr/set.c b/gmp/mpfr/set.c deleted file mode 100755 index 7177925..0000000 --- a/gmp/mpfr/set.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpfr_set -- copy of a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_set4(mpfr_ptr a, mpfr_srcptr b, unsigned char rnd_mode, int signb) -#else -mpfr_set4(a, b, rnd_mode, signb) - mpfr_ptr a; - mpfr_srcptr b; - unsigned char rnd_mode; - int signb; -#endif -{ - int carry, an, preca = PREC(a), sh; mp_limb_t *ap = MANT(a); - - carry = mpfr_round_raw(ap, MANT(b), PREC(b), (signb<0), preca, rnd_mode); - EXP(a) = EXP(b); - if (carry) { - an = (preca-1)/BITS_PER_MP_LIMB + 1; - sh = an * BITS_PER_MP_LIMB - preca; - if ((*ap >> sh) & 1) { - fprintf(stderr, "unable to round in mpfr_set\n"); exit(1); - } - mpn_rshift(ap, ap, an, 1); - ap[an-1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - EXP(a)++; - } - if (SIGN(a) != signb) CHANGE_SIGN(a); -} diff --git a/gmp/mpfr/set_d.c b/gmp/mpfr/set_d.c deleted file mode 100755 index 35c3ba2..0000000 --- a/gmp/mpfr/set_d.c +++ /dev/null @@ -1,329 +0,0 @@ -/* mpfr_set_d, mpfr_get_d -- convert a multiple precision floating-point number - from/to a machine double precision float - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#if __GNUC__ /* gcc "patched" headers seem to omit isnan... */ -extern int isnan(double); -#endif -#include /* for isnan and NaN */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -#define NaN sqrt(-1) /* ensures a machine-independent NaN */ - -/* Included from gmp-2.0.2, patched to support denorms */ - -#ifdef XDEBUG -#undef _GMP_IEEE_FLOATS -#endif - -#ifndef _GMP_IEEE_FLOATS -#define _GMP_IEEE_FLOATS 0 -#endif - -int -#if __STDC__ -__mpfr_extract_double (mp_ptr rp, double d, int e) -#else -__mpfr_extract_double (rp, d, e) - mp_ptr rp; - double d; - int e; -#endif - /* e=0 iff BITS_PER_MP_LIMB=32 and rp has only one limb */ -{ - long exp; - mp_limb_t manl; -#if BITS_PER_MP_LIMB == 32 - mp_limb_t manh; -#endif - - /* BUGS - - 1. Should handle Inf and NaN in IEEE specific code. - 2. Handle Inf and NaN also in default code, to avoid hangs. - 3. Generalize to handle all BITS_PER_MP_LIMB >= 32. - 4. This lits is incomplete and misspelled. - */ - - if (d == 0.0) - { - rp[0] = 0; -#if BITS_PER_MP_LIMB == 32 - if (e) rp[1] = 0; -#endif - return 0; - } - -#if _GMP_IEEE_FLOATS - { - union ieee_double_extract x; - x.d = d; - - exp = x.s.exp; - if (exp) - { -#if BITS_PER_MP_LIMB == 64 - manl = (((mp_limb_t) 1 << 63) - | ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11)); -#else - manh = ((mp_limb_t) 1 << 31) | (x.s.manh << 11) | (x.s.manl >> 21); - manl = x.s.manl << 11; -#endif - } - else - { -#if BITS_PER_MP_LIMB == 64 - manl = ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11); -#else - manh = (x.s.manh << 11) | (x.s.manl >> 21); - manl = x.s.manl << 11; -#endif - } - } -#else - { - /* Unknown (or known to be non-IEEE) double format. */ - exp = 0; - if (d >= 1.0) - { - if (d * 0.5 == d) - abort (); - - while (d >= 32768.0) - { - d *= (1.0 / 65536.0); - exp += 16; - } - while (d >= 1.0) - { - d *= 0.5; - exp += 1; - } - } - else if (d < 0.5) - { - while (d < (1.0 / 65536.0)) - { - d *= 65536.0; - exp -= 16; - } - while (d < 0.5) - { - d *= 2.0; - exp -= 1; - } - } - - d *= MP_BASE_AS_DOUBLE; -#if BITS_PER_MP_LIMB == 64 - manl = d; -#else - manh = d; - manl = (d - manh) * MP_BASE_AS_DOUBLE; -#endif - - exp += 1022; - } -#endif - - if (exp) exp = (unsigned) exp - 1022; else exp = -1021; - -#if BITS_PER_MP_LIMB == 64 - rp[0] = manl; -#else - if (e) { - rp[1] = manh; - rp[0] = manl; - } - else { - rp[0] = manh; - } -#endif - - return exp; -} - -/* End of part included from gmp-2.0.2 */ -/* Part included from gmp temporary releases */ -double -#if __STDC__ -__mpfr_scale2 (double d, int exp) -#else -__mpfr_scale2 (d, exp) - double d; - int exp; -#endif -{ -#if _GMP_IEEE_FLOATS - { - union ieee_double_extract x; - x.d = d; - exp += x.s.exp; - x.s.exp = exp; - if (exp >= 2047) - { - /* Return +-infinity */ - x.s.exp = 2047; - x.s.manl = x.s.manh = 0; - } - else if (exp < 1) - { - x.s.exp = 1; /* smallest exponent (biased) */ - /* Divide result by 2 until we have scaled it to the right IEEE - denormalized number, but stop if it becomes zero. */ - while (exp < 1 && x.d != 0) - { - x.d *= 0.5; - exp++; - } - } - return x.d; - } -#else - { - double factor, r; - - factor = 2.0; - if (exp < 0) - { - factor = 0.5; - exp = -exp; - } - r = d; - if (exp != 0) - { - if ((exp & 1) != 0) - r *= factor; - exp >>= 1; - while (exp != 0) - { - factor *= factor; - if ((exp & 1) != 0) - r *= factor; - exp >>= 1; - } - } - return r; - } -#endif -} - - -/* End of part included from gmp */ - -void -#if __STDC__ -mpfr_set_d(mpfr_t r, double d, unsigned char rnd_mode) -#else -mpfr_set_d(r, d, rnd_mode) - mpfr_t r; - double d; - unsigned char rnd_mode; -#endif -{ - int signd, sizer; unsigned int cnt; - - if (d == 0) { SET_ZERO(r); return; } - else if (isnan(d)) { SET_NAN(r); return; } - - signd = (d < 0) ? -1 : 1; - d = ABS (d); - sizer = (PREC(r)-1)/BITS_PER_MP_LIMB + 1; - - /* warning: __mpfr_extract_double requires at least two limbs */ - if (sizer < MPFR_LIMBS_PER_DOUBLE) - EXP(r) = __mpfr_extract_double (MANT(r), d, 0); - else - EXP(r) = __mpfr_extract_double (MANT(r) + sizer - MPFR_LIMBS_PER_DOUBLE, d, 1); - - if (sizer > MPFR_LIMBS_PER_DOUBLE) - MPN_ZERO(MANT(r), sizer - MPFR_LIMBS_PER_DOUBLE); - - count_leading_zeros(cnt, MANT(r)[sizer-1]); - if (cnt) mpn_lshift(MANT(r), MANT(r), sizer, cnt); - - EXP(r) -= cnt; - if (SIZE(r)*signd<0) CHANGE_SIGN(r); - - mpfr_round(r, rnd_mode, PREC(r)); - return; -} - -double -#if __STDC__ -mpfr_get_d2(mpfr_srcptr src, long e) -#else -mpfr_get_d2(src, e) - mpfr_srcptr(src); - long e; -#endif -{ - double res; - mp_size_t size, i, n_limbs_to_use; - mp_ptr qp; - int negative; - - if (FLAG_NAN(src)) { -#ifdef DEBUG - printf("recognized NaN\n"); -#endif - return NaN; } - if (NOTZERO(src)==0) return 0.0; - size = 1+(PREC(src)-1)/BITS_PER_MP_LIMB; - qp = MANT(src); - negative = (SIGN(src)==-1); - - /* Warning: don't compute the abs(res) and set the sign afterwards, - otherwise the current machine rounding mode will not be taken - correctly into account. */ - /* res = (negative) ? -(double)qp[size - 1] : qp[size - 1]; */ - res = 0.0; - /* Warning: an arbitrary number of limbs may be required for an exact - rounding. The following code is correct but not optimal since one - may be able to decide without considering all limbs. */ - /* n_limbs_to_use = MIN (MPFR_LIMBS_PER_DOUBLE, size); */ - n_limbs_to_use = size; - /* Accumulate the limbs from less significant to most significant - otherwise due to rounding we may accumulate several ulps, - especially in rounding towards -/+infinity. */ - for (i = n_limbs_to_use; i>=1; i--) - res = res / MP_BASE_AS_DOUBLE + - ((negative) ? -(double)qp[size - i] : qp[size - i]); - res = __mpfr_scale2 (res, e - BITS_PER_MP_LIMB); - - return res; -} - -double -#if __STDC__ -mpfr_get_d(mpfr_srcptr src) -#else -mpfr_get_d(src) - mpfr_srcptr src; -#endif -{ - return mpfr_get_d2(src, EXP(src)); -} - diff --git a/gmp/mpfr/set_dfl_prec.c b/gmp/mpfr/set_dfl_prec.c deleted file mode 100755 index aa341be..0000000 --- a/gmp/mpfr/set_dfl_prec.c +++ /dev/null @@ -1,37 +0,0 @@ -/* mpfr_set_default_prec -- set the default precision - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* default is 53 bits */ -mp_size_t __gmp_default_fp_bit_precision = 53; - -void -#if __STDC__ -mpfr_set_default_prec (unsigned long int prec_in_bits) -#else -mpfr_set_default_prec (prec_in_bits) - unsigned long int prec_in_bits; -#endif -{ - __gmp_default_fp_bit_precision = prec_in_bits; -} diff --git a/gmp/mpfr/set_dfl_rnd.c b/gmp/mpfr/set_dfl_rnd.c deleted file mode 100755 index cf8fd01..0000000 --- a/gmp/mpfr/set_dfl_rnd.c +++ /dev/null @@ -1,37 +0,0 @@ -/* mpfr_set_default_rounding_mode -- set the default rounding mode - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -char __gmp_default_rounding_mode = 0; - -void -#if __STDC__ -mpfr_set_default_rounding_mode (char rnd_mode) -#else -mpfr_set_default_rounding_mode (rnd_mode) - char rnd_mode; -#endif -{ - __gmp_default_rounding_mode = rnd_mode; -} - diff --git a/gmp/mpfr/set_f.c b/gmp/mpfr/set_f.c deleted file mode 100755 index d3bb98d..0000000 --- a/gmp/mpfr/set_f.c +++ /dev/null @@ -1,72 +0,0 @@ -/* mpfr_set_f -- set a MPFR number from a GNU MPF number - -Copyright (C) 1999-2000 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_set_f(mpfr_ptr y, mpf_srcptr x, char rnd_mode) -#else -mpfr_set_f(y, x, rnd_mode) - mpfr_ptr y; - mpf_srcptr x; - char rnd_mode; -#endif -{ - mp_limb_t *my, *mx, *tmp; unsigned long cnt, sx, sy; - TMP_DECL(marker); - - sx = ABS(SIZ(x)); sy = ABSSIZE(y); - my = MANT(y); mx = MANT(x); - - if (sx==0) { /* x is zero */ - SET_ZERO(y); return; - } - - count_leading_zeros(cnt, mx[sx - 1]); - - if (SIZ(x)*SIGN(y)<0) CHANGE_SIGN(y); - - if (sy < sx) - { - unsigned long xprec = sx * BITS_PER_MP_LIMB; - - tmp = (mp_limb_t*) TMP_ALLOC(xprec); - if (cnt) mpn_lshift(tmp, mx, sx, cnt); - else MPN_COPY(tmp, mx, sx); - mpfr_round_raw(my, tmp, xprec, (SIZ(x)<0), PREC(y), rnd_mode); - } - else - { - if (cnt) mpn_lshift(my + sy - sx, mx, sx, cnt); - else MPN_COPY(my + sy - sx, mx, sy); - MPN_ZERO(my, sy - sx); - /* no rounding necessary, since y has a larger mantissa */ - } - - EXP(y) = EXP(x) * BITS_PER_MP_LIMB - cnt; - - TMP_FREE(marker); -} diff --git a/gmp/mpfr/set_prec.c b/gmp/mpfr/set_prec.c deleted file mode 100755 index d85eac3..0000000 --- a/gmp/mpfr/set_prec.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpfr_set_prec -- reset the precision of a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_set_prec (mpfr_t x, unsigned long int p) -#else -mpfr_set_prec (x, p) - mpfr_t x; - unsigned long int p; -#endif -{ - unsigned long xsize; - - if (p==0) { - printf("*** cannot set precision to 0 bits\n"); exit(1); - } - - xsize = (p - 1)/BITS_PER_MP_LIMB + 1; /* new limb size */ - - if (xsize > ABSSIZE(x)) { - x -> _mp_d = (mp_ptr) (*_mp_reallocate_func) - (x -> _mp_d, ABSSIZE(x)*BYTES_PER_MP_LIMB, xsize * BYTES_PER_MP_LIMB); - SIZE(x) = xsize; /* new number of allocated limbs */ - } - - x -> _mp_prec = p; -} - -unsigned long int -#if __STDC__ -mpfr_get_prec (mpfr_t x) -#else -mpfr_get_prec (x) - mpfr_t x; -#endif -{ - return x -> _mp_prec; -} diff --git a/gmp/mpfr/set_si.c b/gmp/mpfr/set_si.c deleted file mode 100755 index b2d916c..0000000 --- a/gmp/mpfr/set_si.c +++ /dev/null @@ -1,81 +0,0 @@ -/* mpfr_set_si, mpfr_set_ui -- set a MPFR number from a machine integer - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -void -#if __STDC__ -mpfr_set_si(mpfr_ptr x, long i, unsigned char rnd_mode) -#else -mpfr_set_si(x, i, rnd_mode) - mpfr_ptr x; - long i; - unsigned char rnd_mode; -#endif -{ - unsigned long xn, cnt; mp_limb_t ai; - - if (i==0) { SET_ZERO(x); return; } - xn = (PREC(x)-1)/BITS_PER_MP_LIMB; - ai = ABS(i); - - count_leading_zeros(cnt, ai); - - x -> _mp_d[xn] = ai << cnt; - /* don't forget to put zero in lower limbs */ - MPN_ZERO(MANT(x), xn); - x -> _mp_exp = BITS_PER_MP_LIMB - cnt; - /* warning: don't change the precision of x! */ - if (i*SIGN(x) < 0) CHANGE_SIGN(x); - - return; -} - -void -#if __STDC__ -mpfr_set_ui(mpfr_ptr x, unsigned long i, unsigned char rnd_mode) -#else -mpfr_set_ui(x, i, rnd_mode) - mpfr_ptr x; - long i; - unsigned char rnd_mode; -#endif -{ - unsigned int xn, cnt; - - if (i==0) { SET_ZERO(x); return; } - xn = (PREC(x)-1)/BITS_PER_MP_LIMB; - count_leading_zeros(cnt, (mp_limb_t) i); - - x -> _mp_d[xn] = ((mp_limb_t) i) << cnt; - /* don't forget to put zero in lower limbs */ - MPN_ZERO(MANT(x), xn); - x -> _mp_exp = BITS_PER_MP_LIMB - cnt; - /* warning: don't change the precision of x! */ - if (SIGN(x) < 0) CHANGE_SIGN(x); - - return; -} - diff --git a/gmp/mpfr/set_str_raw.c b/gmp/mpfr/set_str_raw.c deleted file mode 100755 index d0945c4..0000000 --- a/gmp/mpfr/set_str_raw.c +++ /dev/null @@ -1,112 +0,0 @@ -/* mpfr_set_str_raw -- set a floating-point number from a binary string - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#ifdef HAS_STRING_H -#include -#else -#include -#endif -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* Currently the number should be of the form +/- xxxx.xxxxxxEyy, with - decimal exponent. The mantissa of x is supposed to be large enough - to hold all the bits of str. */ - -void -#if __STDC__ -mpfr_set_str_raw(mpfr_ptr x, char *str) -#else -mpfr_set_str_raw(x, str) - mpfr_ptr x; - char *str; -#endif -{ - char *str2, *str0, negative = 0; - unsigned long j, l, k = 0, xsize, cnt; mp_limb_t *xp; - long expn = 0, e; char *endstr2; - - xp = x -> _mp_d; - xsize = 1 + (PREC(x)-1)/BITS_PER_MP_LIMB; - str0 = str2 = (char *) malloc((strlen(str)+1)*sizeof(char)); - - if (*str == '-') { negative = 1; str++; } - else if (*str == '+') str++; - - while (*str == '0') { str++; } - - while (*str == '0' || *str == '1') - { *(str2++) = *(str++); k++; } - - if (*str == '.') - { - str++; - while (*str == '0' || *str == '1') - { *(str2++) = *(str++); } - - if (*str == '[') { while (*str != ']') str++; } - } - - if (*str == '[') { while (*str != ']') str++; } - - if (*str == 'e' || *str == 'E') - { - e = atol(++str); /* signed exponent after 'e' or 'E' */ - expn = k + e; - if (expn < e) - fprintf(stderr, "Warning: overflow in exponent in Str -> mpfr\n"); - } - else expn=k; - - endstr2 = str2; - *str2 = (char) 0; /* end of string */ - l = (strlen(str0) - 1) / BITS_PER_MP_LIMB + 1; str2 = str0; - - /* str2[0]..endstr2[-1] contains the mantissa */ - for (k = 1; k <= l; k++) - { - j = 0; - xp[xsize - k] = 0; - while (str2 _mp_exp = expn - cnt; - x -> _mp_size = xsize; if (negative) CHANGE_SIGN(x); - - free(str0); - - /* May change to take into account : syntax errors, overflow in exponent, - string truncated because of size of x */ -} diff --git a/gmp/mpfr/set_z.c b/gmp/mpfr/set_z.c deleted file mode 100755 index de91320..0000000 --- a/gmp/mpfr/set_z.c +++ /dev/null @@ -1,104 +0,0 @@ -/* mpfr_set_z -- set a floating-point number from a multiple-precision integer - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* set f to the integer z */ -int -#if __STDC__ -mpfr_set_z (mpfr_ptr f, mpz_srcptr z, unsigned char rnd) -#else -mpfr_set_z (f, z, rnd) - mpfr_ptr f; - mpz_srcptr z; - unsigned char rnd; -#endif -{ - int fn, zn, k, dif, sign_z, sh; mp_limb_t *fp = MANT(f), *zp, cc, c2; - - sign_z = mpz_cmp_ui(z,0); - if (sign_z==0) return (SIZE(f)=0); - fn = 1 + (PREC(f)-1)/BITS_PER_MP_LIMB; - zn = ABS(SIZ(z)); - dif = zn-fn; - zp = PTR(z); - count_leading_zeros(k, zp[zn-1]); - EXP(f) = zn*BITS_PER_MP_LIMB-k; - if (SIGN(f)*sign_z<0) CHANGE_SIGN(f); - if (dif>=0) { /* number has to be truncated */ - if (k) { - mpn_lshift(fp, zp + dif, fn, k); - if (dif) *fp += zp[dif-1] >> (BITS_PER_MP_LIMB-k); - } - else MPN_COPY(fp, zp + dif, fn); - sh = fn*BITS_PER_MP_LIMB-PREC(f); - cc = *fp & (((mp_limb_t)1 << sh) - 1); - *fp = *fp & ~cc; - if (rnd==GMP_RNDN) { - if (sh) c2 = (mp_limb_t)1 << (sh-1); - else { /* sh=0 */ - c2 = ((mp_limb_t)1) << (BITS_PER_MP_LIMB-1); - dif--; - cc = (dif>=0) ? ((zp[dif])<0 && k) cc += zp[dif-1] >> (BITS_PER_MP_LIMB-k); - } - /* now compares cc to c2 */ - if (cc>c2) { mpfr_add_one_ulp(f); return cc; } - else if (cc0 && (cc=zp[dif-1])==0) dif--; - if (cc) { mpfr_add_one_ulp(f); return cc; } - else /* exactly in middle: inexact in both cases */ - if (*fp & ((mp_limb_t)1<0 && rnd==GMP_RNDU) || (sign_z<0 && rnd==GMP_RNDD)) { - /* round towards infinity */ - /* result is exact iff all remaining bits are zero */ - if (dif>0 && cc==0) cc=zp[--dif]<0) cc=zp[--dif]; - if (cc) { mpfr_add_one_ulp(f); return 1; } - else return 0; - } - else { /* round towards zero */ - /* result is exact iff all remaining bits are zero */ - towards_zero: - if (cc==0 && dif>0) cc=zp[--dif]<0) cc=zp[--dif]; - return cc; - } - } - else { - if (k) mpn_lshift(fp-dif, zp, zn, k); - else MPN_COPY(fp-dif, zp, zn); - /* fill with zeroes */ - MPN_ZERO(fp, -dif); - return 0; /* result is exact */ - } -} - - - diff --git a/gmp/mpfr/sqrt.c b/gmp/mpfr/sqrt.c deleted file mode 100755 index a34ff6d..0000000 --- a/gmp/mpfr/sqrt.c +++ /dev/null @@ -1,220 +0,0 @@ -/* mpfr_sqrt -- square root of a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" -#include "longlong.h" - -/* #define DEBUG */ - -int -mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, unsigned char rnd_mode) -{ - mp_ptr up, rp, tmp, remp; - mp_size_t usize, rrsize; - mp_size_t rsize; - mp_size_t prec, err; - mp_limb_t q_limb; - long rw, nw, k; - int exact = 0; - unsigned long cc = 0; - char can_round = 0; - TMP_DECL (marker); TMP_DECL(marker0); - - if (FLAG_NAN(u) || SIGN(u) == -1) { SET_NAN(r); return 0; } - - prec = PREC(r); - - if (!NOTZERO(u)) - { - EXP(r) = 0; - MPN_ZERO(MANT(r), ABSSIZE(r)); - return 1; - } - - up = MANT(u); - -#ifdef DEBUG - printf("Entering square root : "); - for(k = usize - 1; k >= 0; k--) { printf("%lu ", up[k]); } - printf(".\n"); -#endif - - /* Compare the mantissas */ - - usize = (PREC(u) - 1)/BITS_PER_MP_LIMB + 1; - rsize = ((PREC(r) + 2 + (EXP(u) & 1))/BITS_PER_MP_LIMB + 1) << 1; - rrsize = (PREC(r) + 2 + (EXP(u) & 1))/BITS_PER_MP_LIMB + 1; - /* One extra bit is needed in order to get the square root with enough - precision ; take one extra bit for rrsize in order to solve more - easily the problem of rounding to nearest. - Need to have 2*rrsize = rsize... - Take one extra bit if the exponent of u is odd since we shall have - to shift then. - */ - - TMP_MARK(marker0); - if (EXP(u) & 1) /* Shift u one bit to the right */ - { - if (PREC(u) & (BITS_PER_MP_LIMB - 1)) - { - up = TMP_ALLOC(usize*BYTES_PER_MP_LIMB); - mpn_rshift(up, u->_mp_d, usize, 1); - } - else - { - up = TMP_ALLOC((usize + 1)*BYTES_PER_MP_LIMB); - if (mpn_rshift(up + 1, u->_mp_d, ABSSIZE(u), 1)) - up [0] = ((mp_limb_t) 1) << (BITS_PER_MP_LIMB - 1); - else up[0] = 0; - usize++; - } - } - - EXP(r) = ((EXP(u) + (EXP(u) & 1)) / 2) ; - - do - { - TMP_MARK (marker); - - err = rsize*BITS_PER_MP_LIMB; - if (rsize < usize) { err--; } - if (err > rrsize * BITS_PER_MP_LIMB) - { err = rrsize * BITS_PER_MP_LIMB; } - - tmp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB); - rp = (mp_ptr) TMP_ALLOC (rrsize * BYTES_PER_MP_LIMB); - remp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB); - - if (usize >= rsize) { - MPN_COPY (tmp, up + usize - rsize, rsize); - } - else { - MPN_COPY (tmp + rsize - usize, up, usize); - MPN_ZERO (tmp, rsize - usize); - } - - /* Do the real job */ - -#ifdef DEBUG - printf("Taking the sqrt of : "); - for(k = rsize - 1; k >= 0; k--) { - printf("+%lu*2^%lu",tmp[k],k*mp_bits_per_limb); } - printf(".\n"); -#endif - - q_limb = kara_sqrtrem (rp, remp, tmp, rsize); - -#ifdef DEBUG - printf("The result is : \n"); - printf("sqrt : "); - for(k = rrsize - 1; k >= 0; k--) { printf("%lu ", rp[k]); } - printf("(q_limb = %lu)\n", q_limb); -#endif - - can_round = (mpfr_can_round_raw(rp, rrsize, 1, err, - GMP_RNDZ, rnd_mode, PREC(r))); - - /* If we used all the limbs of both the dividend and the divisor, - then we have the correct RNDZ rounding */ - - if (!can_round && (rsize < 2*usize)) - { -#ifdef DEBUG - printf("Increasing the precision.\n"); -#endif - TMP_FREE(marker); - } - } - while (!can_round && (rsize < 2*usize) - && (rsize += 2) && (rrsize ++)); - - - /* This part may be deplaced upper to avoid a few mpfr_can_round_raw */ - /* when the square root is exact. It is however very unprobable that */ - /* it would improve the behaviour of the present code on average. */ - - if (!q_limb) /* possibly exact */ - { - /* if we have taken into account the whole of up */ - for (k = usize - rsize - 1; k >= 0; k ++) - if (up[k]) break; - - if (k < 0) { exact = 1; goto fin; } - } - - if (can_round) - { - cc = mpfr_round_raw(rp, rp, err, 0, PREC(r), rnd_mode); - rrsize = (PREC(r) - 1)/BITS_PER_MP_LIMB + 1; - } - else - /* Use the return value of sqrtrem to decide of the rounding */ - /* Note that at this point the sqrt has been computed */ - /* EXACTLY. If rounding = GMP_RNDZ, do nothing [comes from */ - /* the fact that the exact square root can end with a bunch of ones, */ - /* and in that case we indeed cannot round if we do not know that */ - /* the computation was exact. */ - switch (rnd_mode) - { - case GMP_RNDZ : - case GMP_RNDD : break; - - case GMP_RNDN : - /* Not in the situation ...0 111111 */ - rw = (PREC(r) + 1) & (BITS_PER_MP_LIMB - 1); - if (rw) { rw = BITS_PER_MP_LIMB - rw; nw = 0; } else nw = 1; - if ((rp[nw] >> rw) & 1 && /* Not 0111111111 */ - (q_limb || /* Nonzero remainder */ - (rw ? (rp[nw] >> (rw + 1)) & 1 : - (rp[nw] >> (BITS_PER_MP_LIMB - 1)) & 1))) /* or even rounding */ - cc = mpn_add_1(rp + nw, rp + nw, rrsize, ((mp_limb_t)1) << rw); - break; - - case GMP_RNDU : - if (q_limb) - cc = mpn_add_1(rp, rp, rrsize, 1 << (BITS_PER_MP_LIMB - - (PREC(r) & - (BITS_PER_MP_LIMB - 1)))); - } - - if (cc) { - mpn_rshift(rp, rp, rrsize, 1); - rp[rrsize-1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - r->_mp_exp++; - } - - fin: - rsize = rrsize; - rrsize = (PREC(r) - 1)/BITS_PER_MP_LIMB + 1; - MPN_COPY(r->_mp_d, rp + rsize - rrsize, rrsize); - - if (PREC(r) & (BITS_PER_MP_LIMB - 1)) - MANT(r) [0] &= ~(((mp_limb_t)1 << (BITS_PER_MP_LIMB - - (PREC(r) & (BITS_PER_MP_LIMB - 1)))) - 1) ; - - TMP_FREE(marker0); TMP_FREE (marker); - return exact; -} diff --git a/gmp/mpfr/sub.c b/gmp/mpfr/sub.c deleted file mode 100755 index dfe755b..0000000 --- a/gmp/mpfr/sub.c +++ /dev/null @@ -1,483 +0,0 @@ -/* mpfr_sub -- subtract two floating-point numbers - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" - -/* #define DEBUG */ - -extern void mpfr_add1 _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - unsigned char, int)); - -/* put in ap[0]..ap[an-1] the value of bp[0]..bp[n-1] shifted by sh bits - to the left minus ap[0]..ap[n-1], with 0 <= sh < mp_bits_per_limb, and - returns the borrow. -*/ -mp_limb_t -#if __STDC__ -mpn_sub_lshift_n (mp_limb_t *ap, mp_limb_t *bp, int n, int sh, int an) -#else -mpn_sub_lshift_n (ap, bp, n, sh, an) mp_limb_t *ap, *bp; int n,sh,an; -#endif -{ - mp_limb_t c, bh; - - /* shift b to the left */ - if (sh) bh = mpn_lshift(bp, bp, n, sh); - c = (n=abs(c), diff_exp>=0 */ -void -#if __STDC__ -mpfr_sub1(mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, unsigned char rnd_mode, int diff_exp) -#else -mpfr_sub1(a, b, c, rnd_mode, diff_exp) - mpfr_ptr a; - mpfr_srcptr b; - mpfr_srcptr c; - unsigned char rnd_mode; - int diff_exp; -#endif -{ - mp_limb_t *ap, *bp, *cp, cc, c2; unsigned int an,bn,cn; - int sh,dif,k,cancel,cancel1,cancel2; - TMP_DECL(marker); - -#ifdef DEBUG - printf("b= "); if (SIGN(b)>=0) putchar(' '); - mpfr_print_raw(b); putchar('\n'); - printf("c= "); if (SIGN(c)>=0) putchar(' '); - for (k=0;k=prec(a), i.e. c only affects the last bit - through rounding */ - dif = PREC(a)-diff_exp; -#ifdef DEBUG - printf("PREC(a)=%d an=%u PREC(b)=%d bn=%u PREC(c)=%d diff_exp=%u dif=%d cancel=%d\n", - PREC(a),an,PREC(b),bn,PREC(c),diff_exp,dif,cancel); -#endif - if (dif<=0) { /* diff_exp>=PREC(a): c does not overlap with a */ - /* either PREC(b)<=PREC(a), and we can copy the mantissa of b directly - into that of a, or PREC(b)>PREC(a) and we have to round b-c */ - if (PREC(b)<=PREC(a)+cancel) { - if (cancel2) mpn_lshift(ap+(an-bn+cancel1), bp, bn-cancel1, cancel2); - else MPN_COPY(ap+(an-bn+cancel1), bp, bn-cancel1); - /* fill low significant limbs with zero */ - MPN_ZERO(ap, an-bn+cancel1); - /* now take c into account */ - if (rnd_mode==GMP_RNDN) { /* to nearest */ - /* if diff_exp > PREC(a), no change */ - if (diff_exp==PREC(a)) { - /* if c is not zero, then as it is normalized, we have to subtract - one to the lsb of a if c>1/2, or c=1/2 and lsb(a)=1 (round to - even) */ - if (NOTZERO(c)) { /* c is not zero */ - /* check whether mant(c)=1/2 or not */ - cc = *cp - ((mp_limb_t)1<<(mp_bits_per_limb-1)); - if (cc==0) { - bp = cp+(PREC(c)-1)/mp_bits_per_limb; - while (cp 1/2 or mant(c) = 1/2: subtract 1 iff lsb(a)=1 */ - } - } - else if (ap[an-1]==0) { /* case b=2^n */ - ap[an-1] = (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - EXP(a)++; - } - } - else if ((ISNONNEG(b) && rnd_mode==GMP_RNDU) || - (ISNEG(b) && rnd_mode==GMP_RNDD)) { - /* round up: nothing to do */ - if (ap[an-1]==0) { /* case b=2^n */ - ap[an-1] = (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - EXP(a)++; - } - } - else { - /* round down: subtract 1 ulp iff c<>0 */ - if (NOTZERO(c)) goto sub_one_ulp; - } - } - else { /* PREC(b)>PREC(a) : we have to round b-c */ - k=bn-an; - /* first copy the 'an' most significant limbs of b to a */ - MPN_COPY(ap, bp+k, an); - if (rnd_mode==GMP_RNDN) { /* to nearest */ - /* first check whether the truncated bits from b are 1/2*lsb(a) */ - if (sh) { - cc = *ap & (((mp_limb_t)1<0) { /* suppose sizeof(long)=sizeof(mp_limb_t) */ - goto add_one_ulp; /* trunc(b)>1/2*lsb(a) -> round up */ - } - else if (cc==0) { - while (k>1 && cc==0) cc=bp[--k]; - /* now if the truncated part of b = 1/2*lsb(a), check whether c=0 */ - if (NOTZERO(c) || (*ap & ((mp_limb_t)1< round down, i.e. do nothing */ - } - else { /* round towards infinity or zero */ - if (sh) { - cc = *ap & (((mp_limb_t)1<-sh) ? cp[cn]>>(mp_bits_per_limb-dif-sh) : 0; - while (cc==c2 && (k || cn)) { - if (k) cc = bp[--k]; - if (cn) { - c2 = cp[cn]<<(dif+sh); - if (--cn) c2 += cp[cn]>>(mp_bits_per_limb-dif-sh); - } - } - dif = ((ISNONNEG(b) && rnd_mode==GMP_RNDU) || - (ISNEG(b) && rnd_mode==GMP_RNDD)); - /* round towards infinity if dif=1, towards zero otherwise */ - if (dif && cc>c2) goto add_one_ulp; - else if (dif==0 && cc0) { - mpn_rshift(ap, cp+(cn-k), (k<=an) ? k : an, dif); - if (k>an) ap[an-1] += cp[cn-k+an]<<(mp_bits_per_limb-dif); - } - else if (dif<0) { - cc = mpn_lshift(ap, cp+(cn-k), k, -dif); - if (k= k+1) - ap[0] += cp[cn-k-1]>>(mp_bits_per_limb+dif); - } - else MPN_COPY(ap, cp+(cn-k), k); - overlap=1; - } - else { /* c is not truncated, but we have to fill low limbs with 0 */ - MPN_ZERO(ap, k-cn); - overlap = cancel-diff_exp; -#ifdef DEBUG - printf("0:a="); mpfr_print_raw(a); putchar('\n'); - printf("overlap=%d\n",overlap); -#endif - if (overlap>=0) { - cn -= overlap/mp_bits_per_limb; - overlap %= mp_bits_per_limb; - /* warning: a shift of zero with mpn_lshift is not allowed */ - if (overlap) { - if (an>(mp_bits_per_limb-overlap); - } - else mpn_lshift(ap+(an-cn), cp, cn, overlap); - } - else MPN_COPY(ap+(an-cn), cp, cn); - } - else { /* shift to the right by -overlap bits */ - overlap = -overlap; - k = overlap/mp_bits_per_limb; - overlap = overlap % mp_bits_per_limb; - if (overlap) cc = mpn_rshift(ap+(an-k-cn), cp, cn, overlap); - else { - MPN_COPY(ap+(an-k-cn), cp, cn); - cc = 0; - } - if (an>k+cn) ap[an-k-cn-1]=cc; - } - overlap=0; - } -#ifdef DEBUG - printf("1:a="); mpfr_print_raw(a); putchar('\n'); -#endif - /* here overlap=1 iff ulp(c) PREC(a): we have to truncate b */ - mpn_sub_lshift_n(ap, bp+(bn-an-cancel1), an, cancel2, an); - /* remains to do the rounding */ -#ifdef DEBUG - printf("2:a="); mpfr_print_raw(a); putchar('\n'); - printf("overlap=%d\n",overlap); -#endif - if (rnd_mode==GMP_RNDN) { /* to nearest */ - int kc; - /* four cases: overlap = - (0) PREC(b) > PREC(a) and diff_exp+PREC(c) <= PREC(a) - (1) PREC(b) > PREC(a) and diff_exp+PREC(c) > PREC(a) - (2) PREC(b) <= PREC(a) and diff_exp+PREC(c) <= PREC(a) - (3) PREC(b) <= PREC(a) and diff_exp+PREC(c) > PREC(a) */ - switch (overlap) - { - case 1: /* both b and c to round */ - kc = cn-k; /* remains kc limbs from c */ - k = bn-an; /* remains k limbs from b */ - /* truncate last bits and store the difference with 1/2*ulp in cc */ - cc = *ap & (((mp_limb_t)1<>dif) + - (cp[kc+1]<<(mp_bits_per_limb-dif))); - if (cc==0 || cc==-1) cc=c2; - } - if ((long)cc>0) goto add_one_ulp; - else if ((long)cc<-1) goto end_of_sub; /* the carry can be at most 1 */ - else if (kc==0) goto round_b; - /* else round c: go through */ - case 3: /* only c to round */ - bp=cp; k=cn-k; goto to_nearest; - case 0: /* only b to round */ - round_b: - k=bn-an; dif=0; goto to_nearest; - /* otherwise the result is exact: nothing to do */ - } - } - else if ((ISNONNEG(b) && rnd_mode==GMP_RNDU) || - (ISNEG(b) && rnd_mode==GMP_RNDD)) { - cc = *ap & (((mp_limb_t)1<>dif); - if (dif) cc -= (cp[kc+1]<<(mp_bits_per_limb-dif)); - } - if (cc) goto add_one_ulp; - else if (kc==0) goto round_b2; - /* else round c: go through */ - case 3: /* only c to round: nothing to do */ - /* while (kc) if (cp[--kc]) goto add_one_ulp; */ - /* if dif>0 : remains to check last dif bits from c */ - /* if (dif>0 && (cp[0]<<(mp_bits_per_limb-dif))) goto add_one_ulp; */ - break; - case 0: /* only b to round */ - round_b2: - k=bn-an; - while (k) if (bp[--k]) goto add_one_ulp; - /* otherwise the result is exact: nothing to do */ - } - } - } - /* else round to zero: remove 1 ulp if neglected bits from b-c are < 0 */ - else { - cc = *ap & (((mp_limb_t)1< no borrow */ - case 1: /* both b and c are truncated */ - break; - case 3: /* only c is truncated */ - cn -= k; /* take into account cp[0]..cp[cn-1] shifted by dif bits - to the right */ - cc = (dif>0) ? cp[cn]<<(mp_bits_per_limb-dif) : 0; - while (cc==0 && cn>0) cc = cp[--cn]; - if (cc) goto sub_one_ulp; - break; - } - } - } - } - goto end_of_sub; - - to_nearest: /* 0 <= sh < mp_bits_per_limb : number of bits of a to truncate - bp[k] : last significant limb from b */ -#ifdef DEBUG -mpfr_print_raw(a); putchar('\n'); -#endif - if (sh) { - cc = *ap & (((mp_limb_t)1<c2) goto add_one_ulp; /* trunc(b)>1/2*lsb(a) -> round up */ - else if (cc==c2) { - cc=0; while (k && cc==0) cc=bp[--k]; -#ifdef DEBUG - printf("cc=%lu\n",cc); -#endif - /* special case of rouding c shifted to the right */ - if (cc==0 && dif>0) cc=bp[0]<<(mp_bits_per_limb-dif); - /* now if the truncated part of b = 1/2*lsb(a), check whether c=0 */ - if (bp!=cp) { - if (cc || (*ap & ((mp_limb_t)1<0, do nothing */ - if (cc==0 && (*ap & ((mp_limb_t)1< -#include -#include -#include "gmp.h" -#include "longlong.h" -#include "mpfr.h" -#include "mpfr-impl.h" - -int -main() -{ - double x,y; mpfr_t xx,yy; int i,c; - - fprintf(stderr, "Test case 'tcmp' disabled\n"); - exit(0); /* THIS TEST CASE IS NOT WORKING */ - - mpfr_init2(xx, 65); mpfr_init2(yy, 65); - mpfr_set_str_raw(xx, "0.10011010101000110101010000000011001001001110001011101011111011101E623"); - mpfr_set_str_raw(yy, "0.10011010101000110101010000000011001001001110001011101011111011100E623"); - if (mpfr_cmp2(xx,yy)!=64) { printf("Error (1) in mpfr_cmp\n"); exit(1); } - mpfr_set_str_raw(xx, "0.10100010001110110111000010001000010011111101000100011101000011100"); - mpfr_set_str_raw(yy, "0.10100010001110110111000010001000010011111101000100011101000011011"); - if (mpfr_cmp2(xx,yy)!=64) { printf("Error (1) in mpfr_cmp\n"); exit(1); } - mpfr_set_prec(xx,53); mpfr_set_prec(yy,200); - mpfr_set_d(xx, 1.0, 0); - mpfr_set_d(yy, 1.0, 0); - if (mpfr_cmp(xx,yy)!=0) { - printf("Error in mpfr_cmp: 1.0 != 1.0\n"); exit(1); - } - mpfr_set_prec(yy, 31); - mpfr_set_d(xx, 1.0000000002, 0); - mpfr_set_d(yy, 1.0, 0); - if (!(mpfr_cmp(xx,yy)>0)) { - printf("Error in mpfr_cmp: not 1.0000000002 > 1.0\n"); exit(1); - } - mpfr_set_prec(yy, 53); - for (i=0;i<1000000;) { - x=drand(); y=drand(); - if (!isnan(x) && !isnan(y)) { - i++; - mpfr_set_d(xx, x, 0); - mpfr_set_d(yy, y, 0); - c = mpfr_cmp(xx,yy); - if ((c>0 && x<=y) || (c==0 && x!=y) || (c<0 && x>=y)) { - printf("Error in mpfr_cmp with x=%1.20e, y=%1.20e mpfr_cmp(x,y)=%d\n", - x,y,c); exit(1); - } - } - } - mpfr_clear(xx); mpfr_clear(yy); - exit (0); -} diff --git a/gmp/mpfr/tests/tcmp2.c b/gmp/mpfr/tests/tcmp2.c deleted file mode 100755 index f7e3f35..0000000 --- a/gmp/mpfr/tests/tcmp2.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Test file for mpfr_cmp2. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include -#include "gmp.h" -#include "longlong.h" -#include "mpfr.h" -#include "mpfr-impl.h" -#ifdef IRIX64 -#include -#endif - -extern int isnan(); - -void tcmp2(x, y, i) double x, y; int i; -{ - mpfr_t xx,yy; int j; - - if (i==-1) { - if (x==y) i=53; - else i = (int) floor(log(x)/log(2.0)) - (int) floor(log(x-y)/log(2.0)); - } - mpfr_init2(xx, 53); mpfr_init2(yy, 53); - mpfr_set_d(xx, x, 0); - mpfr_set_d(yy, y, 0); - if ((j=mpfr_cmp2(xx, yy)) != i) { - printf("Error in mpfr_cmp2: x=%1.20e y=%1.20e mpfr_cmp2(x,y)=%d instead of %d\n",x,y,j,i); - exit(1); - } - mpfr_set_prec(xx, 127); mpfr_set_prec(yy, 127); - mpfr_set_str_raw(xx, "0.1011010000110111111000000101011110110001000101101011011110010010011110010000101101000010011001100110010000000010110000101000101E6"); - mpfr_set_str_raw(yy, "0.1011010000110111111000000101011011111100011101000011001111000010100010100110110100110010011001100110010000110010010110000010110E6"); - if ((j=mpfr_cmp2(xx, yy)) != 32) { - printf("Error in mpfr_cmp2:\n"); - printf("x="); mpfr_print_raw(xx); putchar('\n'); - printf("y="); mpfr_print_raw(yy); putchar('\n'); - printf("got %d, expected 32\n", j); - exit(1); - } - mpfr_clear(xx); mpfr_clear(yy); -} - -int main() -{ - int i,j; double x=1.0, y, z; -#ifdef IRIX64 - /* to get denormalized numbers on IRIX64 */ - union fpc_csr exp; - exp.fc_word = get_fpc_csr(); - exp.fc_struct.flush = 0; - set_fpc_csr(exp.fc_word); -#endif - - tcmp2(1.06022698059744327881e+71, 1.05824655795525779205e+71, -1); - tcmp2(1.0, 1.0, 53); - for (i=0;i<54;i++) { - tcmp2(1.0, 1.0-x, i); - x /= 2.0; - } - for (j=0;j<1000000;j++) { - x = drand48(); - y = drand48(); - if (x -#include -#include -#include "gmp.h" -#include "longlong.h" -#include "mpfr.h" - -int -main() -{ - mpfr_t x; unsigned long i; long s; - - mpfr_init(x); - - mpfr_set_ui(x, 3, GMP_RNDZ); - if (mpfr_cmp_ui(x, i=3)!=0) { - printf("Error in mpfr_cmp_ui(%1.20f,%d)\n",mpfr_get_d(x), i); exit(1); - } - if (mpfr_cmp_ui(x, i=2)<=0) { - printf("Error in mpfr_cmp_ui(%1.20f,%d)\n",mpfr_get_d(x), i); exit(1); - } - if (mpfr_cmp_ui(x, i=4)>=0) { - printf("Error in mpfr_cmp_ui(%1.20f,%d)\n",mpfr_get_d(x), i); exit(1); - } - - mpfr_set_si(x, -3, GMP_RNDZ); - if (mpfr_cmp_si(x, s=-3)!=0) { - printf("Error in mpfr_cmp_si(%1.20f,%d)\n",mpfr_get_d(x), s); exit(1); - } - if (mpfr_cmp_si(x, s=-4)<=0) { - printf("Error in mpfr_cmp_si(%1.20f,%d)\n",mpfr_get_d(x), s); exit(1); - } - if (mpfr_cmp_si(x, s=1)>=0) { - printf("Error in mpfr_cmp_si(%1.20f,%d)\n",mpfr_get_d(x), s); exit(1); - } - exit (0); -} diff --git a/gmp/mpfr/tests/tlog2.c b/gmp/mpfr/tests/tlog2.c deleted file mode 100755 index 0ba296a..0000000 --- a/gmp/mpfr/tests/tlog2.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Test file for mpfr_log2. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "mpfr.h" - -/* tlog2 [prec] [rnd] [0 = no print] */ - -int main(argc, argv) int argc; char *argv[]; -{ - mpfr_t x; int p; unsigned char rnd; - - p = (argc>1) ? atoi(argv[1]) : 53; - rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ; - mpfr_init2(x, p); - mpfr_log2(x, rnd); - if (argc>=2) { - printf("log(2)="); mpfr_out_str(stdout, 10, 0, x, rnd); putchar('\n'); - } - else if (mpfr_get_d(x) != 6.9314718055994530941e-1) { - fprintf(stderr, "mpfr_log2 failed for prec=53\n"); exit(1); - } - mpfr_clear(x); - exit (0); -} diff --git a/gmp/mpfr/tests/tmul_2exp.c b/gmp/mpfr/tests/tmul_2exp.c deleted file mode 100755 index c470313..0000000 --- a/gmp/mpfr/tests/tmul_2exp.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Test file for mpfr_mul_2exp. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include -#include "gmp.h" -#include "mpfr.h" - -/* checks that x*y gives the same results in double - and with mpfr with 53 bits of precision */ - -int -main(argc,argv) int argc; char *argv[]; -{ - double x, z; mpfr_t w; - - mpfr_init2(w, 53); - - srand48(time(NULL)); - x = drand48(); - mpfr_set_d(w, x, 0); - mpfr_mul_2exp(w, w, 10, GMP_RNDZ); - if (x != (z = mpfr_get_d(w)/1024)) - { - fprintf(stderr, "%f != %f\n", x, z); - exit (1); - } - exit (0); -} - diff --git a/gmp/mpfr/tests/tmul_ui.c b/gmp/mpfr/tests/tmul_ui.c deleted file mode 100755 index fab7d50..0000000 --- a/gmp/mpfr/tests/tmul_ui.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Test file for mpfr_mul_ui. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "mpfr.h" -#include "time.h" - -int -main(int argc, char **argv) -{ - mpfr_t x, y; - - mpfr_init2(x, 53); mpfr_init2(y, 53); - - /* checks that result is normalized */ - mpfr_set_d(y, 6.93147180559945286227e-01, GMP_RNDZ); - mpfr_mul_ui(x, y, 1, GMP_RNDZ); - if (MANT(x)[PREC(x)/BITS_PER_MP_LIMB] >> (BITS_PER_MP_LIMB-1) == 0) { - fprintf(stderr, "Error in mpfr_mul_ui: result not normalized\n"); - exit(1); - } - if (mpfr_cmp(x,y)) { - fprintf(stderr, "Error in mpfr_mul_ui: 1*y != y\n"); - printf("y= "); mpfr_print_raw(y); putchar('\n'); - printf("1*y="); mpfr_print_raw(x); putchar('\n'); - exit(1); - } - - mpfr_set_d(x, 1.0/3.0, GMP_RNDZ); - mpfr_mul_ui(x, x, 3, GMP_RNDU); - if (mpfr_get_d(x) != 1.0) { - fprintf(stderr, "Error in mpfr_mul_ui: U(Z(1/3)*3) does not give 1\n"); exit(1); - } - - /* checks sign is correct */ - mpfr_set_d(x, -2.0, GMP_RNDZ); - mpfr_set_d(y, 3.0, GMP_RNDZ); - mpfr_mul_ui(x, y, 4, GMP_RNDZ); - if (SIGN(x) != 1) { - fprintf(stderr, "Error in mpfr_mul_ui: 4*3.0 does not give a positive result\n"); exit(1); - } - - mpfr_clear(x); mpfr_clear(y); - exit (0); -} diff --git a/gmp/mpfr/tests/tpi.c b/gmp/mpfr/tests/tpi.c deleted file mode 100755 index 487983c..0000000 --- a/gmp/mpfr/tests/tpi.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Test file for mpfr_pi. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "mpfr.h" - -/* tpi [prec] [rnd] [0 = no print] */ - -int main(argc, argv) int argc; char *argv[]; -{ - mpfr_t x; int p; unsigned char rnd; - - p = (argc>1) ? atoi(argv[1]) : 53; - rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ; - mpfr_init2(x, p); - mpfr_pi(x, rnd); - if (argc>=2) { - printf("Pi="); mpfr_out_str(stdout, 10, 0, x, rnd); putchar('\n'); - } - else if (mpfr_get_d(x) != 3.141592653589793116) { - fprintf(stderr, "mpfr_pi failed for prec=53\n"); exit(1); - } - mpfr_clear(x); - exit (0); -} diff --git a/gmp/mpfr/tests/tround.c b/gmp/mpfr/tests/tround.c deleted file mode 100755 index 3ccd6ff..0000000 --- a/gmp/mpfr/tests/tround.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Test file for mpfr_round. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "mpfr.h" - -int -main() -{ - mpfr_t x; - - /* checks that rounds to nearest sets the last - bit to zero in case of equal distance */ - mpfr_init2(x, 2); - mpfr_set_d(x, 5.0, 0); - if (mpfr_get_d(x) != 4.0) { printf("Error in tround: got %1.1f instead of 4.0\n",mpfr_get_d(x)); } - - mpfr_set_d(x, 0.00098539467465030839, 0); - - mpfr_set_d(x, 9.84891017624509146344e-01, GMP_RNDU); - if (mpfr_get_d(x) != 1.0) { printf("Error in tround: got %f instead of 1.0\n",mpfr_get_d(x)); exit(1); } - - mpfr_clear(x); - exit (0); -} diff --git a/gmp/mpfr/tests/tset_d.c b/gmp/mpfr/tests/tset_d.c deleted file mode 100755 index c542dc1..0000000 --- a/gmp/mpfr/tests/tset_d.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Test file for mpfr_set_d and mpfr_get_d. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include -#ifdef IRIX64 -#include -#endif -#include "gmp.h" -#include "mpfr.h" -#include "mpfr-impl.h" - -extern int isnan(); - -int -main(int argc, char **argv) -{ - fprintf(stderr, "Test case tset_d disabled\n"); - exit(0); /* THIS TEST CASE IS NOT WORKING */ - -#if 0 - mpfr_t x,y,z; unsigned long k,n; double d, dd; -#ifdef IRIX64 - /* to get denormalized numbers on IRIX64 */ - union fpc_csr exp; - exp.fc_word = get_fpc_csr(); - exp.fc_struct.flush = 0; - set_fpc_csr(exp.fc_word); -#endif - - mpfr_init2(z, 32); - mpfr_set_d(z, 1.0, 0); - if (mpfr_get_d(z) != 1.0) { - mpfr_print_raw(z); putchar('\n'); - printf("Error: 1.0 != 1.0\n"); exit(1); - } - mpfr_init2(x, 53); mpfr_init2(y, 53); - mpfr_set_d(x, d=-1.08007920352320089721e+150, 0); - if (mpfr_get_d(x) != d) { - mpfr_print_raw(x); putchar('\n'); - printf("Error: get_d o set_d <> identity for d = %1.20e %1.20e\n",d, - mpfr_get_d(x)); exit(1); - } - srand48(time(NULL)); - mpfr_set_d(x, 8.06294740693074521573e-310, 0); - d = -6.72658901114033715233e-165; - mpfr_set_d(x, d, 0); - if (d != mpfr_get_d(x)) { - mpfr_print_raw(x); putchar('\n'); - printf("Error: get_d o set_d <> identity for d = %1.20e %1.20e\n",d, - mpfr_get_d(x)); exit(1); - } - n = (argc==1) ? 1000000 : atoi(argv[1]); - for (k = 1; k <= n; k++) - { - d = drand(); - mpfr_set_d(x, d, 0); - dd = mpfr_get_d(x); - if (d != dd && (!isnan(d) || !isnan(dd))) - { - fprintf(stderr, - "Mismatch on : %1.18g != %1.18g\n", d, mpfr_get_d(x)); - mpfr_print_raw(x); putchar('\n'); - } - } - - mpfr_clear(x); mpfr_clear(y); mpfr_clear(z); - exit (0); -#endif /* 0 */ -} - diff --git a/gmp/mpfr/tests/tset_si.c b/gmp/mpfr/tests/tset_si.c deleted file mode 100755 index db4e73a..0000000 --- a/gmp/mpfr/tests/tset_si.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Test file for mpfr_set_si and mpfr_set_ui. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "mpfr.h" -#include "time.h" - -int -main(int argc, char **argv) -{ - mpfr_t x; long k, z, d; unsigned long zl, dl, N; - - mpfr_init2(x, 100); - - srandom(time(NULL)); - - N = (argc==1) ? 1000000 : atoi(argv[1]); - - for (k = 1; k <= N; k++) - { - z = random() - (1 << 30); - mpfr_set_si(x, z, GMP_RNDZ); - d = (int)mpfr_get_d(x); - if (d != z) - { - fprintf(stderr, "Expected %ld got %ld\n", z, d); - exit(1); - } - } - - for (k = 1; k <= N; k++) - { - zl = random(); - mpfr_set_ui(x, zl, GMP_RNDZ); - dl = (unsigned int) mpfr_get_d(x); - if (dl != zl) - { - fprintf(stderr, "Expected %lu got %lu\n", zl, dl); - exit(1); - } - } - - mpfr_clear(x); - exit (0); -} diff --git a/gmp/mpfr/tests/tset_str.c b/gmp/mpfr/tests/tset_str.c deleted file mode 100755 index a1cd300..0000000 --- a/gmp/mpfr/tests/tset_str.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Test file for mpfr_set_str. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "mpfr.h" -#include - -#if defined (hpux) -#define srandom srand48 -#define random mrand48 -#endif - -int -main(int argc, char **argv) -{ - mpfr_t x; unsigned long k, bd, nc; char *str, *str2; - - if (argc==2) { /* tset_str */ - mpfr_init2(x, 53); - mpfr_set_str_raw(x, argv[1]); - printf("%1.20e\n", mpfr_get_d(x)); - mpfr_clear(x); - exit (0); - } - - srandom(time(NULL)); - - if (argc > 1) { nc = atoi(argv[1]); } else { nc = 53; } - if (nc < 24) { nc = 24; } - - bd = random()&8; - - str2 = str = (char *) malloc (nc*sizeof(char)); - - if (bd) - { - for(k = 1; k <= bd; k++) - { *(str2++) = (random() & 1) + '0'; } - } - else { *(str2++) = '0'; } - - *(str2++) = '.'; - - for(k = 1; k < nc - 17 - bd; k++) - { - *(str2++) = '0' + (random() & 1); - } - - *(str2++) = 'e'; - sprintf(str2, "%d", random() - (1 << 30)); - - /* printf("%s\n", str); */ - mpfr_init2(x, nc + 10); - mpfr_set_str_raw(x, str); - /* mpfr_print_raw(x); printf("\n"); */ - - mpfr_set_prec(x, 53); - mpfr_set_str_raw(x, "+110101100.01010000101101000000100111001000101011101110E00"); - - mpfr_set_str_raw(x, "1.0"); - if (mpfr_get_d(x) != 1.0) { - fprintf(stderr, "Error in mpfr_set_str_raw for s=1.0\n"); exit(1); - } - - mpfr_clear(x); free(str); - exit (0); -} diff --git a/gmp/mpfr/tests/tset_z.c b/gmp/mpfr/tests/tset_z.c deleted file mode 100755 index 61fe654..0000000 --- a/gmp/mpfr/tests/tset_z.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Test file for mpfr_set_z. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "mpfr.h" - -/* tset_z z rnd prec */ - -void check(long i, unsigned char rnd) { - mpfr_t f; mpz_t z; - - mpfr_init2(f, 53); mpz_init(z); - mpz_set_ui(z, i); - mpfr_set_z(f, z, rnd); - if ((long)mpfr_get_d(f) != i) { - printf("Error in mpfr_set_z for i=%ld rnd_mode=%d\n",i,rnd); - exit(1); - } - mpfr_clear(f); mpz_clear(z); -} - -void check_large() -{ - mpz_t z; mpfr_t x,y; - - mpz_init(z); mpfr_init2(x, 160); mpfr_init2(y, 160); - mpz_set_str(z, "77031627725494291259359895954016675357279104942148788042", 10); - mpfr_set_z(x, z, GMP_RNDN); - mpfr_set_str_raw(y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186"); - if (mpfr_cmp(x,y)) { - fprintf(stderr, "Error in mpfr_set_z on large input\n"); exit(1); - } - mpz_clear(z); mpfr_clear(x); mpfr_clear(y); -} - -int main(argc,argv) int argc; char *argv[]; -{ - long j; - - check_large(); - srand(getpid()); - for (j=0; j<1000000; j++) - check(lrand48(), rand()%4); - exit (0); -} - diff --git a/gmp/mpfr/tests/tzeta.c b/gmp/mpfr/tests/tzeta.c deleted file mode 100755 index d9495e5..0000000 --- a/gmp/mpfr/tests/tzeta.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Test file for mpfr_zeta. - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -/* #define DEBUG */ - -int main() -{mpfr_t p,result,res_p; int succes; size_t t; -mpfr_init2(result, 53); -mpfr_init2(res_p, 53); -mpfr_init2(p, 53); mpfr_set_d(p, 2.0, GMP_RNDN); - -mpfr_zeta(result,p,GMP_RNDN); -/*printf("%d\n",succes);*/ -#ifdef DEBUG -printf("Valeur de zeta(2) avec prec=53 et arrondi au plus pres:\n"); -mpfr_print_raw(result);printf("\n"); -t=mpfr_out_str(stdout,10,0,result,GMP_RNDN);printf("\n"); -#endif - if (mpfr_get_d(result) != 1.64493406684822640607e+00) { - fprintf(stderr, "mpfr_zeta fails for s=2 and rnd_mode=GMP_RNDN\n"); - exit(1); - } - -/*Test de comparaison avec pi^2/6*/ -mpfr_set_prec(p, 67); -mpfr_pi(p,GMP_RNDN); -mpfr_mul(p,p,p,GMP_RNDN); -mpfr_set_ui(res_p,6,GMP_RNDN); -mpfr_div(p,p,res_p,GMP_RNDN); -/*mpfr_print_raw(p);printf("\n"); -t=mpfr_out_str(stdout,10,0,p,GMP_RNDN);printf("\n");*/ -succes=mpfr_can_round(p,63,GMP_RNDN,GMP_RNDN,53); -mpfr_set(res_p,p,GMP_RNDN); -/*printf("%d\n",succes);*/ -#ifdef DEBUG -printf("Valeur de pi^2/6 avec prec=53 et arrondi au plus pres:\n"); -mpfr_print_raw(res_p);printf("\n"); -t=mpfr_out_str(stdout,10,0,res_p,GMP_RNDN);printf("\n"); -#endif - -mpfr_clear(p); -mpfr_clear(result); -mpfr_clear(res_p); -exit (0); -} diff --git a/gmp/mpfr/zeta.c b/gmp/mpfr/zeta.c deleted file mode 100755 index 5250a9d..0000000 --- a/gmp/mpfr/zeta.c +++ /dev/null @@ -1,116 +0,0 @@ -/* mpfr_zeta -- Riemann Zeta function at a floating-point number - -Copyright (C) 1999 PolKA project, Inria Lorraine and Loria - -This file is part of the MPFR Library. - -The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your -option) any later version. - -The MPFR Library 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 Library General Public -License for more details. - -You should have received a copy of the GNU Library General Public License -along with the MPFR Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "mpfr.h" - -int -#if __STDC__ -mpfr_zeta(mpfr_ptr result, mpfr_srcptr op, unsigned char rnd_mode) -#else -mpfr_zeta(result, op, rnd_mode) - mpfr_ptr result; - mpfr_srcptr op; - unsigned char rnd_mode; -#endif -{ - mpfr_t s,s2,x,y,u,b,v,nn,z,z2; - int i,n,succes; - - /* first version */ - if (mpfr_get_d(op) != 2.0 || rnd_mode != GMP_RNDN - || PREC(result) != 53) { - fprintf(stderr, "not yet implemented\n"); exit(1); - } - -mpfr_set_default_prec(67); -mpfr_init(x); -mpfr_init(y); -mpfr_init(s); -mpfr_init(s2); -mpfr_init(u); -mpfr_init(b); -mpfr_init(v); -mpfr_init(nn); -mpfr_init(z); -mpfr_init(z2); -mpfr_set_ui(u,1,GMP_RNDN); -mpfr_set_ui(s,0,GMP_RNDN); -/*s=Somme des 1/i^2 (i=100...2)*/ -n=100; -for (i=n; i>1; i--) -{ -mpfr_set_ui(x,i*i,GMP_RNDN); -mpfr_div(y,u,x,GMP_RNDN); -mpfr_add(s,s,y,GMP_RNDN); -}; -/*mpfr_print_raw(s);printf("\n"); -t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/ -/*Application d'Euler-Maclaurin, jusqu'au terme 1/n^7 - n=100)*/ -mpfr_set_ui(nn,n,GMP_RNDN); -mpfr_div(z,u,nn,GMP_RNDN); -mpfr_set(s2,z,GMP_RNDN); -mpfr_mul(z2,z,z,GMP_RNDN); -mpfr_div_2exp(v,z2,1,GMP_RNDN); -mpfr_sub(s2,s2,v,GMP_RNDN); -mpfr_set_ui(b,6,GMP_RNDN); -mpfr_mul(z,z,z2,GMP_RNDN); -mpfr_div(v,z,b,GMP_RNDN); -mpfr_add(s2,s2,v,GMP_RNDN); -mpfr_set_si(b,-30,GMP_RNDN); -mpfr_mul(z,z,z2,GMP_RNDN); -mpfr_div(v,z,b,GMP_RNDN); -mpfr_add(s2,s2,v,GMP_RNDN); -mpfr_set_si(b,42,GMP_RNDN); -mpfr_mul(z,z,z2,GMP_RNDN); -mpfr_div(v,z,b,GMP_RNDN); -mpfr_add(s2,s2,v,GMP_RNDN); -/*mpfr_print_raw(s2);printf("\n"); -t=mpfr_out_str(stdout,10,0,s2,GMP_RNDN);printf("\n");*/ -mpfr_add(s,s,s2,GMP_RNDN); -/*mpfr_print_raw(s);printf("\n"); -t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/ -mpfr_add(s,s,u,GMP_RNDN); -/*mpfr_print_raw(s);printf("\n"); -t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/ -/*Peut-on arrondir ? La reponse est oui*/ -succes=mpfr_can_round(s,57,GMP_RNDN,GMP_RNDN,53); -if (succes) mpfr_set(result,s,GMP_RNDN); -else { - fprintf(stderr, "can't round in mpfr_zeta\n"); exit(1); -} - -mpfr_clear(x); -mpfr_clear(y); -mpfr_clear(s); -mpfr_clear(s2); -mpfr_clear(u); -mpfr_clear(b); -mpfr_clear(v); -mpfr_clear(nn); -mpfr_clear(z); -mpfr_clear(z2); -return 1; /* result is inexact */ -} diff --git a/gmp/mpn/Makefile.am b/gmp/mpn/Makefile.am deleted file mode 100755 index fc1cf2e..0000000 Binary files a/gmp/mpn/Makefile.am and /dev/null differ diff --git a/gmp/mpn/Makefile.in b/gmp/mpn/Makefile.in deleted file mode 100755 index 3d7e478..0000000 Binary files a/gmp/mpn/Makefile.in and /dev/null differ diff --git a/gmp/mpn/README b/gmp/mpn/README deleted file mode 100755 index a54090e..0000000 Binary files a/gmp/mpn/README and /dev/null differ diff --git a/gmp/mpn/a29k/add_n.s b/gmp/mpn/a29k/add_n.s deleted file mode 100755 index 8843c01..0000000 Binary files a/gmp/mpn/a29k/add_n.s and /dev/null differ diff --git a/gmp/mpn/a29k/addmul_1.s b/gmp/mpn/a29k/addmul_1.s deleted file mode 100755 index d1a147c..0000000 Binary files a/gmp/mpn/a29k/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/a29k/lshift.s b/gmp/mpn/a29k/lshift.s deleted file mode 100755 index 3b14fe0..0000000 Binary files a/gmp/mpn/a29k/lshift.s and /dev/null differ diff --git a/gmp/mpn/a29k/mul_1.s b/gmp/mpn/a29k/mul_1.s deleted file mode 100755 index 865bb9f..0000000 Binary files a/gmp/mpn/a29k/mul_1.s and /dev/null differ diff --git a/gmp/mpn/a29k/rshift.s b/gmp/mpn/a29k/rshift.s deleted file mode 100755 index 5d09d69..0000000 Binary files a/gmp/mpn/a29k/rshift.s and /dev/null differ diff --git a/gmp/mpn/a29k/sub_n.s b/gmp/mpn/a29k/sub_n.s deleted file mode 100755 index bee0277..0000000 Binary files a/gmp/mpn/a29k/sub_n.s and /dev/null differ diff --git a/gmp/mpn/a29k/submul_1.s b/gmp/mpn/a29k/submul_1.s deleted file mode 100755 index 94c46e8..0000000 Binary files a/gmp/mpn/a29k/submul_1.s and /dev/null differ diff --git a/gmp/mpn/a29k/udiv.s b/gmp/mpn/a29k/udiv.s deleted file mode 100755 index f49e4b0..0000000 Binary files a/gmp/mpn/a29k/udiv.s and /dev/null differ diff --git a/gmp/mpn/a29k/umul.s b/gmp/mpn/a29k/umul.s deleted file mode 100755 index 7008f13..0000000 Binary files a/gmp/mpn/a29k/umul.s and /dev/null differ diff --git a/gmp/mpn/alpha/README b/gmp/mpn/alpha/README deleted file mode 100755 index c9780f6..0000000 Binary files a/gmp/mpn/alpha/README and /dev/null differ diff --git a/gmp/mpn/alpha/add_n.asm b/gmp/mpn/alpha/add_n.asm deleted file mode 100755 index a608bf5..0000000 Binary files a/gmp/mpn/alpha/add_n.asm and /dev/null differ diff --git a/gmp/mpn/alpha/addmul_1.asm b/gmp/mpn/alpha/addmul_1.asm deleted file mode 100755 index 066b4b8..0000000 Binary files a/gmp/mpn/alpha/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/alpha/cntlz.asm b/gmp/mpn/alpha/cntlz.asm deleted file mode 100755 index 5767151..0000000 Binary files a/gmp/mpn/alpha/cntlz.asm and /dev/null differ diff --git a/gmp/mpn/alpha/default.m4 b/gmp/mpn/alpha/default.m4 deleted file mode 100755 index 6889af9..0000000 Binary files a/gmp/mpn/alpha/default.m4 and /dev/null differ diff --git a/gmp/mpn/alpha/ev5/add_n.asm b/gmp/mpn/alpha/ev5/add_n.asm deleted file mode 100755 index 1393edc..0000000 Binary files a/gmp/mpn/alpha/ev5/add_n.asm and /dev/null differ diff --git a/gmp/mpn/alpha/ev5/lshift.asm b/gmp/mpn/alpha/ev5/lshift.asm deleted file mode 100755 index 77508cb..0000000 Binary files a/gmp/mpn/alpha/ev5/lshift.asm and /dev/null differ diff --git a/gmp/mpn/alpha/ev5/rshift.asm b/gmp/mpn/alpha/ev5/rshift.asm deleted file mode 100755 index a142f6b..0000000 Binary files a/gmp/mpn/alpha/ev5/rshift.asm and /dev/null differ diff --git a/gmp/mpn/alpha/ev5/sub_n.asm b/gmp/mpn/alpha/ev5/sub_n.asm deleted file mode 100755 index b037e66..0000000 Binary files a/gmp/mpn/alpha/ev5/sub_n.asm and /dev/null differ diff --git a/gmp/mpn/alpha/ev6/addmul_1.asm b/gmp/mpn/alpha/ev6/addmul_1.asm deleted file mode 100755 index dba2064..0000000 Binary files a/gmp/mpn/alpha/ev6/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/alpha/ev6/gmp-mparam.h b/gmp/mpn/alpha/ev6/gmp-mparam.h deleted file mode 100755 index 7ea2057..0000000 --- a/gmp/mpn/alpha/ev6/gmp-mparam.h +++ /dev/null @@ -1,62 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* Generated by tuneup.c, 2000-08-02. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 47 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 70 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 94 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 101 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 33 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 70 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 29 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 46 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 33 -#endif diff --git a/gmp/mpn/alpha/gmp-mparam.h b/gmp/mpn/alpha/gmp-mparam.h deleted file mode 100755 index 054ff2f..0000000 --- a/gmp/mpn/alpha/gmp-mparam.h +++ /dev/null @@ -1,64 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values are for the 21164 family. The 21264 will require - different values, since it has such quick multiplication. */ -/* Generated by tuneup.c, 2000-07-19. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 22 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 53 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 31 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 47 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 64 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 98 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 17 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 4 -#endif diff --git a/gmp/mpn/alpha/invert_limb.asm b/gmp/mpn/alpha/invert_limb.asm deleted file mode 100755 index a0df32d..0000000 Binary files a/gmp/mpn/alpha/invert_limb.asm and /dev/null differ diff --git a/gmp/mpn/alpha/lshift.asm b/gmp/mpn/alpha/lshift.asm deleted file mode 100755 index c5f9894..0000000 Binary files a/gmp/mpn/alpha/lshift.asm and /dev/null differ diff --git a/gmp/mpn/alpha/mul_1.asm b/gmp/mpn/alpha/mul_1.asm deleted file mode 100755 index 17b0b74..0000000 Binary files a/gmp/mpn/alpha/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/alpha/rshift.asm b/gmp/mpn/alpha/rshift.asm deleted file mode 100755 index de38e2c..0000000 Binary files a/gmp/mpn/alpha/rshift.asm and /dev/null differ diff --git a/gmp/mpn/alpha/sub_n.asm b/gmp/mpn/alpha/sub_n.asm deleted file mode 100755 index 88c5e72..0000000 Binary files a/gmp/mpn/alpha/sub_n.asm and /dev/null differ diff --git a/gmp/mpn/alpha/submul_1.asm b/gmp/mpn/alpha/submul_1.asm deleted file mode 100755 index fe35e21..0000000 Binary files a/gmp/mpn/alpha/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/alpha/udiv_qrnnd.S b/gmp/mpn/alpha/udiv_qrnnd.S deleted file mode 100755 index 6b50468..0000000 Binary files a/gmp/mpn/alpha/udiv_qrnnd.S and /dev/null differ diff --git a/gmp/mpn/alpha/umul.asm b/gmp/mpn/alpha/umul.asm deleted file mode 100755 index aa9caae..0000000 Binary files a/gmp/mpn/alpha/umul.asm and /dev/null differ diff --git a/gmp/mpn/alpha/unicos.m4 b/gmp/mpn/alpha/unicos.m4 deleted file mode 100755 index 12dd98b..0000000 Binary files a/gmp/mpn/alpha/unicos.m4 and /dev/null differ diff --git a/gmp/mpn/arm/add_n.S b/gmp/mpn/arm/add_n.S deleted file mode 100755 index 1e1d47a..0000000 Binary files a/gmp/mpn/arm/add_n.S and /dev/null differ diff --git a/gmp/mpn/arm/addmul_1.S b/gmp/mpn/arm/addmul_1.S deleted file mode 100755 index e23e969..0000000 Binary files a/gmp/mpn/arm/addmul_1.S and /dev/null differ diff --git a/gmp/mpn/arm/gmp-mparam.h b/gmp/mpn/arm/gmp-mparam.h deleted file mode 100755 index a35b0c7..0000000 --- a/gmp/mpn/arm/gmp-mparam.h +++ /dev/null @@ -1,34 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 21 -#endif -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 48 -#endif diff --git a/gmp/mpn/arm/mul_1.S b/gmp/mpn/arm/mul_1.S deleted file mode 100755 index eaa17ea..0000000 Binary files a/gmp/mpn/arm/mul_1.S and /dev/null differ diff --git a/gmp/mpn/arm/sub_n.S b/gmp/mpn/arm/sub_n.S deleted file mode 100755 index b987ef9..0000000 Binary files a/gmp/mpn/arm/sub_n.S and /dev/null differ diff --git a/gmp/mpn/asm-defs.m4 b/gmp/mpn/asm-defs.m4 deleted file mode 100755 index 2c68861..0000000 Binary files a/gmp/mpn/asm-defs.m4 and /dev/null differ diff --git a/gmp/mpn/clipper/add_n.s b/gmp/mpn/clipper/add_n.s deleted file mode 100755 index 8223b4a..0000000 Binary files a/gmp/mpn/clipper/add_n.s and /dev/null differ diff --git a/gmp/mpn/clipper/mul_1.s b/gmp/mpn/clipper/mul_1.s deleted file mode 100755 index 0c8213d..0000000 Binary files a/gmp/mpn/clipper/mul_1.s and /dev/null differ diff --git a/gmp/mpn/clipper/sub_n.s b/gmp/mpn/clipper/sub_n.s deleted file mode 100755 index 90a98c0..0000000 Binary files a/gmp/mpn/clipper/sub_n.s and /dev/null differ diff --git a/gmp/mpn/cray/README b/gmp/mpn/cray/README deleted file mode 100755 index 3762fb3..0000000 Binary files a/gmp/mpn/cray/README and /dev/null differ diff --git a/gmp/mpn/cray/add_n.c b/gmp/mpn/cray/add_n.c deleted file mode 100755 index 1fdb394..0000000 --- a/gmp/mpn/cray/add_n.c +++ /dev/null @@ -1,96 +0,0 @@ -/* mpn_add_n -- Add two limb vectors of equal, non-zero length. - For Cray vector processors. - - Copyright (C) 1996, 2000 Free Software Foundation, Inc. - - This file is part of the GNU MP Library. - - The GNU MP Library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - The GNU MP Library 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. - - You should have received a copy of the GNU Lesser General Public License - along with the GNU MP Library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -mpn_add_n (c, a, b, n) - mp_ptr c; - mp_srcptr a, b; - mp_size_t n; -{ - mp_size_t i; - mp_size_t nm1 = n - 1; - int more_carries = 0; - int carry_out; - - /* For small operands the non-vector code is faster. */ - if (n < 16) - goto sequential; - - if (a == c || b == c) - { - TMP_DECL (marker); - TMP_MARK (marker); - if (c == a) - { - /* allocate temp space for a */ - mp_ptr ax = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB); - MPN_COPY (ax, a, n); - a = (mp_srcptr) ax; - } - if (c == b) - { - /* allocate temp space for b */ - mp_ptr bx = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB); - MPN_COPY (bx, b, n); - b = (mp_srcptr) bx; - } - carry_out = mpn_add_n (c, a, b, n); - TMP_FREE (marker); - return carry_out; - } - - carry_out = a[nm1] + b[nm1] < a[nm1]; - -#pragma _CRI ivdep /* Cray PVP systems */ - for (i = nm1; i > 0; i--) - { - int cy_in; - cy_in = a[i - 1] + b[i - 1] < a[i - 1]; - c[i] = a[i] + b[i] + cy_in; - more_carries += c[i] < cy_in; - } - c[0] = a[0] + b[0]; - - if (more_carries) - { - /* This won't vectorize, but we should come here rarely. */ - int cy; - sequential: - cy = 0; - for (i = 0; i < n; i++) - { - mp_limb_t ai, ci, t; - ai = a[i]; - t = b[i] + cy; - cy = t < cy; - ci = ai + t; - cy += ci < ai; - c[i] = ci; - } - carry_out = cy; - } - - return carry_out; -} diff --git a/gmp/mpn/cray/addmul_1.c b/gmp/mpn/cray/addmul_1.c deleted file mode 100755 index 031b4e8..0000000 --- a/gmp/mpn/cray/addmul_1.c +++ /dev/null @@ -1,46 +0,0 @@ -/* mpn_addmul_1 for Cray PVP. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t limb) -{ - mp_ptr p0, p1, tp; - mp_limb_t cy_limb; - TMP_DECL (marker); - TMP_MARK (marker); - - p1 = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - p0 = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - tp = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - - GMPN_MULWW (p1, p0, up, &n, &limb); - cy_limb = mpn_add_n (tp, rp, p0, n); - rp[0] = tp[0]; - cy_limb += mpn_add_n (rp + 1, tp + 1, p1, n - 1); - cy_limb += p1[n - 1]; - - TMP_FREE (marker); - return cy_limb; -} diff --git a/gmp/mpn/cray/gmp-mparam.h b/gmp/mpn/cray/gmp-mparam.h deleted file mode 100755 index 14f7b8e..0000000 --- a/gmp/mpn/cray/gmp-mparam.h +++ /dev/null @@ -1,27 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 64 -#define BITS_PER_SHORTINT 32 -#define BITS_PER_CHAR 8 diff --git a/gmp/mpn/cray/mul_1.c b/gmp/mpn/cray/mul_1.c deleted file mode 100755 index 0c8750b..0000000 --- a/gmp/mpn/cray/mul_1.c +++ /dev/null @@ -1,44 +0,0 @@ -/* mpn_mul_1 for Cray PVP. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t limb) -{ - mp_ptr p0, p1; - mp_limb_t cy_limb; - TMP_DECL (marker); - TMP_MARK (marker); - - p1 = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - p0 = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - - GMPN_MULWW (p1, p0, up, &n, &limb); - rp[0] = p0[0]; - cy_limb = mpn_add_n (rp + 1, p0 + 1, p1, n - 1); - cy_limb += p1[n - 1]; - - TMP_FREE (marker); - return cy_limb; -} diff --git a/gmp/mpn/cray/mulww.f b/gmp/mpn/cray/mulww.f deleted file mode 100755 index b374025..0000000 Binary files a/gmp/mpn/cray/mulww.f and /dev/null differ diff --git a/gmp/mpn/cray/mulww.s b/gmp/mpn/cray/mulww.s deleted file mode 100755 index aa67116..0000000 Binary files a/gmp/mpn/cray/mulww.s and /dev/null differ diff --git a/gmp/mpn/cray/sub_n.c b/gmp/mpn/cray/sub_n.c deleted file mode 100755 index 902e07a..0000000 --- a/gmp/mpn/cray/sub_n.c +++ /dev/null @@ -1,97 +0,0 @@ -/* mpn_sub_n -- Subtract two limb vectors of equal, non-zero length. - For Cray vector processors. - - Copyright (C) 1996, 2000 Free Software Foundation, Inc. - - This file is part of the GNU MP Library. - - The GNU MP Library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - The GNU MP Library 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. - - You should have received a copy of the GNU Lesser General Public License - along with the GNU MP Library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -mpn_sub_n (c, a, b, n) - mp_ptr c; - mp_srcptr a, b; - mp_size_t n; -{ - mp_size_t i; - mp_size_t nm1 = n - 1; - int more_carries = 0; - int carry_out; - - /* For small operands the non-vector code is faster. */ - if (n < 16) - goto sequential; - - if (a == c || b == c) - { - TMP_DECL (marker); - TMP_MARK (marker); - if (c == a) - { - /* allocate temp space for a */ - mp_ptr ax = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB); - MPN_COPY (ax, a, n); - a = (mp_srcptr) ax; - } - if (c == b) - { - /* allocate temp space for b */ - mp_ptr bx = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB); - MPN_COPY (bx, b, n); - b = (mp_srcptr) bx; - } - carry_out = mpn_sub_n (c, a, b, n); - TMP_FREE (marker); - return carry_out; - } - - carry_out = a[nm1] < b[nm1]; - -#pragma _CRI ivdep /* Cray PVP systems */ - for (i = nm1; i > 0; i--) - { - int cy_in; mp_limb_t t; - cy_in = a[i - 1] < b[i - 1]; - t = a[i] - b[i]; - more_carries += t < cy_in; - c[i] = t - cy_in; - } - c[0] = a[0] - b[0]; - - if (more_carries) - { - /* This won't vectorize, but we should come here rarely. */ - int cy; - sequential: - cy = 0; - for (i = 0; i < n; i++) - { - mp_limb_t ai, ci, t; - ai = a[i]; - t = b[i] + cy; - cy = t < cy; - ci = ai - t; - cy += ci > ai; - c[i] = ci; - } - carry_out = cy; - } - - return carry_out; -} diff --git a/gmp/mpn/cray/submul_1.c b/gmp/mpn/cray/submul_1.c deleted file mode 100755 index 4d2fb13..0000000 --- a/gmp/mpn/cray/submul_1.c +++ /dev/null @@ -1,46 +0,0 @@ -/* mpn_submul_1 for Cray PVP. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -mpn_submul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t limb) -{ - mp_ptr p0, p1, tp; - mp_limb_t cy_limb; - TMP_DECL (marker); - TMP_MARK (marker); - - p1 = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - p0 = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - tp = TMP_ALLOC (n * BYTES_PER_MP_LIMB); - - GMPN_MULWW (p1, p0, up, &n, &limb); - cy_limb = mpn_sub_n (tp, rp, p0, n); - rp[0] = tp[0]; - cy_limb += mpn_sub_n (rp + 1, tp + 1, p1, n - 1); - cy_limb += p1[n - 1]; - - TMP_FREE (marker); - return cy_limb; -} diff --git a/gmp/mpn/generic/add_n.c b/gmp/mpn/generic/add_n.c deleted file mode 100755 index 5fcb7e4..0000000 --- a/gmp/mpn/generic/add_n.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpn_add_n -- Add two limb vectors of equal, non-zero length. - -Copyright (C) 1992, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -#if __STDC__ -mpn_add_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) -#else -mpn_add_n (res_ptr, s1_ptr, s2_ptr, size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_srcptr s2_ptr; - mp_size_t size; -#endif -{ - register mp_limb_t x, y, cy; - register mp_size_t j; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - s2_ptr -= j; - res_ptr -= j; - - cy = 0; - do - { - y = s2_ptr[j]; - x = s1_ptr[j]; - y += cy; /* add previous carry to one addend */ - cy = (y < cy); /* get out carry from that addition */ - y = x + y; /* add other addend */ - cy = (y < x) + cy; /* get out carry from that add, combine */ - res_ptr[j] = y; - } - while (++j != 0); - - return cy; -} diff --git a/gmp/mpn/generic/addmul_1.c b/gmp/mpn/generic/addmul_1.c deleted file mode 100755 index 746ae31..0000000 --- a/gmp/mpn/generic/addmul_1.c +++ /dev/null @@ -1,65 +0,0 @@ -/* mpn_addmul_1 -- multiply the S1_SIZE long limb vector pointed to by S1_PTR - by S2_LIMB, add the S1_SIZE least significant limbs of the product to the - limb vector pointed to by RES_PTR. Return the most significant limb of - the product, adjusted for carry-out from the addition. - -Copyright (C) 1992, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -mp_limb_t -mpn_addmul_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - mp_size_t s1_size; - register mp_limb_t s2_limb; -{ - register mp_limb_t cy_limb; - register mp_size_t j; - register mp_limb_t prod_high, prod_low; - register mp_limb_t x; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -s1_size; - - /* Offset the base pointers to compensate for the negative indices. */ - res_ptr -= j; - s1_ptr -= j; - - cy_limb = 0; - do - { - umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb); - - prod_low += cy_limb; - cy_limb = (prod_low < cy_limb) + prod_high; - - x = res_ptr[j]; - prod_low = x + prod_low; - cy_limb += (prod_low < x); - res_ptr[j] = prod_low; - } - while (++j != 0); - - return cy_limb; -} diff --git a/gmp/mpn/generic/addsub_n.c b/gmp/mpn/generic/addsub_n.c deleted file mode 100755 index c9bab3e..0000000 --- a/gmp/mpn/generic/addsub_n.c +++ /dev/null @@ -1,167 +0,0 @@ -/* mpn_addsub_n -- Add and Subtract two limb vectors of equal, non-zero length. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#ifndef L1_CACHE_SIZE -#define L1_CACHE_SIZE 8192 /* only 68040 has less than this */ -#endif - -#define PART_SIZE (L1_CACHE_SIZE / BYTES_PER_MP_LIMB / 6) - - -/* mpn_addsub_n. - r1[] = s1[] + s2[] - r2[] = s1[] - s2[] - All operands have n limbs. - In-place operations allowed. */ -mp_limb_t -#if __STDC__ -mpn_addsub_n (mp_ptr r1p, mp_ptr r2p, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n) -#else -mpn_addsub_n (r1p, r2p, s1p, s2p, n) - mp_ptr r1p, r2p; - mp_srcptr s1p, s2p; - mp_size_t n; -#endif -{ - mp_limb_t acyn, acyo; /* carry for add */ - mp_limb_t scyn, scyo; /* carry for subtract */ - mp_size_t off; /* offset in operands */ - mp_size_t this_n; /* size of current chunk */ - - /* We alternatingly add and subtract in chunks that fit into the (L1) - cache. Since the chunks are several hundred limbs, the function call - overhead is insignificant, but we get much better locality. */ - - /* We have three variant of the inner loop, the proper loop is chosen - depending on whether r1 or r2 are the same operand as s1 or s2. */ - - if (r1p != s1p && r1p != s2p) - { - /* r1 is not identical to either input operand. We can therefore write - to r1 directly, without using temporary storage. */ - acyo = 0; - scyo = 0; - for (off = 0; off < n; off += PART_SIZE) - { - this_n = MIN (n - off, PART_SIZE); -#if HAVE_NATIVE_mpn_add_nc || !HAVE_NATIVE_mpn_add_n - acyo = mpn_add_nc (r1p + off, s1p + off, s2p + off, this_n, acyo); -#else - acyn = mpn_add_n (r1p + off, s1p + off, s2p + off, this_n); - acyo = acyn + mpn_add_1 (r1p + off, r1p + off, this_n, acyo); -#endif -#if HAVE_NATIVE_mpn_sub_nc || !HAVE_NATIVE_mpn_sub_n - scyo = mpn_sub_nc (r2p + off, s1p + off, s2p + off, this_n, scyo); -#else - scyn = mpn_sub_n (r2p + off, s1p + off, s2p + off, this_n); - scyo = scyn + mpn_sub_1 (r2p + off, r2p + off, this_n, scyo); -#endif - } - } - else if (r2p != s1p && r2p != s2p) - { - /* r2 is not identical to either input operand. We can therefore write - to r2 directly, without using temporary storage. */ - acyo = 0; - scyo = 0; - for (off = 0; off < n; off += PART_SIZE) - { - this_n = MIN (n - off, PART_SIZE); -#if HAVE_NATIVE_mpn_sub_nc || !HAVE_NATIVE_mpn_sub_n - scyo = mpn_sub_nc (r2p + off, s1p + off, s2p + off, this_n, scyo); -#else - scyn = mpn_sub_n (r2p + off, s1p + off, s2p + off, this_n); - scyo = scyn + mpn_sub_1 (r2p + off, r2p + off, this_n, scyo); -#endif -#if HAVE_NATIVE_mpn_add_nc || !HAVE_NATIVE_mpn_add_n - acyo = mpn_add_nc (r1p + off, s1p + off, s2p + off, this_n, acyo); -#else - acyn = mpn_add_n (r1p + off, s1p + off, s2p + off, this_n); - acyo = acyn + mpn_add_1 (r1p + off, r1p + off, this_n, acyo); -#endif - } - } - else - { - /* r1 and r2 are identical to s1 and s2 (r1==s1 and r2=s2 or vice versa) - Need temporary storage. */ - mp_limb_t tp[PART_SIZE]; - acyo = 0; - scyo = 0; - for (off = 0; off < n; off += PART_SIZE) - { - this_n = MIN (n - off, PART_SIZE); -#if HAVE_NATIVE_mpn_add_nc || !HAVE_NATIVE_mpn_add_n - acyo = mpn_add_nc (tp, s1p + off, s2p + off, this_n, acyo); -#else - acyn = mpn_add_n (tp, s1p + off, s2p + off, this_n); - acyo = acyn + mpn_add_1 (tp, tp, this_n, acyo); -#endif -#if HAVE_NATIVE_mpn_sub_nc || !HAVE_NATIVE_mpn_sub_n - scyo = mpn_sub_nc (r2p + off, s1p + off, s2p + off, this_n, scyo); -#else - scyn = mpn_sub_n (r2p + off, s1p + off, s2p + off, this_n); - scyo = scyn + mpn_sub_1 (r2p + off, r2p + off, this_n, scyo); -#endif - MPN_COPY (r1p + off, tp, this_n); - } - } - - return 2 * acyo + scyo; -} - -#ifdef MAIN -#include -#include -#include "timing.h" - -long cputime (); - -int -main (int argc, char **argv) -{ - mp_ptr r1p, r2p, s1p, s2p; - double t; - mp_size_t n; - - n = strtol (argv[1], 0, 0); - - r1p = malloc (n * BYTES_PER_MP_LIMB); - r2p = malloc (n * BYTES_PER_MP_LIMB); - s1p = malloc (n * BYTES_PER_MP_LIMB); - s2p = malloc (n * BYTES_PER_MP_LIMB); - TIME (t,(mpn_add_n(r1p,s1p,s2p,n),mpn_sub_n(r1p,s1p,s2p,n))); - printf (" separate add and sub: %.3f\n", t); - TIME (t,mpn_addsub_n(r1p,r2p,s1p,s2p,n)); - printf ("combined addsub separate variables: %.3f\n", t); - TIME (t,mpn_addsub_n(r1p,r2p,r1p,s2p,n)); - printf (" combined addsub r1 overlap: %.3f\n", t); - TIME (t,mpn_addsub_n(r1p,r2p,r1p,s2p,n)); - printf (" combined addsub r2 overlap: %.3f\n", t); - TIME (t,mpn_addsub_n(r1p,r2p,r1p,r2p,n)); - printf (" combined addsub in-place: %.3f\n", t); - - return 0; -} -#endif diff --git a/gmp/mpn/generic/bdivmod.c b/gmp/mpn/generic/bdivmod.c deleted file mode 100755 index c4bcb41..0000000 --- a/gmp/mpn/generic/bdivmod.c +++ /dev/null @@ -1,120 +0,0 @@ -/* mpn/bdivmod.c: mpn_bdivmod for computing U/V mod 2^d. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* q_high = mpn_bdivmod (qp, up, usize, vp, vsize, d). - - Puts the low d/BITS_PER_MP_LIMB limbs of Q = U / V mod 2^d at qp, and - returns the high d%BITS_PER_MP_LIMB bits of Q as the result. - - Also, U - Q * V mod 2^(usize*BITS_PER_MP_LIMB) is placed at up. Since the - low d/BITS_PER_MP_LIMB limbs of this difference are zero, the code allows - the limb vectors at qp to overwrite the low limbs at up, provided qp <= up. - - Preconditions: - 1. V is odd. - 2. usize * BITS_PER_MP_LIMB >= d. - 3. If Q and U overlap, qp <= up. - - Ken Weber (kweber@mat.ufrgs.br, kweber@mcs.kent.edu) - - Funding for this work has been partially provided by Conselho Nacional - de Desenvolvimento Cienti'fico e Tecnolo'gico (CNPq) do Brazil, Grant - 301314194-2, and was done while I was a visiting reseacher in the Instituto - de Matema'tica at Universidade Federal do Rio Grande do Sul (UFRGS). - - References: - T. Jebelean, An algorithm for exact division, Journal of Symbolic - Computation, v. 15, 1993, pp. 169-180. - - K. Weber, The accelerated integer GCD algorithm, ACM Transactions on - Mathematical Software, v. 21 (March), 1995, pp. 111-122. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -mp_limb_t -#if __STDC__ -mpn_bdivmod (mp_ptr qp, mp_ptr up, mp_size_t usize, - mp_srcptr vp, mp_size_t vsize, unsigned long int d) -#else -mpn_bdivmod (qp, up, usize, vp, vsize, d) - mp_ptr qp; - mp_ptr up; - mp_size_t usize; - mp_srcptr vp; - mp_size_t vsize; - unsigned long int d; -#endif -{ - mp_limb_t v_inv; - - /* 1/V mod 2^BITS_PER_MP_LIMB. */ - modlimb_invert (v_inv, vp[0]); - - /* Fast code for two cases previously used by the accel part of mpn_gcd. - (Could probably remove this now it's inlined there.) */ - if (usize == 2 && vsize == 2 && - (d == BITS_PER_MP_LIMB || d == 2*BITS_PER_MP_LIMB)) - { - mp_limb_t hi, lo; - mp_limb_t q = up[0] * v_inv; - umul_ppmm (hi, lo, q, vp[0]); - up[0] = 0, up[1] -= hi + q*vp[1], qp[0] = q; - if (d == 2*BITS_PER_MP_LIMB) - q = up[1] * v_inv, up[1] = 0, qp[1] = q; - return 0; - } - - /* Main loop. */ - while (d >= BITS_PER_MP_LIMB) - { - mp_limb_t q = up[0] * v_inv; - mp_limb_t b = mpn_submul_1 (up, vp, MIN (usize, vsize), q); - if (usize > vsize) - mpn_sub_1 (up + vsize, up + vsize, usize - vsize, b); - d -= BITS_PER_MP_LIMB; - up += 1, usize -= 1; - *qp++ = q; - } - - if (d) - { - mp_limb_t b; - mp_limb_t q = (up[0] * v_inv) & (((mp_limb_t)1< vsize) - mpn_sub_1 (up + vsize, up + vsize, usize - vsize, b); - return q; - } - - return 0; -} diff --git a/gmp/mpn/generic/bz_divrem_n.c b/gmp/mpn/generic/bz_divrem_n.c deleted file mode 100755 index 2f5ea57..0000000 --- a/gmp/mpn/generic/bz_divrem_n.c +++ /dev/null @@ -1,224 +0,0 @@ -/* mpn_bz_divrem_n and auxilliary routines. - - THE FUNCTIONS IN THIS FILE ARE INTERNAL FUNCTIONS WITH MUTABLE - INTERFACES. IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. - IN FACT, IT IS ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A - FUTURE GNU MP RELEASE. - - -Copyright (C) 2000 Free Software Foundation, Inc. -Contributed by Paul Zimmermann. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* -[1] Fast Recursive Division, by Christoph Burnikel and Joachim Ziegler, - Technical report MPI-I-98-1-022, october 1998. - http://www.mpi-sb.mpg.de/~ziegler/TechRep.ps.gz -*/ - -static mp_limb_t mpn_bz_div_3_halves_by_2 _PROTO ((mp_ptr, mp_ptr, mp_srcptr, - mp_size_t, mp_ptr)); - -static mp_limb_t mpn_bz_divrem_aux _PROTO ((mp_ptr, mp_ptr, mp_srcptr, - mp_size_t, mp_ptr)); - -/* mpn_bz_divrem_n(n) calls 2*mul(n/2)+2*div(n/2), thus to be faster than - div(n) = 4*div(n/2), we need mul(n/2) to be faster than the classic way, - i.e. n/2 >= KARATSUBA_MUL_THRESHOLD */ -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD (7 * KARATSUBA_MUL_THRESHOLD) -#endif - -#if 0 -static -unused_mpn_divrem (qp, qxn, np, nn, dp, dn) - mp_ptr qp; - mp_size_t qxn; - mp_ptr np; - mp_size_t nn; - mp_srcptr dp; - mp_size_t dn; -{ - /* This might be useful: */ - if (qxn != 0) - { - mp_limb_t c; - mp_ptr tp = alloca ((nn + qxn) * BYTES_PER_MP_LIMB); - MPN_COPY (tp + qxn - nn, np, nn); - MPN_ZERO (tp, qxn); - c = mpn_divrem (qp, 0L, tp, nn + qxn, dp, dn); - /* Maybe copy proper part of tp to np? Documentation is unclear about - the returned np value when qxn != 0 */ - ALLOCA_FREE((nn + qxn) * BYTES_PER_MP_LIMB); - return c; - } -} -#endif - -/* mpn_bz_divrem_n - Implements algorithm of page 8 in [1]: divides (np,2n) - by (dp,n) and puts the quotient in (qp,n), the remainder in (np,n). - Returns most significant limb of the quotient, which is 0 or 1. - Requires that the most significant bit of the divisor is set. */ - -mp_limb_t -#if __STDC__ -mpn_bz_divrem_n (mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n) -#else -mpn_bz_divrem_n (qp, np, dp, n) - mp_ptr qp; - mp_ptr np; - mp_srcptr dp; - mp_size_t n; -#endif -{ - mp_limb_t qhl = 0; - if (mpn_cmp (np + n, dp, n) >= 0) - { - qhl = 1; - mpn_sub_n (np + n, np + n, dp, n); - abort (); - } - if (n % 2 != 0) - { - /* divide (2n - 2) most significant limbs from np by those (n - 1) from dp */ - if (n < BZ_THRESHOLD) - qhl += mpn_sb_divrem_mn (qp + 1, np + 2, 2 * (n - 1), dp + 1, n - 1); - else - qhl += mpn_bz_divrem_n (qp + 1, np + 2, dp + 1, n - 1); - /* now (qp + 1, n - 1) contains the quotient of (np + 2, 2n - 2) by - (dp + 1, n - 1) and (np + 2, n - 1) contains the remainder */ - if (mpn_sub_1 (np + n, np + n, 1, - mpn_submul_1 (np + 1, qp + 1, n - 1, dp[0]))) - { - /* quotient too large */ - qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L); - if (mpn_add_n (np + 1, np + 1, dp, n) == 0) - { /* still too large */ - qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L); - mpn_add_n (np + 1, np + 1, dp, n); /* always carry here */ - } - } - /* now divide (np, n + 1) by (dp, n) */ - qhl += mpn_add_1 (qp + 1, qp + 1, n - 1, - mpn_sb_divrem_mn (qp, np, n + 1, dp, n)); - } - else - { - mp_ptr tmp; - mp_size_t n2 = n/2; - TMP_DECL (marker); - TMP_MARK (marker); - tmp = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB); - qhl = mpn_bz_div_3_halves_by_2 (qp + n2, np + n2, dp, n2, tmp); - qhl += mpn_add_1 (qp + n2, qp + n2, n2, - mpn_bz_div_3_halves_by_2 (qp, np, dp, n2, tmp)); - TMP_FREE (marker); - } - return qhl; -} - -/* Like mpn_bz_divrem_n, but without memory allocation. Also - assumes mpn_cmp (np + n, dp, n) < 0 */ - -static mp_limb_t -#if __STDC__ -mpn_bz_divrem_aux (mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, mp_ptr tmp) -#else -mpn_bz_divrem_aux (qp, np, dp, n, tmp) - mp_ptr qp; - mp_ptr np; - mp_srcptr dp; - mp_size_t n; - mp_ptr tmp; -#endif -{ - mp_limb_t qhl; - - if (n % 2 != 0) - { - /* divide (2n - 2) most significant limbs from np by those (n - 1) from dp */ - qhl = mpn_bz_divrem_aux (qp + 1, np + 2, dp + 1, n - 1, tmp); - /* now (qp + 1, n - 1) contains the quotient of (np + 2, 2n - 2) by - (dp + 1, n - 1) and (np + 2, n - 1) contains the remainder */ - if (mpn_sub_1 (np + n, np + n, 1, - mpn_submul_1 (np + 1, qp + 1, n - 1, dp[0]))) - { - /* quotient too large */ - qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L); - if (mpn_add_n (np + 1, np + 1, dp, n) == 0) - { /* still too large */ - qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L); - mpn_add_n (np + 1, np + 1, dp, n); /* always carry here */ - } - } - /* now divide (np, n + 1) by (dp, n) */ - qhl += mpn_add_1 (qp + 1, qp + 1, n - 1, - mpn_sb_divrem_mn (qp, np, n + 1, dp, n)); - } - else - { - mp_size_t n2 = n/2; - qhl = mpn_bz_div_3_halves_by_2 (qp + n2, np + n2, dp, n2, tmp); - qhl += mpn_add_1 (qp + n2, qp + n2, n2, - mpn_bz_div_3_halves_by_2 (qp, np, dp, n2, tmp)); - } - return qhl; -} - -/* divides (np, 3n) by (dp, 2n) and puts the quotient in (qp, n), - the remainder in (np, 2n) */ - -static mp_limb_t -#if __STDC__ -mpn_bz_div_3_halves_by_2 (mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, - mp_ptr tmp) -#else -mpn_bz_div_3_halves_by_2 (qp, np, dp, n, tmp) - mp_ptr qp; - mp_ptr np; - mp_srcptr dp; - mp_size_t n; - mp_ptr tmp; -#endif -{ - mp_size_t twon = n + n; - mp_limb_t qhl; - - if (n < BZ_THRESHOLD) - qhl = mpn_sb_divrem_mn (qp, np + n, twon, dp + n, n); - else - qhl = mpn_bz_divrem_aux (qp, np + n, dp + n, n, tmp); - /* q = (qp, n), c = (np + n, n) with the notations of [1] */ - mpn_mul_n (tmp, qp, dp, n); - if (qhl != 0) - mpn_add_n (tmp + n, tmp + n, dp, n); - if (mpn_sub_n (np, np, tmp, twon)) /* R = (np, 2n) */ - { - qhl -= mpn_sub_1 (qp, qp, n, 1L); - if (mpn_add_n (np, np, dp, twon) == 0) - { /* qp still too large */ - qhl -= mpn_sub_1 (qp, qp, n, 1L); - mpn_add_n (np, np, dp, twon); /* always carry here */ - } - } - return qhl; -} diff --git a/gmp/mpn/generic/cmp.c b/gmp/mpn/generic/cmp.c deleted file mode 100755 index 8e9792f..0000000 --- a/gmp/mpn/generic/cmp.c +++ /dev/null @@ -1,56 +0,0 @@ -/* mpn_cmp -- Compare two low-level natural-number integers. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE. - There are no restrictions on the relative sizes of - the two arguments. - Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2. */ - -int -#if __STDC__ -mpn_cmp (mp_srcptr op1_ptr, mp_srcptr op2_ptr, mp_size_t size) -#else -mpn_cmp (op1_ptr, op2_ptr, size) - mp_srcptr op1_ptr; - mp_srcptr op2_ptr; - mp_size_t size; -#endif -{ - mp_size_t i; - mp_limb_t op1_word, op2_word; - - for (i = size - 1; i >= 0; i--) - { - op1_word = op1_ptr[i]; - op2_word = op2_ptr[i]; - if (op1_word != op2_word) - goto diff; - } - return 0; - diff: - /* This can *not* be simplified to - op2_word - op2_word - since that expression might give signed overflow. */ - return (op1_word > op2_word) ? 1 : -1; -} diff --git a/gmp/mpn/generic/diveby3.c b/gmp/mpn/generic/diveby3.c deleted file mode 100755 index a2fb552..0000000 --- a/gmp/mpn/generic/diveby3.c +++ /dev/null @@ -1,77 +0,0 @@ -/* mpn_divexact_by3 -- mpn division by 3, expecting no remainder. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - - -#include "gmp.h" -#include "gmp-impl.h" - - -/* Multiplicative inverse of 3, modulo 2^BITS_PER_MP_LIMB. - 0xAAAAAAAB for 32 bits, 0xAAAAAAAAAAAAAAAB for 64 bits. */ -#define INVERSE_3 ((MP_LIMB_T_MAX / 3) * 2 + 1) - - -/* The "c += ..."s are adding the high limb of 3*l to c. That high limb - will be 0, 1 or 2. Doing two separate "+="s seems to turn out better - code on gcc (as of 2.95.2 at least). - - When a subtraction of a 0,1,2 carry value causes a borrow, that leaves a - limb value of either 0xFF...FF or 0xFF...FE and the multiply by INVERSE_3 - gives 0x55...55 or 0xAA...AA respectively, producing a further borrow of - only 0 or 1 respectively. Hence the carry out of each stage and for the - return value is always only 0, 1 or 2. */ - -mp_limb_t -#if __STDC__ -mpn_divexact_by3c (mp_ptr dst, mp_srcptr src, mp_size_t size, mp_limb_t c) -#else -mpn_divexact_by3c (dst, src, size, c) - mp_ptr dst; - mp_srcptr src; - mp_size_t size; - mp_limb_t c; -#endif -{ - mp_size_t i; - - ASSERT (size >= 1); - - i = 0; - do - { - mp_limb_t l, s; - - s = src[i]; - l = s - c; - c = (l > s); - - l *= INVERSE_3; - dst[i] = l; - - c += (l > MP_LIMB_T_MAX/3); - c += (l > (MP_LIMB_T_MAX/3)*2); - } - while (++i < size); - - return c; -} diff --git a/gmp/mpn/generic/divrem.c b/gmp/mpn/generic/divrem.c deleted file mode 100755 index 30673e7..0000000 --- a/gmp/mpn/generic/divrem.c +++ /dev/null @@ -1,101 +0,0 @@ -/* mpn_divrem -- Divide natural numbers, producing both remainder and - quotient. This is now just a middle layer for calling the new - internal mpn_tdiv_qr. - -Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -mp_limb_t -#if __STDC__ -mpn_divrem (mp_ptr qp, mp_size_t qxn, - mp_ptr np, mp_size_t nn, - mp_srcptr dp, mp_size_t dn) -#else -mpn_divrem (qp, qxn, np, nn, dp, dn) - mp_ptr qp; - mp_size_t qxn; - mp_ptr np; - mp_size_t nn; - mp_srcptr dp; - mp_size_t dn; -#endif -{ - if (dn == 1) - { - mp_limb_t ret; - mp_ptr q2p; - mp_size_t qn; - TMP_DECL (marker); - - TMP_MARK (marker); - q2p = (mp_ptr) TMP_ALLOC ((nn + qxn) * BYTES_PER_MP_LIMB); - - np[0] = mpn_divrem_1 (q2p, qxn, np, nn, dp[0]); - qn = nn + qxn - 1; - MPN_COPY (qp, q2p, qn); - ret = q2p[qn]; - - TMP_FREE (marker); - return ret; - } - else if (dn == 2) - { - return mpn_divrem_2 (qp, qxn, np, nn, dp); - } - else - { - mp_ptr rp, q2p; - mp_limb_t qhl; - mp_size_t qn; - TMP_DECL (marker); - - TMP_MARK (marker); - if (qxn != 0) - { - mp_ptr n2p; - n2p = (mp_ptr) TMP_ALLOC ((nn + qxn) * BYTES_PER_MP_LIMB); - MPN_ZERO (n2p, qxn); - MPN_COPY (n2p + qxn, np, nn); - q2p = (mp_ptr) TMP_ALLOC ((nn - dn + qxn + 1) * BYTES_PER_MP_LIMB); - rp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB); - mpn_tdiv_qr (q2p, rp, 0L, n2p, nn + qxn, dp, dn); - MPN_COPY (np, rp, dn); - qn = nn - dn + qxn; - MPN_COPY (qp, q2p, qn); - qhl = q2p[qn]; - } - else - { - q2p = (mp_ptr) TMP_ALLOC ((nn - dn + 1) * BYTES_PER_MP_LIMB); - rp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB); - mpn_tdiv_qr (q2p, rp, 0L, np, nn, dp, dn); - MPN_COPY (np, rp, dn); /* overwrite np area with remainder */ - qn = nn - dn; - MPN_COPY (qp, q2p, qn); - qhl = q2p[qn]; - } - TMP_FREE (marker); - return qhl; - } -} diff --git a/gmp/mpn/generic/divrem_1.c b/gmp/mpn/generic/divrem_1.c deleted file mode 100755 index e93f241..0000000 --- a/gmp/mpn/generic/divrem_1.c +++ /dev/null @@ -1,248 +0,0 @@ -/* mpn_divrem_1(quot_ptr, qsize, dividend_ptr, dividend_size, divisor_limb) -- - Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by DIVISOR_LIMB. - Write DIVIDEND_SIZE limbs of quotient at QUOT_PTR. - Return the single-limb remainder. - There are no constraints on the value of the divisor. - - QUOT_PTR and DIVIDEND_PTR might point to the same limb. - -Copyright (C) 1991, 1993, 1994, 1996, 1998, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - - -/* __gmpn_divmod_1_internal(quot_ptr,dividend_ptr,dividend_size,divisor_limb) - Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by DIVISOR_LIMB. - Write DIVIDEND_SIZE limbs of quotient at QUOT_PTR. - Return the single-limb remainder. - There are no constraints on the value of the divisor. - - QUOT_PTR and DIVIDEND_PTR might point to the same limb. */ - -#ifndef UMUL_TIME -#define UMUL_TIME 1 -#endif - -#ifndef UDIV_TIME -#define UDIV_TIME UMUL_TIME -#endif - -static mp_limb_t -#if __STDC__ -__gmpn_divmod_1_internal (mp_ptr quot_ptr, - mp_srcptr dividend_ptr, mp_size_t dividend_size, - mp_limb_t divisor_limb) -#else -__gmpn_divmod_1_internal (quot_ptr, dividend_ptr, dividend_size, divisor_limb) - mp_ptr quot_ptr; - mp_srcptr dividend_ptr; - mp_size_t dividend_size; - mp_limb_t divisor_limb; -#endif -{ - mp_size_t i; - mp_limb_t n1, n0, r; - int dummy; - - /* ??? Should this be handled at all? Rely on callers? */ - if (dividend_size == 0) - return 0; - - /* If multiplication is much faster than division, and the - dividend is large, pre-invert the divisor, and use - only multiplications in the inner loop. */ - - /* This test should be read: - Does it ever help to use udiv_qrnnd_preinv? - && Does what we save compensate for the inversion overhead? */ - if (UDIV_TIME > (2 * UMUL_TIME + 6) - && (UDIV_TIME - (2 * UMUL_TIME + 6)) * dividend_size > UDIV_TIME) - { - int normalization_steps; - - count_leading_zeros (normalization_steps, divisor_limb); - if (normalization_steps != 0) - { - mp_limb_t divisor_limb_inverted; - - divisor_limb <<= normalization_steps; - invert_limb (divisor_limb_inverted, divisor_limb); - - n1 = dividend_ptr[dividend_size - 1]; - r = n1 >> (BITS_PER_MP_LIMB - normalization_steps); - - /* Possible optimization: - if (r == 0 - && divisor_limb > ((n1 << normalization_steps) - | (dividend_ptr[dividend_size - 2] >> ...))) - ...one division less... */ - - for (i = dividend_size - 2; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd_preinv (quot_ptr[i + 1], r, r, - ((n1 << normalization_steps) - | (n0 >> (BITS_PER_MP_LIMB - normalization_steps))), - divisor_limb, divisor_limb_inverted); - n1 = n0; - } - udiv_qrnnd_preinv (quot_ptr[0], r, r, - n1 << normalization_steps, - divisor_limb, divisor_limb_inverted); - return r >> normalization_steps; - } - else - { - mp_limb_t divisor_limb_inverted; - - invert_limb (divisor_limb_inverted, divisor_limb); - - i = dividend_size - 1; - r = dividend_ptr[i]; - - if (r >= divisor_limb) - r = 0; - else - { - quot_ptr[i] = 0; - i--; - } - - for (; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd_preinv (quot_ptr[i], r, r, - n0, divisor_limb, divisor_limb_inverted); - } - return r; - } - } - else - { - if (UDIV_NEEDS_NORMALIZATION) - { - int normalization_steps; - - count_leading_zeros (normalization_steps, divisor_limb); - if (normalization_steps != 0) - { - divisor_limb <<= normalization_steps; - - n1 = dividend_ptr[dividend_size - 1]; - r = n1 >> (BITS_PER_MP_LIMB - normalization_steps); - - /* Possible optimization: - if (r == 0 - && divisor_limb > ((n1 << normalization_steps) - | (dividend_ptr[dividend_size - 2] >> ...))) - ...one division less... */ - - for (i = dividend_size - 2; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd (quot_ptr[i + 1], r, r, - ((n1 << normalization_steps) - | (n0 >> (BITS_PER_MP_LIMB - normalization_steps))), - divisor_limb); - n1 = n0; - } - udiv_qrnnd (quot_ptr[0], r, r, - n1 << normalization_steps, - divisor_limb); - return r >> normalization_steps; - } - } - /* No normalization needed, either because udiv_qrnnd doesn't require - it, or because DIVISOR_LIMB is already normalized. */ - - i = dividend_size - 1; - r = dividend_ptr[i]; - - if (r >= divisor_limb) - r = 0; - else - { - quot_ptr[i] = 0; - i--; - } - - for (; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd (quot_ptr[i], r, r, n0, divisor_limb); - } - return r; - } -} - - - -mp_limb_t -#if __STDC__ -mpn_divrem_1 (mp_ptr qp, mp_size_t qxn, - mp_srcptr np, mp_size_t nn, - mp_limb_t d) -#else -mpn_divrem_1 (qp, qxn, np, nn, d) - mp_ptr qp; - mp_size_t qxn; - mp_srcptr np; - mp_size_t nn; - mp_limb_t d; -#endif -{ - mp_limb_t rlimb; - mp_size_t i; - - /* Develop integer part of quotient. */ - rlimb = __gmpn_divmod_1_internal (qp + qxn, np, nn, d); - - /* Develop fraction part of quotient. This is not as fast as it should; - the preinvert stuff from __gmpn_divmod_1_internal ought to be used here - too. */ - if (UDIV_NEEDS_NORMALIZATION) - { - int normalization_steps; - - count_leading_zeros (normalization_steps, d); - if (normalization_steps != 0) - { - d <<= normalization_steps; - rlimb <<= normalization_steps; - - for (i = qxn - 1; i >= 0; i--) - udiv_qrnnd (qp[i], rlimb, rlimb, 0, d); - - return rlimb >> normalization_steps; - } - else - /* fall out */ - ; - } - - for (i = qxn - 1; i >= 0; i--) - udiv_qrnnd (qp[i], rlimb, rlimb, 0, d); - - return rlimb; -} diff --git a/gmp/mpn/generic/divrem_2.c b/gmp/mpn/generic/divrem_2.c deleted file mode 100755 index 0bc31ae..0000000 --- a/gmp/mpn/generic/divrem_2.c +++ /dev/null @@ -1,151 +0,0 @@ -/* mpn_divrem_2 -- Divide natural numbers, producing both remainder and - quotient. The divisor is two limbs. - - THIS FILE CONTAINS INTERNAL FUNCTIONS WITH MUTABLE INTERFACES. IT IS - ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS - ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP - RELEASE. - - -Copyright (C) 1993, 1994, 1995, 1996, 1999, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Divide num (NP/NSIZE) by den (DP/2) and write - the NSIZE-2 least significant quotient limbs at QP - and the 2 long remainder at NP. If QEXTRA_LIMBS is - non-zero, generate that many fraction bits and append them after the - other quotient limbs. - Return the most significant limb of the quotient, this is always 0 or 1. - - Preconditions: - 0. NSIZE >= 2. - 1. The most significant bit of the divisor must be set. - 2. QP must either not overlap with the input operands at all, or - QP + 2 >= NP must hold true. (This means that it's - possible to put the quotient in the high part of NUM, right after the - remainder in NUM. - 3. NSIZE >= 2, even if QEXTRA_LIMBS is non-zero. */ - -mp_limb_t -#if __STDC__ -mpn_divrem_2 (mp_ptr qp, mp_size_t qxn, - mp_ptr np, mp_size_t nsize, - mp_srcptr dp) -#else -mpn_divrem_2 (qp, qxn, np, nsize, dp) - mp_ptr qp; - mp_size_t qxn; - mp_ptr np; - mp_size_t nsize; - mp_srcptr dp; -#endif -{ - mp_limb_t most_significant_q_limb = 0; - mp_size_t i; - mp_limb_t n1, n0, n2; - mp_limb_t d1, d0; - mp_limb_t d1inv; - int have_preinv; - - np += nsize - 2; - d1 = dp[1]; - d0 = dp[0]; - n1 = np[1]; - n0 = np[0]; - - if (n1 >= d1 && (n1 > d1 || n0 >= d0)) - { - sub_ddmmss (n1, n0, n1, n0, d1, d0); - most_significant_q_limb = 1; - } - - /* If multiplication is much faster than division, preinvert the most - significant divisor limb before entering the loop. */ - if (UDIV_TIME > 2 * UMUL_TIME + 6) - { - have_preinv = 0; - if ((UDIV_TIME - (2 * UMUL_TIME + 6)) * (nsize - 2) > UDIV_TIME) - { - invert_limb (d1inv, d1); - have_preinv = 1; - } - } - - for (i = qxn + nsize - 2 - 1; i >= 0; i--) - { - mp_limb_t q; - mp_limb_t r; - - if (i >= qxn) - np--; - else - np[0] = 0; - - if (n1 == d1) - { - /* Q should be either 111..111 or 111..110. Need special treatment - of this rare case as normal division would give overflow. */ - q = ~(mp_limb_t) 0; - - r = n0 + d1; - if (r < d1) /* Carry in the addition? */ - { - add_ssaaaa (n1, n0, r - d0, np[0], 0, d0); - qp[i] = q; - continue; - } - n1 = d0 - (d0 != 0); - n0 = -d0; - } - else - { - if (UDIV_TIME > 2 * UMUL_TIME + 6 && have_preinv) - udiv_qrnnd_preinv (q, r, n1, n0, d1, d1inv); - else - udiv_qrnnd (q, r, n1, n0, d1); - umul_ppmm (n1, n0, d0, q); - } - - n2 = np[0]; - - q_test: - if (n1 > r || (n1 == r && n0 > n2)) - { - /* The estimated Q was too large. */ - q--; - - sub_ddmmss (n1, n0, n1, n0, 0, d0); - r += d1; - if (r >= d1) /* If not carry, test Q again. */ - goto q_test; - } - - qp[i] = q; - sub_ddmmss (n1, n0, r, n2, n1, n0); - } - np[1] = n1; - np[0] = n0; - - return most_significant_q_limb; -} diff --git a/gmp/mpn/generic/dump.c b/gmp/mpn/generic/dump.c deleted file mode 100755 index 66f375c..0000000 --- a/gmp/mpn/generic/dump.c +++ /dev/null @@ -1,76 +0,0 @@ -/* THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS NOT SAFE TO - CALL THIS FUNCTION DIRECTLY. IN FACT, IT IS ALMOST GUARANTEED THAT THIS - FUNCTION WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. - - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpn_dump (mp_srcptr ptr, mp_size_t size) -#else -mpn_dump (ptr, size) - mp_srcptr ptr; - mp_size_t size; -#endif -{ - MPN_NORMALIZE (ptr, size); - - if (size == 0) - printf ("0\n"); - else - { - size--; - if (BYTES_PER_MP_LIMB > sizeof (long)) - { - if ((ptr[size] >> BITS_PER_MP_LIMB/2) != 0) - { - printf ("%lX", - (unsigned long) (ptr[size] >> BITS_PER_MP_LIMB/2)); - printf ("%0*lX", (int) (BYTES_PER_MP_LIMB), - (unsigned long) ptr[size]); - } - else - printf ("%lX", (unsigned long) ptr[size]); - } - else - printf ("%lX", ptr[size]); - - while (size) - { - size--; - if (BYTES_PER_MP_LIMB > sizeof (long)) - { - printf ("%0*lX", (int) (BYTES_PER_MP_LIMB), - (unsigned long) (ptr[size] >> BITS_PER_MP_LIMB/2)); - printf ("%0*lX", (int) (BYTES_PER_MP_LIMB), - (unsigned long) ptr[size]); - } - else - printf ("%0*lX", (int) (2 * BYTES_PER_MP_LIMB), ptr[size]); - } - printf ("\n"); - } -} diff --git a/gmp/mpn/generic/gcd.c b/gmp/mpn/generic/gcd.c deleted file mode 100755 index 059e219..0000000 --- a/gmp/mpn/generic/gcd.c +++ /dev/null @@ -1,414 +0,0 @@ -/* mpn/gcd.c: mpn_gcd for gcd of two odd integers. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* Integer greatest common divisor of two unsigned integers, using - the accelerated algorithm (see reference below). - - mp_size_t mpn_gcd (up, usize, vp, vsize). - - Preconditions [U = (up, usize) and V = (vp, vsize)]: - - 1. V is odd. - 2. numbits(U) >= numbits(V). - - Both U and V are destroyed by the operation. The result is left at vp, - and its size is returned. - - Ken Weber (kweber@mat.ufrgs.br, kweber@mcs.kent.edu) - - Funding for this work has been partially provided by Conselho Nacional - de Desenvolvimento Cienti'fico e Tecnolo'gico (CNPq) do Brazil, Grant - 301314194-2, and was done while I was a visiting reseacher in the Instituto - de Matema'tica at Universidade Federal do Rio Grande do Sul (UFRGS). - - Refer to - K. Weber, The accelerated integer GCD algorithm, ACM Transactions on - Mathematical Software, v. 21 (March), 1995, pp. 111-122. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* If MIN (usize, vsize) >= GCD_ACCEL_THRESHOLD, then the accelerated - algorithm is used, otherwise the binary algorithm is used. This may be - adjusted for different architectures. */ -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 5 -#endif - -/* When U and V differ in size by more than BMOD_THRESHOLD, the accelerated - algorithm reduces using the bmod operation. Otherwise, the k-ary reduction - is used. 0 <= BMOD_THRESHOLD < BITS_PER_MP_LIMB. */ -enum - { - BMOD_THRESHOLD = BITS_PER_MP_LIMB/2 - }; - - -/* Use binary algorithm to compute V <-- GCD (V, U) for usize, vsize == 2. - Both U and V must be odd. */ -static __gmp_inline mp_size_t -#if __STDC__ -gcd_2 (mp_ptr vp, mp_srcptr up) -#else -gcd_2 (vp, up) - mp_ptr vp; - mp_srcptr up; -#endif -{ - mp_limb_t u0, u1, v0, v1; - mp_size_t vsize; - - u0 = up[0], u1 = up[1], v0 = vp[0], v1 = vp[1]; - - while (u1 != v1 && u0 != v0) - { - unsigned long int r; - if (u1 > v1) - { - u1 -= v1 + (u0 < v0), u0 -= v0; - count_trailing_zeros (r, u0); - u0 = u1 << (BITS_PER_MP_LIMB - r) | u0 >> r; - u1 >>= r; - } - else /* u1 < v1. */ - { - v1 -= u1 + (v0 < u0), v0 -= u0; - count_trailing_zeros (r, v0); - v0 = v1 << (BITS_PER_MP_LIMB - r) | v0 >> r; - v1 >>= r; - } - } - - vp[0] = v0, vp[1] = v1, vsize = 1 + (v1 != 0); - - /* If U == V == GCD, done. Otherwise, compute GCD (V, |U - V|). */ - if (u1 == v1 && u0 == v0) - return vsize; - - v0 = (u0 == v0) ? (u1 > v1) ? u1-v1 : v1-u1 : (u0 > v0) ? u0-v0 : v0-u0; - vp[0] = mpn_gcd_1 (vp, vsize, v0); - - return 1; -} - -/* The function find_a finds 0 < N < 2^BITS_PER_MP_LIMB such that there exists - 0 < |D| < 2^BITS_PER_MP_LIMB, and N == D * C mod 2^(2*BITS_PER_MP_LIMB). - In the reference article, D was computed along with N, but it is better to - compute D separately as D <-- N / C mod 2^(BITS_PER_MP_LIMB + 1), treating - the result as a twos' complement signed integer. - - Initialize N1 to C mod 2^(2*BITS_PER_MP_LIMB). According to the reference - article, N2 should be initialized to 2^(2*BITS_PER_MP_LIMB), but we use - 2^(2*BITS_PER_MP_LIMB) - N1 to start the calculations within double - precision. If N2 > N1 initially, the first iteration of the while loop - will swap them. In all other situations, N1 >= N2 is maintained. */ - -static -#if ! defined (__i386__) -__gmp_inline /* don't inline this for the x86 */ -#endif -mp_limb_t -#if __STDC__ -find_a (mp_srcptr cp) -#else -find_a (cp) - mp_srcptr cp; -#endif -{ - unsigned long int leading_zero_bits = 0; - - mp_limb_t n1_l = cp[0]; /* N1 == n1_h * 2^BITS_PER_MP_LIMB + n1_l. */ - mp_limb_t n1_h = cp[1]; - - mp_limb_t n2_l = -n1_l; /* N2 == n2_h * 2^BITS_PER_MP_LIMB + n2_l. */ - mp_limb_t n2_h = ~n1_h; - - /* Main loop. */ - while (n2_h) /* While N2 >= 2^BITS_PER_MP_LIMB. */ - { - /* N1 <-- N1 % N2. */ - if ((MP_LIMB_T_HIGHBIT >> leading_zero_bits & n2_h) == 0) - { - unsigned long int i; - count_leading_zeros (i, n2_h); - i -= leading_zero_bits, leading_zero_bits += i; - n2_h = n2_h<>(BITS_PER_MP_LIMB - i), n2_l <<= i; - do - { - if (n1_h > n2_h || (n1_h == n2_h && n1_l >= n2_l)) - n1_h -= n2_h + (n1_l < n2_l), n1_l -= n2_l; - n2_l = n2_l>>1 | n2_h<<(BITS_PER_MP_LIMB - 1), n2_h >>= 1; - i -= 1; - } - while (i); - } - if (n1_h > n2_h || (n1_h == n2_h && n1_l >= n2_l)) - n1_h -= n2_h + (n1_l < n2_l), n1_l -= n2_l; - - MP_LIMB_T_SWAP (n1_h, n2_h); - MP_LIMB_T_SWAP (n1_l, n2_l); - } - - return n2_l; -} - -mp_size_t -#if __STDC__ -mpn_gcd (mp_ptr gp, mp_ptr up, mp_size_t usize, mp_ptr vp, mp_size_t vsize) -#else -mpn_gcd (gp, up, usize, vp, vsize) - mp_ptr gp; - mp_ptr up; - mp_size_t usize; - mp_ptr vp; - mp_size_t vsize; -#endif -{ - mp_ptr orig_vp = vp; - mp_size_t orig_vsize = vsize; - int binary_gcd_ctr; /* Number of times binary gcd will execute. */ - TMP_DECL (marker); - - TMP_MARK (marker); - - /* Use accelerated algorithm if vsize is over GCD_ACCEL_THRESHOLD. - Two EXTRA limbs for U and V are required for kary reduction. */ - if (vsize >= GCD_ACCEL_THRESHOLD) - { - unsigned long int vbitsize, d; - mp_ptr orig_up = up; - mp_size_t orig_usize = usize; - mp_ptr anchor_up = (mp_ptr) TMP_ALLOC ((usize + 2) * BYTES_PER_MP_LIMB); - - MPN_COPY (anchor_up, orig_up, usize); - up = anchor_up; - - count_leading_zeros (d, up[usize-1]); - d = usize * BITS_PER_MP_LIMB - d; - count_leading_zeros (vbitsize, vp[vsize-1]); - vbitsize = vsize * BITS_PER_MP_LIMB - vbitsize; - d = d - vbitsize + 1; - - /* Use bmod reduction to quickly discover whether V divides U. */ - up[usize++] = 0; /* Insert leading zero. */ - mpn_bdivmod (up, up, usize, vp, vsize, d); - - /* Now skip U/V mod 2^d and any low zero limbs. */ - d /= BITS_PER_MP_LIMB, up += d, usize -= d; - while (usize != 0 && up[0] == 0) - up++, usize--; - - if (usize == 0) /* GCD == ORIG_V. */ - goto done; - - vp = (mp_ptr) TMP_ALLOC ((vsize + 2) * BYTES_PER_MP_LIMB); - MPN_COPY (vp, orig_vp, vsize); - - do /* Main loop. */ - { - /* mpn_com_n can't be used here because anchor_up and up may - partially overlap */ - if (up[usize-1] & MP_LIMB_T_HIGHBIT) /* U < 0; take twos' compl. */ - { - mp_size_t i; - anchor_up[0] = -up[0]; - for (i = 1; i < usize; i++) - anchor_up[i] = ~up[i]; - up = anchor_up; - } - - MPN_NORMALIZE_NOT_ZERO (up, usize); - - if ((up[0] & 1) == 0) /* Result even; remove twos. */ - { - unsigned int r; - count_trailing_zeros (r, up[0]); - mpn_rshift (anchor_up, up, usize, r); - usize -= (anchor_up[usize-1] == 0); - } - else if (anchor_up != up) - MPN_COPY_INCR (anchor_up, up, usize); - - MPN_PTR_SWAP (anchor_up,usize, vp,vsize); - up = anchor_up; - - if (vsize <= 2) /* Kary can't handle < 2 limbs and */ - break; /* isn't efficient for == 2 limbs. */ - - d = vbitsize; - count_leading_zeros (vbitsize, vp[vsize-1]); - vbitsize = vsize * BITS_PER_MP_LIMB - vbitsize; - d = d - vbitsize + 1; - - if (d > BMOD_THRESHOLD) /* Bmod reduction. */ - { - up[usize++] = 0; - mpn_bdivmod (up, up, usize, vp, vsize, d); - d /= BITS_PER_MP_LIMB, up += d, usize -= d; - } - else /* Kary reduction. */ - { - mp_limb_t bp[2], cp[2]; - - /* C <-- V/U mod 2^(2*BITS_PER_MP_LIMB). */ - { - mp_limb_t u_inv, hi, lo; - modlimb_invert (u_inv, up[0]); - cp[0] = vp[0] * u_inv; - umul_ppmm (hi, lo, cp[0], up[0]); - cp[1] = (vp[1] - hi - cp[0] * up[1]) * u_inv; - } - - /* U <-- find_a (C) * U. */ - up[usize] = mpn_mul_1 (up, up, usize, find_a (cp)); - usize++; - - /* B <-- A/C == U/V mod 2^(BITS_PER_MP_LIMB + 1). - bp[0] <-- U/V mod 2^BITS_PER_MP_LIMB and - bp[1] <-- ( (U - bp[0] * V)/2^BITS_PER_MP_LIMB ) / V mod 2 - - Like V/U above, but simplified because only the low bit of - bp[1] is wanted. */ - { - mp_limb_t v_inv, hi, lo; - modlimb_invert (v_inv, vp[0]); - bp[0] = up[0] * v_inv; - umul_ppmm (hi, lo, bp[0], vp[0]); - bp[1] = (up[1] + hi + (bp[0]&vp[1])) & 1; - } - - up[usize++] = 0; - if (bp[1]) /* B < 0: U <-- U + (-B) * V. */ - { - mp_limb_t c = mpn_addmul_1 (up, vp, vsize, -bp[0]); - mpn_add_1 (up + vsize, up + vsize, usize - vsize, c); - } - else /* B >= 0: U <-- U - B * V. */ - { - mp_limb_t b = mpn_submul_1 (up, vp, vsize, bp[0]); - mpn_sub_1 (up + vsize, up + vsize, usize - vsize, b); - } - - up += 2, usize -= 2; /* At least two low limbs are zero. */ - } - - /* Must remove low zero limbs before complementing. */ - while (usize != 0 && up[0] == 0) - up++, usize--; - } - while (usize); - - /* Compute GCD (ORIG_V, GCD (ORIG_U, V)). Binary will execute twice. */ - up = orig_up, usize = orig_usize; - binary_gcd_ctr = 2; - } - else - binary_gcd_ctr = 1; - - /* Finish up with the binary algorithm. Executes once or twice. */ - for ( ; binary_gcd_ctr--; up = orig_vp, usize = orig_vsize) - { - if (usize > 2) /* First make U close to V in size. */ - { - unsigned long int vbitsize, d; - count_leading_zeros (d, up[usize-1]); - d = usize * BITS_PER_MP_LIMB - d; - count_leading_zeros (vbitsize, vp[vsize-1]); - vbitsize = vsize * BITS_PER_MP_LIMB - vbitsize; - d = d - vbitsize - 1; - if (d != -(unsigned long int)1 && d > 2) - { - mpn_bdivmod (up, up, usize, vp, vsize, d); /* Result > 0. */ - d /= (unsigned long int)BITS_PER_MP_LIMB, up += d, usize -= d; - } - } - - /* Start binary GCD. */ - do - { - mp_size_t zeros; - - /* Make sure U is odd. */ - MPN_NORMALIZE (up, usize); - while (up[0] == 0) - up += 1, usize -= 1; - if ((up[0] & 1) == 0) - { - unsigned int r; - count_trailing_zeros (r, up[0]); - mpn_rshift (up, up, usize, r); - usize -= (up[usize-1] == 0); - } - - /* Keep usize >= vsize. */ - if (usize < vsize) - MPN_PTR_SWAP (up, usize, vp, vsize); - - if (usize <= 2) /* Double precision. */ - { - if (vsize == 1) - vp[0] = mpn_gcd_1 (up, usize, vp[0]); - else - vsize = gcd_2 (vp, up); - break; /* Binary GCD done. */ - } - - /* Count number of low zero limbs of U - V. */ - for (zeros = 0; up[zeros] == vp[zeros] && ++zeros != vsize; ) - continue; - - /* If U < V, swap U and V; in any case, subtract V from U. */ - if (zeros == vsize) /* Subtract done. */ - up += zeros, usize -= zeros; - else if (usize == vsize) - { - mp_size_t size = vsize; - do - size--; - while (up[size] == vp[size]); - if (up[size] < vp[size]) /* usize == vsize. */ - MP_PTR_SWAP (up, vp); - up += zeros, usize = size + 1 - zeros; - mpn_sub_n (up, up, vp + zeros, usize); - } - else - { - mp_size_t size = vsize - zeros; - up += zeros, usize -= zeros; - if (mpn_sub_n (up, up, vp + zeros, size)) - { - while (up[size] == 0) /* Propagate borrow. */ - up[size++] = -(mp_limb_t)1; - up[size] -= 1; - } - } - } - while (usize); /* End binary GCD. */ - } - -done: - if (vp != gp) - MPN_COPY (gp, vp, vsize); - TMP_FREE (marker); - return vsize; -} diff --git a/gmp/mpn/generic/gcd_1.c b/gmp/mpn/generic/gcd_1.c deleted file mode 100755 index 1832636..0000000 --- a/gmp/mpn/generic/gcd_1.c +++ /dev/null @@ -1,77 +0,0 @@ -/* mpn_gcd_1 -- - -Copyright (C) 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Does not work for U == 0 or V == 0. It would be tough to make it work for - V == 0 since gcd(x,0) = x, and U does not generally fit in an mp_limb_t. */ - -mp_limb_t -#if __STDC__ -mpn_gcd_1 (mp_srcptr up, mp_size_t size, mp_limb_t vlimb) -#else -mpn_gcd_1 (up, size, vlimb) - mp_srcptr up; - mp_size_t size; - mp_limb_t vlimb; -#endif -{ - mp_limb_t ulimb; - unsigned long int u_low_zero_bits, v_low_zero_bits; - - if (size > 1) - { - ulimb = mpn_mod_1 (up, size, vlimb); - if (ulimb == 0) - return vlimb; - } - else - ulimb = up[0]; - - /* Need to eliminate low zero bits. */ - count_trailing_zeros (u_low_zero_bits, ulimb); - ulimb >>= u_low_zero_bits; - - count_trailing_zeros (v_low_zero_bits, vlimb); - vlimb >>= v_low_zero_bits; - - while (ulimb != vlimb) - { - if (ulimb > vlimb) - { - ulimb -= vlimb; - do - ulimb >>= 1; - while ((ulimb & 1) == 0); - } - else /* vlimb > ulimb. */ - { - vlimb -= ulimb; - do - vlimb >>= 1; - while ((vlimb & 1) == 0); - } - } - - return ulimb << MIN (u_low_zero_bits, v_low_zero_bits); -} diff --git a/gmp/mpn/generic/gcdext.c b/gmp/mpn/generic/gcdext.c deleted file mode 100755 index fe22d77..0000000 --- a/gmp/mpn/generic/gcdext.c +++ /dev/null @@ -1,700 +0,0 @@ -/* mpn_gcdext -- Extended Greatest Common Divisor. - -Copyright (C) 1996, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 17 -#endif - -#ifndef EXTEND -#define EXTEND 1 -#endif - -#if STAT -int arr[BITS_PER_MP_LIMB]; -#endif - - -/* mpn_gcdext (GP, SP, SSIZE, UP, USIZE, VP, VSIZE) - - Compute the extended GCD of {UP,USIZE} and {VP,VSIZE} and store the - greatest common divisor at GP (unless it is 0), and the first cofactor at - SP. Write the size of the cofactor through the pointer SSIZE. Return the - size of the value at GP. Note that SP might be a negative number; this is - denoted by storing the negative of the size through SSIZE. - - {UP,USIZE} and {VP,VSIZE} are both clobbered. - - The space allocation for all four areas needs to be USIZE+1. - - Preconditions: 1) U >= V. - 2) V > 0. */ - -/* We use Lehmer's algorithm. The idea is to extract the most significant - bits of the operands, and compute the continued fraction for them. We then - apply the gathered cofactors to the full operands. - - Idea 1: After we have performed a full division, don't shift operands back, - but instead account for the extra factors-of-2 thus introduced. - Idea 2: Simple generalization to use divide-and-conquer would give us an - algorithm that runs faster than O(n^2). - Idea 3: The input numbers need less space as the computation progresses, - while the s0 and s1 variables need more space. To save memory, we - could make them share space, and have the latter variables grow - into the former. - Idea 4: We should not do double-limb arithmetic from the start. Instead, - do things in single-limb arithmetic until the quotients differ, - and then switch to double-limb arithmetic. */ - - -/* Division optimized for small quotients. If the quotient is more than one limb, - store 1 in *qh and return 0. */ -static mp_limb_t -#if __STDC__ -div2 (mp_limb_t *qh, mp_limb_t n1, mp_limb_t n0, mp_limb_t d1, mp_limb_t d0) -#else -div2 (qh, n1, n0, d1, d0) - mp_limb_t *qh; - mp_limb_t n1; - mp_limb_t n0; - mp_limb_t d1; - mp_limb_t d0; -#endif -{ - if (d1 == 0) - { - *qh = 1; - return 0; - } - - if ((mp_limb_signed_t) n1 < 0) - { - mp_limb_t q; - int cnt; - for (cnt = 1; (mp_limb_signed_t) d1 >= 0; cnt++) - { - d1 = (d1 << 1) | (d0 >> (BITS_PER_MP_LIMB - 1)); - d0 = d0 << 1; - } - - q = 0; - while (cnt) - { - q <<= 1; - if (n1 > d1 || (n1 == d1 && n0 >= d0)) - { - sub_ddmmss (n1, n0, n1, n0, d1, d0); - q |= 1; - } - d0 = (d1 << (BITS_PER_MP_LIMB - 1)) | (d0 >> 1); - d1 = d1 >> 1; - cnt--; - } - - *qh = 0; - return q; - } - else - { - mp_limb_t q; - int cnt; - for (cnt = 0; n1 > d1 || (n1 == d1 && n0 >= d0); cnt++) - { - d1 = (d1 << 1) | (d0 >> (BITS_PER_MP_LIMB - 1)); - d0 = d0 << 1; - } - - q = 0; - while (cnt) - { - d0 = (d1 << (BITS_PER_MP_LIMB - 1)) | (d0 >> 1); - d1 = d1 >> 1; - q <<= 1; - if (n1 > d1 || (n1 == d1 && n0 >= d0)) - { - sub_ddmmss (n1, n0, n1, n0, d1, d0); - q |= 1; - } - cnt--; - } - - *qh = 0; - return q; - } -} - -mp_size_t -#if EXTEND -#if __STDC__ -mpn_gcdext (mp_ptr gp, mp_ptr s0p, mp_size_t *s0size, - mp_ptr up, mp_size_t size, mp_ptr vp, mp_size_t vsize) -#else -mpn_gcdext (gp, s0p, s0size, up, size, vp, vsize) - mp_ptr gp; - mp_ptr s0p; - mp_size_t *s0size; - mp_ptr up; - mp_size_t size; - mp_ptr vp; - mp_size_t vsize; -#endif -#else -#if __STDC__ -mpn_gcd (mp_ptr gp, - mp_ptr up, mp_size_t size, mp_ptr vp, mp_size_t vsize) -#else -mpn_gcd (gp, up, size, vp, vsize) - mp_ptr gp; - mp_ptr up; - mp_size_t size; - mp_ptr vp; - mp_size_t vsize; -#endif -#endif -{ - mp_limb_t A, B, C, D; - int cnt; - mp_ptr tp, wp; -#if RECORD - mp_limb_t max = 0; -#endif -#if EXTEND - mp_ptr s1p; - mp_ptr orig_s0p = s0p; - mp_size_t ssize; - int sign = 1; -#endif - int use_double_flag; - TMP_DECL (mark); - - TMP_MARK (mark); - - use_double_flag = (size >= GCDEXT_THRESHOLD); - - tp = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - wp = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); -#if EXTEND - s1p = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB); - - MPN_ZERO (s0p, size); - MPN_ZERO (s1p, size); - - s0p[0] = 1; - s1p[0] = 0; - ssize = 1; -#endif - - if (size > vsize) - { - /* Normalize V (and shift up U the same amount). */ - count_leading_zeros (cnt, vp[vsize - 1]); - if (cnt != 0) - { - mp_limb_t cy; - mpn_lshift (vp, vp, vsize, cnt); - cy = mpn_lshift (up, up, size, cnt); - up[size] = cy; - size += cy != 0; - } - - mpn_divmod (up + vsize, up, size, vp, vsize); -#if EXTEND - /* This is really what it boils down to in this case... */ - s0p[0] = 0; - s1p[0] = 1; - sign = -sign; -#endif - size = vsize; - if (cnt != 0) - { - mpn_rshift (up, up, size, cnt); - mpn_rshift (vp, vp, size, cnt); - } - MP_PTR_SWAP (up, vp); - } - - for (;;) - { - mp_limb_t asign; - /* Figure out exact size of V. */ - vsize = size; - MPN_NORMALIZE (vp, vsize); - if (vsize <= 1) - break; - - if (use_double_flag) - { - mp_limb_t uh, vh, ul, vl; - /* Let UH,UL be the most significant limbs of U, and let VH,VL be - the corresponding bits from V. */ - uh = up[size - 1]; - vh = vp[size - 1]; - ul = up[size - 2]; - vl = vp[size - 2]; - count_leading_zeros (cnt, uh); - if (cnt != 0) - { - uh = (uh << cnt) | (ul >> (BITS_PER_MP_LIMB - cnt)); - vh = (vh << cnt) | (vl >> (BITS_PER_MP_LIMB - cnt)); - vl <<= cnt; - ul <<= cnt; - if (size >= 3) - { - ul |= (up[size - 3] >> (BITS_PER_MP_LIMB - cnt)); - vl |= (vp[size - 3] >> (BITS_PER_MP_LIMB - cnt)); - } - } - - A = 1; - B = 0; - C = 0; - D = 1; - - asign = 0; - for (;;) - { - mp_limb_t T; - mp_limb_t qh, q1, q2; - mp_limb_t nh, nl, dh, dl; - mp_limb_t t1, t0; - mp_limb_t Th, Tl; - - sub_ddmmss (dh, dl, vh, vl, 0, C); - if ((dl | dh) == 0) - break; - add_ssaaaa (nh, nl, uh, ul, 0, A); - q1 = div2 (&qh, nh, nl, dh, dl); - if (qh != 0) - break; /* could handle this */ - - add_ssaaaa (dh, dl, vh, vl, 0, D); - if ((dl | dh) == 0) - break; - sub_ddmmss (nh, nl, uh, ul, 0, B); - q2 = div2 (&qh, nh, nl, dh, dl); - if (qh != 0) - break; /* could handle this */ - - if (q1 != q2) - break; - - asign = ~asign; - - T = A + q1 * C; - A = C; - C = T; - T = B + q1 * D; - B = D; - D = T; - umul_ppmm (t1, t0, q1, vl); - t1 += q1 * vh; - sub_ddmmss (Th, Tl, uh, ul, t1, t0); - uh = vh, ul = vl; - vh = Th, vl = Tl; - - add_ssaaaa (dh, dl, vh, vl, 0, C); - sub_ddmmss (nh, nl, uh, ul, 0, A); - q1 = div2 (&qh, nh, nl, dh, dl); - if (qh != 0) - break; /* could handle this */ - - sub_ddmmss (dh, dl, vh, vl, 0, D); - if ((dl | dh) == 0) - break; - add_ssaaaa (nh, nl, uh, ul, 0, B); - q2 = div2 (&qh, nh, nl, dh, dl); - if (qh != 0) - break; /* could handle this */ - - if (q1 != q2) - break; - - asign = ~asign; - - T = A + q1 * C; - A = C; - C = T; - T = B + q1 * D; - B = D; - D = T; - umul_ppmm (t1, t0, q1, vl); - t1 += q1 * vh; - sub_ddmmss (Th, Tl, uh, ul, t1, t0); - uh = vh, ul = vl; - vh = Th, vl = Tl; - } -#if EXTEND - if (asign) - sign = -sign; -#endif - } - else /* Same, but using single-limb calculations. */ - { - mp_limb_t uh, vh; - /* Make UH be the most significant limb of U, and make VH be - corresponding bits from V. */ - uh = up[size - 1]; - vh = vp[size - 1]; - count_leading_zeros (cnt, uh); - if (cnt != 0) - { - uh = (uh << cnt) | (up[size - 2] >> (BITS_PER_MP_LIMB - cnt)); - vh = (vh << cnt) | (vp[size - 2] >> (BITS_PER_MP_LIMB - cnt)); - } - - A = 1; - B = 0; - C = 0; - D = 1; - - asign = 0; - for (;;) - { - mp_limb_t q, T; - if (vh - C == 0 || vh + D == 0) - break; - - q = (uh + A) / (vh - C); - if (q != (uh - B) / (vh + D)) - break; - - asign = ~asign; - - T = A + q * C; - A = C; - C = T; - T = B + q * D; - B = D; - D = T; - T = uh - q * vh; - uh = vh; - vh = T; - - if (vh - D == 0) - break; - - q = (uh - A) / (vh + C); - if (q != (uh + B) / (vh - D)) - break; - - asign = ~asign; - - T = A + q * C; - A = C; - C = T; - T = B + q * D; - B = D; - D = T; - T = uh - q * vh; - uh = vh; - vh = T; - } -#if EXTEND - if (asign) - sign = -sign; -#endif - } - -#if RECORD - max = MAX (A, max); max = MAX (B, max); - max = MAX (C, max); max = MAX (D, max); -#endif - - if (B == 0) - { - mp_limb_t qh; - mp_size_t i; - /* This is quite rare. I.e., optimize something else! */ - - /* Normalize V (and shift up U the same amount). */ - count_leading_zeros (cnt, vp[vsize - 1]); - if (cnt != 0) - { - mp_limb_t cy; - mpn_lshift (vp, vp, vsize, cnt); - cy = mpn_lshift (up, up, size, cnt); - up[size] = cy; - size += cy != 0; - } - - qh = mpn_divmod (up + vsize, up, size, vp, vsize); -#if EXTEND - MPN_COPY (tp, s0p, ssize); - { - mp_size_t qsize; - - qsize = size - vsize; /* size of stored quotient from division */ - if (ssize < qsize) - { - MPN_ZERO (tp + ssize, qsize - ssize); - MPN_ZERO (s1p + ssize, qsize); /* zero s1 too */ - for (i = 0; i < ssize; i++) - { - mp_limb_t cy; - cy = mpn_addmul_1 (tp + i, up + vsize, qsize, s1p[i]); - tp[qsize + i] = cy; - } - if (qh != 0) - { - mp_limb_t cy; - cy = mpn_add_n (tp + qsize, tp + qsize, s1p, ssize); - if (cy != 0) - abort (); - } - } - else - { - MPN_ZERO (s1p + ssize, qsize); /* zero s1 too */ - for (i = 0; i < qsize; i++) - { - mp_limb_t cy; - cy = mpn_addmul_1 (tp + i, s1p, ssize, up[vsize + i]); - tp[ssize + i] = cy; - } - if (qh != 0) - { - mp_limb_t cy; - cy = mpn_add_n (tp + qsize, tp + qsize, s1p, ssize); - if (cy != 0) - { - tp[qsize + ssize] = cy; - s1p[qsize + ssize] = 0; - ssize++; - } - } - } - ssize += qsize; - ssize -= tp[ssize - 1] == 0; - } - - sign = -sign; - MP_PTR_SWAP (s0p, s1p); - MP_PTR_SWAP (s1p, tp); -#endif - size = vsize; - if (cnt != 0) - { - mpn_rshift (up, up, size, cnt); - mpn_rshift (vp, vp, size, cnt); - } - MP_PTR_SWAP (up, vp); - } - else - { -#if EXTEND - mp_size_t tsize, wsize; -#endif - /* T = U*A + V*B - W = U*C + V*D - U = T - V = W */ - -#if STAT - { mp_limb_t x; x = A | B | C | D; count_leading_zeros (cnt, x); - arr[BITS_PER_MP_LIMB - cnt]++; } -#endif - if (A == 0) - { - /* B == 1 and C == 1 (D is arbitrary) */ - mp_limb_t cy; - MPN_COPY (tp, vp, size); - MPN_COPY (wp, up, size); - mpn_submul_1 (wp, vp, size, D); - MP_PTR_SWAP (tp, up); - MP_PTR_SWAP (wp, vp); -#if EXTEND - MPN_COPY (tp, s1p, ssize); - tsize = ssize; - tp[ssize] = 0; /* must zero since wp might spill below */ - MPN_COPY (wp, s0p, ssize); - cy = mpn_addmul_1 (wp, s1p, ssize, D); - wp[ssize] = cy; - wsize = ssize + (cy != 0); - MP_PTR_SWAP (tp, s0p); - MP_PTR_SWAP (wp, s1p); - ssize = MAX (wsize, tsize); -#endif - } - else - { - if (asign) - { - mp_limb_t cy; - mpn_mul_1 (tp, vp, size, B); - mpn_submul_1 (tp, up, size, A); - mpn_mul_1 (wp, up, size, C); - mpn_submul_1 (wp, vp, size, D); - MP_PTR_SWAP (tp, up); - MP_PTR_SWAP (wp, vp); -#if EXTEND - cy = mpn_mul_1 (tp, s1p, ssize, B); - cy += mpn_addmul_1 (tp, s0p, ssize, A); - tp[ssize] = cy; - tsize = ssize + (cy != 0); - cy = mpn_mul_1 (wp, s0p, ssize, C); - cy += mpn_addmul_1 (wp, s1p, ssize, D); - wp[ssize] = cy; - wsize = ssize + (cy != 0); - MP_PTR_SWAP (tp, s0p); - MP_PTR_SWAP (wp, s1p); - ssize = MAX (wsize, tsize); -#endif - } - else - { - mp_limb_t cy; - mpn_mul_1 (tp, up, size, A); - mpn_submul_1 (tp, vp, size, B); - mpn_mul_1 (wp, vp, size, D); - mpn_submul_1 (wp, up, size, C); - MP_PTR_SWAP (tp, up); - MP_PTR_SWAP (wp, vp); -#if EXTEND - cy = mpn_mul_1 (tp, s0p, ssize, A); - cy += mpn_addmul_1 (tp, s1p, ssize, B); - tp[ssize] = cy; - tsize = ssize + (cy != 0); - cy = mpn_mul_1 (wp, s1p, ssize, D); - cy += mpn_addmul_1 (wp, s0p, ssize, C); - wp[ssize] = cy; - wsize = ssize + (cy != 0); - MP_PTR_SWAP (tp, s0p); - MP_PTR_SWAP (wp, s1p); - ssize = MAX (wsize, tsize); -#endif - } - } - - size -= up[size - 1] == 0; - } - } - -#if RECORD - printf ("max: %lx\n", max); -#endif - -#if STAT - {int i; for (i = 0; i < BITS_PER_MP_LIMB; i++) printf ("%d:%d\n", i, arr[i]);} -#endif - - if (vsize == 0) - { - if (gp != up && gp != 0) - MPN_COPY (gp, up, size); -#if EXTEND - MPN_NORMALIZE (s0p, ssize); - if (orig_s0p != s0p) - MPN_COPY (orig_s0p, s0p, ssize); - *s0size = sign >= 0 ? ssize : -ssize; -#endif - TMP_FREE (mark); - return size; - } - else - { - mp_limb_t vl, ul, t; -#if EXTEND - mp_size_t qsize, i; -#endif - vl = vp[0]; -#if EXTEND - t = mpn_divmod_1 (wp, up, size, vl); - - MPN_COPY (tp, s0p, ssize); - - qsize = size - (wp[size - 1] == 0); /* size of quotient from division */ - if (ssize < qsize) - { - MPN_ZERO (tp + ssize, qsize - ssize); - MPN_ZERO (s1p + ssize, qsize); /* zero s1 too */ - for (i = 0; i < ssize; i++) - { - mp_limb_t cy; - cy = mpn_addmul_1 (tp + i, wp, qsize, s1p[i]); - tp[qsize + i] = cy; - } - } - else - { - MPN_ZERO (s1p + ssize, qsize); /* zero s1 too */ - for (i = 0; i < qsize; i++) - { - mp_limb_t cy; - cy = mpn_addmul_1 (tp + i, s1p, ssize, wp[i]); - tp[ssize + i] = cy; - } - } - ssize += qsize; - ssize -= tp[ssize - 1] == 0; - - sign = -sign; - MP_PTR_SWAP (s0p, s1p); - MP_PTR_SWAP (s1p, tp); -#else - t = mpn_mod_1 (up, size, vl); -#endif - ul = vl; - vl = t; - while (vl != 0) - { - mp_limb_t t; -#if EXTEND - mp_limb_t q; - q = ul / vl; - t = ul - q * vl; - - MPN_COPY (tp, s0p, ssize); - - MPN_ZERO (s1p + ssize, 1); /* zero s1 too */ - - { - mp_limb_t cy; - cy = mpn_addmul_1 (tp, s1p, ssize, q); - tp[ssize] = cy; - } - - ssize += 1; - ssize -= tp[ssize - 1] == 0; - - sign = -sign; - MP_PTR_SWAP (s0p, s1p); - MP_PTR_SWAP (s1p, tp); -#else - t = ul % vl; -#endif - ul = vl; - vl = t; - } - if (gp != 0) - gp[0] = ul; -#if EXTEND - MPN_NORMALIZE (s0p, ssize); - if (orig_s0p != s0p) - MPN_COPY (orig_s0p, s0p, ssize); - *s0size = sign >= 0 ? ssize : -ssize; -#endif - TMP_FREE (mark); - return 1; - } -} diff --git a/gmp/mpn/generic/get_str.c b/gmp/mpn/generic/get_str.c deleted file mode 100755 index a713b61..0000000 --- a/gmp/mpn/generic/get_str.c +++ /dev/null @@ -1,216 +0,0 @@ -/* mpn_get_str -- Convert a MSIZE long limb vector pointed to by MPTR - to a printable string in STR in base BASE. - -Copyright (C) 1991, 1992, 1993, 1994, 1996, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Convert the limb vector pointed to by MPTR and MSIZE long to a - char array, using base BASE for the result array. Store the - result in the character array STR. STR must point to an array with - space for the largest possible number represented by a MSIZE long - limb vector + 1 extra character. - - The result is NOT in Ascii, to convert it to printable format, add - '0' or 'A' depending on the base and range. - - Return the number of digits in the result string. - This may include some leading zeros. - - The limb vector pointed to by MPTR is clobbered. */ - -size_t -#if __STDC__ -mpn_get_str (unsigned char *str, int base, mp_ptr mptr, mp_size_t msize) -#else -mpn_get_str (str, base, mptr, msize) - unsigned char *str; - int base; - mp_ptr mptr; - mp_size_t msize; -#endif -{ - mp_limb_t big_base; -#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME - int normalization_steps; -#endif -#if UDIV_TIME > 2 * UMUL_TIME - mp_limb_t big_base_inverted; -#endif - unsigned int dig_per_u; - mp_size_t out_len; - register unsigned char *s; - - big_base = __mp_bases[base].big_base; - - s = str; - - /* Special case zero, as the code below doesn't handle it. */ - if (msize == 0) - { - s[0] = 0; - return 1; - } - - if ((base & (base - 1)) == 0) - { - /* The base is a power of 2. Make conversion from most - significant side. */ - mp_limb_t n1, n0; - register int bits_per_digit = big_base; - register int x; - register int bit_pos; - register int i; - - n1 = mptr[msize - 1]; - count_leading_zeros (x, n1); - - /* BIT_POS should be R when input ends in least sign. nibble, - R + bits_per_digit * n when input ends in n:th least significant - nibble. */ - - { - int bits; - - bits = BITS_PER_MP_LIMB * msize - x; - x = bits % bits_per_digit; - if (x != 0) - bits += bits_per_digit - x; - bit_pos = bits - (msize - 1) * BITS_PER_MP_LIMB; - } - - /* Fast loop for bit output. */ - i = msize - 1; - for (;;) - { - bit_pos -= bits_per_digit; - while (bit_pos >= 0) - { - *s++ = (n1 >> bit_pos) & ((1 << bits_per_digit) - 1); - bit_pos -= bits_per_digit; - } - i--; - if (i < 0) - break; - n0 = (n1 << -bit_pos) & ((1 << bits_per_digit) - 1); - n1 = mptr[i]; - bit_pos += BITS_PER_MP_LIMB; - *s++ = n0 | (n1 >> bit_pos); - } - - *s = 0; - - return s - str; - } - else - { - /* General case. The base is not a power of 2. Make conversion - from least significant end. */ - - /* If udiv_qrnnd only handles divisors with the most significant bit - set, prepare BIG_BASE for being a divisor by shifting it to the - left exactly enough to set the most significant bit. */ -#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME - count_leading_zeros (normalization_steps, big_base); - big_base <<= normalization_steps; -#if UDIV_TIME > 2 * UMUL_TIME - /* Get the fixed-point approximation to 1/(BIG_BASE << NORMALIZATION_STEPS). */ - big_base_inverted = __mp_bases[base].big_base_inverted; -#endif -#endif - - dig_per_u = __mp_bases[base].chars_per_limb; - out_len = ((size_t) msize * BITS_PER_MP_LIMB - * __mp_bases[base].chars_per_bit_exactly) + 1; - s += out_len; - - while (msize != 0) - { - int i; - mp_limb_t n0, n1; - -#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME - /* If we shifted BIG_BASE above, shift the dividend too, to get - the right quotient. We need to do this every loop, - since the intermediate quotients are OK, but the quotient from - one turn in the loop is going to be the dividend in the - next turn, and the dividend needs to be up-shifted. */ - if (normalization_steps != 0) - { - n0 = mpn_lshift (mptr, mptr, msize, normalization_steps); - - /* If the shifting gave a carry out limb, store it and - increase the length. */ - if (n0 != 0) - { - mptr[msize] = n0; - msize++; - } - } -#endif - - /* Divide the number at TP with BIG_BASE to get a quotient and a - remainder. The remainder is our new digit in base BIG_BASE. */ - i = msize - 1; - n1 = mptr[i]; - - if (n1 >= big_base) - n1 = 0; - else - { - msize--; - i--; - } - - for (; i >= 0; i--) - { - n0 = mptr[i]; -#if UDIV_TIME > 2 * UMUL_TIME - udiv_qrnnd_preinv (mptr[i], n1, n1, n0, big_base, big_base_inverted); -#else - udiv_qrnnd (mptr[i], n1, n1, n0, big_base); -#endif - } - -#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME - /* If we shifted above (at previous UDIV_NEEDS_NORMALIZATION tests) - the remainder will be up-shifted here. Compensate. */ - n1 >>= normalization_steps; -#endif - - /* Convert N1 from BIG_BASE to a string of digits in BASE - using single precision operations. */ - for (i = dig_per_u - 1; i >= 0; i--) - { - *--s = n1 % base; - n1 /= base; - if (n1 == 0 && msize == 0) - break; - } - } - - while (s != str) - *--s = 0; - return out_len; - } -} diff --git a/gmp/mpn/generic/gmp-mparam.h b/gmp/mpn/generic/gmp-mparam.h deleted file mode 100755 index 14bcaec..0000000 --- a/gmp/mpn/generic/gmp-mparam.h +++ /dev/null @@ -1,27 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 diff --git a/gmp/mpn/generic/hamdist.c b/gmp/mpn/generic/hamdist.c deleted file mode 100755 index 35c10e8..0000000 --- a/gmp/mpn/generic/hamdist.c +++ /dev/null @@ -1,94 +0,0 @@ -/* mpn_hamdist -- - -Copyright (C) 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#if defined __GNUC__ -/* No processor claiming to be SPARC v9 compliant seem to - implement the POPC instruction. Disable pattern for now. */ -#if 0 && defined __sparc_v9__ && BITS_PER_MP_LIMB == 64 -#define popc_limb(a) \ - ({ \ - DItype __res; \ - asm ("popc %1,%0" : "=r" (__res) : "rI" (a)); \ - __res; \ - }) -#endif -#endif - -#ifndef popc_limb - -/* Cool population count of a mp_limb_t. - You have to figure out how this works, I won't tell you! */ - -static inline unsigned int -#if __STDC__ -popc_limb (mp_limb_t x) -#else -popc_limb (x) - mp_limb_t x; -#endif -{ -#if BITS_PER_MP_LIMB == 64 - /* We have to go into some trouble to define these constants. - (For mp_limb_t being `long long'.) */ - mp_limb_t cnst; - cnst = 0xaaaaaaaaL | ((mp_limb_t) 0xaaaaaaaaL << BITS_PER_MP_LIMB/2); - x -= (x & cnst) >> 1; - cnst = 0x33333333L | ((mp_limb_t) 0x33333333L << BITS_PER_MP_LIMB/2); - x = ((x & ~cnst) >> 2) + (x & cnst); - cnst = 0x0f0f0f0fL | ((mp_limb_t) 0x0f0f0f0fL << BITS_PER_MP_LIMB/2); - x = ((x >> 4) + x) & cnst; - x = ((x >> 8) + x); - x = ((x >> 16) + x); - x = ((x >> 32) + x) & 0xff; -#endif -#if BITS_PER_MP_LIMB == 32 - x -= (x & 0xaaaaaaaa) >> 1; - x = ((x >> 2) & 0x33333333L) + (x & 0x33333333L); - x = ((x >> 4) + x) & 0x0f0f0f0fL; - x = ((x >> 8) + x); - x = ((x >> 16) + x) & 0xff; -#endif - return x; -} -#endif - -unsigned long int -#if __STDC__ -mpn_hamdist (mp_srcptr up, mp_srcptr vp, mp_size_t size) -#else -mpn_hamdist (up, vp, size) - register mp_srcptr up; - register mp_srcptr vp; - register mp_size_t size; -#endif -{ - unsigned long int hamdist; - mp_size_t i; - - hamdist = 0; - for (i = 0; i < size; i++) - hamdist += popc_limb (up[i] ^ vp[i]); - - return hamdist; -} diff --git a/gmp/mpn/generic/inlines.c b/gmp/mpn/generic/inlines.c deleted file mode 100755 index 9487e58..0000000 --- a/gmp/mpn/generic/inlines.c +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#define _FORCE_INLINES -#define _EXTERN_INLINE /* empty */ -#include "gmp.h" diff --git a/gmp/mpn/generic/jacbase.c b/gmp/mpn/generic/jacbase.c deleted file mode 100755 index dd437f1..0000000 --- a/gmp/mpn/generic/jacbase.c +++ /dev/null @@ -1,136 +0,0 @@ -/* mpn_jacobi_base -- limb/limb Jacobi symbol with restricted arguments. - - THIS INTERFACE IS PRELIMINARY AND MIGHT DISAPPEAR OR BE SUBJECT TO - INCOMPATIBLE CHANGES IN A FUTURE RELEASE OF GMP. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -#if COUNT_TRAILING_ZEROS_TIME <= 7 -/* If count_trailing_zeros is fast, use it. - K7 at 7 cycles and P6 at 2 are good here. K6 at 12-27 and P5 at 18-42 - are not. The default 15 in longlong.h is meant to mean not good here. */ - -#define PROCESS_TWOS_ANY \ - { \ - mp_limb_t twos; \ - count_trailing_zeros (twos, a); \ - result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, b); \ - a >>= twos; \ - } - -#define PROCESS_TWOS_EVEN PROCESS_TWOS_ANY - -#else -/* Use a loop instead. With "a" uniformly distributed there will usually be - only a few trailing zeros. - - Unfortunately the branch for the while loop here will be on a 50/50 - chance of a 1 or 0, which is bad for branch prediction. */ - -#define PROCESS_TWOS_EVEN \ - { \ - int two; \ - two = JACOBI_TWO_U_BIT1 (b); \ - do \ - { \ - a >>= 1; \ - result_bit1 ^= two; \ - ASSERT (a != 0); \ - } \ - while ((a & 1) == 0); \ - } - -#define PROCESS_TWOS_ANY \ - if ((a & 1) == 0) \ - PROCESS_TWOS_EVEN; - -#endif - - -/* Calculate the value of the Jacobi symbol (a/b) of two mp_limb_t's, but - with a restricted range of inputs accepted, namely b>1, b odd, and a<=b. - - The initial result_bit1 is taken as a parameter for the convenience of - mpz_kronecker_zi_ui() et al. The sign changes both here and in those - routines accumulate nicely in bit 1, see the JACOBI macros. - - The return value here is the normal +1, 0, or -1. Note that +1 and -1 - have bit 1 in the "BIT1" sense, which could be useful if the caller is - accumulating it into some extended calculation. - - Duplicating the loop body to avoid the MP_LIMB_T_SWAP(a,b) would be - possible, but a couple of tests suggest it's not a significant speedup, - and may even be a slowdown, so what's here is good enough for now. - - Future: The code doesn't demand a<=b actually, so maybe this could be - relaxed. All the places this is used currently call with a<=b though. */ - -int -#if __STDC__ -mpn_jacobi_base (mp_limb_t a, mp_limb_t b, int result_bit1) -#else -mpn_jacobi_base (a, b, result_bit1) - mp_limb_t a; - mp_limb_t b; - int result_bit1; -#endif -{ - ASSERT (b & 1); /* b odd */ - ASSERT (b != 1); - ASSERT (a <= b); - - if (a == 0) - return 0; - - PROCESS_TWOS_ANY; - if (a == 1) - goto done; - - for (;;) - { - result_bit1 ^= JACOBI_RECIP_UU_BIT1 (a, b); - MP_LIMB_T_SWAP (a, b); - - do - { - /* working on (a/b), a,b odd, a>=b */ - ASSERT (a & 1); - ASSERT (b & 1); - ASSERT (a >= b); - - if ((a -= b) == 0) - return 0; - - PROCESS_TWOS_EVEN; - if (a == 1) - goto done; - } - while (a >= b); - } - - done: - return JACOBI_BIT1_TO_PN (result_bit1); -} diff --git a/gmp/mpn/generic/lshift.c b/gmp/mpn/generic/lshift.c deleted file mode 100755 index 0b58389..0000000 --- a/gmp/mpn/generic/lshift.c +++ /dev/null @@ -1,87 +0,0 @@ -/* mpn_lshift -- Shift left low level. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left - and store the USIZE least significant digits of the result at WP. - Return the bits shifted out from the most significant digit. - - Argument constraints: - 1. 0 < CNT < BITS_PER_MP_LIMB - 2. If the result is to be written over the input, WP must be >= UP. -*/ - -mp_limb_t -#if __STDC__ -mpn_lshift (register mp_ptr wp, - register mp_srcptr up, mp_size_t usize, - register unsigned int cnt) -#else -mpn_lshift (wp, up, usize, cnt) - register mp_ptr wp; - register mp_srcptr up; - mp_size_t usize; - register unsigned int cnt; -#endif -{ - register mp_limb_t high_limb, low_limb; - register unsigned sh_1, sh_2; - register mp_size_t i; - mp_limb_t retval; - -#ifdef DEBUG - if (usize == 0 || cnt == 0) - abort (); -#endif - - sh_1 = cnt; -#if 0 - if (sh_1 == 0) - { - if (wp != up) - { - /* Copy from high end to low end, to allow specified input/output - overlapping. */ - for (i = usize - 1; i >= 0; i--) - wp[i] = up[i]; - } - return 0; - } -#endif - - wp += 1; - sh_2 = BITS_PER_MP_LIMB - sh_1; - i = usize - 1; - low_limb = up[i]; - retval = low_limb >> sh_2; - high_limb = low_limb; - while (--i >= 0) - { - low_limb = up[i]; - wp[i] = (high_limb << sh_1) | (low_limb >> sh_2); - high_limb = low_limb; - } - wp[i] = high_limb << sh_1; - - return retval; -} diff --git a/gmp/mpn/generic/mod_1.c b/gmp/mpn/generic/mod_1.c deleted file mode 100755 index 168ec9d..0000000 --- a/gmp/mpn/generic/mod_1.c +++ /dev/null @@ -1,175 +0,0 @@ -/* mpn_mod_1(dividend_ptr, dividend_size, divisor_limb) -- - Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by DIVISOR_LIMB. - Return the single-limb remainder. - There are no constraints on the value of the divisor. - -Copyright (C) 1991, 1993, 1994, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#ifndef UMUL_TIME -#define UMUL_TIME 1 -#endif - -#ifndef UDIV_TIME -#define UDIV_TIME UMUL_TIME -#endif - -mp_limb_t -#if __STDC__ -mpn_mod_1 (mp_srcptr dividend_ptr, mp_size_t dividend_size, - mp_limb_t divisor_limb) -#else -mpn_mod_1 (dividend_ptr, dividend_size, divisor_limb) - mp_srcptr dividend_ptr; - mp_size_t dividend_size; - mp_limb_t divisor_limb; -#endif -{ - mp_size_t i; - mp_limb_t n1, n0, r; - int dummy; - - /* Botch: Should this be handled at all? Rely on callers? */ - if (dividend_size == 0) - return 0; - - /* If multiplication is much faster than division, and the - dividend is large, pre-invert the divisor, and use - only multiplications in the inner loop. */ - - /* This test should be read: - Does it ever help to use udiv_qrnnd_preinv? - && Does what we save compensate for the inversion overhead? */ - if (UDIV_TIME > (2 * UMUL_TIME + 6) - && (UDIV_TIME - (2 * UMUL_TIME + 6)) * dividend_size > UDIV_TIME) - { - int normalization_steps; - - count_leading_zeros (normalization_steps, divisor_limb); - if (normalization_steps != 0) - { - mp_limb_t divisor_limb_inverted; - - divisor_limb <<= normalization_steps; - invert_limb (divisor_limb_inverted, divisor_limb); - - n1 = dividend_ptr[dividend_size - 1]; - r = n1 >> (BITS_PER_MP_LIMB - normalization_steps); - - /* Possible optimization: - if (r == 0 - && divisor_limb > ((n1 << normalization_steps) - | (dividend_ptr[dividend_size - 2] >> ...))) - ...one division less... */ - - for (i = dividend_size - 2; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd_preinv (dummy, r, r, - ((n1 << normalization_steps) - | (n0 >> (BITS_PER_MP_LIMB - normalization_steps))), - divisor_limb, divisor_limb_inverted); - n1 = n0; - } - udiv_qrnnd_preinv (dummy, r, r, - n1 << normalization_steps, - divisor_limb, divisor_limb_inverted); - return r >> normalization_steps; - } - else - { - mp_limb_t divisor_limb_inverted; - - invert_limb (divisor_limb_inverted, divisor_limb); - - i = dividend_size - 1; - r = dividend_ptr[i]; - - if (r >= divisor_limb) - r = 0; - else - i--; - - for (; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd_preinv (dummy, r, r, - n0, divisor_limb, divisor_limb_inverted); - } - return r; - } - } - else - { - if (UDIV_NEEDS_NORMALIZATION) - { - int normalization_steps; - - count_leading_zeros (normalization_steps, divisor_limb); - if (normalization_steps != 0) - { - divisor_limb <<= normalization_steps; - - n1 = dividend_ptr[dividend_size - 1]; - r = n1 >> (BITS_PER_MP_LIMB - normalization_steps); - - /* Possible optimization: - if (r == 0 - && divisor_limb > ((n1 << normalization_steps) - | (dividend_ptr[dividend_size - 2] >> ...))) - ...one division less... */ - - for (i = dividend_size - 2; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd (dummy, r, r, - ((n1 << normalization_steps) - | (n0 >> (BITS_PER_MP_LIMB - normalization_steps))), - divisor_limb); - n1 = n0; - } - udiv_qrnnd (dummy, r, r, - n1 << normalization_steps, - divisor_limb); - return r >> normalization_steps; - } - } - /* No normalization needed, either because udiv_qrnnd doesn't require - it, or because DIVISOR_LIMB is already normalized. */ - - i = dividend_size - 1; - r = dividend_ptr[i]; - - if (r >= divisor_limb) - r = 0; - else - i--; - - for (; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd (dummy, r, r, n0, divisor_limb); - } - return r; - } -} diff --git a/gmp/mpn/generic/mod_1_rs.c b/gmp/mpn/generic/mod_1_rs.c deleted file mode 100755 index 62aaa94..0000000 --- a/gmp/mpn/generic/mod_1_rs.c +++ /dev/null @@ -1,111 +0,0 @@ -/* mpn_mod_1_rshift -- mpn remainder under hypothetical right shift. - - THE FUNCTION IN THIS FILE IS FOR INTERNAL USE AND HAS A MUTABLE - INTERFACE. IT IS ONLY SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES. - IT'S ALMOST GUARANTEED THAT IT'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP - RELEASE. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* When testing on a CPU with UDIV_NEEDS_NORMALIZATION equal to 0, it can be - changed to 1 temporarily to test the code under that case too. */ -#if 0 -#undef UDIV_NEEDS_NORMALIZATION -#define UDIV_NEEDS_NORMALIZATION 1 -#endif - - -/* Calculate the remainder "(ptr,size >> shift) % divisor". Note ptr,size - is unchanged, the shift is only for its effect on the remainder. - The shift doesn't even need to be considered until the last limb. - - This function has the normal size!=0 restriction, unlike the basic - mpn_mod_1. */ - -mp_limb_t -#if __STDC__ -mpn_mod_1_rshift (mp_srcptr ptr, mp_size_t size, unsigned shift, - mp_limb_t divisor) -#else -mpn_mod_1_rshift (ptr, size, shift, divisor) - mp_srcptr ptr; - mp_size_t size; - unsigned shift; - mp_limb_t divisor; -#endif -{ - mp_limb_t quot, rem; - - ASSERT (shift >= 1); - ASSERT (shift < BITS_PER_MP_LIMB); - ASSERT (size >= 1); - - if (size == 1) - return (ptr[0] >> shift) % divisor; - -#if UDIV_NEEDS_NORMALIZATION - { - int norm; - int delta; - - count_leading_zeros (norm, divisor); - divisor <<= norm; - - delta = shift - norm; - if (delta == 0) - return mpn_mod_1 (ptr, size, divisor) >> norm; - - if (delta > 0) - { - rem = mpn_mod_1 (ptr+1, size-1, divisor); - udiv_qrnnd (quot, rem, - rem >> delta, - (rem << (BITS_PER_MP_LIMB-delta)) | (ptr[0] >> delta), - divisor); - return rem >> norm; - } - else - { - rem = mpn_mod_1 (ptr, size, divisor); - udiv_qrnnd (quot, rem, - rem >> (BITS_PER_MP_LIMB+delta), - rem << -delta, - divisor); - return rem >> norm; - } - } - -#else /* !UDIV_NEEDS_NORMALIZATION */ - - rem = mpn_mod_1 (ptr+1, size-1, divisor); - udiv_qrnnd (quot, rem, - rem >> shift, - (rem << (BITS_PER_MP_LIMB-shift)) | (ptr[0] >> shift), - divisor); - return rem; - -#endif -} diff --git a/gmp/mpn/generic/mul.c b/gmp/mpn/generic/mul.c deleted file mode 100755 index cecfa19..0000000 --- a/gmp/mpn/generic/mul.c +++ /dev/null @@ -1,190 +0,0 @@ -/* mpn_mul -- Multiply two natural numbers. - - THE HELPER FUNCTIONS IN THIS FILE (meaning everything except mpn_mul) - ARE INTERNAL FUNCTIONS WITH MUTABLE INTERFACES. IT IS ONLY SAFE TO REACH - THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED - THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. - - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* Multiply the natural numbers u (pointed to by UP, with UN limbs) and v - (pointed to by VP, with VN limbs), and store the result at PRODP. The - result is UN + VN limbs. Return the most significant limb of the result. - - NOTE: The space pointed to by PRODP is overwritten before finished with U - and V, so overlap is an error. - - Argument constraints: - 1. UN >= VN. - 2. PRODP != UP and PRODP != VP, i.e. the destination must be distinct from - the multiplier and the multiplicand. */ - -void -#if __STDC__ -mpn_sqr_n (mp_ptr prodp, - mp_srcptr up, mp_size_t un) -#else -mpn_sqr_n (prodp, up, un) - mp_ptr prodp; - mp_srcptr up; - mp_size_t un; -#endif -{ - if (un < KARATSUBA_SQR_THRESHOLD) - { /* plain schoolbook multiplication */ - if (un == 0) - return; - mpn_sqr_basecase (prodp, up, un); - } - else if (un < TOOM3_SQR_THRESHOLD) - { /* karatsuba multiplication */ - mp_ptr tspace; - TMP_DECL (marker); - TMP_MARK (marker); - tspace = (mp_ptr) TMP_ALLOC (2 * (un + BITS_PER_MP_LIMB) * BYTES_PER_MP_LIMB); - mpn_kara_sqr_n (prodp, up, un, tspace); - TMP_FREE (marker); - } -#if WANT_FFT || TUNE_PROGRAM_BUILD - else if (un < FFT_SQR_THRESHOLD) -#else - else -#endif - { /* toom3 multiplication */ - mp_ptr tspace; - TMP_DECL (marker); - TMP_MARK (marker); - tspace = (mp_ptr) TMP_ALLOC (2 * (un + BITS_PER_MP_LIMB) * BYTES_PER_MP_LIMB); - mpn_toom3_sqr_n (prodp, up, un, tspace); - TMP_FREE (marker); - } -#if WANT_FFT || TUNE_PROGRAM_BUILD - else - { - /* schoenhage multiplication */ - mpn_mul_fft_full (prodp, up, un, up, un); - } -#endif -} - -mp_limb_t -#if __STDC__ -mpn_mul (mp_ptr prodp, - mp_srcptr up, mp_size_t un, - mp_srcptr vp, mp_size_t vn) -#else -mpn_mul (prodp, up, un, vp, vn) - mp_ptr prodp; - mp_srcptr up; - mp_size_t un; - mp_srcptr vp; - mp_size_t vn; -#endif -{ - mp_size_t l; - mp_limb_t c; - - if (up == vp && un == vn) - { - mpn_sqr_n (prodp, up, un); - return prodp[2 * un - 1]; - } - - if (vn < KARATSUBA_MUL_THRESHOLD) - { /* long multiplication */ - mpn_mul_basecase (prodp, up, un, vp, vn); - return prodp[un + vn - 1]; - } - - mpn_mul_n (prodp, up, vp, vn); - if (un != vn) - { mp_limb_t t; - mp_ptr ws; - TMP_DECL (marker); - TMP_MARK (marker); - - prodp += vn; - l = vn; - up += vn; - un -= vn; - - if (un < vn) - { - /* Swap u's and v's. */ - MPN_SRCPTR_SWAP (up,un, vp,vn); - } - - ws = (mp_ptr) TMP_ALLOC (((vn >= KARATSUBA_MUL_THRESHOLD ? vn : un) + vn) - * BYTES_PER_MP_LIMB); - - t = 0; - while (vn >= KARATSUBA_MUL_THRESHOLD) - { - mpn_mul_n (ws, up, vp, vn); - if (l <= 2*vn) - { - t += mpn_add_n (prodp, prodp, ws, l); - if (l != 2*vn) - { - t = mpn_add_1 (prodp + l, ws + l, 2*vn - l, t); - l = 2*vn; - } - } - else - { - c = mpn_add_n (prodp, prodp, ws, 2*vn); - t += mpn_add_1 (prodp + 2*vn, prodp + 2*vn, l - 2*vn, c); - } - prodp += vn; - l -= vn; - up += vn; - un -= vn; - if (un < vn) - { - /* Swap u's and v's. */ - MPN_SRCPTR_SWAP (up,un, vp,vn); - } - } - - if (vn) - { - mpn_mul_basecase (ws, up, un, vp, vn); - if (l <= un + vn) - { - t += mpn_add_n (prodp, prodp, ws, l); - if (l != un + vn) - t = mpn_add_1 (prodp + l, ws + l, un + vn - l, t); - } - else - { - c = mpn_add_n (prodp, prodp, ws, un + vn); - t += mpn_add_1 (prodp + un + vn, prodp + un + vn, l - un - vn, c); - } - } - - TMP_FREE (marker); - } - return prodp[un + vn - 1]; -} diff --git a/gmp/mpn/generic/mul_1.c b/gmp/mpn/generic/mul_1.c deleted file mode 100755 index 1c36b5f..0000000 --- a/gmp/mpn/generic/mul_1.c +++ /dev/null @@ -1,59 +0,0 @@ -/* mpn_mul_1 -- Multiply a limb vector with a single limb and - store the product in a second limb vector. - -Copyright (C) 1991, 1992, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -mp_limb_t -mpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - mp_size_t s1_size; - register mp_limb_t s2_limb; -{ - register mp_limb_t cy_limb; - register mp_size_t j; - register mp_limb_t prod_high, prod_low; - - /* The loop counter and index J goes from -S1_SIZE to -1. This way - the loop becomes faster. */ - j = -s1_size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - res_ptr -= j; - - cy_limb = 0; - do - { - umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb); - - prod_low += cy_limb; - cy_limb = (prod_low < cy_limb) + prod_high; - - res_ptr[j] = prod_low; - } - while (++j != 0); - - return cy_limb; -} diff --git a/gmp/mpn/generic/mul_basecase.c b/gmp/mpn/generic/mul_basecase.c deleted file mode 100755 index 00c06aa..0000000 --- a/gmp/mpn/generic/mul_basecase.c +++ /dev/null @@ -1,87 +0,0 @@ -/* mpn_mul_basecase -- Internal routine to multiply two natural numbers - of length m and n. - - THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS ONLY - SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES. - - -Copyright (C) 1991, 1992, 1993, 1994, 1996, 1997, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* Handle simple cases with traditional multiplication. - - This is the most critical code of multiplication. All multiplies rely on - this, both small and huge. Small ones arrive here immediately, huge ones - arrive here as this is the base case for Karatsuba's recursive algorithm. */ - -void -#if __STDC__ -mpn_mul_basecase (mp_ptr prodp, - mp_srcptr up, mp_size_t usize, - mp_srcptr vp, mp_size_t vsize) -#else -mpn_mul_basecase (prodp, up, usize, vp, vsize) - mp_ptr prodp; - mp_srcptr up; - mp_size_t usize; - mp_srcptr vp; - mp_size_t vsize; -#endif -{ - /* We first multiply by the low order one or two limbs, as the result can - be stored, not added, to PROD. We also avoid a loop for zeroing this - way. */ -#if HAVE_NATIVE_mpn_mul_2 - if (vsize >= 2) - { - prodp[usize + 1] = mpn_mul_2 (prodp, up, usize, vp[0], vp[1]); - prodp += 2, vp += 2, vsize -= 2; - } - else - { - prodp[usize] = mpn_mul_1 (prodp, up, usize, vp[0]); - return; - } -#else - prodp[usize] = mpn_mul_1 (prodp, up, usize, vp[0]); - prodp += 1, vp += 1, vsize -= 1; -#endif - -#if HAVE_NATIVE_mpn_addmul_2 - while (vsize >= 2) - { - prodp[usize + 1] = mpn_addmul_2 (prodp, up, usize, vp[0], vp[1]); - prodp += 2, vp += 2, vsize -= 2; - } - if (vsize != 0) - prodp[usize] = mpn_addmul_1 (prodp, up, usize, vp[0]); -#else - /* For each iteration in the loop, multiply U with one limb from V, and - add the result to PROD. */ - while (vsize != 0) - { - prodp[usize] = mpn_addmul_1 (prodp, up, usize, vp[0]); - prodp += 1, vp += 1, vsize -= 1; - } -#endif -} diff --git a/gmp/mpn/generic/mul_fft.c b/gmp/mpn/generic/mul_fft.c deleted file mode 100755 index 00fd6d7..0000000 --- a/gmp/mpn/generic/mul_fft.c +++ /dev/null @@ -1,772 +0,0 @@ -/* An implementation in GMP of Scho"nhage's fast multiplication algorithm - modulo 2^N+1, by Paul Zimmermann, INRIA Lorraine, February 1998. - - THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND THE FUNCTIONS HAVE - MUTABLE INTERFACES. IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED - INTERFACES. IT IS ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN - A FUTURE GNU MP RELEASE. - -Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -/* References: - - Schnelle Multiplikation grosser Zahlen, by Arnold Scho"nhage and Volker - Strassen, Computing 7, p. 281-292, 1971. - - Asymptotically fast algorithms for the numerical multiplication - and division of polynomials with complex coefficients, by Arnold Scho"nhage, - Computer Algebra, EUROCAM'82, LNCS 144, p. 3-15, 1982. - - Tapes versus Pointers, a study in implementing fast algorithms, - by Arnold Scho"nhage, Bulletin of the EATCS, 30, p. 23-32, 1986. - - See also http://www.loria.fr/~zimmerma/bignum - - - Future: - - K==2 isn't needed in the current uses of this code and the bits specific - for that could be dropped. - - It might be possible to avoid a small number of MPN_COPYs by using a - rotating temporary or two. - - Multiplications of unequal sized operands can be done with this code, but - it needs a tighter test for identifying squaring (same sizes as well as - same pointers). */ - - -#include -#include "gmp.h" -#include "gmp-impl.h" - - -/* Change this to "#define TRACE(x) x" for some traces. */ -#define TRACE(x) - - - -FFT_TABLE_ATTRS mp_size_t mpn_fft_table[2][MPN_FFT_TABLE_SIZE] = { - FFT_MUL_TABLE, - FFT_SQR_TABLE -}; - - -static void mpn_mul_fft_internal -_PROTO ((mp_limb_t *op, mp_srcptr n, mp_srcptr m, mp_size_t pl, - int k, int K, - mp_limb_t **Ap, mp_limb_t **Bp, - mp_limb_t *A, mp_limb_t *B, - mp_size_t nprime, mp_size_t l, mp_size_t Mp, int **_fft_l, - mp_limb_t *T, int rec)); - - -/* Find the best k to use for a mod 2^(n*BITS_PER_MP_LIMB)+1 FFT. - sqr==0 if for a multiply, sqr==1 for a square */ -int -#if __STDC__ -mpn_fft_best_k (mp_size_t n, int sqr) -#else -mpn_fft_best_k (n, sqr) - mp_size_t n; - int sqr; -#endif -{ - mp_size_t t; - int i; - - for (i = 0; mpn_fft_table[sqr][i] != 0; i++) - if (n < mpn_fft_table[sqr][i]) - return i + FFT_FIRST_K; - - /* treat 4*last as one further entry */ - if (i == 0 || n < 4*mpn_fft_table[sqr][i-1]) - return i + FFT_FIRST_K; - else - return i + FFT_FIRST_K + 1; -} - - -/* Returns smallest possible number of limbs >= pl for a fft of size 2^k. - FIXME: Is this simply pl rounded up to the next multiple of 2^k ? */ - -mp_size_t -#if __STDC__ -mpn_fft_next_size (mp_size_t pl, int k) -#else -mpn_fft_next_size (pl, k) - mp_size_t pl; - int k; -#endif -{ - mp_size_t N, M; - int K; - - /* if (k==0) k = mpn_fft_best_k (pl, sqr); */ - N = pl*BITS_PER_MP_LIMB; - K = 1<=0;i--) ap[i] = ~tp[n-d+i]; - cc = 1-mpn_add_1(ap, ap, d, 1); - if (cc) cc=mpn_sub_1(ap+d, tp, n-d, 1); - else MPN_COPY(ap+d, tp, n-d); - if (cc+=mpn_sub_1(ap+d, ap+d, n-d, tp[n])) - ap[n]=mpn_add_1(ap, ap, n, cc); - else ap[n]=0; - } - else if ((ap[n]=mpn_sub_1(ap, tp, n, tp[n]))) { - ap[n]=mpn_add_1(ap, ap, n, 1); - } - if ((e/(n*BITS_PER_MP_LIMB))%2) mpn_fft_neg_modF(ap, n); -} - - -/* a <- a+b mod 2^(n*BITS_PER_MP_LIMB)+1 */ -static void -#if __STDC__ -mpn_fft_add_modF (mp_limb_t *ap, mp_limb_t *bp, int n) -#else -mpn_fft_add_modF (ap, bp, n) - mp_limb_t *ap,*bp; - int n; -#endif -{ - mp_limb_t c; - - c = ap[n] + bp[n] + mpn_add_n(ap, ap, bp, n); - if (c>1) c -= 1+mpn_sub_1(ap,ap,n,1); - ap[n]=c; -} - - -/* input: A[0] ... A[inc*(K-1)] are residues mod 2^N+1 where - N=n*BITS_PER_MP_LIMB - 2^omega is a primitive root mod 2^N+1 - output: A[inc*l[k][i]] <- \sum (2^omega)^(ij) A[inc*j] mod 2^N+1 */ - -static void -#if __STDC__ -mpn_fft_fft_sqr (mp_limb_t **Ap, mp_size_t K, int **ll, - mp_size_t omega, mp_size_t n, mp_size_t inc, mp_limb_t *tp) -#else -mpn_fft_fft_sqr(Ap,K,ll,omega,n,inc,tp) -mp_limb_t **Ap,*tp; -mp_size_t K,omega,n,inc; -int **ll; -#endif -{ - if (K==2) { -#ifdef ADDSUB - if (mpn_addsub_n(Ap[0], Ap[inc], Ap[0], Ap[inc], n+1) & 1) -#else - MPN_COPY(tp, Ap[0], n+1); - mpn_add_n(Ap[0], Ap[0], Ap[inc],n+1); - if (mpn_sub_n(Ap[inc], tp, Ap[inc],n+1)) -#endif - Ap[inc][n] = mpn_add_1(Ap[inc], Ap[inc], n, 1); - } - else { - int j, inc2=2*inc; - int *lk = *ll; - mp_limb_t *tmp; - TMP_DECL(marker); - - TMP_MARK(marker); - tmp = TMP_ALLOC_LIMBS (n+1); - mpn_fft_fft_sqr(Ap, K/2,ll-1,2*omega,n,inc2, tp); - mpn_fft_fft_sqr(Ap+inc, K/2,ll-1,2*omega,n,inc2, tp); - /* A[2*j*inc] <- A[2*j*inc] + omega^l[k][2*j*inc] A[(2j+1)inc] - A[(2j+1)inc] <- A[2*j*inc] + omega^l[k][(2j+1)inc] A[(2j+1)inc] */ - for (j=0;j= (sqr ? FFT_MODF_SQR_THRESHOLD : FFT_MODF_MUL_THRESHOLD)) { - int k, K2,nprime2,Nprime2,M2,maxLK,l,Mp2; - int **_fft_l; - mp_limb_t **Ap,**Bp,*A,*B,*T; - - k = mpn_fft_best_k (n, sqr); - K2 = 1<BITS_PER_MP_LIMB) ? K2 : BITS_PER_MP_LIMB; - M2 = n*BITS_PER_MP_LIMB/K2; - l = n/K2; - Nprime2 = ((2*M2+k+2+maxLK)/maxLK)*maxLK; /* ceil((2*M2+k+3)/maxLK)*maxLK*/ - nprime2 = Nprime2/BITS_PER_MP_LIMB; - Mp2 = Nprime2/K2; - - Ap = TMP_ALLOC_MP_PTRS (K2); - Bp = TMP_ALLOC_MP_PTRS (K2); - A = TMP_ALLOC_LIMBS (2*K2*(nprime2+1)); - T = TMP_ALLOC_LIMBS (nprime2+1); - B = A + K2*(nprime2+1); - _fft_l = TMP_ALLOC_TYPE (k+1, int*); - for (i=0;i<=k;i++) - _fft_l[i] = TMP_ALLOC_TYPE (1< %d times %dx%d (%1.2f)\n", n, - n, K2, nprime2, nprime2, 2.0*(double)n/nprime2/K2)); - - for (i=0;i2*n) { - l = n; - rp[n] = mpn_add_1(rp+an-2*n, ap+an-2*n, 3*n-an, - mpn_add_n(rp,ap,ap+2*n,an-2*n)); - } - else { - l = an-n; - MPN_COPY(rp, ap, n); - rp[n]=0; - } - if (mpn_sub_n(rp,rp,ap+n,l)) { - if (mpn_sub_1(rp+l,rp+l,n+1-l,1)) - rp[n]=mpn_add_1(rp,rp,n,1); - } -} - - -static void -#if __STDC__ -mpn_mul_fft_internal(mp_limb_t *op, mp_srcptr n, mp_srcptr m, mp_size_t pl, - int k, int K, - mp_limb_t **Ap, mp_limb_t **Bp, - mp_limb_t *A, mp_limb_t *B, - mp_size_t nprime, mp_size_t l, mp_size_t Mp, - int **_fft_l, - mp_limb_t *T, int rec) -#else -mpn_mul_fft_internal(op,n,m,pl,k,K,Ap,Bp,A,B,nprime,l,Mp,_fft_l,T,rec) - mp_limb_t *op; - mp_srcptr n, m; - mp_limb_t **Ap,**Bp,*A,*B,*T; - mp_size_t pl,nprime; - int **_fft_l; - int k,K,l,Mp,rec; -#endif -{ - int i, sqr, pla, lo, sh, j; - mp_limb_t *p; - - sqr = (n==m); - - TRACE (printf ("pl=%d k=%d K=%d np=%d l=%d Mp=%d rec=%d sqr=%d\n", - pl,k,K,nprime,l,Mp,rec,sqr)); - - /* decomposition of inputs into arrays Ap[i] and Bp[i] */ - if (rec) for (i=0;i= pla, i.e. enough */ - MPN_ZERO(p, pla); - sqr=0; /* will accumulate the (signed) carry at p[pla] */ - for (i=K-1,lo=l*i+nprime,sh=l*i;i>=0;i--,lo-=l,sh-=l) { - mp_ptr n = p+sh; - j = (K-i)%K; - if (mpn_add_n(n,n,Ap[j],nprime+1)) - sqr += mpn_add_1(n+nprime+1,n+nprime+1,pla-sh-nprime-1,1); - T[2*l]=i+1; /* T = (i+1)*2^(2*M) */ - if (mpn_cmp(Ap[j],T,nprime+1)>0) { /* subtract 2^N'+1 */ - sqr -= mpn_sub_1(n,n,pla-sh,1); - sqr -= mpn_sub_1(p+lo,p+lo,pla-lo,1); - } - } - if (sqr==-1) { - if ((sqr=mpn_add_1(p+pla-pl,p+pla-pl,pl,1))) { - /* p[pla-pl]...p[pla-1] are all zero */ - mpn_sub_1(p+pla-pl-1,p+pla-pl-1,pl+1,1); - mpn_sub_1(p+pla-1,p+pla-1,1,1); - } - } - else if (sqr==1) { - if (pla>=2*pl) - while ((sqr=mpn_add_1(p+pla-2*pl,p+pla-2*pl,2*pl,sqr))); - else { - sqr = mpn_sub_1(p+pla-pl,p+pla-pl,pl,sqr); - ASSERT (sqr == 0); - } - } - else - ASSERT (sqr == 0); - - /* here p < 2^(2M) [K 2^(M(K-1)) + (K-1) 2^(M(K-2)) + ... ] - < K 2^(2M) [2^(M(K-1)) + 2^(M(K-2)) + ... ] - < K 2^(2M) 2^(M(K-1))*2 = 2^(M*K+M+k+1) */ - mpn_fft_norm_modF(op,p,pl,pla); -} - - -/* op <- n*m mod 2^N+1 with fft of size 2^k where N=pl*BITS_PER_MP_LIMB - n and m have respectively nl and ml limbs - op must have space for pl+1 limbs - One must have pl = mpn_fft_next_size(pl, k). -*/ - -void -#if __STDC__ -mpn_mul_fft (mp_ptr op, mp_size_t pl, - mp_srcptr n, mp_size_t nl, - mp_srcptr m, mp_size_t ml, - int k) -#else -mpn_mul_fft (op, pl, n, nl, m, ml, k) - mp_ptr op; - mp_size_t pl; - mp_srcptr n; - mp_size_t nl; - mp_srcptr m; - mp_size_t ml; - int k; -#endif -{ - int K,maxLK,i,j; - mp_size_t N,Nprime,nprime,M,Mp,l; - mp_limb_t **Ap,**Bp,*A,*T,*B; - int **_fft_l; - int sqr = (n==m && nl==ml); - TMP_DECL(marker); - - TRACE (printf ("\nmpn_mul_fft pl=%ld nl=%ld ml=%ld k=%d\n", - pl, nl, ml, k)); - ASSERT_ALWAYS (mpn_fft_next_size(pl, k) == pl); - - TMP_MARK(marker); - N = pl*BITS_PER_MP_LIMB; - _fft_l = TMP_ALLOC_TYPE (k+1, int*); - for (i=0;i<=k;i++) - _fft_l[i] = TMP_ALLOC_TYPE (1<BITS_PER_MP_LIMB) ? K : BITS_PER_MP_LIMB; - - Nprime = ((2*M+k+2+maxLK)/maxLK)*maxLK; /* ceil((2*M+k+3)/maxLK)*maxLK; */ - nprime = Nprime/BITS_PER_MP_LIMB; - TRACE (printf ("N=%d K=%d, M=%d, l=%d, maxLK=%d, Np=%d, np=%d\n", - N, K, M, l, maxLK, Nprime, nprime)); - if (nprime >= (sqr ? FFT_MODF_SQR_THRESHOLD : FFT_MODF_MUL_THRESHOLD)) { - maxLK = (1< %d times %dx%d limbs (%1.2f)\n", - pl,pl,K,nprime,nprime,2.0*(double)N/Nprime/K); - printf(" temp space %ld\n", 2*K*(nprime+1))); - - A = _MP_ALLOCATE_FUNC_LIMBS (2*K*(nprime+1)); - B = A+K*(nprime+1); - Ap = TMP_ALLOC_MP_PTRS (K); - Bp = TMP_ALLOC_MP_PTRS (K); - /* special decomposition for main call */ - for (i=0;i0) { - j = (nl>=l) ? l : nl; /* limbs to store in Ap[i] */ - MPN_COPY(Ap[i], n, j); n+=l; MPN_ZERO(Ap[i]+j, nprime+1-j); - mpn_fft_mul_2exp_modF(Ap[i], i*Mp, nprime, T); - } - else MPN_ZERO(Ap[i], nprime+1); - nl -= l; - if (n!=m) { - if (ml>0) { - j = (ml>=l) ? l : ml; /* limbs to store in Bp[i] */ - MPN_COPY(Bp[i], m, j); m+=l; MPN_ZERO(Bp[i]+j, nprime+1-j); - mpn_fft_mul_2exp_modF(Bp[i], i*Mp, nprime, T); - } - else MPN_ZERO(Bp[i], nprime+1); - } - ml -= l; - } - mpn_mul_fft_internal(op,n,m,pl,k,K,Ap,Bp,A,B,nprime,l,Mp,_fft_l,T,0); - TMP_FREE(marker); - _MP_FREE_FUNC_LIMBS (A, 2*K*(nprime+1)); -} - - -#if WANT_ASSERT -static int -#if __STDC__ -mpn_zero_p (mp_ptr p, mp_size_t n) -#else - mpn_zero_p (p, n) - mp_ptr p; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - { - if (p[i] != 0) - return 0; - } - - return 1; -} -#endif - - -/* Multiply {n,nl}*{m,ml} and write the result to {op,nl+ml}. - - FIXME: Duplicating the result like this is wasteful, do something better - perhaps at the norm_modF stage above. */ - -void -#if __STDC__ -mpn_mul_fft_full (mp_ptr op, - mp_srcptr n, mp_size_t nl, - mp_srcptr m, mp_size_t ml) -#else -mpn_mul_fft_full (op, n, nl, m, ml) - mp_ptr op; - mp_srcptr n; - mp_size_t nl; - mp_srcptr m; - mp_size_t ml; -#endif -{ - mp_ptr pad_op; - mp_size_t pl; - int k; - int sqr = (n==m && nl==ml); - - k = mpn_fft_best_k (nl+ml, sqr); - pl = mpn_fft_next_size (nl+ml, k); - - TRACE (printf ("mpn_mul_fft_full nl=%ld ml=%ld -> pl=%ld k=%d\n", - nl, ml, pl, k)); - - pad_op = _MP_ALLOCATE_FUNC_LIMBS (pl+1); - mpn_mul_fft (pad_op, pl, n, nl, m, ml, k); - - ASSERT (mpn_zero_p (pad_op+nl+ml, pl+1-(nl+ml))); - MPN_COPY (op, pad_op, nl+ml); - - _MP_FREE_FUNC_LIMBS (pad_op, pl+1); -} diff --git a/gmp/mpn/generic/mul_n.c b/gmp/mpn/generic/mul_n.c deleted file mode 100755 index b7563be..0000000 --- a/gmp/mpn/generic/mul_n.c +++ /dev/null @@ -1,1343 +0,0 @@ -/* mpn_mul_n and helper function -- Multiply/square natural numbers. - - THE HELPER FUNCTIONS IN THIS FILE (meaning everything except mpn_mul_n) - ARE INTERNAL FUNCTIONS WITH MUTABLE INTERFACES. IT IS ONLY SAFE TO REACH - THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED - THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. - - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 1998, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* Multiplicative inverse of 3, modulo 2^BITS_PER_MP_LIMB. - 0xAAAAAAAB for 32 bits, 0xAAAAAAAAAAAAAAAB for 64 bits. */ -#define INVERSE_3 ((MP_LIMB_T_MAX / 3) * 2 + 1) - -#if !defined (__alpha) && !defined (__mips) -/* For all other machines, we want to call mpn functions for the compund - operations instead of open-coding them. */ -#define USE_MORE_MPN -#endif - -/*== Function declarations =================================================*/ - -static void evaluate3 _PROTO ((mp_ptr, mp_ptr, mp_ptr, - mp_ptr, mp_ptr, mp_ptr, - mp_srcptr, mp_srcptr, mp_srcptr, - mp_size_t, mp_size_t)); -static void interpolate3 _PROTO ((mp_srcptr, - mp_ptr, mp_ptr, mp_ptr, - mp_srcptr, - mp_ptr, mp_ptr, mp_ptr, - mp_size_t, mp_size_t)); -static mp_limb_t add2Times _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); - - -/*-- mpn_kara_mul_n ---------------------------------------------------------------*/ - -/* Multiplies using 3 half-sized mults and so on recursively. - * p[0..2*n-1] := product of a[0..n-1] and b[0..n-1]. - * No overlap of p[...] with a[...] or b[...]. - * ws is workspace. - */ - -void -#if __STDC__ -mpn_kara_mul_n (mp_ptr p, mp_srcptr a, mp_srcptr b, mp_size_t n, mp_ptr ws) -#else -mpn_kara_mul_n(p, a, b, n, ws) - mp_ptr p; - mp_srcptr a; - mp_srcptr b; - mp_size_t n; - mp_ptr ws; -#endif -{ - mp_limb_t i, sign, w, w0, w1; - mp_size_t n2; - mp_srcptr x, y; - - n2 = n >> 1; - ASSERT (n2 > 0); - - if (n & 1) - { - /* Odd length. */ - mp_size_t n1, n3, nm1; - - n3 = n - n2; - - sign = 0; - w = a[n2]; - if (w != 0) - w -= mpn_sub_n (p, a, a + n3, n2); - else - { - i = n2; - do - { - --i; - w0 = a[i]; - w1 = a[n3+i]; - } - while (w0 == w1 && i != 0); - if (w0 < w1) - { - x = a + n3; - y = a; - sign = 1; - } - else - { - x = a; - y = a + n3; - } - mpn_sub_n (p, x, y, n2); - } - p[n2] = w; - - w = b[n2]; - if (w != 0) - w -= mpn_sub_n (p + n3, b, b + n3, n2); - else - { - i = n2; - do - { - --i; - w0 = b[i]; - w1 = b[n3+i]; - } - while (w0 == w1 && i != 0); - if (w0 < w1) - { - x = b + n3; - y = b; - sign ^= 1; - } - else - { - x = b; - y = b + n3; - } - mpn_sub_n (p + n3, x, y, n2); - } - p[n] = w; - - n1 = n + 1; - if (n2 < KARATSUBA_MUL_THRESHOLD) - { - if (n3 < KARATSUBA_MUL_THRESHOLD) - { - mpn_mul_basecase (ws, p, n3, p + n3, n3); - mpn_mul_basecase (p, a, n3, b, n3); - } - else - { - mpn_kara_mul_n (ws, p, p + n3, n3, ws + n1); - mpn_kara_mul_n (p, a, b, n3, ws + n1); - } - mpn_mul_basecase (p + n1, a + n3, n2, b + n3, n2); - } - else - { - mpn_kara_mul_n (ws, p, p + n3, n3, ws + n1); - mpn_kara_mul_n (p, a, b, n3, ws + n1); - mpn_kara_mul_n (p + n1, a + n3, b + n3, n2, ws + n1); - } - - if (sign) - mpn_add_n (ws, p, ws, n1); - else - mpn_sub_n (ws, p, ws, n1); - - nm1 = n - 1; - if (mpn_add_n (ws, p + n1, ws, nm1)) - { - mp_limb_t x = ws[nm1] + 1; - ws[nm1] = x; - if (x == 0) - ++ws[n]; - } - if (mpn_add_n (p + n3, p + n3, ws, n1)) - { - mp_limb_t x; - i = n1 + n3; - do - { - x = p[i] + 1; - p[i] = x; - ++i; - } while (x == 0); - } - } - else - { - /* Even length. */ - mp_limb_t t; - - i = n2; - do - { - --i; - w0 = a[i]; - w1 = a[n2+i]; - } - while (w0 == w1 && i != 0); - sign = 0; - if (w0 < w1) - { - x = a + n2; - y = a; - sign = 1; - } - else - { - x = a; - y = a + n2; - } - mpn_sub_n (p, x, y, n2); - - i = n2; - do - { - --i; - w0 = b[i]; - w1 = b[n2+i]; - } - while (w0 == w1 && i != 0); - if (w0 < w1) - { - x = b + n2; - y = b; - sign ^= 1; - } - else - { - x = b; - y = b + n2; - } - mpn_sub_n (p + n2, x, y, n2); - - /* Pointwise products. */ - if (n2 < KARATSUBA_MUL_THRESHOLD) - { - mpn_mul_basecase (ws, p, n2, p + n2, n2); - mpn_mul_basecase (p, a, n2, b, n2); - mpn_mul_basecase (p + n, a + n2, n2, b + n2, n2); - } - else - { - mpn_kara_mul_n (ws, p, p + n2, n2, ws + n); - mpn_kara_mul_n (p, a, b, n2, ws + n); - mpn_kara_mul_n (p + n, a + n2, b + n2, n2, ws + n); - } - - /* Interpolate. */ - if (sign) - w = mpn_add_n (ws, p, ws, n); - else - w = -mpn_sub_n (ws, p, ws, n); - w += mpn_add_n (ws, p + n, ws, n); - w += mpn_add_n (p + n2, p + n2, ws, n); - /* TO DO: could put "if (w) { ... }" here. - * Less work but badly predicted branch. - * No measurable difference in speed on Alpha. - */ - i = n + n2; - t = p[i] + w; - p[i] = t; - if (t < w) - { - do - { - ++i; - w = p[i] + 1; - p[i] = w; - } - while (w == 0); - } - } -} - -void -#if __STDC__ -mpn_kara_sqr_n (mp_ptr p, mp_srcptr a, mp_size_t n, mp_ptr ws) -#else -mpn_kara_sqr_n (p, a, n, ws) - mp_ptr p; - mp_srcptr a; - mp_size_t n; - mp_ptr ws; -#endif -{ - mp_limb_t i, sign, w, w0, w1; - mp_size_t n2; - mp_srcptr x, y; - - n2 = n >> 1; - ASSERT (n2 > 0); - - if (n & 1) - { - /* Odd length. */ - mp_size_t n1, n3, nm1; - - n3 = n - n2; - - sign = 0; - w = a[n2]; - if (w != 0) - w -= mpn_sub_n (p, a, a + n3, n2); - else - { - i = n2; - do - { - --i; - w0 = a[i]; - w1 = a[n3+i]; - } - while (w0 == w1 && i != 0); - if (w0 < w1) - { - x = a + n3; - y = a; - sign = 1; - } - else - { - x = a; - y = a + n3; - } - mpn_sub_n (p, x, y, n2); - } - p[n2] = w; - - w = a[n2]; - if (w != 0) - w -= mpn_sub_n (p + n3, a, a + n3, n2); - else - { - i = n2; - do - { - --i; - w0 = a[i]; - w1 = a[n3+i]; - } - while (w0 == w1 && i != 0); - if (w0 < w1) - { - x = a + n3; - y = a; - sign ^= 1; - } - else - { - x = a; - y = a + n3; - } - mpn_sub_n (p + n3, x, y, n2); - } - p[n] = w; - - n1 = n + 1; - if (n2 < KARATSUBA_SQR_THRESHOLD) - { - if (n3 < KARATSUBA_SQR_THRESHOLD) - { - mpn_sqr_basecase (ws, p, n3); - mpn_sqr_basecase (p, a, n3); - } - else - { - mpn_kara_sqr_n (ws, p, n3, ws + n1); - mpn_kara_sqr_n (p, a, n3, ws + n1); - } - mpn_sqr_basecase (p + n1, a + n3, n2); - } - else - { - mpn_kara_sqr_n (ws, p, n3, ws + n1); - mpn_kara_sqr_n (p, a, n3, ws + n1); - mpn_kara_sqr_n (p + n1, a + n3, n2, ws + n1); - } - - if (sign) - mpn_add_n (ws, p, ws, n1); - else - mpn_sub_n (ws, p, ws, n1); - - nm1 = n - 1; - if (mpn_add_n (ws, p + n1, ws, nm1)) - { - mp_limb_t x = ws[nm1] + 1; - ws[nm1] = x; - if (x == 0) - ++ws[n]; - } - if (mpn_add_n (p + n3, p + n3, ws, n1)) - { - mp_limb_t x; - i = n1 + n3; - do - { - x = p[i] + 1; - p[i] = x; - ++i; - } while (x == 0); - } - } - else - { - /* Even length. */ - mp_limb_t t; - - i = n2; - do - { - --i; - w0 = a[i]; - w1 = a[n2+i]; - } - while (w0 == w1 && i != 0); - sign = 0; - if (w0 < w1) - { - x = a + n2; - y = a; - sign = 1; - } - else - { - x = a; - y = a + n2; - } - mpn_sub_n (p, x, y, n2); - - i = n2; - do - { - --i; - w0 = a[i]; - w1 = a[n2+i]; - } - while (w0 == w1 && i != 0); - if (w0 < w1) - { - x = a + n2; - y = a; - sign ^= 1; - } - else - { - x = a; - y = a + n2; - } - mpn_sub_n (p + n2, x, y, n2); - - /* Pointwise products. */ - if (n2 < KARATSUBA_SQR_THRESHOLD) - { - mpn_sqr_basecase (ws, p, n2); - mpn_sqr_basecase (p, a, n2); - mpn_sqr_basecase (p + n, a + n2, n2); - } - else - { - mpn_kara_sqr_n (ws, p, n2, ws + n); - mpn_kara_sqr_n (p, a, n2, ws + n); - mpn_kara_sqr_n (p + n, a + n2, n2, ws + n); - } - - /* Interpolate. */ - if (sign) - w = mpn_add_n (ws, p, ws, n); - else - w = -mpn_sub_n (ws, p, ws, n); - w += mpn_add_n (ws, p + n, ws, n); - w += mpn_add_n (p + n2, p + n2, ws, n); - /* TO DO: could put "if (w) { ... }" here. - * Less work but badly predicted branch. - * No measurable difference in speed on Alpha. - */ - i = n + n2; - t = p[i] + w; - p[i] = t; - if (t < w) - { - do - { - ++i; - w = p[i] + 1; - p[i] = w; - } - while (w == 0); - } - } -} - -/*-- add2Times -------------------------------------------------------------*/ - -/* z[] = x[] + 2 * y[] - Note that z and x might point to the same vectors. */ -#ifdef USE_MORE_MPN -static inline mp_limb_t -#if __STDC__ -add2Times (mp_ptr z, mp_srcptr x, mp_srcptr y, mp_size_t n) -#else -add2Times (z, x, y, n) - mp_ptr z; - mp_srcptr x; - mp_srcptr y; - mp_size_t n; -#endif -{ - mp_ptr t; - mp_limb_t c; - TMP_DECL (marker); - TMP_MARK (marker); - t = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB); - c = mpn_lshift (t, y, n, 1); - c += mpn_add_n (z, x, t, n); - TMP_FREE (marker); - return c; -} -#else - -static mp_limb_t -#if __STDC__ -add2Times (mp_ptr z, mp_srcptr x, mp_srcptr y, mp_size_t n) -#else -add2Times (z, x, y, n) - mp_ptr z; - mp_srcptr x; - mp_srcptr y; - mp_size_t n; -#endif -{ - mp_limb_t c, v, w; - - ASSERT (n > 0); - v = *x; w = *y; - c = w >> (BITS_PER_MP_LIMB - 1); - w <<= 1; - v += w; - c += v < w; - *z = v; - ++x; ++y; ++z; - while (--n) - { - v = *x; - w = *y; - v += c; - c = v < c; - c += w >> (BITS_PER_MP_LIMB - 1); - w <<= 1; - v += w; - c += v < w; - *z = v; - ++x; ++y; ++z; - } - - return c; -} -#endif - -/*-- evaluate3 -------------------------------------------------------------*/ - -/* Evaluates: - * ph := 4*A+2*B+C - * p1 := A+B+C - * p2 := A+2*B+4*C - * where: - * ph[], p1[], p2[], A[] and B[] all have length len, - * C[] has length len2 with len-len2 = 0, 1 or 2. - * Returns top words (overflow) at pth, pt1 and pt2 respectively. - */ -#ifdef USE_MORE_MPN -static void -#if __STDC__ -evaluate3 (mp_ptr ph, mp_ptr p1, mp_ptr p2, mp_ptr pth, mp_ptr pt1, mp_ptr pt2, - mp_srcptr A, mp_srcptr B, mp_srcptr C, mp_size_t len, mp_size_t len2) -#else -evaluate3 (ph, p1, p2, pth, pt1, pt2, - A, B, C, len, len2) - mp_ptr ph; - mp_ptr p1; - mp_ptr p2; - mp_ptr pth; - mp_ptr pt1; - mp_ptr pt2; - mp_srcptr A; - mp_srcptr B; - mp_srcptr C; - mp_size_t len; - mp_size_t len2; -#endif -{ - mp_limb_t c, d, e; - - ASSERT (len - len2 <= 2); - - e = mpn_lshift (p1, B, len, 1); - - c = mpn_lshift (ph, A, len, 2); - c += e + mpn_add_n (ph, ph, p1, len); - d = mpn_add_n (ph, ph, C, len2); - if (len2 == len) c += d; else c += mpn_add_1 (ph + len2, ph + len2, len-len2, d); - ASSERT (c < 7); - *pth = c; - - c = mpn_lshift (p2, C, len2, 2); -#if 1 - if (len2 != len) { p2[len-1] = 0; p2[len2] = c; c = 0; } - c += e + mpn_add_n (p2, p2, p1, len); -#else - d = mpn_add_n (p2, p2, p1, len2); - c += d; - if (len2 != len) c = mpn_add_1 (p2+len2, p1+len2, len-len2, c); - c += e; -#endif - c += mpn_add_n (p2, p2, A, len); - ASSERT (c < 7); - *pt2 = c; - - c = mpn_add_n (p1, A, B, len); - d = mpn_add_n (p1, p1, C, len2); - if (len2 == len) c += d; - else c += mpn_add_1 (p1+len2, p1+len2, len-len2, d); - ASSERT (c < 3); - *pt1 = c; - -} - -#else - -static void -#if __STDC__ -evaluate3 (mp_ptr ph, mp_ptr p1, mp_ptr p2, mp_ptr pth, mp_ptr pt1, mp_ptr pt2, - mp_srcptr A, mp_srcptr B, mp_srcptr C, mp_size_t l, mp_size_t ls) -#else -evaluate3 (ph, p1, p2, pth, pt1, pt2, - A, B, C, l, ls) - mp_ptr ph; - mp_ptr p1; - mp_ptr p2; - mp_ptr pth; - mp_ptr pt1; - mp_ptr pt2; - mp_srcptr A; - mp_srcptr B; - mp_srcptr C; - mp_size_t l; - mp_size_t ls; -#endif -{ - mp_limb_t a,b,c, i, t, th,t1,t2, vh,v1,v2; - - ASSERT (l - ls <= 2); - - th = t1 = t2 = 0; - for (i = 0; i < l; ++i) - { - a = *A; - b = *B; - c = i < ls ? *C : 0; - - /* TO DO: choose one of the following alternatives. */ -#if 0 - t = a << 2; - vh = th + t; - th = vh < t; - th += a >> (BITS_PER_MP_LIMB - 2); - t = b << 1; - vh += t; - th += vh < t; - th += b >> (BITS_PER_MP_LIMB - 1); - vh += c; - th += vh < c; -#else - vh = th + c; - th = vh < c; - t = b << 1; - vh += t; - th += vh < t; - th += b >> (BITS_PER_MP_LIMB - 1); - t = a << 2; - vh += t; - th += vh < t; - th += a >> (BITS_PER_MP_LIMB - 2); -#endif - - v1 = t1 + a; - t1 = v1 < a; - v1 += b; - t1 += v1 < b; - v1 += c; - t1 += v1 < c; - - v2 = t2 + a; - t2 = v2 < a; - t = b << 1; - v2 += t; - t2 += v2 < t; - t2 += b >> (BITS_PER_MP_LIMB - 1); - t = c << 2; - v2 += t; - t2 += v2 < t; - t2 += c >> (BITS_PER_MP_LIMB - 2); - - *ph = vh; - *p1 = v1; - *p2 = v2; - - ++A; ++B; ++C; - ++ph; ++p1; ++p2; - } - - ASSERT (th < 7); - ASSERT (t1 < 3); - ASSERT (t2 < 7); - - *pth = th; - *pt1 = t1; - *pt2 = t2; -} -#endif - - -/*-- interpolate3 ----------------------------------------------------------*/ - -/* Interpolates B, C, D (in-place) from: - * 16*A+8*B+4*C+2*D+E - * A+B+C+D+E - * A+2*B+4*C+8*D+16*E - * where: - * A[], B[], C[] and D[] all have length l, - * E[] has length ls with l-ls = 0, 2 or 4. - * - * Reads top words (from earlier overflow) from ptb, ptc and ptd, - * and returns new top words there. - */ - -#ifdef USE_MORE_MPN -static void -#if __STDC__ -interpolate3 (mp_srcptr A, mp_ptr B, mp_ptr C, mp_ptr D, mp_srcptr E, - mp_ptr ptb, mp_ptr ptc, mp_ptr ptd, mp_size_t len, mp_size_t len2) -#else -interpolate3 (A, B, C, D, E, - ptb, ptc, ptd, len, len2) - mp_srcptr A; - mp_ptr B; - mp_ptr C; - mp_ptr D; - mp_srcptr E; - mp_ptr ptb; - mp_ptr ptc; - mp_ptr ptd; - mp_size_t len; - mp_size_t len2; -#endif -{ - mp_ptr ws; - mp_limb_t t, tb,tc,td; - TMP_DECL (marker); - TMP_MARK (marker); - - ASSERT (len - len2 == 0 || len - len2 == 2 || len - len2 == 4); - - /* Let x1, x2, x3 be the values to interpolate. We have: - * b = 16*a + 8*x1 + 4*x2 + 2*x3 + e - * c = a + x1 + x2 + x3 + e - * d = a + 2*x1 + 4*x2 + 8*x3 + 16*e - */ - - ws = (mp_ptr) TMP_ALLOC (len * BYTES_PER_MP_LIMB); - - tb = *ptb; tc = *ptc; td = *ptd; - - - /* b := b - 16*a - e - * c := c - a - e - * d := d - a - 16*e - */ - - t = mpn_lshift (ws, A, len, 4); - tb -= t + mpn_sub_n (B, B, ws, len); - t = mpn_sub_n (B, B, E, len2); - if (len2 == len) tb -= t; - else tb -= mpn_sub_1 (B+len2, B+len2, len-len2, t); - - tc -= mpn_sub_n (C, C, A, len); - t = mpn_sub_n (C, C, E, len2); - if (len2 == len) tc -= t; - else tc -= mpn_sub_1 (C+len2, C+len2, len-len2, t); - - t = mpn_lshift (ws, E, len2, 4); - t += mpn_add_n (ws, ws, A, len2); -#if 1 - if (len2 != len) t = mpn_add_1 (ws+len2, A+len2, len-len2, t); - td -= t + mpn_sub_n (D, D, ws, len); -#else - t += mpn_sub_n (D, D, ws, len2); - if (len2 != len) { - t = mpn_sub_1 (D+len2, D+len2, len-len2, t); - t += mpn_sub_n (D+len2, D+len2, A+len2, len-len2); - } /* end if/else */ - td -= t; -#endif - - - /* b, d := b + d, b - d */ - -#ifdef HAVE_MPN_ADD_SUB_N - /* #error TO DO ... */ -#else - t = tb + td + mpn_add_n (ws, B, D, len); - td = tb - td - mpn_sub_n (D, B, D, len); - tb = t; - MPN_COPY (B, ws, len); -#endif - - /* b := b-8*c */ - t = 8 * tc + mpn_lshift (ws, C, len, 3); - tb -= t + mpn_sub_n (B, B, ws, len); - - /* c := 2*c - b */ - tc = 2 * tc + mpn_lshift (C, C, len, 1); - tc -= tb + mpn_sub_n (C, C, B, len); - - /* d := d/3 */ - td = (td - mpn_divexact_by3 (D, D, len)) * INVERSE_3; - - /* b, d := b + d, b - d */ -#ifdef HAVE_MPN_ADD_SUB_N - /* #error TO DO ... */ -#else - t = tb + td + mpn_add_n (ws, B, D, len); - td = tb - td - mpn_sub_n (D, B, D, len); - tb = t; - MPN_COPY (B, ws, len); -#endif - - /* Now: - * b = 4*x1 - * c = 2*x2 - * d = 4*x3 - */ - - ASSERT(!(*B & 3)); - mpn_rshift (B, B, len, 2); - B[len-1] |= tb<<(BITS_PER_MP_LIMB-2); - ASSERT((long)tb >= 0); - tb >>= 2; - - ASSERT(!(*C & 1)); - mpn_rshift (C, C, len, 1); - C[len-1] |= tc<<(BITS_PER_MP_LIMB-1); - ASSERT((long)tc >= 0); - tc >>= 1; - - ASSERT(!(*D & 3)); - mpn_rshift (D, D, len, 2); - D[len-1] |= td<<(BITS_PER_MP_LIMB-2); - ASSERT((long)td >= 0); - td >>= 2; - -#if WANT_ASSERT - ASSERT (tb < 2); - if (len == len2) - { - ASSERT (tc < 3); - ASSERT (td < 2); - } - else - { - ASSERT (tc < 2); - ASSERT (!td); - } -#endif - - *ptb = tb; - *ptc = tc; - *ptd = td; - - TMP_FREE (marker); -} - -#else - -static void -#if __STDC__ -interpolate3 (mp_srcptr A, mp_ptr B, mp_ptr C, mp_ptr D, mp_srcptr E, - mp_ptr ptb, mp_ptr ptc, mp_ptr ptd, mp_size_t l, mp_size_t ls) -#else -interpolate3 (A, B, C, D, E, - ptb, ptc, ptd, l, ls) - mp_srcptr A; - mp_ptr B; - mp_ptr C; - mp_ptr D; - mp_srcptr E; - mp_ptr ptb; - mp_ptr ptc; - mp_ptr ptd; - mp_size_t l; - mp_size_t ls; -#endif -{ - mp_limb_t a,b,c,d,e,t, i, sb,sc,sd, ob,oc,od; - const mp_limb_t maskOffHalf = (~(mp_limb_t) 0) << (BITS_PER_MP_LIMB >> 1); - -#if WANT_ASSERT - t = l - ls; - ASSERT (t == 0 || t == 2 || t == 4); -#endif - - sb = sc = sd = 0; - for (i = 0; i < l; ++i) - { - mp_limb_t tb, tc, td, tt; - - a = *A; - b = *B; - c = *C; - d = *D; - e = i < ls ? *E : 0; - - /* Let x1, x2, x3 be the values to interpolate. We have: - * b = 16*a + 8*x1 + 4*x2 + 2*x3 + e - * c = a + x1 + x2 + x3 + e - * d = a + 2*x1 + 4*x2 + 8*x3 + 16*e - */ - - /* b := b - 16*a - e - * c := c - a - e - * d := d - a - 16*e - */ - t = a << 4; - tb = -(a >> (BITS_PER_MP_LIMB - 4)) - (b < t); - b -= t; - tb -= b < e; - b -= e; - tc = -(c < a); - c -= a; - tc -= c < e; - c -= e; - td = -(d < a); - d -= a; - t = e << 4; - td = td - (e >> (BITS_PER_MP_LIMB - 4)) - (d < t); - d -= t; - - /* b, d := b + d, b - d */ - t = b + d; - tt = tb + td + (t < b); - td = tb - td - (b < d); - d = b - d; - b = t; - tb = tt; - - /* b := b-8*c */ - t = c << 3; - tb = tb - (tc << 3) - (c >> (BITS_PER_MP_LIMB - 3)) - (b < t); - b -= t; - - /* c := 2*c - b */ - t = c << 1; - tc = (tc << 1) + (c >> (BITS_PER_MP_LIMB - 1)) - tb - (t < b); - c = t - b; - - /* d := d/3 */ - d *= INVERSE_3; - td = td - (d >> (BITS_PER_MP_LIMB - 1)) - (d*3 < d); - td *= INVERSE_3; - - /* b, d := b + d, b - d */ - t = b + d; - tt = tb + td + (t < b); - td = tb - td - (b < d); - d = b - d; - b = t; - tb = tt; - - /* Now: - * b = 4*x1 - * c = 2*x2 - * d = 4*x3 - */ - - /* sb has period 2. */ - b += sb; - tb += b < sb; - sb &= maskOffHalf; - sb |= sb >> (BITS_PER_MP_LIMB >> 1); - sb += tb; - - /* sc has period 1. */ - c += sc; - tc += c < sc; - /* TO DO: choose one of the following alternatives. */ -#if 1 - sc = (mp_limb_t)((long)sc >> (BITS_PER_MP_LIMB - 1)); - sc += tc; -#else - sc = tc - ((long)sc < 0L); -#endif - - /* sd has period 2. */ - d += sd; - td += d < sd; - sd &= maskOffHalf; - sd |= sd >> (BITS_PER_MP_LIMB >> 1); - sd += td; - - if (i != 0) - { - B[-1] = ob | b << (BITS_PER_MP_LIMB - 2); - C[-1] = oc | c << (BITS_PER_MP_LIMB - 1); - D[-1] = od | d << (BITS_PER_MP_LIMB - 2); - } - ob = b >> 2; - oc = c >> 1; - od = d >> 2; - - ++A; ++B; ++C; ++D; ++E; - } - - /* Handle top words. */ - b = *ptb; - c = *ptc; - d = *ptd; - - t = b + d; - d = b - d; - b = t; - b -= c << 3; - c = (c << 1) - b; - d *= INVERSE_3; - t = b + d; - d = b - d; - b = t; - - b += sb; - c += sc; - d += sd; - - B[-1] = ob | b << (BITS_PER_MP_LIMB - 2); - C[-1] = oc | c << (BITS_PER_MP_LIMB - 1); - D[-1] = od | d << (BITS_PER_MP_LIMB - 2); - - b >>= 2; - c >>= 1; - d >>= 2; - -#if WANT_ASSERT - ASSERT (b < 2); - if (l == ls) - { - ASSERT (c < 3); - ASSERT (d < 2); - } - else - { - ASSERT (c < 2); - ASSERT (!d); - } -#endif - - *ptb = b; - *ptc = c; - *ptd = d; -} -#endif - - -/*-- mpn_toom3_mul_n --------------------------------------------------------------*/ - -/* Multiplies using 5 mults of one third size and so on recursively. - * p[0..2*n-1] := product of a[0..n-1] and b[0..n-1]. - * No overlap of p[...] with a[...] or b[...]. - * ws is workspace. - */ - -/* TO DO: If TOOM3_MUL_THRESHOLD is much bigger than KARATSUBA_MUL_THRESHOLD then the - * recursion in mpn_toom3_mul_n() will always bottom out with mpn_kara_mul_n() - * because the "n < KARATSUBA_MUL_THRESHOLD" test here will always be false. - */ - -#define TOOM3_MUL_REC(p, a, b, n, ws) \ - do { \ - if (n < KARATSUBA_MUL_THRESHOLD) \ - mpn_mul_basecase (p, a, n, b, n); \ - else if (n < TOOM3_MUL_THRESHOLD) \ - mpn_kara_mul_n (p, a, b, n, ws); \ - else \ - mpn_toom3_mul_n (p, a, b, n, ws); \ - } while (0) - -void -#if __STDC__ -mpn_toom3_mul_n (mp_ptr p, mp_srcptr a, mp_srcptr b, mp_size_t n, mp_ptr ws) -#else -mpn_toom3_mul_n (p, a, b, n, ws) - mp_ptr p; - mp_srcptr a; - mp_srcptr b; - mp_size_t n; - mp_ptr ws; -#endif -{ - mp_limb_t cB,cC,cD, dB,dC,dD, tB,tC,tD; - mp_limb_t *A,*B,*C,*D,*E, *W; - mp_size_t l,l2,l3,l4,l5,ls; - - /* Break n words into chunks of size l, l and ls. - * n = 3*k => l = k, ls = k - * n = 3*k+1 => l = k+1, ls = k-1 - * n = 3*k+2 => l = k+1, ls = k - */ - { - mp_limb_t m; - - ASSERT (n >= TOOM3_MUL_THRESHOLD); - l = ls = n / 3; - m = n - l * 3; - if (m != 0) - ++l; - if (m == 1) - --ls; - - l2 = l * 2; - l3 = l * 3; - l4 = l * 4; - l5 = l * 5; - A = p; - B = ws; - C = p + l2; - D = ws + l2; - E = p + l4; - W = ws + l4; - } - - /** First stage: evaluation at points 0, 1/2, 1, 2, oo. **/ - evaluate3 (A, B, C, &cB, &cC, &cD, a, a + l, a + l2, l, ls); - evaluate3 (A + l, B + l, C + l, &dB, &dC, &dD, b, b + l, b + l2, l, ls); - - /** Second stage: pointwise multiplies. **/ - TOOM3_MUL_REC(D, C, C + l, l, W); - tD = cD*dD; - if (cD) tD += mpn_addmul_1 (D + l, C + l, l, cD); - if (dD) tD += mpn_addmul_1 (D + l, C, l, dD); - ASSERT (tD < 49); - TOOM3_MUL_REC(C, B, B + l, l, W); - tC = cC*dC; - /* TO DO: choose one of the following alternatives. */ -#if 0 - if (cC) tC += mpn_addmul_1 (C + l, B + l, l, cC); - if (dC) tC += mpn_addmul_1 (C + l, B, l, dC); -#else - if (cC) - { - if (cC == 1) tC += mpn_add_n (C + l, C + l, B + l, l); - else tC += add2Times (C + l, C + l, B + l, l); - } - if (dC) - { - if (dC == 1) tC += mpn_add_n (C + l, C + l, B, l); - else tC += add2Times (C + l, C + l, B, l); - } -#endif - ASSERT (tC < 9); - TOOM3_MUL_REC(B, A, A + l, l, W); - tB = cB*dB; - if (cB) tB += mpn_addmul_1 (B + l, A + l, l, cB); - if (dB) tB += mpn_addmul_1 (B + l, A, l, dB); - ASSERT (tB < 49); - TOOM3_MUL_REC(A, a, b, l, W); - TOOM3_MUL_REC(E, a + l2, b + l2, ls, W); - - /** Third stage: interpolation. **/ - interpolate3 (A, B, C, D, E, &tB, &tC, &tD, l2, ls << 1); - - /** Final stage: add up the coefficients. **/ - { - mp_limb_t i, x, y; - tB += mpn_add_n (p + l, p + l, B, l2); - tD += mpn_add_n (p + l3, p + l3, D, l2); - mpn_incr_u (p + l3, tB); - mpn_incr_u (p + l4, tC); - mpn_incr_u (p + l5, tD); - } -} - -/*-- mpn_toom3_sqr_n --------------------------------------------------------------*/ - -/* Like previous function but for squaring */ - -#define TOOM3_SQR_REC(p, a, n, ws) \ - do { \ - if (n < KARATSUBA_SQR_THRESHOLD) \ - mpn_sqr_basecase (p, a, n); \ - else if (n < TOOM3_SQR_THRESHOLD) \ - mpn_kara_sqr_n (p, a, n, ws); \ - else \ - mpn_toom3_sqr_n (p, a, n, ws); \ - } while (0) - -void -#if __STDC__ -mpn_toom3_sqr_n (mp_ptr p, mp_srcptr a, mp_size_t n, mp_ptr ws) -#else -mpn_toom3_sqr_n (p, a, n, ws) - mp_ptr p; - mp_srcptr a; - mp_size_t n; - mp_ptr ws; -#endif -{ - mp_limb_t cB,cC,cD, tB,tC,tD; - mp_limb_t *A,*B,*C,*D,*E, *W; - mp_size_t l,l2,l3,l4,l5,ls; - - /* Break n words into chunks of size l, l and ls. - * n = 3*k => l = k, ls = k - * n = 3*k+1 => l = k+1, ls = k-1 - * n = 3*k+2 => l = k+1, ls = k - */ - { - mp_limb_t m; - - ASSERT (n >= TOOM3_MUL_THRESHOLD); - l = ls = n / 3; - m = n - l * 3; - if (m != 0) - ++l; - if (m == 1) - --ls; - - l2 = l * 2; - l3 = l * 3; - l4 = l * 4; - l5 = l * 5; - A = p; - B = ws; - C = p + l2; - D = ws + l2; - E = p + l4; - W = ws + l4; - } - - /** First stage: evaluation at points 0, 1/2, 1, 2, oo. **/ - evaluate3 (A, B, C, &cB, &cC, &cD, a, a + l, a + l2, l, ls); - - /** Second stage: pointwise multiplies. **/ - TOOM3_SQR_REC(D, C, l, W); - tD = cD*cD; - if (cD) tD += mpn_addmul_1 (D + l, C, l, 2*cD); - ASSERT (tD < 49); - TOOM3_SQR_REC(C, B, l, W); - tC = cC*cC; - /* TO DO: choose one of the following alternatives. */ -#if 0 - if (cC) tC += mpn_addmul_1 (C + l, B, l, 2*cC); -#else - if (cC >= 1) - { - tC += add2Times (C + l, C + l, B, l); - if (cC == 2) - tC += add2Times (C + l, C + l, B, l); - } -#endif - ASSERT (tC < 9); - TOOM3_SQR_REC(B, A, l, W); - tB = cB*cB; - if (cB) tB += mpn_addmul_1 (B + l, A, l, 2*cB); - ASSERT (tB < 49); - TOOM3_SQR_REC(A, a, l, W); - TOOM3_SQR_REC(E, a + l2, ls, W); - - /** Third stage: interpolation. **/ - interpolate3 (A, B, C, D, E, &tB, &tC, &tD, l2, ls << 1); - - /** Final stage: add up the coefficients. **/ - { - mp_limb_t i, x, y; - tB += mpn_add_n (p + l, p + l, B, l2); - tD += mpn_add_n (p + l3, p + l3, D, l2); - mpn_incr_u (p + l3, tB); - mpn_incr_u (p + l4, tC); - mpn_incr_u (p + l5, tD); - } -} - -void -#if __STDC__ -mpn_mul_n (mp_ptr p, mp_srcptr a, mp_srcptr b, mp_size_t n) -#else -mpn_mul_n (p, a, b, n) - mp_ptr p; - mp_srcptr a; - mp_srcptr b; - mp_size_t n; -#endif -{ - if (n < KARATSUBA_MUL_THRESHOLD) - mpn_mul_basecase (p, a, n, b, n); - else if (n < TOOM3_MUL_THRESHOLD) - { - /* Allocate workspace of fixed size on stack: fast! */ -#if TUNE_PROGRAM_BUILD - mp_limb_t ws[2 * (TOOM3_MUL_THRESHOLD_LIMIT-1) + 2 * BITS_PER_MP_LIMB]; -#else - mp_limb_t ws[2 * (TOOM3_MUL_THRESHOLD-1) + 2 * BITS_PER_MP_LIMB]; -#endif - mpn_kara_mul_n (p, a, b, n, ws); - } -#if WANT_FFT || TUNE_PROGRAM_BUILD - else if (n < FFT_MUL_THRESHOLD) -#else - else -#endif - { - /* Use workspace of unknown size in heap, as stack space may - * be limited. Since n is at least TOOM3_MUL_THRESHOLD, the - * multiplication will take much longer than malloc()/free(). */ - mp_limb_t wsLen, *ws; - wsLen = 2 * n + 3 * BITS_PER_MP_LIMB; - ws = (mp_ptr) (*_mp_allocate_func) ((size_t) wsLen * sizeof (mp_limb_t)); - mpn_toom3_mul_n (p, a, b, n, ws); - (*_mp_free_func) (ws, (size_t) wsLen * sizeof (mp_limb_t)); - } -#if WANT_FFT || TUNE_PROGRAM_BUILD - else - { - mpn_mul_fft_full (p, a, n, b, n); - } -#endif -} diff --git a/gmp/mpn/generic/perfsqr.c b/gmp/mpn/generic/perfsqr.c deleted file mode 100755 index 42ee340..0000000 --- a/gmp/mpn/generic/perfsqr.c +++ /dev/null @@ -1,123 +0,0 @@ -/* mpn_perfect_square_p(u,usize) -- Return non-zero if U is a perfect square, - zero otherwise. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* sq_res_0x100[x mod 0x100] == 1 iff x mod 0x100 is a quadratic residue - modulo 0x100. */ -static unsigned char const sq_res_0x100[0x100] = -{ - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, -}; - -int -#if __STDC__ -mpn_perfect_square_p (mp_srcptr up, mp_size_t usize) -#else -mpn_perfect_square_p (up, usize) - mp_srcptr up; - mp_size_t usize; -#endif -{ - mp_limb_t rem; - mp_ptr root_ptr; - int res; - TMP_DECL (marker); - - /* The first test excludes 55/64 (85.9%) of the perfect square candidates - in O(1) time. */ - if ((sq_res_0x100[(unsigned int) up[0] % 0x100] & 1) == 0) - return 0; - -#if defined (PP) - /* The second test excludes 30652543/30808063 (99.5%) of the remaining - perfect square candidates in O(n) time. */ - - /* Firstly, compute REM = A mod PP. */ - if (UDIV_TIME > (2 * UMUL_TIME + 6)) - rem = mpn_preinv_mod_1 (up, usize, (mp_limb_t) PP, (mp_limb_t) PP_INVERTED); - else - rem = mpn_mod_1 (up, usize, (mp_limb_t) PP); - - /* Now decide if REM is a quadratic residue modulo the factors in PP. */ - - /* If A is just a few limbs, computing the square root does not take long - time, so things might run faster if we limit this loop according to the - size of A. */ - -#if BITS_PER_MP_LIMB == 64 - if (((CNST_LIMB(0x12DD703303AED3) >> rem % 53) & 1) == 0) - return 0; - if (((CNST_LIMB(0x4351B2753DF) >> rem % 47) & 1) == 0) - return 0; - if (((CNST_LIMB(0x35883A3EE53) >> rem % 43) & 1) == 0) - return 0; - if (((CNST_LIMB(0x1B382B50737) >> rem % 41) & 1) == 0) - return 0; - if (((CNST_LIMB(0x165E211E9B) >> rem % 37) & 1) == 0) - return 0; - if (((CNST_LIMB(0x121D47B7) >> rem % 31) & 1) == 0) - return 0; -#endif - if (((0x13D122F3L >> rem % 29) & 1) == 0) - return 0; - if (((0x5335FL >> rem % 23) & 1) == 0) - return 0; - if (((0x30AF3L >> rem % 19) & 1) == 0) - return 0; - if (((0x1A317L >> rem % 17) & 1) == 0) - return 0; - if (((0x161BL >> rem % 13) & 1) == 0) - return 0; - if (((0x23BL >> rem % 11) & 1) == 0) - return 0; - if (((0x017L >> rem % 7) & 1) == 0) - return 0; - if (((0x13L >> rem % 5) & 1) == 0) - return 0; - if (((0x3L >> rem % 3) & 1) == 0) - return 0; -#endif - - TMP_MARK (marker); - - /* For the third and last test, we finally compute the square root, - to make sure we've really got a perfect square. */ - root_ptr = (mp_ptr) TMP_ALLOC ((usize + 1) / 2 * BYTES_PER_MP_LIMB); - - /* Iff mpn_sqrtrem returns zero, the square is perfect. */ - res = ! mpn_sqrtrem (root_ptr, NULL, up, usize); - TMP_FREE (marker); - return res; -} diff --git a/gmp/mpn/generic/popcount.c b/gmp/mpn/generic/popcount.c deleted file mode 100755 index 387be95..0000000 --- a/gmp/mpn/generic/popcount.c +++ /dev/null @@ -1,93 +0,0 @@ -/* popcount.c - -Copyright (C) 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#if defined __GNUC__ -/* No processor claiming to be SPARC v9 compliant seem to - implement the POPC instruction. Disable pattern for now. */ -#if 0 && defined __sparc_v9__ && BITS_PER_MP_LIMB == 64 -#define popc_limb(a) \ - ({ \ - DItype __res; \ - asm ("popc %1,%0" : "=r" (__res) : "rI" (a)); \ - __res; \ - }) -#endif -#endif - -#ifndef popc_limb - -/* Cool population count of a mp_limb_t. - You have to figure out how this works, I won't tell you! */ - -static inline unsigned int -#if __STDC__ -popc_limb (mp_limb_t x) -#else -popc_limb (x) - mp_limb_t x; -#endif -{ -#if BITS_PER_MP_LIMB == 64 - /* We have to go into some trouble to define these constants. - (For mp_limb_t being `long long'.) */ - mp_limb_t cnst; - cnst = 0xaaaaaaaaL | ((mp_limb_t) 0xaaaaaaaaL << BITS_PER_MP_LIMB/2); - x -= (x & cnst) >> 1; - cnst = 0x33333333L | ((mp_limb_t) 0x33333333L << BITS_PER_MP_LIMB/2); - x = ((x & ~cnst) >> 2) + (x & cnst); - cnst = 0x0f0f0f0fL | ((mp_limb_t) 0x0f0f0f0fL << BITS_PER_MP_LIMB/2); - x = ((x >> 4) + x) & cnst; - x = ((x >> 8) + x); - x = ((x >> 16) + x); - x = ((x >> 32) + x) & 0xff; -#endif -#if BITS_PER_MP_LIMB == 32 - x -= (x & 0xaaaaaaaa) >> 1; - x = ((x >> 2) & 0x33333333L) + (x & 0x33333333L); - x = ((x >> 4) + x) & 0x0f0f0f0fL; - x = ((x >> 8) + x); - x = ((x >> 16) + x) & 0xff; -#endif - return x; -} -#endif - -unsigned long int -#if __STDC__ -mpn_popcount (register mp_srcptr p, register mp_size_t size) -#else -mpn_popcount (p, size) - register mp_srcptr p; - register mp_size_t size; -#endif -{ - unsigned long int popcnt; - mp_size_t i; - - popcnt = 0; - for (i = 0; i < size; i++) - popcnt += popc_limb (p[i]); - - return popcnt; -} diff --git a/gmp/mpn/generic/pre_mod_1.c b/gmp/mpn/generic/pre_mod_1.c deleted file mode 100755 index 2717968..0000000 --- a/gmp/mpn/generic/pre_mod_1.c +++ /dev/null @@ -1,69 +0,0 @@ -/* mpn_preinv_mod_1 (dividend_ptr, dividend_size, divisor_limb, - divisor_limb_inverted) -- - Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by the normalized DIVISOR_LIMB. - DIVISOR_LIMB_INVERTED should be 2^(2*BITS_PER_MP_LIMB) / DIVISOR_LIMB + - - 2^BITS_PER_MP_LIMB. - Return the single-limb remainder. - -Copyright (C) 1991, 1993, 1994, Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#ifndef UMUL_TIME -#define UMUL_TIME 1 -#endif - -#ifndef UDIV_TIME -#define UDIV_TIME UMUL_TIME -#endif - -mp_limb_t -#if __STDC__ -mpn_preinv_mod_1 (mp_srcptr dividend_ptr, mp_size_t dividend_size, - mp_limb_t divisor_limb, mp_limb_t divisor_limb_inverted) -#else -mpn_preinv_mod_1 (dividend_ptr, dividend_size, divisor_limb, divisor_limb_inverted) - mp_srcptr dividend_ptr; - mp_size_t dividend_size; - mp_limb_t divisor_limb; - mp_limb_t divisor_limb_inverted; -#endif -{ - mp_size_t i; - mp_limb_t n0, r; - int dummy; - - i = dividend_size - 1; - r = dividend_ptr[i]; - - if (r >= divisor_limb) - r = 0; - else - i--; - - for (; i >= 0; i--) - { - n0 = dividend_ptr[i]; - udiv_qrnnd_preinv (dummy, r, r, n0, divisor_limb, divisor_limb_inverted); - } - return r; -} diff --git a/gmp/mpn/generic/random.c b/gmp/mpn/generic/random.c deleted file mode 100755 index dea4e20..0000000 --- a/gmp/mpn/generic/random.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpn_random -- Generate random numbers. - -Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void -#if __STDC__ -mpn_random (mp_ptr res_ptr, mp_size_t size) -#else -mpn_random (res_ptr, size) - mp_ptr res_ptr; - mp_size_t size; -#endif -{ - mp_size_t i; - - for (i = 0; i < size; i++) - res_ptr[i] = urandom (); - - /* Make sure the most significant limb is non-zero. */ - while (res_ptr[size - 1] == 0) - res_ptr[size - 1] = urandom (); -} diff --git a/gmp/mpn/generic/random2.c b/gmp/mpn/generic/random2.c deleted file mode 100755 index 7a507df..0000000 --- a/gmp/mpn/generic/random2.c +++ /dev/null @@ -1,97 +0,0 @@ -/* mpn_random2 -- Generate random numbers with relatively long strings - of ones and zeroes. Suitable for border testing. - -Copyright (C) 1992, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (__hpux) || defined (__alpha) || defined (__svr4__) || defined (__SVR4) -/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */ -long mrand48 (); -static inline long -random () -{ - return mrand48 (); -} -#else -long random (); -#endif - -/* It's a bit tricky to get this right, so please test the code well - if you hack with it. Some early versions of the function produced - random numbers with the leading limb == 0, and some versions never - made the most significant bit set. */ - -void -#if __STDC__ -mpn_random2 (mp_ptr res_ptr, mp_size_t size) -#else -mpn_random2 (res_ptr, size) - mp_ptr res_ptr; - mp_size_t size; -#endif -{ - int n_bits; - int bit_pos; - mp_size_t limb_pos; - unsigned int ran; - mp_limb_t limb; - - limb = 0; - - /* Start off in a random bit position in the most significant limb. */ - bit_pos = random () & (BITS_PER_MP_LIMB - 1); - - /* Least significant bit of RAN chooses string of ones/string of zeroes. - Make most significant limb be non-zero by setting bit 0 of RAN. */ - ran = random () | 1; - - for (limb_pos = size - 1; limb_pos >= 0; ) - { - n_bits = (ran >> 1) % BITS_PER_MP_LIMB + 1; - if ((ran & 1) != 0) - { - /* Generate a string of ones. */ - if (n_bits >= bit_pos) - { - res_ptr[limb_pos--] = limb | ((((mp_limb_t) 2) << bit_pos) - 1); - bit_pos += BITS_PER_MP_LIMB; - limb = (~(mp_limb_t) 0) << (bit_pos - n_bits); - } - else - { - limb |= ((((mp_limb_t) 1) << n_bits) - 1) << (bit_pos - n_bits + 1); - } - } - else - { - /* Generate a string of zeroes. */ - if (n_bits >= bit_pos) - { - res_ptr[limb_pos--] = limb; - limb = 0; - bit_pos += BITS_PER_MP_LIMB; - } - } - bit_pos -= n_bits; - ran = random (); - } -} diff --git a/gmp/mpn/generic/rshift.c b/gmp/mpn/generic/rshift.c deleted file mode 100755 index 59caf73..0000000 --- a/gmp/mpn/generic/rshift.c +++ /dev/null @@ -1,88 +0,0 @@ -/* mpn_rshift -- Shift right a low-level natural-number integer. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right - and store the USIZE least significant limbs of the result at WP. - The bits shifted out to the right are returned. - - Argument constraints: - 1. 0 < CNT < BITS_PER_MP_LIMB - 2. If the result is to be written over the input, WP must be <= UP. -*/ - -mp_limb_t -#if __STDC__ -mpn_rshift (register mp_ptr wp, - register mp_srcptr up, mp_size_t usize, - register unsigned int cnt) -#else -mpn_rshift (wp, up, usize, cnt) - register mp_ptr wp; - register mp_srcptr up; - mp_size_t usize; - register unsigned int cnt; -#endif -{ - register mp_limb_t high_limb, low_limb; - register unsigned sh_1, sh_2; - register mp_size_t i; - mp_limb_t retval; - -#ifdef DEBUG - if (usize == 0 || cnt == 0) - abort (); -#endif - - sh_1 = cnt; - -#if 0 - if (sh_1 == 0) - { - if (wp != up) - { - /* Copy from low end to high end, to allow specified input/output - overlapping. */ - for (i = 0; i < usize; i++) - wp[i] = up[i]; - } - return usize; - } -#endif - - wp -= 1; - sh_2 = BITS_PER_MP_LIMB - sh_1; - high_limb = up[0]; - retval = high_limb << sh_2; - low_limb = high_limb; - - for (i = 1; i < usize; i++) - { - high_limb = up[i]; - wp[i] = (low_limb >> sh_1) | (high_limb << sh_2); - low_limb = high_limb; - } - wp[i] = low_limb >> sh_1; - - return retval; -} diff --git a/gmp/mpn/generic/sb_divrem_mn.c b/gmp/mpn/generic/sb_divrem_mn.c deleted file mode 100755 index a269e34..0000000 --- a/gmp/mpn/generic/sb_divrem_mn.c +++ /dev/null @@ -1,201 +0,0 @@ -/* mpn_sb_divrem_mn -- Divide natural numbers, producing both remainder and - quotient. - - THE FUNCTIONS IN THIS FILE ARE INTERNAL FUNCTIONS WITH MUTABLE - INTERFACES. IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. - IN FACT, IT IS ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A - FUTURE GNU MP RELEASE. - - -Copyright (C) 1993, 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Divide num (NP/NSIZE) by den (DP/DSIZE) and write - the NSIZE-DSIZE least significant quotient limbs at QP - and the DSIZE long remainder at NP. If QEXTRA_LIMBS is - non-zero, generate that many fraction bits and append them after the - other quotient limbs. - Return the most significant limb of the quotient, this is always 0 or 1. - - Preconditions: - 0. NSIZE >= DSIZE. - 1. The most significant bit of the divisor must be set. - 2. QP must either not overlap with the input operands at all, or - QP + DSIZE >= NP must hold true. (This means that it's - possible to put the quotient in the high part of NUM, right after the - remainder in NUM. - 3. NSIZE >= DSIZE, even if QEXTRA_LIMBS is non-zero. - 4. DSIZE >= 2. */ - - -#define PREINVERT_VIABLE \ - (UDIV_TIME > 2 * UMUL_TIME + 6 /* && ! TARGET_REGISTER_STARVED */) - -mp_limb_t -#if __STDC__ -mpn_sb_divrem_mn (mp_ptr qp, - mp_ptr np, mp_size_t nsize, - mp_srcptr dp, mp_size_t dsize) -#else -mpn_sb_divrem_mn (qp, np, nsize, dp, dsize) - mp_ptr qp; - mp_ptr np; - mp_size_t nsize; - mp_srcptr dp; - mp_size_t dsize; -#endif -{ - mp_limb_t most_significant_q_limb = 0; - mp_size_t i; - mp_limb_t dx, d1, n0; - mp_limb_t dxinv; - int have_preinv; - - ASSERT_ALWAYS (dsize > 2); - - np += nsize - dsize; - dx = dp[dsize - 1]; - d1 = dp[dsize - 2]; - n0 = np[dsize - 1]; - - if (n0 >= dx) - { - if (n0 > dx || mpn_cmp (np, dp, dsize - 1) >= 0) - { - mpn_sub_n (np, np, dp, dsize); - most_significant_q_limb = 1; - } - } - - /* If multiplication is much faster than division, preinvert the - most significant divisor limb before entering the loop. */ - if (PREINVERT_VIABLE) - { - have_preinv = 0; - if ((UDIV_TIME - (2 * UMUL_TIME + 6)) * (nsize - dsize) > UDIV_TIME) - { - invert_limb (dxinv, dx); - have_preinv = 1; - } - } - - for (i = nsize - dsize - 1; i >= 0; i--) - { - mp_limb_t q; - mp_limb_t nx; - mp_limb_t cy_limb; - - nx = np[dsize - 1]; - np--; - - if (nx == dx) - { - /* This might over-estimate q, but it's probably not worth - the extra code here to find out. */ - q = ~(mp_limb_t) 0; - -#if 1 - cy_limb = mpn_submul_1 (np, dp, dsize, q); -#else - /* This should be faster on many machines */ - cy_limb = mpn_sub_n (np + 1, np + 1, dp, dsize); - cy = mpn_add_n (np, np, dp, dsize); - np[dsize] += cy; -#endif - - if (nx != cy_limb) - { - mpn_add_n (np, np, dp, dsize); - q--; - } - - qp[i] = q; - } - else - { - mp_limb_t rx, r1, r0, p1, p0; - - /* "workaround" avoids a problem with gcc 2.7.2.3 i386 register - usage when np[dsize-1] is used in an asm statement like - umul_ppmm in udiv_qrnnd_preinv. The symptom is seg faults due - to registers being clobbered. gcc 2.95 i386 doesn't have the - problem. */ - { - mp_limb_t workaround = np[dsize - 1]; - if (PREINVERT_VIABLE && have_preinv) - udiv_qrnnd_preinv (q, r1, nx, workaround, dx, dxinv); - else - udiv_qrnnd (q, r1, nx, workaround, dx); - } - umul_ppmm (p1, p0, d1, q); - - r0 = np[dsize - 2]; - rx = 0; - if (r1 < p1 || (r1 == p1 && r0 < p0)) - { - p1 -= p0 < d1; - p0 -= d1; - q--; - r1 += dx; - rx = r1 < dx; - } - - p1 += r0 < p0; /* cannot carry! */ - rx -= r1 < p1; /* may become 11..1 if q is still too large */ - r1 -= p1; - r0 -= p0; - - cy_limb = mpn_submul_1 (np, dp, dsize - 2, q); - - { - mp_limb_t cy1, cy2; - cy1 = r0 < cy_limb; - r0 -= cy_limb; - cy2 = r1 < cy1; - r1 -= cy1; - np[dsize - 1] = r1; - np[dsize - 2] = r0; - if (cy2 != rx) - { - mpn_add_n (np, np, dp, dsize); - q--; - } - } - qp[i] = q; - } - } - - /* ______ ______ ______ - |__rx__|__r1__|__r0__| partial remainder - ______ ______ - - |__p1__|__p0__| partial product to subtract - ______ ______ - - |______|cylimb| - - rx is -1, 0 or 1. If rx=1, then q is correct (it should match - carry out). If rx=-1 then q is too large. If rx=0, then q might - be too large, but it is most likely correct. - */ - - return most_significant_q_limb; -} diff --git a/gmp/mpn/generic/scan0.c b/gmp/mpn/generic/scan0.c deleted file mode 100755 index 96f05ce..0000000 --- a/gmp/mpn/generic/scan0.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpn_scan0 -- Scan from a given bit position for the next clear bit. - -Copyright (C) 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Design issues: - 1. What if starting_bit is not within U? Caller's problem? - 2. Bit index should be 'unsigned'? - - Argument constraints: - 1. U must sooner ot later have a limb with a clear bit. - */ - -unsigned long int -#if __STDC__ -mpn_scan0 (register mp_srcptr up, - register unsigned long int starting_bit) -#else -mpn_scan0 (up, starting_bit) - register mp_srcptr up; - register unsigned long int starting_bit; -#endif -{ - mp_size_t starting_word; - mp_limb_t alimb; - int cnt; - mp_srcptr p; - - /* Start at the word implied by STARTING_BIT. */ - starting_word = starting_bit / BITS_PER_MP_LIMB; - p = up + starting_word; - alimb = ~*p++; - - /* Mask off any bits before STARTING_BIT in the first limb. */ - alimb &= - (mp_limb_t) 1 << (starting_bit % BITS_PER_MP_LIMB); - - while (alimb == 0) - alimb = ~*p++; - - count_leading_zeros (cnt, alimb & -alimb); - return (p - up) * BITS_PER_MP_LIMB - 1 - cnt; -} diff --git a/gmp/mpn/generic/scan1.c b/gmp/mpn/generic/scan1.c deleted file mode 100755 index 98e2e0d..0000000 --- a/gmp/mpn/generic/scan1.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpn_scan1 -- Scan from a given bit position for the next set bit. - -Copyright (C) 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Design issues: - 1. What if starting_bit is not within U? Caller's problem? - 2. Bit index should be 'unsigned'? - - Argument constraints: - 1. U must sooner ot later have a limb != 0. - */ - -unsigned long int -#if __STDC__ -mpn_scan1 (register mp_srcptr up, - register unsigned long int starting_bit) -#else -mpn_scan1 (up, starting_bit) - register mp_srcptr up; - register unsigned long int starting_bit; -#endif -{ - mp_size_t starting_word; - mp_limb_t alimb; - int cnt; - mp_srcptr p; - - /* Start at the word implied by STARTING_BIT. */ - starting_word = starting_bit / BITS_PER_MP_LIMB; - p = up + starting_word; - alimb = *p++; - - /* Mask off any bits before STARTING_BIT in the first limb. */ - alimb &= - (mp_limb_t) 1 << (starting_bit % BITS_PER_MP_LIMB); - - while (alimb == 0) - alimb = *p++; - - count_leading_zeros (cnt, alimb & -alimb); - return (p - up) * BITS_PER_MP_LIMB - 1 - cnt; -} diff --git a/gmp/mpn/generic/set_str.c b/gmp/mpn/generic/set_str.c deleted file mode 100755 index e6ccc92..0000000 --- a/gmp/mpn/generic/set_str.c +++ /dev/null @@ -1,159 +0,0 @@ -/* mpn_set_str (mp_ptr res_ptr, const char *str, size_t str_len, int base) - -- Convert a STR_LEN long base BASE byte string pointed to by STR to a - limb vector pointed to by RES_PTR. Return the number of limbs in - RES_PTR. - -Copyright (C) 1991, 1992, 1993, 1994, 1996, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_size_t -#if __STDC__ -mpn_set_str (mp_ptr xp, const unsigned char *str, size_t str_len, int base) -#else -mpn_set_str (xp, str, str_len, base) - mp_ptr xp; - const unsigned char *str; - size_t str_len; - int base; -#endif -{ - mp_size_t size; - mp_limb_t big_base; - int indigits_per_limb; - mp_limb_t res_digit; - - big_base = __mp_bases[base].big_base; - indigits_per_limb = __mp_bases[base].chars_per_limb; - -/* size = str_len / indigits_per_limb + 1; */ - - size = 0; - - if ((base & (base - 1)) == 0) - { - /* The base is a power of 2. Read the input string from - least to most significant character/digit. */ - - const unsigned char *s; - int next_bitpos; - int bits_per_indigit = big_base; - - res_digit = 0; - next_bitpos = 0; - - for (s = str + str_len - 1; s >= str; s--) - { - int inp_digit = *s; - - res_digit |= (mp_limb_t) inp_digit << next_bitpos; - next_bitpos += bits_per_indigit; - if (next_bitpos >= BITS_PER_MP_LIMB) - { - xp[size++] = res_digit; - next_bitpos -= BITS_PER_MP_LIMB; - res_digit = inp_digit >> (bits_per_indigit - next_bitpos); - } - } - - if (res_digit != 0) - xp[size++] = res_digit; - } - else - { - /* General case. The base is not a power of 2. */ - - size_t i; - int j; - mp_limb_t cy_limb; - - for (i = indigits_per_limb; i < str_len; i += indigits_per_limb) - { - res_digit = *str++; - if (base == 10) - { /* This is a common case. - Help the compiler to avoid multiplication. */ - for (j = 1; j < indigits_per_limb; j++) - res_digit = res_digit * 10 + *str++; - } - else - { - for (j = 1; j < indigits_per_limb; j++) - res_digit = res_digit * base + *str++; - } - - if (size == 0) - { - if (res_digit != 0) - { - xp[0] = res_digit; - size = 1; - } - } - else - { - cy_limb = mpn_mul_1 (xp, xp, size, big_base); - cy_limb += mpn_add_1 (xp, xp, size, res_digit); - if (cy_limb != 0) - xp[size++] = cy_limb; - } - } - - big_base = base; - res_digit = *str++; - if (base == 10) - { /* This is a common case. - Help the compiler to avoid multiplication. */ - for (j = 1; j < str_len - (i - indigits_per_limb); j++) - { - res_digit = res_digit * 10 + *str++; - big_base *= 10; - } - } - else - { - for (j = 1; j < str_len - (i - indigits_per_limb); j++) - { - res_digit = res_digit * base + *str++; - big_base *= base; - } - } - - if (size == 0) - { - if (res_digit != 0) - { - xp[0] = res_digit; - size = 1; - } - } - else - { - cy_limb = mpn_mul_1 (xp, xp, size, big_base); - cy_limb += mpn_add_1 (xp, xp, size, res_digit); - if (cy_limb != 0) - xp[size++] = cy_limb; - } - } - - return size; -} diff --git a/gmp/mpn/generic/sqr_basecase.c b/gmp/mpn/generic/sqr_basecase.c deleted file mode 100755 index 760258a..0000000 --- a/gmp/mpn/generic/sqr_basecase.c +++ /dev/null @@ -1,83 +0,0 @@ -/* mpn_sqr_basecase -- Internal routine to square two natural numbers - of length m and n. - - THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS ONLY - SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES. - - -Copyright (C) 1991, 1992, 1993, 1994, 1996, 1997, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpn_sqr_basecase (mp_ptr prodp, mp_srcptr up, mp_size_t n) -#else -mpn_sqr_basecase (prodp, up, n) - mp_ptr prodp; - mp_srcptr up; - mp_size_t n; -#endif -{ - mp_size_t i; - - { - /* N.B.! We need the superfluous indirection through argh to work around - a reloader bug in GCC 2.7.*. */ - mp_limb_t x; - mp_limb_t argh; - x = up[0]; - umul_ppmm (argh, prodp[0], x, x); - prodp[1] = argh; - } - if (n > 1) - { - mp_limb_t tarr[2 * KARATSUBA_SQR_THRESHOLD]; - mp_ptr tp = tarr; - mp_limb_t cy; - - /* must fit 2*n limbs in tarr */ - ASSERT (n <= KARATSUBA_SQR_THRESHOLD); - - cy = mpn_mul_1 (tp, up + 1, n - 1, up[0]); - tp[n - 1] = cy; - for (i = 2; i < n; i++) - { - mp_limb_t cy; - cy = mpn_addmul_1 (tp + 2 * i - 2, up + i, n - i, up[i - 1]); - tp[n + i - 2] = cy; - } - for (i = 1; i < n; i++) - { - mp_limb_t x; - x = up[i]; - umul_ppmm (prodp[2 * i + 1], prodp[2 * i], x, x); - } - { - mp_limb_t cy; - cy = mpn_lshift (tp, tp, 2 * n - 2, 1); - cy += mpn_add_n (prodp + 1, prodp + 1, tp, 2 * n - 2); - prodp[2 * n - 1] += cy; - } - } -} diff --git a/gmp/mpn/generic/sqrtrem.c b/gmp/mpn/generic/sqrtrem.c deleted file mode 100755 index ee3b514..0000000 --- a/gmp/mpn/generic/sqrtrem.c +++ /dev/null @@ -1,509 +0,0 @@ -/* mpn_sqrtrem (root_ptr, rem_ptr, op_ptr, op_size) - - Write the square root of {OP_PTR, OP_SIZE} at ROOT_PTR. - Write the remainder at REM_PTR, if REM_PTR != NULL. - Return the size of the remainder. - (The size of the root is always half of the size of the operand.) - - OP_PTR and ROOT_PTR may not point to the same object. - OP_PTR and REM_PTR may point to the same object. - - If REM_PTR is NULL, only the root is computed and the return value of - the function is 0 if OP is a perfect square, and *any* non-zero number - otherwise. - -Copyright (C) 1993, 1994, 1996, 1997, 1998, 1999, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* This code is just correct if "unsigned char" has at least 8 bits. It - doesn't help to use CHAR_BIT from limits.h, as the real problem is - the static arrays. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Square root algorithm: - - 1. Shift OP (the input) to the left an even number of bits s.t. there - are an even number of words and either (or both) of the most - significant bits are set. This way, sqrt(OP) has exactly half as - many words as OP, and has its most significant bit set. - - 2. Get a 9-bit approximation to sqrt(OP) using the pre-computed tables. - This approximation is used for the first single-precision - iterations of Newton's method, yielding a full-word approximation - to sqrt(OP). - - 3. Perform multiple-precision Newton iteration until we have the - exact result. Only about half of the input operand is used in - this calculation, as the square root is perfectly determinable - from just the higher half of a number. */ - -/* Define this macro for IEEE P854 machines with a fast sqrt instruction. */ -#if defined __GNUC__ && ! defined __SOFT_FLOAT - -#if defined (__sparc__) && BITS_PER_MP_LIMB == 32 -#define SQRT(a) \ - ({ \ - double __sqrt_res; \ - asm ("fsqrtd %1,%0" : "=f" (__sqrt_res) : "f" (a)); \ - __sqrt_res; \ - }) -#endif - -#if defined (__HAVE_68881__) -#define SQRT(a) \ - ({ \ - double __sqrt_res; \ - asm ("fsqrtx %1,%0" : "=f" (__sqrt_res) : "f" (a)); \ - __sqrt_res; \ - }) -#endif - -#if defined (__hppa) && BITS_PER_MP_LIMB == 32 -#define SQRT(a) \ - ({ \ - double __sqrt_res; \ - asm ("fsqrt,dbl %1,%0" : "=fx" (__sqrt_res) : "fx" (a)); \ - __sqrt_res; \ - }) -#endif - -#if defined (_ARCH_PWR2) && BITS_PER_MP_LIMB == 32 -#define SQRT(a) \ - ({ \ - double __sqrt_res; \ - asm ("fsqrt %0,%1" : "=f" (__sqrt_res) : "f" (a)); \ - __sqrt_res; \ - }) -#endif - -#if 0 -#if defined (__i386__) || defined (__i486__) -#define SQRT(a) \ - ({ \ - double __sqrt_res; \ - asm ("fsqrt" : "=t" (__sqrt_res) : "0" (a)); \ - __sqrt_res; \ - }) -#endif -#endif - -#endif - -#ifndef SQRT - -/* Tables for initial approximation of the square root. These are - indexed with bits 1-8 of the operand for which the square root is - calculated, where bit 0 is the most significant non-zero bit. I.e. - the most significant one-bit is not used, since that per definition - is one. Likewise, the tables don't return the highest bit of the - result. That bit must be inserted by or:ing the returned value with - 0x100. This way, we get a 9-bit approximation from 8-bit tables! */ - -/* Table to be used for operands with an even total number of bits. - (Exactly as in the decimal system there are similarities between the - square root of numbers with the same initial digits and an even - difference in the total number of digits. Consider the square root - of 1, 10, 100, 1000, ...) */ -static const unsigned char even_approx_tab[256] = -{ - 0x6a, 0x6a, 0x6b, 0x6c, 0x6c, 0x6d, 0x6e, 0x6e, - 0x6f, 0x70, 0x71, 0x71, 0x72, 0x73, 0x73, 0x74, - 0x75, 0x75, 0x76, 0x77, 0x77, 0x78, 0x79, 0x79, - 0x7a, 0x7b, 0x7b, 0x7c, 0x7d, 0x7d, 0x7e, 0x7f, - 0x80, 0x80, 0x81, 0x81, 0x82, 0x83, 0x83, 0x84, - 0x85, 0x85, 0x86, 0x87, 0x87, 0x88, 0x89, 0x89, - 0x8a, 0x8b, 0x8b, 0x8c, 0x8d, 0x8d, 0x8e, 0x8f, - 0x8f, 0x90, 0x90, 0x91, 0x92, 0x92, 0x93, 0x94, - 0x94, 0x95, 0x96, 0x96, 0x97, 0x97, 0x98, 0x99, - 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9c, 0x9d, 0x9e, - 0x9e, 0x9f, 0xa0, 0xa0, 0xa1, 0xa1, 0xa2, 0xa3, - 0xa3, 0xa4, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa7, - 0xa8, 0xa9, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xac, - 0xad, 0xad, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1, - 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb5, 0xb5, 0xb6, - 0xb6, 0xb7, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xba, - 0xbb, 0xbb, 0xbc, 0xbd, 0xbd, 0xbe, 0xbe, 0xbf, - 0xc0, 0xc0, 0xc1, 0xc1, 0xc2, 0xc2, 0xc3, 0xc3, - 0xc4, 0xc5, 0xc5, 0xc6, 0xc6, 0xc7, 0xc7, 0xc8, - 0xc9, 0xc9, 0xca, 0xca, 0xcb, 0xcb, 0xcc, 0xcc, - 0xcd, 0xce, 0xce, 0xcf, 0xcf, 0xd0, 0xd0, 0xd1, - 0xd1, 0xd2, 0xd3, 0xd3, 0xd4, 0xd4, 0xd5, 0xd5, - 0xd6, 0xd6, 0xd7, 0xd7, 0xd8, 0xd9, 0xd9, 0xda, - 0xda, 0xdb, 0xdb, 0xdc, 0xdc, 0xdd, 0xdd, 0xde, - 0xde, 0xdf, 0xe0, 0xe0, 0xe1, 0xe1, 0xe2, 0xe2, - 0xe3, 0xe3, 0xe4, 0xe4, 0xe5, 0xe5, 0xe6, 0xe6, - 0xe7, 0xe7, 0xe8, 0xe8, 0xe9, 0xea, 0xea, 0xeb, - 0xeb, 0xec, 0xec, 0xed, 0xed, 0xee, 0xee, 0xef, - 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf3, - 0xf3, 0xf4, 0xf4, 0xf5, 0xf5, 0xf6, 0xf6, 0xf7, - 0xf7, 0xf8, 0xf8, 0xf9, 0xf9, 0xfa, 0xfa, 0xfb, - 0xfb, 0xfc, 0xfc, 0xfd, 0xfd, 0xfe, 0xfe, 0xff, -}; - -/* Table to be used for operands with an odd total number of bits. - (Further comments before previous table.) */ -static const unsigned char odd_approx_tab[256] = -{ - 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, - 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, - 0x07, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, 0x0b, - 0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0f, - 0x0f, 0x10, 0x10, 0x10, 0x11, 0x11, 0x12, 0x12, - 0x13, 0x13, 0x14, 0x14, 0x15, 0x15, 0x16, 0x16, - 0x16, 0x17, 0x17, 0x18, 0x18, 0x19, 0x19, 0x1a, - 0x1a, 0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, - 0x1e, 0x1e, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x21, - 0x21, 0x22, 0x22, 0x23, 0x23, 0x23, 0x24, 0x24, - 0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x27, 0x28, - 0x28, 0x29, 0x29, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b, - 0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2f, - 0x2f, 0x30, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, - 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x35, - 0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x39, - 0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3c, - 0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3f, 0x3f, - 0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x42, 0x42, - 0x43, 0x43, 0x43, 0x44, 0x44, 0x45, 0x45, 0x45, - 0x46, 0x46, 0x47, 0x47, 0x47, 0x48, 0x48, 0x49, - 0x49, 0x49, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4c, - 0x4c, 0x4c, 0x4d, 0x4d, 0x4e, 0x4e, 0x4e, 0x4f, - 0x4f, 0x50, 0x50, 0x50, 0x51, 0x51, 0x51, 0x52, - 0x52, 0x53, 0x53, 0x53, 0x54, 0x54, 0x54, 0x55, - 0x55, 0x56, 0x56, 0x56, 0x57, 0x57, 0x57, 0x58, - 0x58, 0x59, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b, - 0x5b, 0x5b, 0x5c, 0x5c, 0x5d, 0x5d, 0x5d, 0x5e, - 0x5e, 0x5e, 0x5f, 0x5f, 0x60, 0x60, 0x60, 0x61, - 0x61, 0x61, 0x62, 0x62, 0x62, 0x63, 0x63, 0x63, - 0x64, 0x64, 0x65, 0x65, 0x65, 0x66, 0x66, 0x66, - 0x67, 0x67, 0x67, 0x68, 0x68, 0x68, 0x69, 0x69, -}; -#endif - - -mp_size_t -#if __STDC__ -mpn_sqrtrem (mp_ptr root_ptr, mp_ptr rem_ptr, mp_srcptr op_ptr, mp_size_t op_size) -#else -mpn_sqrtrem (root_ptr, rem_ptr, op_ptr, op_size) - mp_ptr root_ptr; - mp_ptr rem_ptr; - mp_srcptr op_ptr; - mp_size_t op_size; -#endif -{ - /* R (root result) */ - mp_ptr rp; /* Pointer to least significant word */ - mp_size_t rsize; /* The size in words */ - - /* T (OP shifted to the left a.k.a. normalized) */ - mp_ptr tp; /* Pointer to least significant word */ - mp_size_t tsize; /* The size in words */ - mp_ptr t_end_ptr; /* Pointer right beyond most sign. word */ - mp_limb_t t_high0, t_high1; /* The two most significant words */ - - /* TT (temporary for numerator/remainder) */ - mp_ptr ttp; /* Pointer to least significant word */ - - /* X (temporary for quotient in main loop) */ - mp_ptr xp; /* Pointer to least significant word */ - mp_size_t xsize; /* The size in words */ - - unsigned cnt; - mp_limb_t initial_approx; /* Initially made approximation */ - mp_size_t tsizes[BITS_PER_MP_LIMB]; /* Successive calculation precisions */ - mp_size_t tmp; - mp_size_t i; - - mp_limb_t cy_limb; - TMP_DECL (marker); - - /* If OP is zero, both results are zero. */ - if (op_size == 0) - return 0; - - count_leading_zeros (cnt, op_ptr[op_size - 1]); - tsize = op_size; - if ((tsize & 1) != 0) - { - cnt += BITS_PER_MP_LIMB; - tsize++; - } - - rsize = tsize / 2; - rp = root_ptr; - - TMP_MARK (marker); - - /* Shift OP an even number of bits into T, such that either the most or - the second most significant bit is set, and such that the number of - words in T becomes even. This way, the number of words in R=sqrt(OP) - is exactly half as many as in OP, and the most significant bit of R - is set. - - Also, the initial approximation is simplified by this up-shifted OP. - - Finally, the Newtonian iteration which is the main part of this - program performs division by R. The fast division routine expects - the divisor to be "normalized" in exactly the sense of having the - most significant bit set. */ - - tp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB); - - if ((cnt & ~1) % BITS_PER_MP_LIMB != 0) - t_high0 = mpn_lshift (tp + cnt / BITS_PER_MP_LIMB, op_ptr, op_size, - (cnt & ~1) % BITS_PER_MP_LIMB); - else - MPN_COPY (tp + cnt / BITS_PER_MP_LIMB, op_ptr, op_size); - - if (cnt >= BITS_PER_MP_LIMB) - tp[0] = 0; - - t_high0 = tp[tsize - 1]; - t_high1 = tp[tsize - 2]; /* Never stray. TSIZE is >= 2. */ - -/* Is there a fast sqrt instruction defined for this machine? */ -#ifdef SQRT - { - initial_approx = SQRT (t_high0 * MP_BASE_AS_DOUBLE + t_high1); - /* If t_high0,,t_high1 is big, the result in INITIAL_APPROX might have - become incorrect due to overflow in the conversion from double to - mp_limb_t above. It will typically be zero in that case, but might be - a small number on some machines. The most significant bit of - INITIAL_APPROX should be set, so that bit is a good overflow - indication. */ - if ((mp_limb_signed_t) initial_approx >= 0) - initial_approx = ~(mp_limb_t)0; - } -#else - /* Get a 9 bit approximation from the tables. The tables expect to - be indexed with the 8 high bits right below the highest bit. - Also, the highest result bit is not returned by the tables, and - must be or:ed into the result. The scheme gives 9 bits of start - approximation with just 256-entry 8 bit tables. */ - - if ((cnt & 1) == 0) - { - /* The most significant bit of t_high0 is set. */ - initial_approx = t_high0 >> (BITS_PER_MP_LIMB - 8 - 1); - initial_approx &= 0xff; - initial_approx = even_approx_tab[initial_approx]; - } - else - { - /* The most significant bit of t_high0 is unset, - the second most significant is set. */ - initial_approx = t_high0 >> (BITS_PER_MP_LIMB - 8 - 2); - initial_approx &= 0xff; - initial_approx = odd_approx_tab[initial_approx]; - } - initial_approx |= 0x100; - initial_approx <<= BITS_PER_MP_LIMB - 8 - 1; - - /* Perform small precision Newtonian iterations to get a full word - approximation. For small operands, these iterations will do the - entire job. */ - if (t_high0 == ~(mp_limb_t)0) - initial_approx = t_high0; - else - { - mp_limb_t quot; - - if (t_high0 >= initial_approx) - initial_approx = t_high0 + 1; - - /* First get about 18 bits with pure C arithmetics. */ - quot = t_high0 / (initial_approx >> BITS_PER_MP_LIMB/2) << BITS_PER_MP_LIMB/2; - initial_approx = (initial_approx + quot) / 2; - initial_approx |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1); - - /* Now get a full word by one (or for > 36 bit machines) several - iterations. */ - for (i = 18; i < BITS_PER_MP_LIMB; i <<= 1) - { - mp_limb_t ignored_remainder; - - udiv_qrnnd (quot, ignored_remainder, - t_high0, t_high1, initial_approx); - initial_approx = (initial_approx + quot) / 2; - initial_approx |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1); - } - } -#endif - - rp[0] = initial_approx; - rsize = 1; - -#ifdef SQRT_DEBUG - printf ("\n\nT = "); - mpn_dump (tp, tsize); -#endif - - if (tsize > 2) - { - /* Determine the successive precisions to use in the iteration. We - minimize the precisions, beginning with the highest (i.e. last - iteration) to the lowest (i.e. first iteration). */ - - xp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB); - ttp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB); - - t_end_ptr = tp + tsize; - - tmp = tsize / 2; - for (i = 0;; i++) - { - tsize = (tmp + 1) / 2; - if (tmp == tsize) - break; - tsizes[i] = tsize + tmp; - tmp = tsize; - } - - /* Main Newton iteration loop. For big arguments, most of the - time is spent here. */ - - /* It is possible to do a great optimization here. The successive - divisors in the mpn_divmod call below have more and more leading - words equal to its predecessor. Therefore the beginning of - each division will repeat the same work as did the last - division. If we could guarantee that the leading words of two - consecutive divisors are the same (i.e. in this case, a later - divisor has just more digits at the end) it would be a simple - matter of just using the old remainder of the last division in - a subsequent division, to take care of this optimization. This - idea would surely make a difference even for small arguments. */ - - /* Loop invariants: - - R <= shiftdown_to_same_size(floor(sqrt(OP))) < R + 1. - X - 1 < shiftdown_to_same_size(floor(sqrt(OP))) <= X. - R <= shiftdown_to_same_size(X). */ - - while (--i >= 0) - { - mp_limb_t cy; -#ifdef SQRT_DEBUG - mp_limb_t old_least_sign_r = rp[0]; - mp_size_t old_rsize = rsize; - - printf ("R = "); - mpn_dump (rp, rsize); -#endif - tsize = tsizes[i]; - - /* Need to copy the numerator into temporary space, as - mpn_divmod overwrites its numerator argument with the - remainder (which we currently ignore). */ - MPN_COPY (ttp, t_end_ptr - tsize, tsize); - cy = mpn_divmod (xp, ttp, tsize, rp, rsize); - xsize = tsize - rsize; - -#ifdef SQRT_DEBUG - printf ("X =%d ", cy); - mpn_dump (xp, xsize); -#endif - - /* Add X and R with the most significant limbs aligned, - temporarily ignoring at least one limb at the low end of X. */ - tmp = xsize - rsize; - cy += mpn_add_n (xp + tmp, rp, xp + tmp, rsize); - - /* If T begins with more than 2 x BITS_PER_MP_LIMB of ones, we get - intermediate roots that'd need an extra bit. We don't want to - handle that since it would make the subsequent divisor - non-normalized, so round such roots down to be only ones in the - current precision. */ - if (cy == 2) - { - mp_size_t j; - for (j = xsize; j >= 0; j--) - xp[j] = ~(mp_limb_t)0; - } - - /* Divide X by 2 and put the result in R. This is the new - approximation. Shift in the carry from the addition. */ - mpn_rshift (rp, xp, xsize, 1); - rp[xsize - 1] |= ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)); - rsize = xsize; -#ifdef SQRT_DEBUG - if (old_least_sign_r != rp[rsize - old_rsize]) - printf (">>>>>>>> %d: %0*lX, %0*lX <<<<<<<<\n", - i, 2 * BYTES_PER_MP_LIMB, old_least_sign_r, - 2 * BYTES_PER_MP_LIMB, rp[rsize - old_rsize]); -#endif - } - } - -#ifdef SQRT_DEBUG - printf ("(final) R = "); - mpn_dump (rp, rsize); -#endif - - /* We computed the square root of OP * 2**(2*floor(cnt/2)). - This has resulted in R being 2**floor(cnt/2) to large. - Shift it down here to fix that. */ - if (cnt / 2 != 0) - { - mpn_rshift (rp, rp, rsize, cnt/2); - rsize -= rp[rsize - 1] == 0; - } - - /* Calculate the remainder. */ - mpn_mul_n (tp, rp, rp, rsize); - tsize = rsize + rsize; - tsize -= tp[tsize - 1] == 0; - if (op_size < tsize - || (op_size == tsize && mpn_cmp (op_ptr, tp, op_size) < 0)) - { - /* R is too large. Decrement it. */ - - /* These operations can't overflow. */ - cy_limb = mpn_sub_n (tp, tp, rp, rsize); - cy_limb += mpn_sub_n (tp, tp, rp, rsize); - mpn_decr_u (tp + rsize, cy_limb); - mpn_incr_u (tp, (mp_limb_t) 1); - - mpn_decr_u (rp, (mp_limb_t) 1); - -#ifdef SQRT_DEBUG - printf ("(adjusted) R = "); - mpn_dump (rp, rsize); -#endif - } - - if (rem_ptr != NULL) - { - cy_limb = mpn_sub (rem_ptr, op_ptr, op_size, tp, tsize); - MPN_NORMALIZE (rem_ptr, op_size); - TMP_FREE (marker); - return op_size; - } - else - { - int res; - res = op_size != tsize || mpn_cmp (op_ptr, tp, op_size); - TMP_FREE (marker); - return res; - } -} diff --git a/gmp/mpn/generic/sub_n.c b/gmp/mpn/generic/sub_n.c deleted file mode 100755 index 4f2f060..0000000 --- a/gmp/mpn/generic/sub_n.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpn_sub_n -- Subtract two limb vectors of equal, non-zero length. - -Copyright (C) 1992, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -#if __STDC__ -mpn_sub_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) -#else -mpn_sub_n (res_ptr, s1_ptr, s2_ptr, size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_srcptr s2_ptr; - mp_size_t size; -#endif -{ - register mp_limb_t x, y, cy; - register mp_size_t j; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - s2_ptr -= j; - res_ptr -= j; - - cy = 0; - do - { - y = s2_ptr[j]; - x = s1_ptr[j]; - y += cy; /* add previous carry to subtrahend */ - cy = (y < cy); /* get out carry from that addition */ - y = x - y; /* main subtract */ - cy = (y > x) + cy; /* get out carry from the subtract, combine */ - res_ptr[j] = y; - } - while (++j != 0); - - return cy; -} diff --git a/gmp/mpn/generic/submul_1.c b/gmp/mpn/generic/submul_1.c deleted file mode 100755 index c7c08ee..0000000 --- a/gmp/mpn/generic/submul_1.c +++ /dev/null @@ -1,65 +0,0 @@ -/* mpn_submul_1 -- multiply the S1_SIZE long limb vector pointed to by S1_PTR - by S2_LIMB, subtract the S1_SIZE least significant limbs of the product - from the limb vector pointed to by RES_PTR. Return the most significant - limb of the product, adjusted for carry-out from the subtraction. - -Copyright (C) 1992, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -mp_limb_t -mpn_submul_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - mp_size_t s1_size; - register mp_limb_t s2_limb; -{ - register mp_limb_t cy_limb; - register mp_size_t j; - register mp_limb_t prod_high, prod_low; - register mp_limb_t x; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -s1_size; - - /* Offset the base pointers to compensate for the negative indices. */ - res_ptr -= j; - s1_ptr -= j; - - cy_limb = 0; - do - { - umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb); - - prod_low += cy_limb; - cy_limb = (prod_low < cy_limb) + prod_high; - - x = res_ptr[j]; - prod_low = x - prod_low; - cy_limb += (prod_low > x); - res_ptr[j] = prod_low; - } - while (++j != 0); - - return cy_limb; -} diff --git a/gmp/mpn/generic/tdiv_qr.c b/gmp/mpn/generic/tdiv_qr.c deleted file mode 100755 index b748b5d..0000000 --- a/gmp/mpn/generic/tdiv_qr.c +++ /dev/null @@ -1,401 +0,0 @@ -/* mpn_tdiv_qr -- Divide the numerator (np,nn) by the denominator (dp,dn) and - write the nn-dn+1 quotient limbs at qp and the dn remainder limbs at rp. If - qxn is non-zero, generate that many fraction limbs and append them after the - other quotient limbs, and update the remainder accordningly. The input - operands are unaffected. - - Preconditions: - 1. The most significant limb of of the divisor must be non-zero. - 2. No argument overlap is permitted. (??? relax this ???) - 3. nn >= dn, even if qxn is non-zero. (??? relax this ???) - - The time complexity of this is O(qn*qn+M(dn,qn)), where M(m,n) is the time - complexity of multiplication. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD (7 * KARATSUBA_MUL_THRESHOLD) -#endif - -/* Extract the middle limb from ((h,,l) << cnt) */ -#define SHL(h,l,cnt) \ - ((h << cnt) | ((l >> 1) >> ((~cnt) & (BITS_PER_MP_LIMB - 1)))) - -void -#if __STDC__ -mpn_tdiv_qr (mp_ptr qp, mp_ptr rp, mp_size_t qxn, - mp_srcptr np, mp_size_t nn, mp_srcptr dp, mp_size_t dn) -#else -mpn_tdiv_qr (qp, rp, qxn, np, nn, dp, dn) - mp_ptr qp; - mp_ptr rp; - mp_size_t qxn; - mp_srcptr np; - mp_size_t nn; - mp_srcptr dp; - mp_size_t dn; -#endif -{ - /* FIXME: - 1. qxn - 2. pass allocated storage in additional parameter? - */ - if (qxn != 0) - abort (); - - switch (dn) - { - case 0: - DIVIDE_BY_ZERO; - - case 1: - { - rp[0] = mpn_divmod_1 (qp, np, nn, dp[0]); - return; - } - - case 2: - { - int cnt; - mp_ptr n2p, d2p; - mp_limb_t qhl, cy; - TMP_DECL (marker); - TMP_MARK (marker); - count_leading_zeros (cnt, dp[dn - 1]); - if (cnt != 0) - { - d2p = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB); - mpn_lshift (d2p, dp, dn, cnt); - n2p = (mp_ptr) TMP_ALLOC ((nn + 1) * BYTES_PER_MP_LIMB); - cy = mpn_lshift (n2p, np, nn, cnt); - n2p[nn] = cy; - qhl = mpn_divrem_2 (qp, 0L, n2p, nn + (cy != 0), d2p); - if (cy == 0) - qp[nn - 2] = qhl; /* always store nn-dn+1 quotient limbs */ - } - else - { - d2p = (mp_ptr) dp; - n2p = (mp_ptr) TMP_ALLOC (nn * BYTES_PER_MP_LIMB); - MPN_COPY (n2p, np, nn); - qhl = mpn_divrem_2 (qp, 0L, n2p, nn, d2p); - qp[nn - 2] = qhl; /* always store nn-dn+1 quotient limbs */ - } - - if (cnt != 0) - mpn_rshift (rp, n2p, dn, cnt); - else - MPN_COPY (rp, n2p, dn); - TMP_FREE (marker); - return; - } - - default: - { - int adjust; - TMP_DECL (marker); - TMP_MARK (marker); - adjust = np[nn - 1] >= dp[dn - 1]; /* conservative tests for quotient size */ - if (nn + adjust >= 2 * dn) - { - mp_ptr n2p, d2p; - mp_limb_t cy; - int cnt; - count_leading_zeros (cnt, dp[dn - 1]); - - qp[nn - dn] = 0; /* zero high quotient limb */ - if (cnt != 0) /* normalize divisor if needed */ - { - d2p = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB); - mpn_lshift (d2p, dp, dn, cnt); - n2p = (mp_ptr) TMP_ALLOC ((nn + 1) * BYTES_PER_MP_LIMB); - cy = mpn_lshift (n2p, np, nn, cnt); - n2p[nn] = cy; - nn += adjust; - } - else - { - d2p = (mp_ptr) dp; - n2p = (mp_ptr) TMP_ALLOC ((nn + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (n2p, np, nn); - n2p[nn] = 0; - nn += adjust; - } - - if (dn == 2) - mpn_divrem_2 (qp, 0L, n2p, nn, d2p); - else if (dn < BZ_THRESHOLD) - mpn_sb_divrem_mn (qp, n2p, nn, d2p, dn); - else - { - /* Perform 2*dn / dn limb divisions as long as the limbs - in np last. */ - mp_ptr q2p = qp + nn - 2 * dn; - n2p += nn - 2 * dn; - mpn_bz_divrem_n (q2p, n2p, d2p, dn); - nn -= dn; - while (nn >= 2 * dn) - { - mp_limb_t c; - q2p -= dn; n2p -= dn; - c = mpn_bz_divrem_n (q2p, n2p, d2p, dn); - ASSERT_ALWAYS (c == 0); - nn -= dn; - } - - if (nn != dn) - { - n2p -= nn - dn; - /* In theory, we could fall out to the cute code below - since we now have exactly the situation that code - is designed to handle. We botch this badly and call - the basic mpn_sb_divrem_mn! */ - if (dn == 2) - mpn_divrem_2 (qp, 0L, n2p, nn, d2p); - else - mpn_sb_divrem_mn (qp, n2p, nn, d2p, dn); - } - } - - - if (cnt != 0) - mpn_rshift (rp, n2p, dn, cnt); - else - MPN_COPY (rp, n2p, dn); - TMP_FREE (marker); - return; - } - - /* When we come here, the numerator/partial remainder is less - than twice the size of the denominator. */ - - { - /* Problem: - - Divide a numerator N with nn limbs by a denominator D with dn - limbs forming a quotient of nn-dn+1 limbs. When qn is small - compared to dn, conventional division algorithms perform poorly. - We want an algorithm that has an expected running time that is - dependent only on qn. It is assumed that the most significant - limb of the numerator is smaller than the most significant limb - of the denominator. - - Algorithm (very informally stated): - - 1) Divide the 2 x qn most significant limbs from the numerator - by the qn most significant limbs from the denominator. Call - the result qest. This is either the correct quotient, but - might be 1 or 2 too large. Compute the remainder from the - division. (This step is implemented by a mpn_divrem call.) - - 2) Is the most significant limb from the remainder < p, where p - is the product of the most significant limb from the quotient - and the next(d). (Next(d) denotes the next ignored limb from - the denominator.) If it is, decrement qest, and adjust the - remainder accordingly. - - 3) Is the remainder >= qest? If it is, qest is the desired - quotient. The algorithm terminates. - - 4) Subtract qest x next(d) from the remainder. If there is - borrow out, decrement qest, and adjust the remainder - accordingly. - - 5) Skip one word from the denominator (i.e., let next(d) denote - the next less significant limb. */ - - mp_size_t qn; - mp_ptr n2p, d2p; - mp_ptr tp; - mp_limb_t cy; - mp_size_t in, rn; - mp_limb_t quotient_too_large; - int cnt; - - qn = nn - dn; - qp[qn] = 0; /* zero high quotient limb */ - qn += adjust; /* qn cannot become bigger */ - - if (qn == 0) - { - MPN_COPY (rp, np, dn); - TMP_FREE (marker); - return; - } - - in = dn - qn; /* (at least partially) ignored # of limbs in ops */ - /* Normalize denominator by shifting it to the left such that its - most significant bit is set. Then shift the numerator the same - amount, to mathematically preserve quotient. */ - count_leading_zeros (cnt, dp[dn - 1]); - if (cnt != 0) - { - d2p = (mp_ptr) TMP_ALLOC (qn * BYTES_PER_MP_LIMB); - - mpn_lshift (d2p, dp + in, qn, cnt); - d2p[0] |= dp[in - 1] >> (BITS_PER_MP_LIMB - cnt); - - n2p = (mp_ptr) TMP_ALLOC ((2 * qn + 1) * BYTES_PER_MP_LIMB); - cy = mpn_lshift (n2p, np + nn - 2 * qn, 2 * qn, cnt); - if (adjust) - { - n2p[2 * qn] = cy; - n2p++; - } - else - { - n2p[0] |= np[nn - 2 * qn - 1] >> (BITS_PER_MP_LIMB - cnt); - } - } - else - { - d2p = (mp_ptr) dp + in; - - n2p = (mp_ptr) TMP_ALLOC ((2 * qn + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (n2p, np + nn - 2 * qn, 2 * qn); - if (adjust) - { - n2p[2 * qn] = 0; - n2p++; - } - } - - /* Get an approximate quotient using the extracted operands. */ - if (qn == 1) - { - mp_limb_t q0, r0; - mp_limb_t gcc272bug_n1, gcc272bug_n0, gcc272bug_d0; - /* Due to a gcc 2.7.2.3 reload pass bug, we have to use some - temps here. This doesn't hurt code quality on any machines - so we do it unconditionally. */ - gcc272bug_n1 = n2p[1]; - gcc272bug_n0 = n2p[0]; - gcc272bug_d0 = d2p[0]; - udiv_qrnnd (q0, r0, gcc272bug_n1, gcc272bug_n0, gcc272bug_d0); - n2p[0] = r0; - qp[0] = q0; - } - else if (qn == 2) - mpn_divrem_2 (qp, 0L, n2p, 4L, d2p); - else if (qn < BZ_THRESHOLD) - mpn_sb_divrem_mn (qp, n2p, qn * 2, d2p, qn); - else - mpn_bz_divrem_n (qp, n2p, d2p, qn); - - rn = qn; - /* Multiply the first ignored divisor limb by the most significant - quotient limb. If that product is > the partial remainder's - most significant limb, we know the quotient is too large. This - test quickly catches most cases where the quotient is too large; - it catches all cases where the quotient is 2 too large. */ - { - mp_limb_t dl, x; - mp_limb_t h, l; - - if (in - 2 < 0) - dl = 0; - else - dl = dp[in - 2]; - - x = SHL (dp[in - 1], dl, cnt); - umul_ppmm (h, l, x, qp[qn - 1]); - - if (n2p[qn - 1] < h) - { - mp_limb_t cy; - - mpn_decr_u (qp, (mp_limb_t) 1); - cy = mpn_add_n (n2p, n2p, d2p, qn); - if (cy) - { - /* The partial remainder is safely large. */ - n2p[qn] = cy; - ++rn; - } - } - } - - quotient_too_large = 0; - if (cnt != 0) - { - mp_limb_t cy1, cy2; - - /* Append partially used numerator limb to partial remainder. */ - cy1 = mpn_lshift (n2p, n2p, rn, BITS_PER_MP_LIMB - cnt); - n2p[0] |= np[in - 1] & (~(mp_limb_t) 0 >> cnt); - - /* Update partial remainder with partially used divisor limb. */ - cy2 = mpn_submul_1 (n2p, qp, qn, dp[in - 1] & (~(mp_limb_t) 0 >> cnt)); - if (qn != rn) - { - if (n2p[qn] < cy2) - abort (); - n2p[qn] -= cy2; - } - else - { - n2p[qn] = cy1 - cy2; - - quotient_too_large = (cy1 < cy2); - ++rn; - } - --in; - } - /* True: partial remainder now is neutral, i.e., it is not shifted up. */ - - tp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB); - - if (in < qn) - { - if (in == 0) - { - MPN_COPY (rp, n2p, rn); - if (rn != dn) - abort (); - goto foo; - } - mpn_mul (tp, qp, qn, dp, in); - } - else - mpn_mul (tp, dp, in, qp, qn); - - cy = mpn_sub (n2p, n2p, rn, tp + in, qn); - MPN_COPY (rp + in, n2p, dn - in); - quotient_too_large |= cy; - cy = mpn_sub_n (rp, np, tp, in); - cy = mpn_sub_1 (rp + in, rp + in, rn, cy); - quotient_too_large |= cy; - foo: - if (quotient_too_large) - { - mpn_decr_u (qp, (mp_limb_t) 1); - mpn_add_n (rp, rp, dp, dn); - } - } - TMP_FREE (marker); - return; - } - } -} diff --git a/gmp/mpn/generic/udiv_w_sdiv.c b/gmp/mpn/generic/udiv_w_sdiv.c deleted file mode 100755 index 061cce8..0000000 --- a/gmp/mpn/generic/udiv_w_sdiv.c +++ /dev/null @@ -1,131 +0,0 @@ -/* mpn_udiv_w_sdiv -- implement udiv_qrnnd on machines with only signed - division. - - Contributed by Peter L. Montgomery. - - THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS ONLY SAFE - TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS - ALMOST GUARANTEED THAT THIS FUNCTION WILL CHANGE OR DISAPPEAR IN A FUTURE - GNU MP RELEASE. - - -Copyright (C) 1992, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -mp_limb_t -mpn_udiv_w_sdiv (rp, a1, a0, d) - mp_limb_t *rp, a1, a0, d; -{ - mp_limb_t q, r; - mp_limb_t c0, c1, b1; - - if ((mp_limb_signed_t) d >= 0) - { - if (a1 < d - a1 - (a0 >> (BITS_PER_MP_LIMB - 1))) - { - /* dividend, divisor, and quotient are nonnegative */ - sdiv_qrnnd (q, r, a1, a0, d); - } - else - { - /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */ - sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (BITS_PER_MP_LIMB - 1)); - /* Divide (c1*2^32 + c0) by d */ - sdiv_qrnnd (q, r, c1, c0, d); - /* Add 2^31 to quotient */ - q += (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1); - } - } - else - { - b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */ - c1 = a1 >> 1; /* A/2 */ - c0 = (a1 << (BITS_PER_MP_LIMB - 1)) + (a0 >> 1); - - if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */ - { - sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ - - r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */ - if ((d & 1) != 0) - { - if (r >= q) - r = r - q; - else if (q - r <= d) - { - r = r - q + d; - q--; - } - else - { - r = r - q + 2*d; - q -= 2; - } - } - } - else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */ - { - c1 = (b1 - 1) - c1; - c0 = ~c0; /* logical NOT */ - - sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ - - q = ~q; /* (A/2)/b1 */ - r = (b1 - 1) - r; - - r = 2*r + (a0 & 1); /* A/(2*b1) */ - - if ((d & 1) != 0) - { - if (r >= q) - r = r - q; - else if (q - r <= d) - { - r = r - q + d; - q--; - } - else - { - r = r - q + 2*d; - q -= 2; - } - } - } - else /* Implies c1 = b1 */ - { /* Hence a1 = d - 1 = 2*b1 - 1 */ - if (a0 >= -d) - { - q = -1; - r = a0 + d; - } - else - { - q = -2; - r = a0 + 2*d; - } - } - } - - *rp = r; - return q; -} diff --git a/gmp/mpn/hppa/README b/gmp/mpn/hppa/README deleted file mode 100755 index 4cd32d2..0000000 Binary files a/gmp/mpn/hppa/README and /dev/null differ diff --git a/gmp/mpn/hppa/add_n.s b/gmp/mpn/hppa/add_n.s deleted file mode 100755 index 7e60d48..0000000 Binary files a/gmp/mpn/hppa/add_n.s and /dev/null differ diff --git a/gmp/mpn/hppa/gmp-mparam.h b/gmp/mpn/hppa/gmp-mparam.h deleted file mode 100755 index 98b6d9c..0000000 --- a/gmp/mpn/hppa/gmp-mparam.h +++ /dev/null @@ -1,63 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values are for the PA7100 using GCC. */ -/* Generated by tuneup.c, 2000-07-25. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 30 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 172 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 59 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 185 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 96 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 122 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 18 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 46 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 33 -#endif diff --git a/gmp/mpn/hppa/hppa1_1/addmul_1.s b/gmp/mpn/hppa/hppa1_1/addmul_1.s deleted file mode 100755 index 12f1bf6..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/mul_1.s b/gmp/mpn/hppa/hppa1_1/mul_1.s deleted file mode 100755 index 8bcd6a6..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/mul_1.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/pa7100/add_n.s b/gmp/mpn/hppa/hppa1_1/pa7100/add_n.s deleted file mode 100755 index 91ffbde..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/pa7100/add_n.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/pa7100/addmul_1.S b/gmp/mpn/hppa/hppa1_1/pa7100/addmul_1.S deleted file mode 100755 index 0febf56..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/pa7100/addmul_1.S and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/pa7100/lshift.s b/gmp/mpn/hppa/hppa1_1/pa7100/lshift.s deleted file mode 100755 index c8769ca..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/pa7100/lshift.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/pa7100/rshift.s b/gmp/mpn/hppa/hppa1_1/pa7100/rshift.s deleted file mode 100755 index 4fad5c1..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/pa7100/rshift.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/pa7100/sub_n.s b/gmp/mpn/hppa/hppa1_1/pa7100/sub_n.s deleted file mode 100755 index 1a02294..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/pa7100/sub_n.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/pa7100/submul_1.S b/gmp/mpn/hppa/hppa1_1/pa7100/submul_1.S deleted file mode 100755 index 73ef1e2..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/pa7100/submul_1.S and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/submul_1.s b/gmp/mpn/hppa/hppa1_1/submul_1.s deleted file mode 100755 index c60efe5..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/submul_1.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/udiv_qrnnd.S b/gmp/mpn/hppa/hppa1_1/udiv_qrnnd.S deleted file mode 100755 index 3e3e97b..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/udiv_qrnnd.S and /dev/null differ diff --git a/gmp/mpn/hppa/hppa1_1/umul.s b/gmp/mpn/hppa/hppa1_1/umul.s deleted file mode 100755 index e8269d4..0000000 Binary files a/gmp/mpn/hppa/hppa1_1/umul.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa2_0/add_n.s b/gmp/mpn/hppa/hppa2_0/add_n.s deleted file mode 100755 index afdc284..0000000 Binary files a/gmp/mpn/hppa/hppa2_0/add_n.s and /dev/null differ diff --git a/gmp/mpn/hppa/hppa2_0/sub_n.s b/gmp/mpn/hppa/hppa2_0/sub_n.s deleted file mode 100755 index 7bf8f81..0000000 Binary files a/gmp/mpn/hppa/hppa2_0/sub_n.s and /dev/null differ diff --git a/gmp/mpn/hppa/lshift.s b/gmp/mpn/hppa/lshift.s deleted file mode 100755 index 1a3a103..0000000 Binary files a/gmp/mpn/hppa/lshift.s and /dev/null differ diff --git a/gmp/mpn/hppa/rshift.s b/gmp/mpn/hppa/rshift.s deleted file mode 100755 index ce9e064..0000000 Binary files a/gmp/mpn/hppa/rshift.s and /dev/null differ diff --git a/gmp/mpn/hppa/sub_n.s b/gmp/mpn/hppa/sub_n.s deleted file mode 100755 index 2fa8e1c..0000000 Binary files a/gmp/mpn/hppa/sub_n.s and /dev/null differ diff --git a/gmp/mpn/hppa/udiv_qrnnd.s b/gmp/mpn/hppa/udiv_qrnnd.s deleted file mode 100755 index 62c6579..0000000 Binary files a/gmp/mpn/hppa/udiv_qrnnd.s and /dev/null differ diff --git a/gmp/mpn/i960/README b/gmp/mpn/i960/README deleted file mode 100755 index 2037456..0000000 Binary files a/gmp/mpn/i960/README and /dev/null differ diff --git a/gmp/mpn/i960/add_n.s b/gmp/mpn/i960/add_n.s deleted file mode 100755 index 4204384..0000000 Binary files a/gmp/mpn/i960/add_n.s and /dev/null differ diff --git a/gmp/mpn/i960/addmul_1.s b/gmp/mpn/i960/addmul_1.s deleted file mode 100755 index 7135f2c..0000000 Binary files a/gmp/mpn/i960/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/i960/mul_1.s b/gmp/mpn/i960/mul_1.s deleted file mode 100755 index 28567ba..0000000 Binary files a/gmp/mpn/i960/mul_1.s and /dev/null differ diff --git a/gmp/mpn/i960/sub_n.s b/gmp/mpn/i960/sub_n.s deleted file mode 100755 index 2f84d4c..0000000 Binary files a/gmp/mpn/i960/sub_n.s and /dev/null differ diff --git a/gmp/mpn/lisp/gmpasm-mode.el b/gmp/mpn/lisp/gmpasm-mode.el deleted file mode 100755 index d783de1..0000000 Binary files a/gmp/mpn/lisp/gmpasm-mode.el and /dev/null differ diff --git a/gmp/mpn/m68k/add_n.S b/gmp/mpn/m68k/add_n.S deleted file mode 100755 index 7c27131..0000000 Binary files a/gmp/mpn/m68k/add_n.S and /dev/null differ diff --git a/gmp/mpn/m68k/asm_syntax.h b/gmp/mpn/m68k/asm_syntax.h deleted file mode 100755 index 65e8c3b..0000000 Binary files a/gmp/mpn/m68k/asm_syntax.h and /dev/null differ diff --git a/gmp/mpn/m68k/lshift.S b/gmp/mpn/m68k/lshift.S deleted file mode 100755 index 2096f0f..0000000 Binary files a/gmp/mpn/m68k/lshift.S and /dev/null differ diff --git a/gmp/mpn/m68k/mc68020/addmul_1.S b/gmp/mpn/m68k/mc68020/addmul_1.S deleted file mode 100755 index 052472c..0000000 Binary files a/gmp/mpn/m68k/mc68020/addmul_1.S and /dev/null differ diff --git a/gmp/mpn/m68k/mc68020/mul_1.S b/gmp/mpn/m68k/mc68020/mul_1.S deleted file mode 100755 index c38b995..0000000 Binary files a/gmp/mpn/m68k/mc68020/mul_1.S and /dev/null differ diff --git a/gmp/mpn/m68k/mc68020/submul_1.S b/gmp/mpn/m68k/mc68020/submul_1.S deleted file mode 100755 index 2642b8c..0000000 Binary files a/gmp/mpn/m68k/mc68020/submul_1.S and /dev/null differ diff --git a/gmp/mpn/m68k/mc68020/udiv.S b/gmp/mpn/m68k/mc68020/udiv.S deleted file mode 100755 index fefe1c2..0000000 Binary files a/gmp/mpn/m68k/mc68020/udiv.S and /dev/null differ diff --git a/gmp/mpn/m68k/mc68020/umul.S b/gmp/mpn/m68k/mc68020/umul.S deleted file mode 100755 index 101d2df..0000000 Binary files a/gmp/mpn/m68k/mc68020/umul.S and /dev/null differ diff --git a/gmp/mpn/m68k/mpn68k.c b/gmp/mpn/m68k/mpn68k.c deleted file mode 100755 index 522a2c4..0000000 --- a/gmp/mpn/m68k/mpn68k.c +++ /dev/null @@ -1,561 +0,0 @@ -/* -#define MOTOROLA_SYNTAX 1 -#include "asm_syntax.h" -*/ - -#pragma code68020 on - -#if __MC68020__ -#ifndef mc68020 -#define mc68020 1 -#endif -#endif - -/* disable link a6 sequence */ -#pragma a6frames off - -#define R(r)r -#define MEM(base)(base) -#define MEM_DISP(base,displacement)displacement(base) -#define MEM_INDX(base,idx,size_suffix)(base,idx.size_suffix) -#define MEM_INDX1(base,idx,size_suffix,scale)(base,idx.size_suffix*scale) -#define MEM_PREDEC(memory_base)-(memory_base) -#define MEM_POSTINC(memory_base)(memory_base)+ -#define L(label) label -#define lea LEA -#define movel MOVE.L -#define moveml MOVEM.L -#define moveql MOVEQ.L -#define cmpl CMP.L -#define orl OR.L -#define clrl CLR.L -#define eorw EOR.W -#define lsrl LSR.L -#define lsll LSL.L -#define asrl ASR.L -#define asll ASL.L -#define roxrl ROXR.L -#define roxll ROXL.L -#define addl ADD.L -#define addxl ADDX.L -#define addql ADDQ.L -#define subl SUB.L -#define subxl SUBX.L -#define subql SUBQ.L -#define negl NEG.L -#define mulul MULU.L -#define bcc BCC -#define bcs BCS -#define bls BLS -#define beq BEQ -#define bne BNE -#define bra BRA -#define dbf DBF -#define rts RTS -#define d0 D0 -#define d1 D1 -#define d2 D2 -#define d3 D3 -#define d4 D4 -#define d5 D5 -#define d6 D6 -#define d7 D7 -#define a0 A0 -#define a1 A1 -#define a2 A2 -#define a3 A3 -#define a4 A4 -#define a5 A5 -#define a6 A6 -#define a7 A7 -#define sp SP - - -asm void __gmpn_add_n() -{ -/* Save used registers on the stack. */ - movel R(d2),MEM_PREDEC(sp) - movel R(a2),MEM_PREDEC(sp) - -/* Copy the arguments to registers. Better use movem? */ - movel MEM_DISP(sp,12),R(a2) - movel MEM_DISP(sp,16),R(a0) - movel MEM_DISP(sp,20),R(a1) - movel MEM_DISP(sp,24),R(d2) - - eorw #1,R(d2) - lsrl #1,R(d2) - bcc L(L1) - subql #1,R(d2) /* clears cy as side effect */ - -L(Loop:) - movel MEM_POSTINC(a0),R(d0) - movel MEM_POSTINC(a1),R(d1) - addxl R(d1),R(d0) - movel R(d0),MEM_POSTINC(a2) -L(L1:) movel MEM_POSTINC(a0),R(d0) - movel MEM_POSTINC(a1),R(d1) - addxl R(d1),R(d0) - movel R(d0),MEM_POSTINC(a2) - - dbf R(d2),L(Loop) /* loop until 16 lsb of %4 == -1 */ - subxl R(d0),R(d0) /* d0 <= -cy; save cy as 0 or -1 in d0 */ - subl #0x10000,R(d2) - bcs L(L2) - addl R(d0),R(d0) /* restore cy */ - bra L(Loop) - -L(L2:) - negl R(d0) - -/* Restore used registers from stack frame. */ - movel MEM_POSTINC(sp),R(a2) - movel MEM_POSTINC(sp),R(d2) - rts -} - -asm void __gmpn_addmul_1() -{ -#define res_ptr a0 -#define s1_ptr a1 -#define s1_size d2 -#define s2_limb d4 - -/* Save used registers on the stack. */ - moveml R(d2)-R(d5),MEM_PREDEC(sp) - -/* Copy the arguments to registers. Better use movem? */ - movel MEM_DISP(sp,20),R(res_ptr) - movel MEM_DISP(sp,24),R(s1_ptr) - movel MEM_DISP(sp,28),R(s1_size) - movel MEM_DISP(sp,32),R(s2_limb) - - eorw #1,R(s1_size) - clrl R(d1) - clrl R(d5) - lsrl #1,R(s1_size) - bcc L(L1) - subql #1,R(s1_size) - subl R(d0),R(d0) /* (d0,cy) <= (0,0) */ - -L(Loop:) - movel MEM_POSTINC(s1_ptr),R(d3) - mulul R(s2_limb),R(d1):R(d3) - addxl R(d0),R(d3) - addxl R(d5),R(d1) - addl R(d3),MEM_POSTINC(res_ptr) -L(L1:) movel MEM_POSTINC(s1_ptr),R(d3) - mulul R(s2_limb),R(d0):R(d3) - addxl R(d1),R(d3) - addxl R(d5),R(d0) - addl R(d3),MEM_POSTINC(res_ptr) - - dbf R(s1_size),L(Loop) - addxl R(d5),R(d0) - subl #0x10000,R(s1_size) - bcc L(Loop) - -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d5) - rts - -#undef res_ptr -#undef s1_ptr -#undef s1_size -#undef s2_limb -} - -asm void __gmpn_lshift() -{ -#define res_ptr a1 -#define s_ptr a0 -#define s_size d6 -#define cnt d4 - -/* Save used registers on the stack. */ - moveml R(d2)-R(d6)/R(a2),MEM_PREDEC(sp) - -/* Copy the arguments to registers. */ - movel MEM_DISP(sp,28),R(res_ptr) - movel MEM_DISP(sp,32),R(s_ptr) - movel MEM_DISP(sp,36),R(s_size) - movel MEM_DISP(sp,40),R(cnt) - - moveql #1,R(d5) - cmpl R(d5),R(cnt) - bne L(Lnormal) - cmpl R(s_ptr),R(res_ptr) - bls L(Lspecial) /* jump if s_ptr >= res_ptr */ -#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) - lea MEM_INDX1(s_ptr,s_size,l,4),R(a2) -#else /* not mc68020 */ - movel R(s_size),R(d0) - asll #2,R(d0) - lea MEM_INDX(s_ptr,d0,l),R(a2) -#endif - cmpl R(res_ptr),R(a2) - bls L(Lspecial) /* jump if res_ptr >= s_ptr + s_size */ - -L(Lnormal:) - moveql #32,R(d5) - subl R(cnt),R(d5) - -#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) - lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) - lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) -#else /* not mc68000 */ - movel R(s_size),R(d0) - asll #2,R(d0) - addl R(s_size),R(s_ptr) - addl R(s_size),R(res_ptr) -#endif - movel MEM_PREDEC(s_ptr),R(d2) - movel R(d2),R(d0) - lsrl R(d5),R(d0) /* compute carry limb */ - - lsll R(cnt),R(d2) - movel R(d2),R(d1) - subql #1,R(s_size) - beq L(Lend) - lsrl #1,R(s_size) - bcs L(L1) - subql #1,R(s_size) - -L(Loop:) - movel MEM_PREDEC(s_ptr),R(d2) - movel R(d2),R(d3) - lsrl R(d5),R(d3) - orl R(d3),R(d1) - movel R(d1),MEM_PREDEC(res_ptr) - lsll R(cnt),R(d2) -L(L1:) - movel MEM_PREDEC(s_ptr),R(d1) - movel R(d1),R(d3) - lsrl R(d5),R(d3) - orl R(d3),R(d2) - movel R(d2),MEM_PREDEC(res_ptr) - lsll R(cnt),R(d1) - - dbf R(s_size),L(Loop) - subl #0x10000,R(s_size) - bcc L(Loop) - -L(Lend:) - movel R(d1),MEM_PREDEC(res_ptr) /* store least significant limb */ - -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2) - rts - -/* We loop from least significant end of the arrays, which is only - permissable if the source and destination don't overlap, since the - function is documented to work for overlapping source and destination. */ - -L(Lspecial:) - clrl R(d0) /* initialize carry */ - eorw #1,R(s_size) - lsrl #1,R(s_size) - bcc L(LL1) - subql #1,R(s_size) - -L(LLoop:) - movel MEM_POSTINC(s_ptr),R(d2) - addxl R(d2),R(d2) - movel R(d2),MEM_POSTINC(res_ptr) -L(LL1:) - movel MEM_POSTINC(s_ptr),R(d2) - addxl R(d2),R(d2) - movel R(d2),MEM_POSTINC(res_ptr) - - dbf R(s_size),L(LLoop) - addxl R(d0),R(d0) /* save cy in lsb */ - subl #0x10000,R(s_size) - bcs L(LLend) - lsrl #1,R(d0) /* restore cy */ - bra L(LLoop) - -L(LLend:) -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2) - rts - -#undef res_ptr -#undef s_ptr -#undef s_size -#undef cnt -} - -asm void __gmpn_mul_1() -{ -#define res_ptr a0 -#define s1_ptr a1 -#define s1_size d2 -#define s2_limb d4 - -/* Save used registers on the stack. */ - moveml R(d2)-R(d4),MEM_PREDEC(sp) -#if 0 - movel R(d2),MEM_PREDEC(sp) - movel R(d3),MEM_PREDEC(sp) - movel R(d4),MEM_PREDEC(sp) -#endif - -/* Copy the arguments to registers. Better use movem? */ - movel MEM_DISP(sp,16),R(res_ptr) - movel MEM_DISP(sp,20),R(s1_ptr) - movel MEM_DISP(sp,24),R(s1_size) - movel MEM_DISP(sp,28),R(s2_limb) - - eorw #1,R(s1_size) - clrl R(d1) - lsrl #1,R(s1_size) - bcc L(L1) - subql #1,R(s1_size) - subl R(d0),R(d0) /* (d0,cy) <= (0,0) */ - -L(Loop:) - movel MEM_POSTINC(s1_ptr),R(d3) - mulul R(s2_limb),R(d1):R(d3) - addxl R(d0),R(d3) - movel R(d3),MEM_POSTINC(res_ptr) -L(L1:) movel MEM_POSTINC(s1_ptr),R(d3) - mulul R(s2_limb),R(d0):R(d3) - addxl R(d1),R(d3) - movel R(d3),MEM_POSTINC(res_ptr) - - dbf R(s1_size),L(Loop) - clrl R(d3) - addxl R(d3),R(d0) - subl #0x10000,R(s1_size) - bcc L(Loop) - -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d4) -#if 0 - movel MEM_POSTINC(sp),R(d4) - movel MEM_POSTINC(sp),R(d3) - movel MEM_POSTINC(sp),R(d2) -#endif - rts -#undef res_ptr -#undef s1_ptr -#undef s1_size -#undef s2_limb -} - - -asm void __gmpn_rshift() -{ -#define res_ptr a1 -#define s_ptr a0 -#define s_size d6 -#define cnt d4 - -/* Save used registers on the stack. */ - moveml R(d2)-R(d6)/R(a2),MEM_PREDEC(sp) - -/* Copy the arguments to registers. */ - movel MEM_DISP(sp,28),R(res_ptr) - movel MEM_DISP(sp,32),R(s_ptr) - movel MEM_DISP(sp,36),R(s_size) - movel MEM_DISP(sp,40),R(cnt) - - moveql #1,R(d5) - cmpl R(d5),R(cnt) - bne L(Lnormal) - cmpl R(res_ptr),R(s_ptr) - bls L(Lspecial) /* jump if res_ptr >= s_ptr */ -#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) - lea MEM_INDX1(res_ptr,s_size,l,4),R(a2) -#else /* not mc68020 */ - movel R(s_size),R(d0) - asll #2,R(d0) - lea MEM_INDX(res_ptr,d0,l),R(a2) -#endif - cmpl R(s_ptr),R(a2) - bls L(Lspecial) /* jump if s_ptr >= res_ptr + s_size */ - -L(Lnormal:) - moveql #32,R(d5) - subl R(cnt),R(d5) - movel MEM_POSTINC(s_ptr),R(d2) - movel R(d2),R(d0) - lsll R(d5),R(d0) /* compute carry limb */ - - lsrl R(cnt),R(d2) - movel R(d2),R(d1) - subql #1,R(s_size) - beq L(Lend) - lsrl #1,R(s_size) - bcs L(L1) - subql #1,R(s_size) - -L(Loop:) - movel MEM_POSTINC(s_ptr),R(d2) - movel R(d2),R(d3) - lsll R(d5),R(d3) - orl R(d3),R(d1) - movel R(d1),MEM_POSTINC(res_ptr) - lsrl R(cnt),R(d2) -L(L1:) - movel MEM_POSTINC(s_ptr),R(d1) - movel R(d1),R(d3) - lsll R(d5),R(d3) - orl R(d3),R(d2) - movel R(d2),MEM_POSTINC(res_ptr) - lsrl R(cnt),R(d1) - - dbf R(s_size),L(Loop) - subl #0x10000,R(s_size) - bcc L(Loop) - -L(Lend:) - movel R(d1),MEM(res_ptr) /* store most significant limb */ - -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2) - rts - -/* We loop from most significant end of the arrays, which is only - permissable if the source and destination don't overlap, since the - function is documented to work for overlapping source and destination. */ - -L(Lspecial:) -#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) - lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr) - lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr) -#else /* not mc68000 */ - movel R(s_size),R(d0) - asll #2,R(d0) - addl R(s_size),R(s_ptr) - addl R(s_size),R(res_ptr) -#endif - - clrl R(d0) /* initialize carry */ - eorw #1,R(s_size) - lsrl #1,R(s_size) - bcc L(LL1) - subql #1,R(s_size) - -L(LLoop:) - movel MEM_PREDEC(s_ptr),R(d2) - roxrl #1,R(d2) - movel R(d2),MEM_PREDEC(res_ptr) -L(LL1:) - movel MEM_PREDEC(s_ptr),R(d2) - roxrl #1,R(d2) - movel R(d2),MEM_PREDEC(res_ptr) - - dbf R(s_size),L(LLoop) - roxrl #1,R(d0) /* save cy in msb */ - subl #0x10000,R(s_size) - bcs L(LLend) - addl R(d0),R(d0) /* restore cy */ - bra L(LLoop) - -L(LLend:) -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2) - rts - -#undef res_ptr -#undef s_ptr -#undef s_size -#undef cnt -} - -asm void __gmpn_sub_n() -{ -/* Save used registers on the stack. */ - movel R(d2),MEM_PREDEC(sp) - movel R(a2),MEM_PREDEC(sp) - -/* Copy the arguments to registers. Better use movem? */ - movel MEM_DISP(sp,12),R(a2) - movel MEM_DISP(sp,16),R(a0) - movel MEM_DISP(sp,20),R(a1) - movel MEM_DISP(sp,24),R(d2) - - eorw #1,R(d2) - lsrl #1,R(d2) - bcc L(L1) - subql #1,R(d2) /* clears cy as side effect */ - -L(Loop:) - movel MEM_POSTINC(a0),R(d0) - movel MEM_POSTINC(a1),R(d1) - subxl R(d1),R(d0) - movel R(d0),MEM_POSTINC(a2) -L(L1:) movel MEM_POSTINC(a0),R(d0) - movel MEM_POSTINC(a1),R(d1) - subxl R(d1),R(d0) - movel R(d0),MEM_POSTINC(a2) - - dbf R(d2),L(Loop) /* loop until 16 lsb of %4 == -1 */ - subxl R(d0),R(d0) /* d0 <= -cy; save cy as 0 or -1 in d0 */ - subl #0x10000,R(d2) - bcs L(L2) - addl R(d0),R(d0) /* restore cy */ - bra L(Loop) - -L(L2:) - negl R(d0) - -/* Restore used registers from stack frame. */ - movel MEM_POSTINC(sp),R(a2) - movel MEM_POSTINC(sp),R(d2) - rts -} - -asm void __gmpn_submul_1() -{ -#define res_ptr a0 -#define s1_ptr a1 -#define s1_size d2 -#define s2_limb d4 - -/* Save used registers on the stack. */ - moveml R(d2)-R(d5),MEM_PREDEC(sp) - -/* Copy the arguments to registers. Better use movem? */ - movel MEM_DISP(sp,20),R(res_ptr) - movel MEM_DISP(sp,24),R(s1_ptr) - movel MEM_DISP(sp,28),R(s1_size) - movel MEM_DISP(sp,32),R(s2_limb) - - eorw #1,R(s1_size) - clrl R(d1) - clrl R(d5) - lsrl #1,R(s1_size) - bcc L(L1) - subql #1,R(s1_size) - subl R(d0),R(d0) /* (d0,cy) <= (0,0) */ - -L(Loop:) - movel MEM_POSTINC(s1_ptr),R(d3) - mulul R(s2_limb),R(d1):R(d3) - addxl R(d0),R(d3) - addxl R(d5),R(d1) - subl R(d3),MEM_POSTINC(res_ptr) -L(L1:) movel MEM_POSTINC(s1_ptr),R(d3) - mulul R(s2_limb),R(d0):R(d3) - addxl R(d1),R(d3) - addxl R(d5),R(d0) - subl R(d3),MEM_POSTINC(res_ptr) - - dbf R(s1_size),L(Loop) - addxl R(d5),R(d0) - subl #0x10000,R(s1_size) - bcc L(Loop) - -/* Restore used registers from stack frame. */ - moveml MEM_POSTINC(sp),R(d2)-R(d5) - rts - -#undef res_ptr -#undef s1_ptr -#undef s1_size -#undef s2_limb -} - -#pragma a6frames reset diff --git a/gmp/mpn/m68k/rshift.S b/gmp/mpn/m68k/rshift.S deleted file mode 100755 index 2388635..0000000 Binary files a/gmp/mpn/m68k/rshift.S and /dev/null differ diff --git a/gmp/mpn/m68k/sub_n.S b/gmp/mpn/m68k/sub_n.S deleted file mode 100755 index d378f54..0000000 Binary files a/gmp/mpn/m68k/sub_n.S and /dev/null differ diff --git a/gmp/mpn/m68k/syntax.h b/gmp/mpn/m68k/syntax.h deleted file mode 100755 index 9eec279..0000000 --- a/gmp/mpn/m68k/syntax.h +++ /dev/null @@ -1,177 +0,0 @@ -/* asm.h -- Definitions for 68k syntax variations. - -Copyright (C) 1992, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#undef ALIGN - -#ifdef MIT_SYNTAX -#define PROLOG(name) -#define EPILOG(name) -#define R(r)r -#define MEM(base)base@ -#define MEM_DISP(base,displacement)base@(displacement) -#define MEM_INDX(base,idx,size_suffix)base@(idx:size_suffix) -#define MEM_INDX1(base,idx,size_suffix,scale)base@(idx:size_suffix:scale) -#define MEM_PREDEC(memory_base)memory_base@- -#define MEM_POSTINC(memory_base)memory_base@+ -#define L(label) label -#define TEXT .text -#define ALIGN .even -#define GLOBL .globl -#define moveql moveq -/* Use variable sized opcodes. */ -#define bcc jcc -#define bcs jcs -#define bls jls -#define beq jeq -#define bne jne -#define bra jra -#endif - -#ifdef SONY_SYNTAX -#define PROLOG(name) -#define EPILOG(name) -#define R(r)r -#define MEM(base)(base) -#define MEM_DISP(base,displacement)(displacement,base) -#define MEM_INDX(base,idx,size_suffix)(base,idx.size_suffix) -#define MEM_INDX1(base,idx,size_suffix,scale)(base,idx.size_suffix*scale) -#define MEM_PREDEC(memory_base)-(memory_base) -#define MEM_POSTINC(memory_base)(memory_base)+ -#define L(label) label -#define TEXT .text -#define ALIGN .even -#define GLOBL .globl -#endif - -#ifdef MOTOROLA_SYNTAX -#define PROLOG(name) -#define EPILOG(name) -#define R(r)r -#define MEM(base)(base) -#define MEM_DISP(base,displacement)(displacement,base) -#define MEM_INDX(base,idx,size_suffix)(base,idx.size_suffix) -#define MEM_INDX1(base,idx,size_suffix,scale)(base,idx.size_suffix*scale) -#define MEM_PREDEC(memory_base)-(memory_base) -#define MEM_POSTINC(memory_base)(memory_base)+ -#define L(label) label -#define TEXT -#define ALIGN -#define GLOBL XDEF -#define lea LEA -#define movel MOVE.L -#define moveml MOVEM.L -#define moveql MOVEQ.L -#define cmpl CMP.L -#define orl OR.L -#define clrl CLR.L -#define eorw EOR.W -#define lsrl LSR.L -#define lsll LSL.L -#define roxrl ROXR.L -#define roxll ROXL.L -#define addl ADD.L -#define addxl ADDX.L -#define addql ADDQ.L -#define subl SUB.L -#define subxl SUBX.L -#define subql SUBQ.L -#define negl NEG.L -#define mulul MULU.L -#define bcc BCC -#define bcs BCS -#define bls BLS -#define beq BEQ -#define bne BNE -#define bra BRA -#define dbf DBF -#define rts RTS -#define d0 D0 -#define d1 D1 -#define d2 D2 -#define d3 D3 -#define d4 D4 -#define d5 D5 -#define d6 D6 -#define d7 D7 -#define a0 A0 -#define a1 A1 -#define a2 A2 -#define a3 A3 -#define a4 A4 -#define a5 A5 -#define a6 A6 -#define a7 A7 -#define sp SP -#endif - -#ifdef ELF_SYNTAX -#define PROLOG(name) .type name,@function -#define EPILOG(name) .size name,.-name -#define MEM(base)(R(base)) -#define MEM_DISP(base,displacement)(displacement,R(base)) -#define MEM_PREDEC(memory_base)-(R(memory_base)) -#define MEM_POSTINC(memory_base)(R(memory_base))+ -#ifdef __STDC__ -#define R_(r)%##r -#define R(r)R_(r) -#define MEM_INDX_(base,idx,size_suffix)(R(base),R(idx##.##size_suffix)) -#define MEM_INDX(base,idx,size_suffix)MEM_INDX_(base,idx,size_suffix) -#define MEM_INDX1_(base,idx,size_suffix,scale)(R(base),R(idx##.##size_suffix*scale)) -#define MEM_INDX1(base,idx,size_suffix,scale)MEM_INDX1_(base,idx,size_suffix,scale) -#define L(label) .##label -#else -#define R(r)%/**/r -#define MEM_INDX(base,idx,size_suffix)(R(base),R(idx).size_suffix) -#define MEM_INDX1(base,idx,size_suffix,scale)(R(base),R(idx).size_suffix*scale) -#define L(label) ./**/label -#endif -#define TEXT .text -#define ALIGN .align 2 -#define GLOBL .globl -#define bcc jbcc -#define bcs jbcs -#define bls jbls -#define beq jbeq -#define bne jbne -#define bra jbra -#endif - -#if defined (SONY_SYNTAX) || defined (ELF_SYNTAX) -#define movel move.l -#define moveml movem.l -#define moveql moveq.l -#define cmpl cmp.l -#define orl or.l -#define clrl clr.l -#define eorw eor.w -#define lsrl lsr.l -#define lsll lsl.l -#define roxrl roxr.l -#define roxll roxl.l -#define addl add.l -#define addxl addx.l -#define addql addq.l -#define subl sub.l -#define subxl subx.l -#define subql subq.l -#define negl neg.l -#define mulul mulu.l -#endif diff --git a/gmp/mpn/m88k/add_n.s b/gmp/mpn/m88k/add_n.s deleted file mode 100755 index 575f548..0000000 Binary files a/gmp/mpn/m88k/add_n.s and /dev/null differ diff --git a/gmp/mpn/m88k/mc88110/add_n.S b/gmp/mpn/m88k/mc88110/add_n.S deleted file mode 100755 index de22f8a..0000000 Binary files a/gmp/mpn/m88k/mc88110/add_n.S and /dev/null differ diff --git a/gmp/mpn/m88k/mc88110/addmul_1.s b/gmp/mpn/m88k/mc88110/addmul_1.s deleted file mode 100755 index 7ad69e8..0000000 Binary files a/gmp/mpn/m88k/mc88110/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/m88k/mc88110/mul_1.s b/gmp/mpn/m88k/mc88110/mul_1.s deleted file mode 100755 index 222ae6e..0000000 Binary files a/gmp/mpn/m88k/mc88110/mul_1.s and /dev/null differ diff --git a/gmp/mpn/m88k/mc88110/sub_n.S b/gmp/mpn/m88k/mc88110/sub_n.S deleted file mode 100755 index 08500d7..0000000 Binary files a/gmp/mpn/m88k/mc88110/sub_n.S and /dev/null differ diff --git a/gmp/mpn/m88k/mul_1.s b/gmp/mpn/m88k/mul_1.s deleted file mode 100755 index 841df9e..0000000 Binary files a/gmp/mpn/m88k/mul_1.s and /dev/null differ diff --git a/gmp/mpn/m88k/sub_n.s b/gmp/mpn/m88k/sub_n.s deleted file mode 100755 index 2989f27..0000000 Binary files a/gmp/mpn/m88k/sub_n.s and /dev/null differ diff --git a/gmp/mpn/mips2/add_n.s b/gmp/mpn/mips2/add_n.s deleted file mode 100755 index 4808b65..0000000 Binary files a/gmp/mpn/mips2/add_n.s and /dev/null differ diff --git a/gmp/mpn/mips2/addmul_1.s b/gmp/mpn/mips2/addmul_1.s deleted file mode 100755 index f561afb..0000000 Binary files a/gmp/mpn/mips2/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/mips2/lshift.s b/gmp/mpn/mips2/lshift.s deleted file mode 100755 index b79dd3b..0000000 Binary files a/gmp/mpn/mips2/lshift.s and /dev/null differ diff --git a/gmp/mpn/mips2/mul_1.s b/gmp/mpn/mips2/mul_1.s deleted file mode 100755 index 623ccee..0000000 Binary files a/gmp/mpn/mips2/mul_1.s and /dev/null differ diff --git a/gmp/mpn/mips2/rshift.s b/gmp/mpn/mips2/rshift.s deleted file mode 100755 index d950394..0000000 Binary files a/gmp/mpn/mips2/rshift.s and /dev/null differ diff --git a/gmp/mpn/mips2/sub_n.s b/gmp/mpn/mips2/sub_n.s deleted file mode 100755 index 17c74a7..0000000 Binary files a/gmp/mpn/mips2/sub_n.s and /dev/null differ diff --git a/gmp/mpn/mips2/submul_1.s b/gmp/mpn/mips2/submul_1.s deleted file mode 100755 index 0e8f413..0000000 Binary files a/gmp/mpn/mips2/submul_1.s and /dev/null differ diff --git a/gmp/mpn/mips2/umul.s b/gmp/mpn/mips2/umul.s deleted file mode 100755 index df49229..0000000 Binary files a/gmp/mpn/mips2/umul.s and /dev/null differ diff --git a/gmp/mpn/mips3/README b/gmp/mpn/mips3/README deleted file mode 100755 index 8cc48a1..0000000 Binary files a/gmp/mpn/mips3/README and /dev/null differ diff --git a/gmp/mpn/mips3/add_n.s b/gmp/mpn/mips3/add_n.s deleted file mode 100755 index 500b712..0000000 Binary files a/gmp/mpn/mips3/add_n.s and /dev/null differ diff --git a/gmp/mpn/mips3/addmul_1.s b/gmp/mpn/mips3/addmul_1.s deleted file mode 100755 index 7ab41c8..0000000 Binary files a/gmp/mpn/mips3/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/mips3/gmp-mparam.h b/gmp/mpn/mips3/gmp-mparam.h deleted file mode 100755 index 656e90c..0000000 --- a/gmp/mpn/mips3/gmp-mparam.h +++ /dev/null @@ -1,58 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values are for the R10000 usign the system cc. */ -/* Generated by tuneup.c, 2000-07-25. */ -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 16 -#endif -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 32 -#endif - -/* Supressed the TOOM3 values as they looked absolutely crazy - (698 and 21 respectively) */ - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 58 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 54 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 82 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 159 -#endif diff --git a/gmp/mpn/mips3/lshift.s b/gmp/mpn/mips3/lshift.s deleted file mode 100755 index b3875d8..0000000 Binary files a/gmp/mpn/mips3/lshift.s and /dev/null differ diff --git a/gmp/mpn/mips3/mul_1.s b/gmp/mpn/mips3/mul_1.s deleted file mode 100755 index edbb0a2..0000000 Binary files a/gmp/mpn/mips3/mul_1.s and /dev/null differ diff --git a/gmp/mpn/mips3/rshift.s b/gmp/mpn/mips3/rshift.s deleted file mode 100755 index c2048d5..0000000 Binary files a/gmp/mpn/mips3/rshift.s and /dev/null differ diff --git a/gmp/mpn/mips3/sub_n.s b/gmp/mpn/mips3/sub_n.s deleted file mode 100755 index f8aecf0..0000000 Binary files a/gmp/mpn/mips3/sub_n.s and /dev/null differ diff --git a/gmp/mpn/mips3/submul_1.s b/gmp/mpn/mips3/submul_1.s deleted file mode 100755 index 84a203a..0000000 Binary files a/gmp/mpn/mips3/submul_1.s and /dev/null differ diff --git a/gmp/mpn/mp_bases.c b/gmp/mpn/mp_bases.c deleted file mode 100755 index 011c328..0000000 --- a/gmp/mpn/mp_bases.c +++ /dev/null @@ -1,550 +0,0 @@ -/* __mp_bases -- Structure for conversion between internal binary - format and strings in base 2..255. The fields are explained in - gmp-impl.h. - - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - - -#if BITS_PER_MP_LIMB == 32 -const struct bases __mp_bases[256] = -{ - /* 0 */ {0, 0.0, 0, 0}, - /* 1 */ {0, 1e38, 0, 0}, - /* 2 */ {32, 1.0000000000000000, 0x1, 0x0}, - /* 3 */ {20, 0.6309297535714575, 0xcfd41b91, 0x3b563c24}, - /* 4 */ {16, 0.5000000000000000, 0x2, 0x0}, - /* 5 */ {13, 0.4306765580733931, 0x48c27395, 0xc25c2684}, - /* 6 */ {12, 0.3868528072345416, 0x81bf1000, 0xf91bd1b6}, - /* 7 */ {11, 0.3562071871080222, 0x75db9c97, 0x1607a2cb}, - /* 8 */ {10, 0.3333333333333334, 0x3, 0x0}, - /* 9 */ {10, 0.3154648767857287, 0xcfd41b91, 0x3b563c24}, - /* 10 */ {9, 0.3010299956639811, 0x3b9aca00, 0x12e0be82}, - /* 11 */ {9, 0.2890648263178878, 0x8c8b6d2b, 0xd24cde04}, - /* 12 */ {8, 0.2789429456511298, 0x19a10000, 0x3fa39ab5}, - /* 13 */ {8, 0.2702381544273197, 0x309f1021, 0x50f8ac5f}, - /* 14 */ {8, 0.2626495350371936, 0x57f6c100, 0x74843b1e}, - /* 15 */ {8, 0.2559580248098155, 0x98c29b81, 0xad0326c2}, - /* 16 */ {8, 0.2500000000000000, 0x4, 0x0}, - /* 17 */ {7, 0.2446505421182260, 0x18754571, 0x4ef0b6bd}, - /* 18 */ {7, 0.2398124665681315, 0x247dbc80, 0xc0fc48a1}, - /* 19 */ {7, 0.2354089133666382, 0x3547667b, 0x33838942}, - /* 20 */ {7, 0.2313782131597592, 0x4c4b4000, 0xad7f29ab}, - /* 21 */ {7, 0.2276702486969530, 0x6b5a6e1d, 0x313c3d15}, - /* 22 */ {7, 0.2242438242175754, 0x94ace180, 0xb8cca9e0}, - /* 23 */ {7, 0.2210647294575037, 0xcaf18367, 0x42ed6de9}, - /* 24 */ {6, 0.2181042919855316, 0xb640000, 0x67980e0b}, - /* 25 */ {6, 0.2153382790366965, 0xe8d4a51, 0x19799812}, - /* 26 */ {6, 0.2127460535533632, 0x1269ae40, 0xbce85396}, - /* 27 */ {6, 0.2103099178571525, 0x17179149, 0x62c103a9}, - /* 28 */ {6, 0.2080145976765095, 0x1cb91000, 0x1d353d43}, - /* 29 */ {6, 0.2058468324604344, 0x23744899, 0xce1decea}, - /* 30 */ {6, 0.2037950470905062, 0x2b73a840, 0x790fc511}, - /* 31 */ {6, 0.2018490865820999, 0x34e63b41, 0x35b865a0}, - /* 32 */ {6, 0.2000000000000000, 0x5, 0x0}, - /* 33 */ {6, 0.1982398631705605, 0x4cfa3cc1, 0xa9aed1b3}, - /* 34 */ {6, 0.1965616322328226, 0x5c13d840, 0x63dfc229}, - /* 35 */ {6, 0.1949590218937863, 0x6d91b519, 0x2b0fee30}, - /* 36 */ {6, 0.1934264036172708, 0x81bf1000, 0xf91bd1b6}, - /* 37 */ {6, 0.1919587200065601, 0x98ede0c9, 0xac89c3a9}, - /* 38 */ {6, 0.1905514124267734, 0xb3773e40, 0x6d2c32fe}, - /* 39 */ {6, 0.1892003595168700, 0xd1bbc4d1, 0x387907c9}, - /* 40 */ {6, 0.1879018247091076, 0xf4240000, 0xc6f7a0b}, - /* 41 */ {5, 0.1866524112389434, 0x6e7d349, 0x28928154}, - /* 42 */ {5, 0.1854490234153689, 0x7ca30a0, 0x6e8629d}, - /* 43 */ {5, 0.1842888331487062, 0x8c32bbb, 0xd373dca0}, - /* 44 */ {5, 0.1831692509136336, 0x9d46c00, 0xa0b17895}, - /* 45 */ {5, 0.1820879004699383, 0xaffacfd, 0x746811a5}, - /* 46 */ {5, 0.1810425967800402, 0xc46bee0, 0x4da6500f}, - /* 47 */ {5, 0.1800313266566926, 0xdab86ef, 0x2ba23582}, - /* 48 */ {5, 0.1790522317510414, 0xf300000, 0xdb20a88}, - /* 49 */ {5, 0.1781035935540111, 0x10d63af1, 0xe68d5ce4}, - /* 50 */ {5, 0.1771838201355579, 0x12a05f20, 0xb7cdfd9d}, - /* 51 */ {5, 0.1762914343888821, 0x1490aae3, 0x8e583933}, - /* 52 */ {5, 0.1754250635819545, 0x16a97400, 0x697cc3ea}, - /* 53 */ {5, 0.1745834300480449, 0x18ed2825, 0x48a5ca6c}, - /* 54 */ {5, 0.1737653428714400, 0x1b5e4d60, 0x2b52db16}, - /* 55 */ {5, 0.1729696904450771, 0x1dff8297, 0x111586a6}, - /* 56 */ {5, 0.1721954337940981, 0x20d38000, 0xf31d2b36}, - /* 57 */ {5, 0.1714416005739134, 0x23dd1799, 0xc8d76d19}, - /* 58 */ {5, 0.1707072796637201, 0x271f35a0, 0xa2cb1eb4}, - /* 59 */ {5, 0.1699916162869140, 0x2a9ce10b, 0x807c3ec3}, - /* 60 */ {5, 0.1692938075987814, 0x2e593c00, 0x617ec8bf}, - /* 61 */ {5, 0.1686130986895011, 0x3257844d, 0x45746cbe}, - /* 62 */ {5, 0.1679487789570419, 0x369b13e0, 0x2c0aa273}, - /* 63 */ {5, 0.1673001788101741, 0x3b27613f, 0x14f90805}, - /* 64 */ {5, 0.1666666666666667, 0x6, 0x0}, - /* 65 */ {5, 0.1660476462159378, 0x4528a141, 0xd9cf0829}, - /* 66 */ {5, 0.1654425539190583, 0x4aa51420, 0xb6fc4841}, - /* 67 */ {5, 0.1648508567221604, 0x50794633, 0x973054cb}, - /* 68 */ {5, 0.1642720499620502, 0x56a94400, 0x7a1dbe4b}, - /* 69 */ {5, 0.1637056554452156, 0x5d393975, 0x5f7fcd7f}, - /* 70 */ {5, 0.1631512196835108, 0x642d7260, 0x47196c84}, - /* 71 */ {5, 0.1626083122716341, 0x6b8a5ae7, 0x30b43635}, - /* 72 */ {5, 0.1620765243931223, 0x73548000, 0x1c1fa5f6}, - /* 73 */ {5, 0.1615554674429964, 0x7b908fe9, 0x930634a}, - /* 74 */ {5, 0.1610447717564445, 0x84435aa0, 0xef7f4a3c}, - /* 75 */ {5, 0.1605440854340214, 0x8d71d25b, 0xcf5552d2}, - /* 76 */ {5, 0.1600530732548213, 0x97210c00, 0xb1a47c8e}, - /* 77 */ {5, 0.1595714156699382, 0xa1563f9d, 0x9634b43e}, - /* 78 */ {5, 0.1590988078692941, 0xac16c8e0, 0x7cd3817d}, - /* 79 */ {5, 0.1586349589155960, 0xb768278f, 0x65536761}, - /* 80 */ {5, 0.1581795909397823, 0xc3500000, 0x4f8b588e}, - /* 81 */ {5, 0.1577324383928644, 0xcfd41b91, 0x3b563c24}, - /* 82 */ {5, 0.1572932473495469, 0xdcfa6920, 0x28928154}, - /* 83 */ {5, 0.1568617748594410, 0xeac8fd83, 0x1721bfb0}, - /* 84 */ {5, 0.1564377883420716, 0xf9461400, 0x6e8629d}, - /* 85 */ {4, 0.1560210650222250, 0x31c84b1, 0x491cc17c}, - /* 86 */ {4, 0.1556113914024940, 0x342ab10, 0x3a11d83b}, - /* 87 */ {4, 0.1552085627701551, 0x36a2c21, 0x2be074cd}, - /* 88 */ {4, 0.1548123827357682, 0x3931000, 0x1e7a02e7}, - /* 89 */ {4, 0.1544226628011101, 0x3bd5ee1, 0x11d10edd}, - /* 90 */ {4, 0.1540392219542636, 0x3e92110, 0x5d92c68}, - /* 91 */ {4, 0.1536618862898642, 0x4165ef1, 0xf50dbfb2}, - /* 92 */ {4, 0.1532904886526781, 0x4452100, 0xdf9f1316}, - /* 93 */ {4, 0.1529248683028321, 0x4756fd1, 0xcb52a684}, - /* 94 */ {4, 0.1525648706011593, 0x4a75410, 0xb8163e97}, - /* 95 */ {4, 0.1522103467132434, 0x4dad681, 0xa5d8f269}, - /* 96 */ {4, 0.1518611533308632, 0x5100000, 0x948b0fcd}, - /* 97 */ {4, 0.1515171524096389, 0x546d981, 0x841e0215}, - /* 98 */ {4, 0.1511782109217764, 0x57f6c10, 0x74843b1e}, - /* 99 */ {4, 0.1508442006228941, 0x5b9c0d1, 0x65b11e6e}, - /* 100 */ {4, 0.1505149978319906, 0x5f5e100, 0x5798ee23}, - /* 101 */ {4, 0.1501904832236879, 0x633d5f1, 0x4a30b99b}, - /* 102 */ {4, 0.1498705416319474, 0x673a910, 0x3d6e4d94}, - /* 103 */ {4, 0.1495550618645152, 0x6b563e1, 0x314825b0}, - /* 104 */ {4, 0.1492439365274121, 0x6f91000, 0x25b55f2e}, - /* 105 */ {4, 0.1489370618588283, 0x73eb721, 0x1aadaccb}, - /* 106 */ {4, 0.1486343375718350, 0x7866310, 0x10294ba2}, - /* 107 */ {4, 0.1483356667053617, 0x7d01db1, 0x620f8f6}, - /* 108 */ {4, 0.1480409554829326, 0x81bf100, 0xf91bd1b6}, - /* 109 */ {4, 0.1477501131786861, 0x869e711, 0xe6d37b2a}, - /* 110 */ {4, 0.1474630519902391, 0x8ba0a10, 0xd55cff6e}, - /* 111 */ {4, 0.1471796869179852, 0x90c6441, 0xc4ad2db2}, - /* 112 */ {4, 0.1468999356504447, 0x9610000, 0xb4b985cf}, - /* 113 */ {4, 0.1466237184553111, 0x9b7e7c1, 0xa5782bef}, - /* 114 */ {4, 0.1463509580758620, 0xa112610, 0x96dfdd2a}, - /* 115 */ {4, 0.1460815796324244, 0xa6cc591, 0x88e7e509}, - /* 116 */ {4, 0.1458155105286054, 0xacad100, 0x7b8813d3}, - /* 117 */ {4, 0.1455526803620167, 0xb2b5331, 0x6eb8b595}, - /* 118 */ {4, 0.1452930208392428, 0xb8e5710, 0x627289db}, - /* 119 */ {4, 0.1450364656948130, 0xbf3e7a1, 0x56aebc07}, - /* 120 */ {4, 0.1447829506139581, 0xc5c1000, 0x4b66dc33}, - /* 121 */ {4, 0.1445324131589439, 0xcc6db61, 0x4094d8a3}, - /* 122 */ {4, 0.1442847926987864, 0xd345510, 0x3632f7a5}, - /* 123 */ {4, 0.1440400303421672, 0xda48871, 0x2c3bd1f0}, - /* 124 */ {4, 0.1437980688733775, 0xe178100, 0x22aa4d5f}, - /* 125 */ {4, 0.1435588526911310, 0xe8d4a51, 0x19799812}, - /* 126 */ {4, 0.1433223277500932, 0xf05f010, 0x10a523e5}, - /* 127 */ {4, 0.1430884415049874, 0xf817e01, 0x828a237}, - /* 128 */ {4, 0.1428571428571428, 0x7, 0x0}, - /* 129 */ {4, 0.1426283821033600, 0x10818201, 0xf04ec452}, - /* 130 */ {4, 0.1424021108869747, 0x11061010, 0xe136444a}, - /* 131 */ {4, 0.1421782821510107, 0x118db651, 0xd2af9589}, - /* 132 */ {4, 0.1419568500933153, 0x12188100, 0xc4b42a83}, - /* 133 */ {4, 0.1417377701235801, 0x12a67c71, 0xb73dccf5}, - /* 134 */ {4, 0.1415209988221527, 0x1337b510, 0xaa4698c5}, - /* 135 */ {4, 0.1413064939005528, 0x13cc3761, 0x9dc8f729}, - /* 136 */ {4, 0.1410942141636095, 0x14641000, 0x91bf9a30}, - /* 137 */ {4, 0.1408841194731412, 0x14ff4ba1, 0x86257887}, - /* 138 */ {4, 0.1406761707131039, 0x159df710, 0x7af5c98c}, - /* 139 */ {4, 0.1404703297561400, 0x16401f31, 0x702c01a0}, - /* 140 */ {4, 0.1402665594314587, 0x16e5d100, 0x65c3ceb1}, - /* 141 */ {4, 0.1400648234939879, 0x178f1991, 0x5bb91502}, - /* 142 */ {4, 0.1398650865947379, 0x183c0610, 0x5207ec23}, - /* 143 */ {4, 0.1396673142523192, 0x18eca3c1, 0x48ac9c19}, - /* 144 */ {4, 0.1394714728255649, 0x19a10000, 0x3fa39ab5}, - /* 145 */ {4, 0.1392775294872041, 0x1a592841, 0x36e98912}, - /* 146 */ {4, 0.1390854521985406, 0x1b152a10, 0x2e7b3140}, - /* 147 */ {4, 0.1388952096850913, 0x1bd51311, 0x2655840b}, - /* 148 */ {4, 0.1387067714131417, 0x1c98f100, 0x1e7596ea}, - /* 149 */ {4, 0.1385201075671774, 0x1d60d1b1, 0x16d8a20d}, - /* 150 */ {4, 0.1383351890281539, 0x1e2cc310, 0xf7bfe87}, - /* 151 */ {4, 0.1381519873525671, 0x1efcd321, 0x85d2492}, - /* 152 */ {4, 0.1379704747522905, 0x1fd11000, 0x179a9f4}, - /* 153 */ {4, 0.1377906240751463, 0x20a987e1, 0xf59e80eb}, - /* 154 */ {4, 0.1376124087861776, 0x21864910, 0xe8b768db}, - /* 155 */ {4, 0.1374358029495937, 0x226761f1, 0xdc39d6d5}, - /* 156 */ {4, 0.1372607812113589, 0x234ce100, 0xd021c5d1}, - /* 157 */ {4, 0.1370873187823978, 0x2436d4d1, 0xc46b5e37}, - /* 158 */ {4, 0.1369153914223921, 0x25254c10, 0xb912f39c}, - /* 159 */ {4, 0.1367449754241439, 0x26185581, 0xae150294}, - /* 160 */ {4, 0.1365760475984821, 0x27100000, 0xa36e2eb1}, - /* 161 */ {4, 0.1364085852596902, 0x280c5a81, 0x991b4094}, - /* 162 */ {4, 0.1362425662114337, 0x290d7410, 0x8f19241e}, - /* 163 */ {4, 0.1360779687331669, 0x2a135bd1, 0x8564e6b7}, - /* 164 */ {4, 0.1359147715670014, 0x2b1e2100, 0x7bfbb5b4}, - /* 165 */ {4, 0.1357529539050150, 0x2c2dd2f1, 0x72dadcc8}, - /* 166 */ {4, 0.1355924953769863, 0x2d428110, 0x69ffc498}, - /* 167 */ {4, 0.1354333760385373, 0x2e5c3ae1, 0x6167f154}, - /* 168 */ {4, 0.1352755763596663, 0x2f7b1000, 0x5911016e}, - /* 169 */ {4, 0.1351190772136599, 0x309f1021, 0x50f8ac5f}, - /* 170 */ {4, 0.1349638598663645, 0x31c84b10, 0x491cc17c}, - /* 171 */ {4, 0.1348099059658079, 0x32f6d0b1, 0x417b26d8}, - /* 172 */ {4, 0.1346571975321549, 0x342ab100, 0x3a11d83b}, - /* 173 */ {4, 0.1345057169479844, 0x3563fc11, 0x32dee622}, - /* 174 */ {4, 0.1343554469488779, 0x36a2c210, 0x2be074cd}, - /* 175 */ {4, 0.1342063706143054, 0x37e71341, 0x2514bb58}, - /* 176 */ {4, 0.1340584713587980, 0x39310000, 0x1e7a02e7}, - /* 177 */ {4, 0.1339117329233981, 0x3a8098c1, 0x180ea5d0}, - /* 178 */ {4, 0.1337661393673756, 0x3bd5ee10, 0x11d10edd}, - /* 179 */ {4, 0.1336216750601996, 0x3d311091, 0xbbfb88e}, - /* 180 */ {4, 0.1334783246737591, 0x3e921100, 0x5d92c68}, - /* 181 */ {4, 0.1333360731748201, 0x3ff90031, 0x1c024c}, - /* 182 */ {4, 0.1331949058177136, 0x4165ef10, 0xf50dbfb2}, - /* 183 */ {4, 0.1330548081372441, 0x42d8eea1, 0xea30efa3}, - /* 184 */ {4, 0.1329157659418126, 0x44521000, 0xdf9f1316}, - /* 185 */ {4, 0.1327777653067443, 0x45d16461, 0xd555c0c9}, - /* 186 */ {4, 0.1326407925678156, 0x4756fd10, 0xcb52a684}, - /* 187 */ {4, 0.1325048343149731, 0x48e2eb71, 0xc193881f}, - /* 188 */ {4, 0.1323698773862368, 0x4a754100, 0xb8163e97}, - /* 189 */ {4, 0.1322359088617821, 0x4c0e0f51, 0xaed8b724}, - /* 190 */ {4, 0.1321029160581950, 0x4dad6810, 0xa5d8f269}, - /* 191 */ {4, 0.1319708865228925, 0x4f535d01, 0x9d15039d}, - /* 192 */ {4, 0.1318398080287045, 0x51000000, 0x948b0fcd}, - /* 193 */ {4, 0.1317096685686114, 0x52b36301, 0x8c394d1d}, - /* 194 */ {4, 0.1315804563506306, 0x546d9810, 0x841e0215}, - /* 195 */ {4, 0.1314521597928493, 0x562eb151, 0x7c3784f8}, - /* 196 */ {4, 0.1313247675185968, 0x57f6c100, 0x74843b1e}, - /* 197 */ {4, 0.1311982683517524, 0x59c5d971, 0x6d02985d}, - /* 198 */ {4, 0.1310726513121843, 0x5b9c0d10, 0x65b11e6e}, - /* 199 */ {4, 0.1309479056113158, 0x5d796e61, 0x5e8e5c64}, - /* 200 */ {4, 0.1308240206478128, 0x5f5e1000, 0x5798ee23}, - /* 201 */ {4, 0.1307009860033912, 0x614a04a1, 0x50cf7bde}, - /* 202 */ {4, 0.1305787914387386, 0x633d5f10, 0x4a30b99b}, - /* 203 */ {4, 0.1304574268895465, 0x65383231, 0x43bb66bd}, - /* 204 */ {4, 0.1303368824626505, 0x673a9100, 0x3d6e4d94}, - /* 205 */ {4, 0.1302171484322746, 0x69448e91, 0x374842ee}, - /* 206 */ {4, 0.1300982152363760, 0x6b563e10, 0x314825b0}, - /* 207 */ {4, 0.1299800734730872, 0x6d6fb2c1, 0x2b6cde75}, - /* 208 */ {4, 0.1298627138972530, 0x6f910000, 0x25b55f2e}, - /* 209 */ {4, 0.1297461274170591, 0x71ba3941, 0x2020a2c5}, - /* 210 */ {4, 0.1296303050907487, 0x73eb7210, 0x1aadaccb}, - /* 211 */ {4, 0.1295152381234257, 0x7624be11, 0x155b891f}, - /* 212 */ {4, 0.1294009178639407, 0x78663100, 0x10294ba2}, - /* 213 */ {4, 0.1292873358018581, 0x7aafdeb1, 0xb160fe9}, - /* 214 */ {4, 0.1291744835645007, 0x7d01db10, 0x620f8f6}, - /* 215 */ {4, 0.1290623529140715, 0x7f5c3a21, 0x14930ef}, - /* 216 */ {4, 0.1289509357448472, 0x81bf1000, 0xf91bd1b6}, - /* 217 */ {4, 0.1288402240804449, 0x842a70e1, 0xefdcb0c7}, - /* 218 */ {4, 0.1287302100711567, 0x869e7110, 0xe6d37b2a}, - /* 219 */ {4, 0.1286208859913518, 0x891b24f1, 0xddfeb94a}, - /* 220 */ {4, 0.1285122442369443, 0x8ba0a100, 0xd55cff6e}, - /* 221 */ {4, 0.1284042773229231, 0x8e2ef9d1, 0xcceced50}, - /* 222 */ {4, 0.1282969778809442, 0x90c64410, 0xc4ad2db2}, - /* 223 */ {4, 0.1281903386569819, 0x93669481, 0xbc9c75f9}, - /* 224 */ {4, 0.1280843525090381, 0x96100000, 0xb4b985cf}, - /* 225 */ {4, 0.1279790124049077, 0x98c29b81, 0xad0326c2}, - /* 226 */ {4, 0.1278743114199984, 0x9b7e7c10, 0xa5782bef}, - /* 227 */ {4, 0.1277702427352035, 0x9e43b6d1, 0x9e1771a9}, - /* 228 */ {4, 0.1276667996348261, 0xa1126100, 0x96dfdd2a}, - /* 229 */ {4, 0.1275639755045533, 0xa3ea8ff1, 0x8fd05c41}, - /* 230 */ {4, 0.1274617638294791, 0xa6cc5910, 0x88e7e509}, - /* 231 */ {4, 0.1273601581921741, 0xa9b7d1e1, 0x8225759d}, - /* 232 */ {4, 0.1272591522708010, 0xacad1000, 0x7b8813d3}, - /* 233 */ {4, 0.1271587398372755, 0xafac2921, 0x750eccf9}, - /* 234 */ {4, 0.1270589147554692, 0xb2b53310, 0x6eb8b595}, - /* 235 */ {4, 0.1269596709794558, 0xb5c843b1, 0x6884e923}, - /* 236 */ {4, 0.1268610025517973, 0xb8e57100, 0x627289db}, - /* 237 */ {4, 0.1267629036018709, 0xbc0cd111, 0x5c80c07b}, - /* 238 */ {4, 0.1266653683442337, 0xbf3e7a10, 0x56aebc07}, - /* 239 */ {4, 0.1265683910770258, 0xc27a8241, 0x50fbb19b}, - /* 240 */ {4, 0.1264719661804097, 0xc5c10000, 0x4b66dc33}, - /* 241 */ {4, 0.1263760881150453, 0xc91209c1, 0x45ef7c7c}, - /* 242 */ {4, 0.1262807514205999, 0xcc6db610, 0x4094d8a3}, - /* 243 */ {4, 0.1261859507142915, 0xcfd41b91, 0x3b563c24}, - /* 244 */ {4, 0.1260916806894653, 0xd3455100, 0x3632f7a5}, - /* 245 */ {4, 0.1259979361142023, 0xd6c16d31, 0x312a60c3}, - /* 246 */ {4, 0.1259047118299582, 0xda488710, 0x2c3bd1f0}, - /* 247 */ {4, 0.1258120027502338, 0xdddab5a1, 0x2766aa45}, - /* 248 */ {4, 0.1257198038592741, 0xe1781000, 0x22aa4d5f}, - /* 249 */ {4, 0.1256281102107963, 0xe520ad61, 0x1e06233c}, - /* 250 */ {4, 0.1255369169267456, 0xe8d4a510, 0x19799812}, - /* 251 */ {4, 0.1254462191960791, 0xec940e71, 0x15041c33}, - /* 252 */ {4, 0.1253560122735751, 0xf05f0100, 0x10a523e5}, - /* 253 */ {4, 0.1252662914786691, 0xf4359451, 0xc5c2749}, - /* 254 */ {4, 0.1251770521943144, 0xf817e010, 0x828a237}, - /* 255 */ {4, 0.1250882898658681, 0xfc05fc01, 0x40a1423}, -}; -#endif -#if BITS_PER_MP_LIMB == 64 -const struct bases __mp_bases[256] = -{ - /* 0 */ {0, 0.0, 0, 0}, - /* 1 */ {0, 1e38, 0, 0}, - /* 2 */ {64, 1.0000000000000000, CNST_LIMB(0x1), CNST_LIMB(0x0)}, - /* 3 */ {40, 0.6309297535714574, CNST_LIMB(0xa8b8b452291fe821), CNST_LIMB(0x846d550e37b5063d)}, - /* 4 */ {32, 0.5000000000000000, CNST_LIMB(0x2), CNST_LIMB(0x0)}, - /* 5 */ {27, 0.4306765580733931, CNST_LIMB(0x6765c793fa10079d), CNST_LIMB(0x3ce9a36f23c0fc90)}, - /* 6 */ {24, 0.3868528072345416, CNST_LIMB(0x41c21cb8e1000000), CNST_LIMB(0xf24f62335024a295)}, - /* 7 */ {22, 0.3562071871080222, CNST_LIMB(0x3642798750226111), CNST_LIMB(0x2df495ccaa57147b)}, - /* 8 */ {21, 0.3333333333333334, CNST_LIMB(0x3), CNST_LIMB(0x0)}, - /* 9 */ {20, 0.3154648767857287, CNST_LIMB(0xa8b8b452291fe821), CNST_LIMB(0x846d550e37b5063d)}, - /* 10 */ {19, 0.3010299956639811, CNST_LIMB(0x8ac7230489e80000), CNST_LIMB(0xd83c94fb6d2ac34a)}, - /* 11 */ {18, 0.2890648263178878, CNST_LIMB(0x4d28cb56c33fa539), CNST_LIMB(0xa8adf7ae45e7577b)}, - /* 12 */ {17, 0.2789429456511298, CNST_LIMB(0x1eca170c00000000), CNST_LIMB(0xa10c2bec5da8f8f)}, - /* 13 */ {17, 0.2702381544273197, CNST_LIMB(0x780c7372621bd74d), CNST_LIMB(0x10f4becafe412ec3)}, - /* 14 */ {16, 0.2626495350371936, CNST_LIMB(0x1e39a5057d810000), CNST_LIMB(0xf08480f672b4e86)}, - /* 15 */ {16, 0.2559580248098155, CNST_LIMB(0x5b27ac993df97701), CNST_LIMB(0x6779c7f90dc42f48)}, - /* 16 */ {16, 0.2500000000000000, CNST_LIMB(0x4), CNST_LIMB(0x0)}, - /* 17 */ {15, 0.2446505421182260, CNST_LIMB(0x27b95e997e21d9f1), CNST_LIMB(0x9c71e11bab279323)}, - /* 18 */ {15, 0.2398124665681315, CNST_LIMB(0x5da0e1e53c5c8000), CNST_LIMB(0x5dfaa697ec6f6a1c)}, - /* 19 */ {15, 0.2354089133666382, CNST_LIMB(0xd2ae3299c1c4aedb), CNST_LIMB(0x3711783f6be7e9ec)}, - /* 20 */ {14, 0.2313782131597592, CNST_LIMB(0x16bcc41e90000000), CNST_LIMB(0x6849b86a12b9b01e)}, - /* 21 */ {14, 0.2276702486969530, CNST_LIMB(0x2d04b7fdd9c0ef49), CNST_LIMB(0x6bf097ba5ca5e239)}, - /* 22 */ {14, 0.2242438242175754, CNST_LIMB(0x5658597bcaa24000), CNST_LIMB(0x7b8015c8d7af8f08)}, - /* 23 */ {14, 0.2210647294575037, CNST_LIMB(0xa0e2073737609371), CNST_LIMB(0x975a24b3a3151b38)}, - /* 24 */ {13, 0.2181042919855316, CNST_LIMB(0xc29e98000000000), CNST_LIMB(0x50bd367972689db1)}, - /* 25 */ {13, 0.2153382790366965, CNST_LIMB(0x14adf4b7320334b9), CNST_LIMB(0x8c240c4aecb13bb5)}, - /* 26 */ {13, 0.2127460535533632, CNST_LIMB(0x226ed36478bfa000), CNST_LIMB(0xdbd2e56854e118c9)}, - /* 27 */ {13, 0.2103099178571525, CNST_LIMB(0x383d9170b85ff80b), CNST_LIMB(0x2351ffcaa9c7c4ae)}, - /* 28 */ {13, 0.2080145976765095, CNST_LIMB(0x5a3c23e39c000000), CNST_LIMB(0x6b24188ca33b0636)}, - /* 29 */ {13, 0.2058468324604344, CNST_LIMB(0x8e65137388122bcd), CNST_LIMB(0xcc3dceaf2b8ba99d)}, - /* 30 */ {13, 0.2037950470905062, CNST_LIMB(0xdd41bb36d259e000), CNST_LIMB(0x2832e835c6c7d6b6)}, - /* 31 */ {12, 0.2018490865820999, CNST_LIMB(0xaee5720ee830681), CNST_LIMB(0x76b6aa272e1873c5)}, - /* 32 */ {12, 0.2000000000000000, CNST_LIMB(0x5), CNST_LIMB(0x0)}, - /* 33 */ {12, 0.1982398631705605, CNST_LIMB(0x172588ad4f5f0981), CNST_LIMB(0x61eaf5d402c7bf4f)}, - /* 34 */ {12, 0.1965616322328226, CNST_LIMB(0x211e44f7d02c1000), CNST_LIMB(0xeeb658123ffb27ec)}, - /* 35 */ {12, 0.1949590218937863, CNST_LIMB(0x2ee56725f06e5c71), CNST_LIMB(0x5d5e3762e6fdf509)}, - /* 36 */ {12, 0.1934264036172708, CNST_LIMB(0x41c21cb8e1000000), CNST_LIMB(0xf24f62335024a295)}, - /* 37 */ {12, 0.1919587200065601, CNST_LIMB(0x5b5b57f8a98a5dd1), CNST_LIMB(0x66ae7831762efb6f)}, - /* 38 */ {12, 0.1905514124267734, CNST_LIMB(0x7dcff8986ea31000), CNST_LIMB(0x47388865a00f544)}, - /* 39 */ {12, 0.1892003595168700, CNST_LIMB(0xabd4211662a6b2a1), CNST_LIMB(0x7d673c33a123b54c)}, - /* 40 */ {12, 0.1879018247091076, CNST_LIMB(0xe8d4a51000000000), CNST_LIMB(0x19799812dea11197)}, - /* 41 */ {11, 0.1866524112389434, CNST_LIMB(0x7a32956ad081b79), CNST_LIMB(0xc27e62e0686feae)}, - /* 42 */ {11, 0.1854490234153689, CNST_LIMB(0x9f49aaff0e86800), CNST_LIMB(0x9b6e7507064ce7c7)}, - /* 43 */ {11, 0.1842888331487062, CNST_LIMB(0xce583bb812d37b3), CNST_LIMB(0x3d9ac2bf66cfed94)}, - /* 44 */ {11, 0.1831692509136336, CNST_LIMB(0x109b79a654c00000), CNST_LIMB(0xed46bc50ce59712a)}, - /* 45 */ {11, 0.1820879004699383, CNST_LIMB(0x1543beff214c8b95), CNST_LIMB(0x813d97e2c89b8d46)}, - /* 46 */ {11, 0.1810425967800402, CNST_LIMB(0x1b149a79459a3800), CNST_LIMB(0x2e81751956af8083)}, - /* 47 */ {11, 0.1800313266566926, CNST_LIMB(0x224edfb5434a830f), CNST_LIMB(0xdd8e0a95e30c0988)}, - /* 48 */ {11, 0.1790522317510413, CNST_LIMB(0x2b3fb00000000000), CNST_LIMB(0x7ad4dd48a0b5b167)}, - /* 49 */ {11, 0.1781035935540111, CNST_LIMB(0x3642798750226111), CNST_LIMB(0x2df495ccaa57147b)}, - /* 50 */ {11, 0.1771838201355579, CNST_LIMB(0x43c33c1937564800), CNST_LIMB(0xe392010175ee5962)}, - /* 51 */ {11, 0.1762914343888821, CNST_LIMB(0x54411b2441c3cd8b), CNST_LIMB(0x84eaf11b2fe7738e)}, - /* 52 */ {11, 0.1754250635819545, CNST_LIMB(0x6851455acd400000), CNST_LIMB(0x3a1e3971e008995d)}, - /* 53 */ {11, 0.1745834300480449, CNST_LIMB(0x80a23b117c8feb6d), CNST_LIMB(0xfd7a462344ffce25)}, - /* 54 */ {11, 0.1737653428714400, CNST_LIMB(0x9dff7d32d5dc1800), CNST_LIMB(0x9eca40b40ebcef8a)}, - /* 55 */ {11, 0.1729696904450771, CNST_LIMB(0xc155af6faeffe6a7), CNST_LIMB(0x52fa161a4a48e43d)}, - /* 56 */ {11, 0.1721954337940981, CNST_LIMB(0xebb7392e00000000), CNST_LIMB(0x1607a2cbacf930c1)}, - /* 57 */ {10, 0.1714416005739134, CNST_LIMB(0x50633659656d971), CNST_LIMB(0x97a014f8e3be55f1)}, - /* 58 */ {10, 0.1707072796637201, CNST_LIMB(0x5fa8624c7fba400), CNST_LIMB(0x568df8b76cbf212c)}, - /* 59 */ {10, 0.1699916162869140, CNST_LIMB(0x717d9faa73c5679), CNST_LIMB(0x20ba7c4b4e6ef492)}, - /* 60 */ {10, 0.1692938075987814, CNST_LIMB(0x86430aac6100000), CNST_LIMB(0xe81ee46b9ef492f5)}, - /* 61 */ {10, 0.1686130986895011, CNST_LIMB(0x9e64d9944b57f29), CNST_LIMB(0x9dc0d10d51940416)}, - /* 62 */ {10, 0.1679487789570419, CNST_LIMB(0xba5ca5392cb0400), CNST_LIMB(0x5fa8ed2f450272a5)}, - /* 63 */ {10, 0.1673001788101741, CNST_LIMB(0xdab2ce1d022cd81), CNST_LIMB(0x2ba9eb8c5e04e641)}, - /* 64 */ {10, 0.1666666666666667, CNST_LIMB(0x6), CNST_LIMB(0x0)}, - /* 65 */ {10, 0.1660476462159378, CNST_LIMB(0x12aeed5fd3e2d281), CNST_LIMB(0xb67759cc00287bf1)}, - /* 66 */ {10, 0.1654425539190583, CNST_LIMB(0x15c3da1572d50400), CNST_LIMB(0x78621feeb7f4ed33)}, - /* 67 */ {10, 0.1648508567221604, CNST_LIMB(0x194c05534f75ee29), CNST_LIMB(0x43d55b5f72943bc0)}, - /* 68 */ {10, 0.1642720499620502, CNST_LIMB(0x1d56299ada100000), CNST_LIMB(0x173decb64d1d4409)}, - /* 69 */ {10, 0.1637056554452156, CNST_LIMB(0x21f2a089a4ff4f79), CNST_LIMB(0xe29fb54fd6b6074f)}, - /* 70 */ {10, 0.1631512196835108, CNST_LIMB(0x2733896c68d9a400), CNST_LIMB(0xa1f1f5c210d54e62)}, - /* 71 */ {10, 0.1626083122716341, CNST_LIMB(0x2d2cf2c33b533c71), CNST_LIMB(0x6aac7f9bfafd57b2)}, - /* 72 */ {10, 0.1620765243931223, CNST_LIMB(0x33f506e440000000), CNST_LIMB(0x3b563c2478b72ee2)}, - /* 73 */ {10, 0.1615554674429964, CNST_LIMB(0x3ba43bec1d062211), CNST_LIMB(0x12b536b574e92d1b)}, - /* 74 */ {10, 0.1610447717564444, CNST_LIMB(0x4455872d8fd4e400), CNST_LIMB(0xdf86c03020404fa5)}, - /* 75 */ {10, 0.1605440854340214, CNST_LIMB(0x4e2694539f2f6c59), CNST_LIMB(0xa34adf02234eea8e)}, - /* 76 */ {10, 0.1600530732548213, CNST_LIMB(0x5938006c18900000), CNST_LIMB(0x6f46eb8574eb59dd)}, - /* 77 */ {10, 0.1595714156699382, CNST_LIMB(0x65ad9912474aa649), CNST_LIMB(0x42459b481df47cec)}, - /* 78 */ {10, 0.1590988078692941, CNST_LIMB(0x73ae9ff4241ec400), CNST_LIMB(0x1b424b95d80ca505)}, - /* 79 */ {10, 0.1586349589155960, CNST_LIMB(0x836612ee9c4ce1e1), CNST_LIMB(0xf2c1b982203a0dac)}, - /* 80 */ {10, 0.1581795909397823, CNST_LIMB(0x9502f90000000000), CNST_LIMB(0xb7cdfd9d7bdbab7d)}, - /* 81 */ {10, 0.1577324383928644, CNST_LIMB(0xa8b8b452291fe821), CNST_LIMB(0x846d550e37b5063d)}, - /* 82 */ {10, 0.1572932473495469, CNST_LIMB(0xbebf59a07dab4400), CNST_LIMB(0x57931eeaf85cf64f)}, - /* 83 */ {10, 0.1568617748594410, CNST_LIMB(0xd7540d4093bc3109), CNST_LIMB(0x305a944507c82f47)}, - /* 84 */ {10, 0.1564377883420716, CNST_LIMB(0xf2b96616f1900000), CNST_LIMB(0xe007ccc9c22781a)}, - /* 85 */ {9, 0.1560210650222250, CNST_LIMB(0x336de62af2bca35), CNST_LIMB(0x3e92c42e000eeed4)}, - /* 86 */ {9, 0.1556113914024940, CNST_LIMB(0x39235ec33d49600), CNST_LIMB(0x1ebe59130db2795e)}, - /* 87 */ {9, 0.1552085627701551, CNST_LIMB(0x3f674e539585a17), CNST_LIMB(0x268859e90f51b89)}, - /* 88 */ {9, 0.1548123827357682, CNST_LIMB(0x4645b6958000000), CNST_LIMB(0xd24cde0463108cfa)}, - /* 89 */ {9, 0.1544226628011101, CNST_LIMB(0x4dcb74afbc49c19), CNST_LIMB(0xa536009f37adc383)}, - /* 90 */ {9, 0.1540392219542636, CNST_LIMB(0x56064e1d18d9a00), CNST_LIMB(0x7cea06ce1c9ace10)}, - /* 91 */ {9, 0.1536618862898642, CNST_LIMB(0x5f04fe2cd8a39fb), CNST_LIMB(0x58db032e72e8ba43)}, - /* 92 */ {9, 0.1532904886526781, CNST_LIMB(0x68d74421f5c0000), CNST_LIMB(0x388cc17cae105447)}, - /* 93 */ {9, 0.1529248683028321, CNST_LIMB(0x738df1f6ab4827d), CNST_LIMB(0x1b92672857620ce0)}, - /* 94 */ {9, 0.1525648706011593, CNST_LIMB(0x7f3afbc9cfb5e00), CNST_LIMB(0x18c6a9575c2ade4)}, - /* 95 */ {9, 0.1522103467132434, CNST_LIMB(0x8bf187fba88f35f), CNST_LIMB(0xd44da7da8e44b24f)}, - /* 96 */ {9, 0.1518611533308632, CNST_LIMB(0x99c600000000000), CNST_LIMB(0xaa2f78f1b4cc6794)}, - /* 97 */ {9, 0.1515171524096389, CNST_LIMB(0xa8ce21eb6531361), CNST_LIMB(0x843c067d091ee4cc)}, - /* 98 */ {9, 0.1511782109217764, CNST_LIMB(0xb92112c1a0b6200), CNST_LIMB(0x62005e1e913356e3)}, - /* 99 */ {9, 0.1508442006228941, CNST_LIMB(0xcad7718b8747c43), CNST_LIMB(0x4316eed01dedd518)}, - /* 100 */ {9, 0.1505149978319906, CNST_LIMB(0xde0b6b3a7640000), CNST_LIMB(0x2725dd1d243aba0e)}, - /* 101 */ {9, 0.1501904832236879, CNST_LIMB(0xf2d8cf5fe6d74c5), CNST_LIMB(0xddd9057c24cb54f)}, - /* 102 */ {9, 0.1498705416319474, CNST_LIMB(0x1095d25bfa712600), CNST_LIMB(0xedeee175a736d2a1)}, - /* 103 */ {9, 0.1495550618645152, CNST_LIMB(0x121b7c4c3698faa7), CNST_LIMB(0xc4699f3df8b6b328)}, - /* 104 */ {9, 0.1492439365274121, CNST_LIMB(0x13c09e8d68000000), CNST_LIMB(0x9ebbe7d859cb5a7c)}, - /* 105 */ {9, 0.1489370618588283, CNST_LIMB(0x15876ccb0b709ca9), CNST_LIMB(0x7c828b9887eb2179)}, - /* 106 */ {9, 0.1486343375718350, CNST_LIMB(0x17723c2976da2a00), CNST_LIMB(0x5d652ab99001adcf)}, - /* 107 */ {9, 0.1483356667053617, CNST_LIMB(0x198384e9c259048b), CNST_LIMB(0x4114f1754e5d7b32)}, - /* 108 */ {9, 0.1480409554829326, CNST_LIMB(0x1bbde41dfeec0000), CNST_LIMB(0x274b7c902f7e0188)}, - /* 109 */ {9, 0.1477501131786861, CNST_LIMB(0x1e241d6e3337910d), CNST_LIMB(0xfc9e0fbb32e210c)}, - /* 110 */ {9, 0.1474630519902391, CNST_LIMB(0x20b91cee9901ee00), CNST_LIMB(0xf4afa3e594f8ea1f)}, - /* 111 */ {9, 0.1471796869179852, CNST_LIMB(0x237ff9079863dfef), CNST_LIMB(0xcd85c32e9e4437b0)}, - /* 112 */ {9, 0.1468999356504447, CNST_LIMB(0x267bf47000000000), CNST_LIMB(0xa9bbb147e0dd92a8)}, - /* 113 */ {9, 0.1466237184553111, CNST_LIMB(0x29b08039fbeda7f1), CNST_LIMB(0x8900447b70e8eb82)}, - /* 114 */ {9, 0.1463509580758620, CNST_LIMB(0x2d213df34f65f200), CNST_LIMB(0x6b0a92adaad5848a)}, - /* 115 */ {9, 0.1460815796324244, CNST_LIMB(0x30d201d957a7c2d3), CNST_LIMB(0x4f990ad8740f0ee5)}, - /* 116 */ {9, 0.1458155105286054, CNST_LIMB(0x34c6d52160f40000), CNST_LIMB(0x3670a9663a8d3610)}, - /* 117 */ {9, 0.1455526803620167, CNST_LIMB(0x3903f855d8f4c755), CNST_LIMB(0x1f5c44188057be3c)}, - /* 118 */ {9, 0.1452930208392428, CNST_LIMB(0x3d8de5c8ec59b600), CNST_LIMB(0xa2bea956c4e4977)}, - /* 119 */ {9, 0.1450364656948130, CNST_LIMB(0x4269541d1ff01337), CNST_LIMB(0xed68b23033c3637e)}, - /* 120 */ {9, 0.1447829506139581, CNST_LIMB(0x479b38e478000000), CNST_LIMB(0xc99cf624e50549c5)}, - /* 121 */ {9, 0.1445324131589439, CNST_LIMB(0x4d28cb56c33fa539), CNST_LIMB(0xa8adf7ae45e7577b)}, - /* 122 */ {9, 0.1442847926987864, CNST_LIMB(0x5317871fa13aba00), CNST_LIMB(0x8a5bc740b1c113e5)}, - /* 123 */ {9, 0.1440400303421672, CNST_LIMB(0x596d2f44de9fa71b), CNST_LIMB(0x6e6c7efb81cfbb9b)}, - /* 124 */ {9, 0.1437980688733775, CNST_LIMB(0x602fd125c47c0000), CNST_LIMB(0x54aba5c5cada5f10)}, - /* 125 */ {9, 0.1435588526911310, CNST_LIMB(0x6765c793fa10079d), CNST_LIMB(0x3ce9a36f23c0fc90)}, - /* 126 */ {9, 0.1433223277500932, CNST_LIMB(0x6f15be069b847e00), CNST_LIMB(0x26fb43de2c8cd2a8)}, - /* 127 */ {9, 0.1430884415049874, CNST_LIMB(0x7746b3e82a77047f), CNST_LIMB(0x12b94793db8486a1)}, - /* 128 */ {9, 0.1428571428571428, CNST_LIMB(0x7), CNST_LIMB(0x0)}, - /* 129 */ {9, 0.1426283821033600, CNST_LIMB(0x894953f7ea890481), CNST_LIMB(0xdd5deca404c0156d)}, - /* 130 */ {9, 0.1424021108869747, CNST_LIMB(0x932abffea4848200), CNST_LIMB(0xbd51373330291de0)}, - /* 131 */ {9, 0.1421782821510107, CNST_LIMB(0x9dacb687d3d6a163), CNST_LIMB(0x9fa4025d66f23085)}, - /* 132 */ {9, 0.1419568500933153, CNST_LIMB(0xa8d8102a44840000), CNST_LIMB(0x842530ee2db4949d)}, - /* 133 */ {9, 0.1417377701235801, CNST_LIMB(0xb4b60f9d140541e5), CNST_LIMB(0x6aa7f2766b03dc25)}, - /* 134 */ {9, 0.1415209988221527, CNST_LIMB(0xc15065d4856e4600), CNST_LIMB(0x53035ba7ebf32e8d)}, - /* 135 */ {9, 0.1413064939005528, CNST_LIMB(0xceb1363f396d23c7), CNST_LIMB(0x3d12091fc9fb4914)}, - /* 136 */ {9, 0.1410942141636095, CNST_LIMB(0xdce31b2488000000), CNST_LIMB(0x28b1cb81b1ef1849)}, - /* 137 */ {9, 0.1408841194731412, CNST_LIMB(0xebf12a24bca135c9), CNST_LIMB(0x15c35be67ae3e2c9)}, - /* 138 */ {9, 0.1406761707131039, CNST_LIMB(0xfbe6f8dbf88f4a00), CNST_LIMB(0x42a17bd09be1ff0)}, - /* 139 */ {8, 0.1404703297561400, CNST_LIMB(0x1ef156c084ce761), CNST_LIMB(0x8bf461f03cf0bbf)}, - /* 140 */ {8, 0.1402665594314587, CNST_LIMB(0x20c4e3b94a10000), CNST_LIMB(0xf3fbb43f68a32d05)}, - /* 141 */ {8, 0.1400648234939879, CNST_LIMB(0x22b0695a08ba421), CNST_LIMB(0xd84f44c48564dc19)}, - /* 142 */ {8, 0.1398650865947379, CNST_LIMB(0x24b4f35d7a4c100), CNST_LIMB(0xbe58ebcce7956abe)}, - /* 143 */ {8, 0.1396673142523192, CNST_LIMB(0x26d397284975781), CNST_LIMB(0xa5fac463c7c134b7)}, - /* 144 */ {8, 0.1394714728255649, CNST_LIMB(0x290d74100000000), CNST_LIMB(0x8f19241e28c7d757)}, - /* 145 */ {8, 0.1392775294872041, CNST_LIMB(0x2b63b3a37866081), CNST_LIMB(0x799a6d046c0ae1ae)}, - /* 146 */ {8, 0.1390854521985406, CNST_LIMB(0x2dd789f4d894100), CNST_LIMB(0x6566e37d746a9e40)}, - /* 147 */ {8, 0.1388952096850913, CNST_LIMB(0x306a35e51b58721), CNST_LIMB(0x526887dbfb5f788f)}, - /* 148 */ {8, 0.1387067714131417, CNST_LIMB(0x331d01712e10000), CNST_LIMB(0x408af3382b8efd3d)}, - /* 149 */ {8, 0.1385201075671774, CNST_LIMB(0x35f14200a827c61), CNST_LIMB(0x2fbb374806ec05f1)}, - /* 150 */ {8, 0.1383351890281539, CNST_LIMB(0x38e858b62216100), CNST_LIMB(0x1fe7c0f0afce87fe)}, - /* 151 */ {8, 0.1381519873525671, CNST_LIMB(0x3c03b2c13176a41), CNST_LIMB(0x11003d517540d32e)}, - /* 152 */ {8, 0.1379704747522905, CNST_LIMB(0x3f44c9b21000000), CNST_LIMB(0x2f5810f98eff0dc)}, - /* 153 */ {8, 0.1377906240751463, CNST_LIMB(0x42ad23cef3113c1), CNST_LIMB(0xeb72e35e7840d910)}, - /* 154 */ {8, 0.1376124087861776, CNST_LIMB(0x463e546b19a2100), CNST_LIMB(0xd27de19593dc3614)}, - /* 155 */ {8, 0.1374358029495937, CNST_LIMB(0x49f9fc3f96684e1), CNST_LIMB(0xbaf391fd3e5e6fc2)}, - /* 156 */ {8, 0.1372607812113589, CNST_LIMB(0x4de1c9c5dc10000), CNST_LIMB(0xa4bd38c55228c81d)}, - /* 157 */ {8, 0.1370873187823978, CNST_LIMB(0x51f77994116d2a1), CNST_LIMB(0x8fc5a8de8e1de782)}, - /* 158 */ {8, 0.1369153914223921, CNST_LIMB(0x563cd6bb3398100), CNST_LIMB(0x7bf9265bea9d3a3b)}, - /* 159 */ {8, 0.1367449754241439, CNST_LIMB(0x5ab3bb270beeb01), CNST_LIMB(0x69454b325983dccd)}, - /* 160 */ {8, 0.1365760475984821, CNST_LIMB(0x5f5e10000000000), CNST_LIMB(0x5798ee2308c39df9)}, - /* 161 */ {8, 0.1364085852596902, CNST_LIMB(0x643dce0ec16f501), CNST_LIMB(0x46e40ba0fa66a753)}, - /* 162 */ {8, 0.1362425662114337, CNST_LIMB(0x6954fe21e3e8100), CNST_LIMB(0x3717b0870b0db3a7)}, - /* 163 */ {8, 0.1360779687331669, CNST_LIMB(0x6ea5b9755f440a1), CNST_LIMB(0x2825e6775d11cdeb)}, - /* 164 */ {8, 0.1359147715670014, CNST_LIMB(0x74322a1c0410000), CNST_LIMB(0x1a01a1c09d1b4dac)}, - /* 165 */ {8, 0.1357529539050150, CNST_LIMB(0x79fc8b6ae8a46e1), CNST_LIMB(0xc9eb0a8bebc8f3e)}, - /* 166 */ {8, 0.1355924953769863, CNST_LIMB(0x80072a66d512100), CNST_LIMB(0xffe357ff59e6a004)}, - /* 167 */ {8, 0.1354333760385373, CNST_LIMB(0x86546633b42b9c1), CNST_LIMB(0xe7dfd1be05fa61a8)}, - /* 168 */ {8, 0.1352755763596663, CNST_LIMB(0x8ce6b0861000000), CNST_LIMB(0xd11ed6fc78f760e5)}, - /* 169 */ {8, 0.1351190772136599, CNST_LIMB(0x93c08e16a022441), CNST_LIMB(0xbb8db609dd29ebfe)}, - /* 170 */ {8, 0.1349638598663645, CNST_LIMB(0x9ae49717f026100), CNST_LIMB(0xa71aec8d1813d532)}, - /* 171 */ {8, 0.1348099059658079, CNST_LIMB(0xa25577ae24c1a61), CNST_LIMB(0x93b612a9f20fbc02)}, - /* 172 */ {8, 0.1346571975321549, CNST_LIMB(0xaa15f068e610000), CNST_LIMB(0x814fc7b19a67d317)}, - /* 173 */ {8, 0.1345057169479844, CNST_LIMB(0xb228d6bf7577921), CNST_LIMB(0x6fd9a03f2e0a4b7c)}, - /* 174 */ {8, 0.1343554469488779, CNST_LIMB(0xba91158ef5c4100), CNST_LIMB(0x5f4615a38d0d316e)}, - /* 175 */ {8, 0.1342063706143054, CNST_LIMB(0xc351ad9aec0b681), CNST_LIMB(0x4f8876863479a286)}, - /* 176 */ {8, 0.1340584713587980, CNST_LIMB(0xcc6db6100000000), CNST_LIMB(0x4094d8a3041b60eb)}, - /* 177 */ {8, 0.1339117329233981, CNST_LIMB(0xd5e85d09025c181), CNST_LIMB(0x32600b8ed883a09b)}, - /* 178 */ {8, 0.1337661393673756, CNST_LIMB(0xdfc4e816401c100), CNST_LIMB(0x24df8c6eb4b6d1f1)}, - /* 179 */ {8, 0.1336216750601996, CNST_LIMB(0xea06b4c72947221), CNST_LIMB(0x18097a8ee151acef)}, - /* 180 */ {8, 0.1334783246737591, CNST_LIMB(0xf4b139365210000), CNST_LIMB(0xbd48cc8ec1cd8e3)}, - /* 181 */ {8, 0.1333360731748201, CNST_LIMB(0xffc80497d520961), CNST_LIMB(0x3807a8d67485fb)}, - /* 182 */ {8, 0.1331949058177136, CNST_LIMB(0x10b4ebfca1dee100), CNST_LIMB(0xea5768860b62e8d8)}, - /* 183 */ {8, 0.1330548081372441, CNST_LIMB(0x117492de921fc141), CNST_LIMB(0xd54faf5b635c5005)}, - /* 184 */ {8, 0.1329157659418126, CNST_LIMB(0x123bb2ce41000000), CNST_LIMB(0xc14a56233a377926)}, - /* 185 */ {8, 0.1327777653067443, CNST_LIMB(0x130a8b6157bdecc1), CNST_LIMB(0xae39a88db7cd329f)}, - /* 186 */ {8, 0.1326407925678156, CNST_LIMB(0x13e15dede0e8a100), CNST_LIMB(0x9c10bde69efa7ab6)}, - /* 187 */ {8, 0.1325048343149731, CNST_LIMB(0x14c06d941c0ca7e1), CNST_LIMB(0x8ac36c42a2836497)}, - /* 188 */ {8, 0.1323698773862368, CNST_LIMB(0x15a7ff487a810000), CNST_LIMB(0x7a463c8b84f5ef67)}, - /* 189 */ {8, 0.1322359088617821, CNST_LIMB(0x169859ddc5c697a1), CNST_LIMB(0x6a8e5f5ad090fd4b)}, - /* 190 */ {8, 0.1321029160581950, CNST_LIMB(0x1791c60f6fed0100), CNST_LIMB(0x5b91a2943596fc56)}, - /* 191 */ {8, 0.1319708865228925, CNST_LIMB(0x18948e8c0e6fba01), CNST_LIMB(0x4d4667b1c468e8f0)}, - /* 192 */ {8, 0.1318398080287045, CNST_LIMB(0x19a1000000000000), CNST_LIMB(0x3fa39ab547994daf)}, - /* 193 */ {8, 0.1317096685686114, CNST_LIMB(0x1ab769203dafc601), CNST_LIMB(0x32a0a9b2faee1e2a)}, - /* 194 */ {8, 0.1315804563506306, CNST_LIMB(0x1bd81ab557f30100), CNST_LIMB(0x26357ceac0e96962)}, - /* 195 */ {8, 0.1314521597928493, CNST_LIMB(0x1d0367a69fed1ba1), CNST_LIMB(0x1a5a6f65caa5859e)}, - /* 196 */ {8, 0.1313247675185968, CNST_LIMB(0x1e39a5057d810000), CNST_LIMB(0xf08480f672b4e86)}, - /* 197 */ {8, 0.1311982683517524, CNST_LIMB(0x1f7b2a18f29ac3e1), CNST_LIMB(0x4383340615612ca)}, - /* 198 */ {8, 0.1310726513121843, CNST_LIMB(0x20c850694c2aa100), CNST_LIMB(0xf3c77969ee4be5a2)}, - /* 199 */ {8, 0.1309479056113158, CNST_LIMB(0x222173cc014980c1), CNST_LIMB(0xe00993cc187c5ec9)}, - /* 200 */ {8, 0.1308240206478128, CNST_LIMB(0x2386f26fc1000000), CNST_LIMB(0xcd2b297d889bc2b6)}, - /* 201 */ {8, 0.1307009860033912, CNST_LIMB(0x24f92ce8af296d41), CNST_LIMB(0xbb214d5064862b22)}, - /* 202 */ {8, 0.1305787914387386, CNST_LIMB(0x2678863cd0ece100), CNST_LIMB(0xa9e1a7ca7ea10e20)}, - /* 203 */ {8, 0.1304574268895465, CNST_LIMB(0x280563f0a9472d61), CNST_LIMB(0x99626e72b39ea0cf)}, - /* 204 */ {8, 0.1303368824626505, CNST_LIMB(0x29a02e1406210000), CNST_LIMB(0x899a5ba9c13fafd9)}, - /* 205 */ {8, 0.1302171484322746, CNST_LIMB(0x2b494f4efe6d2e21), CNST_LIMB(0x7a80a705391e96ff)}, - /* 206 */ {8, 0.1300982152363760, CNST_LIMB(0x2d0134ef21cbc100), CNST_LIMB(0x6c0cfe23de23042a)}, - /* 207 */ {8, 0.1299800734730872, CNST_LIMB(0x2ec84ef4da2ef581), CNST_LIMB(0x5e377df359c944dd)}, - /* 208 */ {8, 0.1298627138972530, CNST_LIMB(0x309f102100000000), CNST_LIMB(0x50f8ac5fc8f53985)}, - /* 209 */ {8, 0.1297461274170591, CNST_LIMB(0x3285ee02a1420281), CNST_LIMB(0x44497266278e35b7)}, - /* 210 */ {8, 0.1296303050907487, CNST_LIMB(0x347d6104fc324100), CNST_LIMB(0x382316831f7ee175)}, - /* 211 */ {8, 0.1295152381234257, CNST_LIMB(0x3685e47dade53d21), CNST_LIMB(0x2c7f377833b8946e)}, - /* 212 */ {8, 0.1294009178639407, CNST_LIMB(0x389ff6bb15610000), CNST_LIMB(0x2157c761ab4163ef)}, - /* 213 */ {8, 0.1292873358018581, CNST_LIMB(0x3acc1912ebb57661), CNST_LIMB(0x16a7071803cc49a9)}, - /* 214 */ {8, 0.1291744835645007, CNST_LIMB(0x3d0acff111946100), CNST_LIMB(0xc6781d80f8224fc)}, - /* 215 */ {8, 0.1290623529140715, CNST_LIMB(0x3f5ca2e692eaf841), CNST_LIMB(0x294092d370a900b)}, - /* 216 */ {8, 0.1289509357448472, CNST_LIMB(0x41c21cb8e1000000), CNST_LIMB(0xf24f62335024a295)}, - /* 217 */ {8, 0.1288402240804449, CNST_LIMB(0x443bcb714399a5c1), CNST_LIMB(0xe03b98f103fad6d2)}, - /* 218 */ {8, 0.1287302100711567, CNST_LIMB(0x46ca406c81af2100), CNST_LIMB(0xcee3d32cad2a9049)}, - /* 219 */ {8, 0.1286208859913518, CNST_LIMB(0x496e106ac22aaae1), CNST_LIMB(0xbe3f9df9277fdada)}, - /* 220 */ {8, 0.1285122442369443, CNST_LIMB(0x4c27d39fa5410000), CNST_LIMB(0xae46f0d94c05e933)}, - /* 221 */ {8, 0.1284042773229231, CNST_LIMB(0x4ef825c296e43ca1), CNST_LIMB(0x9ef2280fb437a33d)}, - /* 222 */ {8, 0.1282969778809442, CNST_LIMB(0x51dfa61f5ad88100), CNST_LIMB(0x9039ff426d3f284b)}, - /* 223 */ {8, 0.1281903386569819, CNST_LIMB(0x54def7a6d2f16901), CNST_LIMB(0x82178c6d6b51f8f4)}, - /* 224 */ {8, 0.1280843525090381, CNST_LIMB(0x57f6c10000000000), CNST_LIMB(0x74843b1ee4c1e053)}, - /* 225 */ {8, 0.1279790124049077, CNST_LIMB(0x5b27ac993df97701), CNST_LIMB(0x6779c7f90dc42f48)}, - /* 226 */ {8, 0.1278743114199984, CNST_LIMB(0x5e7268b9bbdf8100), CNST_LIMB(0x5af23c74f9ad9fe9)}, - /* 227 */ {8, 0.1277702427352035, CNST_LIMB(0x61d7a7932ff3d6a1), CNST_LIMB(0x4ee7eae2acdc617e)}, - /* 228 */ {8, 0.1276667996348261, CNST_LIMB(0x65581f53c8c10000), CNST_LIMB(0x43556aa2ac262a0b)}, - /* 229 */ {8, 0.1275639755045533, CNST_LIMB(0x68f48a385b8320e1), CNST_LIMB(0x3835949593b8ddd1)}, - /* 230 */ {8, 0.1274617638294791, CNST_LIMB(0x6cada69ed07c2100), CNST_LIMB(0x2d837fbe78458762)}, - /* 231 */ {8, 0.1273601581921741, CNST_LIMB(0x70843718cdbf27c1), CNST_LIMB(0x233a7e150a54a555)}, - /* 232 */ {8, 0.1272591522708010, CNST_LIMB(0x7479027ea1000000), CNST_LIMB(0x19561984a50ff8fe)}, - /* 233 */ {8, 0.1271587398372755, CNST_LIMB(0x788cd40268f39641), CNST_LIMB(0xfd211159fe3490f)}, - /* 234 */ {8, 0.1270589147554692, CNST_LIMB(0x7cc07b437ecf6100), CNST_LIMB(0x6aa563e655033e3)}, - /* 235 */ {8, 0.1269596709794558, CNST_LIMB(0x8114cc6220762061), CNST_LIMB(0xfbb614b3f2d3b14c)}, - /* 236 */ {8, 0.1268610025517973, CNST_LIMB(0x858aa0135be10000), CNST_LIMB(0xeac0f8837fb05773)}, - /* 237 */ {8, 0.1267629036018709, CNST_LIMB(0x8a22d3b53c54c321), CNST_LIMB(0xda6e4c10e8615ca5)}, - /* 238 */ {8, 0.1266653683442337, CNST_LIMB(0x8ede496339f34100), CNST_LIMB(0xcab755a8d01fa67f)}, - /* 239 */ {8, 0.1265683910770258, CNST_LIMB(0x93bde80aec3a1481), CNST_LIMB(0xbb95a9ae71aa3e0c)}, - /* 240 */ {8, 0.1264719661804097, CNST_LIMB(0x98c29b8100000000), CNST_LIMB(0xad0326c296b4f529)}, - /* 241 */ {8, 0.1263760881150453, CNST_LIMB(0x9ded549671832381), CNST_LIMB(0x9ef9f21eed31b7c1)}, - /* 242 */ {8, 0.1262807514205999, CNST_LIMB(0xa33f092e0b1ac100), CNST_LIMB(0x91747422be14b0b2)}, - /* 243 */ {8, 0.1261859507142915, CNST_LIMB(0xa8b8b452291fe821), CNST_LIMB(0x846d550e37b5063d)}, - /* 244 */ {8, 0.1260916806894653, CNST_LIMB(0xae5b564ac3a10000), CNST_LIMB(0x77df79e9a96c06f6)}, - /* 245 */ {8, 0.1259979361142023, CNST_LIMB(0xb427f4b3be74c361), CNST_LIMB(0x6bc6019636c7d0c2)}, - /* 246 */ {8, 0.1259047118299582, CNST_LIMB(0xba1f9a938041e100), CNST_LIMB(0x601c4205aebd9e47)}, - /* 247 */ {8, 0.1258120027502338, CNST_LIMB(0xc0435871d1110f41), CNST_LIMB(0x54ddc59756f05016)}, - /* 248 */ {8, 0.1257198038592741, CNST_LIMB(0xc694446f01000000), CNST_LIMB(0x4a0648979c838c18)}, - /* 249 */ {8, 0.1256281102107963, CNST_LIMB(0xcd137a5b57ac3ec1), CNST_LIMB(0x3f91b6e0bb3a053d)}, - /* 250 */ {8, 0.1255369169267456, CNST_LIMB(0xd3c21bcecceda100), CNST_LIMB(0x357c299a88ea76a5)}, - /* 251 */ {8, 0.1254462191960791, CNST_LIMB(0xdaa150410b788de1), CNST_LIMB(0x2bc1e517aecc56e3)}, - /* 252 */ {8, 0.1253560122735751, CNST_LIMB(0xe1b24521be010000), CNST_LIMB(0x225f56ceb3da9f5d)}, - /* 253 */ {8, 0.1252662914786691, CNST_LIMB(0xe8f62df12777c1a1), CNST_LIMB(0x1951136d53ad63ac)}, - /* 254 */ {8, 0.1251770521943144, CNST_LIMB(0xf06e445906fc0100), CNST_LIMB(0x1093d504b3cd7d93)}, - /* 255 */ {8, 0.1250882898658681, CNST_LIMB(0xf81bc845c81bf801), CNST_LIMB(0x824794d1ec1814f)}, -}; -#endif diff --git a/gmp/mpn/ns32k/add_n.s b/gmp/mpn/ns32k/add_n.s deleted file mode 100755 index d3ece1b..0000000 Binary files a/gmp/mpn/ns32k/add_n.s and /dev/null differ diff --git a/gmp/mpn/ns32k/addmul_1.s b/gmp/mpn/ns32k/addmul_1.s deleted file mode 100755 index e24a84d..0000000 Binary files a/gmp/mpn/ns32k/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/ns32k/mul_1.s b/gmp/mpn/ns32k/mul_1.s deleted file mode 100755 index db84d91..0000000 Binary files a/gmp/mpn/ns32k/mul_1.s and /dev/null differ diff --git a/gmp/mpn/ns32k/sub_n.s b/gmp/mpn/ns32k/sub_n.s deleted file mode 100755 index d839322..0000000 Binary files a/gmp/mpn/ns32k/sub_n.s and /dev/null differ diff --git a/gmp/mpn/ns32k/submul_1.s b/gmp/mpn/ns32k/submul_1.s deleted file mode 100755 index cd0eb06..0000000 Binary files a/gmp/mpn/ns32k/submul_1.s and /dev/null differ diff --git a/gmp/mpn/pa64/README b/gmp/mpn/pa64/README deleted file mode 100755 index 50d0b8a..0000000 Binary files a/gmp/mpn/pa64/README and /dev/null differ diff --git a/gmp/mpn/pa64/add_n.s b/gmp/mpn/pa64/add_n.s deleted file mode 100755 index d51c3ef..0000000 Binary files a/gmp/mpn/pa64/add_n.s and /dev/null differ diff --git a/gmp/mpn/pa64/addmul_1.S b/gmp/mpn/pa64/addmul_1.S deleted file mode 100755 index e05f477..0000000 Binary files a/gmp/mpn/pa64/addmul_1.S and /dev/null differ diff --git a/gmp/mpn/pa64/gmp-mparam.h b/gmp/mpn/pa64/gmp-mparam.h deleted file mode 100755 index 847735b..0000000 --- a/gmp/mpn/pa64/gmp-mparam.h +++ /dev/null @@ -1,65 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values were measured in a PA8000 using the system compiler version - A.10.32.30. Presumably the PA8200 and PA8500 have the same timing - characteristic, but GCC might give somewhat different results. */ -/* Generated by tuneup.c, 2000-07-25. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 16 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 105 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 40 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 116 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 72 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 94 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 50 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 46 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 1 -#endif diff --git a/gmp/mpn/pa64/lshift.s b/gmp/mpn/pa64/lshift.s deleted file mode 100755 index 1942e25..0000000 Binary files a/gmp/mpn/pa64/lshift.s and /dev/null differ diff --git a/gmp/mpn/pa64/mul_1.S b/gmp/mpn/pa64/mul_1.S deleted file mode 100755 index 74456f7..0000000 Binary files a/gmp/mpn/pa64/mul_1.S and /dev/null differ diff --git a/gmp/mpn/pa64/rshift.s b/gmp/mpn/pa64/rshift.s deleted file mode 100755 index 8ffdcba..0000000 Binary files a/gmp/mpn/pa64/rshift.s and /dev/null differ diff --git a/gmp/mpn/pa64/sub_n.s b/gmp/mpn/pa64/sub_n.s deleted file mode 100755 index f525828..0000000 Binary files a/gmp/mpn/pa64/sub_n.s and /dev/null differ diff --git a/gmp/mpn/pa64/submul_1.S b/gmp/mpn/pa64/submul_1.S deleted file mode 100755 index 0b7d517..0000000 Binary files a/gmp/mpn/pa64/submul_1.S and /dev/null differ diff --git a/gmp/mpn/pa64/udiv_qrnnd.c b/gmp/mpn/pa64/udiv_qrnnd.c deleted file mode 100755 index 1c9fe08..0000000 --- a/gmp/mpn/pa64/udiv_qrnnd.c +++ /dev/null @@ -1,111 +0,0 @@ -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#define TWO64 18446744073709551616.0 - -mp_limb_t -#if __STDC__ -__MPN(udiv_qrnnd) (mp_limb_t n1, mp_limb_t n0, mp_limb_t d, mp_limb_t *r) -#else -__MPN(udiv_qrnnd) (n1, n0, d, r) - mp_limb_t n1; - mp_limb_t n0; - mp_limb_t d; - mp_limb_t *r; -#endif -{ - mp_limb_t q1, q2, q; - mp_limb_t p1, p0; - double di, dq; - - di = 1.0 / d; - - /* Generate upper 53 bits of quotient. Be careful here; the `double' - quotient may be rounded to 2^64 which we cannot safely convert back - to a 64-bit integer. */ - dq = (TWO64 * (double) n1 + (double) n0) * di; - if (dq >= TWO64) - q1 = 0xfffffffffffff800LL; - else - q1 = (mp_limb_t) dq; - - /* Multiply back in order to compare the product to the dividend. */ - umul_ppmm (p1, p0, q1, d); - - /* Was the 53-bit quotient greater that our sought quotient? Test the - sign of the partial remainder to find out. */ - if (n1 < p1 || (n1 == p1 && n0 < p0)) - { - /* 53-bit quotient too large. Partial remainder is negative. - Compute the absolute value of the remainder in n1,,n0. */ - n1 = p1 - (n1 + (p0 < n0)); - n0 = p0 - n0; - - /* Now use the partial remainder as new dividend to compute more bits of - quotient. This is an adjustment for the one we got previously. */ - q2 = (mp_limb_t) ((TWO64 * (double) n1 + (double) n0) * di); - umul_ppmm (p1, p0, q2, d); - - q = q1 - q2; - if (n1 < p1 || (n1 == p1 && n0 <= p0)) - { - n0 = p0 - n0; - } - else - { - n0 = p0 - n0; - n0 += d; - q--; - } - } - else - { - n1 = n1 - (p1 + (n0 < p0)); - n0 = n0 - p0; - - q2 = (mp_limb_t) ((TWO64 * (double) n1 + (double) n0) * di); - umul_ppmm (p1, p0, q2, d); - - q = q1 + q2; - if (n1 < p1 || (n1 == p1 && n0 < p0)) - { - n0 = n0 - p0; - n0 += d; - q--; - } - else - { - n0 = n0 - p0; - if (n0 >= d) - { - n0 -= d; - q++; - } - } - } - - *r = n0; - return q; -} diff --git a/gmp/mpn/pa64/umul_ppmm.S b/gmp/mpn/pa64/umul_ppmm.S deleted file mode 100755 index f63b78c..0000000 Binary files a/gmp/mpn/pa64/umul_ppmm.S and /dev/null differ diff --git a/gmp/mpn/pa64w/README b/gmp/mpn/pa64w/README deleted file mode 100755 index 2b7108b..0000000 Binary files a/gmp/mpn/pa64w/README and /dev/null differ diff --git a/gmp/mpn/pa64w/add_n.s b/gmp/mpn/pa64w/add_n.s deleted file mode 100755 index 1aa861e..0000000 Binary files a/gmp/mpn/pa64w/add_n.s and /dev/null differ diff --git a/gmp/mpn/pa64w/addmul_1.S b/gmp/mpn/pa64w/addmul_1.S deleted file mode 100755 index 572b1e5..0000000 Binary files a/gmp/mpn/pa64w/addmul_1.S and /dev/null differ diff --git a/gmp/mpn/pa64w/gmp-mparam.h b/gmp/mpn/pa64w/gmp-mparam.h deleted file mode 100755 index ee5a0a3..0000000 --- a/gmp/mpn/pa64w/gmp-mparam.h +++ /dev/null @@ -1,65 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values were measured on a PA8500 using the system compiler version - A.11.01.02. Presumably the PA8000 and PA8200 have the same timing - characteristic, but GCC might give somewhat different results.. */ -/* Generated by tuneup.c, 2000-07-25. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 18 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 105 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 46 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 83 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 58 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 134 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 56 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 26 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 1 -#endif diff --git a/gmp/mpn/pa64w/lshift.s b/gmp/mpn/pa64w/lshift.s deleted file mode 100755 index aea67fe..0000000 Binary files a/gmp/mpn/pa64w/lshift.s and /dev/null differ diff --git a/gmp/mpn/pa64w/mul_1.S b/gmp/mpn/pa64w/mul_1.S deleted file mode 100755 index e77b605..0000000 Binary files a/gmp/mpn/pa64w/mul_1.S and /dev/null differ diff --git a/gmp/mpn/pa64w/rshift.s b/gmp/mpn/pa64w/rshift.s deleted file mode 100755 index 2d038c5..0000000 Binary files a/gmp/mpn/pa64w/rshift.s and /dev/null differ diff --git a/gmp/mpn/pa64w/sub_n.s b/gmp/mpn/pa64w/sub_n.s deleted file mode 100755 index c9f8c45..0000000 Binary files a/gmp/mpn/pa64w/sub_n.s and /dev/null differ diff --git a/gmp/mpn/pa64w/submul_1.S b/gmp/mpn/pa64w/submul_1.S deleted file mode 100755 index ebfc8b0..0000000 Binary files a/gmp/mpn/pa64w/submul_1.S and /dev/null differ diff --git a/gmp/mpn/pa64w/udiv_qrnnd.c b/gmp/mpn/pa64w/udiv_qrnnd.c deleted file mode 100755 index 1852913..0000000 --- a/gmp/mpn/pa64w/udiv_qrnnd.c +++ /dev/null @@ -1,117 +0,0 @@ -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#define TWO64 18446744073709551616.0 -#define TWO63 9223372036854775808.0 - -mp_limb_t -#if __STDC__ -__MPN(udiv_qrnnd) (mp_limb_t n1, mp_limb_t n0, mp_limb_t d, mp_limb_t *r) -#else -__MPN(udiv_qrnnd) (n1, n0, d, r) - mp_limb_t n1; - mp_limb_t n0; - mp_limb_t d; - mp_limb_t *r; -#endif -{ - mp_limb_t q1, q2, q; - mp_limb_t p1, p0; - double di, dq; - - di = 1.0 / d; - - /* Generate upper 53 bits of quotient. Be careful here; the `double' - quotient may be rounded to 2^64 which we cannot safely convert back - to a 64-bit integer. */ - dq = (TWO64 * (double) n1 + (double) n0) * di; - if (dq >= TWO64) - q1 = 0xfffffffffffff800L; -#ifndef __GNUC__ - /* Work around HP compiler bug. */ - else if (dq > TWO63) - q1 = (mp_limb_t) (dq - TWO63) + 0x8000000000000000L; -#endif - else - q1 = (mp_limb_t) dq; - - /* Multiply back in order to compare the product to the dividend. */ - umul_ppmm (p1, p0, q1, d); - - /* Was the 53-bit quotient greater that our sought quotient? Test the - sign of the partial remainder to find out. */ - if (n1 < p1 || (n1 == p1 && n0 < p0)) - { - /* 53-bit quotient too large. Partial remainder is negative. - Compute the absolute value of the remainder in n1,,n0. */ - n1 = p1 - (n1 + (p0 < n0)); - n0 = p0 - n0; - - /* Now use the partial remainder as new dividend to compute more bits of - quotient. This is an adjustment for the one we got previously. */ - q2 = (mp_limb_t) ((TWO64 * (double) n1 + (double) n0) * di); - umul_ppmm (p1, p0, q2, d); - - q = q1 - q2; - if (n1 < p1 || (n1 == p1 && n0 <= p0)) - { - n0 = p0 - n0; - } - else - { - n0 = p0 - n0; - n0 += d; - q--; - } - } - else - { - n1 = n1 - (p1 + (n0 < p0)); - n0 = n0 - p0; - - q2 = (mp_limb_t) ((TWO64 * (double) n1 + (double) n0) * di); - umul_ppmm (p1, p0, q2, d); - - q = q1 + q2; - if (n1 < p1 || (n1 == p1 && n0 < p0)) - { - n0 = n0 - p0; - n0 += d; - q--; - } - else - { - n0 = n0 - p0; - if (n0 >= d) - { - n0 -= d; - q++; - } - } - } - - *r = n0; - return q; -} diff --git a/gmp/mpn/pa64w/umul_ppmm.S b/gmp/mpn/pa64w/umul_ppmm.S deleted file mode 100755 index 03a663f..0000000 Binary files a/gmp/mpn/pa64w/umul_ppmm.S and /dev/null differ diff --git a/gmp/mpn/power/add_n.s b/gmp/mpn/power/add_n.s deleted file mode 100755 index f0d4e65..0000000 Binary files a/gmp/mpn/power/add_n.s and /dev/null differ diff --git a/gmp/mpn/power/addmul_1.s b/gmp/mpn/power/addmul_1.s deleted file mode 100755 index 83d972f..0000000 Binary files a/gmp/mpn/power/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/power/lshift.s b/gmp/mpn/power/lshift.s deleted file mode 100755 index d165429..0000000 Binary files a/gmp/mpn/power/lshift.s and /dev/null differ diff --git a/gmp/mpn/power/mul_1.s b/gmp/mpn/power/mul_1.s deleted file mode 100755 index 65a16f6..0000000 Binary files a/gmp/mpn/power/mul_1.s and /dev/null differ diff --git a/gmp/mpn/power/rshift.s b/gmp/mpn/power/rshift.s deleted file mode 100755 index a74bede..0000000 Binary files a/gmp/mpn/power/rshift.s and /dev/null differ diff --git a/gmp/mpn/power/sdiv.s b/gmp/mpn/power/sdiv.s deleted file mode 100755 index 3bcb827..0000000 Binary files a/gmp/mpn/power/sdiv.s and /dev/null differ diff --git a/gmp/mpn/power/sub_n.s b/gmp/mpn/power/sub_n.s deleted file mode 100755 index df90997..0000000 Binary files a/gmp/mpn/power/sub_n.s and /dev/null differ diff --git a/gmp/mpn/power/submul_1.s b/gmp/mpn/power/submul_1.s deleted file mode 100755 index 11e1f9e..0000000 Binary files a/gmp/mpn/power/submul_1.s and /dev/null differ diff --git a/gmp/mpn/power/umul.s b/gmp/mpn/power/umul.s deleted file mode 100755 index 5695ecf..0000000 Binary files a/gmp/mpn/power/umul.s and /dev/null differ diff --git a/gmp/mpn/powerpc32/add_n.asm b/gmp/mpn/powerpc32/add_n.asm deleted file mode 100755 index f7f5e0d..0000000 Binary files a/gmp/mpn/powerpc32/add_n.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/addmul_1.asm b/gmp/mpn/powerpc32/addmul_1.asm deleted file mode 100755 index 4f1945d..0000000 Binary files a/gmp/mpn/powerpc32/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/aix.m4 b/gmp/mpn/powerpc32/aix.m4 deleted file mode 100755 index 775f083..0000000 Binary files a/gmp/mpn/powerpc32/aix.m4 and /dev/null differ diff --git a/gmp/mpn/powerpc32/gmp-mparam.h b/gmp/mpn/powerpc32/gmp-mparam.h deleted file mode 100755 index b283185..0000000 --- a/gmp/mpn/powerpc32/gmp-mparam.h +++ /dev/null @@ -1,66 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* These values are for the 604. Presumably, these should be considerably - different for the 603 and 750 that have much slower multiply - instructions. */ - -/* Generated by tuneup.c, 2000-05-26. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 26 /* tuneup says 20 */ -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 228 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 46 /* tuneup says 44 */ -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 262 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 52 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 86 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 23 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 7 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 53 -#endif diff --git a/gmp/mpn/powerpc32/lshift.asm b/gmp/mpn/powerpc32/lshift.asm deleted file mode 100755 index c77fe5c..0000000 Binary files a/gmp/mpn/powerpc32/lshift.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/mpnppc32.c b/gmp/mpn/powerpc32/mpnppc32.c deleted file mode 100755 index ee5fba5..0000000 --- a/gmp/mpn/powerpc32/mpnppc32.c +++ /dev/null @@ -1,454 +0,0 @@ - - -asm void __gmpn_add_n() -{ - mtctr r6 //# copy size into CTR - addic r0,r0,0 //# clear cy - lwz r8,0(r4) //# load least significant s1 limb - lwz r0,0(r5) //# load least significant s2 limb - addi r3,r3,-4 //# offset res_ptr, it's updated before it's used - bdz Lend //# If done, skip loop -Loop: lwz r9,4(r4) //# load s1 limb - lwz r10,4(r5) //# load s2 limb - adde r7,r0,r8 //# add limbs with cy, set cy - stw r7,4(r3) //# store result limb - bdz Lexit //# decrement CTR and exit if done - lwzu r8,8(r4) //# load s1 limb and update s1_ptr - lwzu r0,8(r5) //# load s2 limb and update s2_ptr - adde r7,r10,r9 //# add limbs with cy, set cy - stwu r7,8(r3) //# store result limb and update res_ptr - bdnz Loop //# decrement CTR and loop back - -Lend: adde r7,r0,r8 - stw r7,4(r3) //# store ultimate result limb - li r3,0 //# load cy into ... - addze r3,r3 //# ... return value register - blr -Lexit: adde r7,r10,r9 - stw r7,8(r3) - li r3,0 //# load cy into ... - addze r3,r3 //# ... return value register -} - -asm void __gmpn_addmul_1() -{ - cmpi cr0,r5,9 //# more than 9 limbs? - bgt cr0,Lbig //# branch if more than 9 limbs - - mtctr r5 - lwz r0,0(r4) - mullw r7,r0,r6 - mulhwu r10,r0,r6 - lwz r9,0(r3) - addc r8,r7,r9 - addi r3,r3,-4 - bdz Lend -Lloop: - lwzu r0,4(r4) - stwu r8,4(r3) - mullw r8,r0,r6 - adde r7,r8,r10 - mulhwu r10,r0,r6 - lwz r9,4(r3) - addze r10,r10 - addc r8,r7,r9 - bdnz Lloop -Lend: stw r8,4(r3) - addze r3,r10 - blr - -Lbig: stmw r30,-32(r1) - addi r5,r5,-1 - srwi r0,r5,2 - mtctr r0 - - lwz r7,0(r4) - mullw r8,r7,r6 - mulhwu r0,r7,r6 - lwz r7,0(r3) - addc r8,r8,r7 - stw r8,0(r3) - -LloopU: - lwz r7,4(r4) - lwz r12,8(r4) - lwz r30,12(r4) - lwzu r31,16(r4) - mullw r8,r7,r6 - mullw r9,r12,r6 - mullw r10,r30,r6 - mullw r11,r31,r6 - adde r8,r8,r0 //# add cy_limb - mulhwu r0,r7,r6 - lwz r7,4(r3) - adde r9,r9,r0 - mulhwu r0,r12,r6 - lwz r12,8(r3) - adde r10,r10,r0 - mulhwu r0,r30,r6 - lwz r30,12(r3) - adde r11,r11,r0 - mulhwu r0,r31,r6 - lwz r31,16(r3) - addze r0,r0 //# new cy_limb - addc r8,r8,r7 - stw r8,4(r3) - adde r9,r9,r12 - stw r9,8(r3) - adde r10,r10,r30 - stw r10,12(r3) - adde r11,r11,r31 - stwu r11,16(r3) - bdnz LloopU - - andi. r31,r5,3 - mtctr r31 - beq cr0,Lendx - -LloopE: - lwzu r7,4(r4) - mullw r8,r7,r6 - adde r8,r8,r0 //# add cy_limb - mulhwu r0,r7,r6 - lwz r7,4(r3) - addze r0,r0 //# new cy_limb - addc r8,r8,r7 - stwu r8,4(r3) - bdnz LloopE -Lendx: - addze r3,r0 - lmw r30,-32(r1) -} - -asm void __gmpn_lshift() -{ - cmpi cr0,r5,12 //# more than 12 limbs? - slwi r0,r5,2 - add r4,r4,r0 //# make r4 point at end of s1 - add r7,r3,r0 //# make r7 point at end of res - bgt LBIG //# branch if more than 12 limbs - - mtctr r5 //# copy size into CTR - subfic r8,r6,32 - lwzu r11,-4(r4) //# load first s1 limb - srw r3,r11,r8 //# compute function return value - bdz Lend1 - -Loop: lwzu r10,-4(r4) - slw r9,r11,r6 - srw r12,r10,r8 - or r9,r9,r12 - stwu r9,-4(r7) - bdz Lend2 - lwzu r11,-4(r4) - slw r9,r10,r6 - srw r12,r11,r8 - or r9,r9,r12 - stwu r9,-4(r7) - bdnz Loop - -Lend1: slw r0,r11,r6 - stw r0,-4(r7) - blr -Lend2: slw r0,r10,r6 - stw r0,-4(r7) - blr - -LBIG: - stmw r24,-32(r1) //# save registers we are supposed to preserve - lwzu r9,-4(r4) - subfic r8,r6,32 - srw r3,r9,r8 //# compute function return value - slw r0,r9,r6 - addi r5,r5,-1 - - andi. r10,r5,3 //# count for spill loop - beq Le - mtctr r10 - lwzu r28,-4(r4) - bdz Lxe0 - -Loop0: slw r12,r28,r6 - srw r24,r28,r8 - lwzu r28,-4(r4) - or r24,r0,r24 - stwu r24,-4(r7) - mr r0,r12 - bdnz Loop0 //# taken at most once! - -Lxe0: slw r12,r28,r6 - srw r24,r28,r8 - or r24,r0,r24 - stwu r24,-4(r7) - mr r0,r12 - -Le: srwi r5,r5,2 //# count for unrolled loop - addi r5,r5,-1 - mtctr r5 - lwz r28,-4(r4) - lwz r29,-8(r4) - lwz r30,-12(r4) - lwzu r31,-16(r4) - -LoopU: slw r9,r28,r6 - srw r24,r28,r8 - lwz r28,-4(r4) - slw r10,r29,r6 - srw r25,r29,r8 - lwz r29,-8(r4) - slw r11,r30,r6 - srw r26,r30,r8 - lwz r30,-12(r4) - slw r12,r31,r6 - srw r27,r31,r8 - lwzu r31,-16(r4) - or r24,r0,r24 - stw r24,-4(r7) - or r25,r9,r25 - stw r25,-8(r7) - or r26,r10,r26 - stw r26,-12(r7) - or r27,r11,r27 - stwu r27,-16(r7) - mr r0,r12 - bdnz LoopU - - slw r9,r28,r6 - srw r24,r28,r8 - slw r10,r29,r6 - srw r25,r29,r8 - slw r11,r30,r6 - srw r26,r30,r8 - slw r12,r31,r6 - srw r27,r31,r8 - or r24,r0,r24 - stw r24,-4(r7) - or r25,r9,r25 - stw r25,-8(r7) - or r26,r10,r26 - stw r26,-12(r7) - or r27,r11,r27 - stwu r27,-16(r7) - mr r0,r12 - - stw r0,-4(r7) - lmw r24,-32(r1) //# restore registers -} - -asm void __gmpn_mul_1() -{ - mtctr r5 - addi r3,r3,-4 //# adjust res_ptr, it's offset before it's used - li r12,0 //# clear upper product reg - addic r0,r0,0 //# clear cy -//# Start software pipeline - lwz r8,0(r4) - bdz Lend3 - stmw r30,-8(r1) //# save registers we are supposed to preserve - lwzu r9,4(r4) - mullw r11,r8,r6 - mulhwu r0,r8,r6 - bdz Lend1 -//# Software pipelined main loop -Loop: lwz r8,4(r4) - mullw r10,r9,r6 - adde r30,r11,r12 - mulhwu r12,r9,r6 - stw r30,4(r3) - bdz Lend2 - lwzu r9,8(r4) - mullw r11,r8,r6 - adde r31,r10,r0 - mulhwu r0,r8,r6 - stwu r31,8(r3) - bdnz Loop -//# Finish software pipeline -Lend1: mullw r10,r9,r6 - adde r30,r11,r12 - mulhwu r12,r9,r6 - stw r30,4(r3) - adde r31,r10,r0 - stwu r31,8(r3) - addze r3,r12 - lmw r30,-8(r1) //# restore registers from stack - blr -Lend2: mullw r11,r8,r6 - adde r31,r10,r0 - mulhwu r0,r8,r6 - stwu r31,8(r3) - adde r30,r11,r12 - stw r30,4(r3) - addze r3,r0 - lmw r30,-8(r1) //# restore registers from stack - blr -Lend3: mullw r11,r8,r6 - stw r11,4(r3) - mulhwu r3,r8,r6 -} - - -asm void __gmpn_rshift() -{ - mtctr r5 //# copy size into CTR - addi r7,r3,-4 //# move adjusted res_ptr to free return reg - subfic r8,r6,32 - lwz r11,0(r4) //# load first s1 limb - slw r3,r11,r8 //# compute function return value - bdz Lend1 - -Loop: lwzu r10,4(r4) - srw r9,r11,r6 - slw r12,r10,r8 - or r9,r9,r12 - stwu r9,4(r7) - bdz Lend2 - lwzu r11,4(r4) - srw r9,r10,r6 - slw r12,r11,r8 - or r9,r9,r12 - stwu r9,4(r7) - bdnz Loop - -Lend1: srw r0,r11,r6 - stw r0,4(r7) - blr - -Lend2: srw r0,r10,r6 - stw r0,4(r7) -} - -asm void __gmpn_sub_n() -{ - mtctr r6 //# copy size into CTR - addic r0,r6,-1 //# set cy - lwz r8,0(r4) //# load least significant s1 limb - lwz r0,0(r5) //# load least significant s2 limb - addi r3,r3,-4 //# offset res_ptr, it's updated before it's used - bdz Lend //# If done, skip loop -Loop: lwz r9,4(r4) //# load s1 limb - lwz r10,4(r5) //# load s2 limb - subfe r7,r0,r8 //# subtract limbs with cy, set cy - stw r7,4(r3) //# store result limb - bdz Lexit //# decrement CTR and exit if done - lwzu r8,8(r4) //# load s1 limb and update s1_ptr - lwzu r0,8(r5) //# load s2 limb and update s2_ptr - subfe r7,r10,r9 //# subtract limbs with cy, set cy - stwu r7,8(r3) //# store result limb and update res_ptr - bdnz Loop //# decrement CTR and loop back - -Lend: subfe r7,r0,r8 - stw r7,4(r3) //# store ultimate result limb - subfe r3,r0,r0 //# load !cy into ... - subfic r3,r3,0 //# ... return value register - blr -Lexit: subfe r7,r10,r9 - stw r7,8(r3) - subfe r3,r0,r0 //# load !cy into ... - subfic r3,r3,0 //# ... return value register -} - -asm void __gmpn_submul_1() -{ - cmpi cr0,r5,9 //# more than 9 limbs? - bgt cr0,Lbig //# branch if more than 9 limbs - - mtctr r5 - lwz r0,0(r4) - mullw r7,r0,r6 - mulhwu r10,r0,r6 - lwz r9,0(r3) - subfc r8,r7,r9 - addc r7,r7,r8 //# invert cy (r7 is junk) - addi r3,r3,-4 - bdz Lend -Lloop: - lwzu r0,4(r4) - stwu r8,4(r3) - mullw r8,r0,r6 - adde r7,r8,r10 - mulhwu r10,r0,r6 - lwz r9,4(r3) - addze r10,r10 - subfc r8,r7,r9 - addc r7,r7,r8 //# invert cy (r7 is junk) - bdnz Lloop -Lend: stw r8,4(r3) - addze r3,r10 - blr - -Lbig: stmw r30,-32(r1) - addi r5,r5,-1 - srwi r0,r5,2 - mtctr r0 - - lwz r7,0(r4) - mullw r8,r7,r6 - mulhwu r0,r7,r6 - lwz r7,0(r3) - subfc r7,r8,r7 - addc r8,r8,r7 - stw r7,0(r3) - -LloopU: - lwz r7,4(r4) - lwz r12,8(r4) - lwz r30,12(r4) - lwzu r31,16(r4) - mullw r8,r7,r6 - mullw r9,r12,r6 - mullw r10,r30,r6 - mullw r11,r31,r6 - adde r8,r8,r0 //# add cy_limb - mulhwu r0,r7,r6 - lwz r7,4(r3) - adde r9,r9,r0 - mulhwu r0,r12,r6 - lwz r12,8(r3) - adde r10,r10,r0 - mulhwu r0,r30,r6 - lwz r30,12(r3) - adde r11,r11,r0 - mulhwu r0,r31,r6 - lwz r31,16(r3) - addze r0,r0 //# new cy_limb - subfc r7,r8,r7 - stw r7,4(r3) - subfe r12,r9,r12 - stw r12,8(r3) - subfe r30,r10,r30 - stw r30,12(r3) - subfe r31,r11,r31 - stwu r31,16(r3) - subfe r11,r11,r11 //# invert ... - addic r11,r11,1 //# ... carry - bdnz LloopU - - andi. r31,r5,3 - mtctr r31 - beq cr0,Lendx - -LloopE: - lwzu r7,4(r4) - mullw r8,r7,r6 - adde r8,r8,r0 //# add cy_limb - mulhwu r0,r7,r6 - lwz r7,4(r3) - addze r0,r0 //# new cy_limb - subfc r7,r8,r7 - addc r8,r8,r7 - stwu r7,4(r3) - bdnz LloopE -Lendx: - addze r3,r0 - lmw r30,-32(r1) -} - -/* -asm void __umul_ppmm() -{ - mullw r0,r4,r5 - mulhwu r9,r4,r5 - stw r0,0(r3) - mr r3,r9 -} -*/ diff --git a/gmp/mpn/powerpc32/mul_1.asm b/gmp/mpn/powerpc32/mul_1.asm deleted file mode 100755 index f54866b..0000000 Binary files a/gmp/mpn/powerpc32/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/regmap.m4 b/gmp/mpn/powerpc32/regmap.m4 deleted file mode 100755 index 4cd98cd..0000000 Binary files a/gmp/mpn/powerpc32/regmap.m4 and /dev/null differ diff --git a/gmp/mpn/powerpc32/rshift.asm b/gmp/mpn/powerpc32/rshift.asm deleted file mode 100755 index 2102d31..0000000 Binary files a/gmp/mpn/powerpc32/rshift.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/sub_n.asm b/gmp/mpn/powerpc32/sub_n.asm deleted file mode 100755 index 05ec2cd..0000000 Binary files a/gmp/mpn/powerpc32/sub_n.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/submul_1.asm b/gmp/mpn/powerpc32/submul_1.asm deleted file mode 100755 index b66bbcd..0000000 Binary files a/gmp/mpn/powerpc32/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/powerpc32/umul.asm b/gmp/mpn/powerpc32/umul.asm deleted file mode 100755 index d7ba188..0000000 Binary files a/gmp/mpn/powerpc32/umul.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/README b/gmp/mpn/powerpc64/README deleted file mode 100755 index 9886107..0000000 Binary files a/gmp/mpn/powerpc64/README and /dev/null differ diff --git a/gmp/mpn/powerpc64/add_n.asm b/gmp/mpn/powerpc64/add_n.asm deleted file mode 100755 index 0a80276..0000000 Binary files a/gmp/mpn/powerpc64/add_n.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/addmul_1.asm b/gmp/mpn/powerpc64/addmul_1.asm deleted file mode 100755 index 5d0e061..0000000 Binary files a/gmp/mpn/powerpc64/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/addsub_n.asm b/gmp/mpn/powerpc64/addsub_n.asm deleted file mode 100755 index 96f738a..0000000 Binary files a/gmp/mpn/powerpc64/addsub_n.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/aix.m4 b/gmp/mpn/powerpc64/aix.m4 deleted file mode 100755 index 9ea5948..0000000 Binary files a/gmp/mpn/powerpc64/aix.m4 and /dev/null differ diff --git a/gmp/mpn/powerpc64/copyd.asm b/gmp/mpn/powerpc64/copyd.asm deleted file mode 100755 index fbe8485..0000000 Binary files a/gmp/mpn/powerpc64/copyd.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/copyi.asm b/gmp/mpn/powerpc64/copyi.asm deleted file mode 100755 index e7caef2..0000000 Binary files a/gmp/mpn/powerpc64/copyi.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/gmp-mparam.h b/gmp/mpn/powerpc64/gmp-mparam.h deleted file mode 100755 index 6fefb96..0000000 --- a/gmp/mpn/powerpc64/gmp-mparam.h +++ /dev/null @@ -1,62 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1995, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* Generated by tuneup.c, 2000-07-16. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 10 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 57 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 16 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 89 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 28 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 216 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 14 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 6 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 163 -#endif diff --git a/gmp/mpn/powerpc64/lshift.asm b/gmp/mpn/powerpc64/lshift.asm deleted file mode 100755 index 60b074a..0000000 Binary files a/gmp/mpn/powerpc64/lshift.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/mul_1.asm b/gmp/mpn/powerpc64/mul_1.asm deleted file mode 100755 index c6661f9..0000000 Binary files a/gmp/mpn/powerpc64/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/rshift.asm b/gmp/mpn/powerpc64/rshift.asm deleted file mode 100755 index eb082ba..0000000 Binary files a/gmp/mpn/powerpc64/rshift.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/sub_n.asm b/gmp/mpn/powerpc64/sub_n.asm deleted file mode 100755 index 6467269..0000000 Binary files a/gmp/mpn/powerpc64/sub_n.asm and /dev/null differ diff --git a/gmp/mpn/powerpc64/submul_1.asm b/gmp/mpn/powerpc64/submul_1.asm deleted file mode 100755 index f1e195e..0000000 Binary files a/gmp/mpn/powerpc64/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/pyr/add_n.s b/gmp/mpn/pyr/add_n.s deleted file mode 100755 index e3708c5..0000000 Binary files a/gmp/mpn/pyr/add_n.s and /dev/null differ diff --git a/gmp/mpn/pyr/addmul_1.s b/gmp/mpn/pyr/addmul_1.s deleted file mode 100755 index 2d9e9ec..0000000 Binary files a/gmp/mpn/pyr/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/pyr/mul_1.s b/gmp/mpn/pyr/mul_1.s deleted file mode 100755 index 84c3a3a..0000000 Binary files a/gmp/mpn/pyr/mul_1.s and /dev/null differ diff --git a/gmp/mpn/pyr/sub_n.s b/gmp/mpn/pyr/sub_n.s deleted file mode 100755 index 98c094f..0000000 Binary files a/gmp/mpn/pyr/sub_n.s and /dev/null differ diff --git a/gmp/mpn/sh/add_n.s b/gmp/mpn/sh/add_n.s deleted file mode 100755 index 2773a45..0000000 Binary files a/gmp/mpn/sh/add_n.s and /dev/null differ diff --git a/gmp/mpn/sh/sh2/addmul_1.s b/gmp/mpn/sh/sh2/addmul_1.s deleted file mode 100755 index b577a99..0000000 Binary files a/gmp/mpn/sh/sh2/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/sh/sh2/mul_1.s b/gmp/mpn/sh/sh2/mul_1.s deleted file mode 100755 index a52611f..0000000 Binary files a/gmp/mpn/sh/sh2/mul_1.s and /dev/null differ diff --git a/gmp/mpn/sh/sh2/submul_1.s b/gmp/mpn/sh/sh2/submul_1.s deleted file mode 100755 index c6c3fda..0000000 Binary files a/gmp/mpn/sh/sh2/submul_1.s and /dev/null differ diff --git a/gmp/mpn/sh/sub_n.s b/gmp/mpn/sh/sub_n.s deleted file mode 100755 index 365e478..0000000 Binary files a/gmp/mpn/sh/sub_n.s and /dev/null differ diff --git a/gmp/mpn/sparc32/README b/gmp/mpn/sparc32/README deleted file mode 100755 index aed808e..0000000 Binary files a/gmp/mpn/sparc32/README and /dev/null differ diff --git a/gmp/mpn/sparc32/add_n.asm b/gmp/mpn/sparc32/add_n.asm deleted file mode 100755 index 7c88ff9..0000000 Binary files a/gmp/mpn/sparc32/add_n.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/addmul_1.asm b/gmp/mpn/sparc32/addmul_1.asm deleted file mode 100755 index 58f888d..0000000 Binary files a/gmp/mpn/sparc32/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/lshift.asm b/gmp/mpn/sparc32/lshift.asm deleted file mode 100755 index 697f4fc..0000000 Binary files a/gmp/mpn/sparc32/lshift.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/mul_1.asm b/gmp/mpn/sparc32/mul_1.asm deleted file mode 100755 index 1431f0f..0000000 Binary files a/gmp/mpn/sparc32/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/rshift.asm b/gmp/mpn/sparc32/rshift.asm deleted file mode 100755 index d026244..0000000 Binary files a/gmp/mpn/sparc32/rshift.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/sub_n.asm b/gmp/mpn/sparc32/sub_n.asm deleted file mode 100755 index 99c86cc..0000000 Binary files a/gmp/mpn/sparc32/sub_n.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/submul_1.asm b/gmp/mpn/sparc32/submul_1.asm deleted file mode 100755 index 7397c17..0000000 Binary files a/gmp/mpn/sparc32/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/udiv_fp.asm b/gmp/mpn/sparc32/udiv_fp.asm deleted file mode 100755 index cde279a..0000000 Binary files a/gmp/mpn/sparc32/udiv_fp.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/udiv_nfp.asm b/gmp/mpn/sparc32/udiv_nfp.asm deleted file mode 100755 index 182fa55..0000000 Binary files a/gmp/mpn/sparc32/udiv_nfp.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/umul.asm b/gmp/mpn/sparc32/umul.asm deleted file mode 100755 index 4bb4168..0000000 Binary files a/gmp/mpn/sparc32/umul.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v8/addmul_1.asm b/gmp/mpn/sparc32/v8/addmul_1.asm deleted file mode 100755 index 21916b3..0000000 Binary files a/gmp/mpn/sparc32/v8/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v8/mul_1.asm b/gmp/mpn/sparc32/v8/mul_1.asm deleted file mode 100755 index 53c14b8..0000000 Binary files a/gmp/mpn/sparc32/v8/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v8/submul_1.asm b/gmp/mpn/sparc32/v8/submul_1.asm deleted file mode 100755 index 5c34741..0000000 Binary files a/gmp/mpn/sparc32/v8/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v8/supersparc/udiv.asm b/gmp/mpn/sparc32/v8/supersparc/udiv.asm deleted file mode 100755 index adffb0b..0000000 Binary files a/gmp/mpn/sparc32/v8/supersparc/udiv.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v8/umul.asm b/gmp/mpn/sparc32/v8/umul.asm deleted file mode 100755 index d54e9bc..0000000 Binary files a/gmp/mpn/sparc32/v8/umul.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v9/README b/gmp/mpn/sparc32/v9/README deleted file mode 100755 index 2bc9766..0000000 Binary files a/gmp/mpn/sparc32/v9/README and /dev/null differ diff --git a/gmp/mpn/sparc32/v9/addmul_1.asm b/gmp/mpn/sparc32/v9/addmul_1.asm deleted file mode 100755 index 296bd31..0000000 Binary files a/gmp/mpn/sparc32/v9/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v9/gmp-mparam.h b/gmp/mpn/sparc32/v9/gmp-mparam.h deleted file mode 100755 index f946b90..0000000 --- a/gmp/mpn/sparc32/v9/gmp-mparam.h +++ /dev/null @@ -1,69 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - - -/* These values are for UltraSPARC I, II, and IIi. It is bogus that - this file lives in v9, but that will do for now. */ - -/* Variations in addmul_1 speed make the multiply and square thresholds - doubtful. TOOM3_SQR_THRESHOLD had to be estimated here. */ - -/* Generated by tuneup.c, 2000-07-06. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 30 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 200 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 59 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 500 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 107 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 146 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 29 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 3 -#endif diff --git a/gmp/mpn/sparc32/v9/mul_1.asm b/gmp/mpn/sparc32/v9/mul_1.asm deleted file mode 100755 index 0f26ff3..0000000 Binary files a/gmp/mpn/sparc32/v9/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc32/v9/submul_1.asm b/gmp/mpn/sparc32/v9/submul_1.asm deleted file mode 100755 index 58cd61b..0000000 Binary files a/gmp/mpn/sparc32/v9/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/README b/gmp/mpn/sparc64/README deleted file mode 100755 index fca99d3..0000000 Binary files a/gmp/mpn/sparc64/README and /dev/null differ diff --git a/gmp/mpn/sparc64/add_n.asm b/gmp/mpn/sparc64/add_n.asm deleted file mode 100755 index e2b1189..0000000 Binary files a/gmp/mpn/sparc64/add_n.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/addmul1h.asm b/gmp/mpn/sparc64/addmul1h.asm deleted file mode 100755 index 5cc82a9..0000000 Binary files a/gmp/mpn/sparc64/addmul1h.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/addmul_1.asm b/gmp/mpn/sparc64/addmul_1.asm deleted file mode 100755 index aa3bddb..0000000 Binary files a/gmp/mpn/sparc64/addmul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/copyi.asm b/gmp/mpn/sparc64/copyi.asm deleted file mode 100755 index 7122e60..0000000 Binary files a/gmp/mpn/sparc64/copyi.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/gmp-mparam.h b/gmp/mpn/sparc64/gmp-mparam.h deleted file mode 100755 index 74f6166..0000000 --- a/gmp/mpn/sparc64/gmp-mparam.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Sparc64 gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 64 -#define BYTES_PER_MP_LIMB 8 -#define BITS_PER_LONGINT 64 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - -/* Tell the toom3 multiply implementation to call low-level mpn - functions instead of open-coding operations in C. */ -#define USE_MORE_MPN 1 - - -/* Run on sun workshop cc. */ -/* Generated by tuneup.c, 2000-07-30. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 12 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 95 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 33 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 125 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 27 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 107 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 12 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 199 -#endif - -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE { 304, 608, 1344, 2304, 7168, 20480, 49152, 0 } -#endif -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD 320 -#endif -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD 1664 -#endif - -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE { 304, 608, 1344, 2816, 7168, 20480, 49152, 0 } -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD 320 -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD 1664 -#endif diff --git a/gmp/mpn/sparc64/lshift.asm b/gmp/mpn/sparc64/lshift.asm deleted file mode 100755 index 0315063..0000000 Binary files a/gmp/mpn/sparc64/lshift.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/mul_1.asm b/gmp/mpn/sparc64/mul_1.asm deleted file mode 100755 index 26e9287..0000000 Binary files a/gmp/mpn/sparc64/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/mul_1h.asm b/gmp/mpn/sparc64/mul_1h.asm deleted file mode 100755 index fddea9c..0000000 Binary files a/gmp/mpn/sparc64/mul_1h.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/rshift.asm b/gmp/mpn/sparc64/rshift.asm deleted file mode 100755 index 9013b49..0000000 Binary files a/gmp/mpn/sparc64/rshift.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/sub_n.asm b/gmp/mpn/sparc64/sub_n.asm deleted file mode 100755 index 8c9fc03..0000000 Binary files a/gmp/mpn/sparc64/sub_n.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/submul1h.asm b/gmp/mpn/sparc64/submul1h.asm deleted file mode 100755 index dca99cf..0000000 Binary files a/gmp/mpn/sparc64/submul1h.asm and /dev/null differ diff --git a/gmp/mpn/sparc64/submul_1.asm b/gmp/mpn/sparc64/submul_1.asm deleted file mode 100755 index 5ce9215..0000000 Binary files a/gmp/mpn/sparc64/submul_1.asm and /dev/null differ diff --git a/gmp/mpn/tests/Makefile.am b/gmp/mpn/tests/Makefile.am deleted file mode 100755 index 593c01a..0000000 Binary files a/gmp/mpn/tests/Makefile.am and /dev/null differ diff --git a/gmp/mpn/tests/Makefile.in b/gmp/mpn/tests/Makefile.in deleted file mode 100755 index 18e6165..0000000 Binary files a/gmp/mpn/tests/Makefile.in and /dev/null differ diff --git a/gmp/mpn/tests/README b/gmp/mpn/tests/README deleted file mode 100755 index 8714e2b..0000000 Binary files a/gmp/mpn/tests/README and /dev/null differ diff --git a/gmp/mpn/tests/add_n.c b/gmp/mpn/tests/add_n.c deleted file mode 100755 index 5662951..0000000 --- a/gmp/mpn/tests/add_n.c +++ /dev/null @@ -1,257 +0,0 @@ -/* -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 328 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - - -mp_limb_t -#if __STDC__ -refmpn_add_n (mp_ptr res_ptr, - mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) -#else -refmpn_add_n (res_ptr, s1_ptr, s2_ptr, size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_srcptr s2_ptr; - mp_size_t size; -#endif -{ - register mp_limb_t x, y, cy; - register mp_size_t j; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - s2_ptr -= j; - res_ptr -= j; - - cy = 0; - do - { - y = s2_ptr[j]; - x = s1_ptr[j]; - y += cy; /* add previous carry to one addend */ - cy = (y < cy); /* get out carry from that addition */ - y = x + y; /* add other addend */ - cy = (y < x) + cy; /* get out carry from that add, combine */ - res_ptr[j] = y; - } - while (++j != 0); - - return cy; -} - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t s2[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - int cyx, cyy; - int i; - long t0, t; - int test; - mp_size_t size; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - - dx[0] = 0x87654321; - dy[0] = 0x87654321; - dx[size+1] = 0x12345678; - dy[size+1] = 0x12345678; - -#if TIMES != 1 - mpn_random (s1, size); - mpn_random (s2, size); - -#ifndef NOCHECK - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_add_n (dx+1, s1, s2, size); - t = cputime() - t0; - printf ("refmpn_add_n: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_add_n (dx+1, s1, s2, size); - t = cputime() - t0; - printf ("mpn_add_n: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - -#ifndef NOCHECK - mpn_random2 (s1, size); - mpn_random2 (s2, size); - -#ifdef PRINT - mpn_print (s1, size); - mpn_print (s2, size); -#endif - - /* Put garbage in the destination. */ - for (i = 0; i < size; i++) - { - dx[i+1] = 0xdead; - dy[i+1] = 0xbeef; - } - - cyx = refmpn_add_n (dx+1, s1, s2, size); - cyy = mpn_add_n (dy+1, s1, s2, size); -#ifdef PRINT - printf ("%d ", cyx); mpn_print (dx+1, size); - printf ("%d ", cyy); mpn_print (dy+1, size); -#endif - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[0] != 0x87654321 || dx[size+1] != 0x12345678) - { -#ifndef PRINT - printf ("%d ", cyx); mpn_print (dx+1, size); - printf ("%d ", cyy); mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/addmul_1.c b/gmp/mpn/tests/addmul_1.c deleted file mode 100755 index 53513f3..0000000 --- a/gmp/mpn/tests/addmul_1.c +++ /dev/null @@ -1,265 +0,0 @@ -/* -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 496 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - -mp_limb_t -refmpn_addmul_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - mp_size_t s1_size; - register mp_limb_t s2_limb; -{ - register mp_limb_t cy_limb; - register mp_size_t j; - register mp_limb_t prod_high, prod_low; - register mp_limb_t x; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -s1_size; - - /* Offset the base pointers to compensate for the negative indices. */ - res_ptr -= j; - s1_ptr -= j; - - cy_limb = 0; - do - { - umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb); - - prod_low += cy_limb; - cy_limb = (prod_low < cy_limb) + prod_high; - - x = res_ptr[j]; - prod_low = x + prod_low; - cy_limb += (prod_low < x); - res_ptr[j] = prod_low; - } - while (++j != 0); - - return cy_limb; -} - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - mp_limb_t cyx, cyy; - int i; - long t0, t; - int test; - mp_limb_t xlimb; - mp_size_t size; - double cyc; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - - dy[size+1] = 0x12345678; - dy[0] = 0x87654321; - - mpn_random2 (&xlimb, 1); - -#if TIMES != 1 - mpn_random (s1, size); - mpn_random (dy+1, size); - -#ifndef NOCHECK - MPN_COPY (dx, dy, size+2); - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_addmul_1 (dx+1, s1, size, xlimb); - t = cputime() - t0; - cyc = ((double) t * CLOCK) / (OPS * 1000.0); - printf ("refmpn_addmul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n", - t, cyc, - CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9); -#endif - - MPN_COPY (dx, dy, size+2); - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_addmul_1 (dx+1, s1, size, xlimb); - t = cputime() - t0; - cyc = ((double) t * CLOCK) / (OPS * 1000.0); - printf ("mpn_addmul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n", - t, cyc, - CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9); -#endif - - mpn_random2 (s1, size); - mpn_random2 (dy+1, size); -#if defined (PRINT) || defined (XPRINT) - printf ("xlimb="); - mpn_print (&xlimb, 1); -#endif -#ifdef PRINT - mpn_print (dy+1, size); - mpn_print (s1, size); -#endif - - MPN_COPY (dx, dy, size+2); - cyx = refmpn_addmul_1 (dx+1, s1, size, xlimb); - cyy = mpn_addmul_1 (dy+1, s1, size, xlimb); - -#ifdef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - -#ifndef NOCHECK - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[size+1] != 0x12345678 || dx[0] != 0x87654321) - { -#ifndef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/copy.c b/gmp/mpn/tests/copy.c deleted file mode 100755 index 07d8495..0000000 --- a/gmp/mpn/tests/copy.c +++ /dev/null @@ -1,228 +0,0 @@ -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/2) -#endif -#ifndef SIZE -#define SIZE 328 -#endif -#ifndef TIMES -#define TIMES (OPS/SIZE) -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - - -void -#if __STDC__ -refmpn_copyi (mp_ptr rptr, mp_srcptr sptr, mp_size_t n) -#else -refmpn_copyi (rptr, sptr, n) - register mp_ptr rptr; - register mp_srcptr sptr; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - rptr[i] = sptr[i]; -} - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - int i; - long t0, t; - int test; - mp_size_t size; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#ifdef RANDOM - size = (random () % SIZE + 1); -#else - size = SIZE; -#endif - - dx[0] = 0x87654321; - dy[0] = 0x87654321; - dx[size+1] = 0x12345678; - dy[size+1] = 0x12345678; - -#if TIMES != 1 - mpn_random (s1, size); - -#ifndef NOCHECK - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_copyi (dx+1, s1, size); - t = cputime() - t0; - printf ("refmpn_copyi: %ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - - t0 = cputime(); - for (i = 0; i < TIMES; i++) - MPN_COPY_INCR (dx+1, s1, size); - t = cputime() - t0; - printf ("MPN_COPY_INCR: %ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - -#ifndef NOCHECK - mpn_random2 (s1, size); - -#ifdef PRINT - mpn_print (s1, size); -#endif - - /* Put garbage in the destination. */ - for (i = 0; i < size; i++) - { - dx[i+1] = 0xdead; - dy[i+1] = 0xbeef; - } - - refmpn_copyi (dx+1, s1, size); - MPN_COPY_INCR (dy+1, s1, size); -#ifdef PRINT - mpn_print (dx+1, size); - mpn_print (dy+1, size); -#endif - if (mpn_cmp (dx, dy, size+2) != 0 - || dx[0] != 0x87654321 || dx[size+1] != 0x12345678) - { -#ifndef PRINT - mpn_print (dx+1, size); - mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/divmod_1.c b/gmp/mpn/tests/divmod_1.c deleted file mode 100755 index 4f0b07d..0000000 --- a/gmp/mpn/tests/divmod_1.c +++ /dev/null @@ -1,148 +0,0 @@ -/* -Copyright (C) 1996, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS 20000000 -#endif -#ifndef SIZE -#define SIZE 1000 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - -main () -{ - mp_limb_t nptr[SIZE]; - mp_limb_t qptr[SIZE]; - mp_limb_t pptr[SIZE]; - mp_limb_t dlimb, rlimb, plimb; - mp_size_t nsize, qsize, psize; - int test; - - for (test = 0; ; test++) - { -#ifdef RANDOM - nsize = random () % SIZE + 1; -#else - nsize = SIZE; -#endif - - mpn_random2 (nptr, nsize); - - mpn_random2 (&dlimb, 1); - if (dlimb == 0) - abort (); - - rlimb = mpn_divmod_1 (qptr, nptr, nsize, dlimb); - qsize = nsize - (qptr[nsize - 1] == 0); - if (qsize == 0) - { - plimb = rlimb; - psize = qsize; - } - else - { - plimb = mpn_mul_1 (pptr, qptr, qsize, dlimb); - psize = qsize; - plimb += mpn_add_1 (pptr, pptr, psize, rlimb); - } - if (plimb != 0) - pptr[psize++] = plimb; - - - if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0) - abort (); - } -} diff --git a/gmp/mpn/tests/divrem.c b/gmp/mpn/tests/divrem.c deleted file mode 100755 index 0f071a3..0000000 --- a/gmp/mpn/tests/divrem.c +++ /dev/null @@ -1,158 +0,0 @@ -/* -Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS 20000000 -#endif -#ifndef SIZE -#define SIZE 100 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - -main () -{ - mp_limb_t nptr[2 * SIZE]; - mp_limb_t dptr[2 * SIZE]; - mp_limb_t qptr[2 * SIZE]; - mp_limb_t pptr[2 * SIZE + 1]; - mp_limb_t rptr[2 * SIZE]; - mp_size_t nsize, dsize, qsize, rsize, psize; - int test; - mp_limb_t qlimb; - - for (test = 0; ; test++) - { - printf ("%d\n", test); -#ifdef RANDOM - nsize = random () % (2 * SIZE) + 1; - dsize = random () % nsize + 1; -#else - nsize = 2 * SIZE; - dsize = SIZE; -#endif - - mpn_random2 (nptr, nsize); - mpn_random2 (dptr, dsize); - dptr[dsize - 1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1); - - MPN_COPY (rptr, nptr, nsize); - qlimb = mpn_divrem (qptr, (mp_size_t) 0, rptr, nsize, dptr, dsize); - rsize = dsize; - qsize = nsize - dsize; - qptr[qsize] = qlimb; - qsize += qlimb; - if (qsize == 0 || qsize > 2 * SIZE) - { - continue; /* bogus */ - } - else - { - mp_limb_t cy; - if (qsize > dsize) - mpn_mul (pptr, qptr, qsize, dptr, dsize); - else - mpn_mul (pptr, dptr, dsize, qptr, qsize); - psize = qsize + dsize; - psize -= pptr[psize - 1] == 0; - cy = mpn_add (pptr, pptr, psize, rptr, rsize); - pptr[psize] = cy; - psize += cy; - } - - if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0) - abort (); - } -} diff --git a/gmp/mpn/tests/lshift.c b/gmp/mpn/tests/lshift.c deleted file mode 100755 index cf3f522..0000000 --- a/gmp/mpn/tests/lshift.c +++ /dev/null @@ -1,279 +0,0 @@ -/* -Copyright (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 496 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - -mp_limb_t -refmpn_lshift (wp, up, usize, cnt) - register mp_ptr wp; - register mp_srcptr up; - mp_size_t usize; - register unsigned int cnt; -{ - register mp_limb_t high_limb, low_limb; - register unsigned sh_1, sh_2; - register mp_size_t i; - mp_limb_t retval; - -#ifdef DEBUG - if (usize == 0 || cnt == 0) - abort (); -#endif - - sh_1 = cnt; -#if 0 - if (sh_1 == 0) - { - if (wp != up) - { - /* Copy from high end to low end, to allow specified input/output - overlapping. */ - for (i = usize - 1; i >= 0; i--) - wp[i] = up[i]; - } - return 0; - } -#endif - - wp += 1; - sh_2 = BITS_PER_MP_LIMB - sh_1; - i = usize - 1; - low_limb = up[i]; - retval = low_limb >> sh_2; - high_limb = low_limb; - while (--i >= 0) - { - low_limb = up[i]; - wp[i] = (high_limb << sh_1) | (low_limb >> sh_2); - high_limb = low_limb; - } - wp[i] = high_limb << sh_1; - - return retval; -} - -#ifndef CNT -#define CNT 4 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - mp_limb_t cyx, cyy; - int i; - long t0, t; - int test; - int cnt = CNT; - mp_size_t size; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#if TIMES == 1 - cnt = random () % (BITS_PER_MP_LIMB - 1) + 1; -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - mpn_random2 (s1, size); - - dx[size+1] = 0x12345678; - dy[size+1] = 0x12345678; - dx[0] = 0x87654321; - dy[0] = 0x87654321; - -#if TIMES != 1 - mpn_random (s1, size); - -#ifndef NOCHECK - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_lshift (dx+1, s1, size, cnt); - t = cputime() - t0; - printf ("refmpn_lshift: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_lshift (dx+1, s1, size, cnt); - t = cputime() - t0; - printf ("mpn_lshift: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - -#ifndef NOCHECK - mpn_random2 (s1, size); - -#ifdef PRINT - printf ("%-*d ", (int) (2 * sizeof(mp_limb_t)), cnt); mpn_print (s1, size); -#endif - - /* Put garbage in the destination. */ - for (i = 0; i < size; i++) - { - dx[i+1] = 0xdead; - dy[i+1] = 0xbeef; - } - - cyx = refmpn_lshift (dx+1, s1, size, cnt); - cyy = mpn_lshift (dy+1, s1, size, cnt); -#ifdef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[0] != 0x87654321 || dx[size+1] != 0x12345678) - { -#ifndef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - if (dy[size+1] != 0x12345678) - printf ("clobbered at high end\n"); - if (dy[0] != 0x87654321) - printf ("clobbered at low end\n"); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/mul_1.c b/gmp/mpn/tests/mul_1.c deleted file mode 100755 index 08ab001..0000000 --- a/gmp/mpn/tests/mul_1.c +++ /dev/null @@ -1,263 +0,0 @@ -/* -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 496 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - -mp_limb_t -refmpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - mp_size_t s1_size; - register mp_limb_t s2_limb; -{ - register mp_limb_t cy_limb; - register mp_size_t j; - register mp_limb_t prod_high, prod_low; - - /* The loop counter and index J goes from -S1_SIZE to -1. This way - the loop becomes faster. */ - j = -s1_size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - res_ptr -= j; - - cy_limb = 0; - do - { - umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb); - - prod_low += cy_limb; - cy_limb = (prod_low < cy_limb) + prod_high; - - res_ptr[j] = prod_low; - } - while (++j != 0); - - return cy_limb; -} - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - mp_limb_t cyx, cyy; - int i; - long t0, t; - int test; - mp_limb_t xlimb; - mp_size_t size; - double cyc; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - - dy[size+1] = 0x12345678; - dy[0] = 0x87654321; - - mpn_random2 (&xlimb, 1); - -#if TIMES != 1 - mpn_random (s1, size); - mpn_random (dy+1, size); - -#ifndef NOCHECK - MPN_COPY (dx, dy, size+2); - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_mul_1 (dx+1, s1, size, xlimb); - t = cputime() - t0; - cyc = ((double) t * CLOCK) / (OPS * 1000.0); - printf ("refmpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n", - t, cyc, - CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9); -#endif - - MPN_COPY (dx, dy, size+2); - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_mul_1 (dx+1, s1, size, xlimb); - t = cputime() - t0; - cyc = ((double) t * CLOCK) / (OPS * 1000.0); - printf ("mpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n", - t, cyc, - CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9); -#endif - - mpn_random2 (s1, size); - mpn_random2 (dy+1, size); -#if defined (PRINT) || defined (XPRINT) - printf ("xlimb="); - mpn_print (&xlimb, 1); -#endif -#ifdef PRINT - mpn_print (s1, size); -#endif - - MPN_COPY (dx, dy, size+2); - cyx = refmpn_mul_1 (dx+1, s1, size, xlimb); - cyy = mpn_mul_1 (dy+1, s1, size, xlimb); - -#ifdef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - -#ifndef NOCHECK - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[size+1] != 0x12345678 || dx[0] != 0x87654321) - { -#if ! (defined (PRINT) || defined (XPRINT)) - printf ("xlimb=%*lX\n", (int) (2 * sizeof(mp_limb_t)), xlimb); -#endif -#ifndef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/ref.c b/gmp/mpn/tests/ref.c deleted file mode 100755 index 5bf9609..0000000 --- a/gmp/mpn/tests/ref.c +++ /dev/null @@ -1,942 +0,0 @@ -/* Reference mpn functions, designed to be simple, portable and independent - of the normal gmp code. Speed isn't a consideration. */ - -/* -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - - -/* Most routines have assertions representing what the mpn routines are - supposed to accept. Many of these reference routines do sensible things - outside these ranges (eg. for size==0), but the assertions are present to - pick up bad parameters passed here that are about to be passed the same - to a real mpn routine being compared. */ - -/* always do assertion checking */ -#define WANT_ASSERT 1 - -#include /* for NULL */ -#include /* for malloc */ -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#include "ref.h" - - -/* Check overlap for a routine defined to work low to high. */ -int -refmpn_overlap_low_to_high_p (mp_srcptr dst, mp_srcptr src, mp_size_t size) -{ - return (!MPN_OVERLAP_P (dst, size, src, size) || dst <= src); -} - -/* Check overlap for a routine defined to work high to low. */ -int -refmpn_overlap_high_to_low_p (mp_srcptr dst, mp_srcptr src, mp_size_t size) -{ - return (!MPN_OVERLAP_P (dst, size, src, size) || dst >= src); -} - -/* Check overlap for a standard routine requiring equal or separate. */ -int -refmpn_overlap_fullonly_p (mp_srcptr dst, mp_srcptr src, mp_size_t size) -{ - return (dst == src || !MPN_OVERLAP_P (dst, size, src, size)); -} -int -refmpn_overlap_fullonly_two_p (mp_srcptr dst, mp_srcptr src1, mp_srcptr src2, - mp_size_t size) -{ - return (refmpn_overlap_fullonly_p (dst, src1, size) - && refmpn_overlap_fullonly_p (dst, src2, size)); -} - - -mp_ptr -refmpn_malloc_limbs (mp_size_t size) -{ - mp_ptr p; - ASSERT (size >= 0); - if (size == 0) - size = 1; - p = (mp_ptr) malloc (size * BYTES_PER_MP_LIMB); - ASSERT (p != NULL); - return p; -} - -mp_ptr -refmpn_memdup_limbs (mp_srcptr ptr, mp_size_t size) -{ - mp_ptr p; - p = refmpn_malloc_limbs (size); - refmpn_copyi (p, ptr, size); - return p; -} - -void -refmpn_fill (mp_ptr ptr, mp_size_t size, mp_limb_t value) -{ - mp_size_t i; - ASSERT (size >= 0); - for (i = 0; i < size; i++) - ptr[i] = value; -} - -int -refmpn_zero_p (mp_srcptr ptr, mp_size_t size) -{ - mp_size_t i; - for (i = 0; i < size; i++) - if (ptr[i] != 0) - return 0; - return 1; -} - -mp_limb_t -refmpn_msbone (mp_limb_t x) -{ - mp_limb_t n = (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - - while (n != 0) - { - if (x & n) - break; - n >>= 1; - } - return n; -} - -/* a mask of the MSB one bit and all bits below */ -mp_limb_t -refmpn_msbone_mask (mp_limb_t x) -{ - if (x == 0) - return 0; - - return (refmpn_msbone (x) << 1) - 1; -} - -void -refmpn_copyi (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ - mp_size_t i; - - ASSERT (refmpn_overlap_low_to_high_p (rp, sp, size)); - ASSERT (size >= 0); - - for (i = 0; i < size; i++) - rp[i] = sp[i]; -} - -void -refmpn_copyd (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ - mp_size_t i; - - ASSERT (refmpn_overlap_high_to_low_p (rp, sp, size)); - ASSERT (size >= 0); - - for (i = size-1; i >= 0; i--) - rp[i] = sp[i]; -} - -void -refmpn_com_n (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ - mp_size_t i; - - ASSERT (refmpn_overlap_fullonly_p (rp, sp, size)); - ASSERT (size >= 1); - - for (i = 0; i < size; i++) - rp[i] = ~sp[i]; -} - - -int -refmpn_cmp (mp_srcptr xp, mp_srcptr yp, mp_size_t size) -{ - mp_size_t i; - - ASSERT (size >= 1); - - for (i = size-1; i >= 0; i--) - { - if (xp[i] > yp[i]) return 1; - if (xp[i] < yp[i]) return -1; - } - return 0; -} - -int -refmpn_cmp_twosizes (mp_srcptr xp, mp_size_t xsize, - mp_srcptr yp, mp_size_t ysize) -{ - int opp, cmp; - - opp = (xsize < ysize); - if (opp) - MPN_SRCPTR_SWAP (xp,xsize, yp,ysize); - - if (! refmpn_zero_p (xp+ysize, xsize-ysize)) - cmp = 1; - else - cmp = refmpn_cmp (xp, yp, ysize); - - return (opp ? -cmp : cmp); -} - - -#define LOGOPS(operation) \ - { \ - mp_size_t i; \ - \ - ASSERT (refmpn_overlap_fullonly_two_p (rp, s1p, s2p, size)); \ - ASSERT (size >= 1); \ - \ - for (i = 0; i < size; i++) \ - rp[i] = operation; \ - } - -void -refmpn_and_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (s1p[i] & s2p[i]); -} -void -refmpn_andn_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (s1p[i] & ~s2p[i]); -} -void -refmpn_nand_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (~(s1p[i] & s2p[i])); -} -void -refmpn_ior_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (s1p[i] | s2p[i]); -} -void -refmpn_iorn_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (s1p[i] | ~s2p[i]); -} -void -refmpn_nior_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (~(s1p[i] | s2p[i])); -} -void -refmpn_xor_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (s1p[i] ^ s2p[i]); -} -void -refmpn_xnor_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - LOGOPS (~(s1p[i] ^ s2p[i])); -} - -/* set *w to x+y, return 0 or 1 carry */ -mp_limb_t -add (mp_limb_t *w, mp_limb_t x, mp_limb_t y) -{ - *w = x + y; - return *w < x; -} - -/* set *w to x-y, return 0 or 1 borrow */ -mp_limb_t -sub (mp_limb_t *w, mp_limb_t x, mp_limb_t y) -{ - *w = x - y; - return *w > x; -} - -/* set *w to x+y+c (where c is 0 or 1), return 0 or 1 carry */ -mp_limb_t -adc (mp_limb_t *w, mp_limb_t x, mp_limb_t y, mp_limb_t c) -{ - mp_limb_t r; - ASSERT (c == 0 || c == 1); - r = add (w, x, y); - return r + add (w, *w, c); -} - -/* set *w to x-y-c (where c is 0 or 1), return 0 or 1 borrow */ -mp_limb_t -sbb (mp_limb_t *w, mp_limb_t x, mp_limb_t y, mp_limb_t c) -{ - mp_limb_t r; - ASSERT (c == 0 || c == 1); - r = sub (w, x, y); - return r + sub (w, *w, c); -} - - -#define AORS_1(operation) \ - { \ - mp_limb_t i; \ - \ - ASSERT (refmpn_overlap_fullonly_p (rp, sp, size)); \ - ASSERT (size >= 1); \ - \ - for (i = 0; i < size; i++) \ - n = operation (&rp[i], sp[i], n); \ - return n; \ - } - -mp_limb_t -refmpn_add_1 (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t n) -{ - AORS_1 (add); -} -mp_limb_t -refmpn_sub_1 (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t n) -{ - AORS_1 (sub); -} - -#define AORS_NC(operation) \ - { \ - mp_size_t i; \ - \ - ASSERT (refmpn_overlap_fullonly_two_p (rp, s1p, s2p, size)); \ - ASSERT (carry == 0 || carry == 1); \ - ASSERT (size >= 1); \ - \ - for (i = 0; i < size; i++) \ - carry = operation (&rp[i], s1p[i], s2p[i], carry); \ - return carry; \ - } - -mp_limb_t -refmpn_add_nc (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size, - mp_limb_t carry) -{ - AORS_NC (adc); -} -mp_limb_t -refmpn_sub_nc (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size, - mp_limb_t carry) -{ - AORS_NC (sbb); -} - - -mp_limb_t -refmpn_add_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - return refmpn_add_nc (rp, s1p, s2p, size, 0); -} -mp_limb_t -refmpn_sub_n (mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - return refmpn_sub_nc (rp, s1p, s2p, size, 0); -} - - -#define AORS(aors_n, aors_1) \ - { \ - mp_limb_t c; \ - ASSERT (s1size >= s2size); \ - ASSERT (s2size >= 1); \ - c = aors_n (rp, s1p, s2p, s2size); \ - if (s1size-s2size != 0) \ - c = aors_1 (rp+s2size, s1p+s2size, s1size-s2size, c); \ - return c; \ - } -mp_limb_t -refmpn_add (mp_ptr rp, - mp_srcptr s1p, mp_size_t s1size, - mp_srcptr s2p, mp_size_t s2size) -{ - AORS (refmpn_add_n, refmpn_add_1); -} -mp_limb_t -refmpn_sub (mp_ptr rp, - mp_srcptr s1p, mp_size_t s1size, - mp_srcptr s2p, mp_size_t s2size) -{ - AORS (refmpn_sub_n, refmpn_sub_1); -} - - -#define SHIFTHIGH(x) ((x) << BITS_PER_MP_LIMB/2) -#define SHIFTLOW(x) ((x) >> BITS_PER_MP_LIMB/2) - -#define LOWMASK (((mp_limb_t) 1 << BITS_PER_MP_LIMB/2)-1) -#define HIGHMASK SHIFTHIGH(LOWMASK) - -#define LOWPART(x) ((x) & LOWMASK) -#define HIGHPART(x) SHIFTLOW((x) & HIGHMASK) - -/* set *hi,*lo to x*y */ -void -mul (mp_limb_t *hi, mp_limb_t *lo, mp_limb_t x, mp_limb_t y) -{ - mp_limb_t s; - - *lo = LOWPART(x) * LOWPART(y); - *hi = HIGHPART(x) * HIGHPART(y); - - s = LOWPART(x) * HIGHPART(y); - ASSERT_NOCARRY (add (hi, *hi, add (lo, *lo, SHIFTHIGH(LOWPART(s))))); - ASSERT_NOCARRY (add (hi, *hi, HIGHPART(s))); - - s = HIGHPART(x) * LOWPART(y); - ASSERT_NOCARRY (add (hi, *hi, add (lo, *lo, SHIFTHIGH(LOWPART(s))))); - ASSERT_NOCARRY (add (hi, *hi, HIGHPART(s))); -} - -mp_limb_t -refmpn_mul_1c (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t multiplier, - mp_limb_t carry) -{ - mp_size_t i; - mp_limb_t hi, lo; - - ASSERT (refmpn_overlap_fullonly_p (rp, sp, size)); - ASSERT (size >= 1); - - for (i = 0; i < size; i++) - { - mul (&hi, &lo, sp[i], multiplier); - ASSERT_NOCARRY (add (&hi, hi, add (&lo, lo, carry))); - rp[i] = lo; - carry = hi; - } - - return carry; -} - -mp_limb_t -refmpn_mul_1 (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t multiplier) -{ - return refmpn_mul_1c (rp, sp, size, multiplier, 0); -} - - -#define AORSMUL_1C(operation_n) \ - { \ - mp_ptr p = refmpn_malloc_limbs (size); \ - mp_limb_t ret; \ - \ - ASSERT (refmpn_overlap_fullonly_p (rp, sp, size)); \ - ASSERT (size >= 1); \ - \ - ret = refmpn_mul_1c (p, sp, size, multiplier, carry); \ - ret += operation_n (rp, rp, p, size); \ - \ - free (p); \ - return ret; \ - } - -mp_limb_t -refmpn_addmul_1c (mp_ptr rp, mp_srcptr sp, mp_size_t size, - mp_limb_t multiplier, mp_limb_t carry) -{ - AORSMUL_1C (refmpn_add_n); -} -mp_limb_t -refmpn_submul_1c (mp_ptr rp, mp_srcptr sp, mp_size_t size, - mp_limb_t multiplier, mp_limb_t carry) -{ - AORSMUL_1C (refmpn_sub_n); -} - - -mp_limb_t -refmpn_addmul_1 (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t multiplier) -{ - return refmpn_addmul_1c (rp, sp, size, multiplier, 0); -} -mp_limb_t -refmpn_submul_1 (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t multiplier) -{ - return refmpn_submul_1c (rp, sp, size, multiplier, 0); -} - - -mp_limb_t -refmpn_addsub_nc (mp_ptr r1p, mp_ptr r2p, - mp_srcptr s1p, mp_srcptr s2p, mp_size_t size, - mp_limb_t carry) -{ - mp_ptr p; - mp_limb_t acy, scy; - - /* Destinations can't overlap. */ - ASSERT (! MPN_OVERLAP_P (r1p, size, r2p, size)); - ASSERT (refmpn_overlap_fullonly_two_p (r1p, s1p, s2p, size)); - ASSERT (refmpn_overlap_fullonly_two_p (r2p, s1p, s2p, size)); - ASSERT (size >= 1); - - p = refmpn_malloc_limbs (size); - acy = refmpn_add_nc (p, s1p, s2p, size, carry >> 1); - scy = refmpn_sub_nc (r2p, s1p, s2p, size, carry & 1); - refmpn_copyi (r1p, p, size); - free (p); - return 2 * acy + scy; -} - -mp_limb_t -refmpn_addsub_n (mp_ptr r1p, mp_ptr r2p, - mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - return refmpn_addsub_nc (r1p, r2p, s1p, s2p, size, 0); -} - - -/* Right shift hi,lo and return the low limb of the result. - Note a shift by BITS_PER_MP_LIMB isn't assumed to work (doesn't on x86). */ -mp_limb_t -rshift_make (mp_limb_t hi, mp_limb_t lo, unsigned shift) -{ - ASSERT (shift >= 0 && shift < BITS_PER_MP_LIMB); - if (shift == 0) - return lo; - else - return (hi << (BITS_PER_MP_LIMB-shift)) | (lo >> shift); -} - -/* Left shift hi,lo and return the high limb of the result. - Note a shift by BITS_PER_MP_LIMB isn't assumed to work (doesn't on x86). */ -mp_limb_t -lshift_make (mp_limb_t hi, mp_limb_t lo, unsigned shift) -{ - ASSERT (shift >= 0 && shift < BITS_PER_MP_LIMB); - if (shift == 0) - return hi; - else - return (hi << shift) | (lo >> (BITS_PER_MP_LIMB-shift)); -} - - -mp_limb_t -refmpn_rshift (mp_ptr rp, mp_srcptr sp, mp_size_t size, unsigned shift) -{ - mp_limb_t ret; - mp_size_t i; - - ASSERT (refmpn_overlap_low_to_high_p (rp, sp, size)); - ASSERT (size >= 1); - ASSERT (shift >= 1 && shift < BITS_PER_MP_LIMB); - - ret = rshift_make (sp[0], 0, shift); - - for (i = 0; i < size-1; i++) - rp[i] = rshift_make (sp[i+1], sp[i], shift); - - rp[i] = rshift_make (0, sp[i], shift); - return ret; -} - -mp_limb_t -refmpn_lshift (mp_ptr rp, mp_srcptr sp, mp_size_t size, unsigned shift) -{ - mp_limb_t ret; - mp_size_t i; - - ASSERT (refmpn_overlap_high_to_low_p (rp, sp, size)); - ASSERT (size >= 1); - ASSERT (shift >= 1 && shift < BITS_PER_MP_LIMB); - - ret = lshift_make (0, sp[size-1], shift); - - for (i = size-2; i >= 0; i--) - rp[i+1] = lshift_make (sp[i+1], sp[i], shift); - - rp[i+1] = lshift_make (sp[i+1], 0, shift); - return ret; -} - - -/* Divide h,l by d, producing a quotient *q and remainder *r. - Must have h < d. - __udiv_qrnnd_c isn't simple, and it's a bit slow, but it works. */ -void -div1 (mp_limb_t *q, mp_limb_t *r, mp_limb_t h, mp_limb_t l, mp_limb_t d) -{ - int n; - - ASSERT (d != 0); - ASSERT (h < d); - -#if 0 - udiv_qrnnd (*q, *r, h, l, d); - return; -#endif - - for (n = 0; !(d & MP_LIMB_T_HIGHBIT); n++) - d <<= 1; - - h = lshift_make (h, l, n); - l <<= n; - - __udiv_qrnnd_c (*q, *r, h, l, d); - *r >>= n; -} - -mp_limb_t -refmpn_divmod_1c (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t divisor, - mp_limb_t carry) -{ - mp_ptr sp_orig; - mp_ptr prod; - mp_limb_t carry_orig; - mp_size_t i; - - ASSERT (refmpn_overlap_fullonly_p (rp, sp, size)); - ASSERT (size >= 0); - ASSERT (carry < divisor); - - if (size == 0) - return carry; - - sp_orig = refmpn_memdup_limbs (sp, size); - prod = refmpn_malloc_limbs (size); - carry_orig = carry; - - for (i = size-1; i >= 0; i--) - div1 (&rp[i], &carry, carry, sp[i], divisor); - - /* check by multiplying back */ -#if 0 - printf ("size=%ld divisor=0x%lX carry=0x%lX remainder=0x%lX\n", - size, divisor, carry_orig, carry); - mpn_trace("s",sp_copy,size); - mpn_trace("r",rp,size); - printf ("mul_1c %lX\n", refmpn_mul_1c (prod, rp, size, divisor, carry)); - mpn_trace("p",prod,size); -#endif - ASSERT (refmpn_mul_1c (prod, rp, size, divisor, carry) == carry_orig); - ASSERT (refmpn_cmp (prod, sp_orig, size) == 0); - free (sp_orig); - free (prod); - - return carry; -} - -mp_limb_t -refmpn_divmod_1 (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t divisor) -{ - return refmpn_divmod_1c (rp, sp, size, divisor, 0); -} - - -mp_limb_t -refmpn_mod_1c (mp_srcptr sp, mp_size_t size, mp_limb_t divisor, - mp_limb_t carry) -{ - mp_ptr p = refmpn_malloc_limbs (size); - carry = refmpn_divmod_1c (p, sp, size, divisor, carry); - free (p); - return carry; -} - -mp_limb_t -refmpn_mod_1 (mp_srcptr sp, mp_size_t size, mp_limb_t divisor) -{ - return refmpn_mod_1c (sp, size, divisor, 0); -} - -mp_limb_t -refmpn_mod_1_rshift (mp_srcptr sp, mp_size_t size, - unsigned shift, mp_limb_t divisor) -{ - mp_limb_t r; - mp_ptr p = refmpn_malloc_limbs (size); - refmpn_rshift (p, sp, size, shift); - r = refmpn_mod_1 (p, size, divisor); - free (p); - return r; -} - - -mp_limb_t -refmpn_divrem_1c (mp_ptr rp, mp_size_t xsize, - mp_srcptr sp, mp_size_t size, mp_limb_t divisor, - mp_limb_t carry) -{ - mp_ptr z; - - z = refmpn_malloc_limbs (xsize); - refmpn_fill (z, xsize, 0); - - carry = refmpn_divmod_1c (rp+xsize, sp, size, divisor, carry); - carry = refmpn_divmod_1c (rp, z, xsize, divisor, carry); - - free (z); - return carry; -} - -mp_limb_t -refmpn_divrem_1 (mp_ptr rp, mp_size_t xsize, - mp_srcptr sp, mp_size_t size, mp_limb_t divisor) -{ - return refmpn_divrem_1c (rp, xsize, sp, size, divisor, 0); -} - - -/* As given in the manual, the divexact method gives quotient q and return - value c satisfying - - c*b^n + a-i == 3*q - - where a=dividend, i=initial carry, b=2^BITS_PER_MP_LIMB, and n=size. - - If a-i is divisible by 3 then c==0 and a plain divmod gives the quotient. - If (a-i)%3==r then c is a high limb tacked on that will turn r into 0. - Because 2^BITS_PER_MP_LIMB==1mod3 (so long as BITS_PER_MP_LIMB is even) - it's enough to set c=3-r, ie. if r=1 then c=2, or if r=2 then c=1. - - If a-i produces a borrow then refmpn_sub_1 leaves a twos complement - negative, ie. b^n+a-i, and the calculation produces c1 satisfying - - c1*b^n + b^n+a-i == 3*q - - From which clearly c=c1+1, so it's enough to just add any borrow to the - return value otherwise calculated. - - A borrow only occurs when a==0 or a==1, and, by the same reasoning as in - mpn/generic/diveby3.c, the c1 that results in those cases will only be 0 - or 1 respectively, so with 1 added the final return value is still in the - prescribed range 0 to 2. */ - -mp_limb_t -refmpn_divexact_by3c (mp_ptr rp, mp_srcptr sp, mp_size_t size, mp_limb_t carry) -{ - mp_ptr spcopy; - mp_limb_t c, cs; - - ASSERT (refmpn_overlap_fullonly_p (rp, sp, size)); - ASSERT (size >= 1); - ASSERT (carry <= 2); - - spcopy = refmpn_memdup_limbs (sp, size); - cs = refmpn_sub_1 (spcopy, spcopy, size, carry); - - c = refmpn_divmod_1 (rp, spcopy, size, 3); - if (c != 0) - { - ASSERT ((BITS_PER_MP_LIMB % 2) == 0); - c = 3-c; - ASSERT_NOCARRY (refmpn_divmod_1c (rp, spcopy, size, 3, c)); - } - - c += cs; - ASSERT (c <= 2); - - free (spcopy); - return c; -} - -mp_limb_t -refmpn_divexact_by3 (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ - return refmpn_divexact_by3c (rp, sp, size, 0); -} - - -/* The same as mpn/generic/mul_basecase.c, but using refmpn functions. */ -void -refmpn_mul_basecase (mp_ptr prodp, - mp_srcptr up, mp_size_t usize, - mp_srcptr vp, mp_size_t vsize) -{ - mp_size_t i; - - ASSERT (! MPN_OVERLAP_P (prodp, usize+vsize, up, usize)); - ASSERT (! MPN_OVERLAP_P (prodp, usize+vsize, vp, vsize)); - ASSERT (usize >= vsize); - ASSERT (vsize >= 1); - - prodp[usize] = refmpn_mul_1 (prodp, up, usize, vp[0]); - for (i = 1; i < vsize; i++) - prodp[usize+i] = refmpn_addmul_1 (prodp+i, up, usize, vp[i]); -} - -void -refmpn_mul_n (mp_ptr prodp, mp_srcptr up, mp_srcptr vp, mp_size_t size) -{ - refmpn_mul_basecase (prodp, up, size, vp, size); -} - -void -refmpn_sqr (mp_ptr dst, mp_srcptr src, mp_size_t size) -{ - refmpn_mul_basecase (dst, src, size, src, size); -} - - -mp_limb_t -refmpn_gcd_1 (mp_srcptr xp, mp_size_t xsize, mp_limb_t y) -{ - mp_limb_t x; - int twos; - - ASSERT (y != 0); - ASSERT (! refmpn_zero_p (xp, xsize)); - - x = mpn_mod_1 (xp, xsize, y); - if (x == 0) - return y; - - twos = 0; - while ((x & 1) == 0 && (y & 1) == 0) - { - x >>= 1; - y >>= 1; - twos++; - } - - for (;;) - { - while ((x & 1) == 0) x >>= 1; - while ((y & 1) == 0) y >>= 1; - - if (x < y) - MP_LIMB_T_SWAP (x, y); - - x -= y; - if (x == 0) - break; - } - - return y << twos; -} - - -unsigned -refmpn_count_trailing_zeros (mp_limb_t x) -{ - unsigned n = 0; - - ASSERT (x != 0); - while ((x & 1) == 0) - { - x >>= 1; - n++; - } - return n; -} - -mp_size_t -refmpn_strip_twos (mp_ptr p, mp_size_t size) -{ - mp_size_t limbs; - unsigned shift; - - ASSERT (size >= 1); - ASSERT (! refmpn_zero_p (p, size)); - - for (limbs = 0; p[0] == 0; limbs++) - { - MPN_COPY_INCR (p, p+1, size-1); - p[size-1] = 0; - } - - shift = refmpn_count_trailing_zeros (p[0]); - if (shift) - refmpn_rshift (p, p, size, shift); - - return limbs*BITS_PER_MP_LIMB + shift; -} - -mp_limb_t -refmpn_gcd (mp_ptr gp, mp_ptr xp, mp_size_t xsize, mp_ptr yp, mp_size_t ysize) -{ - int cmp; - - ASSERT (ysize >= 1); - ASSERT (xsize >= ysize); - ASSERT ((xp[0] & 1) != 0); - ASSERT ((yp[0] & 1) != 0); - ASSERT (xp[xsize-1] != 0); - ASSERT (yp[ysize-1] != 0); - ASSERT (refmpn_overlap_fullonly_p (gp, xp, xsize)); - ASSERT (refmpn_overlap_fullonly_p (gp, yp, ysize)); - ASSERT (! MPN_OVERLAP_P (xp, xsize, yp, ysize)); - if (xsize == ysize) - ASSERT (refmpn_msbone (xp[xsize-1]) >= refmpn_msbone (yp[ysize-1])); - - refmpn_strip_twos (xp, xsize); - MPN_NORMALIZE (xp, xsize); - MPN_NORMALIZE (yp, ysize); - - for (;;) - { - cmp = refmpn_cmp_twosizes (xp, xsize, yp, ysize); - if (cmp == 0) - break; - if (cmp < 0) - MPN_PTR_SWAP (xp,xsize, yp,ysize); - - ASSERT_NOCARRY (refmpn_sub (xp, xp, xsize, yp, ysize)); - - refmpn_strip_twos (xp, xsize); - MPN_NORMALIZE (xp, xsize); - } - - refmpn_copyi (gp, xp, xsize); - return xsize; -} - - -unsigned long -refmpn_popcount (mp_srcptr sp, mp_size_t size) -{ - unsigned long count = 0; - mp_size_t i; - int j; - mp_limb_t l; - - ASSERT (size >= 0); - for (i = 0; i < size; i++) - { - l = sp[i]; - for (j = 0; j < BITS_PER_MP_LIMB; j++) - { - count += (l & 1); - l >>= 1; - } - } - return count; -} - -unsigned long -refmpn_hamdist (mp_srcptr s1p, mp_srcptr s2p, mp_size_t size) -{ - mp_ptr d; - unsigned long count; - - if (size == 0) - return 0; - - d = refmpn_malloc_limbs (size); - refmpn_xor_n (d, s1p, s2p, size); - count = refmpn_popcount (d, size); - free (d); - return count; -} diff --git a/gmp/mpn/tests/ref.h b/gmp/mpn/tests/ref.h deleted file mode 100755 index 7f4eb65..0000000 --- a/gmp/mpn/tests/ref.h +++ /dev/null @@ -1,141 +0,0 @@ -/* Prototypes for refmpn functions. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - - -#if defined (__cplusplus) -extern "C" { -#endif - -mp_limb_t refmpn_add_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -mp_limb_t refmpn_add_nc _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size, mp_limb_t carry)); -mp_limb_t refmpn_addmul_1 _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - mp_limb_t multiplier)); -mp_limb_t refmpn_addmul_1c _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - mp_limb_t multiplier, mp_limb_t carry)); -mp_limb_t refmpn_addsub_n _PROTO ((mp_ptr r1p, mp_ptr r2p, - mp_srcptr s1p, mp_srcptr s2p, - mp_size_t size)); -mp_limb_t refmpn_addsub_nc _PROTO ((mp_ptr r1p, mp_ptr r2p, - mp_srcptr s1p, mp_srcptr s2p, - mp_size_t size, mp_limb_t carry)); - -void refmpn_and_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -void refmpn_andn_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); - -int refmpn_cmp _PROTO ((mp_srcptr s1p, mp_srcptr s2p, mp_size_t size)); - -void refmpn_com_n _PROTO ((mp_ptr rp, mp_srcptr sp, mp_size_t size)); -void refmpn_copyi _PROTO ((mp_ptr rp, mp_srcptr sp, mp_size_t size)); -void refmpn_copyd _PROTO ((mp_ptr rp, mp_srcptr sp, mp_size_t size)); - -mp_limb_t refmpn_divexact_by3 _PROTO ((mp_ptr rp, mp_srcptr sp, - mp_size_t size)); -mp_limb_t refmpn_divexact_by3c _PROTO ((mp_ptr rp, mp_srcptr sp, - mp_size_t size, mp_limb_t carry)); - -mp_limb_t refmpn_divmod_1 _PROTO ((mp_ptr rp, mp_srcptr sp, mp_size_t size, - mp_limb_t divisor)); -mp_limb_t refmpn_divmod_1c _PROTO ((mp_ptr rp, mp_srcptr sp, mp_size_t size, - mp_limb_t divisor, mp_limb_t carry)); -mp_limb_t refmpn_divrem_1 _PROTO ((mp_ptr rp, mp_size_t xsize, - mp_srcptr sp, mp_size_t size, - mp_limb_t divisor)); -mp_limb_t refmpn_divrem_1c _PROTO ((mp_ptr rp, mp_size_t xsize, - mp_srcptr sp, mp_size_t size, - mp_limb_t divisor, mp_limb_t carry)); - -void refmpn_fill _PROTO ((mp_ptr p, mp_size_t s, mp_limb_t v)); - -mp_limb_t refmpn_gcd_1 _PROTO ((mp_srcptr xp, mp_size_t xsize, mp_limb_t y)); -mp_limb_t refmpn_gcd _PROTO ((mp_ptr gp, mp_ptr xp, mp_size_t xsize, - mp_ptr yp, mp_size_t ysize)); - -unsigned long refmpn_hamdist _PROTO ((mp_srcptr s1p, mp_srcptr s2p, - mp_size_t size)); - -void refmpn_ior_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -void refmpn_iorn_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); - -mp_limb_t refmpn_lshift _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - unsigned shift)); - -mp_ptr refmpn_malloc_limbs _PROTO ((mp_size_t size)); -mp_limb_t refmpn_msbone _PROTO ((mp_limb_t x)); -mp_limb_t refmpn_msbone_mask _PROTO ((mp_limb_t x)); -mp_ptr refmpn_memdup_limbs _PROTO ((mp_srcptr ptr, mp_size_t size)); - -mp_limb_t refmpn_mod_1 _PROTO ((mp_srcptr sp, mp_size_t size, - mp_limb_t divisor)); -mp_limb_t refmpn_mod_1c _PROTO ((mp_srcptr sp, mp_size_t size, - mp_limb_t divisor, mp_limb_t carry)); -mp_limb_t refmpn_mod_1_rshift _PROTO ((mp_srcptr sp, mp_size_t size, - unsigned shift, mp_limb_t divisor)); - -mp_limb_t refmpn_mul_1 _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - mp_limb_t multiplier)); -mp_limb_t refmpn_mul_1c _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - mp_limb_t multiplier, mp_limb_t carry)); - -void refmpn_mul_basecase _PROTO ((mp_ptr prodp, - mp_srcptr up, mp_size_t usize, - mp_srcptr vp, mp_size_t vsize)); -void refmpn_mul_n _PROTO ((mp_ptr prodp, mp_srcptr up, mp_srcptr vp, - mp_size_t size)); - -void refmpn_nand_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -void refmpn_nior_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); - -unsigned long refmpn_popcount _PROTO ((mp_srcptr sp, mp_size_t size)); - -mp_limb_t refmpn_rshift _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - unsigned shift)); - -void refmpn_sqr _PROTO ((mp_ptr dst, mp_srcptr src, mp_size_t size)); - -mp_limb_t refmpn_sub_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -mp_limb_t refmpn_sub_nc _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size, mp_limb_t carry)); -mp_limb_t refmpn_submul_1 _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - mp_limb_t multiplier)); -mp_limb_t refmpn_submul_1c _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size, - mp_limb_t multiplier, mp_limb_t carry)); - -void refmpn_xnor_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -void refmpn_xor_n _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); - -int refmpn_zero_p _PROTO ((mp_srcptr ptr, mp_size_t size)); - -#if defined (__cplusplus) -} -#endif diff --git a/gmp/mpn/tests/rshift.c b/gmp/mpn/tests/rshift.c deleted file mode 100755 index 9748b90..0000000 --- a/gmp/mpn/tests/rshift.c +++ /dev/null @@ -1,309 +0,0 @@ -/* -Copyright (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#if powerpc -#define CLOCK (343 M) -#else -#define CLOCK (20 M) -#endif -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 496 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - - -#ifdef MACOS -//#include -long random() -{ - //return (Random() << 16) + Random(); - return rand(); -} -#endif - - -mp_limb_t -refmpn_rshift (wp, up, usize, cnt) - register mp_ptr wp; - register mp_srcptr up; - mp_size_t usize; - register unsigned int cnt; -{ - register mp_limb_t high_limb, low_limb; - register unsigned sh_1, sh_2; - register mp_size_t i; - mp_limb_t retval; - -#ifdef DEBUG - if (usize == 0 || cnt == 0) - abort (); -#endif - - sh_1 = cnt; -#if 0 - if (sh_1 == 0) - { - if (wp != up) - { - /* Copy from low end to high end, to allow specified input/output - overlapping. */ - for (i = 0; i < usize; i++) - wp[i] = up[i]; - } - return 0; - } -#endif - - wp -= 1; - sh_2 = BITS_PER_MP_LIMB - sh_1; - high_limb = up[0]; - retval = high_limb << sh_2; - low_limb = high_limb; - - for (i = 1; i < usize; i++) - { - high_limb = up[i]; - wp[i] = (low_limb >> sh_1) | (high_limb << sh_2); - low_limb = high_limb; - } - low_limb >>= sh_1; - wp[i] = low_limb; - - return retval; -} - -#ifndef CNT -#define CNT 4 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - mp_limb_t cyx, cyy; - int i; - long t0, t; - int test; - int cnt = CNT; - mp_size_t size; - -#if GENERATING68K - SetApplLimit(GetApplLimit() - 65535); /* We need more stack */ - MaxApplZone(); -#endif - - printf("\n"); - fgets((char *)s1, SIZE, stdin); - fflush(stdout); - - srand(time(NULL)); - //qd.randSeed = TickCount(); - //test = Random(); - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#if TIMES == 1 - cnt = random () % (BITS_PER_MP_LIMB - 1) + 1; -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - mpn_random2 (s1, size); - - dx[size+1] = 0x12345678; - dy[size+1] = 0x12345678; - dx[0] = 0x87654321; - dy[0] = 0x87654321; - -#if TIMES != 1 - mpn_random (s1, size); - -#ifndef NOCHECK - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_rshift (dx+1, s1, size, cnt); - t = cputime() - t0; - printf ("refmpn_rshift: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_rshift (dx+1, s1, size, cnt); - t = cputime() - t0; - printf ("mpn_rshift: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - -#ifndef NOCHECK - mpn_random2 (s1, size); - -#ifdef PRINT - printf ("%-*d ", (int) (2 * sizeof(mp_limb_t)), cnt); mpn_print (s1, size); -#endif - - /* Put garbage in the destination. */ - for (i = 0; i < size; i++) - { - dx[i+1] = 0xdead; - dy[i+1] = 0xbeef; - } - - cyx = refmpn_rshift (dx+1, s1, size, cnt); - cyy = mpn_rshift (dy+1, s1, size, cnt); -#ifdef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[0] != 0x87654321 || dx[size+1] != 0x12345678) - { -#ifndef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - if (dy[size+1] != 0x12345678) - printf ("clobbered at high end\n"); - if (dy[0] != 0x87654321) - printf ("clobbered at low end\n"); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/spinner.c b/gmp/mpn/tests/spinner.c deleted file mode 100755 index 1fb051a..0000000 --- a/gmp/mpn/tests/spinner.c +++ /dev/null @@ -1,112 +0,0 @@ -/* A stupid little spinning wheel designed to make it look like useful work - is being done. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "config.h" - -#include -#include -#if HAVE_UNISTD_H -#include /* for isatty */ -#endif - -#include "gmp.h" -#include "gmp-impl.h" - -#include "try.h" - - -/* An application can update this to get a count printed with the spinner. - If left at 0, no count is printed. */ - -unsigned long spinner_count = 0; - - -static int spinner_wanted = -1; /* -1 uninitialized, 1 wanted, 0 not */ -static int spinner_tick = 1; /* 1 ready to print, 0 not */ - - -/*ARGSUSED*/ -void -spinner_signal (int signum) -{ - spinner_tick = 1; - - if (signal (SIGALRM, spinner_signal) == SIG_ERR) abort (); - alarm (1); -} - - -/* Initialize the spinner. - - This is done the first time spinner() is called, so an application - doesn't need to call this directly. - - The spinner is only wanted if the output is a tty. */ - -#define SPINNER_WANTED_INIT() \ - if (spinner_wanted < 0) spinner_init () - -void -spinner_init (void) -{ - spinner_wanted = isatty (fileno (stdout)); - if (spinner_wanted == -1) - abort (); - - if (!spinner_wanted) - return; - - if (signal (SIGALRM, spinner_signal) == SIG_ERR) abort (); - alarm (1); -} - - -void -spinner (void) -{ - static const char data[] = { '|', '/', '-', '\\' }; - static int pos = 0; - - char buf[128]; - - SPINNER_WANTED_INIT (); - - if (spinner_tick) - { - buf[0] = data[pos]; - pos = (pos + 1) % numberof (data); - spinner_tick = 0; - - if (spinner_count != 0) - { - sprintf (buf+1, " %lu\r", spinner_count); - } - else - { - buf[1] = '\r'; - buf[2] = '\0'; - } - fputs (buf, stdout); - } -} diff --git a/gmp/mpn/tests/sub_n.c b/gmp/mpn/tests/sub_n.c deleted file mode 100755 index ce9ad67..0000000 --- a/gmp/mpn/tests/sub_n.c +++ /dev/null @@ -1,257 +0,0 @@ -/* -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 328 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - - -mp_limb_t -#if __STDC__ -refmpn_sub_n (mp_ptr res_ptr, - mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) -#else -refmpn_sub_n (res_ptr, s1_ptr, s2_ptr, size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_srcptr s2_ptr; - mp_size_t size; -#endif -{ - register mp_limb_t x, y, cy; - register mp_size_t j; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - s2_ptr -= j; - res_ptr -= j; - - cy = 0; - do - { - y = s2_ptr[j]; - x = s1_ptr[j]; - y += cy; /* add previous carry to subtrahend */ - cy = (y < cy); /* get out carry from that addition */ - y = x - y; /* main subtract */ - cy = (y > x) + cy; /* get out carry from the subtract, combine */ - res_ptr[j] = y; - } - while (++j != 0); - - return cy; -} - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t s2[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - int cyx, cyy; - int i; - long t0, t; - int test; - mp_size_t size; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - - dx[0] = 0x87654321; - dy[0] = 0x87654321; - dx[size+1] = 0x12345678; - dy[size+1] = 0x12345678; - -#if TIMES != 1 - mpn_random (s1, size); - mpn_random (s2, size); - -#ifndef NOCHECK - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_sub_n (dx+1, s1, s2, size); - t = cputime() - t0; - printf ("refmpn_sub_n: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_sub_n (dx+1, s1, s2, size); - t = cputime() - t0; - printf ("mpn_sub_n: %5ldms (%.2f cycles/limb)\n", - t, ((double) t * CLOCK) / (OPS * 1000.0)); -#endif - -#ifndef NOCHECK - mpn_random2 (s1, size); - mpn_random2 (s2, size); - -#ifdef PRINT - mpn_print (s1, size); - mpn_print (s2, size); -#endif - - /* Put garbage in the destination. */ - for (i = 0; i < size; i++) - { - dx[i+1] = 0xdead; - dy[i+1] = 0xbeef; - } - - cyx = refmpn_sub_n (dx+1, s1, s2, size); - cyy = mpn_sub_n (dy+1, s1, s2, size); -#ifdef PRINT - printf ("%d ", cyx); mpn_print (dx+1, size); - printf ("%d ", cyy); mpn_print (dy+1, size); -#endif - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[0] != 0x87654321 || dx[size+1] != 0x12345678) - { -#ifndef PRINT - printf ("%d ", cyx); mpn_print (dx+1, size); - printf ("%d ", cyy); mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/submul_1.c b/gmp/mpn/tests/submul_1.c deleted file mode 100755 index b564f18..0000000 --- a/gmp/mpn/tests/submul_1.c +++ /dev/null @@ -1,265 +0,0 @@ -/* -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) -#include - -int -cputime () -{ - if (CLOCKS_PER_SEC < 100000) - return clock () * 1000 / CLOCKS_PER_SEC; - return clock () / (CLOCKS_PER_SEC / 1000); -} -#else -#include -#include -#if !defined MACOS -#include - -int -cputime () -{ - struct rusage rus; - - getrusage (0, &rus); - return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; -} -#else -#include -int -cputime () -{ - UnsignedWide msecs; - - Microseconds (&msecs); - return(int)(*(long long *)&msecs / 1000); -} - -#endif -#endif - -#define M * 1000000 - -#ifndef CLOCK -#if defined (__m88k__) -#define CLOCK 20 M -#elif defined (__i386__) -#define CLOCK (16666667) -#elif defined (__m68k__) -#define CLOCK (20 M) -#elif defined (_IBMR2) -#define CLOCK (25 M) -#elif defined (__sparc__) -#define CLOCK (20 M) -#elif defined (__sun__) -#define CLOCK (20 M) -#elif defined (__mips) -#define CLOCK (40 M) -#elif defined (__hppa__) -#define CLOCK (50 M) -#elif defined (__alpha) -#define CLOCK (133 M) -#elif defined (MACOS) -#define CLOCK (343 M) -#else -#error "Don't know CLOCK of your machine" -#endif -#endif - -#ifndef OPS -#define OPS (CLOCK/5) -#endif -#ifndef SIZE -#define SIZE 496 -#endif -#ifndef TIMES -#define TIMES OPS/SIZE -#else -#undef OPS -#define OPS (SIZE*TIMES) -#endif - -mp_limb_t -refmpn_submul_1 (res_ptr, s1_ptr, s1_size, s2_limb) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - mp_size_t s1_size; - register mp_limb_t s2_limb; -{ - register mp_limb_t cy_limb; - register mp_size_t j; - register mp_limb_t prod_high, prod_low; - register mp_limb_t x; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -s1_size; - - /* Offset the base pointers to compensate for the negative indices. */ - res_ptr -= j; - s1_ptr -= j; - - cy_limb = 0; - do - { - umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb); - - prod_low += cy_limb; - cy_limb = (prod_low < cy_limb) + prod_high; - - x = res_ptr[j]; - prod_low = x - prod_low; - cy_limb += (prod_low > x); - res_ptr[j] = prod_low; - } - while (++j != 0); - - return cy_limb; -} - -main (argc, argv) - int argc; - char **argv; -{ - mp_limb_t s1[SIZE]; - mp_limb_t dx[SIZE+2]; - mp_limb_t dy[SIZE+2]; - mp_limb_t cyx, cyy; - int i; - long t0, t; - int test; - mp_limb_t xlimb; - mp_size_t size; - double cyc; - - for (test = 0; ; test++) - { -#if TIMES == 1 && ! defined (PRINT) - if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) - { - printf ("\r%d", test); - fflush (stdout); - } -#endif - -#ifdef RANDOM - size = random () % SIZE + 1; -#else - size = SIZE; -#endif - - dy[size+1] = 0x12345678; - dy[0] = 0x87654321; - - mpn_random2 (&xlimb, 1); - -#if TIMES != 1 - mpn_random (s1, size); - mpn_random (dy+1, size); - -#ifndef NOCHECK - MPN_COPY (dx, dy, size+2); - t0 = cputime(); - for (i = 0; i < TIMES; i++) - refmpn_submul_1 (dx+1, s1, size, xlimb); - t = cputime() - t0; - cyc = ((double) t * CLOCK) / (OPS * 1000.0); - printf ("refmpn_submul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n", - t, cyc, - CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9); -#endif - - MPN_COPY (dx, dy, size+2); - t0 = cputime(); - for (i = 0; i < TIMES; i++) - mpn_submul_1 (dx+1, s1, size, xlimb); - t = cputime() - t0; - cyc = ((double) t * CLOCK) / (OPS * 1000.0); - printf ("mpn_submul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n", - t, cyc, - CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9); -#endif - - mpn_random2 (s1, size); - mpn_random2 (dy+1, size); -#if defined (PRINT) || defined (XPRINT) - printf ("xlimb="); - mpn_print (&xlimb, 1); -#endif -#ifdef PRINT - mpn_print (dy+1, size); - mpn_print (s1, size); -#endif - - MPN_COPY (dx, dy, size+2); - cyx = refmpn_submul_1 (dx+1, s1, size, xlimb); - cyy = mpn_submul_1 (dy+1, s1, size, xlimb); - -#ifdef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - -#ifndef NOCHECK - if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 - || dx[size+1] != 0x12345678 || dx[0] != 0x87654321) - { -#ifndef PRINT - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); - mpn_print (dx+1, size); - printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); - mpn_print (dy+1, size); -#endif - printf ("TEST NUMBER %d\n", test); - abort(); - } -#endif - } -} - -mpn_print (mp_ptr p, mp_size_t size) -{ - mp_size_t i; - - for (i = size - 1; i >= 0; i--) - { -#ifdef _LONG_LONG_LIMB - printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), - (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), - (int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); -#else - printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); -#endif -#ifdef SPACE - if (i != 0) - printf (" "); -#endif - } - puts (""); -} diff --git a/gmp/mpn/tests/trace.c b/gmp/mpn/tests/trace.c deleted file mode 100755 index a701833..0000000 --- a/gmp/mpn/tests/trace.c +++ /dev/null @@ -1,206 +0,0 @@ -/* trace.c -- Support for diagnostic traces. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "try.h" - - -/* Number base for the various trace printing routines. - Set this in main() or with the debugger. - If hexadecimal is going to be fed into GNU bc, remember to use -16 - because bc requires upper case. */ - -int mp_trace_base = 10; - - -/* Print "name=value\n" to stdout for an mpq_t value. */ -void -mpq_trace (const char *name, mpq_srcptr q) -{ - if (name != NULL && name[0] != '\0') - printf ("%s=", name); - - switch (ABS (mp_trace_base)) { - case 8: printf ("oct"); break; - case 10: break; - case 16: printf ("0x"); break; - default: printf ("base%d:", ABS (mp_trace_base)); break; - } - - mpq_out_str (stdout, mp_trace_base, q); - - /* It's not very interesting to know when numbers are unnormalized. - mpz's should always be and ought to be checked with ASSERT() if in doubt. - mpn's can often be unnormalized without affecting anything. */ - /* if (!mpq_normalized_p (z)) printf (" (unnorm)"); */ - - printf ("\n"); -} - - -/* Print "name=value\n" to stdout for an mpz_t value. */ -void -mpz_trace (const char *name, mpz_srcptr z) -{ - mpq_t q; - mpz_t one; - mp_limb_t one_limb; - - PTR(one) = &one_limb; - SIZ(one) = 1; - one_limb = 1; - - q->_mp_num = *z; - q->_mp_den = *one; - - mpq_trace(name, q); -} - - -/* Print "namenum=value\n" to stdout for an mpz_t value. - "name" should have a "%d" to get the number. */ -void -mpz_tracen (const char *name, int num, mpz_srcptr z) -{ - if (name != NULL && name[0] != '\0') - { - printf (name, num); - putchar ('='); - } - mpz_trace (NULL, z); -} - - -/* Print "name=value\n" to stdout for an mpn style ptr,size. */ -void -mpn_trace (const char *name, mp_srcptr ptr, mp_size_t size) -{ - mpz_t z; - MPN_NORMALIZE (ptr, size); - PTR(z) = (mp_ptr) ptr; - SIZ(z) = (int) size; - mpz_trace (name, z); -} - - -/* Print "namenum=value\n" to stdout for an mpn style ptr,size. - "name" should have a "%d" to get the number. */ -void -mpn_tracen (const char *name, int num, mp_srcptr ptr, mp_size_t size) -{ - if (name != NULL && name[0] != '\0') - { - printf (name, num); - putchar ('='); - } - mpn_trace (NULL, ptr, size); -} - - -/* Print "namenum=value\n" to stdout for an array of mpn style ptr,size. - - "a" is an array of pointers, each a[i] is a pointer to "size" many limbs. - The formal parameter isn't mp_srcptr because that causes compiler - warnings, but the values aren't modified. - - "name" should have a printf style "%d" to get the array index. */ - -void -mpn_tracea (const char *name, const mp_ptr *a, int count, mp_size_t size) -{ - int i; - for (i = 0; i < count; i++) - mpn_tracen (name, i, a[i], size); -} - - -/* Print "value\n" to a file for an mpz_t value. Any previous contents of - the file are overwritten, so you need different file names each time this - is called. - - Overwriting the file is a feature, it means you get old data replaced - when you run a test program repeatedly. */ - -void -mpn_trace_file (const char *filename, mp_srcptr ptr, mp_size_t size) -{ - FILE *fp; - mpz_t z; - - fp = fopen (filename, "w"); - if (fp == NULL) - { - perror ("fopen"); - abort(); - } - - MPN_NORMALIZE (ptr, size); - PTR(z) = (mp_ptr) ptr; - SIZ(z) = (int) size; - - mpz_out_str (fp, mp_trace_base, z); - fprintf (fp, "\n"); - - if (ferror (fp) || fclose (fp) != 0) - { - printf ("error writing %s\n", filename); - abort(); - } -} - - -/* Print "value\n" to a set of files, one file for each element of the given - array of mpn style ptr,size. Any previous contents of the files are - overwritten, so you need different file names each time this is called. - Each file is "filenameN" where N is 0 to count-1. - - "a" is an array of pointers, each a[i] is a pointer to "size" many limbs. - The formal parameter isn't mp_srcptr because that causes compiler - warnings, but the values aren't modified. - - Overwriting the files is a feature, it means you get old data replaced - when you run a test program repeatedly. The output style isn't - particularly pretty, but at least it gets something out, and you can cat - the files into bc, or whatever. */ - -void -mpn_tracea_file (const char *filename, - const mp_ptr *a, int count, mp_size_t size) -{ - char *s; - int i; - TMP_DECL (marker); - - TMP_MARK (marker); - s = (char *) TMP_ALLOC (strlen (filename) + 50); - - for (i = 0; i < count; i++) - { - sprintf (s, "%s%d", filename, i); - mpn_trace_file (s, a[i], size); - } - - TMP_FREE (marker); -} diff --git a/gmp/mpn/tests/try.c b/gmp/mpn/tests/try.c deleted file mode 100755 index 3ba893a..0000000 --- a/gmp/mpn/tests/try.c +++ /dev/null @@ -1,1517 +0,0 @@ -/* Run some tests on various mpn routines. - - THIS IS A TEST PROGRAM USED ONLY FOR DEVELOPMENT. IT'S ALMOST CERTAIN TO - BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE VERSIONS OF GMP. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - - -/* Usage: try [options] ... - - For example, "./try mpn_add_n" to run tests of that function. - - Combinations of alignments and overlaps are tested, with redzones above - or below the destinations, and with the sources write-protected. - - The number of tests performed becomes ridiculously large with all the - combinations, and for that reason this can't be a part of a "make check", - it's meant only for development. The code isn't very pretty either. - - During development it can help to disable the redzones, since seeing the - rest of the destination written can show where the wrong part is, or if - the dst pointers are off by 1 or whatever. The magic DEADVAL initial - fill (see below) will show locations never written. - - The -s option can be used to test only certain size operands, which is - useful if some new code doesn't yet support say sizes less than the - unrolling, or whatever. - - When a problem occurs it'll of course be necessary to run the program - under gdb to find out quite where, how and why it's going wrong. Disable - the spinner with the -W option when doing this, or single stepping won't - work. Using -1 to run with simple data can be useful. - - New functions to test can be added by defining a TRY_TYPE_, adding an - entry to try_array[] and adding a call to the call() function (if the - type isn't already supported). Extra TRY_TYPE_ bits can be easily added - if necessary. - - - Future: - - Automatically detect gdb and disable the spinner timer (use -W for now). - - Make a way to re-run a failing case in the debugger. Have an option to - snapshot each test case before it's run so the data is available if a - segv occurs. (This should be more reliable than the current print_all() - in the signal handler.) - - When alignment means a dst isn't hard against the redzone, check the - space in between remains unchanged. - - See if the 80x86 debug registers can do redzones on byte boundaries. - - When a source overlaps a destination, don't run both s[i].high 0 and 1, - as s[i].high has no effect. Maybe encode s[i].high into overlap->s[i]. - - When partial overlaps aren't done, don't loop over source alignments - during overlaps. - -*/ - - -/* always do assertion checking */ -#define WANT_ASSERT 1 - -#include "config.h" - -#if HAVE_GETOPT_H -#include /* for getopt_long() */ -#endif -#include -#include -#include -#include -#include -#include -#include -/*#include */ - -#include "gmp.h" -#include "gmp-impl.h" - -#include "ref.h" -#include "try.h" - -#if HAVE_SPA_EXTRAS -#include "spa-out.asm.h" -#endif - -#if !HAVE_DECL_OPTARG -extern char *optarg; -extern int optind, opterr; -#endif - - -#define DEFAULT_REPETITIONS 10 - -int option_repetitions = DEFAULT_REPETITIONS; -int option_spinner = 1; -int option_redzones = 1; -int option_firstsize = 0; -int option_lastsize = 500; -int option_firstsize2 = 0; - -#define ALIGNMENTS 4 -#define OVERLAPS 4 -#define CARRY_RANDOMS 5 -#define MULTIPLIER_RANDOMS 5 -#define DIVISOR_RANDOMS 5 -#define XSIZE_COUNT 4 - -int option_print = 0; - -#define DATA_TRAND 0 -#define DATA_ZEROS 1 -#define DATA_SEQ 2 -#define DATA_FFS 3 -#define DATA_2FD 4 -int option_data = DATA_TRAND; - - -mp_size_t pagesize; -#define PAGESIZE_LIMBS (pagesize / BYTES_PER_MP_LIMB) - -/* must be a multiple of the page size */ -#define REDZONE_BYTES (pagesize * 16) -#define REDZONE_LIMBS (REDZONE_BYTES / BYTES_PER_MP_LIMB) - - -#define MAX3(x,y,z) (MAX (x, MAX (y, z))) - -#if BITS_PER_MP_LIMB == 32 -#define DEADVAL CNST_LIMB(0xDEADBEEF) -#else -#define DEADVAL CNST_LIMB(0xDEADBEEFBADDCAFE) -#endif - - -#define TRY_RETVAL (1<<0) -#define TRY_SIZE2 (1<<1) -#define TRY_SHIFT (1<<2) -#define TRY_CARRYBIT (1<<3) -#define TRY_CARRY3 (1<<4) -#define TRY_CARRY4 (1<<4) -#define TRY_CARRYLIMB (1<<5) -#define TRY_MULTIPLIER (1<<6) -#define TRY_DIVISOR (1<<7) -#define TRY_DOUBLE_DST (1<<8) -#define TRY_DST0_INIT (1<<9) -#define TRY_XSIZE (1<<10) -#define TRY_SIZE_ZERO (1<<11) -#define TRY_DST_SIZE_RETVAL (1<<12) -#define TRY_SRC1_GCDDATA (1<<13) - -#define TRY_OVERLAP_LOW_TO_HIGH (1<<15) /* Default is allow full overlap. */ -#define TRY_OVERLAP_HIGH_TO_LOW (1<<16) -#define TRY_OVERLAP_NONE (1<<17) -#define TRY_OVERLAP_NOTSRCS (1<<18) - -#define TRY_SRC0 (1<<20) -#define TRY_SRC1 (TRY_SRC0 << 1) - -#define TRY_DST0 (1<<24) -#define TRY_DST1 (TRY_DST0 << 1) - - -#define TRY_SRC(n) (TRY_SRC0 << (n)) -#define TRY_DST(n) (TRY_DST0 << (n)) - -#define TRY_CARRYANY (TRY_CARRYBIT | TRY_CARRY3 | TRY_CARRY4 | TRY_CARRYLIMB) - - -#define TRY_TYPE_AORS_N (TRY_RETVAL | TRY_DST0 | TRY_SRC0 | TRY_SRC1) -#define TRY_TYPE_AORS_NC (TRY_TYPE_AORS_N | TRY_CARRYBIT) - -#define TRY_TYPE_AORSMUL_1 (TRY_TYPE_MUL_1 | TRY_DST0_INIT) -#define TRY_TYPE_AORSMUL_1C (TRY_TYPE_MUL_1C | TRY_DST0_INIT) - -#define TRY_TYPE_LOGOPS_N (TRY_DST0 | TRY_SRC0 | TRY_SRC1) - -#define TRY_TYPE_ADDSUB_N \ - (TRY_RETVAL | TRY_DST0 | TRY_DST1 | TRY_SRC0 | TRY_SRC1) -#define TRY_TYPE_ADDSUB_NC \ - (TRY_TYPE_ADDSUB_N | TRY_CARRY4) - -#define TRY_TYPE_COPYI \ - (TRY_DST0 | TRY_SRC0 | TRY_OVERLAP_LOW_TO_HIGH | TRY_SIZE_ZERO) -#define TRY_TYPE_COPYD \ - (TRY_DST0 | TRY_SRC0 | TRY_OVERLAP_HIGH_TO_LOW | TRY_SIZE_ZERO) -#define TRY_TYPE_COM_N (TRY_DST0 | TRY_SRC0) - -#define TRY_TYPE_MOD_1 (TRY_RETVAL | TRY_SRC0 | TRY_DIVISOR | TRY_SIZE_ZERO) -#define TRY_TYPE_MOD_1C (TRY_TYPE_MOD_1 | TRY_CARRYLIMB) -#define TRY_TYPE_DIVMOD_1 (TRY_TYPE_MOD_1 | TRY_DST0) -#define TRY_TYPE_DIVMOD_1C (TRY_TYPE_MOD_1C | TRY_DST0) -#define TRY_TYPE_DIVREM_1 (TRY_TYPE_DIVMOD_1 | TRY_XSIZE) -#define TRY_TYPE_DIVREM_1C (TRY_TYPE_DIVMOD_1C | TRY_XSIZE) -#define TRY_TYPE_MOD_1_RSHIFT (TRY_RETVAL | TRY_SRC0 | TRY_SHIFT | TRY_DIVISOR) - -#define TRY_TYPE_DIVEXACT_BY3 (TRY_RETVAL | TRY_DST0 | TRY_SRC0) -#define TRY_TYPE_DIVEXACT_BY3C (TRY_TYPE_DIVEXACT_BY3 | TRY_CARRY3) - -#define TRY_TYPE_GCD_1 (TRY_RETVAL | TRY_SRC0 | TRY_DIVISOR) -#define TRY_TYPE_GCD \ - (TRY_RETVAL | TRY_DST0 | TRY_SRC0 | TRY_SRC1 | TRY_SIZE2 \ - | TRY_DST_SIZE_RETVAL | TRY_OVERLAP_NOTSRCS | TRY_SRC1_GCDDATA) - -#define TRY_TYPE_MUL_1 (TRY_RETVAL | TRY_DST0 | TRY_SRC0 | TRY_MULTIPLIER) -#define TRY_TYPE_MUL_1C (TRY_TYPE_MUL_1 | TRY_CARRYLIMB) - -#define TRY_TYPE_MUL_BASECASE \ - (TRY_DST0 | TRY_SRC0 | TRY_SRC1 | TRY_SIZE2 | TRY_OVERLAP_NONE) -#define TRY_TYPE_MUL_N \ - (TRY_DST0 | TRY_SRC0 | TRY_SRC1 | TRY_DOUBLE_DST | TRY_OVERLAP_NONE) -#define TRY_TYPE_SQR \ - (TRY_DST0 | TRY_SRC0 | TRY_DOUBLE_DST | TRY_OVERLAP_NONE) - -#define TRY_TYPE_RSHIFT \ - (TRY_RETVAL | TRY_DST0 | TRY_SRC0 | TRY_SHIFT | TRY_OVERLAP_LOW_TO_HIGH) -#define TRY_TYPE_LSHIFT \ - (TRY_RETVAL | TRY_DST0 | TRY_SRC0 | TRY_SHIFT | TRY_OVERLAP_HIGH_TO_LOW) - -#define TRY_TYPE_POPCOUNT (TRY_RETVAL | TRY_SRC0 | TRY_SIZE_ZERO) -#define TRY_TYPE_HAMDIST (TRY_TYPE_POPCOUNT | TRY_SRC1) - - -/* The following are macros if there's no native versions, so wrap them in - functions that can be in try_array[]. */ - -void -MPN_COPY_INCR_fun (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ MPN_COPY_INCR (rp, sp, size); } - -void -MPN_COPY_DECR_fun (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ MPN_COPY_DECR (rp, sp, size); } - -void -mpn_com_n_fun (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ mpn_com_n (rp, sp, size); } - -void -mpn_and_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_and_n (rp, s1, s2, size); } - -void -mpn_andn_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_andn_n (rp, s1, s2, size); } - -void -mpn_nand_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_nand_n (rp, s1, s2, size); } - -void -mpn_ior_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_ior_n (rp, s1, s2, size); } - -void -mpn_iorn_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_iorn_n (rp, s1, s2, size); } - -void -mpn_nior_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_nior_n (rp, s1, s2, size); } - -void -mpn_xor_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_xor_n (rp, s1, s2, size); } - -void -mpn_xnor_n_fun (mp_ptr rp, mp_srcptr s1, mp_srcptr s2, mp_size_t size) -{ mpn_xnor_n (rp, s1, s2, size); } - -void -mpn_divexact_by3_fun (mp_ptr rp, mp_srcptr sp, mp_size_t size) -{ mpn_divexact_by3 (rp, sp, size); } - - -struct try_t { - struct try_one_t { - tryfun_t function; - const char *name; - } ref, fun; - int flag; - mp_size_t minsize; -}; - -#if HAVE_STRINGIZE -#define TRY(fun) { (tryfun_t) fun, #fun } -#define TRY_FUNFUN(fun) { (tryfun_t) fun##_fun, #fun } -#else -#define TRY(fun) { (tryfun_t) fun, "fun" } -#define TRY_FUNFUN(fun) { (tryfun_t) fun/**/_fun, "fun" } -#endif - -struct try_t try_array[] = { - { TRY(refmpn_add_n), TRY(mpn_add_n), TRY_TYPE_AORS_N }, - { TRY(refmpn_sub_n), TRY(mpn_sub_n), TRY_TYPE_AORS_N }, -#if HAVE_NATIVE_mpn_add_nc - { TRY(refmpn_add_nc), TRY(mpn_add_nc), TRY_TYPE_AORS_NC }, -#endif -#if HAVE_NATIVE_mpn_sub_nc - { TRY(refmpn_sub_nc), TRY(mpn_sub_nc), TRY_TYPE_AORS_NC }, -#endif - - { TRY(refmpn_addmul_1), TRY(mpn_addmul_1), TRY_TYPE_AORSMUL_1 }, - { TRY(refmpn_submul_1), TRY(mpn_submul_1), TRY_TYPE_AORSMUL_1 }, -#if HAVE_NATIVE_mpn_addmul_1c - { TRY(refmpn_addmul_1c), TRY(mpn_addmul_1c), TRY_TYPE_AORSMUL_1C }, -#endif -#if HAVE_NATIVE_mpn_submul_1c - { TRY(refmpn_submul_1c), TRY(mpn_submul_1c), TRY_TYPE_AORSMUL_1C }, -#endif - -/* { TRY(refmpn_com_n), TRY_FUNFUN(mpn_com_n), TRY_TYPE_COM_N },*/ - - { TRY(refmpn_copyi), TRY_FUNFUN(MPN_COPY_INCR), TRY_TYPE_COPYI }, - { TRY(refmpn_copyd), TRY_FUNFUN(MPN_COPY_DECR), TRY_TYPE_COPYD }, - - { TRY(refmpn_and_n), TRY_FUNFUN(mpn_and_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_andn_n), TRY_FUNFUN(mpn_andn_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_nand_n), TRY_FUNFUN(mpn_nand_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_ior_n), TRY_FUNFUN(mpn_ior_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_iorn_n), TRY_FUNFUN(mpn_iorn_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_nior_n), TRY_FUNFUN(mpn_nior_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_xor_n), TRY_FUNFUN(mpn_xor_n), TRY_TYPE_LOGOPS_N }, - { TRY(refmpn_xnor_n), TRY_FUNFUN(mpn_xnor_n), TRY_TYPE_LOGOPS_N }, - - { TRY(refmpn_divrem_1), TRY(mpn_divrem_1), TRY_TYPE_DIVREM_1 }, - { TRY(refmpn_mod_1), TRY(mpn_mod_1), TRY_TYPE_MOD_1 }, - { TRY(refmpn_mod_1_rshift), TRY(mpn_mod_1_rshift), TRY_TYPE_MOD_1_RSHIFT }, -#if HAVE_NATIVE_mpn_divrem_1c - { TRY(refmpn_divrem_1c), TRY(mpn_divrem_1c), TRY_TYPE_DIVREM_1C }, -#endif -#if HAVE_NATIVE_mpn_mod_1c - { TRY(refmpn_mod_1c), TRY(mpn_mod_1c), TRY_TYPE_MOD_1C }, -#endif - { TRY(refmpn_divexact_by3), TRY_FUNFUN(mpn_divexact_by3), - TRY_TYPE_DIVEXACT_BY3 }, - { TRY(refmpn_divexact_by3c),TRY(mpn_divexact_by3c),TRY_TYPE_DIVEXACT_BY3C }, - - { TRY(refmpn_mul_1), TRY(mpn_mul_1), TRY_TYPE_MUL_1 }, -#if HAVE_NATIVE_mpn_mul_1c - { TRY(refmpn_mul_1c), TRY(mpn_mul_1c), TRY_TYPE_MUL_1C }, -#endif - - { TRY(refmpn_rshift), TRY(mpn_rshift), TRY_TYPE_RSHIFT }, - { TRY(refmpn_lshift), TRY(mpn_lshift), TRY_TYPE_LSHIFT }, - - - { TRY(refmpn_mul_basecase), TRY(mpn_mul_basecase), TRY_TYPE_MUL_BASECASE }, - { TRY(refmpn_sqr), TRY(mpn_sqr_basecase), TRY_TYPE_SQR }, - - { TRY(refmpn_mul_basecase), TRY(mpn_mul), TRY_TYPE_MUL_BASECASE }, - { TRY(refmpn_mul_n), TRY(mpn_mul_n), TRY_TYPE_MUL_N }, - { TRY(refmpn_sqr), TRY(mpn_sqr_n), TRY_TYPE_SQR }, - - { TRY(refmpn_gcd_1), TRY(mpn_gcd_1), TRY_TYPE_GCD_1 }, - { TRY(refmpn_gcd), TRY(mpn_gcd), TRY_TYPE_GCD }, - - { TRY(refmpn_popcount), TRY(mpn_popcount), TRY_TYPE_POPCOUNT }, - { TRY(refmpn_hamdist), TRY(mpn_hamdist), TRY_TYPE_HAMDIST }, - -#if 0 - /* need wrapper functions since they take workspace arguments */ - { TRY(refmpn_mul_n), TRY_FUNFUN(mpn_kara_mul_n), TRY_TYPE_MUL_N, - MPN_KARA_MINSIZE}, - { TRY(refmpn_sqr), TRY_FUNFUN(mpn_kara_sqr_n), TRY_TYPE_SQR, - MPN_KARA_MINSIZE}, - { TRY(refmpn_mul_n), TRY_FUNFUN(mpn_toom3_mul_n), TRY_TYPE_MUL_N, - MPN_TOOM3_MINSIZE}, - { TRY(refmpn_sqr), TRY_FUNFUN(mpn_toom3_sqr_n), TRY_TYPE_SQR, - MPN_TOOM3_MINSIZE }, -#endif - -#if HAVE_SPA_EXTRAS -#include "spa-out.t-table.i" -#endif -}; - -struct try_t *tr = &try_array[0]; - - -struct region_t { - mp_ptr ptr; - mp_size_t size; -}; - - -#define TRAP_NOWHERE 0 -#define TRAP_REF 1 -#define TRAP_FUN 2 -#define TRAP_SETUPS 3 -int trap_location = TRAP_NOWHERE; - - -/* Find least significant limb position where p1,size and p2,size differ. */ -mp_size_t -mpn_diff_lowest (mp_srcptr p1, mp_srcptr p2, mp_size_t size) -{ - mp_size_t i; - - for (i = 0; i < size; i++) - if (p1[i] != p2[i]) - return i; - - /* no differences */ - return -1; -} - - -/* Find most significant limb position where p1,size and p2,size differ. */ -mp_size_t -mpn_diff_highest (mp_srcptr p1, mp_srcptr p2, mp_size_t size) -{ - mp_size_t i; - - for (i = size-1; i >= 0; i--) - if (p1[i] != p2[i]) - return i; - - /* no differences */ - return -1; -} - - -/* Return p advanced to the next multiple of "align" bytes. "align" must be - a power of 2. Care is taken not to assume sizeof(int)==sizeof(pointer). */ -void * -align_pointer (void *p, size_t align) -{ - unsigned d; - d = ((unsigned) p) & (align-1); - d = (d != 0 ? align-d : 0); - return (void *) (((char *) p) + d); -} - -/* malloc n limbs on a multiple of m bytes boundary */ -mp_ptr -malloc_limbs_aligned (size_t n, size_t m) -{ - return (mp_ptr) align_pointer (refmpn_malloc_limbs (n + m-1), m); -} - -void -mprotect_maybe (void *addr, size_t len, int prot) -{ - if (!option_redzones) - return; - - if (mprotect (addr, len, prot) != 0) - { - fprintf (stderr, "Cannot mprotect %p 0x%X 0x%X\n", addr, len, prot); - exit (1); - } -} - -/* round "a" up to a multiple of "m" */ -size_t -round_up_multiple (size_t a, size_t m) -{ - unsigned long r; - - r = a % m; - if (r == 0) - return a; - else - return a + (m - r); -} - -void -malloc_region (struct region_t *r, mp_size_t n) -{ - mp_ptr p; - - ASSERT ((pagesize % BYTES_PER_MP_LIMB) == 0); - - r->size = round_up_multiple (n, PAGESIZE_LIMBS); - p = malloc_limbs_aligned (r->size + REDZONE_LIMBS*2, pagesize); - mprotect_maybe (p, REDZONE_BYTES, PROT_NONE); - - r->ptr = p + REDZONE_LIMBS; - mprotect_maybe (r->ptr + r->size, REDZONE_BYTES, PROT_NONE); -} - -void -mprotect_region (const struct region_t *r, int prot) -{ - mprotect_maybe (r->ptr, r->size, prot); -} - - -#define NUM_SOURCES 2 -#define NUM_DESTS 2 - -struct source_t { - struct region_t region; - int high; - mp_size_t align; - mp_ptr p; -}; - -struct source_t s[NUM_SOURCES]; - -struct dest_t { - int high; - mp_size_t align; -}; - -struct dest_t d[NUM_SOURCES]; - -struct source_each_t { - mp_ptr p; -}; - -struct dest_each_t { - struct region_t region; - mp_ptr p; -}; - -mp_size_t size; -mp_size_t size2; -mp_size_t dsize; -unsigned long shift; - -struct each_t { - const char *name; - struct dest_each_t d[numberof(d)]; - struct source_each_t s[numberof(s)]; - mp_limb_t retval; -}; - -struct each_t ref = { "Ref" }; -struct each_t fun = { "Fun" }; - -#define SRC_SIZE(n) \ - ((n) == 1 && (tr->flag & (TRY_SIZE2|TRY_XSIZE)) ? size2 : size) - - -/* First four entries must be 0,1,2,3 for TRY_CARRYBIT, TRY_CARRY3, and - TRY_CARRY4 */ -mp_limb_t carry_array[] = { - 0, 1, 2, 3, - 4, - (mp_limb_t) 1 << 8, - (mp_limb_t) 1 << 16, - (mp_limb_t) -1 -}; -mp_limb_t carry; -int carry_index; - -#define CARRY_COUNT \ - ((tr->flag & TRY_CARRYBIT) ? 2 \ - : (tr->flag & TRY_CARRY3) ? 3 \ - : (tr->flag & TRY_CARRY4) ? 4 \ - : (tr->flag & TRY_CARRYLIMB) ? numberof(carry_array) + CARRY_RANDOMS \ - : 1) - -#define MPN_RANDOM_ALT(index,dst,size) \ - (((index) & 1) ? mpn_random (dst, size) : mpn_random2 (dst, size)) - -/* The dummy value after MPN_RANDOM_ALT ensures both sides of the ":" have - the same type */ -#define CARRY_ITERATION \ - for (carry_index = 0; \ - (carry_index < numberof (carry_array) \ - ? (carry = carry_array[carry_index]) \ - : (MPN_RANDOM_ALT (carry_index, &carry, 1), (mp_limb_t) 0)), \ - carry_index < CARRY_COUNT; \ - carry_index++) - - -mp_limb_t multiplier_array[] = { - 0, 1, 2, 3, - (mp_limb_t) 1 << 8, - (mp_limb_t) 1 << 16, - (mp_limb_t) -3, - (mp_limb_t) -2, - (mp_limb_t) -1, -}; -mp_limb_t multiplier; -int multiplier_index; - -mp_limb_t divisor_array[] = { - 1, 2, 3, - (mp_limb_t) 1 << 8, - (mp_limb_t) 1 << 16, - (mp_limb_t) -3, - (mp_limb_t) -2, - (mp_limb_t) -1, -}; - -mp_limb_t divisor; -int divisor_index; - -/* The dummy value after MPN_RANDOM_ALT ensures both sides of the ":" have - the same type */ -#define ARRAY_ITERATION(var, index, limit, array, randoms, cond) \ - for (index = 0; \ - (index < numberof (array) \ - ? CAST_TO_VOID (var = array[index]) \ - : (MPN_RANDOM_ALT (index, &var, 1), (mp_limb_t) 0)), \ - index < limit; \ - index++) - -#define MULTIPLIER_COUNT \ - ((tr->flag & TRY_MULTIPLIER) \ - ? numberof (multiplier_array) + MULTIPLIER_RANDOMS \ - : 1) - -#define MULTIPLIER_ITERATION \ - ARRAY_ITERATION(multiplier, multiplier_index, MULTIPLIER_COUNT, \ - multiplier_array, MULTIPLIER_RANDOMS, TRY_MULTIPLIER) - -#define DIVISOR_COUNT \ - ((tr->flag & TRY_DIVISOR) \ - ? numberof (divisor_array) + DIVISOR_RANDOMS \ - : 1) - -#define DIVISOR_ITERATION \ - ARRAY_ITERATION(divisor, divisor_index, DIVISOR_COUNT, divisor_array, \ - DIVISOR_RANDOMS, TRY_DIVISOR) - - -/* overlap_array[].s[i] is where s[i] should be, 0 or 1 means overlapping - d[0] or d[1] respectively, -1 means a separate (write-protected) - location. */ - -struct overlap_t { - int s[NUM_SOURCES]; -} overlap_array[] = { - { { -1, -1 } }, - { { 0, -1 } }, - { { -1, 0 } }, - { { 0, 0 } }, - { { 1, -1 } }, - { { -1, 1 } }, - { { 1, 1 } }, - { { 0, 1 } }, - { { 1, 0 } }, -}; - -struct overlap_t *overlap, *overlap_limit; - -#define OVERLAP_COUNT \ - (tr->flag & TRY_OVERLAP_NONE ? 1 \ - : tr->flag & TRY_OVERLAP_NOTSRCS ? 3 \ - : tr->flag & TRY_DST1 ? 9 \ - : tr->flag & TRY_SRC1 ? 4 \ - : tr->flag & TRY_DST0 ? 2 \ - : 1) - -#define OVERLAP_ITERATION \ - for (overlap = &overlap_array[0], \ - overlap_limit = &overlap_array[OVERLAP_COUNT]; \ - overlap < overlap_limit; \ - overlap++) - - -#define T_RAND_COUNT 2 -int t_rand; - -void -t_random (mp_ptr ptr, mp_size_t n) -{ - if (size == 0) - return; - - switch (option_data) { - case DATA_TRAND: - switch (t_rand) { - case 0: mpn_random (ptr, n); break; - case 1: mpn_random2 (ptr, n); break; - default: abort(); - } - break; - case DATA_SEQ: - { - static mp_limb_t counter = 0; - mp_size_t i; - for (i = 0; i < n; i++) - ptr[i] = ++counter; - } - break; - case DATA_ZEROS: - refmpn_fill (ptr, n, (mp_limb_t) 0); - break; - case DATA_FFS: - refmpn_fill (ptr, n, (mp_limb_t) -1); - break; - case DATA_2FD: - /* Special value 0x2FFF...FFFD, which divided by 3 gives 0xFFF...FFF, - inducing the q1_ff special case in the mul-by-inverse part of some - versions of divrem_1 and mod_1. */ - refmpn_fill (ptr, n, (mp_limb_t) -1); - ptr[n-1] = 2; - ptr[0] -= 2; - break; - - default: - abort(); - } -} -#define T_RAND_ITERATION \ - for (t_rand = 0; t_rand < T_RAND_COUNT; t_rand++) - - -void -print_each (const struct each_t *e) -{ - int i; - - printf ("%s %s\n", e->name, e == &ref ? tr->ref.name : tr->fun.name); - if (tr->flag & TRY_RETVAL) - printf (" retval %08lX\n", e->retval); - - for (i = 0; i < numberof (e->d); i++) - { - if (tr->flag & TRY_DST(i)) - { - mpn_tracen (" d[%d]", i, e->d[i].p, dsize); - printf (" located %p\n", e->d[i].p); - } - } - - for (i = 0; i < numberof (e->s); i++) - if (tr->flag & TRY_SRC(i)) - printf (" s[%d] located %p\n", i, e->s[i].p); -} - -void -print_all (void) -{ - int i; - - printf ("\n"); - printf ("size %ld\n", size); - if (tr->flag & (TRY_SIZE2|TRY_XSIZE)) - printf ("size2 %ld\n", size2); - if (dsize != size) - printf ("dsize %ld\n", dsize); - if (tr->flag & TRY_MULTIPLIER) - printf (" multiplier 0x%lX\n", multiplier); - if (tr->flag & TRY_DIVISOR) - printf (" divisor 0x%lX\n", divisor); - if (tr->flag & TRY_SHIFT) - printf (" shift %lu\n", shift); - if (tr->flag & TRY_CARRYANY) - printf (" carry %lX\n", carry); - - for (i = 0; i < numberof (d); i++) - if (tr->flag & TRY_DST(i)) - printf (" d[%d] %s, align %ld\n", - i, d[i].high ? "high" : "low", d[i].align); - - for (i = 0; i < numberof (s); i++) - { - if (tr->flag & TRY_SRC(i)) - { - printf (" s[%d] %s, align %ld, ", - i, s[i].high ? "high" : "low", s[i].align); - switch (overlap->s[i]) { - case -1: - printf ("no overlap\n"); - break; - default: - printf ("==d[%d]%s\n", - overlap->s[i], - tr->flag & TRY_OVERLAP_LOW_TO_HIGH ? "+a" - : tr->flag & TRY_OVERLAP_HIGH_TO_LOW ? "-a" - : ""); - break; - } - mpn_tracen (" s[%d]", i, s[i].p, SRC_SIZE(i)); - } - } - - if (tr->flag & TRY_DST0_INIT) - mpn_trace (" d[0]", s[1].region.ptr, size); - - print_each (&ref); - print_each (&fun); -} - -void -compare (void) -{ - int error = 0; - int i; - - if ((tr->flag & TRY_RETVAL) && ref.retval != fun.retval) - { - printf ("Different return values\n"); - error = 1; - } - - if (! CALLING_CONVENTIONS_CHECK ()) - error = 1; - - if (tr->flag & TRY_DST_SIZE_RETVAL) - dsize = ref.retval; - - for (i = 0; i < numberof (ref.d); i++) - { - if (!(tr->flag & TRY_DST(i))) - continue; - - if (dsize != 0 && refmpn_cmp (ref.d[i].p, fun.d[i].p, dsize) != 0) - { - printf ("Different d[%d] data results, low diff at %ld, high diff at %ld\n", - i, - mpn_diff_lowest (ref.d[i].p, fun.d[i].p, dsize), - mpn_diff_highest (ref.d[i].p, fun.d[i].p, dsize)); - error = 1; - } - } - - if (error) - { - print_all(); - abort(); - } -} - -void -call (struct each_t *e, tryfun_t function) -{ - switch (tr->flag) { - case TRY_TYPE_AORS_N: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, e->s[1].p, size); - break; - case TRY_TYPE_AORS_NC: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, e->s[1].p, size, carry); - break; - - case TRY_TYPE_LOGOPS_N: - CALLING_CONVENTIONS (function) (e->d[0].p, e->s[0].p, e->s[1].p, size); - break; - - case TRY_TYPE_ADDSUB_N: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->d[1].p, e->s[0].p, e->s[1].p, size); - break; - case TRY_TYPE_ADDSUB_NC: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->d[1].p, e->s[0].p, e->s[1].p, size, carry); - break; - - case TRY_TYPE_COPYI: - case TRY_TYPE_COPYD: - case TRY_TYPE_COM_N: - CALLING_CONVENTIONS (function) (e->d[0].p, e->s[0].p, size); - break; - - case TRY_TYPE_DIVEXACT_BY3: - e->retval = CALLING_CONVENTIONS (function) (e->d[0].p, e->s[0].p, size); - break; - case TRY_TYPE_DIVEXACT_BY3C: - e->retval = CALLING_CONVENTIONS (function) (e->d[0].p, e->s[0].p, size, - carry); - break; - - case TRY_TYPE_DIVMOD_1: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, size, divisor); - break; - case TRY_TYPE_DIVMOD_1C: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, size, divisor, carry); - break; - case TRY_TYPE_DIVREM_1: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, size2, e->s[0].p, size, divisor); - break; - case TRY_TYPE_DIVREM_1C: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, size2, e->s[0].p, size, divisor, carry); - break; - case TRY_TYPE_MOD_1: - e->retval = CALLING_CONVENTIONS (function) - (e->s[0].p, size, divisor); - break; - case TRY_TYPE_MOD_1C: - e->retval = CALLING_CONVENTIONS (function) - (e->s[0].p, size, divisor, carry); - break; - case TRY_TYPE_MOD_1_RSHIFT: - e->retval = CALLING_CONVENTIONS (function) - (e->s[0].p, size, shift, divisor); - break; - - case TRY_TYPE_GCD_1: - /* Must have a non-zero src, but this probably isn't the best way to do - it. */ - if (refmpn_zero_p (e->s[0].p, size)) - e->retval = 0; - else - e->retval = CALLING_CONVENTIONS (function) (e->s[0].p, size, divisor); - break; - - case TRY_TYPE_GCD: - /* Sources are destroyed, so they're saved and replaced, but a general - approach to this might be better. Note that it's still e->s[0].p and - e->s[1].p that are passed, to get the desired alignments. */ - { - mp_ptr s0 = refmpn_malloc_limbs (size); - mp_ptr s1 = refmpn_malloc_limbs (size2); - refmpn_copyi (s0, e->s[0].p, size); - refmpn_copyi (s1, e->s[1].p, size2); - - mprotect_region (&s[0].region, PROT_READ|PROT_WRITE); - mprotect_region (&s[1].region, PROT_READ|PROT_WRITE); - e->retval = CALLING_CONVENTIONS (function) (e->d[0].p, - e->s[0].p, size, - e->s[1].p, size2); - refmpn_copyi (e->s[0].p, s0, size); - refmpn_copyi (e->s[1].p, s1, size2); - free (s0); - free (s1); - } - break; - - case TRY_TYPE_MUL_1: - case TRY_TYPE_AORSMUL_1: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, size, multiplier); - break; - case TRY_TYPE_MUL_1C: - case TRY_TYPE_AORSMUL_1C: - /* TRY_TYPE_AORSMUL_1C same */ - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, size, multiplier, carry); - break; - - case TRY_TYPE_MUL_BASECASE: - CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, size, e->s[1].p, size2); - break; - case TRY_TYPE_MUL_N: - CALLING_CONVENTIONS (function) (e->d[0].p, e->s[0].p, e->s[1].p, size); - break; - case TRY_TYPE_SQR: - CALLING_CONVENTIONS (function) (e->d[0].p, e->s[0].p, size); - break; - - case TRY_TYPE_LSHIFT: - case TRY_TYPE_RSHIFT: - e->retval = CALLING_CONVENTIONS (function) - (e->d[0].p, e->s[0].p, size, shift); - break; - - case TRY_TYPE_POPCOUNT: - e->retval = CALLING_CONVENTIONS (function) (e->s[0].p, size); - break; - case TRY_TYPE_HAMDIST: - e->retval = CALLING_CONVENTIONS (function) (e->s[0].p, e->s[1].p, size); - break; - - default: - printf ("Unknown routine type 0x%X\n", tr->flag); - abort (); - break; - } -} - - -void -pointer_setup (struct each_t *e) -{ - int i, j; - - if (tr->flag & TRY_DOUBLE_DST) - dsize = 2*size; - else if (tr->flag & (TRY_SIZE2|TRY_XSIZE)) - dsize = size+size2; - else - dsize = size; - - /* establish e->d[].p destinations */ - for (i = 0; i < numberof (e->d); i++) - { - mp_size_t offset = 0; - - /* possible room for overlapping sources */ - for (j = 0; j < numberof (overlap->s); j++) - if (overlap->s[j] == i) - offset = MAX (offset, s[j].align); - - if (d[i].high) - { - e->d[i].p = e->d[i].region.ptr + e->d[i].region.size - - dsize - d[i].align; - if (tr->flag & TRY_OVERLAP_LOW_TO_HIGH) - e->d[i].p -= offset; - } - else - { - e->d[i].p = e->d[i].region.ptr + d[i].align; - if (tr->flag & TRY_OVERLAP_HIGH_TO_LOW) - e->d[i].p += offset; - } - } - - /* establish e->s[].p sources */ - for (i = 0; i < numberof (s); i++) - { - int o = overlap->s[i]; - switch (o) { - case -1: - /* no overlap */ - e->s[i].p = s[i].p; - break; - case 0: - case 1: - /* overlap with d[o] */ - if (tr->flag & TRY_OVERLAP_HIGH_TO_LOW) - e->s[i].p = e->d[o].p - s[i].align; - else if (tr->flag & TRY_OVERLAP_LOW_TO_HIGH) - e->s[i].p = e->d[o].p + s[i].align; - else if (tr->flag & TRY_XSIZE) - e->s[i].p = e->d[o].p + size2; - else - e->s[i].p = e->d[o].p; - break; - default: - abort(); - break; - } - } -} - - -void -try_one (void) -{ - int i; - - if (option_spinner) - spinner(); - spinner_count++; - - trap_location = TRAP_SETUPS; - - for (i = 0; i < numberof (s); i++) - { - if (s[i].high) - s[i].p = s[i].region.ptr + s[i].region.size - SRC_SIZE(i) - s[i].align; - else - s[i].p = s[i].region.ptr + s[i].align; - } - - pointer_setup (&ref); - pointer_setup (&fun); - - if (tr->flag & TRY_DST0_INIT) - { - t_random (s[1].region.ptr, dsize); - MPN_COPY (fun.d[0].p, s[1].region.ptr, dsize); - MPN_COPY (ref.d[0].p, s[1].region.ptr, dsize); - } - else if (tr->flag & TRY_DST0) - { - refmpn_fill (ref.d[0].p, dsize, DEADVAL); - refmpn_fill (fun.d[0].p, dsize, DEADVAL); - } - for (i = 1; i < numberof (d); i++) - { - if (!(tr->flag & TRY_DST(i))) - continue; - - refmpn_fill (ref.d[i].p, dsize, DEADVAL); - refmpn_fill (fun.d[i].p, dsize, DEADVAL); - } - - ref.retval = 0x04152637; - fun.retval = 0x8C9DAEBF; - - for (i = 0; i < numberof (s); i++) - { - if (!(tr->flag & TRY_SRC(i))) - continue; - - mprotect_region (&s[i].region, PROT_READ|PROT_WRITE); - t_random (s[i].p, SRC_SIZE(i)); - - if (tr->flag & TRY_SRC1_GCDDATA) - { - /* s[1] no more bits than s[0] */ - if (i == 1 && size2 == size) - s[1].p[size-1] &= refmpn_msbone_mask (s[0].p[size-1]); - - /* normalized */ - s[i].p[SRC_SIZE(i)-1] += (s[i].p[SRC_SIZE(i)-1] == 0); - - /* odd */ - s[i].p[0] |= 1; - } - - mprotect_region (&s[i].region, PROT_READ); - - if (ref.s[i].p != s[i].p) - { - MPN_COPY (ref.s[i].p, s[i].p, SRC_SIZE(i)); - MPN_COPY (fun.s[i].p, s[i].p, SRC_SIZE(i)); - } - } - - /* special requirement of divmod_1c,divrem_1c,mod_1c */ - if (tr->flag == TRY_TYPE_DIVMOD_1C - || tr->flag == TRY_TYPE_DIVREM_1C - || tr->flag == TRY_TYPE_MOD_1C) - carry %= divisor; - - if (option_print) - print_all(); - - trap_location = TRAP_REF; - call (&ref, tr->ref.function); - trap_location = TRAP_FUN; - call (&fun, tr->fun.function); - trap_location = TRAP_NOWHERE; - - compare (); -} - - -#define SIZE_ITERATION \ - for (size = MAX3 (option_firstsize, \ - tr->minsize, \ - (tr->flag & TRY_SIZE_ZERO) ? 0 : 1); \ - size <= option_lastsize; \ - size++) - -#define SIZE2_FIRST \ - (option_firstsize2 != 0 ? option_firstsize2 \ - : tr->flag & TRY_SIZE2 ? 1 \ - : tr->flag & TRY_XSIZE ? 0 \ - : 0) -#define SIZE2_LAST \ - (tr->flag & TRY_SIZE2 ? size \ - : tr->flag & TRY_XSIZE ? XSIZE_COUNT-1 \ - : 0) - -#define SIZE2_ITERATION \ - for (size2 = SIZE2_FIRST; size2 <= SIZE2_LAST; size2++) - -#define ALIGN_COUNT(cond) ((cond) ? ALIGNMENTS : 1) -#define ALIGN_ITERATION(w,n,cond) \ - for (w[n].align = 0; w[n].align < ALIGN_COUNT(cond); w[n].align++) - -#define HIGH_LIMIT(cond) ((cond) != 0) -#define HIGH_COUNT(cond) (HIGH_LIMIT (cond) + 1) -#define HIGH_ITERATION(w,n,cond) \ - for (w[n].high = 0; w[n].high <= HIGH_LIMIT(cond); w[n].high++) - -#define SHIFT_LIMIT \ - ((unsigned long) ((tr->flag & TRY_SHIFT) ? BITS_PER_MP_LIMB-1 : 1)) - -#define SHIFT_ITERATION \ - for (shift = 1; shift <= SHIFT_LIMIT; shift++) - - -void -try_many (void) -{ - int i; - - { - unsigned long total = 1; - - total *= option_repetitions; - total *= option_lastsize; - if (tr->flag & TRY_SIZE2) total *= (option_lastsize+1)/2; - if (tr->flag & TRY_XSIZE) total *= XSIZE_COUNT; - - total *= SHIFT_LIMIT; - total *= MULTIPLIER_COUNT; - total *= DIVISOR_COUNT; - total *= CARRY_COUNT; - total *= T_RAND_COUNT; - - total *= HIGH_COUNT (tr->flag & TRY_DST0); - total *= HIGH_COUNT (tr->flag & TRY_DST1); - total *= HIGH_COUNT (tr->flag & TRY_SRC0); - total *= HIGH_COUNT (tr->flag & TRY_SRC1); - - total *= ALIGN_COUNT (tr->flag & TRY_DST0); - total *= ALIGN_COUNT (tr->flag & TRY_DST1); - total *= ALIGN_COUNT (tr->flag & TRY_SRC0); - total *= ALIGN_COUNT (tr->flag & TRY_SRC1); - - total *= OVERLAP_COUNT; - - printf ("%s %lu\n", tr->fun.name, total); - } - - spinner_count = 0; - - for (i = 0; i < option_repetitions; i++) - SIZE_ITERATION - SIZE2_ITERATION - - SHIFT_ITERATION - MULTIPLIER_ITERATION - DIVISOR_ITERATION - CARRY_ITERATION /* must be after divisor */ - T_RAND_ITERATION - - HIGH_ITERATION(d,0, tr->flag & TRY_DST0) - HIGH_ITERATION(d,1, tr->flag & TRY_DST1) - HIGH_ITERATION(s,0, tr->flag & TRY_SRC0) - HIGH_ITERATION(s,1, tr->flag & TRY_SRC1) - - ALIGN_ITERATION(d,0, tr->flag & TRY_DST0) - ALIGN_ITERATION(d,1, tr->flag & TRY_DST1) - ALIGN_ITERATION(s,0, tr->flag & TRY_SRC0) - ALIGN_ITERATION(s,1, tr->flag & TRY_SRC1) - - OVERLAP_ITERATION - try_one(); - - printf("\n"); -} - - -/* Usually print_all() doesn't show much, but it might give a hint as to - where the function was up to when it died. */ -void -trap (int sig) -{ - const char *name = "noname"; - - switch (sig) { - case SIGILL: name = "SIGILL"; break; -#ifdef SIGBUS - case SIGBUS: name = "SIGBUS"; break; -#endif - case SIGSEGV: name = "SIGSEGV"; break; - case SIGFPE: name = "SIGFPE"; break; - } - - printf ("\n\nSIGNAL TRAP: %s\n", name); - - switch (trap_location) { - case TRAP_REF: - printf (" in reference function: %s\n", tr->ref.name); - break; - case TRAP_FUN: - printf (" in test function: %s\n", tr->fun.name); - print_all (); - break; - case TRAP_SETUPS: - printf (" in parameter setups\n"); - print_all (); - break; - default: - printf (" somewhere unknown\n"); - break; - } - exit (1); -} - - -void -try_init (void) -{ -#if HAVE_GETPAGESIZE - /* Prefer getpagesize() over sysconf(), since on SunOS 4 sysconf() doesn't - know _SC_PAGESIZE. */ - pagesize = getpagesize (); -#else -#if HAVE_SYSCONF - if ((pagesize = sysconf (_SC_PAGESIZE)) == -1) - { - /* According to the linux man page, sysconf doesn't set errno */ - fprintf (stderr, "Cannot get sysconf _SC_PAGESIZE\n"); - exit (1); - } -#else -Error, error, cannot get page size -#endif -#endif - - printf ("pagesize is 0x%lX bytes\n", pagesize); - - signal (SIGILL, trap); -#ifdef SIGBUS - signal (SIGBUS, trap); -#endif - signal (SIGSEGV, trap); - signal (SIGFPE, trap); - - { - int i; - - for (i = 0; i < numberof (s); i++) - { - malloc_region (&s[i].region, 2*option_lastsize+ALIGNMENTS-1); - printf ("s[%d] %p to %p (0x%lX bytes)\n", - i, s[i].region.ptr, - s[i].region.ptr + s[i].region.size, - s[i].region.size * BYTES_PER_MP_LIMB); - } - -#define INIT_EACH(e,es) \ - for (i = 0; i < numberof (e.d); i++) \ - { \ - malloc_region (&e.d[i].region, 2*option_lastsize+ALIGNMENTS-1); \ - printf ("%s d[%d] %p to %p (0x%lX bytes)\n", \ - es, i, e.d[i].region.ptr, \ - e.d[i].region.ptr + e.d[i].region.size, \ - e.d[i].region.size * BYTES_PER_MP_LIMB); \ - } - - INIT_EACH(ref, "ref"); - INIT_EACH(fun, "fun"); - } -} - -int -strmatch_wild (const char *pattern, const char *str) -{ - size_t plen, slen; - - /* wildcard at start */ - if (pattern[0] == '*') - { - pattern++; - plen = strlen (pattern); - slen = strlen (str); - return (plen == 0 - || (slen >= plen && memcmp (pattern, str+slen-plen, plen) == 0)); - } - - /* wildcard at end */ - plen = strlen (pattern); - if (plen >= 1 && pattern[plen-1] == '*') - return (memcmp (pattern, str, plen-1) == 0); - - /* no wildcards */ - return (strcmp (pattern, str) == 0); -} - -void -try_name (const char *name) -{ - int found = 0; - int i; - - for (i = 0; i < numberof (try_array); i++) - { - if (strmatch_wild (name, try_array[i].fun.name)) - { - tr = &try_array[i]; - try_many (); - found = 1; - } - } - - if (!found) - { - printf ("%s unknown\n", name); - /* exit (1); */ - } -} - - -void -usage (const char *prog) -{ - int col = 0; - int i; - - printf ("Usage: %s [options] function...\n\ - -1 use limb data 1,2,3,etc\n\ - -9 use limb data all 0xFF..FFs\n\ - -a zeros use limb data all zeros\n\ - -a ffs use limb data all 0xFF..FFs (same as -9)\n\ - -a 2fd use data 0x2FFF...FFFD\n\ - -p print each case tried (try this if seg faulting)\n\ - -R seed random numbers from time()\n\ - -r reps set repetitions (default %d)\n\ - -S seed randomize from given seed\n\ - -s size starting size to test\n\ - -s s1-s2 range of sizes to test\n\ - -W don't show the spinner (use this in gdb)\n\ - -z disable mprotect() redzones\n\ -Default data is mpn_random() and mpn_random2().\n\ -\n\ -Functions that can be tested:\n\ -", prog, DEFAULT_REPETITIONS); - - for (i = 0; i < numberof (try_array); i++) - { - if (col + 1 + strlen (try_array[i].fun.name) > 79) - { - printf ("\n"); - col = 0; - } - printf (" %s", try_array[i].fun.name); - col += 1 + strlen (try_array[i].fun.name); - } - printf ("\n"); - - exit(1); -} - - -int -main (int argc, char *argv[]) -{ - int i; - - /* unbuffered output */ - setbuf (stdout, NULL); - setbuf (stderr, NULL); - - /* always trace in hex, upper-case so can paste into bc */ - mp_trace_base = -16; - - { - unsigned seed = 123; - int opt; - - while ((opt = getopt(argc, argv, "19a:pRr:S:s:Wz")) != EOF) - { - switch (opt) { - case '1': - /* use limb data values 1, 2, 3, ... etc */ - option_data = DATA_SEQ; - break; - case '9': - /* use limb data values 0xFFF...FFF always */ - option_data = DATA_FFS; - break; - case 'a': - if (strcmp (optarg, "zeros") == 0) option_data = DATA_ZEROS; - else if (strcmp (optarg, "seq") == 0) option_data = DATA_SEQ; - else if (strcmp (optarg, "ffs") == 0) option_data = DATA_FFS; - else if (strcmp (optarg, "2fd") == 0) option_data = DATA_2FD; - else - { - fprintf (stderr, "unrecognised data option: %s\n", optarg); - exit (1); - } - break; - case 'p': - option_print = 1; - break; - case 'R': - /* randomize */ - seed = time (NULL); - break; - case 'r': - option_repetitions = atoi (optarg); - break; - case 's': - { - char *p; - option_firstsize = atoi (optarg); - if ((p = strchr (optarg, '-')) != NULL) - option_lastsize = atoi (p+1); - } - break; - case 'S': - /* -S sets the starting size for the second of a two size - routine (like mpn_mul_basecase) */ - option_firstsize2 = atoi (optarg); - break; - case 'W': - /* use this when running in the debugger */ - option_spinner = 0; - break; - case 'z': - /* disable redzones */ - option_redzones = 0; - break; - case '?': - usage (argv[0]); - break; - } - } - - srandom (seed); - } - - try_init(); - - if (argc <= optind) - usage (argv[0]); - - for (i = optind; i < argc; i++) - try_name (argv[i]); - - return 0; -} diff --git a/gmp/mpn/tests/try.h b/gmp/mpn/tests/try.h deleted file mode 100755 index 027e844..0000000 --- a/gmp/mpn/tests/try.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#ifndef __TRY_H__ -#define __TRY_H__ - -#if defined (__cplusplus) -extern "C" { -#endif - - -#ifdef __cplusplus -#define ANYARGS ... -#else -#define ANYARGS -#endif - -typedef mp_limb_t (*tryfun_t) _PROTO ((ANYARGS)); - -#if HAVE_CALLING_CONVENTIONS -extern tryfun_t calling_conventions_function; -mp_limb_t calling_conventions _PROTO ((ANYARGS)); -int calling_conventions_check _PROTO ((void)); -#define CALLING_CONVENTIONS(function) \ - (calling_conventions_function = (function), calling_conventions) -#define CALLING_CONVENTIONS_CHECK() (calling_conventions_check()) -#else -#define CALLING_CONVENTIONS(function) (function) -#define CALLING_CONVENTIONS_CHECK() 1 /* always ok */ -#endif - - -extern int mp_trace_base; -void mpn_trace _PROTO ((const char *name, mp_srcptr ptr, mp_size_t size)); -void mpn_tracea _PROTO ((const char *name, const mp_ptr *a, int count, - mp_size_t size)); -void mpn_tracen _PROTO ((const char *name, int num, mp_srcptr ptr, - mp_size_t size)); -void mpn_trace_file _PROTO ((const char *filename, - mp_srcptr ptr, mp_size_t size)); -void mpn_tracea_file _PROTO ((const char *filename, - const mp_ptr *a, int count, mp_size_t size)); -void mpq_trace _PROTO ((const char *name, mpq_srcptr q)); -void mpz_trace _PROTO ((const char *name, mpz_srcptr z)); -void mpz_tracen _PROTO ((const char *name, int num, mpz_srcptr z)); - -void spinner _PROTO ((void)); -extern unsigned long spinner_count; - - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/gmp/mpn/tests/tst-addsub.c b/gmp/mpn/tests/tst-addsub.c deleted file mode 100755 index 23dbba0..0000000 --- a/gmp/mpn/tests/tst-addsub.c +++ /dev/null @@ -1,185 +0,0 @@ -/* -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" - -#define ADD 1 -#define SUB 2 - -#ifndef METHOD -#define METHOD ADD -#endif - -#if METHOD == ADD -#define REFCALL refmpn_add_n -#define TESTCALL mpn_add_n -#endif - -#if METHOD == SUB -#define REFCALL refmpn_sub_n -#define TESTCALL mpn_sub_n -#endif - -mp_limb_t refmpn_add_n (); -mp_limb_t refmpn_sub_n (); - -#define SIZE 100 - -main (argc, argv) - int argc; - char **argv; -{ - mp_size_t alloc_size, max_size, size, i, cumul_size; - mp_ptr s1, s2, dx, dy; - int s1_align, s2_align, d_align; - long pass, n_passes; - mp_limb_t cx, cy; - - max_size = SIZE; - n_passes = 1000000; - - argc--; argv++; - if (argc) - { - max_size = atol (*argv); - argc--; argv++; - } - - alloc_size = max_size + 32; - s1 = malloc (alloc_size * BYTES_PER_MP_LIMB); - s2 = malloc (alloc_size * BYTES_PER_MP_LIMB); - dx = malloc (alloc_size * BYTES_PER_MP_LIMB); - dy = malloc (alloc_size * BYTES_PER_MP_LIMB); - - cumul_size = 0; - for (pass = 0; pass < n_passes; pass++) - { - cumul_size += size; - if (cumul_size >= 1000000) - { - cumul_size -= 1000000; - printf ("%d ", pass); fflush (stdout); - } - s1_align = random () % 32; - s2_align = random () % 32; - d_align = random () % 32; - - size = random () % max_size + 1; - - mpn_random2 (s1 + s1_align, size); - mpn_random2 (s2 + s2_align, size); - - for (i = 0; i < alloc_size; i++) - dx[i] = dy[i] = i + 0x9876500; - - cx = TESTCALL (dx + d_align, s1 + s1_align, s2 + s2_align, size); - cy = REFCALL (dy + d_align, s1 + s1_align, s2 + s2_align, size); - - if (cx != cy || mpn_cmp (dx, dy, alloc_size) != 0) - abort (); - } - - printf ("%d passes OK\n", n_passes); - exit (0); -} - -mp_limb_t -#if __STDC__ -refmpn_add_n (mp_ptr res_ptr, - mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) -#else -refmpn_add_n (res_ptr, s1_ptr, s2_ptr, size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_srcptr s2_ptr; - mp_size_t size; -#endif -{ - register mp_limb_t x, y, cy; - register mp_size_t j; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - s2_ptr -= j; - res_ptr -= j; - - cy = 0; - do - { - y = s2_ptr[j]; - x = s1_ptr[j]; - y += cy; /* add previous carry to one addend */ - cy = (y < cy); /* get out carry from that addition */ - y = x + y; /* add other addend */ - cy = (y < x) + cy; /* get out carry from that add, combine */ - res_ptr[j] = y; - } - while (++j != 0); - - return cy; -} - -mp_limb_t -#if __STDC__ -refmpn_sub_n (mp_ptr res_ptr, - mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) -#else -refmpn_sub_n (res_ptr, s1_ptr, s2_ptr, size) - register mp_ptr res_ptr; - register mp_srcptr s1_ptr; - register mp_srcptr s2_ptr; - mp_size_t size; -#endif -{ - register mp_limb_t x, y, cy; - register mp_size_t j; - - /* The loop counter and index J goes from -SIZE to -1. This way - the loop becomes faster. */ - j = -size; - - /* Offset the base pointers to compensate for the negative indices. */ - s1_ptr -= j; - s2_ptr -= j; - res_ptr -= j; - - cy = 0; - do - { - y = s2_ptr[j]; - x = s1_ptr[j]; - y += cy; /* add previous carry to subtrahend */ - cy = (y < cy); /* get out carry from that addition */ - y = x - y; /* main subtract */ - cy = (y > x) + cy; /* get out carry from the subtract, combine */ - res_ptr[j] = y; - } - while (++j != 0); - - return cy; -} diff --git a/gmp/mpn/tests/x86call.asm b/gmp/mpn/tests/x86call.asm deleted file mode 100755 index 796139c..0000000 Binary files a/gmp/mpn/tests/x86call.asm and /dev/null differ diff --git a/gmp/mpn/tests/x86check.c b/gmp/mpn/tests/x86check.c deleted file mode 100755 index ae15144..0000000 --- a/gmp/mpn/tests/x86check.c +++ /dev/null @@ -1,102 +0,0 @@ -/* x86 calling conventions checking. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "try.h" - - -/* function to call */ -tryfun_t calling_conventions_function; - -/* temporaries */ -int calling_conventions_save_ebx; -int calling_conventions_save_esi; -int calling_conventions_save_edi; -int calling_conventions_save_ebp; -int calling_conventions_retaddr; -int calling_conventions_retval; - -/* values to check */ -struct { - unsigned control; - unsigned status; - unsigned tag; - unsigned other[4]; -} calling_conventions_fenv; -int calling_conventions_ebx; -int calling_conventions_esi; -int calling_conventions_edi; -int calling_conventions_ebp; -int calling_conventions_eflags; - -/* expected values, as per x86call.asm */ -#define VALUE_EBX 0x01234567 -#define VALUE_ESI 0x89ABCDEF -#define VALUE_EDI 0xFEDCBA98 -#define VALUE_EBP 0x76543210 - -#define DIR_BIT(eflags) (((eflags) & (1<<10)) != 0) - - -/* Return 1 if ok, 0 if not */ - -int -calling_conventions_check (void) -{ - const char *header = "Violated calling conventions:\n"; - int ret = 1; - -#define CHECK(callreg, regstr, value) \ - if (callreg != value) \ - { \ - printf ("%s %s got 0x%08X want 0x%08X\n", \ - header, regstr, callreg, value); \ - header = ""; \ - ret = 0; \ - } - - CHECK (calling_conventions_ebx, "ebx", VALUE_EBX); - CHECK (calling_conventions_esi, "esi", VALUE_ESI); - CHECK (calling_conventions_edi, "edi", VALUE_EDI); - CHECK (calling_conventions_ebp, "ebp", VALUE_EBP); - - if (DIR_BIT (calling_conventions_eflags) != 0) - { - printf ("%s eflags dir bit got %d want 0\n", - header, DIR_BIT (calling_conventions_eflags)); - header = ""; - ret = 0; - } - - if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF) - { - printf ("%s fpu tags got 0x%X want 0xFFFF\n", - header, calling_conventions_fenv.tag & 0xFFFF); - header = ""; - ret = 0; - } - - return ret; -} diff --git a/gmp/mpn/thumb/add_n.s b/gmp/mpn/thumb/add_n.s deleted file mode 100755 index 0789297..0000000 Binary files a/gmp/mpn/thumb/add_n.s and /dev/null differ diff --git a/gmp/mpn/thumb/sub_n.s b/gmp/mpn/thumb/sub_n.s deleted file mode 100755 index e0f5c4b..0000000 Binary files a/gmp/mpn/thumb/sub_n.s and /dev/null differ diff --git a/gmp/mpn/underscore.h b/gmp/mpn/underscore.h deleted file mode 100755 index 240dae0..0000000 --- a/gmp/mpn/underscore.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#if __STDC__ -#define C_SYMBOL_NAME(name) _##name -#else -#define C_SYMBOL_NAME(name) _/**/name -#endif diff --git a/gmp/mpn/vax/add_n.s b/gmp/mpn/vax/add_n.s deleted file mode 100755 index 88a6e28..0000000 Binary files a/gmp/mpn/vax/add_n.s and /dev/null differ diff --git a/gmp/mpn/vax/addmul_1.s b/gmp/mpn/vax/addmul_1.s deleted file mode 100755 index 3b22052..0000000 Binary files a/gmp/mpn/vax/addmul_1.s and /dev/null differ diff --git a/gmp/mpn/vax/lshift.s b/gmp/mpn/vax/lshift.s deleted file mode 100755 index 23a4e63..0000000 Binary files a/gmp/mpn/vax/lshift.s and /dev/null differ diff --git a/gmp/mpn/vax/mul_1.s b/gmp/mpn/vax/mul_1.s deleted file mode 100755 index 41d55d6..0000000 Binary files a/gmp/mpn/vax/mul_1.s and /dev/null differ diff --git a/gmp/mpn/vax/rshift.s b/gmp/mpn/vax/rshift.s deleted file mode 100755 index b20f848..0000000 Binary files a/gmp/mpn/vax/rshift.s and /dev/null differ diff --git a/gmp/mpn/vax/sub_n.s b/gmp/mpn/vax/sub_n.s deleted file mode 100755 index 18ff25d..0000000 Binary files a/gmp/mpn/vax/sub_n.s and /dev/null differ diff --git a/gmp/mpn/vax/submul_1.s b/gmp/mpn/vax/submul_1.s deleted file mode 100755 index edb1780..0000000 Binary files a/gmp/mpn/vax/submul_1.s and /dev/null differ diff --git a/gmp/mpn/x86/README b/gmp/mpn/x86/README deleted file mode 100755 index 7a172dc..0000000 Binary files a/gmp/mpn/x86/README and /dev/null differ diff --git a/gmp/mpn/x86/README.family b/gmp/mpn/x86/README.family deleted file mode 100755 index 091b60a..0000000 Binary files a/gmp/mpn/x86/README.family and /dev/null differ diff --git a/gmp/mpn/x86/addsub_n.S b/gmp/mpn/x86/addsub_n.S deleted file mode 100755 index 143b05f..0000000 Binary files a/gmp/mpn/x86/addsub_n.S and /dev/null differ diff --git a/gmp/mpn/x86/aors_n.asm b/gmp/mpn/x86/aors_n.asm deleted file mode 100755 index 17b647a..0000000 Binary files a/gmp/mpn/x86/aors_n.asm and /dev/null differ diff --git a/gmp/mpn/x86/aorsmul_1.asm b/gmp/mpn/x86/aorsmul_1.asm deleted file mode 100755 index 5254e73..0000000 Binary files a/gmp/mpn/x86/aorsmul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/copyd.asm b/gmp/mpn/x86/copyd.asm deleted file mode 100755 index f9287c5..0000000 Binary files a/gmp/mpn/x86/copyd.asm and /dev/null differ diff --git a/gmp/mpn/x86/copyi.asm b/gmp/mpn/x86/copyi.asm deleted file mode 100755 index 1f16b02..0000000 Binary files a/gmp/mpn/x86/copyi.asm and /dev/null differ diff --git a/gmp/mpn/x86/diveby3.asm b/gmp/mpn/x86/diveby3.asm deleted file mode 100755 index f744236..0000000 Binary files a/gmp/mpn/x86/diveby3.asm and /dev/null differ diff --git a/gmp/mpn/x86/divrem_1.asm b/gmp/mpn/x86/divrem_1.asm deleted file mode 100755 index 8387c97..0000000 Binary files a/gmp/mpn/x86/divrem_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/README b/gmp/mpn/x86/k6/README deleted file mode 100755 index 9d82601..0000000 Binary files a/gmp/mpn/x86/k6/README and /dev/null differ diff --git a/gmp/mpn/x86/k6/aors_n.asm b/gmp/mpn/x86/k6/aors_n.asm deleted file mode 100755 index ea7cd73..0000000 Binary files a/gmp/mpn/x86/k6/aors_n.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/aorsmul_1.asm b/gmp/mpn/x86/k6/aorsmul_1.asm deleted file mode 100755 index 5e5e8ca..0000000 Binary files a/gmp/mpn/x86/k6/aorsmul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/cross.pl b/gmp/mpn/x86/k6/cross.pl deleted file mode 100755 index 7e7cc42..0000000 Binary files a/gmp/mpn/x86/k6/cross.pl and /dev/null differ diff --git a/gmp/mpn/x86/k6/diveby3.asm b/gmp/mpn/x86/k6/diveby3.asm deleted file mode 100755 index eb477ec..0000000 Binary files a/gmp/mpn/x86/k6/diveby3.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/gmp-mparam.h b/gmp/mpn/x86/k6/gmp-mparam.h deleted file mode 100755 index 77f3948..0000000 --- a/gmp/mpn/x86/k6/gmp-mparam.h +++ /dev/null @@ -1,97 +0,0 @@ -/* AMD K6 gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - - -#ifndef UMUL_TIME -#define UMUL_TIME 3 /* cycles */ -#endif - -#ifndef UDIV_TIME -#define UDIV_TIME 20 /* cycles */ -#endif - -/* bsfl takes 12-27 cycles, put an average for uniform random numbers */ -#ifndef COUNT_TRAILING_ZEROS_TIME -#define COUNT_TRAILING_ZEROS_TIME 14 /* cycles */ -#endif - - -/* Generated by tuneup.c, 2000-07-04. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 18 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 130 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 34 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 116 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 68 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 98 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 13 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 67 -#endif - -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE { 528, 1184, 2176, 5632, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD 472 -#endif -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD 4352 -#endif - -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE { 528, 1184, 2176, 5632, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD 544 -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD 4352 -#endif diff --git a/gmp/mpn/x86/k6/k62mmx/copyd.asm b/gmp/mpn/x86/k6/k62mmx/copyd.asm deleted file mode 100755 index cce4856..0000000 Binary files a/gmp/mpn/x86/k6/k62mmx/copyd.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/k62mmx/copyi.asm b/gmp/mpn/x86/k6/k62mmx/copyi.asm deleted file mode 100755 index ef7c4e2..0000000 Binary files a/gmp/mpn/x86/k6/k62mmx/copyi.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/k62mmx/lshift.asm b/gmp/mpn/x86/k6/k62mmx/lshift.asm deleted file mode 100755 index d4700a6..0000000 Binary files a/gmp/mpn/x86/k6/k62mmx/lshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/k62mmx/rshift.asm b/gmp/mpn/x86/k6/k62mmx/rshift.asm deleted file mode 100755 index 3866c66..0000000 Binary files a/gmp/mpn/x86/k6/k62mmx/rshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mmx/com_n.asm b/gmp/mpn/x86/k6/mmx/com_n.asm deleted file mode 100755 index 979f2f6..0000000 Binary files a/gmp/mpn/x86/k6/mmx/com_n.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mmx/logops_n.asm b/gmp/mpn/x86/k6/mmx/logops_n.asm deleted file mode 100755 index ec1679d..0000000 Binary files a/gmp/mpn/x86/k6/mmx/logops_n.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mmx/lshift.asm b/gmp/mpn/x86/k6/mmx/lshift.asm deleted file mode 100755 index 2eaac4d..0000000 Binary files a/gmp/mpn/x86/k6/mmx/lshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mmx/popham.asm b/gmp/mpn/x86/k6/mmx/popham.asm deleted file mode 100755 index d53d5b3..0000000 Binary files a/gmp/mpn/x86/k6/mmx/popham.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mmx/rshift.asm b/gmp/mpn/x86/k6/mmx/rshift.asm deleted file mode 100755 index a40ad58..0000000 Binary files a/gmp/mpn/x86/k6/mmx/rshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mul_1.asm b/gmp/mpn/x86/k6/mul_1.asm deleted file mode 100755 index a00bb85..0000000 Binary files a/gmp/mpn/x86/k6/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/mul_basecase.asm b/gmp/mpn/x86/k6/mul_basecase.asm deleted file mode 100755 index eb4eedc..0000000 Binary files a/gmp/mpn/x86/k6/mul_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/k6/sqr_basecase.asm b/gmp/mpn/x86/k6/sqr_basecase.asm deleted file mode 100755 index 799c28a..0000000 Binary files a/gmp/mpn/x86/k6/sqr_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/README b/gmp/mpn/x86/k7/README deleted file mode 100755 index 7745574..0000000 Binary files a/gmp/mpn/x86/k7/README and /dev/null differ diff --git a/gmp/mpn/x86/k7/aors_n.asm b/gmp/mpn/x86/k7/aors_n.asm deleted file mode 100755 index 0c7febe..0000000 Binary files a/gmp/mpn/x86/k7/aors_n.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/aorsmul_1.asm b/gmp/mpn/x86/k7/aorsmul_1.asm deleted file mode 100755 index 7ccd52e..0000000 Binary files a/gmp/mpn/x86/k7/aorsmul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/diveby3.asm b/gmp/mpn/x86/k7/diveby3.asm deleted file mode 100755 index 31f16e6..0000000 Binary files a/gmp/mpn/x86/k7/diveby3.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/gmp-mparam.h b/gmp/mpn/x86/k7/gmp-mparam.h deleted file mode 100755 index c3bba0a..0000000 --- a/gmp/mpn/x86/k7/gmp-mparam.h +++ /dev/null @@ -1,100 +0,0 @@ -/* AMD K7 gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - - -/* the low limb is ready after 4 cycles, but normally it's the high limb - which is of interest, and that comes out after 6 cycles */ -#ifndef UMUL_TIME -#define UMUL_TIME 6 /* cycles */ -#endif - -/* AMD doco says 40, but it measures 39 back-to-back */ -#ifndef UDIV_TIME -#define UDIV_TIME 39 /* cycles */ -#endif - -/* using bsf */ -#ifndef COUNT_TRAILING_ZEROS_TIME -#define COUNT_TRAILING_ZEROS_TIME 7 /* cycles */ -#endif - - -/* Generated by tuneup.c, 2000-07-06. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 26 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 177 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 52 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 173 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 76 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 114 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 34 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 5 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 54 -#endif - -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE { 720, 1440, 2944, 7680, 18432, 57344, 0 } -#endif -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD 736 -#endif -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD 6912 -#endif - -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE { 784, 1696, 3200, 7680, 18432, 57344, 0 } -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD 800 -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD 8448 -#endif diff --git a/gmp/mpn/x86/k7/mmx/copyd.asm b/gmp/mpn/x86/k7/mmx/copyd.asm deleted file mode 100755 index 621cc51..0000000 Binary files a/gmp/mpn/x86/k7/mmx/copyd.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mmx/copyi.asm b/gmp/mpn/x86/k7/mmx/copyi.asm deleted file mode 100755 index 4bb3f05..0000000 Binary files a/gmp/mpn/x86/k7/mmx/copyi.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mmx/divrem_1.asm b/gmp/mpn/x86/k7/mmx/divrem_1.asm deleted file mode 100755 index 2747d31..0000000 Binary files a/gmp/mpn/x86/k7/mmx/divrem_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mmx/lshift.asm b/gmp/mpn/x86/k7/mmx/lshift.asm deleted file mode 100755 index e10f44d..0000000 Binary files a/gmp/mpn/x86/k7/mmx/lshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mmx/mod_1.asm b/gmp/mpn/x86/k7/mmx/mod_1.asm deleted file mode 100755 index 59c32e2..0000000 Binary files a/gmp/mpn/x86/k7/mmx/mod_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mmx/popham.asm b/gmp/mpn/x86/k7/mmx/popham.asm deleted file mode 100755 index eadfeb2..0000000 Binary files a/gmp/mpn/x86/k7/mmx/popham.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mmx/rshift.asm b/gmp/mpn/x86/k7/mmx/rshift.asm deleted file mode 100755 index 6231c12..0000000 Binary files a/gmp/mpn/x86/k7/mmx/rshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mul_1.asm b/gmp/mpn/x86/k7/mul_1.asm deleted file mode 100755 index 0e95e8e..0000000 Binary files a/gmp/mpn/x86/k7/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/mul_basecase.asm b/gmp/mpn/x86/k7/mul_basecase.asm deleted file mode 100755 index 2a6e972..0000000 Binary files a/gmp/mpn/x86/k7/mul_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/k7/sqr_basecase.asm b/gmp/mpn/x86/k7/sqr_basecase.asm deleted file mode 100755 index b8dcb7f..0000000 Binary files a/gmp/mpn/x86/k7/sqr_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/lshift.asm b/gmp/mpn/x86/lshift.asm deleted file mode 100755 index 10b7b6e..0000000 Binary files a/gmp/mpn/x86/lshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/mod_1.asm b/gmp/mpn/x86/mod_1.asm deleted file mode 100755 index 5fb525f..0000000 Binary files a/gmp/mpn/x86/mod_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/mul_1.asm b/gmp/mpn/x86/mul_1.asm deleted file mode 100755 index a5ba3bc..0000000 Binary files a/gmp/mpn/x86/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/mul_basecase.asm b/gmp/mpn/x86/mul_basecase.asm deleted file mode 100755 index 0ce6629..0000000 Binary files a/gmp/mpn/x86/mul_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/README b/gmp/mpn/x86/p6/README deleted file mode 100755 index ac5db75..0000000 Binary files a/gmp/mpn/x86/p6/README and /dev/null differ diff --git a/gmp/mpn/x86/p6/aorsmul_1.asm b/gmp/mpn/x86/p6/aorsmul_1.asm deleted file mode 100755 index 388dd77..0000000 Binary files a/gmp/mpn/x86/p6/aorsmul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/diveby3.asm b/gmp/mpn/x86/p6/diveby3.asm deleted file mode 100755 index ef24421..0000000 Binary files a/gmp/mpn/x86/p6/diveby3.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/gmp-mparam.h b/gmp/mpn/x86/p6/gmp-mparam.h deleted file mode 100755 index d7bfb6d..0000000 --- a/gmp/mpn/x86/p6/gmp-mparam.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Intel P6 gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - - -#ifndef UMUL_TIME -#define UMUL_TIME 5 /* cycles */ -#endif -#ifndef UDIV_TIME -#define UDIV_TIME 39 /* cycles */ -#endif - -#ifndef COUNT_TRAILING_ZEROS_TIME -#define COUNT_TRAILING_ZEROS_TIME 2 /* cycles */ -#endif - - -/* Generated by tuneup.c, 2000-07-06. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 23 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 139 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 52 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 166 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 116 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 66 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 20 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 54 -#endif - -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE { 592, 1440, 2688, 5632, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD 608 -#endif -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD 5888 -#endif - -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE { 656, 1504, 2944, 6656, 18432, 57344, 0 } -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD 672 -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD 5888 -#endif diff --git a/gmp/mpn/x86/p6/mmx/divrem_1.asm b/gmp/mpn/x86/p6/mmx/divrem_1.asm deleted file mode 100755 index 4963c98..0000000 Binary files a/gmp/mpn/x86/p6/mmx/divrem_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/mmx/mod_1.asm b/gmp/mpn/x86/p6/mmx/mod_1.asm deleted file mode 100755 index baec706..0000000 Binary files a/gmp/mpn/x86/p6/mmx/mod_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/mmx/popham.asm b/gmp/mpn/x86/p6/mmx/popham.asm deleted file mode 100755 index 89ebff0..0000000 Binary files a/gmp/mpn/x86/p6/mmx/popham.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/p3mmx/popham.asm b/gmp/mpn/x86/p6/p3mmx/popham.asm deleted file mode 100755 index 068edd4..0000000 Binary files a/gmp/mpn/x86/p6/p3mmx/popham.asm and /dev/null differ diff --git a/gmp/mpn/x86/p6/sqr_basecase.asm b/gmp/mpn/x86/p6/sqr_basecase.asm deleted file mode 100755 index 8874b26..0000000 Binary files a/gmp/mpn/x86/p6/sqr_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/README b/gmp/mpn/x86/pentium/README deleted file mode 100755 index 77fca52..0000000 Binary files a/gmp/mpn/x86/pentium/README and /dev/null differ diff --git a/gmp/mpn/x86/pentium/aors_n.asm b/gmp/mpn/x86/pentium/aors_n.asm deleted file mode 100755 index 6d21803..0000000 Binary files a/gmp/mpn/x86/pentium/aors_n.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/aorsmul_1.asm b/gmp/mpn/x86/pentium/aorsmul_1.asm deleted file mode 100755 index 7c269f1..0000000 Binary files a/gmp/mpn/x86/pentium/aorsmul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/diveby3.asm b/gmp/mpn/x86/pentium/diveby3.asm deleted file mode 100755 index 90a894f..0000000 Binary files a/gmp/mpn/x86/pentium/diveby3.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/gmp-mparam.h b/gmp/mpn/x86/pentium/gmp-mparam.h deleted file mode 100755 index d3ed3d7..0000000 --- a/gmp/mpn/x86/pentium/gmp-mparam.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Intel P54 gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - - -#ifndef UMUL_TIME -#define UMUL_TIME 9 /* cycles */ -#endif -#ifndef UDIV_TIME -#define UDIV_TIME 41 /* cycles */ -#endif - -/* bsf takes 18-42 cycles, put an average for uniform random numbers */ -#ifndef COUNT_TRAILING_ZEROS_TIME -#define COUNT_TRAILING_ZEROS_TIME 20 /* cycles */ -#endif - - -/* Generated by tuneup.c, 2000-07-06. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 14 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 179 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 22 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 153 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 46 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 110 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 13 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 4 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 25 -#endif - -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE { 496, 928, 1920, 4608, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD 512 -#endif -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD 3840 -#endif - -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE { 496, 1184, 1920, 5632, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD 512 -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD 3840 -#endif diff --git a/gmp/mpn/x86/pentium/lshift.asm b/gmp/mpn/x86/pentium/lshift.asm deleted file mode 100755 index 22952ff..0000000 Binary files a/gmp/mpn/x86/pentium/lshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/mmx/gmp-mparam.h b/gmp/mpn/x86/pentium/mmx/gmp-mparam.h deleted file mode 100755 index 2379077..0000000 --- a/gmp/mpn/x86/pentium/mmx/gmp-mparam.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Intel P55 gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#define BITS_PER_MP_LIMB 32 -#define BYTES_PER_MP_LIMB 4 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 32 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 - - -#ifndef UMUL_TIME -#define UMUL_TIME 9 /* cycles */ -#endif -#ifndef UDIV_TIME -#define UDIV_TIME 41 /* cycles */ -#endif - -/* bsf takes 18-42 cycles, put an average for uniform random numbers */ -#ifndef COUNT_TRAILING_ZEROS_TIME -#define COUNT_TRAILING_ZEROS_TIME 20 /* cycles */ -#endif - - -/* Generated by tuneup.c, 2000-07-06. */ - -#ifndef KARATSUBA_MUL_THRESHOLD -#define KARATSUBA_MUL_THRESHOLD 14 -#endif -#ifndef TOOM3_MUL_THRESHOLD -#define TOOM3_MUL_THRESHOLD 99 -#endif - -#ifndef KARATSUBA_SQR_THRESHOLD -#define KARATSUBA_SQR_THRESHOLD 22 -#endif -#ifndef TOOM3_SQR_THRESHOLD -#define TOOM3_SQR_THRESHOLD 89 -#endif - -#ifndef BZ_THRESHOLD -#define BZ_THRESHOLD 40 -#endif - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 98 -#endif - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD 13 -#endif - -#ifndef GCD_ACCEL_THRESHOLD -#define GCD_ACCEL_THRESHOLD 5 -#endif -#ifndef GCDEXT_THRESHOLD -#define GCDEXT_THRESHOLD 25 -#endif - -#ifndef FFT_MUL_TABLE -#define FFT_MUL_TABLE { 496, 1056, 1920, 4608, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_MUL_THRESHOLD -#define FFT_MODF_MUL_THRESHOLD 512 -#endif -#ifndef FFT_MUL_THRESHOLD -#define FFT_MUL_THRESHOLD 3840 -#endif - -#ifndef FFT_SQR_TABLE -#define FFT_SQR_TABLE { 496, 1184, 2176, 5632, 14336, 40960, 0 } -#endif -#ifndef FFT_MODF_SQR_THRESHOLD -#define FFT_MODF_SQR_THRESHOLD 512 -#endif -#ifndef FFT_SQR_THRESHOLD -#define FFT_SQR_THRESHOLD 4352 -#endif diff --git a/gmp/mpn/x86/pentium/mmx/lshift.asm b/gmp/mpn/x86/pentium/mmx/lshift.asm deleted file mode 100755 index 1d12e5b..0000000 Binary files a/gmp/mpn/x86/pentium/mmx/lshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/mmx/popham.asm b/gmp/mpn/x86/pentium/mmx/popham.asm deleted file mode 100755 index 809f33f..0000000 Binary files a/gmp/mpn/x86/pentium/mmx/popham.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/mmx/rshift.asm b/gmp/mpn/x86/pentium/mmx/rshift.asm deleted file mode 100755 index e5759b1..0000000 Binary files a/gmp/mpn/x86/pentium/mmx/rshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/mul_1.asm b/gmp/mpn/x86/pentium/mul_1.asm deleted file mode 100755 index da6862e..0000000 Binary files a/gmp/mpn/x86/pentium/mul_1.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/mul_basecase.asm b/gmp/mpn/x86/pentium/mul_basecase.asm deleted file mode 100755 index aef3f47..0000000 Binary files a/gmp/mpn/x86/pentium/mul_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/rshift.asm b/gmp/mpn/x86/pentium/rshift.asm deleted file mode 100755 index 9b10dda..0000000 Binary files a/gmp/mpn/x86/pentium/rshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/pentium/sqr_basecase.asm b/gmp/mpn/x86/pentium/sqr_basecase.asm deleted file mode 100755 index f175808..0000000 Binary files a/gmp/mpn/x86/pentium/sqr_basecase.asm and /dev/null differ diff --git a/gmp/mpn/x86/rshift.asm b/gmp/mpn/x86/rshift.asm deleted file mode 100755 index dfdd72d..0000000 Binary files a/gmp/mpn/x86/rshift.asm and /dev/null differ diff --git a/gmp/mpn/x86/udiv.asm b/gmp/mpn/x86/udiv.asm deleted file mode 100755 index 9f8ca2a..0000000 Binary files a/gmp/mpn/x86/udiv.asm and /dev/null differ diff --git a/gmp/mpn/x86/umul.asm b/gmp/mpn/x86/umul.asm deleted file mode 100755 index 312abf3..0000000 Binary files a/gmp/mpn/x86/umul.asm and /dev/null differ diff --git a/gmp/mpn/x86/x86-defs.m4 b/gmp/mpn/x86/x86-defs.m4 deleted file mode 100755 index bdb061d..0000000 Binary files a/gmp/mpn/x86/x86-defs.m4 and /dev/null differ diff --git a/gmp/mpn/z8000/add_n.s b/gmp/mpn/z8000/add_n.s deleted file mode 100755 index 68e8b9b..0000000 Binary files a/gmp/mpn/z8000/add_n.s and /dev/null differ diff --git a/gmp/mpn/z8000/gmp-mparam.h b/gmp/mpn/z8000/gmp-mparam.h deleted file mode 100755 index 4216df6..0000000 --- a/gmp/mpn/z8000/gmp-mparam.h +++ /dev/null @@ -1,27 +0,0 @@ -/* gmp-mparam.h -- Compiler/machine parameter header file. - -Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#define BITS_PER_MP_LIMB 16 -#define BYTES_PER_MP_LIMB 2 -#define BITS_PER_LONGINT 32 -#define BITS_PER_INT 16 -#define BITS_PER_SHORTINT 16 -#define BITS_PER_CHAR 8 diff --git a/gmp/mpn/z8000/mul_1.s b/gmp/mpn/z8000/mul_1.s deleted file mode 100755 index 7e3bed9..0000000 Binary files a/gmp/mpn/z8000/mul_1.s and /dev/null differ diff --git a/gmp/mpn/z8000/sub_n.s b/gmp/mpn/z8000/sub_n.s deleted file mode 100755 index 2b22dbf..0000000 Binary files a/gmp/mpn/z8000/sub_n.s and /dev/null differ diff --git a/gmp/mpn/z8000x/add_n.s b/gmp/mpn/z8000x/add_n.s deleted file mode 100755 index e01cf2b..0000000 Binary files a/gmp/mpn/z8000x/add_n.s and /dev/null differ diff --git a/gmp/mpn/z8000x/sub_n.s b/gmp/mpn/z8000x/sub_n.s deleted file mode 100755 index 6c96fdf..0000000 Binary files a/gmp/mpn/z8000x/sub_n.s and /dev/null differ diff --git a/gmp/mpq/Makefile.am b/gmp/mpq/Makefile.am deleted file mode 100755 index 16529f6..0000000 Binary files a/gmp/mpq/Makefile.am and /dev/null differ diff --git a/gmp/mpq/Makefile.in b/gmp/mpq/Makefile.in deleted file mode 100755 index 39d7a93..0000000 Binary files a/gmp/mpq/Makefile.in and /dev/null differ diff --git a/gmp/mpq/add.c b/gmp/mpq/add.c deleted file mode 100755 index 5b141f5..0000000 --- a/gmp/mpq/add.c +++ /dev/null @@ -1,85 +0,0 @@ -/* mpq_add -- add two rational numbers. - -Copyright (C) 1991, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_add (mpq_ptr rop, mpq_srcptr op1, mpq_srcptr op2) -#else -mpq_add (rop, op1, op2) - mpq_ptr rop; - mpq_srcptr op1; - mpq_srcptr op2; -#endif -{ - mpz_t gcd; - mpz_t tmp1, tmp2; - mp_size_t op1_num_size = ABS (op1->_mp_num._mp_size); - mp_size_t op1_den_size = ABS (op1->_mp_den._mp_size); - mp_size_t op2_num_size = ABS (op2->_mp_num._mp_size); - mp_size_t op2_den_size = ABS (op2->_mp_den._mp_size); - TMP_DECL (marker); - - TMP_MARK (marker); - MPZ_TMP_INIT (gcd, MIN (op1_den_size, op2_den_size)); - MPZ_TMP_INIT (tmp1, op1_num_size + op2_den_size); - MPZ_TMP_INIT (tmp2, op2_num_size + op1_den_size); - - /* ROP might be identical to either operand, so don't store the - result there until we are finished with the input operands. We - dare to overwrite the numerator of ROP when we are finished - with the numerators of OP1 and OP2. */ - - mpz_gcd (gcd, &(op1->_mp_den), &(op2->_mp_den)); - if (gcd->_mp_size > 1 || gcd->_mp_d[0] != 1) - { - mpz_t t; - - mpz_divexact (tmp1, &(op2->_mp_den), gcd); - mpz_mul (tmp1, &(op1->_mp_num), tmp1); - - mpz_divexact (tmp2, &(op1->_mp_den), gcd); - mpz_mul (tmp2, &(op2->_mp_num), tmp2); - - MPZ_TMP_INIT (t, MAX (ABS (tmp1->_mp_size), ABS (tmp2->_mp_size)) + 1); - - mpz_add (t, tmp1, tmp2); - mpz_divexact (tmp2, &(op1->_mp_den), gcd); - mpz_gcd (gcd, t, gcd); - - mpz_divexact (&(rop->_mp_num), t, gcd); - - mpz_divexact (tmp1, &(op2->_mp_den), gcd); - mpz_mul (&(rop->_mp_den), tmp1, tmp2); - } - else - { - /* The common divisor is 1. This is the case (for random input) with - probability 6/(pi**2). */ - mpz_mul (tmp1, &(op1->_mp_num), &(op2->_mp_den)); - mpz_mul (tmp2, &(op2->_mp_num), &(op1->_mp_den)); - mpz_add (&(rop->_mp_num), tmp1, tmp2); - mpz_mul (&(rop->_mp_den), &(op1->_mp_den), &(op2->_mp_den)); - } - TMP_FREE (marker); -} diff --git a/gmp/mpq/canonicalize.c b/gmp/mpq/canonicalize.c deleted file mode 100755 index 933cb52..0000000 --- a/gmp/mpq/canonicalize.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpq_canonicalize(op) -- Remove common factors of the denominator and - numerator in OP. - -Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_canonicalize (MP_RAT *op) -#else -mpq_canonicalize (op) - MP_RAT *op; -#endif -{ - mpz_t gcd; - TMP_DECL (marker); - - TMP_MARK (marker); - - /* ??? Dunno if the 1+ is needed. */ - MPZ_TMP_INIT (gcd, 1 + MAX (ABS (op->_mp_num._mp_size), - ABS (op->_mp_den._mp_size))); - - mpz_gcd (gcd, &(op->_mp_num), &(op->_mp_den)); - mpz_divexact (&(op->_mp_num), &(op->_mp_num), gcd); - mpz_divexact (&(op->_mp_den), &(op->_mp_den), gcd); - - if (op->_mp_den._mp_size < 0) - { - op->_mp_num._mp_size = -op->_mp_num._mp_size; - op->_mp_den._mp_size = -op->_mp_den._mp_size; - } - TMP_FREE (marker); -} diff --git a/gmp/mpq/clear.c b/gmp/mpq/clear.c deleted file mode 100755 index e29bcfc..0000000 --- a/gmp/mpq/clear.c +++ /dev/null @@ -1,37 +0,0 @@ -/* mpq_clear -- free the space occupied by a MP_RAT. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_clear (MP_RAT *m) -#else -mpq_clear (m) - MP_RAT *m; -#endif -{ - (*_mp_free_func) (m->_mp_num._mp_d, - m->_mp_num._mp_alloc * BYTES_PER_MP_LIMB); - (*_mp_free_func) (m->_mp_den._mp_d, - m->_mp_den._mp_alloc * BYTES_PER_MP_LIMB); -} diff --git a/gmp/mpq/cmp.c b/gmp/mpq/cmp.c deleted file mode 100755 index 43daa03..0000000 --- a/gmp/mpq/cmp.c +++ /dev/null @@ -1,120 +0,0 @@ -/* mpq_cmp(u,v) -- Compare U, V. Return postive, zero, or negative - based on if U > V, U == V, or U < V. - -Copyright (C) 1991, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -int -#if __STDC__ -mpq_cmp (const MP_RAT *op1, const MP_RAT *op2) -#else -mpq_cmp (op1, op2) - const MP_RAT *op1; - const MP_RAT *op2; -#endif -{ - mp_size_t num1_size = op1->_mp_num._mp_size; - mp_size_t den1_size = op1->_mp_den._mp_size; - mp_size_t num2_size = op2->_mp_num._mp_size; - mp_size_t den2_size = op2->_mp_den._mp_size; - mp_size_t tmp1_size, tmp2_size; - mp_ptr tmp1_ptr, tmp2_ptr; - mp_size_t num1_sign; - int cc; - TMP_DECL (marker); - - if (num1_size == 0) - return -num2_size; - if (num2_size == 0) - return num1_size; - if ((num1_size ^ num2_size) < 0) /* I.e. are the signs different? */ - return num1_size; - - num1_sign = num1_size; - num1_size = ABS (num1_size); - num2_size = ABS (num2_size); - - tmp1_size = num1_size + den2_size; - tmp2_size = num2_size + den1_size; - - /* 1. Check to see if we can tell which operand is larger by just looking at - the number of limbs. */ - - /* NUM1 x DEN2 is either TMP1_SIZE limbs or TMP1_SIZE-1 limbs. - Same for NUM1 x DEN1 with respect to TMP2_SIZE. */ - if (tmp1_size > tmp2_size + 1) - /* NUM1 x DEN2 is surely larger in magnitude than NUM2 x DEN1. */ - return num1_sign; - if (tmp2_size > tmp1_size + 1) - /* NUM1 x DEN2 is surely smaller in magnitude than NUM2 x DEN1. */ - return -num1_sign; - - /* 2. Same, but compare the number of significant bits. */ - { - int cnt1, cnt2; - unsigned long int bits1, bits2; - - count_leading_zeros (cnt1, op1->_mp_num._mp_d[num1_size - 1]); - count_leading_zeros (cnt2, op2->_mp_den._mp_d[den2_size - 1]); - bits1 = tmp1_size * BITS_PER_MP_LIMB - cnt1 - cnt2; - - count_leading_zeros (cnt1, op2->_mp_num._mp_d[num2_size - 1]); - count_leading_zeros (cnt2, op1->_mp_den._mp_d[den1_size - 1]); - bits2 = tmp2_size * BITS_PER_MP_LIMB - cnt1 - cnt2; - - if (bits1 > bits2 + 1) - return num1_sign; - if (bits2 > bits1 + 1) - return -num1_sign; - } - - /* 3. Finally, cross multiply and compare. */ - - TMP_MARK (marker); - tmp1_ptr = (mp_ptr) TMP_ALLOC (tmp1_size * BYTES_PER_MP_LIMB); - tmp2_ptr = (mp_ptr) TMP_ALLOC (tmp2_size * BYTES_PER_MP_LIMB); - - if (num1_size >= den2_size) - tmp1_size -= 0 == mpn_mul (tmp1_ptr, - op1->_mp_num._mp_d, num1_size, - op2->_mp_den._mp_d, den2_size); - else - tmp1_size -= 0 == mpn_mul (tmp1_ptr, - op2->_mp_den._mp_d, den2_size, - op1->_mp_num._mp_d, num1_size); - - if (num2_size >= den1_size) - tmp2_size -= 0 == mpn_mul (tmp2_ptr, - op2->_mp_num._mp_d, num2_size, - op1->_mp_den._mp_d, den1_size); - else - tmp2_size -= 0 == mpn_mul (tmp2_ptr, - op1->_mp_den._mp_d, den1_size, - op2->_mp_num._mp_d, num2_size); - - - cc = tmp1_size - tmp2_size != 0 - ? tmp1_size - tmp2_size : mpn_cmp (tmp1_ptr, tmp2_ptr, tmp1_size); - TMP_FREE (marker); - return num1_sign < 0 ? -cc : cc; -} diff --git a/gmp/mpq/cmp_ui.c b/gmp/mpq/cmp_ui.c deleted file mode 100755 index 75f54ed..0000000 --- a/gmp/mpq/cmp_ui.c +++ /dev/null @@ -1,81 +0,0 @@ -/* mpq_cmp_ui(u,vn,vd) -- Compare U with Vn/Vd. Return positive, zero, or - negative based on if U > V, U == V, or U < V. Vn and Vd may have - common factors. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -_mpq_cmp_ui (const MP_RAT *op1, unsigned long int num2, unsigned long int den2) -#else -_mpq_cmp_ui (op1, num2, den2) - const MP_RAT *op1; - unsigned long int num2; - unsigned long int den2; -#endif -{ - mp_size_t num1_size = op1->_mp_num._mp_size; - mp_size_t den1_size = op1->_mp_den._mp_size; - mp_size_t tmp1_size, tmp2_size; - mp_ptr tmp1_ptr, tmp2_ptr; - mp_size_t num1_sign; - mp_limb_t cy_limb; - int cc; - TMP_DECL (marker); - - if (num1_size == 0) - return -(num2 != 0); - if (num1_size < 0) - return num1_size; - if (num2 == 0) - return num1_size; - - num1_sign = num1_size; - num1_size = ABS (num1_size); - - /* NUM1 x DEN2 is either TMP1_SIZE limbs or TMP1_SIZE-1 limbs. - Same for NUM1 x DEN1 with respect to TMP2_SIZE. */ - if (num1_size > den1_size + 1) - /* NUM1 x DEN2 is surely larger in magnitude than NUM2 x DEN1. */ - return num1_sign; - if (den1_size > num1_sign + 1) - /* NUM1 x DEN2 is surely smaller in magnitude than NUM2 x DEN1. */ - return -num1_sign; - - TMP_MARK (marker); - tmp1_ptr = (mp_ptr) TMP_ALLOC ((num1_size + 1) * BYTES_PER_MP_LIMB); - tmp2_ptr = (mp_ptr) TMP_ALLOC ((den1_size + 1) * BYTES_PER_MP_LIMB); - - cy_limb = mpn_mul_1 (tmp1_ptr, op1->_mp_num._mp_d, num1_size, den2); - tmp1_ptr[num1_size] = cy_limb; - tmp1_size = num1_size + (cy_limb != 0); - - cy_limb = mpn_mul_1 (tmp2_ptr, op1->_mp_den._mp_d, den1_size, num2); - tmp2_ptr[den1_size] = cy_limb; - tmp2_size = den1_size + (cy_limb != 0); - - cc = tmp1_size - tmp2_size != 0 - ? tmp1_size - tmp2_size : mpn_cmp (tmp1_ptr, tmp2_ptr, tmp1_size); - TMP_FREE (marker); - return (num1_sign < 0) ? -cc : cc; -} diff --git a/gmp/mpq/div.c b/gmp/mpq/div.c deleted file mode 100755 index 0440426..0000000 --- a/gmp/mpq/div.c +++ /dev/null @@ -1,96 +0,0 @@ -/* mpq_div -- divide two rational numbers. - -Copyright (C) 1991, 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_div (mpq_ptr quot, mpq_srcptr op1, mpq_srcptr op2) -#else -mpq_div (quot, op1, op2) - mpq_ptr quot; - mpq_srcptr op1; - mpq_srcptr op2; -#endif -{ - mpz_t gcd1, gcd2; - mpz_t tmp1, tmp2; - mpz_t numtmp; - - if (op2->_mp_num._mp_size == 0) - DIVIDE_BY_ZERO; - - mpz_init (gcd1); - mpz_init (gcd2); - mpz_init (tmp1); - mpz_init (tmp2); - mpz_init (numtmp); - - /* QUOT might be identical to either operand, so don't store the - result there until we are finished with the input operands. We - dare to overwrite the numerator of QUOT when we are finished - with the numerators of OP1 and OP2. */ - - mpz_gcd (gcd1, &(op1->_mp_num), &(op2->_mp_num)); - mpz_gcd (gcd2, &(op2->_mp_den), &(op1->_mp_den)); - - if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1) - mpz_divexact (tmp1, &(op1->_mp_num), gcd1); - else - mpz_set (tmp1, &(op1->_mp_num)); - - if (gcd2->_mp_size > 1 || gcd2->_mp_d[0] != 1) - mpz_divexact (tmp2, &(op2->_mp_den), gcd2); - else - mpz_set (tmp2, &(op2->_mp_den)); - - mpz_mul (numtmp, tmp1, tmp2); - - if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1) - mpz_divexact (tmp1, &(op2->_mp_num), gcd1); - else - mpz_set (tmp1, &(op2->_mp_num)); - - if (gcd2->_mp_size > 1 || gcd2->_mp_d[0] != 1) - mpz_divexact (tmp2, &(op1->_mp_den), gcd2); - else - mpz_set (tmp2, &(op1->_mp_den)); - - mpz_mul (&(quot->_mp_den), tmp1, tmp2); - - /* We needed to go via NUMTMP to take care of QUOT being the same - as either input operands. Now move NUMTMP to QUOT->_mp_num. */ - mpz_set (&(quot->_mp_num), numtmp); - - /* Keep the denominator positive. */ - if (quot->_mp_den._mp_size < 0) - { - quot->_mp_den._mp_size = -quot->_mp_den._mp_size; - quot->_mp_num._mp_size = -quot->_mp_num._mp_size; - } - - mpz_clear (numtmp); - mpz_clear (tmp2); - mpz_clear (tmp1); - mpz_clear (gcd2); - mpz_clear (gcd1); -} diff --git a/gmp/mpq/equal.c b/gmp/mpq/equal.c deleted file mode 100755 index c19134d..0000000 --- a/gmp/mpq/equal.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpq_equal(u,v) -- Compare U, V. Return non-zero if they are equal, zero - if they are non-equal. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpq_equal (mpq_srcptr op1, mpq_srcptr op2) -#else -mpq_equal (op1, op2) - mpq_srcptr op1; - mpq_srcptr op2; -#endif -{ - mp_size_t num1_size = op1->_mp_num._mp_size; - mp_size_t den1_size = op1->_mp_den._mp_size; - mp_size_t num2_size = op2->_mp_num._mp_size; - mp_size_t den2_size = op2->_mp_den._mp_size; - - return (num1_size == num2_size && den1_size == den2_size - && mpn_cmp (op1->_mp_num._mp_d, op2->_mp_num._mp_d, ABS (num1_size)) == 0 - && mpn_cmp (op1->_mp_den._mp_d, op2->_mp_den._mp_d, den1_size) == 0); -} diff --git a/gmp/mpq/get_d.c b/gmp/mpq/get_d.c deleted file mode 100755 index 4497fd3..0000000 --- a/gmp/mpq/get_d.c +++ /dev/null @@ -1,165 +0,0 @@ -/* double mpq_get_d (mpq_t src) -- Return the double approximation to SRC. - -Copyright (C) 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* Algorithm: - 1. Develop >= n bits of src.num / src.den, where n is the number of bits - in a double. This (partial) division will use all bits from the - denominator. - 2. Use the remainder to determine how to round the result. - 3. Assign the integral result to a temporary double. - 4. Scale the temporary double, and return the result. - - An alternative algorithm, that would be faster: - 0. Let n be somewhat larger than the number of significant bits in a double. - 1. Extract the most significant n bits of the denominator, and an equal - number of bits from the numerator. - 2. Interpret the extracted numbers as integers, call them a and b - respectively, and develop n bits of the fractions ((a + 1) / b) and - (a / (b + 1)) using mpn_divrem. - 3. If the computed values are identical UP TO THE POSITION WE CARE ABOUT, - we are done. If they are different, repeat the algorithm from step 1, - but first let n = n * 2. - 4. If we end up using all bits from the numerator and denominator, fall - back to the first algorithm above. - 5. Just to make life harder, The computation of a + 1 and b + 1 above - might give carry-out... Needs special handling. It might work to - subtract 1 in both cases instead. -*/ - -double -#if __STDC__ -mpq_get_d (const MP_RAT *src) -#else -mpq_get_d (src) - const MP_RAT *src; -#endif -{ - mp_ptr np, dp; - mp_ptr rp; - mp_size_t nsize = src->_mp_num._mp_size; - mp_size_t dsize = src->_mp_den._mp_size; - mp_size_t qsize, rsize; - mp_size_t sign_quotient = nsize ^ dsize; - unsigned normalization_steps; - mp_limb_t qlimb; -#define N_QLIMBS (1 + (sizeof (double) + BYTES_PER_MP_LIMB-1) / BYTES_PER_MP_LIMB) - mp_limb_t qarr[N_QLIMBS + 1]; - mp_ptr qp = qarr; - TMP_DECL (marker); - - if (nsize == 0) - return 0.0; - - TMP_MARK (marker); - nsize = ABS (nsize); - dsize = ABS (dsize); - np = src->_mp_num._mp_d; - dp = src->_mp_den._mp_d; - - rsize = dsize + N_QLIMBS; - rp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB); - - count_leading_zeros (normalization_steps, dp[dsize - 1]); - - /* Normalize the denominator, i.e. make its most significant bit set by - shifting it NORMALIZATION_STEPS bits to the left. Also shift the - numerator the same number of steps (to keep the quotient the same!). */ - if (normalization_steps != 0) - { - mp_ptr tp; - mp_limb_t nlimb; - - /* Shift up the denominator setting the most significant bit of - the most significant limb. Use temporary storage not to clobber - the original contents of the denominator. */ - tp = (mp_ptr) TMP_ALLOC (dsize * BYTES_PER_MP_LIMB); - mpn_lshift (tp, dp, dsize, normalization_steps); - dp = tp; - - if (rsize > nsize) - { - MPN_ZERO (rp, rsize - nsize); - nlimb = mpn_lshift (rp + (rsize - nsize), - np, nsize, normalization_steps); - } - else - { - nlimb = mpn_lshift (rp, np + (nsize - rsize), - rsize, normalization_steps); - } - if (nlimb != 0) - { - rp[rsize] = nlimb; - rsize++; - } - } - else - { - if (rsize > nsize) - { - MPN_ZERO (rp, rsize - nsize); - MPN_COPY (rp + (rsize - nsize), np, nsize); - } - else - { - MPN_COPY (rp, np + (nsize - rsize), rsize); - } - } - - qlimb = mpn_divmod (qp, rp, rsize, dp, dsize); - qsize = rsize - dsize; - if (qlimb) - { - qp[qsize] = qlimb; - qsize++; - } - - { - double res; - mp_size_t i; - int scale = nsize - dsize - N_QLIMBS; - -#if defined (__vax__) - /* Ignore excess quotient limbs. This is necessary on a vax - with its small double exponent, since we'd otherwise get - exponent overflow while forming RES. */ - if (qsize > N_QLIMBS) - { - qp += qsize - N_QLIMBS; - scale += qsize - N_QLIMBS; - qsize = N_QLIMBS; - } -#endif - - res = qp[qsize - 1]; - for (i = qsize - 2; i >= 0; i--) - res = res * MP_BASE_AS_DOUBLE + qp[i]; - - res = __gmp_scale2 (res, BITS_PER_MP_LIMB * scale); - - TMP_FREE (marker); - return sign_quotient >= 0 ? res : -res; - } -} diff --git a/gmp/mpq/get_den.c b/gmp/mpq/get_den.c deleted file mode 100755 index 7c33e6f..0000000 --- a/gmp/mpq/get_den.c +++ /dev/null @@ -1,41 +0,0 @@ -/* mpq_get_den(den,rat_src) -- Set DEN to the denominator of RAT_SRC. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_get_den (MP_INT *den, const MP_RAT *src) -#else -mpq_get_den (den, src) - MP_INT *den; - const MP_RAT *src; -#endif -{ - mp_size_t size = src->_mp_den._mp_size; - - if (den->_mp_alloc < size) - _mpz_realloc (den, size); - - MPN_COPY (den->_mp_d, src->_mp_den._mp_d, size); - den->_mp_size = size; -} diff --git a/gmp/mpq/get_num.c b/gmp/mpq/get_num.c deleted file mode 100755 index 3df0a4a..0000000 --- a/gmp/mpq/get_num.c +++ /dev/null @@ -1,42 +0,0 @@ - /* mpq_get_num(num,rat_src) -- Set NUM to the numerator of RAT_SRC. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_get_num (MP_INT *num, const MP_RAT *src) -#else -mpq_get_num (num, src) - MP_INT *num; - const MP_RAT *src; -#endif -{ - mp_size_t size = src->_mp_num._mp_size; - mp_size_t abs_size = ABS (size); - - if (num->_mp_alloc < abs_size) - _mpz_realloc (num, abs_size); - - MPN_COPY (num->_mp_d, src->_mp_num._mp_d, abs_size); - num->_mp_size = size; -} diff --git a/gmp/mpq/init.c b/gmp/mpq/init.c deleted file mode 100755 index bd86bb3..0000000 --- a/gmp/mpq/init.c +++ /dev/null @@ -1,40 +0,0 @@ -/* mpq_init -- Make a new rational number with value 0/1. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_init (MP_RAT *x) -#else -mpq_init (x) - MP_RAT *x; -#endif -{ - x->_mp_num._mp_alloc = 1; - x->_mp_num._mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - x->_mp_num._mp_size = 0; - x->_mp_den._mp_alloc = 1; - x->_mp_den._mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - x->_mp_den._mp_d[0] = 1; - x->_mp_den._mp_size = 1; -} diff --git a/gmp/mpq/inv.c b/gmp/mpq/inv.c deleted file mode 100755 index 66bc33a..0000000 --- a/gmp/mpq/inv.c +++ /dev/null @@ -1,75 +0,0 @@ -/* mpq_inv(dest,src) -- invert a rational number, i.e. set DEST to SRC - with the numerator and denominator swapped. - -Copyright (C) 1991, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_inv (MP_RAT *dest, const MP_RAT *src) -#else -mpq_inv (dest, src) - MP_RAT *dest; - const MP_RAT *src; -#endif -{ - mp_size_t num_size = src->_mp_num._mp_size; - mp_size_t den_size = src->_mp_den._mp_size; - - if (num_size == 0) - DIVIDE_BY_ZERO; - - if (num_size < 0) - { - num_size = -num_size; - den_size = -den_size; - } - dest->_mp_den._mp_size = num_size; - dest->_mp_num._mp_size = den_size; - - /* If dest == src we may just swap the numerator and denominator, but - we have to ensure the new denominator is positive. */ - - if (dest == src) - { - mp_size_t alloc = dest->_mp_num._mp_alloc; - mp_ptr limb_ptr = dest->_mp_num._mp_d; - - dest->_mp_num._mp_alloc = dest->_mp_den._mp_alloc; - dest->_mp_num._mp_d = dest->_mp_den._mp_d; - - dest->_mp_den._mp_alloc = alloc; - dest->_mp_den._mp_d = limb_ptr; - } - else - { - den_size = ABS (den_size); - if (dest->_mp_num._mp_alloc < den_size) - _mpz_realloc (&(dest->_mp_num), den_size); - - if (dest->_mp_den._mp_alloc < num_size) - _mpz_realloc (&(dest->_mp_den), num_size); - - MPN_COPY (dest->_mp_num._mp_d, src->_mp_den._mp_d, den_size); - MPN_COPY (dest->_mp_den._mp_d, src->_mp_num._mp_d, num_size); - } -} diff --git a/gmp/mpq/mul.c b/gmp/mpq/mul.c deleted file mode 100755 index 9b8abc2..0000000 --- a/gmp/mpq/mul.c +++ /dev/null @@ -1,79 +0,0 @@ -/* mpq_mul -- mutiply two rational numbers. - -Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_mul (mpq_ptr prod, mpq_srcptr op1, mpq_srcptr op2) -#else -mpq_mul (prod, op1, op2) - mpq_ptr prod; - mpq_srcptr op1; - mpq_srcptr op2; -#endif -{ - mpz_t gcd1, gcd2; - mpz_t tmp1, tmp2; - - mpz_init (gcd1); - mpz_init (gcd2); - mpz_init (tmp1); - mpz_init (tmp2); - - /* PROD might be identical to either operand, so don't store the - result there until we are finished with the input operands. We - dare to overwrite the numerator of PROD when we are finished - with the numerators of OP1 and OP2. */ - - mpz_gcd (gcd1, &(op1->_mp_num), &(op2->_mp_den)); - mpz_gcd (gcd2, &(op2->_mp_num), &(op1->_mp_den)); - - if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1) - mpz_divexact (tmp1, &(op1->_mp_num), gcd1); - else - mpz_set (tmp1, &(op1->_mp_num)); - - if (gcd2->_mp_size > 1 || gcd2->_mp_d[0] != 1) - mpz_divexact (tmp2, &(op2->_mp_num), gcd2); - else - mpz_set (tmp2, &(op2->_mp_num)); - - mpz_mul (&(prod->_mp_num), tmp1, tmp2); - - if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1) - mpz_divexact (tmp1, &(op2->_mp_den), gcd1); - else - mpz_set (tmp1, &(op2->_mp_den)); - - if (gcd2->_mp_size > 1 || gcd2->_mp_d[0] != 1) - mpz_divexact (tmp2, &(op1->_mp_den), gcd2); - else - mpz_set (tmp2, &(op1->_mp_den)); - - mpz_mul (&(prod->_mp_den), tmp1, tmp2); - - mpz_clear (tmp2); - mpz_clear (tmp1); - mpz_clear (gcd2); - mpz_clear (gcd1); -} diff --git a/gmp/mpq/neg.c b/gmp/mpq/neg.c deleted file mode 100755 index e7da160..0000000 --- a/gmp/mpq/neg.c +++ /dev/null @@ -1,36 +0,0 @@ -/* mpq_neg(dst, src) -- Assign the negated value of SRC to DST. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_neg (MP_RAT *dst, const MP_RAT *src) -#else -mpq_neg (dst, src) - MP_RAT *dst; - const MP_RAT *src; -#endif -{ - mpz_neg (&dst->_mp_num, &src->_mp_num); - mpz_set (&dst->_mp_den, &src->_mp_den); -} diff --git a/gmp/mpq/out_str.c b/gmp/mpq/out_str.c deleted file mode 100755 index 6898dfa..0000000 --- a/gmp/mpq/out_str.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpq_out_str(stream,base,integer) */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - - -size_t -#if __STDC__ -mpq_out_str (FILE *stream, int base, mpq_srcptr q) -#else -mpq_out_str (stream, base, q) - FILE *stream; - int base; - mpq_srcptr q; -#endif -{ - size_t written; - - if (stream == NULL) - stream = stdout; - - written = mpz_out_str (stream, base, mpq_numref (q)); - - if (mpz_cmp_ui (mpq_denref (q), 1) != 0) - { - putc ('/', stream); - written += 1 + mpz_out_str (stream, base, mpq_denref (q)); - } - - return ferror (stream) ? 0 : written; -} diff --git a/gmp/mpq/set.c b/gmp/mpq/set.c deleted file mode 100755 index bad0da2..0000000 --- a/gmp/mpq/set.c +++ /dev/null @@ -1,49 +0,0 @@ -/* mpq_set(dest,src) -- Set DEST to SRC. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_set (MP_RAT *dest, const MP_RAT *src) -#else -mpq_set (dest, src) - MP_RAT *dest; - const MP_RAT *src; -#endif -{ - mp_size_t num_size, den_size; - mp_size_t abs_num_size; - - num_size = src->_mp_num._mp_size; - abs_num_size = ABS (num_size); - if (dest->_mp_num._mp_alloc < abs_num_size) - _mpz_realloc (&(dest->_mp_num), abs_num_size); - MPN_COPY (dest->_mp_num._mp_d, src->_mp_num._mp_d, abs_num_size); - dest->_mp_num._mp_size = num_size; - - den_size = src->_mp_den._mp_size; - if (dest->_mp_den._mp_alloc < den_size) - _mpz_realloc (&(dest->_mp_den), den_size); - MPN_COPY (dest->_mp_den._mp_d, src->_mp_den._mp_d, den_size); - dest->_mp_den._mp_size = den_size; -} diff --git a/gmp/mpq/set_d.c b/gmp/mpq/set_d.c deleted file mode 100755 index 7ccc741..0000000 --- a/gmp/mpq/set_d.c +++ /dev/null @@ -1,139 +0,0 @@ -/* mpq_set_d(mpq_t q, double d) -- Set q to d without rounding. - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#if BITS_PER_MP_LIMB != 32 && BITS_PER_MP_LIMB != 64 -This file does not handle any the used BITS_PER_MP_LIMB. -#endif - -void -#if __STDC__ -mpq_set_d (mpq_ptr dest, double d) -#else -mpq_set_d (dest, d) - mpq_ptr dest; - double d; -#endif -{ - int negative; - mp_exp_t exp; - mp_limb_t tp[3]; - mp_ptr np, dp; - mp_size_t nn, dn; - int c; - - negative = d < 0; - d = ABS (d); - - exp = __gmp_extract_double (tp, d); - - /* There are two main version of the conversion. The `then' arm handles - things that have a fractional part, while the `else' part handles - only integers. */ -#if BITS_PER_MP_LIMB == 32 - if (exp <= 1 || (exp == 2 && tp[0] != 0)) -#else - if (exp <= 1) -#endif - { - if (d == 0.0) - { - SIZ(&(dest->_mp_num)) = 0; - SIZ(&(dest->_mp_den)) = 1; - PTR(&(dest->_mp_den))[0] = 1; - return; - } - - dn = -exp; - if (dest->_mp_num._mp_alloc < 3) - _mpz_realloc (&(dest->_mp_num), 3); - np = PTR(&(dest->_mp_num)); -#if BITS_PER_MP_LIMB == 32 - if ((tp[0] | tp[1]) == 0) - np[0] = tp[2], nn = 1; - else if (tp[0] == 0) - np[1] = tp[2], np[0] = tp[1], nn = 2; - else - np[2] = tp[2], np[1] = tp[1], np[0] = tp[0], nn = 3; -#else - if (tp[0] == 0) - np[0] = tp[1], nn = 1; - else - np[1] = tp[1], np[0] = tp[0], nn = 2; -#endif - dn += nn + 1; - if (dest->_mp_den._mp_alloc < dn) - _mpz_realloc (&(dest->_mp_den), dn); - dp = PTR(&(dest->_mp_den)); - MPN_ZERO (dp, dn - 1); - dp[dn - 1] = 1; - count_trailing_zeros (c, np[0] | dp[0]); - if (c != 0) - { - mpn_rshift (np, np, nn, c); - nn -= np[nn - 1] == 0; - mpn_rshift (dp, dp, dn, c); - dn -= dp[dn - 1] == 0; - } - SIZ(&(dest->_mp_den)) = dn; - SIZ(&(dest->_mp_num)) = negative ? -nn : nn; - } - else - { - nn = exp; - if (dest->_mp_num._mp_alloc < nn) - _mpz_realloc (&(dest->_mp_num), nn); - np = PTR(&(dest->_mp_num)); -#if BITS_PER_MP_LIMB == 32 - switch (nn) - { - default: - MPN_ZERO (np, nn - 3); - np += nn - 3; - /* fall through */ - case 3: - np[2] = tp[2], np[1] = tp[1], np[0] = tp[0]; - break; - case 2: - np[1] = tp[2], np[0] = tp[1]; - break; - } -#else - switch (nn) - { - default: - MPN_ZERO (np, nn - 2); - np += nn - 2; - /* fall through */ - case 2: - np[1] = tp[1], np[0] = tp[0]; - break; - } -#endif - dp = PTR(&(dest->_mp_den)); - dp[0] = 1; - SIZ(&(dest->_mp_den)) = 1; - SIZ(&(dest->_mp_num)) = negative ? -nn : nn; - } -} diff --git a/gmp/mpq/set_den.c b/gmp/mpq/set_den.c deleted file mode 100755 index 561f626..0000000 --- a/gmp/mpq/set_den.c +++ /dev/null @@ -1,42 +0,0 @@ -/* mpq_set_den(dest,den) -- Set the denominator of DEST from DEN. - -Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_set_den (MP_RAT *dest, const MP_INT *den) -#else -mpq_set_den (dest, den) - MP_RAT *dest; - const MP_INT *den; -#endif -{ - mp_size_t size = den->_mp_size; - mp_size_t abs_size = ABS (size); - - if (dest->_mp_den._mp_alloc < abs_size) - _mpz_realloc (&(dest->_mp_den), abs_size); - - MPN_COPY (dest->_mp_den._mp_d, den->_mp_d, abs_size); - dest->_mp_den._mp_size = abs_size; -} diff --git a/gmp/mpq/set_num.c b/gmp/mpq/set_num.c deleted file mode 100755 index 0fab008..0000000 --- a/gmp/mpq/set_num.c +++ /dev/null @@ -1,42 +0,0 @@ -/* mpq_set_num(dest,num) -- Set the numerator of DEST from NUM. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_set_num (MP_RAT *dest, const MP_INT *num) -#else -mpq_set_num (dest, num) - MP_RAT *dest; - const MP_INT *num; -#endif -{ - mp_size_t size = num->_mp_size; - mp_size_t abs_size = ABS (size); - - if (dest->_mp_num._mp_alloc < abs_size) - _mpz_realloc (&(dest->_mp_num), abs_size); - - MPN_COPY (dest->_mp_num._mp_d, num->_mp_d, abs_size); - dest->_mp_num._mp_size = size; -} diff --git a/gmp/mpq/set_si.c b/gmp/mpq/set_si.c deleted file mode 100755 index 8e5b084..0000000 --- a/gmp/mpq/set_si.c +++ /dev/null @@ -1,54 +0,0 @@ -/* mpq_set_si(dest,ulong_num,ulong_den) -- Set DEST to the retional number - ULONG_NUM/ULONG_DEN. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_set_si (MP_RAT *dest, signed long int num, unsigned long int den) -#else -mpq_set_si (dest, num, den) - MP_RAT *dest; - signed long int num; - unsigned long int den; -#endif -{ - unsigned long int abs_num; - - abs_num = ABS (num); - - if (num == 0) - { - /* Canonicalize 0/d to 0/1. */ - den = 1; - dest->_mp_num._mp_size = 0; - } - else - { - dest->_mp_num._mp_d[0] = abs_num; - dest->_mp_num._mp_size = num > 0 ? 1 : -1; - } - - dest->_mp_den._mp_d[0] = den; - dest->_mp_den._mp_size = 1; -} diff --git a/gmp/mpq/set_ui.c b/gmp/mpq/set_ui.c deleted file mode 100755 index 2c5f73f..0000000 --- a/gmp/mpq/set_ui.c +++ /dev/null @@ -1,50 +0,0 @@ -/* mpq_set_ui(dest,ulong_num,ulong_den) -- Set DEST to the retional number - ULONG_NUM/ULONG_DEN. - -Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_set_ui (MP_RAT *dest, unsigned long int num, unsigned long int den) -#else -mpq_set_ui (dest, num, den) - MP_RAT *dest; - unsigned long int num; - unsigned long int den; -#endif -{ - if (num == 0) - { - /* Canonicalize 0/n to 0/1. */ - den = 1; - dest->_mp_num._mp_size = 0; - } - else - { - dest->_mp_num._mp_d[0] = num; - dest->_mp_num._mp_size = 1; - } - - dest->_mp_den._mp_d[0] = den; - dest->_mp_den._mp_size = 1; -} diff --git a/gmp/mpq/set_z.c b/gmp/mpq/set_z.c deleted file mode 100755 index 347c67d..0000000 --- a/gmp/mpq/set_z.c +++ /dev/null @@ -1,46 +0,0 @@ -/* mpq_set_z (dest,src) -- Set DEST to SRC. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_set_z (mpq_ptr dest, mpz_srcptr src) -#else -mpq_set_z (dest, src) - mpq_ptr dest; - mpz_srcptr src; -#endif -{ - mp_size_t num_size; - mp_size_t abs_num_size; - - num_size = src->_mp_size; - abs_num_size = ABS (num_size); - if (dest->_mp_num._mp_alloc < abs_num_size) - _mpz_realloc (&(dest->_mp_num), abs_num_size); - MPN_COPY (dest->_mp_num._mp_d, src->_mp_d, abs_num_size); - dest->_mp_num._mp_size = num_size; - - dest->_mp_den._mp_d[0] = 1; - dest->_mp_den._mp_size = 1; -} diff --git a/gmp/mpq/sub.c b/gmp/mpq/sub.c deleted file mode 100755 index f6ef770..0000000 --- a/gmp/mpq/sub.c +++ /dev/null @@ -1,85 +0,0 @@ -/* mpq_sub -- subtract two rational numbers. - -Copyright (C) 1991, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_sub (mpq_ptr rop, mpq_srcptr op1, mpq_srcptr op2) -#else -mpq_sub (rop, op1, op2) - mpq_ptr rop; - mpq_srcptr op1; - mpq_srcptr op2; -#endif -{ - mpz_t gcd; - mpz_t tmp1, tmp2; - mp_size_t op1_num_size = ABS (op1->_mp_num._mp_size); - mp_size_t op1_den_size = ABS (op1->_mp_den._mp_size); - mp_size_t op2_num_size = ABS (op2->_mp_num._mp_size); - mp_size_t op2_den_size = ABS (op2->_mp_den._mp_size); - TMP_DECL (marker); - - TMP_MARK (marker); - MPZ_TMP_INIT (gcd, MIN (op1_den_size, op2_den_size)); - MPZ_TMP_INIT (tmp1, op1_num_size + op2_den_size); - MPZ_TMP_INIT (tmp2, op2_num_size + op1_den_size); - - /* ROP might be identical to either operand, so don't store the - result there until we are finished with the input operands. We - dare to overwrite the numerator of ROP when we are finished - with the numerators of OP1 and OP2. */ - - mpz_gcd (gcd, &(op1->_mp_den), &(op2->_mp_den)); - if (gcd->_mp_size > 1 || gcd->_mp_d[0] != 1) - { - mpz_t t; - - mpz_divexact (tmp1, &(op2->_mp_den), gcd); - mpz_mul (tmp1, &(op1->_mp_num), tmp1); - - mpz_divexact (tmp2, &(op1->_mp_den), gcd); - mpz_mul (tmp2, &(op2->_mp_num), tmp2); - - MPZ_TMP_INIT (t, MAX (ABS (tmp1->_mp_size), ABS (tmp2->_mp_size)) + 1); - - mpz_sub (t, tmp1, tmp2); - mpz_divexact (tmp2, &(op1->_mp_den), gcd); - mpz_gcd (gcd, t, gcd); - - mpz_divexact (&(rop->_mp_num), t, gcd); - - mpz_divexact (tmp1, &(op2->_mp_den), gcd); - mpz_mul (&(rop->_mp_den), tmp1, tmp2); - } - else - { - /* The common divisor is 1. This is the case (for random input) with - probability 6/(pi**2). */ - mpz_mul (tmp1, &(op1->_mp_num), &(op2->_mp_den)); - mpz_mul (tmp2, &(op2->_mp_num), &(op1->_mp_den)); - mpz_sub (&(rop->_mp_num), tmp1, tmp2); - mpz_mul (&(rop->_mp_den), &(op1->_mp_den), &(op2->_mp_den)); - } - TMP_FREE (marker); -} diff --git a/gmp/mpq/swap.c b/gmp/mpq/swap.c deleted file mode 100755 index 431a637..0000000 --- a/gmp/mpq/swap.c +++ /dev/null @@ -1,68 +0,0 @@ -/* mpq_swap (U, V) -- Swap U and V. - -Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpq_swap (mpq_ptr u, mpq_ptr v) -#else -mpq_swap (u, v) - mpq_ptr u; - mpq_ptr v; -#endif -{ - mp_ptr up, vp; - mp_size_t usize, vsize; - mp_size_t ualloc, valloc; - - ualloc = u->_mp_num._mp_alloc; - valloc = v->_mp_num._mp_alloc; - v->_mp_num._mp_alloc = ualloc; - u->_mp_num._mp_alloc = valloc; - - usize = u->_mp_num._mp_size; - vsize = v->_mp_num._mp_size; - v->_mp_num._mp_size = usize; - u->_mp_num._mp_size = vsize; - - up = u->_mp_num._mp_d; - vp = v->_mp_num._mp_d; - v->_mp_num._mp_d = up; - u->_mp_num._mp_d = vp; - - - ualloc = u->_mp_den._mp_alloc; - valloc = v->_mp_den._mp_alloc; - v->_mp_den._mp_alloc = ualloc; - u->_mp_den._mp_alloc = valloc; - - usize = u->_mp_den._mp_size; - vsize = v->_mp_den._mp_size; - v->_mp_den._mp_size = usize; - u->_mp_den._mp_size = vsize; - - up = u->_mp_den._mp_d; - vp = v->_mp_den._mp_d; - v->_mp_den._mp_d = up; - u->_mp_den._mp_d = vp; -} diff --git a/gmp/mpq/tests/Makefile.am b/gmp/mpq/tests/Makefile.am deleted file mode 100755 index 67d33d7..0000000 Binary files a/gmp/mpq/tests/Makefile.am and /dev/null differ diff --git a/gmp/mpq/tests/Makefile.in b/gmp/mpq/tests/Makefile.in deleted file mode 100755 index d2bc415..0000000 Binary files a/gmp/mpq/tests/Makefile.in and /dev/null differ diff --git a/gmp/mpq/tests/t-cmp.c b/gmp/mpq/tests/t-cmp.c deleted file mode 100755 index 3ecbf56..0000000 --- a/gmp/mpq/tests/t-cmp.c +++ /dev/null @@ -1,109 +0,0 @@ -/* Test mpq_cmp. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#define NUM(x) (&((x)->_mp_num)) -#define DEN(x) (&((x)->_mp_den)) - -#define SGN(x) ((x) < 0 ? -1 : (x) > 0 ? 1 : 0) - -ref_mpq_cmp (a, b) - mpq_t a, b; -{ - mpz_t ai, bi; - int cc; - - mpz_init (ai); - mpz_init (bi); - - mpz_mul (ai, NUM (a), DEN (b)); - mpz_mul (bi, NUM (b), DEN (a)); - cc = mpz_cmp (ai, bi); - mpz_clear (ai); - mpz_clear (bi); - return cc; -} - -#ifndef SIZE -#define SIZE 8 /* increasing this lowers the probabilty of finding an error */ -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpq_t a, b; - mp_size_t size; - int reps = 100000; - int i; - int cc, ccref; - - if (argc == 2) - reps = atoi (argv[1]); - - mpq_init (a); - mpq_init (b); - - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (NUM (a), size); - do - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (DEN (a), size); - } - while (mpz_cmp_ui (DEN (a), 0) == 0); - - size = urandom () % SIZE - SIZE/2; - mpz_random2 (NUM (b), size); - do - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (DEN (b), size); - } - while (mpz_cmp_ui (DEN (b), 0) == 0); - - mpq_canonicalize (a); - mpq_canonicalize (b); - - ccref = ref_mpq_cmp (a, b); - cc = mpq_cmp (a, b); - - if (SGN (ccref) != SGN (cc)) - abort (); - } - - exit (0); -} - -dump (x) - mpq_t x; -{ - mpz_out_str (stdout, 10, NUM (x)); - printf ("/"); - mpz_out_str (stdout, 10, DEN (x)); - printf ("\n"); -} diff --git a/gmp/mpq/tests/t-cmp_ui.c b/gmp/mpq/tests/t-cmp_ui.c deleted file mode 100755 index 4f26790..0000000 --- a/gmp/mpq/tests/t-cmp_ui.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Test mpq_cmp_ui. - -Copyright (C) 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#define NUM(x) (&((x)->_mp_num)) -#define DEN(x) (&((x)->_mp_den)) - -#define SGN(x) ((x) < 0 ? -1 : (x) > 0 ? 1 : 0) - -ref_mpq_cmp_ui (a, bn, bd) - mpq_t a; - unsigned long int bn, bd; -{ - mpz_t ai, bi; - int cc; - - mpz_init (ai); - mpz_init (bi); - - mpz_mul_ui (ai, NUM (a), bd); - mpz_mul_ui (bi, DEN (a), bn); - cc = mpz_cmp (ai, bi); - mpz_clear (ai); - mpz_clear (bi); - return cc; -} - -#ifndef SIZE -#define SIZE 8 /* increasing this lowers the probabilty of finding an error */ -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpq_t a, b; - mp_size_t size; - int reps = 100000; - int i; - int cc, ccref; - unsigned long int bn, bd; - - if (argc == 2) - reps = atoi (argv[1]); - - mpq_init (a); - mpq_init (b); - - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (NUM (a), size); - do - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (DEN (a), size); - } - while (mpz_cmp_ui (DEN (a), 0) == 0); - - mpz_random2 (NUM (b), 1); - mpz_mod_ui (NUM (b), NUM (b), ~(unsigned long int) 0); - mpz_add_ui (NUM (b), NUM (b), 1); - - mpz_random2 (DEN (b), 1); - mpz_mod_ui (DEN (b), DEN (b), ~(unsigned long int) 0); - mpz_add_ui (DEN (b), DEN (b), 1); - - mpq_canonicalize (a); - mpq_canonicalize (b); - - bn = mpz_get_ui (NUM (b)); - bd = mpz_get_ui (DEN (b)); - - ccref = ref_mpq_cmp_ui (a, bn, bd); - cc = mpq_cmp_ui (a, bn, bd); - - if (SGN (ccref) != SGN (cc)) - abort (); - } - - exit (0); -} diff --git a/gmp/mpq/tests/t-get_d.c b/gmp/mpq/tests/t-get_d.c deleted file mode 100755 index 97f4000..0000000 --- a/gmp/mpq/tests/t-get_d.c +++ /dev/null @@ -1,132 +0,0 @@ -/* Test mpq_get_d and mpq_set_d - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 8 -#endif - -#if defined (__vax__) && SIZE > 4 -#undef SIZE -#define SIZE 4 -#endif - -void -MPQ_CHECK_FORMAT (q) - mpq_t q; -{ - mp_size_t n; - - n = ABSIZ (mpq_numref (q)); - if (n != 0) - ASSERT_ALWAYS (PTR(mpq_numref(q))[n - 1] != 0); - - n = ABSIZ (mpq_denref (q)); - if (n != 0) - ASSERT_ALWAYS (PTR(mpq_denref(q))[n - 1] != 0); -} - -main (argc, argv) - int argc; - char **argv; -{ - mpq_t a; - mp_size_t size; - int reps = 1000; - int i, j; - double last_d, new_d; - mpq_t qlast_d, qnew_d; - mpq_t eps; - - if (argc == 2) - reps = atoi (argv[1]); - - /* The idea here is to test the monotonousness of mpq_get_d by adding - numbers to the numerator and denominator. */ - - mpq_init (a); - mpq_init (eps); - mpq_init (qlast_d); - mpq_init (qnew_d); - - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (mpq_numref (a), size); - do - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (mpq_denref (a), size); - } - while (mpz_cmp_ui (mpq_denref (a), 0) == 0); - - mpq_canonicalize (a); - - last_d = mpq_get_d (a); - mpq_set_d (qlast_d, last_d); - for (j = 0; j < 10; j++) - { - size = urandom () % SIZE + 1; - mpz_random2 (mpq_numref (eps), size); - size = urandom () % SIZE + 1; - mpz_random2 (mpq_denref (eps), size); - mpq_canonicalize (eps); - - mpq_add (a, a, eps); - mpq_canonicalize (a); - new_d = mpq_get_d (a); - if (last_d > new_d) - { - fprintf (stderr, "ERROR (test %d/%d): bad mpq_get_d results\n", i, j); - printf ("\nlast: %f\n ", last_d); - printf (" new: %f\n ", new_d); dump (a); - abort (); - } - mpq_set_d (qnew_d, new_d); - MPQ_CHECK_FORMAT (qnew_d); - if (mpq_cmp (qlast_d, qnew_d) > 0) - { - fprintf (stderr, - "ERROR (test %d/%d): bad mpq_set_d results\n", i, j); - printf ("\nlast: %f\n ", last_d); dump (qlast_d); - printf (" new: %f\n ", new_d); dump (qnew_d); - abort (); - } - last_d = new_d; - mpq_set (qlast_d, qnew_d); - } - } - - exit (0); -} - -dump (x) - mpq_t x; -{ - mpz_out_str (stdout, 10, mpq_numref (x)); - printf ("/"); - mpz_out_str (stdout, 10, mpq_denref (x)); - printf ("\n"); -} diff --git a/gmp/mpz/Makefile.am b/gmp/mpz/Makefile.am deleted file mode 100755 index 7d08c01..0000000 Binary files a/gmp/mpz/Makefile.am and /dev/null differ diff --git a/gmp/mpz/Makefile.in b/gmp/mpz/Makefile.in deleted file mode 100755 index e00cb50..0000000 Binary files a/gmp/mpz/Makefile.in and /dev/null differ diff --git a/gmp/mpz/README b/gmp/mpz/README deleted file mode 100755 index e0e03ad..0000000 Binary files a/gmp/mpz/README and /dev/null differ diff --git a/gmp/mpz/abs.c b/gmp/mpz/abs.c deleted file mode 100755 index 0b5eab1..0000000 --- a/gmp/mpz/abs.c +++ /dev/null @@ -1,51 +0,0 @@ -/* mpz_abs(dst, src) -- Assign the absolute value of SRC to DST. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_abs (mpz_ptr w, mpz_srcptr u) -#else -mpz_abs (w, u) - mpz_ptr w; - mpz_srcptr u; -#endif -{ - mp_ptr wp, up; - mp_size_t size; - - size = ABS (u->_mp_size); - - if (u != w) - { - if (w->_mp_alloc < size) - _mpz_realloc (w, size); - - wp = w->_mp_d; - up = u->_mp_d; - - MPN_COPY (wp, up, size); - } - - w->_mp_size = size; -} diff --git a/gmp/mpz/add.c b/gmp/mpz/add.c deleted file mode 100755 index a22c377..0000000 --- a/gmp/mpz/add.c +++ /dev/null @@ -1,123 +0,0 @@ -/* mpz_add -- Add two integers. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_add (mpz_ptr w, mpz_srcptr u, mpz_srcptr v) -#else -mpz_add (w, u, v) - mpz_ptr w; - mpz_srcptr u; - mpz_srcptr v; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -madd (mpz_srcptr u, mpz_srcptr v, mpz_ptr w) -#else -madd (u, v, w) - mpz_srcptr u; - mpz_srcptr v; - mpz_ptr w; -#endif -#endif /* BERKELEY_MP */ -{ - mp_srcptr up, vp; - mp_ptr wp; - mp_size_t usize, vsize, wsize; - mp_size_t abs_usize; - mp_size_t abs_vsize; - - usize = u->_mp_size; - vsize = v->_mp_size; - abs_usize = ABS (usize); - abs_vsize = ABS (vsize); - - if (abs_usize < abs_vsize) - { - /* Swap U and V. */ - MPZ_SRCPTR_SWAP (u, v); - MP_SIZE_T_SWAP (usize, vsize); - MP_SIZE_T_SWAP (abs_usize, abs_vsize); - } - - /* True: ABS_USIZE >= ABS_VSIZE. */ - - /* If not space for w (and possible carry), increase space. */ - wsize = abs_usize + 1; - if (w->_mp_alloc < wsize) - _mpz_realloc (w, wsize); - - /* These must be after realloc (u or v may be the same as w). */ - up = u->_mp_d; - vp = v->_mp_d; - wp = w->_mp_d; - - if ((usize ^ vsize) < 0) - { - /* U and V have different sign. Need to compare them to determine - which operand to subtract from which. */ - - /* This test is right since ABS_USIZE >= ABS_VSIZE. */ - if (abs_usize != abs_vsize) - { - mpn_sub (wp, up, abs_usize, vp, abs_vsize); - wsize = abs_usize; - MPN_NORMALIZE (wp, wsize); - if (usize < 0) - wsize = -wsize; - } - else if (mpn_cmp (up, vp, abs_usize) < 0) - { - mpn_sub_n (wp, vp, up, abs_usize); - wsize = abs_usize; - MPN_NORMALIZE (wp, wsize); - if (usize >= 0) - wsize = -wsize; - } - else - { - mpn_sub_n (wp, up, vp, abs_usize); - wsize = abs_usize; - MPN_NORMALIZE (wp, wsize); - if (usize < 0) - wsize = -wsize; - } - } - else - { - /* U and V have same sign. Add them. */ - mp_limb_t cy_limb = mpn_add (wp, up, abs_usize, vp, abs_vsize); - wp[abs_usize] = cy_limb; - wsize = abs_usize + cy_limb; - if (usize < 0) - wsize = -wsize; - } - - w->_mp_size = wsize; -} diff --git a/gmp/mpz/add_ui.c b/gmp/mpz/add_ui.c deleted file mode 100755 index 28dbd71..0000000 --- a/gmp/mpz/add_ui.c +++ /dev/null @@ -1,84 +0,0 @@ -/* mpz_add_ui -- Add an mpz_t and an unsigned one-word integer. - -Copyright (C) 1991, 1993, 1994, 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_add_ui (mpz_ptr w, mpz_srcptr u, unsigned long int v) -#else -mpz_add_ui (w, u, v) - mpz_ptr w; - mpz_srcptr u; - unsigned long int v; -#endif -{ - mp_srcptr up; - mp_ptr wp; - mp_size_t usize, wsize; - mp_size_t abs_usize; - - usize = u->_mp_size; - abs_usize = ABS (usize); - - /* If not space for W (and possible carry), increase space. */ - wsize = abs_usize + 1; - if (w->_mp_alloc < wsize) - _mpz_realloc (w, wsize); - - /* These must be after realloc (U may be the same as W). */ - up = u->_mp_d; - wp = w->_mp_d; - - if (abs_usize == 0) - { - wp[0] = v; - w->_mp_size = v != 0; - return; - } - - if (usize >= 0) - { - mp_limb_t cy; - cy = mpn_add_1 (wp, up, abs_usize, (mp_limb_t) v); - wp[abs_usize] = cy; - wsize = abs_usize + cy; - } - else - { - /* The signs are different. Need exact comparison to determine - which operand to subtract from which. */ - if (abs_usize == 1 && up[0] < v) - { - wp[0] = v - up[0]; - wsize = 1; - } - else - { - mpn_sub_1 (wp, up, abs_usize, (mp_limb_t) v); - /* Size can decrease with at most one limb. */ - wsize = -(abs_usize - (wp[abs_usize - 1] == 0)); - } - } - - w->_mp_size = wsize; -} diff --git a/gmp/mpz/addmul_ui.c b/gmp/mpz/addmul_ui.c deleted file mode 100755 index 7b38d36..0000000 --- a/gmp/mpz/addmul_ui.c +++ /dev/null @@ -1,214 +0,0 @@ -/* mpz_addmul_ui(prodsum, multiplier, small_multiplicand) -- - Add MULTIPLICATOR times SMALL_MULTIPLICAND to PRODSUM. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -static mp_limb_t mpn_neg1 _PROTO ((mp_ptr, mp_size_t)); - -#if 0 -#undef MPN_NORMALIZE -#define MPN_NORMALIZE(DST, NLIMBS) \ - do { \ - while (--(NLIMBS) >= 0 && (DST)[NLIMBS] == 0) \ - ; \ - (NLIMBS)++; \ - } while (0) -#undef MPN_NORMALIZE_NOT_ZERO -#define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \ - do { \ - while ((DST)[--(NLIMBS)] == 0) \ - ; \ - (NLIMBS)++; \ - } while (0) -#endif - -void -#if __STDC__ -mpz_addmul_ui (mpz_ptr rz, mpz_srcptr az, unsigned long int bu) -#else -mpz_addmul_ui (rz, az, bu) - mpz_ptr rz; - mpz_srcptr az; - unsigned long int bu; -#endif -{ - mp_size_t rn, an; - mp_ptr rp, ap; - - an = SIZ (az); - - /* If either multiplier is zero, result is unaffected. */ - if (bu == 0 || an == 0) - return; - - rn = SIZ (rz); - - if (rn == 0) - { - mp_limb_t cy; - - an = ABS (an); - if (ALLOC (rz) <= an) - _mpz_realloc (rz, an + 1); - rp = PTR (rz); - ap = PTR (az); - cy = mpn_mul_1 (rp, ap, an, (mp_limb_t) bu); - rp[an] = cy; - an += cy != 0; - SIZ (rz) = SIZ (az) >= 0 ? an : -an; - return; - } - - if ((an ^ rn) >= 0) - { - /* Sign of operands are the same--really add. */ - an = ABS (an); - rn = ABS (rn); - if (rn > an) - { - mp_limb_t cy; - if (ALLOC (rz) <= rn) - _mpz_realloc (rz, rn + 1); - rp = PTR (rz); - ap = PTR (az); - cy = mpn_addmul_1 (rp, ap, an, (mp_limb_t) bu); - cy = mpn_add_1 (rp + an, rp + an, rn - an, cy); - rp[rn] = cy; - rn += cy != 0; - SIZ (rz) = SIZ (rz) >= 0 ? rn : -rn; - return; - } - else - { - mp_limb_t cy; - if (ALLOC (rz) <= an) - _mpz_realloc (rz, an + 1); - rp = PTR (rz); - ap = PTR (az); - cy = mpn_addmul_1 (rp, ap, rn, (mp_limb_t) bu); - if (an != rn) - { - mp_limb_t cy2; - cy2 = mpn_mul_1 (rp + rn, ap + rn, an - rn, (mp_limb_t) bu); - cy = cy2 + mpn_add_1 (rp + rn, rp + rn, an - rn, cy); - } - rn = an; - rp[rn] = cy; - rn += cy != 0; - SIZ (rz) = SIZ (rz) >= 0 ? rn : -rn; - return; - } - } - else - { - /* Sign of operands are different--actually subtract. */ - an = ABS (an); - rn = ABS (rn); - if (rn > an) - { - mp_limb_t cy; - rp = PTR (rz); - ap = PTR (az); - cy = mpn_submul_1 (rp, ap, an, (mp_limb_t) bu); - cy = mpn_sub_1 (rp + an, rp + an, rn - an, cy); - if (cy != 0) - { - mpn_neg1 (rp, rn); - MPN_NORMALIZE_NOT_ZERO (rp, rn); - } - else - { - MPN_NORMALIZE (rp, rn); - rn = -rn; - } - - SIZ (rz) = SIZ (rz) >= 0 ? -rn : rn; - return; - } - else - { - /* Tricky case. We need to subtract an operand that might be larger - than the minuend. To avoid allocating temporary space, we compute - a*b-r instead of r-a*b and then negate. */ - mp_limb_t cy; - if (ALLOC (rz) <= an) - _mpz_realloc (rz, an + 1); - rp = PTR (rz); - ap = PTR (az); - cy = mpn_submul_1 (rp, ap, rn, (mp_limb_t) bu); - if (an != rn) - { - mp_limb_t cy2; - cy -= mpn_neg1 (rp, rn); - cy2 = mpn_mul_1 (rp + rn, ap + rn, an - rn, (mp_limb_t) bu); - if (cy == ~(mp_limb_t) 0) - cy = cy2 - mpn_sub_1 (rp + rn, rp + rn, an - rn, (mp_limb_t) 1); - else - cy = cy2 + mpn_add_1 (rp + rn, rp + rn, an - rn, cy); - rp[an] = cy; - rn = an + (cy != 0); - rn -= rp[rn - 1] == 0; - } - else if (cy != 0) - { - cy -= mpn_neg1 (rp, rn); - rp[an] = cy; - rn = an + 1; - MPN_NORMALIZE_NOT_ZERO (rp, rn); - } - else - { - rn = an; - MPN_NORMALIZE (rp, rn); - rn = -rn; - } - - SIZ (rz) = SIZ (rz) >= 0 ? -rn : rn; - return; - } - } -} - -static mp_limb_t -#if __STDC__ -mpn_neg1 (mp_ptr rp, mp_size_t rn) -#else -mpn_neg1 (rp, rn) - mp_ptr rp; - mp_size_t rn; -#endif -{ - mp_size_t i; - - while (rn != 0 && rp[0] == 0) - rp++, rn--; - - if (rn != 0) - { - rp[0] = -rp[0]; - for (i = 1; i < rn; i++) - rp[i] = ~rp[i]; - return 1; - } - return 0; -} diff --git a/gmp/mpz/and.c b/gmp/mpz/and.c deleted file mode 100755 index 354e945..0000000 --- a/gmp/mpz/and.c +++ /dev/null @@ -1,278 +0,0 @@ -/* mpz_and -- Logical and. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_and (mpz_ptr res, mpz_srcptr op1, mpz_srcptr op2) -#else -mpz_and (res, op1, op2) - mpz_ptr res; - mpz_srcptr op1; - mpz_srcptr op2; -#endif -{ - mp_srcptr op1_ptr, op2_ptr; - mp_size_t op1_size, op2_size; - mp_ptr res_ptr; - mp_size_t res_size; - mp_size_t i; - TMP_DECL (marker); - - TMP_MARK (marker); - op1_size = op1->_mp_size; - op2_size = op2->_mp_size; - - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - - if (op1_size >= 0) - { - if (op2_size >= 0) - { - res_size = MIN (op1_size, op2_size); - /* First loop finds the size of the result. */ - for (i = res_size - 1; i >= 0; i--) - if ((op1_ptr[i] & op2_ptr[i]) != 0) - break; - res_size = i + 1; - - /* Handle allocation, now then we know exactly how much space is - needed for the result. */ - if (res->_mp_alloc < res_size) - { - _mpz_realloc (res, res_size); - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - } - - /* Second loop computes the real result. */ - for (i = res_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] & op2_ptr[i]; - - res->_mp_size = res_size; - return; - } - else /* op2_size < 0 */ - { - /* Fall through to the code at the end of the function. */ - } - } - else - { - if (op2_size < 0) - { - mp_ptr opx; - mp_limb_t cy; - mp_size_t res_alloc; - - /* Both operands are negative, so will be the result. - -((-OP1) & (-OP2)) = -(~(OP1 - 1) & ~(OP2 - 1)) = - = ~(~(OP1 - 1) & ~(OP2 - 1)) + 1 = - = ((OP1 - 1) | (OP2 - 1)) + 1 */ - - /* It might seem as we could end up with an (invalid) result with - a leading zero-limb here when one of the operands is of the - type 1,,0,,..,,.0. But some analysis shows that we surely - would get carry into the zero-limb in this situation... */ - - op1_size = -op1_size; - op2_size = -op2_size; - - res_alloc = 1 + MAX (op1_size, op2_size); - - opx = (mp_ptr) TMP_ALLOC (op1_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op1_ptr, op1_size, (mp_limb_t) 1); - op1_ptr = opx; - - opx = (mp_ptr) TMP_ALLOC (op2_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op2_ptr, op2_size, (mp_limb_t) 1); - op2_ptr = opx; - - if (res->_mp_alloc < res_alloc) - { - _mpz_realloc (res, res_alloc); - res_ptr = res->_mp_d; - /* Don't re-read OP1_PTR and OP2_PTR. They point to - temporary space--never to the space RES->_mp_d used - to point to before reallocation. */ - } - - if (op1_size >= op2_size) - { - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, - op1_size - op2_size); - for (i = op2_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] | op2_ptr[i]; - res_size = op1_size; - } - else - { - MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size, - op2_size - op1_size); - for (i = op1_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] | op2_ptr[i]; - res_size = op2_size; - } - - cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1); - if (cy) - { - res_ptr[res_size] = cy; - res_size++; - } - - res->_mp_size = -res_size; - TMP_FREE (marker); - return; - } - else - { - /* We should compute -OP1 & OP2. Swap OP1 and OP2 and fall - through to the code that handles OP1 & -OP2. */ - MPZ_SRCPTR_SWAP (op1, op2); - MPN_SRCPTR_SWAP (op1_ptr,op1_size, op2_ptr,op2_size); - } - - } - - { -#if ANDNEW - mp_size_t op2_lim; - mp_size_t count; - - /* OP2 must be negated as with infinite precision. - - Scan from the low end for a non-zero limb. The first non-zero - limb is simply negated (two's complement). Any subsequent - limbs are one's complemented. Of course, we don't need to - handle more limbs than there are limbs in the other, positive - operand as the result for those limbs is going to become zero - anyway. */ - - /* Scan for the least significant non-zero OP2 limb, and zero the - result meanwhile for those limb positions. (We will surely - find a non-zero limb, so we can write the loop with one - termination condition only.) */ - for (i = 0; op2_ptr[i] == 0; i++) - res_ptr[i] = 0; - op2_lim = i; - - op2_size = -op2_size; - - if (op1_size <= op2_size) - { - /* The ones-extended OP2 is >= than the zero-extended OP1. - RES_SIZE <= OP1_SIZE. Find the exact size. */ - for (i = op1_size - 1; i > op2_lim; i--) - if ((op1_ptr[i] & ~op2_ptr[i]) != 0) - break; - res_size = i + 1; - for (i = res_size - 1; i > op2_lim; i--) - res_ptr[i] = op1_ptr[i] & ~op2_ptr[i]; - res_ptr[op2_lim] = op1_ptr[op2_lim] & -op2_ptr[op2_lim]; - /* Yes, this *can* happen! */ - MPN_NORMALIZE (res_ptr, res_size); - } - else - { - /* The ones-extended OP2 is < than the zero-extended OP1. - RES_SIZE == OP1_SIZE, since OP1 is normalized. */ - res_size = op1_size; - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, op1_size - op2_size); - for (i = op2_size - 1; i > op2_lim; i--) - res_ptr[i] = op1_ptr[i] & ~op2_ptr[i]; - res_ptr[op2_lim] = op1_ptr[op2_lim] & -op2_ptr[op2_lim]; - } - - res->_mp_size = res_size; -#else - - /* OP1 is positive and zero-extended, - OP2 is negative and ones-extended. - The result will be positive. - OP1 & -OP2 = OP1 & ~(OP2 - 1). */ - - mp_ptr opx; - - op2_size = -op2_size; - opx = (mp_ptr) TMP_ALLOC (op2_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op2_ptr, op2_size, (mp_limb_t) 1); - op2_ptr = opx; - - if (op1_size > op2_size) - { - /* The result has the same size as OP1, since OP1 is normalized - and longer than the ones-extended OP2. */ - res_size = op1_size; - - /* Handle allocation, now then we know exactly how much space is - needed for the result. */ - if (res->_mp_alloc < res_size) - { - _mpz_realloc (res, res_size); - res_ptr = res->_mp_d; - op1_ptr = op1->_mp_d; - /* Don't re-read OP2_PTR. It points to temporary space--never - to the space RES->_mp_d used to point to before reallocation. */ - } - - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, - res_size - op2_size); - for (i = op2_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] & ~op2_ptr[i]; - - res->_mp_size = res_size; - } - else - { - /* Find out the exact result size. Ignore the high limbs of OP2, - OP1 is zero-extended and would make the result zero. */ - for (i = op1_size - 1; i >= 0; i--) - if ((op1_ptr[i] & ~op2_ptr[i]) != 0) - break; - res_size = i + 1; - - /* Handle allocation, now then we know exactly how much space is - needed for the result. */ - if (res->_mp_alloc < res_size) - { - _mpz_realloc (res, res_size); - res_ptr = res->_mp_d; - op1_ptr = op1->_mp_d; - /* Don't re-read OP2_PTR. It points to temporary space--never - to the space RES->_mp_d used to point to before reallocation. */ - } - - for (i = res_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] & ~op2_ptr[i]; - - res->_mp_size = res_size; - } -#endif - } - TMP_FREE (marker); -} diff --git a/gmp/mpz/array_init.c b/gmp/mpz/array_init.c deleted file mode 100755 index 1c22046..0000000 --- a/gmp/mpz/array_init.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mpz_array_init (array, array_size, size_per_elem) -- - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_array_init (mpz_ptr arr, mp_size_t arr_size, mp_size_t nbits) -#else -mpz_array_init (arr, arr_size, nbits) - mpz_ptr arr; - mp_size_t arr_size; - mp_size_t nbits; -#endif -{ - register mp_ptr p; - register size_t i; - mp_size_t nlimbs; - - nlimbs = (nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - p = (mp_ptr) (*_mp_allocate_func) (arr_size * nlimbs * BYTES_PER_MP_LIMB); - - for (i = 0; i < arr_size; i++) - { - arr[i]._mp_alloc = nlimbs + 1; /* Yes, lie a little... */ - arr[i]._mp_size = 0; - arr[i]._mp_d = p + i * nlimbs; - } -} diff --git a/gmp/mpz/bin_ui.c b/gmp/mpz/bin_ui.c deleted file mode 100755 index a7a6c98..0000000 --- a/gmp/mpz/bin_ui.c +++ /dev/null @@ -1,141 +0,0 @@ -/* mpz_bin_uiui - compute n over k. - -Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* This is a poor implementation. Look at bin_uiui.c for improvement ideas. - In fact consider calling mpz_bin_uiui() when the arguments fit, leaving - the code here only for big n. - - The identity bin(n,k) = (-1)^k * bin(-n+k-1,k) can be found in Knuth vol - 1 section 1.2.6 part G. */ - - -/* Enhancement: use mpn_divexact_1 when it exists */ -#define DIVIDE() \ - ASSERT (SIZ(r) > 0); \ - ASSERT_NOCARRY (mpn_divrem_1 (PTR(r), (mp_size_t) 0, \ - PTR(r), SIZ(r), kacc)); \ - SIZ(r) -= (PTR(r)[SIZ(r)-1] == 0); - -void -#if __STDC__ -mpz_bin_ui (mpz_ptr r, mpz_srcptr n, unsigned long int k) -#else -mpz_bin_ui (r, n, k) - mpz_ptr r; - mpz_srcptr n; - unsigned long int k; -#endif -{ - mpz_t ni; - mp_limb_t i; - mpz_t nacc; - mp_limb_t kacc; - mp_size_t negate; - - if (mpz_sgn (n) < 0) - { - /* bin(n,k) = (-1)^k * bin(-n+k-1,k), and set ni = -n+k-1 - k = -n-1 */ - mpz_init (ni); - mpz_neg (ni, n); - mpz_sub_ui (ni, ni, 1L); - negate = (k & 1); /* (-1)^k */ - } - else - { - /* bin(n,k) == 0 if k>n - (no test for this under the n<0 case, since -n+k-1 >= k there) */ - if (mpz_cmp_ui (n, k) < 0) - { - mpz_set_ui (r, 0L); - return; - } - - /* set ni = n-k */ - mpz_init (ni); - mpz_sub_ui (ni, n, k); - negate = 0; - } - - /* Now wanting bin(ni+k,k), with ni positive, and "negate" is the sign (0 - for positive, 1 for negative). */ - mpz_set_ui (r, 1L); - - /* Rewrite bin(n,k) as bin(n,n-k) if that is smaller. In this case it's - whether ni+k-k < k meaning ni>= 1; - nacclow >>= 1; - } - mpz_div_2exp (nacc, nacc, c); -#endif - - mpz_add_ui (ni, ni, 1); - mpz_mul (nacc, nacc, ni); - umul_ppmm (k1, k0, kacc, i); - if (k1 != 0) - { - /* Accumulator overflow. Perform bignum step. */ - mpz_mul (r, r, nacc); - mpz_set_ui (nacc, 1); - DIVIDE (); - kacc = i; - } - else - { - /* Save new products in accumulators to keep accumulating. */ - kacc = k0; - } - } - - mpz_mul (r, r, nacc); - DIVIDE (); - SIZ(r) = (SIZ(r) ^ -negate) + negate; - - mpz_clear (nacc); - mpz_clear (ni); -} diff --git a/gmp/mpz/bin_uiui.c b/gmp/mpz/bin_uiui.c deleted file mode 100755 index b37541b..0000000 --- a/gmp/mpz/bin_uiui.c +++ /dev/null @@ -1,120 +0,0 @@ -/* mpz_bin_uiui - compute n over k. - -Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* Avoid reallocs by rounding up any new size */ -#define ROUNDUP_MASK 15 - -/* Enhancement: use mpn_divexact_1 when it exists */ -#define MULDIV() \ - MPZ_REALLOC (r, (SIZ(r)+1)|ROUNDUP_MASK); \ - PTR(r)[SIZ(r)] = mpn_mul_1 (PTR(r), PTR(r), SIZ(r), nacc); \ - ASSERT_NOCARRY (mpn_divrem_1 (PTR(r), (mp_size_t) 0, \ - PTR(r), SIZ(r)+1, kacc)); \ - SIZ(r) += (PTR(r)[SIZ(r)] != 0); - -void -#if __STDC__ -mpz_bin_uiui (mpz_ptr r, unsigned long int n, unsigned long int k) -#else -mpz_bin_uiui (r, n, k) - mpz_ptr r; - unsigned long int n; - unsigned long int k; -#endif -{ - unsigned long int i, j; - mp_limb_t nacc, kacc; - unsigned long int cnt; - - /* bin(n,k) = 0 if k>n. */ - if (n < k) - { - mpz_set_ui (r, 0); - return; - } - - /* Rewrite bin(n,k) as bin(n,n-k) if that is smaller. */ - k = MIN (k, n-k); - - /* bin(n,0) = 1 */ - if (k == 0) - { - mpz_set_ui (r, 1); - return; - } - - j = n - k + 1; - mpz_set_ui (r, j); - - /* Initialize accumulators. */ - nacc = 1; - kacc = 1; - - cnt = 0; - for (i = 2; i <= k; i++) - { - mp_limb_t n1, n0, k1, k0; - - j++; -#if 0 - /* Remove common multiples of 2. This will allow us to accumulate - more in nacc and kacc before we need a bignum step. It would make - sense to cancel factors of 3, 5, etc too, but this would be best - handled by sieving out factors. Alternatively, we could perform a - gcd of the accumulators just as they have overflown, and keep - accumulating until the gcd doesn't remove a significant factor. */ - while (((nacc | kacc) & 1) == 0) - { - nacc >>= 1; - kacc >>= 1; - } -#else - cnt = ((nacc | kacc) & 1) ^ 1; - nacc >>= cnt; - kacc >>= cnt; -#endif - /* Accumulate next multiples. */ - umul_ppmm (n1, n0, nacc, j); - umul_ppmm (k1, k0, kacc, i); - if (n1 != 0) - { - /* Accumulator overflow. Perform bignum step. */ - MULDIV (); - nacc = j; - kacc = i; - } - else - { - if (k1 != 0) abort (); - /* Save new products in accumulators to keep accumulating. */ - nacc = n0; - kacc = k0; - } - } - - /* Take care of whatever is left in accumulators. */ - MULDIV (); -} diff --git a/gmp/mpz/cdiv_q.c b/gmp/mpz/cdiv_q.c deleted file mode 100755 index b15ba8a..0000000 --- a/gmp/mpz/cdiv_q.c +++ /dev/null @@ -1,51 +0,0 @@ -/* mpz_cdiv_q -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. - -Copyright (C) 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_cdiv_q (mpz_ptr quot, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_cdiv_q (quot, dividend, divisor) - mpz_ptr quot; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t dividend_size = dividend->_mp_size; - mp_size_t divisor_size = divisor->_mp_size; - mpz_t rem; - TMP_DECL (marker); - - TMP_MARK (marker); - - MPZ_TMP_INIT (rem, ABS (divisor_size)); - - mpz_tdiv_qr (quot, rem, dividend, divisor); - - if ((divisor_size ^ dividend_size) >= 0 && rem->_mp_size != 0) - mpz_add_ui (quot, quot, 1L); - - TMP_FREE (marker); -} diff --git a/gmp/mpz/cdiv_q_ui.c b/gmp/mpz/cdiv_q_ui.c deleted file mode 100755 index 74f3a90..0000000 --- a/gmp/mpz/cdiv_q_ui.c +++ /dev/null @@ -1,67 +0,0 @@ -/* mpz_cdiv_q_ui -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. In order to make it - always fit into the return type, the negative of the true remainder is - returned. - -Copyright (C) 1994, 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_cdiv_q_ui (mpz_ptr quot, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_cdiv_q_ui (quot, dividend, divisor) - mpz_ptr quot; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_ptr quot_ptr; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - if (quot->_mp_alloc < size) - _mpz_realloc (quot, size); - - quot_ptr = quot->_mp_d; - - remainder_limb = mpn_divmod_1 (quot_ptr, dividend->_mp_d, size, - (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size >= 0) - { - mpn_incr_u (quot_ptr, (mp_limb_t) 1); - remainder_limb = divisor - remainder_limb; - } - - size -= size != 0 && quot_ptr[size - 1] == 0; - quot->_mp_size = dividend_size >= 0 ? size : -size; - - return remainder_limb; -} diff --git a/gmp/mpz/cdiv_qr.c b/gmp/mpz/cdiv_qr.c deleted file mode 100755 index 29c7c41..0000000 --- a/gmp/mpz/cdiv_qr.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpz_cdiv_qr -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. - -Copyright (C) 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_cdiv_qr (mpz_ptr quot, mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_cdiv_qr (quot, rem, dividend, divisor) - mpz_ptr quot; - mpz_ptr rem; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t divisor_size = divisor->_mp_size; - mp_size_t xsize; - mpz_t temp_divisor; /* N.B.: lives until function returns! */ - TMP_DECL (marker); - - TMP_MARK (marker); - - /* We need the original value of the divisor after the quotient and - remainder have been preliminary calculated. We have to copy it to - temporary space if it's the same variable as either QUOT or REM. */ - if (quot == divisor || rem == divisor) - { - MPZ_TMP_INIT (temp_divisor, ABS (divisor_size)); - mpz_set (temp_divisor, divisor); - divisor = temp_divisor; - } - - xsize = dividend->_mp_size ^ divisor_size;; - mpz_tdiv_qr (quot, rem, dividend, divisor); - - if (xsize >= 0 && rem->_mp_size != 0) - { - mpz_add_ui (quot, quot, 1L); - mpz_sub (rem, rem, divisor); - } - - TMP_FREE (marker); -} diff --git a/gmp/mpz/cdiv_qr_ui.c b/gmp/mpz/cdiv_qr_ui.c deleted file mode 100755 index a7873c6..0000000 --- a/gmp/mpz/cdiv_qr_ui.c +++ /dev/null @@ -1,71 +0,0 @@ -/* mpz_cdiv_qr_ui -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. In order to make it - always fit into the return type, the negative of the true remainder is - returned. - -Copyright (C) 1994, 1995, 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_cdiv_qr_ui (mpz_ptr quot, mpz_ptr rem, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_cdiv_qr_ui (quot, rem, dividend, divisor) - mpz_ptr quot; - mpz_ptr rem; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_ptr quot_ptr; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - if (quot->_mp_alloc < size) - _mpz_realloc (quot, size); - - quot_ptr = quot->_mp_d; - - remainder_limb = mpn_divmod_1 (quot_ptr, dividend->_mp_d, size, - (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size >= 0) - { - mpn_incr_u (quot_ptr, (mp_limb_t) 1); - remainder_limb = divisor - remainder_limb; - } - - size -= size != 0 && quot_ptr[size - 1] == 0; - quot->_mp_size = dividend_size >= 0 ? size : -size; - - rem->_mp_d[0] = remainder_limb; - rem->_mp_size = -(remainder_limb != 0); - - return remainder_limb; -} diff --git a/gmp/mpz/cdiv_r.c b/gmp/mpz/cdiv_r.c deleted file mode 100755 index e96ce7e..0000000 --- a/gmp/mpz/cdiv_r.c +++ /dev/null @@ -1,59 +0,0 @@ -/* mpz_cdiv_r -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. - -Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_cdiv_r (mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_cdiv_r (rem, dividend, divisor) - mpz_ptr rem; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t divisor_size = divisor->_mp_size; - mpz_t temp_divisor; /* N.B.: lives until function returns! */ - TMP_DECL (marker); - - TMP_MARK (marker); - - /* We need the original value of the divisor after the remainder has been - preliminary calculated. We have to copy it to temporary space if it's - the same variable as REM. */ - if (rem == divisor) - { - - MPZ_TMP_INIT (temp_divisor, ABS (divisor_size)); - mpz_set (temp_divisor, divisor); - divisor = temp_divisor; - } - - mpz_tdiv_r (rem, dividend, divisor); - - if ((divisor_size ^ dividend->_mp_size) >= 0 && rem->_mp_size != 0) - mpz_sub (rem, rem, divisor); - - TMP_FREE (marker); -} diff --git a/gmp/mpz/cdiv_r_ui.c b/gmp/mpz/cdiv_r_ui.c deleted file mode 100755 index e17e238..0000000 --- a/gmp/mpz/cdiv_r_ui.c +++ /dev/null @@ -1,57 +0,0 @@ -/* mpz_cdiv_r_ui -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. In order to make it - always fit into the return type, the negative of the true remainder is - returned. - -Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_cdiv_r_ui (mpz_ptr rem, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_cdiv_r_ui (rem, dividend, divisor) - mpz_ptr rem; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - remainder_limb = mpn_mod_1 (dividend->_mp_d, size, (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size >= 0) - remainder_limb = divisor - remainder_limb; - - rem->_mp_d[0] = remainder_limb; - rem->_mp_size = -(remainder_limb != 0); - - return remainder_limb; -} diff --git a/gmp/mpz/cdiv_ui.c b/gmp/mpz/cdiv_ui.c deleted file mode 100755 index 63547a7..0000000 --- a/gmp/mpz/cdiv_ui.c +++ /dev/null @@ -1,50 +0,0 @@ -/* mpz_cdiv_ui -- Division rounding the quotient towards +infinity. The - remainder gets the opposite sign as the denominator. In order to make it - always fit into the return type, the negative of the true remainder is - returned. - -Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_cdiv_ui (mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_cdiv_ui (dividend, divisor) - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_limb_t remainder_limb; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - remainder_limb = mpn_mod_1 (dividend->_mp_d, size, (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size >= 0) - remainder_limb = divisor - remainder_limb; - - return remainder_limb; -} diff --git a/gmp/mpz/clear.c b/gmp/mpz/clear.c deleted file mode 100755 index 5224553..0000000 --- a/gmp/mpz/clear.c +++ /dev/null @@ -1,35 +0,0 @@ -/* mpz_clear -- de-allocate the space occupied by the dynamic digit space of - an integer. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_clear (mpz_ptr m) -#else -mpz_clear (m) - mpz_ptr m; -#endif -{ - (*_mp_free_func) (m->_mp_d, m->_mp_alloc * BYTES_PER_MP_LIMB); -} diff --git a/gmp/mpz/clrbit.c b/gmp/mpz/clrbit.c deleted file mode 100755 index 865d849..0000000 --- a/gmp/mpz/clrbit.c +++ /dev/null @@ -1,114 +0,0 @@ -/* mpz_clrbit -- clear a specified bit. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_clrbit (mpz_ptr d, unsigned long int bit_index) -#else -mpz_clrbit (d, bit_index) - mpz_ptr d; - unsigned long int bit_index; -#endif -{ - mp_size_t dsize = d->_mp_size; - mp_ptr dp = d->_mp_d; - mp_size_t limb_index; - - limb_index = bit_index / BITS_PER_MP_LIMB; - if (dsize >= 0) - { - if (limb_index < dsize) - { - dp[limb_index] &= ~((mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB)); - MPN_NORMALIZE (dp, dsize); - d->_mp_size = dsize; - } - else - ; - } - else - { - mp_size_t zero_bound; - - /* Simulate two's complement arithmetic, i.e. simulate - 1. Set OP = ~(OP - 1) [with infinitely many leading ones]. - 2. clear the bit. - 3. Set OP = ~OP + 1. */ - - dsize = -dsize; - - /* No upper bound on this loop, we're sure there's a non-zero limb - sooner ot later. */ - for (zero_bound = 0; ; zero_bound++) - if (dp[zero_bound] != 0) - break; - - if (limb_index > zero_bound) - { - if (limb_index < dsize) - dp[limb_index] |= (mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB); - else - { - /* Ugh. The bit should be cleared outside of the end of the - number. We have to increase the size of the number. */ - if (d->_mp_alloc < limb_index + 1) - { - _mpz_realloc (d, limb_index + 1); - dp = d->_mp_d; - } - MPN_ZERO (dp + dsize, limb_index - dsize); - dp[limb_index] = (mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB); - d->_mp_size = -(limb_index + 1); - } - } - else if (limb_index == zero_bound) - { - dp[limb_index] = ((dp[limb_index] - 1) - | ((mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB))) + 1; - if (dp[limb_index] == 0) - { - mp_size_t i; - for (i = limb_index + 1; i < dsize; i++) - { - dp[i] += 1; - if (dp[i] != 0) - goto fin; - } - /* We got carry all way out beyond the end of D. Increase - its size (and allocation if necessary). */ - dsize++; - if (d->_mp_alloc < dsize) - { - _mpz_realloc (d, dsize); - dp = d->_mp_d; - } - dp[i] = 1; - d->_mp_size = -dsize; - fin:; - } - } - else - ; - } -} diff --git a/gmp/mpz/cmp.c b/gmp/mpz/cmp.c deleted file mode 100755 index 6062834..0000000 --- a/gmp/mpz/cmp.c +++ /dev/null @@ -1,75 +0,0 @@ -/* mpz_cmp(u,v) -- Compare U, V. Return postive, zero, or negative - based on if U > V, U == V, or U < V. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#ifdef BERKELEY_MP -#include "mp.h" -#endif -#include "gmp.h" -#include "gmp-impl.h" - -#ifndef BERKELEY_MP -int -#if __STDC__ -mpz_cmp (mpz_srcptr u, mpz_srcptr v) -#else -mpz_cmp (u, v) - mpz_srcptr u; - mpz_srcptr v; -#endif -#else /* BERKELEY_MP */ -int -#if __STDC__ -mcmp (mpz_srcptr u, mpz_srcptr v) -#else -mcmp (u, v) - mpz_srcptr u; - mpz_srcptr v; -#endif -#endif /* BERKELEY_MP */ -{ - mp_size_t usize = u->_mp_size; - mp_size_t vsize = v->_mp_size; - mp_size_t size; - mp_srcptr up, vp; - int cmp; - - if (usize != vsize) - return usize - vsize; - - if (usize == 0) - return 0; - - size = ABS (usize); - - up = u->_mp_d; - vp = v->_mp_d; - - cmp = mpn_cmp (up, vp, size); - - if (cmp == 0) - return 0; - - if ((cmp < 0) == (usize < 0)) - return 1; - else - return -1; -} diff --git a/gmp/mpz/cmp_si.c b/gmp/mpz/cmp_si.c deleted file mode 100755 index 0c2212f..0000000 --- a/gmp/mpz/cmp_si.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpz_cmp_si(u,v) -- Compare an integer U with a single-word int V. - Return positive, zero, or negative based on if U > V, U == V, or U < V. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -_mpz_cmp_si (mpz_srcptr u, signed long int v_digit) -#else -_mpz_cmp_si (u, v_digit) - mpz_srcptr u; - signed long int v_digit; -#endif -{ - mp_size_t usize = u->_mp_size; - mp_size_t vsize; - mp_limb_t u_digit; - - vsize = 0; - if (v_digit > 0) - vsize = 1; - else if (v_digit < 0) - { - vsize = -1; - v_digit = -v_digit; - } - - if (usize != vsize) - return usize - vsize; - - if (usize == 0) - return 0; - - u_digit = u->_mp_d[0]; - - if (u_digit == (mp_limb_t) (unsigned long) v_digit) - return 0; - - if (u_digit > (mp_limb_t) (unsigned long) v_digit) - return usize; - else - return -usize; -} diff --git a/gmp/mpz/cmp_ui.c b/gmp/mpz/cmp_ui.c deleted file mode 100755 index fd84f30..0000000 --- a/gmp/mpz/cmp_ui.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpz_cmp_ui.c -- Compare a mpz_t a with an mp_limb_t b. Return positive, - zero, or negative based on if a > b, a == b, or a < b. - -Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -_mpz_cmp_ui (mpz_srcptr u, unsigned long int v_digit) -#else -_mpz_cmp_ui (u, v_digit) - mpz_srcptr u; - unsigned long int v_digit; -#endif -{ - mp_size_t usize = u->_mp_size; - - if (usize == 0) - return -(v_digit != 0); - - if (usize == 1) - { - mp_limb_t u_digit; - - u_digit = u->_mp_d[0]; - if (u_digit > v_digit) - return 1; - if (u_digit < v_digit) - return -1; - return 0; - } - - return (usize > 0) ? 1 : -1; -} diff --git a/gmp/mpz/cmpabs.c b/gmp/mpz/cmpabs.c deleted file mode 100755 index 037d7a9..0000000 --- a/gmp/mpz/cmpabs.c +++ /dev/null @@ -1,57 +0,0 @@ -/* mpz_cmpabs(u,v) -- Compare U, V. Return postive, zero, or negative - based on if U > V, U == V, or U < V. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_cmpabs (mpz_srcptr u, mpz_srcptr v) -#else -mpz_cmpabs (u, v) - mpz_srcptr u; - mpz_srcptr v; -#endif -{ - mp_size_t usize = u->_mp_size; - mp_size_t vsize = v->_mp_size; - mp_size_t size; - mp_srcptr up, vp; - int cmp; - - usize = ABS (usize); - vsize = ABS (vsize); - - if (usize != vsize) - return usize - vsize; - - if (usize == 0) - return 0; - - up = u->_mp_d; - vp = v->_mp_d; - - cmp = mpn_cmp (up, vp, usize); - - return cmp; -} diff --git a/gmp/mpz/cmpabs_ui.c b/gmp/mpz/cmpabs_ui.c deleted file mode 100755 index db816b5..0000000 --- a/gmp/mpz/cmpabs_ui.c +++ /dev/null @@ -1,56 +0,0 @@ -/* mpz_cmpabs_ui.c -- Compare a mpz_t a with an mp_limb_t b. Return positive, - zero, or negative based on if a > b, a == b, or a < b. - -Copyright (C) 1991, 1993, 1994, 1995, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_cmpabs_ui (mpz_srcptr u, unsigned long int v_digit) -#else -mpz_cmpabs_ui (u, v_digit) - mpz_srcptr u; - unsigned long int v_digit; -#endif -{ - mp_size_t usize = u->_mp_size; - - if (usize == 0) - return -(v_digit != 0); - - usize = ABS (usize); - - if (usize == 1) - { - mp_limb_t u_digit; - - u_digit = u->_mp_d[0]; - if (u_digit > v_digit) - return 1; - if (u_digit < v_digit) - return -1; - return 0; - } - - return 1; -} diff --git a/gmp/mpz/com.c b/gmp/mpz/com.c deleted file mode 100755 index 18d6427..0000000 --- a/gmp/mpz/com.c +++ /dev/null @@ -1,93 +0,0 @@ -/* mpz_com(mpz_ptr dst, mpz_ptr src) -- Assign the bit-complemented value of - SRC to DST. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_com (mpz_ptr dst, mpz_srcptr src) -#else -mpz_com (dst, src) - mpz_ptr dst; - mpz_srcptr src; -#endif -{ - mp_size_t size = src->_mp_size; - mp_srcptr src_ptr; - mp_ptr dst_ptr; - - if (size >= 0) - { - /* As with infinite precision: one's complement, two's complement. - But this can be simplified using the identity -x = ~x + 1. - So we're going to compute (~~x) + 1 = x + 1! */ - - if (dst->_mp_alloc < size + 1) - _mpz_realloc (dst, size + 1); - - src_ptr = src->_mp_d; - dst_ptr = dst->_mp_d; - - if (size == 0) - { - /* Special case, as mpn_add wants the first arg's size >= the - second arg's size. */ - dst_ptr[0] = 1; - dst->_mp_size = -1; - return; - } - - { - mp_limb_t cy; - - cy = mpn_add_1 (dst_ptr, src_ptr, size, (mp_limb_t) 1); - if (cy) - { - dst_ptr[size] = cy; - size++; - } - } - - /* Store a negative size, to indicate ones-extension. */ - dst->_mp_size = -size; - } - else - { - /* As with infinite precision: two's complement, then one's complement. - But that can be simplified using the identity -x = ~(x - 1). - So we're going to compute ~~(x - 1) = x - 1! */ - size = -size; - - if (dst->_mp_alloc < size) - _mpz_realloc (dst, size); - - src_ptr = src->_mp_d; - dst_ptr = dst->_mp_d; - - mpn_sub_1 (dst_ptr, src_ptr, size, (mp_limb_t) 1); - size -= dst_ptr[size - 1] == 0; - - /* Store a positive size, to indicate zero-extension. */ - dst->_mp_size = size; - } -} diff --git a/gmp/mpz/divexact.c b/gmp/mpz/divexact.c deleted file mode 100755 index c297045..0000000 --- a/gmp/mpz/divexact.c +++ /dev/null @@ -1,125 +0,0 @@ -/* mpz_divexact -- finds quotient when known that quot * den == num && den != 0. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* Ken Weber (kweber@mat.ufrgs.br, kweber@mcs.kent.edu) - - Funding for this work has been partially provided by Conselho Nacional - de Desenvolvimento Cienti'fico e Tecnolo'gico (CNPq) do Brazil, Grant - 301314194-2, and was done while I was a visiting reseacher in the Instituto - de Matema'tica at Universidade Federal do Rio Grande do Sul (UFRGS). - - References: - T. Jebelean, An algorithm for exact division, Journal of Symbolic - Computation, v. 15, 1993, pp. 169-180. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpz_divexact (mpz_ptr quot, mpz_srcptr num, mpz_srcptr den) -#else -mpz_divexact (quot, num, den) - mpz_ptr quot; - mpz_srcptr num; - mpz_srcptr den; -#endif -{ - mp_ptr qp, tp; - mp_size_t qsize, tsize; - mp_srcptr np, dp; - mp_size_t nsize, dsize; - TMP_DECL (marker); - - nsize = ABS (num->_mp_size); - dsize = ABS (den->_mp_size); - - qsize = nsize - dsize + 1; - if (quot->_mp_alloc < qsize) - _mpz_realloc (quot, qsize); - - np = num->_mp_d; - dp = den->_mp_d; - qp = quot->_mp_d; - - if (nsize == 0) - { - if (dsize == 0) - DIVIDE_BY_ZERO; - quot->_mp_size = 0; - return; - } - - if (dsize <= 1) - { - if (dsize == 1) - { - mpn_divmod_1 (qp, np, nsize, dp[0]); - qsize -= qp[qsize - 1] == 0; - quot->_mp_size = (num->_mp_size ^ den->_mp_size) >= 0 ? qsize : -qsize; - return; - } - - /* Generate divide-by-zero error since dsize == 0. */ - DIVIDE_BY_ZERO; - } - - TMP_MARK (marker); - - /* QUOT <-- NUM/2^r, T <-- DEN/2^r where = r number of twos in DEN. */ - while (dp[0] == 0) - np += 1, nsize -= 1, dp += 1, dsize -= 1; - tsize = MIN (qsize, dsize); - if ((dp[0] & 1) != 0) - { - if (quot == den) /* QUOT and DEN overlap. */ - { - tp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB); - MPN_COPY (tp, dp, tsize); - } - else - tp = (mp_ptr) dp; - if (qp != np) - MPN_COPY_INCR (qp, np, qsize); - } - else - { - unsigned int r; - tp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB); - count_trailing_zeros (r, dp[0]); - mpn_rshift (tp, dp, tsize, r); - if (dsize > tsize) - tp[tsize - 1] |= dp[tsize] << (BITS_PER_MP_LIMB - r); - mpn_rshift (qp, np, qsize, r); - if (nsize > qsize) - qp[qsize - 1] |= np[qsize] << (BITS_PER_MP_LIMB - r); - } - - /* Now QUOT <-- QUOT/T. */ - mpn_bdivmod (qp, qp, qsize, tp, tsize, qsize * BITS_PER_MP_LIMB); - MPN_NORMALIZE (qp, qsize); - - quot->_mp_size = (num->_mp_size ^ den->_mp_size) >= 0 ? qsize : -qsize; - - TMP_FREE (marker); -} diff --git a/gmp/mpz/dump.c b/gmp/mpz/dump.c deleted file mode 100755 index dc318ac..0000000 --- a/gmp/mpz/dump.c +++ /dev/null @@ -1,44 +0,0 @@ -/* mpz_dump - Dump an integer to stdout. - - THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS NOT SAFE TO - CALL THIS FUNCTION DIRECTLY. IN FACT, IT IS ALMOST GUARANTEED THAT THIS - FUNCTION WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. - - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_dump (mpz_srcptr u) -#else -mpz_dump (u) - mpz_srcptr u; -#endif -{ - char *str; - - str = mpz_get_str (0, 10, u); - printf ("%s\n", str); - (*_mp_free_func) (str, 0);/* ??? broken alloc interface, pass what size ??? */ -} diff --git a/gmp/mpz/fac_ui.c b/gmp/mpz/fac_ui.c deleted file mode 100755 index 85f40f2..0000000 --- a/gmp/mpz/fac_ui.c +++ /dev/null @@ -1,157 +0,0 @@ -/* mpz_fac_ui(result, n) -- Set RESULT to N!. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#ifdef DBG -#include -#endif - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpz_fac_ui (mpz_ptr result, unsigned long int n) -#else -mpz_fac_ui (result, n) - mpz_ptr result; - unsigned long int n; -#endif -{ -#if SIMPLE_FAC - - /* Be silly. Just multiply the numbers in ascending order. O(n**2). */ - - unsigned long int k; - - mpz_set_ui (result, 1L); - - for (k = 2; k <= n; k++) - mpz_mul_ui (result, result, k); -#else - - /* Be smarter. Multiply groups of numbers in ascending order until the - product doesn't fit in a limb. Multiply these partial product in a - balanced binary tree fashion, to make the operand have as equal sizes - as possible. When the operands have about the same size, mpn_mul - becomes faster. */ - - unsigned long int p, k; - mp_limb_t p1, p0; - - /* Stack of partial products, used to make the computation balanced - (i.e. make the sizes of the multiplication operands equal). The - topmost position of MP_STACK will contain a one-limb partial product, - the second topmost will contain a two-limb partial product, and so - on. MP_STACK[0] will contain a partial product with 2**t limbs. - To compute n! MP_STACK needs to be less than - log(n)**2/log(BITS_PER_MP_LIMB), so 30 is surely enough. */ -#define MP_STACK_SIZE 30 - mpz_t mp_stack[MP_STACK_SIZE]; - - /* TOP is an index into MP_STACK, giving the topmost element. - TOP_LIMIT_SO_FAR is the largets value it has taken so far. */ - int top, top_limit_so_far; - - /* Count of the total number of limbs put on MP_STACK so far. This - variable plays an essential role in making the compututation balanced. - See below. */ - unsigned int tree_cnt; - - top = top_limit_so_far = -1; - tree_cnt = 0; - p = 1; - for (k = 2; k <= n; k++) - { - /* Multiply the partial product in P with K. */ - umul_ppmm (p1, p0, (mp_limb_t) p, (mp_limb_t) k); - - /* Did we get overflow into the high limb, i.e. is the partial - product now more than one limb? */ - if (p1 != 0) - { - tree_cnt++; - - if (tree_cnt % 2 == 0) - { - mp_size_t i; - - /* TREE_CNT is even (i.e. we have generated an even number of - one-limb partial products), which means that we have a - single-limb product on the top of MP_STACK. */ - - mpz_mul_ui (mp_stack[top], mp_stack[top], p); - - /* If TREE_CNT is divisable by 4, 8,..., we have two - similar-sized partial products with 2, 4,... limbs at - the topmost two positions of MP_STACK. Multiply them - to form a new partial product with 4, 8,... limbs. */ - for (i = 4; (tree_cnt & (i - 1)) == 0; i <<= 1) - { - mpz_mul (mp_stack[top - 1], - mp_stack[top], mp_stack[top - 1]); - top--; - } - } - else - { - /* Put the single-limb partial product in P on the stack. - (The next time we get a single-limb product, we will - multiply the two together.) */ - top++; - if (top > top_limit_so_far) - { - if (top > MP_STACK_SIZE) - abort(); - /* The stack is now bigger than ever, initialize the top - element. */ - mpz_init_set_ui (mp_stack[top], p); - top_limit_so_far++; - } - else - mpz_set_ui (mp_stack[top], p); - } - - /* We ignored the last result from umul_ppmm. Put K in P as the - first component of the next single-limb partial product. */ - p = k; - } - else - /* We didn't get overflow in umul_ppmm. Put p0 in P and try - with one more value of K. */ - p = p0; /* bogus if long != mp_limb_t */ - } - - /* We have partial products in mp_stack[0..top], in descending order. - We also have a small partial product in p. - Their product is the final result. */ - if (top < 0) - mpz_set_ui (result, p); - else - mpz_mul_ui (result, mp_stack[top--], p); - while (top >= 0) - mpz_mul (result, result, mp_stack[top--]); - - /* Free the storage allocated for MP_STACK. */ - for (top = top_limit_so_far; top >= 0; top--) - mpz_clear (mp_stack[top]); -#endif -} diff --git a/gmp/mpz/fdiv_q.c b/gmp/mpz/fdiv_q.c deleted file mode 100755 index 9d75ca3..0000000 --- a/gmp/mpz/fdiv_q.c +++ /dev/null @@ -1,51 +0,0 @@ -/* mpz_fdiv_q -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_fdiv_q (mpz_ptr quot, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_fdiv_q (quot, dividend, divisor) - mpz_ptr quot; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t dividend_size = dividend->_mp_size; - mp_size_t divisor_size = divisor->_mp_size; - mpz_t rem; - TMP_DECL (marker); - - TMP_MARK (marker); - - MPZ_TMP_INIT (rem, ABS (divisor_size)); - - mpz_tdiv_qr (quot, rem, dividend, divisor); - - if ((divisor_size ^ dividend_size) < 0 && rem->_mp_size != 0) - mpz_sub_ui (quot, quot, 1L); - - TMP_FREE (marker); -} diff --git a/gmp/mpz/fdiv_q_2exp.c b/gmp/mpz/fdiv_q_2exp.c deleted file mode 100755 index 000c885..0000000 --- a/gmp/mpz/fdiv_q_2exp.c +++ /dev/null @@ -1,114 +0,0 @@ -/* mpz_fdiv_q_2exp -- Divide an integer by 2**CNT. Round the quotient - towards -infinity. - -Copyright (C) 1991, 1993, 1994, 1996, 1998, 1999 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* NONO */ -#include -/* NONO */ - -void -#if __STDC__ -mpz_fdiv_q_2exp (mpz_ptr w, mpz_srcptr u, unsigned long int cnt) -#else -mpz_fdiv_q_2exp (w, u, cnt) - mpz_ptr w; - mpz_srcptr u; - unsigned long int cnt; -#endif -{ - mp_size_t usize = u->_mp_size; - mp_size_t wsize; - mp_size_t abs_usize = ABS (usize); - mp_size_t limb_cnt; - mp_ptr wp; - mp_limb_t round = 0; - - limb_cnt = cnt / BITS_PER_MP_LIMB; - wsize = abs_usize - limb_cnt; - if (wsize <= 0) - { - wp = w->_mp_d; - wsize = 0; - /* Set ROUND since we know we skip some non-zero words in this case. - Well, if U is zero, we don't, but then this will be taken care of - below, since rounding only really takes place for negative U. */ - round = 1; - wp[0] = 1; - w->_mp_size = -(usize < 0); - return; - } - else - { - mp_size_t i; - mp_ptr up; - - /* Make sure there is enough space. We make an extra limb - here to account for possible rounding at the end. */ - if (w->_mp_alloc < wsize + 1) - _mpz_realloc (w, wsize + 1); - - wp = w->_mp_d; - up = u->_mp_d; - - /* Set ROUND if we are about skip some non-zero limbs. */ - for (i = 0; i < limb_cnt && round == 0; i++) - round = up[i]; - - cnt %= BITS_PER_MP_LIMB; - if (cnt != 0) - { -/* -plnt_printf("wp : 0x%x\n", wp); -plnt_printf("up + limb_cnt : 0x%x\n", up + limb_cnt); -plnt_printf("wsize : 0x%x\n", wsize); -plnt_printf("cnt : 0x%x\n", cnt); -*/ - round |= mpn_rshift (wp, up + limb_cnt, wsize, cnt); - wsize -= wp[wsize - 1] == 0; - } - else - { - MPN_COPY_INCR (wp, up + limb_cnt, wsize); - } - } - - if (usize < 0 && round != 0) - { - mp_limb_t cy; - if (wsize != 0) - { - cy = mpn_add_1 (wp, wp, wsize, (mp_limb_t) 1); - wp[wsize] = cy; - wsize += cy; - } - else - { - /* We shifted something negative to zero. The result is -1. */ - wp[0] = 1; - wsize = 1; - } - } - w->_mp_size = usize >= 0 ? wsize : -wsize; -} diff --git a/gmp/mpz/fdiv_q_ui.c b/gmp/mpz/fdiv_q_ui.c deleted file mode 100755 index 55d2498..0000000 --- a/gmp/mpz/fdiv_q_ui.c +++ /dev/null @@ -1,65 +0,0 @@ -/* mpz_fdiv_q_ui -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_fdiv_q_ui (mpz_ptr quot, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_fdiv_q_ui (quot, dividend, divisor) - mpz_ptr quot; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_ptr quot_ptr; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - if (quot->_mp_alloc < size) - _mpz_realloc (quot, size); - - quot_ptr = quot->_mp_d; - - remainder_limb = mpn_divmod_1 (quot_ptr, dividend->_mp_d, size, - (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size < 0) - { - mpn_incr_u (quot_ptr, (mp_limb_t) 1); - remainder_limb = divisor - remainder_limb; - } - - size -= size != 0 && quot_ptr[size - 1] == 0; - quot->_mp_size = dividend_size >= 0 ? size : -size; - - return remainder_limb; -} diff --git a/gmp/mpz/fdiv_qr.c b/gmp/mpz/fdiv_qr.c deleted file mode 100755 index 06ce506..0000000 --- a/gmp/mpz/fdiv_qr.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpz_fdiv_qr -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_fdiv_qr (mpz_ptr quot, mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_fdiv_qr (quot, rem, dividend, divisor) - mpz_ptr quot; - mpz_ptr rem; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t divisor_size = divisor->_mp_size; - mp_size_t xsize; - mpz_t temp_divisor; /* N.B.: lives until function returns! */ - TMP_DECL (marker); - - TMP_MARK (marker); - - /* We need the original value of the divisor after the quotient and - remainder have been preliminary calculated. We have to copy it to - temporary space if it's the same variable as either QUOT or REM. */ - if (quot == divisor || rem == divisor) - { - MPZ_TMP_INIT (temp_divisor, ABS (divisor_size)); - mpz_set (temp_divisor, divisor); - divisor = temp_divisor; - } - - xsize = dividend->_mp_size ^ divisor_size;; - mpz_tdiv_qr (quot, rem, dividend, divisor); - - if (xsize < 0 && rem->_mp_size != 0) - { - mpz_sub_ui (quot, quot, 1L); - mpz_add (rem, rem, divisor); - } - - TMP_FREE (marker); -} diff --git a/gmp/mpz/fdiv_qr_ui.c b/gmp/mpz/fdiv_qr_ui.c deleted file mode 100755 index 600c0da..0000000 --- a/gmp/mpz/fdiv_qr_ui.c +++ /dev/null @@ -1,69 +0,0 @@ -/* mpz_fdiv_qr_ui -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_fdiv_qr_ui (mpz_ptr quot, mpz_ptr rem, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_fdiv_qr_ui (quot, rem, dividend, divisor) - mpz_ptr quot; - mpz_ptr rem; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_ptr quot_ptr; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - if (quot->_mp_alloc < size) - _mpz_realloc (quot, size); - - quot_ptr = quot->_mp_d; - - remainder_limb = mpn_divmod_1 (quot_ptr, dividend->_mp_d, size, - (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size < 0) - { - mpn_incr_u (quot_ptr, (mp_limb_t) 1); - remainder_limb = divisor - remainder_limb; - } - - size -= size != 0 && quot_ptr[size - 1] == 0; - quot->_mp_size = dividend_size >= 0 ? size : -size; - - rem->_mp_d[0] = remainder_limb; - rem->_mp_size = remainder_limb != 0; - - return remainder_limb; -} diff --git a/gmp/mpz/fdiv_r.c b/gmp/mpz/fdiv_r.c deleted file mode 100755 index a365283..0000000 --- a/gmp/mpz/fdiv_r.c +++ /dev/null @@ -1,58 +0,0 @@ -/* mpz_fdiv_r -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_fdiv_r (mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_fdiv_r (rem, dividend, divisor) - mpz_ptr rem; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t divisor_size = divisor->_mp_size; - mpz_t temp_divisor; /* N.B.: lives until function returns! */ - TMP_DECL (marker); - - TMP_MARK (marker); - - /* We need the original value of the divisor after the remainder has been - preliminary calculated. We have to copy it to temporary space if it's - the same variable as REM. */ - if (rem == divisor) - { - MPZ_TMP_INIT (temp_divisor, ABS (divisor_size)); - mpz_set (temp_divisor, divisor); - divisor = temp_divisor; - } - - mpz_tdiv_r (rem, dividend, divisor); - - if ((divisor_size ^ dividend->_mp_size) < 0 && rem->_mp_size != 0) - mpz_add (rem, rem, divisor); - - TMP_FREE (marker); -} diff --git a/gmp/mpz/fdiv_r_2exp.c b/gmp/mpz/fdiv_r_2exp.c deleted file mode 100755 index d0cd039..0000000 --- a/gmp/mpz/fdiv_r_2exp.c +++ /dev/null @@ -1,153 +0,0 @@ -/* mpz_fdiv_r_2exp -- Divide a integer by 2**CNT and produce a remainder. - -Copyright (C) 1991, 1993, 1994, 1995, 1998, 1999 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_fdiv_r_2exp (mpz_ptr res, mpz_srcptr in, unsigned long int cnt) -#else -mpz_fdiv_r_2exp (res, in, cnt) - mpz_ptr res; - mpz_srcptr in; - unsigned long int cnt; -#endif -{ - mp_size_t in_size = ABS (in->_mp_size); - mp_size_t res_size; - mp_size_t limb_cnt = cnt / BITS_PER_MP_LIMB; - mp_srcptr in_ptr = in->_mp_d; - - if (in_size > limb_cnt) - { - /* The input operand is (probably) greater than 2**CNT. */ - mp_limb_t x; - - x = in_ptr[limb_cnt] & (((mp_limb_t) 1 << cnt % BITS_PER_MP_LIMB) - 1); - if (x != 0) - { - res_size = limb_cnt + 1; - if (res->_mp_alloc < res_size) - _mpz_realloc (res, res_size); - - res->_mp_d[limb_cnt] = x; - } - else - { - res_size = limb_cnt; - MPN_NORMALIZE (in_ptr, res_size); - - if (res->_mp_alloc < res_size) - _mpz_realloc (res, res_size); - - limb_cnt = res_size; - } - } - else - { - /* The input operand is smaller than 2**CNT. We perform a no-op, - apart from that we might need to copy IN to RES, and may need - to round the result. */ - res_size = in_size; - if (res->_mp_alloc < res_size) - _mpz_realloc (res, res_size); - - limb_cnt = res_size; - } - - if (res != in) - MPN_COPY (res->_mp_d, in->_mp_d, limb_cnt); - in_size = in->_mp_size; - res->_mp_size = res_size; - if (in_size < 0 && res_size != 0) - { - /* Result should be 2^CNT - RES */ - mpz_t tmp; - MPZ_TMP_INIT (tmp, cnt/BITS_PER_MP_LIMB + 2); - mpz_set_ui (tmp, 1L); - mpz_mul_2exp (tmp, tmp, cnt); - mpz_sub (res, tmp, res); - } -} - -/* This is an alternative ending of the above function using just low-level - functions. Tested, but perhaps excessive? */ -#if 0 - if (in->_mp_size < 0 && res_size != 0) - { - /* Result should be 2^CNT - RES */ - - mp_ptr rp; - - limb_cnt = cnt / BITS_PER_MP_LIMB; - - if (res->_mp_alloc <= limb_cnt) - _mpz_realloc (res, limb_cnt + 1); - rp = PTR(res); - if (res_size > limb_cnt) - { - mpn_nz_neg (rp, rp, res_size); - rp[limb_cnt] &= ~(~(mp_limb_t) 0 << cnt % BITS_PER_MP_LIMB); - MPN_NORMALIZE_NOT_ZERO (rp, res_size); - } - else - { - mp_size_t i; - mpn_nz_neg (rp, rp, res_size); - for (i = res_size; i < limb_cnt; i++) - rp[i] = ~ (mp_limb_t) 0; - res_size = limb_cnt; - if (cnt % BITS_PER_MP_LIMB != 0) - { - rp[res_size] = ((mp_limb_t) 1 << (cnt % BITS_PER_MP_LIMB)) - 1; - res_size++; - } - else - MPN_NORMALIZE_NOT_ZERO (rp, res_size); - } - } - SIZ(res) = res_size; -} - -static void -mpn_nz_neg (rp, sp, n) - mp_ptr rp, sp; - mp_size_t n; -{ - mp_size_t i; - mp_limb_t x; - - x = sp[0]; - rp[0] = -x; - for (i = 1; x == 0; i++) - { - x = sp[i]; - rp[i] = -x; - } - - for (; i < n; i++) - { - rp[i] = ~sp[i]; - } -} -#endif diff --git a/gmp/mpz/fdiv_r_ui.c b/gmp/mpz/fdiv_r_ui.c deleted file mode 100755 index dd5c743..0000000 --- a/gmp/mpz/fdiv_r_ui.c +++ /dev/null @@ -1,55 +0,0 @@ -/* mpz_fdiv_r_ui -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_fdiv_r_ui (mpz_ptr rem, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_fdiv_r_ui (rem, dividend, divisor) - mpz_ptr rem; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - remainder_limb = mpn_mod_1 (dividend->_mp_d, size, (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size < 0) - remainder_limb = divisor - remainder_limb; - - rem->_mp_d[0] = remainder_limb; - rem->_mp_size = remainder_limb != 0; - - return remainder_limb; -} diff --git a/gmp/mpz/fdiv_ui.c b/gmp/mpz/fdiv_ui.c deleted file mode 100755 index f937b5f..0000000 --- a/gmp/mpz/fdiv_ui.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mpz_fdiv_ui -- Division rounding the quotient towards -infinity. - The remainder gets the same sign as the denominator. - -Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_fdiv_ui (mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_fdiv_ui (dividend, divisor) - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_limb_t remainder_limb; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - remainder_limb = mpn_mod_1 (dividend->_mp_d, size, (mp_limb_t) divisor); - - if (remainder_limb != 0 && dividend_size < 0) - remainder_limb = divisor - remainder_limb; - - return remainder_limb; -} diff --git a/gmp/mpz/fib_ui.c b/gmp/mpz/fib_ui.c deleted file mode 100755 index 4bebb80..0000000 --- a/gmp/mpz/fib_ui.c +++ /dev/null @@ -1,165 +0,0 @@ -/* mpz_fib_ui(result, n) -- Set RESULT to the Nth Fibonacci number. - -Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -/* This is fast, but could be made somewhat faster and neater. - The timing is somewhat fluctuating for even/odd sizes because - of the extra hair used to save variables and operations. Here - are a few things one might want to address: - 1. Avoid using 4 intermediate variables in mpz_fib_bigcase. - 2. Call mpn functions directly. Straightforward for these functions. - 3. Merge the three functions into one. - -Said by Kevin: - Consider using the Lucas numbers L[n] as an auxiliary sequence, making - it possible to do the "doubling" operation in mpz_fib_bigcase with two - squares rather than two multiplies. The formulas are a little more - complicated, something like the following (untested). - - F[2n] = ((F[n]+L[n])^2 - 6*F[n]^2 - 4*(-1)^n) / 2 - L[2n] = 5*F[n]^2 + 2*(-1)^n - - F[2n+1] = (F[2n] + L[2n]) / 2 - L[2n+1] = (5*F[2n] + L[2n]) / 2 - - The Lucas number that comes for free here could even be returned. - - Maybe there's formulas with two squares using just F[n], but I don't - know of any. -*/ - -/* Determine the needed storage for Fib(n). */ -#define FIB_SIZE(n) (((mp_size_t) ((n)*0.695)) / BITS_PER_MP_LIMB + 2) - -static void mpz_fib_bigcase _PROTO ((mpz_t, mpz_t, unsigned long int)); -static void mpz_fib_basecase _PROTO ((mpz_t, mpz_t, unsigned long int)); - - -#ifndef FIB_THRESHOLD -#define FIB_THRESHOLD 60 -#endif - -void -#if __STDC__ -mpz_fib_ui (mpz_t r, unsigned long int n) -#else -mpz_fib_ui (r, n) - mpz_t r; - unsigned long int n; -#endif -{ - if (n == 0) - mpz_set_ui (r, 0); - else - { - mpz_t t1; - mpz_init (t1); - if (n < FIB_THRESHOLD) - mpz_fib_basecase (t1, r, n); - else - mpz_fib_bigcase (t1, r, n); - mpz_clear (t1); - } -} - -static void -#if __STDC__ -mpz_fib_basecase (mpz_t t1, mpz_t t2, unsigned long int n) -#else -mpz_fib_basecase (t1, t2, n) - mpz_t t1; - mpz_t t2; - unsigned long int n; -#endif -{ - unsigned long int m, i; - - mpz_set_ui (t1, 0); - mpz_set_ui (t2, 1); - m = n/2; - for (i = 0; i < m; i++) - { - mpz_add (t1, t1, t2); - mpz_add (t2, t1, t2); - } - if ((n & 1) == 0) - { - mpz_sub (t1, t2, t1); - mpz_sub (t2, t2, t1); /* trick: recover t1 value just overwritten */ - } -} - -static void -#if __STDC__ -mpz_fib_bigcase (mpz_t t1, mpz_t t2, unsigned long int n) -#else -mpz_fib_bigcase (t1, t2, n) - mpz_t t1; - mpz_t t2; - unsigned long int n; -#endif -{ - unsigned long int n2; - int ni, i; - mpz_t x1, x2, u1, u2; - - ni = 0; - for (n2 = n; n2 >= FIB_THRESHOLD; n2 /= 2) - ni++; - - mpz_fib_basecase (t1, t2, n2); - - mpz_init (x1); - mpz_init (x2); - mpz_init (u1); - mpz_init (u2); - - for (i = ni - 1; i >= 0; i--) - { - mpz_mul_2exp (x1, t1, 1); - mpz_mul_2exp (x2, t2, 1); - - mpz_add (x1, x1, t2); - mpz_sub (x2, x2, t1); - - mpz_mul (u1, t2, x1); - mpz_mul (u2, t1, x2); - - if (((n >> i) & 1) == 0) - { - mpz_sub (t1, u1, u2); - mpz_set (t2, u1); - } - else - { - mpz_set (t1, u1); - mpz_mul_2exp (t2, u1, 1); - mpz_sub (t2, t2, u2); - } - } - - mpz_clear (x1); - mpz_clear (x2); - mpz_clear (u1); - mpz_clear (u2); -} diff --git a/gmp/mpz/fits_sint_p.c b/gmp/mpz/fits_sint_p.c deleted file mode 100755 index 82e32a2..0000000 --- a/gmp/mpz/fits_sint_p.c +++ /dev/null @@ -1,50 +0,0 @@ -/* int mpz_fits_X_p (mpz_t src) -- Return whether src fits the C type X. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_fits_sint_p (mpz_srcptr src) -#else -mpz_fits_sint_p (src) - mpz_srcptr src; -#endif -{ - mp_size_t size; - mp_limb_t mpl; - - mpl = PTR(src)[0]; - size = SIZ(src); - if (size > 0) - { - if (size > 1) - return 0; - return mpl < ~((~(unsigned int) 0) >> 1); - } - else - { - if (size < -1) - return 0; - return mpl <= ~((~(unsigned int) 0) >> 1); - } -} diff --git a/gmp/mpz/fits_slong_p.c b/gmp/mpz/fits_slong_p.c deleted file mode 100755 index e0669b5..0000000 --- a/gmp/mpz/fits_slong_p.c +++ /dev/null @@ -1,50 +0,0 @@ -/* int mpz_fits_X_p (mpz_t src) -- Return whether src fits the C type X. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_fits_slong_p (mpz_srcptr src) -#else -mpz_fits_slong_p (src) - mpz_srcptr src; -#endif -{ - mp_size_t size; - mp_limb_t mpl; - - mpl = PTR(src)[0]; - size = SIZ(src); - if (size > 0) - { - if (size > 1) - return 0; - return mpl < ~((~(unsigned long int) 0) >> 1); - } - else - { - if (size < -1) - return 0; - return mpl <= ~((~(unsigned long int) 0) >> 1); - } -} diff --git a/gmp/mpz/fits_sshort_p.c b/gmp/mpz/fits_sshort_p.c deleted file mode 100755 index 5b8e31a..0000000 --- a/gmp/mpz/fits_sshort_p.c +++ /dev/null @@ -1,50 +0,0 @@ -/* int mpz_fits_X_p (mpz_t src) -- Return whether src fits the C type X. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_fits_sshort_p (mpz_srcptr src) -#else -mpz_fits_sshort_p (src) - mpz_srcptr src; -#endif -{ - mp_size_t size; - mp_limb_t mpl; - - mpl = PTR(src)[0]; - size = SIZ(src); - if (size > 0) - { - if (size > 1) - return 0; - return mpl <= (((unsigned short int) ~(unsigned int) 0) >> 1); - } - else - { - if (size < -1) - return 0; - return mpl <= (((unsigned short int) ~(unsigned int) 0) >> 1) + 1; - } -} diff --git a/gmp/mpz/fits_uint_p.c b/gmp/mpz/fits_uint_p.c deleted file mode 100755 index 72f62fa..0000000 --- a/gmp/mpz/fits_uint_p.c +++ /dev/null @@ -1,41 +0,0 @@ -/* int mpz_fits_X_p (mpz_t src) -- Return whether src fits the C type X. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_fits_uint_p (mpz_srcptr src) -#else -mpz_fits_uint_p (src) - mpz_srcptr src; -#endif -{ - mp_size_t size; - mp_limb_t mpl; - - mpl = PTR(src)[0]; - size = SIZ(src); - if (size < 0 || size > 1) - return 0; - return mpl <= (~(unsigned int) 0); -} diff --git a/gmp/mpz/fits_ulong_p.c b/gmp/mpz/fits_ulong_p.c deleted file mode 100755 index 92eb42e..0000000 --- a/gmp/mpz/fits_ulong_p.c +++ /dev/null @@ -1,41 +0,0 @@ -/* int mpz_fits_X_p (mpz_t src) -- Return whether src fits the C type X. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_fits_ulong_p (mpz_srcptr src) -#else -mpz_fits_ulong_p (src) - mpz_srcptr src; -#endif -{ - mp_size_t size; - mp_limb_t mpl; - - mpl = PTR(src)[0]; - size = SIZ(src); - if (size < 0 || size > 1) - return 0; - return mpl <= (~(unsigned long int) 0); -} diff --git a/gmp/mpz/fits_ushort_p.c b/gmp/mpz/fits_ushort_p.c deleted file mode 100755 index bde0eda..0000000 --- a/gmp/mpz/fits_ushort_p.c +++ /dev/null @@ -1,41 +0,0 @@ -/* int mpz_fits_X_p (mpz_t src) -- Return whether src fits the C type X. - -Copyright (C) 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_fits_ushort_p (mpz_srcptr src) -#else -mpz_fits_ushort_p (src) - mpz_srcptr src; -#endif -{ - mp_size_t size; - mp_limb_t mpl; - - mpl = PTR(src)[0]; - size = SIZ(src); - if (size < 0 || size > 1) - return 0; - return mpl <= ((unsigned short int) ~(unsigned int) 0); -} diff --git a/gmp/mpz/gcd.c b/gmp/mpz/gcd.c deleted file mode 100755 index 0d950dd..0000000 --- a/gmp/mpz/gcd.c +++ /dev/null @@ -1,180 +0,0 @@ -/* mpz/gcd.c: Calculate the greatest common divisor of two integers. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_gcd (mpz_ptr g, mpz_srcptr u, mpz_srcptr v) -#else -mpz_gcd (g, u, v) - mpz_ptr g; - mpz_srcptr u; - mpz_srcptr v; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -gcd (mpz_srcptr u, mpz_srcptr v, mpz_ptr g) -#else -gcd (u, v, g) - mpz_ptr g; - mpz_srcptr u; - mpz_srcptr v; -#endif -#endif /* BERKELEY_MP */ - -{ - unsigned long int g_zero_bits, u_zero_bits, v_zero_bits; - mp_size_t g_zero_limbs, u_zero_limbs, v_zero_limbs; - mp_ptr tp; - mp_ptr up = u->_mp_d; - mp_size_t usize = ABS (u->_mp_size); - mp_ptr vp = v->_mp_d; - mp_size_t vsize = ABS (v->_mp_size); - mp_size_t gsize; - TMP_DECL (marker); - - /* GCD(0, V) == V. */ - if (usize == 0) - { - g->_mp_size = vsize; - if (g == v) - return; - if (g->_mp_alloc < vsize) - _mpz_realloc (g, vsize); - MPN_COPY (g->_mp_d, vp, vsize); - return; - } - - /* GCD(U, 0) == U. */ - if (vsize == 0) - { - g->_mp_size = usize; - if (g == u) - return; - if (g->_mp_alloc < usize) - _mpz_realloc (g, usize); - MPN_COPY (g->_mp_d, up, usize); - return; - } - - if (usize == 1) - { - g->_mp_size = 1; - g->_mp_d[0] = mpn_gcd_1 (vp, vsize, up[0]); - return; - } - - if (vsize == 1) - { - g->_mp_size = 1; - g->_mp_d[0] = mpn_gcd_1 (up, usize, vp[0]); - return; - } - - TMP_MARK (marker); - - /* Eliminate low zero bits from U and V and move to temporary storage. */ - while (*up == 0) - up++; - u_zero_limbs = up - u->_mp_d; - usize -= u_zero_limbs; - count_trailing_zeros (u_zero_bits, *up); - tp = up; - up = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB); - if (u_zero_bits != 0) - { - mpn_rshift (up, tp, usize, u_zero_bits); - usize -= up[usize - 1] == 0; - } - else - MPN_COPY (up, tp, usize); - - while (*vp == 0) - vp++; - v_zero_limbs = vp - v->_mp_d; - vsize -= v_zero_limbs; - count_trailing_zeros (v_zero_bits, *vp); - tp = vp; - vp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - if (v_zero_bits != 0) - { - mpn_rshift (vp, tp, vsize, v_zero_bits); - vsize -= vp[vsize - 1] == 0; - } - else - MPN_COPY (vp, tp, vsize); - - if (u_zero_limbs > v_zero_limbs) - { - g_zero_limbs = v_zero_limbs; - g_zero_bits = v_zero_bits; - } - else if (u_zero_limbs < v_zero_limbs) - { - g_zero_limbs = u_zero_limbs; - g_zero_bits = u_zero_bits; - } - else /* Equal. */ - { - g_zero_limbs = u_zero_limbs; - g_zero_bits = MIN (u_zero_bits, v_zero_bits); - } - - /* Call mpn_gcd. The 2nd argument must not have more bits than the 1st. */ - vsize = (usize < vsize || (usize == vsize && up[usize-1] < vp[vsize-1])) - ? mpn_gcd (vp, vp, vsize, up, usize) - : mpn_gcd (vp, up, usize, vp, vsize); - - /* Here G <-- V << (g_zero_limbs*BITS_PER_MP_LIMB + g_zero_bits). */ - gsize = vsize + g_zero_limbs; - if (g_zero_bits != 0) - { - mp_limb_t cy_limb; - gsize += (vp[vsize - 1] >> (BITS_PER_MP_LIMB - g_zero_bits)) != 0; - if (g->_mp_alloc < gsize) - _mpz_realloc (g, gsize); - MPN_ZERO (g->_mp_d, g_zero_limbs); - - tp = g->_mp_d + g_zero_limbs; - cy_limb = mpn_lshift (tp, vp, vsize, g_zero_bits); - if (cy_limb != 0) - tp[vsize] = cy_limb; - } - else - { - if (g->_mp_alloc < gsize) - _mpz_realloc (g, gsize); - MPN_ZERO (g->_mp_d, g_zero_limbs); - MPN_COPY (g->_mp_d + g_zero_limbs, vp, vsize); - } - - g->_mp_size = gsize; - TMP_FREE (marker); -} diff --git a/gmp/mpz/gcd_ui.c b/gmp/mpz/gcd_ui.c deleted file mode 100755 index f3bec58..0000000 --- a/gmp/mpz/gcd_ui.c +++ /dev/null @@ -1,65 +0,0 @@ -/* mpz_gcd_ui -- Calculate the greatest common divisior of two integers. - -Copyright (C) 1994, 1996, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_gcd_ui (mpz_ptr w, mpz_srcptr u, unsigned long int v) -#else -mpz_gcd_ui (w, u, v) - mpz_ptr w; - mpz_srcptr u; - unsigned long int v; -#endif -{ - mp_size_t size; - mp_limb_t res; - - size = ABS (u->_mp_size); - - if (size == 0) - res = v; - else if (v == 0) - { - if (w != NULL && u != w) - { - if (w->_mp_alloc < size) - _mpz_realloc (w, size); - - MPN_COPY (w->_mp_d, u->_mp_d, size); - } - w->_mp_size = size; - /* We can't return any useful result for gcd(big,0). */ - return size > 1 ? 0 : w->_mp_d[0]; - } - else - res = mpn_gcd_1 (u->_mp_d, size, (mp_limb_t) v); - - if (w != NULL) - { - w->_mp_d[0] = res; - w->_mp_size = 1; - } - return res; -} diff --git a/gmp/mpz/gcdext.c b/gmp/mpz/gcdext.c deleted file mode 100755 index 3ba04c8..0000000 --- a/gmp/mpz/gcdext.c +++ /dev/null @@ -1,137 +0,0 @@ -/* mpz_gcdext(g, s, t, a, b) -- Set G to gcd(a, b), and S and T such that - g = as + bt. - -Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_gcdext (mpz_ptr g, mpz_ptr s, mpz_ptr t, mpz_srcptr a, mpz_srcptr b) -#else -mpz_gcdext (g, s, t, a, b) - mpz_ptr g; - mpz_ptr s; - mpz_ptr t; - mpz_srcptr a; - mpz_srcptr b; -#endif -{ - mp_size_t asize, bsize, usize, vsize; - mp_srcptr ap, bp; - mp_ptr up, vp; - mp_size_t gsize, ssize, tmp_ssize; - mp_ptr gp, sp, tmp_gp, tmp_sp; - mpz_srcptr u, v; - mpz_ptr ss, tt; - __mpz_struct stmp, gtmp; - TMP_DECL (marker); - - TMP_MARK (marker); - - /* mpn_gcdext requires that U >= V. Therefore, we often have to swap U and - V. This in turn leads to a lot of complications. The computed cofactor - will be the wrong one, so we have to fix that up at the end. */ - - asize = ABS (SIZ (a)); - bsize = ABS (SIZ (b)); - ap = PTR (a); - bp = PTR (b); - if (asize > bsize || (asize == bsize && mpn_cmp (ap, bp, asize) > 0)) - { - usize = asize; - vsize = bsize; - up = (mp_ptr) TMP_ALLOC ((usize + 1) * BYTES_PER_MP_LIMB); - vp = (mp_ptr) TMP_ALLOC ((vsize + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (up, ap, usize); - MPN_COPY (vp, bp, vsize); - u = a; - v = b; - ss = s; - tt = t; - } - else - { - usize = bsize; - vsize = asize; - up = (mp_ptr) TMP_ALLOC ((usize + 1) * BYTES_PER_MP_LIMB); - vp = (mp_ptr) TMP_ALLOC ((vsize + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (up, bp, usize); - MPN_COPY (vp, ap, vsize); - u = b; - v = a; - ss = t; - tt = s; - } - - tmp_gp = (mp_ptr) TMP_ALLOC ((usize + 1) * BYTES_PER_MP_LIMB); - tmp_sp = (mp_ptr) TMP_ALLOC ((usize + 1) * BYTES_PER_MP_LIMB); - - if (vsize == 0) - { - tmp_sp[0] = 1; - tmp_ssize = 1; - MPN_COPY (tmp_gp, up, usize); - gsize = usize; - } - else - gsize = mpn_gcdext (tmp_gp, tmp_sp, &tmp_ssize, up, usize, vp, vsize); - ssize = ABS (tmp_ssize); - - PTR (>mp) = tmp_gp; - SIZ (>mp) = gsize; - - PTR (&stmp) = tmp_sp; - SIZ (&stmp) = (tmp_ssize ^ SIZ (u)) >= 0 ? ssize : -ssize; - - if (tt != NULL) - { - if (SIZ (v) == 0) - SIZ (tt) = 0; - else - { - mpz_t x; - MPZ_TMP_INIT (x, ssize + usize + 1); - mpz_mul (x, &stmp, u); - mpz_sub (x, >mp, x); - mpz_tdiv_q (tt, x, v); - } - } - - if (ss != NULL) - { - if (ALLOC (ss) < ssize) - _mpz_realloc (ss, ssize); - sp = PTR (ss); - MPN_COPY (sp, tmp_sp, ssize); - SIZ (ss) = SIZ (&stmp); - } - - if (ALLOC (g) < gsize) - _mpz_realloc (g, gsize); - gp = PTR (g); - MPN_COPY (gp, tmp_gp, gsize); - SIZ (g) = gsize; - - TMP_FREE (marker); -} diff --git a/gmp/mpz/get_d.c b/gmp/mpz/get_d.c deleted file mode 100755 index 6a7c585..0000000 --- a/gmp/mpz/get_d.c +++ /dev/null @@ -1,128 +0,0 @@ -/* double mpz_get_d (mpz_t src) -- Return the double approximation to SRC. - -Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -static int -#if __STDC__ -mpn_zero_p (mp_ptr p, mp_size_t n) -#else -mpn_zero_p (p, n) - mp_ptr p; - mp_size_t n; -#endif -{ - mp_size_t i; - - for (i = 0; i < n; i++) - { - if (p[i] != 0) - return 0; - } - - return 1; -} - - -double -#if __STDC__ -mpz_get_d (mpz_srcptr src) -#else -mpz_get_d (src) - mpz_srcptr src; -#endif -{ - double res; - mp_size_t size; - int negative; - mp_ptr qp; - mp_limb_t hz, lz; - int cnt; - - size = SIZ(src); - if (size == 0) - return 0.0; - - negative = size < 0; - size = ABS (size); - qp = PTR(src); - - if (size == 1) - { - res = qp[size - 1]; - } - else if (size == 2) - { - res = MP_BASE_AS_DOUBLE * qp[size - 1] + qp[size - 2]; - } - else - { - count_leading_zeros (cnt, qp[size - 1]); - -#if BITS_PER_MP_LIMB == 32 - if (cnt == 0) - { - hz = qp[size - 1]; - lz = qp[size - 2]; - } - else - { - hz = (qp[size - 1] << cnt) | (qp[size - 2] >> BITS_PER_MP_LIMB - cnt); - lz = (qp[size - 2] << cnt) | (qp[size - 3] >> BITS_PER_MP_LIMB - cnt); - } -#if _GMP_IEEE_FLOATS - /* Take bits from less significant limbs, but only if they may affect - the result. */ - if ((lz & 0x7ff) == 0x400) - { - if (cnt != 0) - lz += ((qp[size - 3] << cnt) != 0 || ! mpn_zero_p (qp, size - 3)); - else - lz += (! mpn_zero_p (qp, size - 2)); - } -#endif - res = MP_BASE_AS_DOUBLE * hz + lz; - res = __gmp_scale2 (res, (size - 2) * BITS_PER_MP_LIMB - cnt); -#endif -#if BITS_PER_MP_LIMB == 64 - if (cnt == 0) - hz = qp[size - 1]; - else - hz = (qp[size - 1] << cnt) | (qp[size - 2] >> BITS_PER_MP_LIMB - cnt); -#if _GMP_IEEE_FLOATS - if ((hz & 0x7ff) == 0x400) - { - if (cnt != 0) - hz += ((qp[size - 2] << cnt) != 0 || ! mpn_zero_p (qp, size - 2)); - else - hz += (! mpn_zero_p (qp, size - 1)); - } -#endif - res = hz; - res = __gmp_scale2 (res, (size - 1) * BITS_PER_MP_LIMB - cnt); -#endif - } - - return negative ? -res : res; -} diff --git a/gmp/mpz/get_si.c b/gmp/mpz/get_si.c deleted file mode 100755 index 8a5d0e4..0000000 --- a/gmp/mpz/get_si.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpz_get_si(integer) -- Return the least significant digit from INTEGER. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -signed long int -#if __STDC__ -mpz_get_si (mpz_srcptr op) -#else -mpz_get_si (op) - mpz_srcptr op; -#endif -{ - mp_size_t size = op->_mp_size; - mp_limb_t low_limb = op->_mp_d[0]; - - if (size > 0) - return low_limb % ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)); - else if (size < 0) - /* This convoluted expression is necessary to properly handle 0x80000000 */ - return ~((low_limb - 1) % ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1))); - else - return 0; -} diff --git a/gmp/mpz/get_str.c b/gmp/mpz/get_str.c deleted file mode 100755 index c7278af..0000000 --- a/gmp/mpz/get_str.c +++ /dev/null @@ -1,118 +0,0 @@ -/* mpz_get_str (string, base, mp_src) -- Convert the multiple precision - number MP_SRC to a string STRING of base BASE. If STRING is NULL - allocate space for the result. In any case, return a pointer to the - result. If STRING is not NULL, the caller must ensure enough space is - available to store the result. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -char * -#if __STDC__ -mpz_get_str (char *res_str, int base, mpz_srcptr x) -#else -mpz_get_str (res_str, base, x) - char *res_str; - int base; - mpz_srcptr x; -#endif -{ - mp_ptr xp; - mp_size_t x_size = x->_mp_size; - unsigned char *str; - char *return_str; - size_t str_size; - char *num_to_text; - int i; - TMP_DECL (marker); - - TMP_MARK (marker); - if (base >= 0) - { - if (base == 0) - base = 10; - num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz"; - } - else - { - base = -base; - num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - } - - /* We allways allocate space for the string. If the caller passed a - NULL pointer for RES_STR, we allocate permanent space and return - a pointer to that to the caller. */ - str_size = ((size_t) (ABS (x_size) * BITS_PER_MP_LIMB - * __mp_bases[base].chars_per_bit_exactly)) + 3; - if (res_str == 0) - { - /* We didn't get a string from the user. Allocate one (and return - a pointer to it). */ - res_str = (char *) (*_mp_allocate_func) (str_size); - /* Make str, the variable used for raw result from mpn_get_str, - point to the same string, but just after a possible minus sign. */ - str = (unsigned char *) res_str + 1; - } - else - { - /* Use TMP_ALLOC to get temporary space, since we need a few extra bytes - that we can't expect to caller to supply us with. */ - str = (unsigned char *) TMP_ALLOC (str_size); - } - - return_str = res_str; - - if (x_size == 0) - { - res_str[0] = '0'; - res_str[1] = 0; - TMP_FREE (marker); - return res_str; - } - if (x_size < 0) - { - *res_str++ = '-'; - x_size = -x_size; - } - - /* Move the number to convert into temporary space, since mpn_get_str - clobbers its argument + needs one extra high limb.... */ - xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (xp, x->_mp_d, x_size); - - str_size = mpn_get_str (str, base, xp, x_size); - - /* mpn_get_str might make some leading zeros. Skip them. */ - while (*str == 0) - { - str_size--; - str++; - } - - /* Translate result to printable chars and move result to RES_STR. */ - for (i = 0; i < str_size; i++) - res_str[i] = num_to_text[str[i]]; - res_str[str_size] = 0; - - TMP_FREE (marker); - return return_str; -} diff --git a/gmp/mpz/get_ui.c b/gmp/mpz/get_ui.c deleted file mode 100755 index a8ec9e0..0000000 --- a/gmp/mpz/get_ui.c +++ /dev/null @@ -1,37 +0,0 @@ -/* mpz_get_ui(integer) -- Return the least significant digit from INTEGER. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_get_ui (mpz_srcptr integer) -#else -mpz_get_ui (integer) - mpz_srcptr integer; -#endif -{ - if (integer->_mp_size == 0) - return 0; - else - return integer->_mp_d[0]; -} diff --git a/gmp/mpz/getlimbn.c b/gmp/mpz/getlimbn.c deleted file mode 100755 index b772ed0..0000000 --- a/gmp/mpz/getlimbn.c +++ /dev/null @@ -1,38 +0,0 @@ -/* mpz_getlimbn(integer,n) -- Return the N:th limb from INTEGER. - -Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -mp_limb_t -#if __STDC__ -mpz_getlimbn (mpz_srcptr integer, mp_size_t n) -#else -mpz_getlimbn (integer, n) - mpz_srcptr integer; - mp_size_t n; -#endif -{ - if (ABS (integer->_mp_size) <= n || n < 0) - return 0; - else - return integer->_mp_d[n]; -} diff --git a/gmp/mpz/hamdist.c b/gmp/mpz/hamdist.c deleted file mode 100755 index b039a65..0000000 --- a/gmp/mpz/hamdist.c +++ /dev/null @@ -1,62 +0,0 @@ -/* mpz_hamdist(mpz_ptr op1, mpz_ptr op2) -- Compute the hamming distance - between OP1 and OP2. If one of the operands is negative, return ~0. (We - could make the function well-defined when both operands are negative, but - that would probably not be worth the trouble. - -Copyright (C) 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_hamdist (mpz_srcptr u, mpz_srcptr v) -#else -mpz_hamdist (u, v) - mpz_srcptr u; - mpz_srcptr v; -#endif -{ - mp_srcptr up, vp; - mp_size_t usize, vsize, size; - unsigned long int count; - - usize = u->_mp_size; - vsize = v->_mp_size; - - if ((usize | vsize) < 0) - return ~ (unsigned long int) 0; - - up = u->_mp_d; - vp = v->_mp_d; - - if (usize > vsize) - { - count = mpn_popcount (up + vsize, usize - vsize); - size = vsize; - } - else - { - count = mpn_popcount (vp + usize, vsize - usize); - size = usize; - } - - return count + mpn_hamdist (up, vp, size); -} diff --git a/gmp/mpz/init.c b/gmp/mpz/init.c deleted file mode 100755 index 2e8e4d2..0000000 --- a/gmp/mpz/init.c +++ /dev/null @@ -1,36 +0,0 @@ -/* mpz_init() -- Make a new multiple precision number with value 0. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_init (mpz_ptr x) -#else -mpz_init (x) - mpz_ptr x; -#endif -{ - x->_mp_alloc = 1; - x->_mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - x->_mp_size = 0; -} diff --git a/gmp/mpz/inp_raw.c b/gmp/mpz/inp_raw.c deleted file mode 100755 index 15e6012..0000000 --- a/gmp/mpz/inp_raw.c +++ /dev/null @@ -1,101 +0,0 @@ -/* mpz_inp_raw -- Input a mpz_t in raw, but endianess, and wordsize - independent format (as output by mpz_out_raw). - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include - -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpz_inp_raw (mpz_ptr x, FILE *stream) -#else -mpz_inp_raw (x, stream) - mpz_ptr x; - FILE *stream; -#endif -{ - int i; - mp_size_t s; - mp_size_t xsize; - mp_ptr xp; - unsigned int c; - mp_limb_t x_limb; - mp_size_t in_bytesize; - int neg_flag; - - if (stream == 0) - stream = stdin; - - /* Read 4-byte size */ - in_bytesize = 0; - for (i = 4 - 1; i >= 0; i--) - { - c = fgetc (stream); - in_bytesize = (in_bytesize << BITS_PER_CHAR) | c; - } - - /* Size is stored as a 32 bit word; sign extend in_bytesize for non-32 bit - machines. */ - if (sizeof (mp_size_t) > 4) - in_bytesize |= (-(in_bytesize < 0)) << 31; - - neg_flag = in_bytesize < 0; - in_bytesize = ABS (in_bytesize); - xsize = (in_bytesize + BYTES_PER_MP_LIMB - 1) / BYTES_PER_MP_LIMB; - - if (xsize == 0) - { - x->_mp_size = 0; - return 4; /* we've read 4 bytes */ - } - - if (x->_mp_alloc < xsize) - _mpz_realloc (x, xsize); - xp = x->_mp_d; - - x_limb = 0; - for (i = (in_bytesize - 1) % BYTES_PER_MP_LIMB; i >= 0; i--) - { - c = fgetc (stream); - x_limb = (x_limb << BITS_PER_CHAR) | c; - } - xp[xsize - 1] = x_limb; - - for (s = xsize - 2; s >= 0; s--) - { - x_limb = 0; - for (i = BYTES_PER_MP_LIMB - 1; i >= 0; i--) - { - c = fgetc (stream); - x_limb = (x_limb << BITS_PER_CHAR) | c; - } - xp[s] = x_limb; - } - - if (c == EOF) - return 0; /* error */ - - MPN_NORMALIZE (xp, xsize); - x->_mp_size = neg_flag ? -xsize : xsize; - return in_bytesize + 4; -} diff --git a/gmp/mpz/inp_str.c b/gmp/mpz/inp_str.c deleted file mode 100755 index 7aa5e1f..0000000 --- a/gmp/mpz/inp_str.c +++ /dev/null @@ -1,167 +0,0 @@ -/* mpz_inp_str(dest_integer, stream, base) -- Input a number in base - BASE from stdio stream STREAM and store the result in DEST_INTEGER. - -Copyright (C) 1991, 1993, 1994, 1996, 1998, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" - -static int -#if __STDC__ -digit_value_in_base (int c, int base) -#else -digit_value_in_base (c, base) - int c; - int base; -#endif -{ - int digit; - - if (isdigit (c)) - digit = c - '0'; - else if (islower (c)) - digit = c - 'a' + 10; - else if (isupper (c)) - digit = c - 'A' + 10; - else - return -1; - - if (digit < base) - return digit; - return -1; -} - -size_t -#if __STDC__ -mpz_inp_str (mpz_ptr x, FILE *stream, int base) -#else -mpz_inp_str (x, stream, base) - mpz_ptr x; - FILE *stream; - int base; -#endif -{ - char *str; - size_t alloc_size, str_size; - int c; - int negative; - mp_size_t xsize; - size_t nread; - - if (stream == 0) - stream = stdin; - - nread = 0; - - /* Skip whitespace. */ - do - { - c = getc (stream); - nread++; - } - while (isspace (c)); - - negative = 0; - if (c == '-') - { - negative = 1; - c = getc (stream); - nread++; - } - - if (digit_value_in_base (c, base == 0 ? 10 : base) < 0) - return 0; /* error if no digits */ - - /* If BASE is 0, try to find out the base by looking at the initial - characters. */ - if (base == 0) - { - base = 10; - if (c == '0') - { - base = 8; - c = getc (stream); - nread++; - if (c == 'x' || c == 'X') - { - base = 16; - c = getc (stream); - nread++; - } - else if (c == 'b' || c == 'B') - { - base = 2; - c = getc (stream); - nread++; - } - } - } - - /* Skip leading zeros. */ - while (c == '0') - { - c = getc (stream); - nread++; - } - - alloc_size = 100; - str = (char *) (*_mp_allocate_func) (alloc_size); - str_size = 0; - - for (;;) - { - int dig; - if (str_size >= alloc_size) - { - size_t old_alloc_size = alloc_size; - alloc_size = alloc_size * 3 / 2; - str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); - } - dig = digit_value_in_base (c, base); - if (dig < 0) - break; - str[str_size++] = dig; - c = getc (stream); - } - - ungetc (c, stream); - - /* Make sure the string is not empty, mpn_set_str would fail. */ - if (str_size == 0) - { - x->_mp_size = 0; - (*_mp_free_func) (str, alloc_size); - return nread; - } - - xsize = (((mp_size_t) (str_size / __mp_bases[base].chars_per_bit_exactly)) - / BITS_PER_MP_LIMB + 2); - if (x->_mp_alloc < xsize) - _mpz_realloc (x, xsize); - - /* Convert the byte array in base BASE to our bignum format. */ - xsize = mpn_set_str (x->_mp_d, (unsigned char *) str, str_size, base); - x->_mp_size = negative ? -xsize : xsize; - - (*_mp_free_func) (str, alloc_size); - return str_size + nread; -} diff --git a/gmp/mpz/invert.c b/gmp/mpz/invert.c deleted file mode 100755 index 749a096..0000000 --- a/gmp/mpz/invert.c +++ /dev/null @@ -1,77 +0,0 @@ -/* mpz_invert (inv, x, n). Find multiplicative inverse of X in Z(N). - If X has an inverse, return non-zero and store inverse in INVERSE, - otherwise, return 0 and put garbage in INVERSE. - -Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_invert (mpz_ptr inverse, mpz_srcptr x, mpz_srcptr n) -#else -mpz_invert (inverse, x, n) - mpz_ptr inverse; - mpz_srcptr x, n; -#endif -{ - mpz_t gcd, tmp; - mp_size_t xsize, nsize, size; - TMP_DECL (marker); - - xsize = SIZ (x); - nsize = SIZ (n); - xsize = ABS (xsize); - nsize = ABS (nsize); - size = MAX (xsize, nsize) + 1; - - /* No inverse exists if the leftside operand is 0. Likewise, no - inverse exists if the mod operand is 1. */ - if (xsize == 0 || (nsize == 1 && (PTR (n))[0] == 1)) - return 0; - - TMP_MARK (marker); - - MPZ_TMP_INIT (gcd, size); - MPZ_TMP_INIT (tmp, size); - mpz_gcdext (gcd, tmp, (mpz_ptr) 0, x, n); - - /* If no inverse existed, return with an indication of that. */ - if (gcd->_mp_size != 1 || (gcd->_mp_d)[0] != 1) - { - TMP_FREE (marker); - return 0; - } - - /* Make sure we return a positive inverse. */ - if (SIZ (tmp) < 0) - { - if (SIZ (n) < 0) - mpz_sub (inverse, tmp, n); - else - mpz_add (inverse, tmp, n); - } - else - mpz_set (inverse, tmp); - - TMP_FREE (marker); - return 1; -} diff --git a/gmp/mpz/ior.c b/gmp/mpz/ior.c deleted file mode 100755 index 0bb5a80..0000000 --- a/gmp/mpz/ior.c +++ /dev/null @@ -1,244 +0,0 @@ -/* mpz_ior -- Logical inclusive or. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_ior (mpz_ptr res, mpz_srcptr op1, mpz_srcptr op2) -#else -mpz_ior (res, op1, op2) - mpz_ptr res; - mpz_srcptr op1; - mpz_srcptr op2; -#endif -{ - mp_srcptr op1_ptr, op2_ptr; - mp_size_t op1_size, op2_size; - mp_ptr res_ptr; - mp_size_t res_size; - mp_size_t i; - TMP_DECL (marker); - - TMP_MARK (marker); - op1_size = op1->_mp_size; - op2_size = op2->_mp_size; - - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - - if (op1_size >= 0) - { - if (op2_size >= 0) - { - if (op1_size >= op2_size) - { - if (res->_mp_alloc < op1_size) - { - _mpz_realloc (res, op1_size); - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - } - - if (res_ptr != op1_ptr) - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, - op1_size - op2_size); - for (i = op2_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] | op2_ptr[i]; - res_size = op1_size; - } - else - { - if (res->_mp_alloc < op2_size) - { - _mpz_realloc (res, op2_size); - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - } - - if (res_ptr != op2_ptr) - MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size, - op2_size - op1_size); - for (i = op1_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] | op2_ptr[i]; - res_size = op2_size; - } - - res->_mp_size = res_size; - return; - } - else /* op2_size < 0 */ - { - /* Fall through to the code at the end of the function. */ - } - } - else - { - if (op2_size < 0) - { - mp_ptr opx; - mp_limb_t cy; - - /* Both operands are negative, so will be the result. - -((-OP1) | (-OP2)) = -(~(OP1 - 1) | ~(OP2 - 1)) = - = ~(~(OP1 - 1) | ~(OP2 - 1)) + 1 = - = ((OP1 - 1) & (OP2 - 1)) + 1 */ - - op1_size = -op1_size; - op2_size = -op2_size; - - res_size = MIN (op1_size, op2_size); - - /* Possible optimization: Decrease mpn_sub precision, - as we won't use the entire res of both. */ - opx = (mp_ptr) TMP_ALLOC (res_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op1_ptr, res_size, (mp_limb_t) 1); - op1_ptr = opx; - - opx = (mp_ptr) TMP_ALLOC (res_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op2_ptr, res_size, (mp_limb_t) 1); - op2_ptr = opx; - - if (res->_mp_alloc < res_size) - { - _mpz_realloc (res, res_size); - res_ptr = res->_mp_d; - /* Don't re-read OP1_PTR and OP2_PTR. They point to - temporary space--never to the space RES->_mp_d used - to point to before reallocation. */ - } - - /* First loop finds the size of the result. */ - for (i = res_size - 1; i >= 0; i--) - if ((op1_ptr[i] & op2_ptr[i]) != 0) - break; - res_size = i + 1; - - if (res_size != 0) - { - /* Second loop computes the real result. */ - for (i = res_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] & op2_ptr[i]; - - cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1); - if (cy) - { - res_ptr[res_size] = cy; - res_size++; - } - } - else - { - res_ptr[0] = 1; - res_size = 1; - } - - res->_mp_size = -res_size; - TMP_FREE (marker); - return; - } - else - { - /* We should compute -OP1 | OP2. Swap OP1 and OP2 and fall - through to the code that handles OP1 | -OP2. */ - MPZ_SRCPTR_SWAP (op1, op2); - MPN_SRCPTR_SWAP (op1_ptr,op1_size, op2_ptr,op2_size); - } - } - - { - mp_ptr opx; - mp_limb_t cy; - mp_size_t res_alloc; - mp_size_t count; - - /* Operand 2 negative, so will be the result. - -(OP1 | (-OP2)) = -(OP1 | ~(OP2 - 1)) = - = ~(OP1 | ~(OP2 - 1)) + 1 = - = (~OP1 & (OP2 - 1)) + 1 */ - - op2_size = -op2_size; - - res_alloc = op2_size; - - opx = (mp_ptr) TMP_ALLOC (op2_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op2_ptr, op2_size, (mp_limb_t) 1); - op2_ptr = opx; - op2_size -= op2_ptr[op2_size - 1] == 0; - - if (res->_mp_alloc < res_alloc) - { - _mpz_realloc (res, res_alloc); - op1_ptr = op1->_mp_d; - res_ptr = res->_mp_d; - /* Don't re-read OP2_PTR. It points to temporary space--never - to the space RES->_mp_d used to point to before reallocation. */ - } - - if (op1_size >= op2_size) - { - /* We can just ignore the part of OP1 that stretches above OP2, - because the result limbs are zero there. */ - - /* First loop finds the size of the result. */ - for (i = op2_size - 1; i >= 0; i--) - if ((~op1_ptr[i] & op2_ptr[i]) != 0) - break; - res_size = i + 1; - count = res_size; - } - else - { - res_size = op2_size; - - /* Copy the part of OP2 that stretches above OP1, to RES. */ - MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size, op2_size - op1_size); - count = op1_size; - } - - if (res_size != 0) - { - /* Second loop computes the real result. */ - for (i = count - 1; i >= 0; i--) - res_ptr[i] = ~op1_ptr[i] & op2_ptr[i]; - - cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1); - if (cy) - { - res_ptr[res_size] = cy; - res_size++; - } - } - else - { - res_ptr[0] = 1; - res_size = 1; - } - - res->_mp_size = -res_size; - } - TMP_FREE (marker); -} diff --git a/gmp/mpz/iset.c b/gmp/mpz/iset.c deleted file mode 100755 index 114bc2d..0000000 --- a/gmp/mpz/iset.c +++ /dev/null @@ -1,49 +0,0 @@ -/* mpz_init_set (src_integer) -- Make a new multiple precision number with - a value copied from SRC_INTEGER. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_init_set (mpz_ptr w, mpz_srcptr u) -#else -mpz_init_set (w, u) - mpz_ptr w; - mpz_srcptr u; -#endif -{ - mp_ptr wp, up; - mp_size_t usize, size; - - usize = u->_mp_size; - size = ABS (usize); - - w->_mp_alloc = MAX (size, 1); - w->_mp_d = (mp_ptr) (*_mp_allocate_func) (w->_mp_alloc * BYTES_PER_MP_LIMB); - - wp = w->_mp_d; - up = u->_mp_d; - - MPN_COPY (wp, up, size); - w->_mp_size = usize; -} diff --git a/gmp/mpz/iset_d.c b/gmp/mpz/iset_d.c deleted file mode 100755 index 502a893..0000000 --- a/gmp/mpz/iset_d.c +++ /dev/null @@ -1,39 +0,0 @@ -/* mpz_init_set_d(integer, val) -- Initialize and assign INTEGER with a double - value VAL. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_init_set_d (mpz_ptr dest, double val) -#else -mpz_init_set_d (dest, val) - mpz_ptr dest; - double val; -#endif -{ - dest->_mp_alloc = 1; - dest->_mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - dest->_mp_size = 0; - mpz_set_d (dest, val); -} diff --git a/gmp/mpz/iset_si.c b/gmp/mpz/iset_si.c deleted file mode 100755 index 842db14..0000000 --- a/gmp/mpz/iset_si.c +++ /dev/null @@ -1,49 +0,0 @@ -/* mpz_init_set_si(val) -- Make a new multiple precision number with - value val. - -Copyright (C) 1991, 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_init_set_si (mpz_ptr x, signed long int val) -#else -mpz_init_set_si (x, val) - mpz_ptr x; - signed long int val; -#endif -{ - x->_mp_alloc = 1; - x->_mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - if (val > 0) - { - x->_mp_d[0] = val; - x->_mp_size = 1; - } - else if (val < 0) - { - x->_mp_d[0] = (unsigned long) -val; - x->_mp_size = -1; - } - else - x->_mp_size = 0; -} diff --git a/gmp/mpz/iset_str.c b/gmp/mpz/iset_str.c deleted file mode 100755 index dfb8c6b..0000000 --- a/gmp/mpz/iset_str.c +++ /dev/null @@ -1,47 +0,0 @@ -/* mpz_init_set_str(string, base) -- Convert the \0-terminated string - STRING in base BASE to a multiple precision integer. Return a MP_INT - structure representing the integer. Allow white space in the - string. If BASE == 0 determine the base in the C standard way, - i.e. 0xhh...h means base 16, 0oo...o means base 8, otherwise - assume base 10. - -Copyright (C) 1991, 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_init_set_str (mpz_ptr x, const char *str, int base) -#else -mpz_init_set_str (x, str, base) - mpz_ptr x; - const char *str; - int base; -#endif -{ - x->_mp_alloc = 1; - x->_mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - - /* if str has no digits mpz_set_str leaves x->_mp_size unset */ - x->_mp_size = 0; - - return mpz_set_str (x, str, base); -} diff --git a/gmp/mpz/iset_ui.c b/gmp/mpz/iset_ui.c deleted file mode 100755 index 759182c..0000000 --- a/gmp/mpz/iset_ui.c +++ /dev/null @@ -1,39 +0,0 @@ -/* mpz_init_set_ui(val) -- Make a new multiple precision number with - value val. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_init_set_ui (mpz_ptr x, unsigned long int val) -#else -mpz_init_set_ui (x, val) - mpz_ptr x; - unsigned long int val; -#endif -{ - x->_mp_alloc = 1; - x->_mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - x->_mp_d[0] = val; - x->_mp_size = val != 0; -} diff --git a/gmp/mpz/jacobi.c b/gmp/mpz/jacobi.c deleted file mode 100755 index 9d49e1d..0000000 --- a/gmp/mpz/jacobi.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpz_jacobi (op1, op2). - Contributed by Bennet Yee (bsy) at Carnegie-Mellon University - -Copyright (C) 1991, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" - -/* Precondition: both p and q are positive */ - -int -#if __STDC__ -mpz_jacobi (mpz_srcptr pi, mpz_srcptr qi) -#else -mpz_jacobi (pi, qi) - mpz_srcptr pi, qi; -#endif -{ -#if GCDCHECK - int retval; - mpz_t gcdval; - - mpz_init (gcdval); - mpz_gcd (gcdval, pi, qi); - if (!mpz_cmp_ui (gcdval, 1L)) - { - /* J(ab,cb) = J(ab,c)J(ab,b) = J(ab,c)J(0,b) = J(ab,c)*0 */ - retval = 0; - } - else - retval = mpz_legendre (pi, qi); - mpz_clear (gcdval); - return retval; -#else - return mpz_legendre (pi, qi); -#endif -} diff --git a/gmp/mpz/kronsz.c b/gmp/mpz/kronsz.c deleted file mode 100755 index c8c6752..0000000 --- a/gmp/mpz/kronsz.c +++ /dev/null @@ -1,126 +0,0 @@ -/* mpz_si_kronecker -- Kronecker/Jacobi symbol. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -int -#if __STDC__ -mpz_si_kronecker (long a, mpz_srcptr b) -#else -mpz_si_kronecker (a, b) - long a; - mpz_srcptr b; -#endif -{ - int b_abs_size; - mp_srcptr b_ptr; - mp_limb_t b_low; - int twos; - int result_bit1; - - b_abs_size = ABSIZ (b); - if (b_abs_size == 0) - return JACOBI_S0 (a); /* (a/0) */ - - b_ptr = PTR(b); - b_low = b_ptr[0]; - - /* (0/b) = 1 if b=+/-1, 0 otherwise */ - if (a == 0) - return (b_abs_size == 1) & (b_low == 1); - - /* account for the effect of the sign of b, so can then ignore it */ - result_bit1 = JACOBI_BSGN_SZ_BIT1 (a, b); - - if ((b_low & 1) == 0) - { - /* b even */ - - if ((a & 1) == 0) - return 0; /* (a/b)=0 if both a,b even */ - - /* Require MP_BITS_PER_LIMB even, so that (a/2)^MP_BITS_PER_LIMB = 1, - and so that therefore there's no need to account for how many zero - limbs are stripped. */ - ASSERT ((BITS_PER_MP_LIMB & 1) == 0); - - MPN_STRIP_LOW_ZEROS_NOT_ZERO (b_ptr, b_abs_size); - b_low = b_ptr[0]; - - if ((b_low & 1) == 0) - { - /* odd a, even b */ - - mp_limb_t b_shl_bit1; - - count_trailing_zeros (twos, b_low); - - /* b_shl_bit1 is b>>twos, but with only bit 1 guaranteed */ - if (twos == BITS_PER_MP_LIMB-1) - b_shl_bit1 = (b_abs_size == 1) ? 0 : (b_ptr[1] << 1); - else - b_shl_bit1 = (b_low >> twos); - - result_bit1 ^= JACOBI_ASGN_SU_BIT1 (a, b_shl_bit1); - a = ABS(a); - - if (a == 1) - return JACOBI_BIT1_TO_PN (result_bit1); /* (1/b)=1 */ - - /* twos (a/2), reciprocity to (b/a), and (b/a) = (b mod a / b) */ - return mpn_jacobi_base (mpn_mod_1_rshift (b_ptr, b_abs_size, - twos, a), - a, - result_bit1 - ^ JACOBI_TWOS_U_BIT1 (twos, a) - ^ JACOBI_RECIP_UU_BIT1 (a, b_shl_bit1)); - } - } - - /* b odd */ - - result_bit1 ^= JACOBI_ASGN_SU_BIT1 (a, b_low); - a = ABS(a); - - /* (a/1) = 1 for any a */ - if (b_abs_size == 1 && b_low == 1) - return JACOBI_BIT1_TO_PN (result_bit1); - - /* Note a is cast to unsigned because 0x80..00 doesn't fit in a signed. */ - if ((a & 1) == 0) - { - count_trailing_zeros (twos, a); - a = ((unsigned long) a) >> twos; - result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, b_low); - } - - if (a == 1) - return JACOBI_BIT1_TO_PN (result_bit1); /* (1/b)=1 */ - - /* reciprocity to (b/a), and (b/a) == (b mod a / a) */ - return mpn_jacobi_base (mpn_mod_1 (b_ptr, b_abs_size, a), a, - result_bit1 ^ JACOBI_RECIP_UU_BIT1 (a, b_low)); -} diff --git a/gmp/mpz/kronuz.c b/gmp/mpz/kronuz.c deleted file mode 100755 index b877e6f..0000000 --- a/gmp/mpz/kronuz.c +++ /dev/null @@ -1,115 +0,0 @@ -/* mpz_ui_kronecker -- Kronecker/Jacobi symbol. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -int -#if __STDC__ -mpz_ui_kronecker (unsigned long a, mpz_srcptr b) -#else -mpz_ui_kronecker (a, b) - unsigned long a; - mpz_srcptr b; -#endif -{ - int b_abs_size; - mp_srcptr b_ptr; - mp_limb_t b_low; - int twos; - int result_bit1; - - /* (a/0) */ - b_abs_size = ABSIZ (b); - if (b_abs_size == 0) - return JACOBI_U0 (a); - - /* (a/-1)=1 when a>=0, so the sign of b is ignored */ - b_ptr = PTR(b); - b_low = b_ptr[0]; - - /* (0/1)=1; (0/-1)=1; (0/b)=0 for b!=+/-1 - (1/b)=1, for any b */ - if (a <= 1) - return (a == 1) | ((b_abs_size == 1) & (b_low == 1)); - - if (b_low & 1) - { - /* (a/1) = 1 for any a */ - if (b_abs_size == 1 && b_low == 1) - return 1; - - count_trailing_zeros (twos, a); - a >>= twos; - if (a == 1) - return JACOBI_TWOS_U (twos, b_low); /* powers of (2/b) only */ - - /* powers of (2/b); reciprocity to (b/a); (b/a) == (b mod a / a) */ - return mpn_jacobi_base (mpn_mod_1 (b_ptr, b_abs_size, a), - a, - JACOBI_TWOS_U_BIT1 (twos, b_low) - ^ JACOBI_RECIP_UU_BIT1 (b_low, a)); - } - - /* b is even; (a/2)=0 if a is even */ - if ((a & 1) == 0) - return 0; - - /* Require MP_BITS_PER_LIMB even, so (a/2)^MP_BITS_PER_LIMB = 1, and so we - don't have to pay attention to how many trailing zero limbs are - stripped. */ - ASSERT ((BITS_PER_MP_LIMB & 1) == 0); - - MPN_STRIP_LOW_ZEROS_NOT_ZERO (b_ptr, b_abs_size); - b_low = b_ptr[0]; - - if (b_low & 1) - /* reciprocity to (b/a); (b/a) == (b mod a / a) */ - return mpn_jacobi_base (mpn_mod_1 (b_ptr, b_abs_size, a), - a, - JACOBI_RECIP_UU_BIT1 (b_low, a)); - - count_trailing_zeros (twos, b_low); - - /* reciprocity to get (b/a) */ - if (twos == BITS_PER_MP_LIMB-1) - { - if (b_abs_size == 1) - { - /* b==0x800...00, one limb high bit only, so (a/2)^(BPML-1) */ - return JACOBI_TWOS_U (BITS_PER_MP_LIMB-1, a); - } - - /* b_abs_size > 1 */ - result_bit1 = JACOBI_RECIP_UU_BIT1 (a, b_ptr[1] << 1); - } - else - result_bit1 = JACOBI_RECIP_UU_BIT1 (a, b_low >> twos); - - /* powers of (a/2); reciprocity to (b/a); (b/a) == (b mod a / a) */ - return mpn_jacobi_base (mpn_mod_1_rshift (b_ptr, b_abs_size, twos, a), - a, - JACOBI_TWOS_U_BIT1 (twos, a) ^ result_bit1); -} diff --git a/gmp/mpz/kronzs.c b/gmp/mpz/kronzs.c deleted file mode 100755 index edfb465..0000000 --- a/gmp/mpz/kronzs.c +++ /dev/null @@ -1,74 +0,0 @@ -/* mpz_kronecker_si -- Kronecker/Jacobi symbol. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* This function is expected to be often used with b odd, so there's a test - for this before invoking count_trailing_zeros(). - - After the absolute value of b is established it's treated as an unsigned - long, because 0x80..00 doesn't fit in a signed long. */ - -int -#if __STDC__ -mpz_kronecker_si (mpz_srcptr a, long b) -#else -mpz_kronecker_si (a, b) - mpz_srcptr a; - long b; -#endif -{ - int result_bit1; - int twos; - - if (b == 0) - return JACOBI_Z0 (a); - - result_bit1 = JACOBI_BSGN_ZS_BIT1(a, b); - b = ABS (b); - - if (b == 1) - return JACOBI_BIT1_TO_PN (result_bit1); /* (a/1) = 1 for any a */ - - if (b & 1) - return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, result_bit1); - - /* result 0 if both a,b even */ - if (mpz_even_p (a)) - return 0; - - /* (a/2)=(2/a) when a odd */ - count_trailing_zeros (twos, b); - result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, PTR(a)[0]); - - b = ((unsigned long) b) >> twos; - if (b == 1) - return JACOBI_BIT1_TO_PN (result_bit1); - else - return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, result_bit1); -} - - diff --git a/gmp/mpz/kronzu.c b/gmp/mpz/kronzu.c deleted file mode 100755 index 749be5d..0000000 --- a/gmp/mpz/kronzu.c +++ /dev/null @@ -1,66 +0,0 @@ -/* mpz_kronecker_ui -- Kronecker/Jacobi symbol. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -/* This function is expected to be often used with b an odd prime, so the - code for odd b is nice and short. */ - -int -#if __STDC__ -mpz_kronecker_ui (mpz_srcptr a, unsigned long b) -#else -mpz_kronecker_ui (a, b) - mpz_srcptr a; - unsigned long b; -#endif -{ - int twos; - - if (b & 1) - { - if (b != 1) - return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, 0); - else - return 1; /* (a/1)=1 for any a */ - } - - if (b == 0) - return JACOBI_Z0 (a); - - /* (a/2)=0 if a even */ - if (mpz_even_p (a)) - return 0; - - /* (a/2)=(2/a) when a odd */ - count_trailing_zeros (twos, b); - b >>= twos; - if (b == 1) - return JACOBI_TWOS_U (twos, PTR(a)[0]); - - return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, - JACOBI_TWOS_U_BIT1(twos, PTR(a)[0])); -} diff --git a/gmp/mpz/lcm.c b/gmp/mpz/lcm.c deleted file mode 100755 index ca8c15c..0000000 --- a/gmp/mpz/lcm.c +++ /dev/null @@ -1,56 +0,0 @@ -/* mpz/lcm.c: Calculate the least common multiple of two integers. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void *_mpz_realloc (); - -void -#if __STDC__ -mpz_lcm (mpz_ptr r, mpz_srcptr u, mpz_srcptr v) -#else -mpz_lcm (r, u, v) - mpz_ptr r; - mpz_srcptr u; - mpz_srcptr v; -#endif -{ - mpz_t g; - mp_size_t usize, vsize, size; - - usize = ABS (SIZ (u)); - vsize = ABS (SIZ (v)); - - if (usize == 0 || vsize == 0) - { - SIZ (r) = 0; - return; - } - - size = MAX (usize, vsize); - MPZ_TMP_INIT (g, size); - - mpz_gcd (g, u, v); - mpz_divexact (g, u, g); - mpz_mul (r, g, v); -} diff --git a/gmp/mpz/legendre.c b/gmp/mpz/legendre.c deleted file mode 100755 index ab665f7..0000000 --- a/gmp/mpz/legendre.c +++ /dev/null @@ -1,184 +0,0 @@ -/* mpz_legendre (op1, op2). - Contributed by Bennet Yee (bsy) at Carnegie-Mellon University - -Copyright (C) 1992, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" - -#if defined (DEBUG) -#include -#endif - -/* Precondition: both p and q are positive */ - -int -#if __STDC__ -mpz_legendre (mpz_srcptr pi, mpz_srcptr qi) -#else -mpz_legendre (pi, qi) -mpz_srcptr pi, qi; -#endif -{ - mpz_t p, q, qdiv2; -#ifdef Q_MINUS_1 - mpz_t q_minus_1; -#endif - mpz_ptr mtmp; - register mpz_ptr pptr, qptr; - register int retval = 1; - register unsigned long int s; - - pptr = p; - mpz_init_set (pptr, pi); - qptr = q; - mpz_init_set (qptr, qi); - -#ifdef Q_MINUS_1 - mpz_init (q_minus_1); -#endif - mpz_init (qdiv2); - -tail_recurse2: -#ifdef DEBUG - printf ("tail_recurse2: p="); - mpz_out_str (stdout, 10, pptr); - printf ("\nq="); - mpz_out_str (stdout, 10, qptr); - putchar ('\n'); -#endif - s = mpz_scan1 (qptr, 0); - if (s) mpz_tdiv_q_2exp (qptr, qptr, s); /* J(a,2) = 1 */ -#ifdef DEBUG - printf ("2 factor decomposition: p="); - mpz_out_str (stdout, 10, pptr); - printf ("\nq="); - mpz_out_str (stdout, 10, qptr); - putchar ('\n'); -#endif - /* postcondition q odd */ - if (!mpz_cmp_ui (qptr, 1L)) /* J(a,1) = 1 */ - goto done; - mpz_mod (pptr, pptr, qptr); /* J(a,q) = J(b,q) when a == b mod q */ -#ifdef DEBUG - printf ("mod out by q: p="); - mpz_out_str (stdout, 10, pptr); - printf ("\nq="); - mpz_out_str (stdout, 10, qptr); - putchar ('\n'); -#endif - /* quick calculation to get approximate size first */ - /* precondition: p < q */ - if ((mpz_sizeinbase (pptr, 2) + 1 >= mpz_sizeinbase (qptr,2)) - && (mpz_tdiv_q_2exp (qdiv2, qptr, 1L), mpz_cmp (pptr, qdiv2) > 0)) - { - /* p > q/2 */ - mpz_sub (pptr, qptr, pptr); - /* J(-1,q) = (-1)^((q-1)/2), q odd */ - if (mpz_get_ui (qptr) & 2) - retval = -retval; - } - /* p < q/2 */ -#ifdef Q_MINUS_1 - mpz_sub_ui (q_minus_q, qptr, 1L); -#endif -tail_recurse: /* we use tail_recurse only if q has not changed */ -#ifdef DEBUG - printf ("tail_recurse1: p="); - mpz_out_str (stdout, 10, pptr); - printf ("\nq="); - mpz_out_str (stdout, 10, qptr); - putchar ('\n'); -#endif - /* - * J(0,q) = 0 - * this occurs only if gcd(p,q) != 1 which is never true for - * Legendre function. - */ - if (!mpz_cmp_ui (pptr, 0L)) - { - retval = 0; - goto done; - } - - if (!mpz_cmp_ui (pptr, 1L)) - { - /* J(1,q) = 1 */ - /* retval *= 1; */ - goto done; - } -#ifdef Q_MINUS_1 - if (!mpz_cmp (pptr, q_minus_1)) - { - /* J(-1,q) = (-1)^((q-1)/2) */ - if (mpz_get_ui (qptr) & 2) - retval = -retval; - /* else retval *= 1; */ - goto done; - } -#endif - /* - * we do not handle J(xy,q) except for x==2 - * since we do not want to factor - */ - if ((s = mpz_scan1 (pptr, 0)) != 0) - { - /* - * J(2,q) = (-1)^((q^2-1)/8) - * - * Note that q odd guarantees that q^2-1 is divisible by 8: - * Let a: q=2a+1. q^2 = 4a^2+4a+1, (q^2-1)/8 = a(a+1)/2, qed - * - * Now, note that this means that the low two bits of _a_ - * (or the low bits of q shifted over by 1 determines - * the factor). - */ - mpz_tdiv_q_2exp (pptr, pptr, s); - - /* even powers of 2 gives J(2,q)^{2n} = 1 */ - if (s & 1) - { - s = mpz_get_ui (qptr) >> 1; - s = s * (s + 1); - if (s & 2) - retval = -retval; - } - goto tail_recurse; - } - /* - * we know p is odd since we have cast out 2s - * precondition that q is odd guarantees both odd. - * - * quadratic reciprocity - * J(p,q) = (-1)^((p-1)(q-1)/4) * J(q,p) - */ - if ((s = mpz_scan1 (pptr, 1)) <= 2 && (s + mpz_scan1 (qptr, 1)) <= 2) - retval = -retval; - - mtmp = pptr; pptr = qptr; qptr = mtmp; - goto tail_recurse2; -done: - mpz_clear (p); - mpz_clear (q); - mpz_clear (qdiv2); -#ifdef Q_MINUS_1 - mpz_clear (q_minus_1); -#endif - return retval; -} diff --git a/gmp/mpz/mod.c b/gmp/mpz/mod.c deleted file mode 100755 index 87033b3..0000000 --- a/gmp/mpz/mod.c +++ /dev/null @@ -1,63 +0,0 @@ -/* mpz_mod -- The mathematical mod function. - -Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_mod (mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor) -#else -mpz_mod (rem, dividend, divisor) - mpz_ptr rem; - mpz_srcptr dividend; - mpz_srcptr divisor; -#endif -{ - mp_size_t divisor_size = divisor->_mp_size; - mpz_t temp_divisor; /* N.B.: lives until function returns! */ - TMP_DECL (marker); - - TMP_MARK (marker); - - /* We need the original value of the divisor after the remainder has been - preliminary calculated. We have to copy it to temporary space if it's - the same variable as REM. */ - if (rem == divisor) - { - MPZ_TMP_INIT (temp_divisor, ABS (divisor_size)); - mpz_set (temp_divisor, divisor); - divisor = temp_divisor; - } - - mpz_tdiv_r (rem, dividend, divisor); - - if (rem->_mp_size != 0) - { - if (dividend->_mp_size < 0) - if (divisor->_mp_size < 0) - mpz_sub (rem, rem, divisor); - else - mpz_add (rem, rem, divisor); - } - - TMP_FREE (marker); -} diff --git a/gmp/mpz/mul.c b/gmp/mpz/mul.c deleted file mode 100755 index 7854788..0000000 --- a/gmp/mpz/mul.c +++ /dev/null @@ -1,131 +0,0 @@ -/* mpz_mul -- Multiply two integers. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_mul (mpz_ptr w, mpz_srcptr u, mpz_srcptr v) -#else -mpz_mul (w, u, v) - mpz_ptr w; - mpz_srcptr u; - mpz_srcptr v; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -mult (mpz_srcptr u, mpz_srcptr v, mpz_ptr w) -#else -mult (u, v, w) - mpz_srcptr u; - mpz_srcptr v; - mpz_ptr w; -#endif -#endif /* BERKELEY_MP */ -{ - mp_size_t usize = u->_mp_size; - mp_size_t vsize = v->_mp_size; - mp_size_t wsize; - mp_size_t sign_product; - mp_ptr up, vp; - mp_ptr wp; - mp_ptr free_me = NULL; - size_t free_me_size; - mp_limb_t cy_limb; - TMP_DECL (marker); - - TMP_MARK (marker); - sign_product = usize ^ vsize; - usize = ABS (usize); - vsize = ABS (vsize); - - if (usize < vsize) - { - /* Swap U and V. */ - {const __mpz_struct *t = u; u = v; v = t;} - {mp_size_t t = usize; usize = vsize; vsize = t;} - } - - up = u->_mp_d; - vp = v->_mp_d; - wp = w->_mp_d; - - /* Ensure W has space enough to store the result. */ - wsize = usize + vsize; - if (w->_mp_alloc < wsize) - { - if (wp == up || wp == vp) - { - free_me = wp; - free_me_size = w->_mp_alloc; - } - else - (*_mp_free_func) (wp, w->_mp_alloc * BYTES_PER_MP_LIMB); - - w->_mp_alloc = wsize; - wp = (mp_ptr) (*_mp_allocate_func) (wsize * BYTES_PER_MP_LIMB); - w->_mp_d = wp; - } - else - { - /* Make U and V not overlap with W. */ - if (wp == up) - { - /* W and U are identical. Allocate temporary space for U. */ - up = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB); - /* Is V identical too? Keep it identical with U. */ - if (wp == vp) - vp = up; - /* Copy to the temporary space. */ - MPN_COPY (up, wp, usize); - } - else if (wp == vp) - { - /* W and V are identical. Allocate temporary space for V. */ - vp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - /* Copy to the temporary space. */ - MPN_COPY (vp, wp, vsize); - } - } - - if (vsize == 0) - { - wsize = 0; - } - else - { - cy_limb = mpn_mul (wp, up, usize, vp, vsize); - wsize = usize + vsize; - wsize -= cy_limb == 0; - } - - w->_mp_size = sign_product < 0 ? -wsize : wsize; - if (free_me != NULL) - (*_mp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB); - TMP_FREE (marker); -} diff --git a/gmp/mpz/mul_2exp.c b/gmp/mpz/mul_2exp.c deleted file mode 100755 index abea5fe..0000000 --- a/gmp/mpz/mul_2exp.c +++ /dev/null @@ -1,76 +0,0 @@ -/* mpz_mul_2exp -- Multiply a bignum by 2**CNT - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_mul_2exp (mpz_ptr w, mpz_srcptr u, unsigned long int cnt) -#else -mpz_mul_2exp (w, u, cnt) - mpz_ptr w; - mpz_srcptr u; - unsigned long int cnt; -#endif -{ - mp_size_t usize = u->_mp_size; - mp_size_t abs_usize = ABS (usize); - mp_size_t wsize; - mp_size_t limb_cnt; - mp_ptr wp; - mp_limb_t wlimb; - - if (usize == 0) - { - w->_mp_size = 0; - return; - } - - limb_cnt = cnt / BITS_PER_MP_LIMB; - wsize = abs_usize + limb_cnt + 1; - if (w->_mp_alloc < wsize) - _mpz_realloc (w, wsize); - - wp = w->_mp_d; - wsize = abs_usize + limb_cnt; - - cnt %= BITS_PER_MP_LIMB; - if (cnt != 0) - { - wlimb = mpn_lshift (wp + limb_cnt, u->_mp_d, abs_usize, cnt); - if (wlimb != 0) - { - wp[wsize] = wlimb; - wsize++; - } - } - else - { - MPN_COPY_DECR (wp + limb_cnt, u->_mp_d, abs_usize); - } - - /* Zero all whole limbs at low end. Do it here and not before calling - mpn_lshift, not to lose for U == W. */ - MPN_ZERO (wp, limb_cnt); - - w->_mp_size = usize >= 0 ? wsize : -wsize; -} diff --git a/gmp/mpz/mul_si.c b/gmp/mpz/mul_si.c deleted file mode 100755 index a39634c..0000000 --- a/gmp/mpz/mul_si.c +++ /dev/null @@ -1,82 +0,0 @@ -/* mpz_mul_ui/si (product, multiplier, small_multiplicand) -- Set PRODUCT to - MULTIPLICATOR times SMALL_MULTIPLICAND. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#define OPERATION_mul_si - -#ifdef OPERATION_mul_ui -#define FUNCTION mpz_mul_ui -#define MULTIPLICAND_UNSIGNED unsigned -#define MULTIPLICAND_ABS(x) x -#else -#ifdef OPERATION_mul_si -#define FUNCTION mpz_mul_si -#define MULTIPLICAND_UNSIGNED -#define MULTIPLICAND_ABS(x) ABS(x) -#else -Error, error, unrecognised OPERATION -#endif -#endif - - -void -#if __STDC__ -FUNCTION (mpz_ptr prod, mpz_srcptr mult, - MULTIPLICAND_UNSIGNED long int small_mult) -#else -FUNCTION (prod, mult, small_mult) - mpz_ptr prod; - mpz_srcptr mult; - MULTIPLICAND_UNSIGNED long int small_mult; -#endif -{ - mp_size_t size = mult->_mp_size; - mp_size_t sign_product = size; - mp_limb_t cy; - mp_size_t prod_size; - mp_ptr prod_ptr; - - if (size == 0 || small_mult == 0) - { - prod->_mp_size = 0; - return; - } - size = ABS (size); - - prod_size = size + 1; - if (prod->_mp_alloc < prod_size) - _mpz_realloc (prod, prod_size); - - prod_ptr = prod->_mp_d; - - cy = mpn_mul_1 (prod_ptr, mult->_mp_d, size, - (mp_limb_t) MULTIPLICAND_ABS (small_mult)); - if (cy != 0) - { - prod_ptr[size] = cy; - size++; - } - - prod->_mp_size = ((sign_product < 0) ^ (small_mult < 0)) ? -size : size; -} diff --git a/gmp/mpz/mul_siui.c b/gmp/mpz/mul_siui.c deleted file mode 100755 index 9849cd4..0000000 --- a/gmp/mpz/mul_siui.c +++ /dev/null @@ -1,81 +0,0 @@ -/* mpz_mul_ui/si (product, multiplier, small_multiplicand) -- Set PRODUCT to - MULTIPLICATOR times SMALL_MULTIPLICAND. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - - -#ifdef OPERATION_mul_ui -#define FUNCTION mpz_mul_ui -#define MULTIPLICAND_UNSIGNED unsigned -#define MULTIPLICAND_ABS(x) x -#else -#ifdef OPERATION_mul_si -#define FUNCTION mpz_mul_si -#define MULTIPLICAND_UNSIGNED -#define MULTIPLICAND_ABS(x) ABS(x) -#else -Error, error, unrecognised OPERATION -#endif -#endif - - -void -#if __STDC__ -FUNCTION (mpz_ptr prod, mpz_srcptr mult, - MULTIPLICAND_UNSIGNED long int small_mult) -#else -FUNCTION (prod, mult, small_mult) - mpz_ptr prod; - mpz_srcptr mult; - MULTIPLICAND_UNSIGNED long int small_mult; -#endif -{ - mp_size_t size = mult->_mp_size; - mp_size_t sign_product = size; - mp_limb_t cy; - mp_size_t prod_size; - mp_ptr prod_ptr; - - if (size == 0 || small_mult == 0) - { - prod->_mp_size = 0; - return; - } - size = ABS (size); - - prod_size = size + 1; - if (prod->_mp_alloc < prod_size) - _mpz_realloc (prod, prod_size); - - prod_ptr = prod->_mp_d; - - cy = mpn_mul_1 (prod_ptr, mult->_mp_d, size, - (mp_limb_t) MULTIPLICAND_ABS (small_mult)); - if (cy != 0) - { - prod_ptr[size] = cy; - size++; - } - - prod->_mp_size = ((sign_product < 0) ^ (small_mult < 0)) ? -size : size; -} diff --git a/gmp/mpz/mul_ui.c b/gmp/mpz/mul_ui.c deleted file mode 100755 index f399c54..0000000 --- a/gmp/mpz/mul_ui.c +++ /dev/null @@ -1,82 +0,0 @@ -/* mpz_mul_ui/si (product, multiplier, small_multiplicand) -- Set PRODUCT to - MULTIPLICATOR times SMALL_MULTIPLICAND. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -#define OPERATION_mul_ui - -#ifdef OPERATION_mul_ui -#define FUNCTION mpz_mul_ui -#define MULTIPLICAND_UNSIGNED unsigned -#define MULTIPLICAND_ABS(x) x -#else -#ifdef OPERATION_mul_si -#define FUNCTION mpz_mul_si -#define MULTIPLICAND_UNSIGNED -#define MULTIPLICAND_ABS(x) ABS(x) -#else -Error, error, unrecognised OPERATION -#endif -#endif - - -void -#if __STDC__ -FUNCTION (mpz_ptr prod, mpz_srcptr mult, - MULTIPLICAND_UNSIGNED long int small_mult) -#else -FUNCTION (prod, mult, small_mult) - mpz_ptr prod; - mpz_srcptr mult; - MULTIPLICAND_UNSIGNED long int small_mult; -#endif -{ - mp_size_t size = mult->_mp_size; - mp_size_t sign_product = size; - mp_limb_t cy; - mp_size_t prod_size; - mp_ptr prod_ptr; - - if (size == 0 || small_mult == 0) - { - prod->_mp_size = 0; - return; - } - size = ABS (size); - - prod_size = size + 1; - if (prod->_mp_alloc < prod_size) - _mpz_realloc (prod, prod_size); - - prod_ptr = prod->_mp_d; - - cy = mpn_mul_1 (prod_ptr, mult->_mp_d, size, - (mp_limb_t) MULTIPLICAND_ABS (small_mult)); - if (cy != 0) - { - prod_ptr[size] = cy; - size++; - } - - prod->_mp_size = ((sign_product < 0) ^ (small_mult < 0)) ? -size : size; -} diff --git a/gmp/mpz/neg.c b/gmp/mpz/neg.c deleted file mode 100755 index 566c3a9..0000000 --- a/gmp/mpz/neg.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpz_neg(mpz_ptr dst, mpz_ptr src) -- Assign the negated value of SRC to DST. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_neg (mpz_ptr w, mpz_srcptr u) -#else -mpz_neg (w, u) - mpz_ptr w; - mpz_srcptr u; -#endif -{ - mp_ptr wp, up; - mp_size_t usize, size; - - usize = u->_mp_size; - - if (u != w) - { - size = ABS (usize); - - if (w->_mp_alloc < size) - _mpz_realloc (w, size); - - wp = w->_mp_d; - up = u->_mp_d; - - MPN_COPY (wp, up, size); - } - - w->_mp_size = -usize; -} diff --git a/gmp/mpz/nextprime.c b/gmp/mpz/nextprime.c deleted file mode 100755 index f024dd1..0000000 --- a/gmp/mpz/nextprime.c +++ /dev/null @@ -1,120 +0,0 @@ -/* mpz_nextprime(p,t) - compute the next prime > t and store that in p. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_nextprime (mpz_ptr p, mpz_srcptr t) -#else -mpz_nextprime (p, t) - mpz_ptr p; - mpz_srcptr t; -#endif -{ - mpz_add_ui (p, t, 1L); - while (! mpz_probab_prime_p (p, 5)) - mpz_add_ui (p, p, 1L); -} - -#if 0 -/* This code is not yet tested. Will be enabled in 3.1. */ - -status unsigned short primes[] = -{ -3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97, -101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181, -191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277, -281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383, -389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487, -491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601, -607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709, -719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827, -829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947, -953,967,971,977,983,991,997 -}; - -#define NUMBER_OF_PRIMES 167 - -void -#if __STDC__ -mpz_nextprime (mpz_ptr p, mpz_srcptr n) -#else -mpz_nextprime (p, n) - mpz_ptr p; - mpz_srcptr n; -#endif -{ - mpz_t tmp; - unsigned short *moduli; - unsigned long difference; - int i; - int composite; - - /* First handle tiny numbers */ - if (mpz_cmp_ui (n, 2) < 0) - { - mpz_set_ui (p, 2); - return; - } - mpz_add_ui (p, n, 1); - mpz_setbit (p, 0); - - if (mpz_cmp_ui (p, 7) <= 0) - return; - - prime_limit = NUMBER_OF_PRIMES - 1; - if (mpz_cmp_ui (p, primes[prime_limit]) <= 0) - /* Just use first three entries (3,5,7) of table for small numbers */ - prime_limit = 3; - if (prime_limit) - { - /* Compute residues modulo small odd primes */ - moduli = (unsigned short *) TMP_ALLOC (prime_limit * sizeof moduli[0]); - for (i = 0; i < prime_limit; i++) - moduli[i] = mpz_fdiv_ui (p, primes[i]); - } - for (difference = 0; ; difference += 2) - { - composite = 0; - - /* First check residues */ - for (i = 0; i < prime_limit; i++) - { - int acc, pr; - composite |= (moduli[i] == 0); - acc = moduli[i] + 2; - pr = primes[i]; - moduli[i] = acc >= pr ? acc - pr : acc; - } - if (composite) - continue; - - mpz_add_ui (p, p, difference); - difference = 0; - - /* Miller-Rabin test */ - if (mpz_millerrabin (p, 2)) - break; - } -} -#endif diff --git a/gmp/mpz/out_raw.c b/gmp/mpz/out_raw.c deleted file mode 100755 index 6270947..0000000 --- a/gmp/mpz/out_raw.c +++ /dev/null @@ -1,89 +0,0 @@ -/* mpz_out_raw -- Output a mpz_t in binary. Use an endianess and word size - independent format. - -Copyright (C) 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include - -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpz_out_raw (FILE *stream, mpz_srcptr x) -#else -mpz_out_raw (stream, x) - FILE *stream; - mpz_srcptr x; -#endif -{ - int i; - mp_size_t s; - mp_size_t xsize = ABS (x->_mp_size); - mp_srcptr xp = x->_mp_d; - mp_size_t out_bytesize; - mp_limb_t hi_limb; - int n_bytes_in_hi_limb; - - if (stream == 0) - stream = stdout; - - if (xsize == 0) - { - for (i = 4 - 1; i >= 0; i--) - fputc (0, stream); - return ferror (stream) ? 0 : 4; - } - - hi_limb = xp[xsize - 1]; - for (i = BYTES_PER_MP_LIMB - 1; i > 0; i--) - { - if ((hi_limb >> i * BITS_PER_CHAR) != 0) - break; - } - n_bytes_in_hi_limb = i + 1; - out_bytesize = BYTES_PER_MP_LIMB * (xsize - 1) + n_bytes_in_hi_limb; - if (x->_mp_size < 0) - out_bytesize = -out_bytesize; - - /* Make the size 4 bytes on all machines, to make the format portable. */ - for (i = 4 - 1; i >= 0; i--) - fputc ((out_bytesize >> (i * BITS_PER_CHAR)) % (1 << BITS_PER_CHAR), - stream); - - /* Output from the most significant limb to the least significant limb, - with each limb also output in decreasing significance order. */ - - /* Output the most significant limb separately, since we will only - output some of its bytes. */ - for (i = n_bytes_in_hi_limb - 1; i >= 0; i--) - fputc ((hi_limb >> (i * BITS_PER_CHAR)) % (1 << BITS_PER_CHAR), stream); - - /* Output the remaining limbs. */ - for (s = xsize - 2; s >= 0; s--) - { - mp_limb_t x_limb; - - x_limb = xp[s]; - for (i = BYTES_PER_MP_LIMB - 1; i >= 0; i--) - fputc ((x_limb >> (i * BITS_PER_CHAR)) % (1 << BITS_PER_CHAR), stream); - } - return ferror (stream) ? 0 : ABS (out_bytesize) + 4; -} diff --git a/gmp/mpz/out_str.c b/gmp/mpz/out_str.c deleted file mode 100755 index bf971b0..0000000 --- a/gmp/mpz/out_str.c +++ /dev/null @@ -1,108 +0,0 @@ -/* mpz_out_str(stream, base, integer) -- Output to STREAM the multi prec. - integer INTEGER in base BASE. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpz_out_str (FILE *stream, int base, mpz_srcptr x) -#else -mpz_out_str (stream, base, x) - FILE *stream; - int base; - mpz_srcptr x; -#endif -{ - mp_ptr xp; - mp_size_t x_size = x->_mp_size; - unsigned char *str; - size_t str_size; - size_t i; - size_t written; - char *num_to_text; - TMP_DECL (marker); - - if (stream == 0) - stream = stdout; - - if (base >= 0) - { - if (base == 0) - base = 10; - num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz"; - } - else - { - base = -base; - num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - } - - if (x_size == 0) - { - fputc ('0', stream); - return ferror (stream) ? 0 : 1; - } - - written = 0; - - if (x_size < 0) - { - fputc ('-', stream); - x_size = -x_size; - written = 1; - } - - TMP_MARK (marker); - str_size = ((size_t) (x_size * BITS_PER_MP_LIMB - * __mp_bases[base].chars_per_bit_exactly)) + 3; - str = (unsigned char *) TMP_ALLOC (str_size); - - /* Move the number to convert into temporary space, since mpn_get_str - clobbers its argument + needs one extra high limb.... */ - xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (xp, x->_mp_d, x_size); - - str_size = mpn_get_str (str, base, xp, x_size); - - /* mpn_get_str might make some leading zeros. Skip them. */ - while (*str == 0) - { - str_size--; - str++; - } - - /* Translate to printable chars. */ - for (i = 0; i < str_size; i++) - str[i] = num_to_text[str[i]]; - str[str_size] = 0; - - { - size_t fwret; - fwret = fwrite ((char *) str, 1, str_size, stream); - written += fwret; - } - - TMP_FREE (marker); - return ferror (stream) ? 0 : written; -} diff --git a/gmp/mpz/perfpow.c b/gmp/mpz/perfpow.c deleted file mode 100755 index e71670a..0000000 --- a/gmp/mpz/perfpow.c +++ /dev/null @@ -1,272 +0,0 @@ -/* mpz_perfect_power_p(arg) -- Return non-zero if ARG is a perfect power, - zero otherwise. - -Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* - We are to determine if c is a perfect power, c = a ^ b. - Assume c is divisible by 2^n and that codd = c/2^n is odd. - Assume a is divisible by 2^m and that aodd = a/2^m is odd. - It is always true that m divides n. - - * If n is prime, either 1) a is 2*aodd and b = n - or 2) a = c and b = 1. - So for n prime, we readily have a solution. - * If n is factorable into the non-trivial factors p1,p2,... - Since m divides n, m has a subset of n's factors and b = n / m. - - BUG: Should handle negative numbers, since they can be odd perfect powers. -*/ - -/* This is a naive approach to recognizing perfect powers. - Many things can be improved. In particular, we should use p-adic - arithmetic for computing possible roots. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -static unsigned long int gcd _PROTO ((unsigned long int a, unsigned long int b)); -static int isprime _PROTO ((unsigned long int t)); - -static const unsigned short primes[] = -{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, - 59, 61, 67, 71, 73, 79, 83, 89, 97,101,103,107,109,113,127,131, - 137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223, - 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311, - 313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409, - 419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503, - 509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613, - 617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719, - 727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827, - 829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941, - 947,953,967,971,977,983,991,997,0 -}; -#define SMALLEST_OMITTED_PRIME 1009 - - -int -#if __STDC__ -mpz_perfect_power_p (mpz_srcptr u) -#else -mpz_perfect_power_p (u) - mpz_srcptr u; -#endif -{ - unsigned long int prime; - unsigned long int n, n2; - int i; - unsigned long int rem; - mpz_t u2, q; - int exact; - mp_size_t uns; - TMP_DECL (marker); - - if (mpz_cmp_ui (u, 1) <= 0) - return 0; - - n2 = mpz_scan1 (u, 0); - if (n2 == 1) - return 0; - - TMP_MARK (marker); - - uns = ABSIZ (u) - n2 / BITS_PER_MP_LIMB; - MPZ_TMP_INIT (q, uns); - MPZ_TMP_INIT (u2, uns); - - mpz_tdiv_q_2exp (u2, u, n2); - - if (isprime (n2)) - goto n2prime; - - for (i = 1; primes[i] != 0; i++) - { - prime = primes[i]; - rem = mpz_tdiv_ui (u2, prime); - if (rem == 0) /* divisable? */ - { - rem = mpz_tdiv_q_ui (q, u2, prime * prime); - if (rem != 0) - { - TMP_FREE (marker); - return 0; - } - mpz_swap (q, u2); - for (n = 2;;) - { - rem = mpz_tdiv_q_ui (q, u2, prime); - if (rem != 0) - break; - mpz_swap (q, u2); - n++; - } - - n2 = gcd (n2, n); - if (n2 == 1) - { - TMP_FREE (marker); - return 0; - } - - /* As soon as n2 becomes a prime number, stop factoring. - Either we have u=x^n2 or u is not a perfect power. */ - if (isprime (n2)) - goto n2prime; - } - } - - if (mpz_cmp_ui (u2, 1) == 0) - { - TMP_FREE (marker); - return 1; - } - - if (n2 == 0) - { - unsigned long int nth; - /* We did not find any factors above. We have to consider all values - of n. */ - for (nth = 2;; nth++) - { - if (! isprime (nth)) - continue; -#if 0 - exact = mpz_padic_root (q, u2, nth, PTH); - if (exact) -#endif - exact = mpz_root (q, u2, nth); - if (exact) - { - TMP_FREE (marker); - return 1; - } - if (mpz_cmp_ui (q, SMALLEST_OMITTED_PRIME) < 0) - { - TMP_FREE (marker); - return 0; - } - } - } - else - { - unsigned long int nth; - /* We found some factors above. We just need to consider values of n - that divides n2. */ - for (nth = 2; nth <= n2; nth++) - { - if (! isprime (nth)) - continue; - if (n2 % nth != 0) - continue; -#if 0 - exact = mpz_padic_root (q, u2, nth, PTH); - if (exact) -#endif - exact = mpz_root (q, u2, nth); - if (exact) - { - TMP_FREE (marker); - return 1; - } - if (mpz_cmp_ui (q, SMALLEST_OMITTED_PRIME) < 0) - { - TMP_FREE (marker); - return 0; - } - } - - TMP_FREE (marker); - return 0; - } - -n2prime: - exact = mpz_root (NULL, u2, n2); - TMP_FREE (marker); - return exact; -} - -static unsigned long int -#if __STDC__ -gcd (unsigned long int a, unsigned long int b) -#else -gcd (a, b) - unsigned long int a, b; -#endif -{ - int an2, bn2, n2; - - if (a == 0) - return b; - if (b == 0) - return a; - - count_trailing_zeros (an2, a); - a >>= an2; - - count_trailing_zeros (bn2, b); - b >>= bn2; - - n2 = MIN (an2, bn2); - - while (a != b) - { - if (a > b) - { - a -= b; - do - a >>= 1; - while ((a & 1) == 0); - } - else /* b > a. */ - { - b -= a; - do - b >>= 1; - while ((b & 1) == 0); - } - } - - return a << n2; -} - -static int -#if __STDC__ -isprime (unsigned long int t) -#else -isprime (t) - unsigned long int t; -#endif -{ - unsigned long int q, r, d; - - if (t < 3 || (t & 1) == 0) - return t == 2; - - for (d = 3, r = 1; r != 0; d += 2) - { - q = t / d; - r = t - q * d; - if (q < d) - return 1; - } - return 0; -} diff --git a/gmp/mpz/perfsqr.c b/gmp/mpz/perfsqr.c deleted file mode 100755 index 92e8d08..0000000 --- a/gmp/mpz/perfsqr.c +++ /dev/null @@ -1,45 +0,0 @@ -/* mpz_perfect_square_p(arg) -- Return non-zero if ARG is a perfect square, - zero otherwise. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_perfect_square_p (mpz_srcptr a) -#else -mpz_perfect_square_p (a) - mpz_srcptr a; -#endif -{ - mp_size_t asize = a->_mp_size; - - /* No negative numbers are perfect squares. */ - if (asize < 0) - return 0; - - /* Zero is a perfect square. */ - if (asize == 0) - return 1; - - return mpn_perfect_square_p (a->_mp_d, asize); -} diff --git a/gmp/mpz/popcount.c b/gmp/mpz/popcount.c deleted file mode 100755 index 3105258..0000000 --- a/gmp/mpz/popcount.c +++ /dev/null @@ -1,42 +0,0 @@ -/* mpz_popcount(mpz_ptr op) -- Population count of OP. If the operand is - negative, return ~0 (a novel representation of infinity). - -Copyright (C) 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_popcount (mpz_srcptr u) -#else -mpz_popcount (u) - mpz_srcptr u; -#endif -{ - mp_size_t usize; - - usize = u->_mp_size; - - if ((usize) < 0) - return ~ (unsigned long int) 0; - - return mpn_popcount (u->_mp_d, usize); -} diff --git a/gmp/mpz/pow_ui.c b/gmp/mpz/pow_ui.c deleted file mode 100755 index 96ca114..0000000 --- a/gmp/mpz/pow_ui.c +++ /dev/null @@ -1,129 +0,0 @@ -/* mpz_pow_ui(res, base, exp) -- Set RES to BASE**EXP. - -Copyright (C) 1991, 1993, 1994, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#ifdef BERKELEY_MP -#include "mp.h" -#endif -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_pow_ui (mpz_ptr r, mpz_srcptr b, unsigned long int e) -#else -mpz_pow_ui (r, b, e) - mpz_ptr r; - mpz_srcptr b; - unsigned long int e; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -rpow (const MINT *b, signed short int e, MINT *r) -#else -rpow (b, e, r) - const MINT *b; - signed short int e; - MINT *r; -#endif -#endif /* BERKELEY_MP */ -{ - mp_ptr rp, bp, tp, xp; - mp_size_t ralloc, rsize, bsize; - int cnt, i; - mp_limb_t blimb; - TMP_DECL (marker); - - bsize = ABS (b->_mp_size); - - /* Single out cases that give result == 0 or 1. These tests are here - to simplify the general code below, not to optimize. */ - if (e == 0) - { - r->_mp_d[0] = 1; - r->_mp_size = 1; - return; - } - if (bsize == 0 -#ifdef BERKELEY_MP - || e < 0 -#endif - ) - { - r->_mp_size = 0; - return; - } - - bp = b->_mp_d; - - blimb = bp[bsize - 1]; - if (bsize == 1 && blimb < 0x100) - { - /* Estimate space requirements accurately. Using the code from the - `else' path would over-estimate space requirements wildly. */ - float lb = __mp_bases[blimb].chars_per_bit_exactly; - ralloc = 3 + ((mp_size_t) (e / lb) / BITS_PER_MP_LIMB); - } - else - { - /* Over-estimate space requirements somewhat. */ - count_leading_zeros (cnt, blimb); - ralloc = bsize * e - cnt * e / BITS_PER_MP_LIMB + 2; - } - - TMP_MARK (marker); - - /* The two areas are used to alternatingly hold the input and recieve the - product for mpn_mul. (This scheme is used to fulfill the requirements - of mpn_mul; that the product space may not be the same as any of the - input operands.) */ - rp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - tp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - - MPN_COPY (rp, bp, bsize); - rsize = bsize; - count_leading_zeros (cnt, e); - - for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--) - { - mpn_mul_n (tp, rp, rp, rsize); - rsize = 2 * rsize; - rsize -= tp[rsize - 1] == 0; - xp = tp; tp = rp; rp = xp; - - if ((e & ((mp_limb_t) 1 << i)) != 0) - { - rsize = rsize + bsize - (mpn_mul (tp, rp, rsize, bp, bsize) == 0); - xp = tp; tp = rp; rp = xp; - } - } - - /* Now then we know the exact space requirements, reallocate if - necessary. */ - if (r->_mp_alloc < rsize) - _mpz_realloc (r, rsize); - - MPN_COPY (r->_mp_d, rp, rsize); - r->_mp_size = (e & 1) == 0 || b->_mp_size >= 0 ? rsize : -rsize; - TMP_FREE (marker); -} diff --git a/gmp/mpz/powm.c b/gmp/mpz/powm.c deleted file mode 100755 index e6af855..0000000 --- a/gmp/mpz/powm.c +++ /dev/null @@ -1,364 +0,0 @@ -/* mpz_powm(res,base,exp,mod) -- Set RES to (base**exp) mod MOD. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc. -Contributed by Paul Zimmermann. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - - -/* set c <- (a*b)/R^n mod m c has to have at least (2n) allocated limbs */ -static void -#if __STDC__ -mpz_redc (mpz_ptr c, mpz_srcptr a, mpz_srcptr b, mpz_srcptr m, mp_limb_t Nprim) -#else -mpz_redc (c, a, b, m, Nprim) - mpz_ptr c; - mpz_srcptr a; - mpz_srcptr b; - mpz_srcptr m; - mp_limb_t Nprim; -#endif -{ - mp_ptr cp, mp = PTR (m); - mp_limb_t cy, cout = 0; - mp_limb_t q; - size_t j, n = ABSIZ (m); - - ASSERT (ALLOC (c) >= 2 * n); - - mpz_mul (c, a, b); - cp = PTR (c); - j = ABSIZ (c); - MPN_ZERO (cp + j, 2 * n - j); - for (j = 0; j < n; j++) - { - q = cp[0] * Nprim; - cy = mpn_addmul_1 (cp, mp, n, q); - cout += mpn_add_1 (cp + n, cp + n, n - j, cy); - cp++; - } - cp -= n; - if (cout) - { - cy = cout - mpn_sub_n (cp, cp + n, mp, n); - while (cy) - cy -= mpn_sub_n (cp, cp, mp, n); - } - else - MPN_COPY (cp, cp + n, n); - MPN_NORMALIZE (cp, n); - SIZ (c) = SIZ (c) < 0 ? -n : n; -} - -/* average number of calls to redc for an exponent of n bits - with the sliding window algorithm of base 2^k: the optimal is - obtained for the value of k which minimizes 2^(k-1)+n/(k+1): - - n\k 4 5 6 7 8 - 128 156* 159 171 200 261 - 256 309 307* 316 343 403 - 512 617 607* 610 632 688 - 1024 1231 1204 1195* 1207 1256 - 2048 2461 2399 2366 2360* 2396 - 4096 4918 4787 4707 4665* 4670 -*/ - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_powm (mpz_ptr res, mpz_srcptr base, mpz_srcptr e, mpz_srcptr mod) -#else -mpz_powm (res, base, e, mod) - mpz_ptr res; - mpz_srcptr base; - mpz_srcptr e; - mpz_srcptr mod; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -pow (mpz_srcptr base, mpz_srcptr e, mpz_srcptr mod, mpz_ptr res) -#else -pow (base, e, mod, res) - mpz_srcptr base; - mpz_srcptr e; - mpz_srcptr mod; - mpz_ptr res; -#endif -#endif /* BERKELEY_MP */ -{ - mp_limb_t invm, *ep, c, mask; - mpz_t xx, *g; - mp_size_t n, i, K, j, l, k; - int sh; - int use_redc; - -#ifdef POWM_DEBUG - mpz_t exp; - mpz_init (exp); -#endif - - n = ABSIZ (mod); - - if (n == 0) - DIVIDE_BY_ZERO; - - if (SIZ (e) == 0) - { - /* Exponent is zero, result is 1 mod MOD, i.e., 1 or 0 - depending on if MOD equals 1. */ - SIZ(res) = (ABSIZ (mod) == 1 && (PTR(mod))[0] == 1) ? 0 : 1; - PTR(res)[0] = 1; - return; - } - - /* Use REDC instead of usual reduction for sizes < POWM_THRESHOLD. - In REDC each modular multiplication costs about 2*n^2 limbs operations, - whereas using usual reduction it costs 3*K(n), where K(n) is the cost of a - multiplication using Karatsuba, and a division is assumed to cost 2*K(n), - for example using Burnikel-Ziegler's algorithm. This gives a theoretical - threshold of a*KARATSUBA_SQR_THRESHOLD, with a=(3/2)^(1/(2-ln(3)/ln(2))) ~ - 2.66. */ - /* For now, also disable REDC when MOD is even, as the inverse can't - handle that. */ - -#ifndef POWM_THRESHOLD -#define POWM_THRESHOLD ((8 * KARATSUBA_SQR_THRESHOLD) / 3) -#endif - - use_redc = (n < POWM_THRESHOLD && PTR(mod)[0] % 2 != 0); - if (use_redc) - { - /* invm = -1/m mod 2^BITS_PER_MP_LIMB, must have m odd */ - modlimb_invert (invm, PTR(mod)[0]); - invm = -invm; - } - - /* determines optimal value of k */ - l = ABSIZ (e) * BITS_PER_MP_LIMB; /* number of bits of exponent */ - k = 1; - K = 2; - while (2 * l > K * (2 + k * (3 + k))) - { - k++; - K *= 2; - } - - g = (mpz_t *) (*_mp_allocate_func) (K / 2 * sizeof (mpz_t)); - /* compute x*R^n where R=2^BITS_PER_MP_LIMB */ - mpz_init (g[0]); - if (use_redc) - { - mpz_mul_2exp (g[0], base, n * BITS_PER_MP_LIMB); - mpz_mod (g[0], g[0], mod); - } - else - mpz_mod (g[0], base, mod); - - /* compute xx^g for odd g < 2^k */ - mpz_init (xx); - if (use_redc) - { - _mpz_realloc (xx, 2 * n); - mpz_redc (xx, g[0], g[0], mod, invm); /* xx = x^2*R^n */ - } - else - { - mpz_mul (xx, g[0], g[0]); - mpz_mod (xx, xx, mod); - } - for (i = 1; i < K / 2; i++) - { - mpz_init (g[i]); - if (use_redc) - { - _mpz_realloc (g[i], 2 * n); - mpz_redc (g[i], g[i - 1], xx, mod, invm); /* g[i] = x^(2i+1)*R^n */ - } - else - { - mpz_mul (g[i], g[i - 1], xx); - mpz_mod (g[i], g[i], mod); - } - } - - /* now starts the real stuff */ - mask = (mp_limb_t) ((1< 0) - { - i--; - c = (c << (-sh)) | (ep[i] >> (BITS_PER_MP_LIMB + sh)); - sh += BITS_PER_MP_LIMB; - } - } - else - c = c >> sh; -#ifdef POWM_DEBUG - printf ("-1/m mod 2^%u = %lu\n", BITS_PER_MP_LIMB, invm); - mpz_set_ui (exp, c); -#endif - j=0; - while (c % 2 == 0) - { - j++; - c = (c >> 1); - } - mpz_set (xx, g[c >> 1]); - while (j--) - { - if (use_redc) - mpz_redc (xx, xx, xx, mod, invm); - else - { - mpz_mul (xx, xx, xx); - mpz_mod (xx, xx, mod); - } - } - -#ifdef POWM_DEBUG - printf ("x^"); mpz_out_str (0, 10, exp); - printf ("*2^%u mod m = ", n * BITS_PER_MP_LIMB); mpz_out_str (0, 10, xx); - putchar ('\n'); -#endif - - while (i > 0 || sh > 0) - { - c = ep[i]; - sh -= k; - l = k; /* number of bits treated */ - if (sh < 0) - { - if (i > 0) - { - i--; - c = (c << (-sh)) | (ep[i] >> (BITS_PER_MP_LIMB + sh)); - sh += BITS_PER_MP_LIMB; - } - else - { - l += sh; /* may be less bits than k here */ - c = c & ((1<> sh; - c = c & mask; - - /* this while loop implements the sliding window improvement */ - while ((c & (1 << (k - 1))) == 0 && (i > 0 || sh > 0)) - { - if (use_redc) mpz_redc (xx, xx, xx, mod, invm); - else - { - mpz_mul (xx, xx, xx); - mpz_mod (xx, xx, mod); - } - if (sh) - { - sh--; - c = (c<<1) + ((ep[i]>>sh) & 1); - } - else - { - i--; - sh = BITS_PER_MP_LIMB - 1; - c = (c<<1) + (ep[i]>>sh); - } - } - -#ifdef POWM_DEBUG - printf ("l=%u c=%lu\n", l, c); - mpz_mul_2exp (exp, exp, k); - mpz_add_ui (exp, exp, c); -#endif - - /* now replace xx by xx^(2^k)*x^c */ - if (c != 0) - { - j = 0; - while (c % 2 == 0) - { - j++; - c = c >> 1; - } - /* c0 = c * 2^j, i.e. xx^(2^k)*x^c = (A^(2^(k - j))*c)^(2^j) */ - l -= j; - while (l--) - if (use_redc) mpz_redc (xx, xx, xx, mod, invm); - else - { - mpz_mul (xx, xx, xx); - mpz_mod (xx, xx, mod); - } - if (use_redc) - mpz_redc (xx, xx, g[c >> 1], mod, invm); - else - { - mpz_mul (xx, xx, g[c >> 1]); - mpz_mod (xx, xx, mod); - } - } - else - j = l; /* case c=0 */ - while (j--) - { - if (use_redc) - mpz_redc (xx, xx, xx, mod, invm); - else - { - mpz_mul (xx, xx, xx); - mpz_mod (xx, xx, mod); - } - } -#ifdef POWM_DEBUG - printf ("x^"); mpz_out_str (0, 10, exp); - printf ("*2^%u mod m = ", n * BITS_PER_MP_LIMB); mpz_out_str (0, 10, xx); - putchar ('\n'); -#endif - } - - /* now convert back xx to xx/R^n */ - if (use_redc) - { - mpz_set_ui (g[0], 1); - mpz_redc (xx, xx, g[0], mod, invm); - if (mpz_cmp (xx, mod) >= 0) - mpz_sub (xx, xx, mod); - } - mpz_set (res, xx); - - mpz_clear (xx); - for (i = 0; i < K / 2; i++) - mpz_clear (g[i]); - (*_mp_free_func) (g, K / 2 * sizeof (mpz_t)); -} diff --git a/gmp/mpz/powm_ui.c b/gmp/mpz/powm_ui.c deleted file mode 100755 index 00f70bd..0000000 --- a/gmp/mpz/powm_ui.c +++ /dev/null @@ -1,248 +0,0 @@ -/* mpz_powm_ui(res,base,exp,mod) -- Set RES to (base**exp) mod MOD. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpz_powm_ui (mpz_ptr res, mpz_srcptr base, unsigned long int exp, mpz_srcptr mod) -#else -mpz_powm_ui (res, base, exp, mod) - mpz_ptr res; - mpz_srcptr base; - unsigned long int exp; - mpz_srcptr mod; -#endif -{ - mp_ptr rp, mp, bp; - mp_size_t msize, bsize, rsize; - mp_size_t size; - int mod_shift_cnt; - int negative_result; - mp_limb_t *free_me = NULL; - size_t free_me_size; - TMP_DECL (marker); - - msize = ABS (mod->_mp_size); - size = 2 * msize; - - rp = res->_mp_d; - - if (msize == 0) - DIVIDE_BY_ZERO; - - if (exp == 0) - { - /* Exponent is zero, result is 1 mod MOD, i.e., 1 or 0 - depending on if MOD equals 1. */ - res->_mp_size = (msize == 1 && (mod->_mp_d)[0] == 1) ? 0 : 1; - rp[0] = 1; - return; - } - - TMP_MARK (marker); - - /* Normalize MOD (i.e. make its most significant bit set) as required by - mpn_divmod. This will make the intermediate values in the calculation - slightly larger, but the correct result is obtained after a final - reduction using the original MOD value. */ - - mp = (mp_ptr) TMP_ALLOC (msize * BYTES_PER_MP_LIMB); - count_leading_zeros (mod_shift_cnt, mod->_mp_d[msize - 1]); - if (mod_shift_cnt != 0) - mpn_lshift (mp, mod->_mp_d, msize, mod_shift_cnt); - else - MPN_COPY (mp, mod->_mp_d, msize); - - bsize = ABS (base->_mp_size); - if (bsize > msize) - { - /* The base is larger than the module. Reduce it. */ - - /* Allocate (BSIZE + 1) with space for remainder and quotient. - (The quotient is (bsize - msize + 1) limbs.) */ - bp = (mp_ptr) TMP_ALLOC ((bsize + 1) * BYTES_PER_MP_LIMB); - MPN_COPY (bp, base->_mp_d, bsize); - /* We don't care about the quotient, store it above the remainder, - at BP + MSIZE. */ - mpn_divmod (bp + msize, bp, bsize, mp, msize); - bsize = msize; - /* Canonicalize the base, since we are going to multiply with it - quite a few times. */ - MPN_NORMALIZE (bp, bsize); - } - else - bp = base->_mp_d; - - if (bsize == 0) - { - res->_mp_size = 0; - TMP_FREE (marker); - return; - } - - if (res->_mp_alloc < size) - { - /* We have to allocate more space for RES. If any of the input - parameters are identical to RES, defer deallocation of the old - space. */ - - if (rp == mp || rp == bp) - { - free_me = rp; - free_me_size = res->_mp_alloc; - } - else - (*_mp_free_func) (rp, res->_mp_alloc * BYTES_PER_MP_LIMB); - - rp = (mp_ptr) (*_mp_allocate_func) (size * BYTES_PER_MP_LIMB); - res->_mp_alloc = size; - res->_mp_d = rp; - } - else - { - /* Make BASE, EXP and MOD not overlap with RES. */ - if (rp == bp) - { - /* RES and BASE are identical. Allocate temp. space for BASE. */ - bp = (mp_ptr) TMP_ALLOC (bsize * BYTES_PER_MP_LIMB); - MPN_COPY (bp, rp, bsize); - } - if (rp == mp) - { - /* RES and MOD are identical. Allocate temporary space for MOD. */ - mp = (mp_ptr) TMP_ALLOC (msize * BYTES_PER_MP_LIMB); - MPN_COPY (mp, rp, msize); - } - } - - MPN_COPY (rp, bp, bsize); - rsize = bsize; - - { - mp_ptr xp = (mp_ptr) TMP_ALLOC (2 * (msize + 1) * BYTES_PER_MP_LIMB); - int c; - mp_limb_t e; - mp_limb_t carry_limb; - - negative_result = (exp & 1) && base->_mp_size < 0; - - e = exp; - count_leading_zeros (c, e); - e = (e << c) << 1; /* shift the exp bits to the left, lose msb */ - c = BITS_PER_MP_LIMB - 1 - c; - - /* Main loop. - - Make the result be pointed to alternately by XP and RP. This - helps us avoid block copying, which would otherwise be necessary - with the overlap restrictions of mpn_divmod. With 50% probability - the result after this loop will be in the area originally pointed - by RP (==RES->_mp_d), and with 50% probability in the area originally - pointed to by XP. */ - - while (c != 0) - { - mp_ptr tp; - mp_size_t xsize; - - mpn_mul_n (xp, rp, rp, rsize); - xsize = 2 * rsize; - xsize -= xp[xsize - 1] == 0; - if (xsize > msize) - { - mpn_divmod (xp + msize, xp, xsize, mp, msize); - xsize = msize; - } - - tp = rp; rp = xp; xp = tp; - rsize = xsize; - - if ((mp_limb_signed_t) e < 0) - { - mpn_mul (xp, rp, rsize, bp, bsize); - xsize = rsize + bsize; - xsize -= xp[xsize - 1] == 0; - if (xsize > msize) - { - mpn_divmod (xp + msize, xp, xsize, mp, msize); - xsize = msize; - } - - tp = rp; rp = xp; xp = tp; - rsize = xsize; - } - e <<= 1; - c--; - } - - /* We shifted MOD, the modulo reduction argument, left MOD_SHIFT_CNT - steps. Adjust the result by reducing it with the original MOD. - - Also make sure the result is put in RES->_mp_d (where it already - might be, see above). */ - - if (mod_shift_cnt != 0) - { - carry_limb = mpn_lshift (res->_mp_d, rp, rsize, mod_shift_cnt); - rp = res->_mp_d; - if (carry_limb != 0) - { - rp[rsize] = carry_limb; - rsize++; - } - } - else - { - MPN_COPY (res->_mp_d, rp, rsize); - rp = res->_mp_d; - } - - if (rsize >= msize) - { - mpn_divmod (rp + msize, rp, rsize, mp, msize); - rsize = msize; - } - - /* Remove any leading zero words from the result. */ - if (mod_shift_cnt != 0) - mpn_rshift (rp, rp, rsize, mod_shift_cnt); - MPN_NORMALIZE (rp, rsize); - } - - if (negative_result && rsize != 0) - { - if (mod_shift_cnt != 0) - mpn_rshift (mp, mp, msize, mod_shift_cnt); - mpn_sub (rp, mp, msize, rp, rsize); - rsize = msize; - MPN_NORMALIZE (rp, rsize); - } - res->_mp_size = rsize; - - if (free_me != NULL) - (*_mp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB); - TMP_FREE (marker); -} diff --git a/gmp/mpz/pprime_p.c b/gmp/mpz/pprime_p.c deleted file mode 100755 index 0217d8f..0000000 --- a/gmp/mpz/pprime_p.c +++ /dev/null @@ -1,242 +0,0 @@ -/* mpz_probab_prime_p -- - An implementation of the probabilistic primality test found in Knuth's - Seminumerical Algorithms book. If the function mpz_probab_prime_p() - returns 0 then n is not prime. If it returns 1, then n is 'probably' - prime. If it returns 2, n is surely prime. The probability of a false - positive is (1/4)**reps, where reps is the number of internal passes of the - probabilistic algorithm. Knuth indicates that 25 passes are reasonable. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 1998, 1999, 2000 Free Software -Foundation, Inc. Miller-Rabin code contributed by John Amanatides. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -static int isprime _PROTO ((unsigned long int t)); -static int mpz_millerrabin _PROTO ((mpz_srcptr n, int reps)); - -int -#if __STDC__ -mpz_probab_prime_p (mpz_srcptr n, int reps) -#else -mpz_probab_prime_p (n, reps) - mpz_srcptr n; - int reps; -#endif -{ - mp_limb_t r; - - /* Handle small and negative n. */ - if (mpz_cmp_ui (n, 1000000L) <= 0) - { - int is_prime; - if (mpz_sgn (n) < 0) - { - /* Negative number. Negate and call ourselves. */ - mpz_t n2; - mpz_init (n2); - mpz_neg (n2, n); - is_prime = mpz_probab_prime_p (n2, reps); - mpz_clear (n2); - return is_prime; - } - is_prime = isprime (mpz_get_ui (n)); - return is_prime ? 2 : 0; - } - - /* If n is now even, it is not a prime. */ - if ((mpz_get_ui (n) & 1) == 0) - return 0; - - /* Check if n has small factors. */ - if (UDIV_TIME > (2 * UMUL_TIME + 6)) - r = mpn_preinv_mod_1 (PTR(n), SIZ(n), (mp_limb_t) PP, (mp_limb_t) PP_INVERTED); - else - r = mpn_mod_1 (PTR(n), SIZ(n), (mp_limb_t) PP); - if (r % 3 == 0 || r % 5 == 0 || r % 7 == 0 || r % 11 == 0 || r % 13 == 0 - || r % 17 == 0 || r % 19 == 0 || r % 23 == 0 || r % 29 == 0 -#if BITS_PER_MP_LIMB == 64 - || r % 31 == 0 || r % 37 == 0 || r % 41 == 0 || r % 43 == 0 - || r % 47 == 0 || r % 53 == 0 -#endif - ) - { - return 0; - } - - /* Do more dividing. We collect small primes, using umul_ppmm, until we - overflow a single limb. We divide our number by the small primes product, - and look for factors in the remainder. */ - { - unsigned long int ln2; - unsigned long int q; - mp_limb_t p1, p0, p; - unsigned int primes[15]; - int nprimes; - - nprimes = 0; - p = 1; - ln2 = mpz_sizeinbase (n, 2) / 30; ln2 = ln2 * ln2; - for (q = BITS_PER_MP_LIMB == 64 ? 59 : 31; q < ln2; q += 2) - { - if (isprime (q)) - { - umul_ppmm (p1, p0, p, q); - if (p1 != 0) - { - r = mpn_mod_1 (PTR(n), SIZ(n), p); - while (--nprimes >= 0) - if (r % primes[nprimes] == 0) - { - if (mpn_mod_1 (PTR(n), SIZ(n), (mp_limb_t) primes[nprimes]) != 0) - abort (); - return 0; - } - p = q; - nprimes = 0; - } - else - { - p = p0; - } - primes[nprimes++] = q; - } - } - } - - /* Perform a number of Miller-Rabin tests. */ - return mpz_millerrabin (n, reps); -} - -static int -#if __STDC__ -isprime (unsigned long int t) -#else -isprime (t) - unsigned long int t; -#endif -{ - unsigned long int q, r, d; - - if (t < 3 || (t & 1) == 0) - return t == 2; - - for (d = 3, r = 1; r != 0; d += 2) - { - q = t / d; - r = t - q * d; - if (q < d) - return 1; - } - return 0; -} - -static int millerrabin _PROTO ((mpz_srcptr n, mpz_srcptr nm1, - mpz_ptr x, mpz_ptr y, - mpz_srcptr q, unsigned long int k)); - -static int -#if __STDC__ -mpz_millerrabin (mpz_srcptr n, int reps) -#else -mpz_millerrabin (n, reps) - mpz_srcptr n; - int reps; -#endif -{ - int r; - mpz_t nm1, x, y, q; - unsigned long int k; - gmp_randstate_t rstate; - int is_prime; - TMP_DECL (marker); - TMP_MARK (marker); - - MPZ_TMP_INIT (nm1, SIZ (n) + 1); - mpz_sub_ui (nm1, n, 1L); - - MPZ_TMP_INIT (x, SIZ (n)); - MPZ_TMP_INIT (y, 2 * SIZ (n)); /* mpz_powm_ui needs excessive memory!!! */ - - /* Perform a Fermat test. */ - mpz_set_ui (x, 210L); - mpz_powm (y, x, nm1, n); - if (mpz_cmp_ui (y, 1L) != 0) - { - return 0; - TMP_FREE (marker); - } - - MPZ_TMP_INIT (q, SIZ (n)); - - /* Find q and k, where q is odd and n = 1 + 2**k * q. */ - k = mpz_scan1 (nm1, 0L); - mpz_tdiv_q_2exp (q, nm1, k); - - gmp_randinit (rstate, GMP_RAND_ALG_DEFAULT, 32L); - - is_prime = 1; - for (r = 0; r < reps && is_prime; r++) - { - do - mpz_urandomb (x, rstate, mpz_sizeinbase (n, 2) - 1); - while (mpz_cmp_ui (x, 1L) <= 0); - - is_prime = millerrabin (n, nm1, x, y, q, k); - } - - gmp_randclear (rstate); - - TMP_FREE (marker); - return is_prime; -} - -static int -#if __STDC__ -millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y, - mpz_srcptr q, unsigned long int k) -#else -millerrabin (n, nm1, x, y, q, k) - mpz_srcptr n; - mpz_srcptr nm1; - mpz_ptr x; - mpz_ptr y; - mpz_srcptr q; - unsigned long int k; -#endif -{ - unsigned long int i; - - mpz_powm (y, x, q, n); - - if (mpz_cmp_ui (y, 1L) == 0 || mpz_cmp (y, nm1) == 0) - return 1; - - for (i = 1; i < k; i++) - { - mpz_powm_ui (y, y, 2L, n); - if (mpz_cmp (y, nm1) == 0) - return 1; - if (mpz_cmp_ui (y, 1L) == 0) - return 0; - } - return 0; -} diff --git a/gmp/mpz/random.c b/gmp/mpz/random.c deleted file mode 100755 index 60d9113..0000000 --- a/gmp/mpz/random.c +++ /dev/null @@ -1,56 +0,0 @@ -/* mpz_random -- Generate a random mpz_t of specified size. - This function is non-portable and generates poor random numbers. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void -#if __STDC__ -mpz_random (mpz_ptr x, mp_size_t size) -#else -mpz_random (x, size) - mpz_ptr x; - mp_size_t size; -#endif -{ - mp_size_t i; - mp_limb_t ran; - mp_ptr xp; - mp_size_t abs_size; - - abs_size = ABS (size); - - if (x->_mp_alloc < abs_size) - _mpz_realloc (x, abs_size); - - xp = x->_mp_d; - - for (i = 0; i < abs_size; i++) - { - ran = urandom (); - xp[i] = ran; - } - - MPN_NORMALIZE (xp, abs_size); - x->_mp_size = size < 0 ? -abs_size : abs_size; -} diff --git a/gmp/mpz/random2.c b/gmp/mpz/random2.c deleted file mode 100755 index a90af11..0000000 --- a/gmp/mpz/random2.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mpz_random2 -- Generate a positive random mpz_t of specified size, with - long runs of consecutive ones and zeros in the binary representation. - Meant for testing of other MP routines. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_random2 (mpz_ptr x, mp_size_t size) -#else -mpz_random2 (x, size) - mpz_ptr x; - mp_size_t size; -#endif -{ - mp_size_t abs_size; - - abs_size = ABS (size); - if (abs_size != 0) - { - if (x->_mp_alloc < abs_size) - _mpz_realloc (x, abs_size); - - mpn_random2 (x->_mp_d, abs_size); - } - - x->_mp_size = size; -} diff --git a/gmp/mpz/realloc.c b/gmp/mpz/realloc.c deleted file mode 100755 index 0b9e447..0000000 --- a/gmp/mpz/realloc.c +++ /dev/null @@ -1,52 +0,0 @@ -/* _mpz_realloc -- make the mpz_t have NEW_SIZE digits allocated. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void * -#if __STDC__ -_mpz_realloc (mpz_ptr m, mp_size_t new_size) -#else -_mpz_realloc (m, new_size) - mpz_ptr m; - mp_size_t new_size; -#endif -{ - /* Never allocate zero space. */ - if (new_size == 0) - new_size = 1; - - m->_mp_d = (mp_ptr) (*_mp_reallocate_func) (m->_mp_d, - m->_mp_alloc * BYTES_PER_MP_LIMB, - new_size * BYTES_PER_MP_LIMB); - m->_mp_alloc = new_size; - -#if 0 - /* This might break some code that reads the size field after - reallocation, in the case the reallocated destination and a - source argument are identical. */ - if (ABS (m->_mp_size) > new_size) - m->_mp_size = 0; -#endif - - return (void *) m->_mp_d; -} diff --git a/gmp/mpz/remove.c b/gmp/mpz/remove.c deleted file mode 100755 index bc6675f..0000000 --- a/gmp/mpz/remove.c +++ /dev/null @@ -1,93 +0,0 @@ -/* mpz_remove -- divide out a factor and return its multiplicity. - -Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_remove (mpz_ptr dest, mpz_srcptr src, mpz_srcptr f) -#else -mpz_remove (dest, src, f) - mpz_ptr dest; - mpz_srcptr src; - mpz_srcptr f; -#endif -{ - mpz_t fpow[40]; /* inexhaustible...until year 2020 or so */ - mpz_t x, rem; - unsigned long int pwr; - int p; - - if (mpz_cmp_ui (f, 1) <= 0 || mpz_sgn (src) == 0) - DIVIDE_BY_ZERO; - if (mpz_cmp_ui (f, 2) == 0) - { - unsigned long int s0; - s0 = mpz_scan1 (src, 0); - mpz_div_2exp (dest, src, s0); - return s0; - } - - /* We could perhaps compute mpz_scan1(src,0)/mpz_scan1(f,0). It is an - upper bound of the result we're seeking. We could also shift down the - operands so that they become odd, to make intermediate values smaller. */ - - mpz_init (rem); - mpz_init (x); - - pwr = 0; - mpz_init (fpow[0]); - mpz_set (fpow[0], f); - mpz_set (dest, src); - - /* Divide by f, f^2, ..., f^(2^k) until we get a remainder for f^(2^k). */ - for (p = 0;; p++) - { - mpz_tdiv_qr (x, rem, dest, fpow[p]); - if (SIZ (rem) != 0) - break; - mpz_init (fpow[p + 1]); - mpz_mul (fpow[p + 1], fpow[p], fpow[p]); - mpz_set (dest, x); - } - - pwr = (1 << p) - 1; - - mpz_clear (fpow[p]); - - /* Divide by f^(2^(k-1)), f^(2^(k-2)), ..., f for all divisors that give a - zero remainder. */ - while (--p >= 0) - { - mpz_tdiv_qr (x, rem, dest, fpow[p]); - if (SIZ (rem) == 0) - { - pwr += 1 << p; - mpz_set (dest, x); - } - mpz_clear (fpow[p]); - } - - mpz_clear (x); - mpz_clear (rem); - return pwr; -} diff --git a/gmp/mpz/root.c b/gmp/mpz/root.c deleted file mode 100755 index 0920bf2..0000000 --- a/gmp/mpz/root.c +++ /dev/null @@ -1,183 +0,0 @@ -/* mpz_root(root, u, nth) -- Set ROOT to floor(U^(1/nth)). - Return an indication if the result is exact. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -/* Naive implementation of nth root extraction. It would probably be a - better idea to use a division-free Newton iteration. It is insane - to use full precision from iteration 1. The mpz_scan1 trick compensates - to some extent. It would be natural to avoid representing the low zero - bits mpz_scan1 is counting, and at the same time call mpn directly. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -int -#if __STDC__ -mpz_root (mpz_ptr r, mpz_srcptr c, unsigned long int nth) -#else -mpz_root (r, c, nth) - mpz_ptr r; - mpz_srcptr c; - unsigned long int nth; -#endif -{ - mpz_t x, t0, t1, t2; - __mpz_struct ccs, *cc = &ccs; - unsigned long int nbits; - int bit; - int exact; - int i; - unsigned long int lowz; - unsigned long int rl; - - /* even roots of negatives provoke an exception */ - if (mpz_sgn (c) < 0 && (nth & 1) == 0) - SQRT_OF_NEGATIVE; - - /* root extraction interpreted as c^(1/nth) means a zeroth root should - provoke a divide by zero, do this even if c==0 */ - if (nth == 0) - DIVIDE_BY_ZERO; - - if (mpz_sgn (c) == 0) - { - if (r != NULL) - mpz_set_ui (r, 0); - return 1; /* exact result */ - } - - PTR(cc) = PTR(c); - SIZ(cc) = ABSIZ(c); - - nbits = (mpz_sizeinbase (cc, 2) - 1) / nth; - if (nbits == 0) - { - if (r != NULL) - mpz_set_ui (r, 1); - if (mpz_sgn (c) < 0) - { - if (r != NULL) - SIZ(r) = -SIZ(r); - return mpz_cmp_si (c, -1L) == 0; - } - return mpz_cmp_ui (c, 1L) == 0; - } - - mpz_init (x); - mpz_init (t0); - mpz_init (t1); - mpz_init (t2); - - /* Create a one-bit approximation. */ - mpz_set_ui (x, 0); - mpz_setbit (x, nbits); - - /* Make the approximation better, one bit at a time. This odd-looking - termination criteria makes large nth get better initial approximation, - which avoids slow convergence for such values. */ - bit = nbits - 1; - for (i = 1; (nth >> i) != 0; i++) - { - mpz_setbit (x, bit); - mpz_tdiv_q_2exp (t0, x, bit); - mpz_pow_ui (t1, t0, nth); - mpz_mul_2exp (t1, t1, bit * nth); - if (mpz_cmp (cc, t1) < 0) - mpz_clrbit (x, bit); - - bit--; /* check/set next bit */ - if (bit < 0) - { - /* We're done. */ - mpz_pow_ui (t1, x, nth); - goto done; - } - } - mpz_setbit (x, bit); - mpz_set_ui (t2, 0); mpz_setbit (t2, bit); mpz_add (x, x, t2); - -#if DEBUG - /* Check that the starting approximation is >= than the root. */ - mpz_pow_ui (t1, x, nth); - if (mpz_cmp (cc, t1) >= 0) - abort (); -#endif - - mpz_add_ui (x, x, 1); - - /* Main loop */ - do - { - lowz = mpz_scan1 (x, 0); - mpz_tdiv_q_2exp (t0, x, lowz); - mpz_pow_ui (t1, t0, nth - 1); - mpz_mul_2exp (t1, t1, lowz * (nth - 1)); - mpz_tdiv_q (t2, cc, t1); - mpz_sub (t2, x, t2); - rl = mpz_tdiv_q_ui (t2, t2, nth); - mpz_sub (x, x, t2); - } - while (mpz_sgn (t2) != 0); - - /* If we got a non-zero remainder in the last division, we know our root - is too large. */ - mpz_sub_ui (x, x, (mp_limb_t) (rl != 0)); - - /* Adjustment loop. If we spend more care on rounding in the loop above, - we could probably get rid of this, or greatly simplify it. */ - { - int bad = 0; - lowz = mpz_scan1 (x, 0); - mpz_tdiv_q_2exp (t0, x, lowz); - mpz_pow_ui (t1, t0, nth); - mpz_mul_2exp (t1, t1, lowz * nth); - while (mpz_cmp (cc, t1) < 0) - { - bad++; - if (bad > 2) - abort (); /* abort if our root is far off */ - mpz_sub_ui (x, x, 1); - lowz = mpz_scan1 (x, 0); - mpz_tdiv_q_2exp (t0, x, lowz); - mpz_pow_ui (t1, t0, nth); - mpz_mul_2exp (t1, t1, lowz * nth); - } - } - - done: - exact = mpz_cmp (t1, cc) == 0; - - if (r != NULL) - { - mpz_set (r, x); - if (mpz_sgn (c) < 0) - SIZ(r) = -SIZ(r); - } - - mpz_clear (t2); - mpz_clear (t1); - mpz_clear (t0); - mpz_clear (x); - - return exact; -} diff --git a/gmp/mpz/rrandomb.c b/gmp/mpz/rrandomb.c deleted file mode 100755 index 7d78243..0000000 --- a/gmp/mpz/rrandomb.c +++ /dev/null @@ -1,117 +0,0 @@ -/* mpz_rrandomb -- Generate a positive random mpz_t of specified bit size, with - long runs of consecutive ones and zeros in the binary representation. - Meant for testing of other MP routines. - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -static void gmp_rrandomb _PROTO ((mp_ptr rp, gmp_randstate_t rstate, unsigned long int nbits)); - -void -#if __STDC__ -mpz_rrandomb (mpz_ptr x, gmp_randstate_t rstate, unsigned long int nbits) -#else -mpz_rrandomb (x, rstate, nbits) - mpz_ptr x; - gmp_randstate_t rstate; - unsigned long int nbits; -#endif -{ - mp_size_t nl = 0; - - if (nbits != 0) - { - mp_ptr xp; - nl = (nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - if (x->_mp_alloc < nl) - _mpz_realloc (x, nl); - - xp = PTR(x); - gmp_rrandomb (xp, rstate, nbits); - MPN_NORMALIZE (xp, nl); - } - - SIZ(x) = nl; -} - -#define BITS_PER_CHUNK 4 - -static void -#if __STDC__ -gmp_rrandomb (mp_ptr rp, gmp_randstate_t rstate, unsigned long int nbits) -#else -gmp_rrandomb (rp, rstate, nbits) - mp_ptr rp; - gmp_randstate_t rstate; - unsigned long int nbits; -#endif -{ - int nb; - int bit_pos; - mp_size_t limb_pos; - mp_limb_t ran, ranm; - mp_limb_t acc; - mp_size_t n; - - bit_pos = nbits % BITS_PER_MP_LIMB; - limb_pos = nbits / BITS_PER_MP_LIMB; - if (bit_pos == 0) - { - bit_pos = BITS_PER_MP_LIMB; - limb_pos--; - } - - acc = 0; - while (limb_pos >= 0) - { - _gmp_rand (&ranm, rstate, BITS_PER_CHUNK + 1); - ran = ranm; - nb = (ran >> 1) + 1; - if ((ran & 1) != 0) - { - /* Generate a string of ones. */ - if (nb > bit_pos) - { - rp[limb_pos--] = acc | ((((mp_limb_t) 1) << bit_pos) - 1); - bit_pos += BITS_PER_MP_LIMB; - bit_pos -= nb; - acc = (~(mp_limb_t) 0) << bit_pos; - } - else - { - bit_pos -= nb; - acc |= ((((mp_limb_t) 1) << nb) - 1) << bit_pos; - } - } - else - { - /* Generate a string of zeroes. */ - if (nb > bit_pos) - { - rp[limb_pos--] = acc; - acc = 0; - bit_pos += BITS_PER_MP_LIMB; - } - bit_pos -= nb; - } - } -} diff --git a/gmp/mpz/scan0.c b/gmp/mpz/scan0.c deleted file mode 100755 index 6c59cf8..0000000 --- a/gmp/mpz/scan0.c +++ /dev/null @@ -1,35 +0,0 @@ -/* mpz_scan0(op, startbit) -- Scan for the next set bit, starting at startbit. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_scan0 (mpz_srcptr u, unsigned long int starting_bit) -#else -mpz_scan0 (u, starting_bit) - mpz_srcptr u; - unsigned long int starting_bit; -#endif -{ - return mpn_scan0 (u->_mp_d, starting_bit); -} diff --git a/gmp/mpz/scan1.c b/gmp/mpz/scan1.c deleted file mode 100755 index 3b84e34..0000000 --- a/gmp/mpz/scan1.c +++ /dev/null @@ -1,35 +0,0 @@ -/* mpz_scan1(op, startbit) -- Scan for the next set bit, starting at startbit. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_scan1 (mpz_srcptr u, unsigned long int starting_bit) -#else -mpz_scan1 (u, starting_bit) - mpz_srcptr u; - unsigned long int starting_bit; -#endif -{ - return mpn_scan1 (u->_mp_d, starting_bit); -} diff --git a/gmp/mpz/set.c b/gmp/mpz/set.c deleted file mode 100755 index 06b2eef..0000000 --- a/gmp/mpz/set.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mpz_set (dest_integer, src_integer) -- Assign DEST_INTEGER from SRC_INTEGER. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_set (mpz_ptr w, mpz_srcptr u) -#else -mpz_set (w, u) - mpz_ptr w; - mpz_srcptr u; -#endif -{ - mp_ptr wp, up; - mp_size_t usize, size; - - usize = u->_mp_size; - size = ABS (usize); - - if (w->_mp_alloc < size) - _mpz_realloc (w, size); - - wp = w->_mp_d; - up = u->_mp_d; - - MPN_COPY (wp, up, size); - w->_mp_size = usize; -} diff --git a/gmp/mpz/set_d.c b/gmp/mpz/set_d.c deleted file mode 100755 index e90ed9b..0000000 --- a/gmp/mpz/set_d.c +++ /dev/null @@ -1,96 +0,0 @@ -/* mpz_set_d(integer, val) -- Assign INTEGER with a double value VAL. - -Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_set_d (mpz_ptr r, double d) -#else -mpz_set_d (r, d) - mpz_ptr r; - double d; -#endif -{ - int negative; - mp_limb_t tp[3]; - mp_ptr rp; - mp_size_t rn; - - negative = d < 0; - d = ABS (d); - - /* Handle small arguments quickly. */ - if (d < MP_BASE_AS_DOUBLE) - { - mp_limb_t tmp; - tmp = d; - PTR(r)[0] = tmp; - SIZ(r) = negative ? -(tmp != 0) : (tmp != 0); - return; - } - - rn = __gmp_extract_double (tp, d); - - if (ALLOC(r) < rn) - _mpz_realloc (r, rn); - - rp = PTR (r); - -#if BITS_PER_MP_LIMB == 32 - switch (rn) - { - default: - MPN_ZERO (rp, rn - 3); - rp += rn - 3; - /* fall through */ - case 3: - rp[2] = tp[2]; - rp[1] = tp[1]; - rp[0] = tp[0]; - break; - case 2: - rp[1] = tp[2]; - rp[0] = tp[1]; - break; - case 1: - /* handled in "small aguments" case above */ - abort (); - } -#else - switch (rn) - { - default: - MPN_ZERO (rp, rn - 2); - rp += rn - 2; - /* fall through */ - case 2: - rp[1] = tp[1], rp[0] = tp[0]; - break; - case 1: - /* handled in "small aguments" case above */ - abort (); - } -#endif - - SIZ(r) = negative ? -rn : rn; -} diff --git a/gmp/mpz/set_f.c b/gmp/mpz/set_f.c deleted file mode 100755 index 2273953..0000000 --- a/gmp/mpz/set_f.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpz_set_f (dest_integer, src_float) -- Assign DEST_INTEGER from SRC_FLOAT. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_set_f (mpz_ptr w, mpf_srcptr u) -#else -mpz_set_f (w, u) - mpz_ptr w; - mpf_srcptr u; -#endif -{ - mp_ptr wp, up; - mp_size_t usize, size; - mp_exp_t exp; - - usize = SIZ (u); - size = ABS (usize); - exp = EXP (u); - - if (w->_mp_alloc < exp) - _mpz_realloc (w, exp); - - wp = w->_mp_d; - up = u->_mp_d; - - if (exp <= 0) - { - SIZ (w) = 0; - return; - } - if (exp < size) - { - MPN_COPY (wp, up + size - exp, exp); - } - else - { - MPN_ZERO (wp, exp - size); - MPN_COPY (wp + exp - size, up, size); - } - - w->_mp_size = usize >= 0 ? exp : -exp; -} diff --git a/gmp/mpz/set_q.c b/gmp/mpz/set_q.c deleted file mode 100755 index 72d3222..0000000 --- a/gmp/mpz/set_q.c +++ /dev/null @@ -1,36 +0,0 @@ -/* mpz_set_q (dest_integer, src_rational) -- Assign DEST_INTEGER from - SRC_rational. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_set_q (mpz_ptr w, mpq_srcptr u) -#else -mpz_set_q (w, u) - mpz_ptr w; - mpq_srcptr u; -#endif -{ - mpz_tdiv_q (w, mpq_numref (u), mpq_denref (u)); -} diff --git a/gmp/mpz/set_si.c b/gmp/mpz/set_si.c deleted file mode 100755 index 9ba2fba..0000000 --- a/gmp/mpz/set_si.c +++ /dev/null @@ -1,48 +0,0 @@ -/* mpz_set_si(integer, val) -- Assign INTEGER with a small value VAL. - -Copyright (C) 1991, 1993, 1994, 1995, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_set_si (mpz_ptr dest, signed long int val) -#else -mpz_set_si (dest, val) - mpz_ptr dest; - signed long int val; -#endif -{ - /* We don't check if the allocation is enough, since the rest of the - package ensures it's at least 1, which is what we need here. */ - if (val > 0) - { - dest->_mp_d[0] = val; - dest->_mp_size = 1; - } - else if (val < 0) - { - dest->_mp_d[0] = (unsigned long) -val; - dest->_mp_size = -1; - } - else - dest->_mp_size = 0; -} diff --git a/gmp/mpz/set_str.c b/gmp/mpz/set_str.c deleted file mode 100755 index 3ab79c0..0000000 --- a/gmp/mpz/set_str.c +++ /dev/null @@ -1,157 +0,0 @@ -/* mpz_set_str(mp_dest, string, base) -- Convert the \0-terminated - string STRING in base BASE to multiple precision integer in - MP_DEST. Allow white space in the string. If BASE == 0 determine - the base in the C standard way, i.e. 0xhh...h means base 16, - 0oo...o means base 8, otherwise assume base 10. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 1998, 2000 Free Software -Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -static int -#if __STDC__ -digit_value_in_base (int c, int base) -#else -digit_value_in_base (c, base) - int c; - int base; -#endif -{ - int digit; - - if (isdigit (c)) - digit = c - '0'; - else if (islower (c)) - digit = c - 'a' + 10; - else if (isupper (c)) - digit = c - 'A' + 10; - else - return -1; - - if (digit < base) - return digit; - return -1; -} - -int -#if __STDC__ -mpz_set_str (mpz_ptr x, const char *str, int base) -#else -mpz_set_str (x, str, base) - mpz_ptr x; - const char *str; - int base; -#endif -{ - size_t str_size; - char *s, *begs; - size_t i; - mp_size_t xsize; - int c; - int negative; - TMP_DECL (marker); - - /* Skip whitespace. */ - do - c = *str++; - while (isspace (c)); - - negative = 0; - if (c == '-') - { - negative = 1; - c = *str++; - } - - if (digit_value_in_base (c, base == 0 ? 10 : base) < 0) - return -1; /* error if no digits */ - - /* If BASE is 0, try to find out the base by looking at the initial - characters. */ - if (base == 0) - { - base = 10; - if (c == '0') - { - base = 8; - c = *str++; - if (c == 'x' || c == 'X') - { - base = 16; - c = *str++; - } - else if (c == 'b' || c == 'B') - { - base = 2; - c = *str++; - } - } - } - - /* Skip leading zeros. */ - while (c == '0') - c = *str++; - /* Make sure the string does not become empty, mpn_set_str would fail. */ - if (c == 0) - { - x->_mp_size = 0; - return 0; - } - - TMP_MARK (marker); - str_size = strlen (str - 1); - s = begs = (char *) TMP_ALLOC (str_size + 1); - - /* Remove spaces from the string and convert the result from ASCII to a - byte array. */ - for (i = 0; i < str_size; i++) - { - if (!isspace (c)) - { - int dig = digit_value_in_base (c, base); - if (dig < 0) - { - TMP_FREE (marker); - return -1; - } - *s++ = dig; - } - c = *str++; - } - - str_size = s - begs; - - xsize = (((mp_size_t) (str_size / __mp_bases[base].chars_per_bit_exactly)) - / BITS_PER_MP_LIMB + 2); - if (x->_mp_alloc < xsize) - _mpz_realloc (x, xsize); - - /* Convert the byte array in base BASE to our bignum format. */ - xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, base); - x->_mp_size = negative ? -xsize : xsize; - - TMP_FREE (marker); - return 0; -} diff --git a/gmp/mpz/set_ui.c b/gmp/mpz/set_ui.c deleted file mode 100755 index d6097c1..0000000 --- a/gmp/mpz/set_ui.c +++ /dev/null @@ -1,43 +0,0 @@ -/* mpz_set_ui(integer, val) -- Assign INTEGER with a small value VAL. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_set_ui (mpz_ptr dest, unsigned long int val) -#else -mpz_set_ui (dest, val) - mpz_ptr dest; - unsigned long int val; -#endif -{ - /* We don't check if the allocation is enough, since the rest of the - package ensures it's at least 1, which is what we need here. */ - if (val > 0) - { - dest->_mp_d[0] = val; - dest->_mp_size = 1; - } - else - dest->_mp_size = 0; -} diff --git a/gmp/mpz/setbit.c b/gmp/mpz/setbit.c deleted file mode 100755 index d4249a4..0000000 --- a/gmp/mpz/setbit.c +++ /dev/null @@ -1,119 +0,0 @@ -/* mpz_setbit -- set a specified bit. - -Copyright (C) 1991, 1993, 1994, 1995, 1997, 1999 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_setbit (mpz_ptr d, unsigned long int bit_index) -#else -mpz_setbit (d, bit_index) - mpz_ptr d; - unsigned long int bit_index; -#endif -{ - mp_size_t dsize = d->_mp_size; - mp_ptr dp = d->_mp_d; - mp_size_t limb_index; - - limb_index = bit_index / BITS_PER_MP_LIMB; - if (dsize >= 0) - { - if (limb_index < dsize) - { - dp[limb_index] |= (mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB); - d->_mp_size = dsize; - } - else - { - /* Ugh. The bit should be set outside of the end of the - number. We have to increase the size of the number. */ - if (d->_mp_alloc < limb_index + 1) - { - _mpz_realloc (d, limb_index + 1); - dp = d->_mp_d; - } - MPN_ZERO (dp + dsize, limb_index - dsize); - dp[limb_index] = (mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB); - d->_mp_size = limb_index + 1; - } - } - else - { - mp_size_t zero_bound; - - /* Simulate two's complement arithmetic, i.e. simulate - 1. Set OP = ~(OP - 1) [with infinitely many leading ones]. - 2. Set the bit. - 3. Set OP = ~OP + 1. */ - - dsize = -dsize; - - /* No upper bound on this loop, we're sure there's a non-zero limb - sooner ot later. */ - for (zero_bound = 0; ; zero_bound++) - if (dp[zero_bound] != 0) - break; - - if (limb_index > zero_bound) - { - if (limb_index < dsize) - dp[limb_index] &= ~((mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB)); - else - ; - } - else if (limb_index == zero_bound) - { - dp[limb_index] = ((dp[limb_index] - 1) - & ~((mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB))) + 1; - if (dp[limb_index] == 0) - { - mp_size_t i; - for (i = limb_index + 1; i < dsize; i++) - { - dp[i] += 1; - if (dp[i] != 0) - goto fin; - } - /* We got carry all way out beyond the end of D. Increase - its size (and allocation if necessary). */ - dsize++; - if (d->_mp_alloc < dsize) - { - _mpz_realloc (d, dsize); - dp = d->_mp_d; - } - dp[i] = 1; - d->_mp_size = -dsize; - fin:; - } - } - else - { - mpn_decr_u (dp + limb_index, - (mp_limb_t) 1 << (bit_index % BITS_PER_MP_LIMB)); - dsize -= dp[dsize - 1] == 0; - d->_mp_size = -dsize; - } - } -} diff --git a/gmp/mpz/size.c b/gmp/mpz/size.c deleted file mode 100755 index 6574756..0000000 --- a/gmp/mpz/size.c +++ /dev/null @@ -1,35 +0,0 @@ -/* mpz_size(x) -- return the number of lims currently used by the - value of integer X. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -size_t -#if __STDC__ -mpz_size (mpz_srcptr x) -#else -mpz_size (x) - mpz_srcptr x; -#endif -{ - return ABS (x->_mp_size); -} diff --git a/gmp/mpz/sizeinbase.c b/gmp/mpz/sizeinbase.c deleted file mode 100755 index 734f9c4..0000000 --- a/gmp/mpz/sizeinbase.c +++ /dev/null @@ -1,60 +0,0 @@ -/* mpz_sizeinbase(x, base) -- return an approximation to the number of - character the integer X would have printed in base BASE. The - approximation is never too small. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -size_t -#if __STDC__ -mpz_sizeinbase (mpz_srcptr x, int base) -#else -mpz_sizeinbase (x, base) - mpz_srcptr x; - int base; -#endif -{ - mp_size_t size = ABS (x->_mp_size); - int lb_base, cnt; - size_t totbits; - - /* Special case for X == 0. */ - if (size == 0) - return 1; - - /* Calculate the total number of significant bits of X. */ - count_leading_zeros (cnt, x->_mp_d[size - 1]); - totbits = size * BITS_PER_MP_LIMB - cnt; - - if ((base & (base - 1)) == 0) - { - /* Special case for powers of 2, giving exact result. */ - - count_leading_zeros (lb_base, base); - lb_base = BITS_PER_MP_LIMB - lb_base - 1; - - return (totbits + lb_base - 1) / lb_base; - } - else - return (size_t) (totbits * __mp_bases[base].chars_per_bit_exactly) + 1; -} diff --git a/gmp/mpz/sqrt.c b/gmp/mpz/sqrt.c deleted file mode 100755 index fe82fe4..0000000 --- a/gmp/mpz/sqrt.c +++ /dev/null @@ -1,86 +0,0 @@ -/* mpz_sqrt(root, u) -- Set ROOT to floor(sqrt(U)). - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_sqrt (mpz_ptr root, mpz_srcptr op) -#else -mpz_sqrt (root, op) - mpz_ptr root; - mpz_srcptr op; -#endif -{ - mp_size_t op_size, root_size; - mp_ptr root_ptr, op_ptr; - mp_ptr free_me = NULL; - mp_size_t free_me_size; - TMP_DECL (marker); - - TMP_MARK (marker); - op_size = op->_mp_size; - if (op_size < 0) - SQRT_OF_NEGATIVE; - - /* The size of the root is accurate after this simple calculation. */ - root_size = (op_size + 1) / 2; - - root_ptr = root->_mp_d; - op_ptr = op->_mp_d; - - if (root->_mp_alloc < root_size) - { - if (root_ptr == op_ptr) - { - free_me = root_ptr; - free_me_size = root->_mp_alloc; - } - else - (*_mp_free_func) (root_ptr, root->_mp_alloc * BYTES_PER_MP_LIMB); - - root->_mp_alloc = root_size; - root_ptr = (mp_ptr) (*_mp_allocate_func) (root_size * BYTES_PER_MP_LIMB); - root->_mp_d = root_ptr; - } - else - { - /* Make OP not overlap with ROOT. */ - if (root_ptr == op_ptr) - { - /* ROOT and OP are identical. Allocate temporary space for OP. */ - op_ptr = (mp_ptr) TMP_ALLOC (op_size * BYTES_PER_MP_LIMB); - /* Copy to the temporary space. Hack: Avoid temporary variable - by using ROOT_PTR. */ - MPN_COPY (op_ptr, root_ptr, op_size); - } - } - - mpn_sqrtrem (root_ptr, NULL, op_ptr, op_size); - - root->_mp_size = root_size; - - if (free_me != NULL) - (*_mp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB); - TMP_FREE (marker); -} diff --git a/gmp/mpz/sqrtrem.c b/gmp/mpz/sqrtrem.c deleted file mode 100755 index 99a6453..0000000 --- a/gmp/mpz/sqrtrem.c +++ /dev/null @@ -1,111 +0,0 @@ -/* mpz_sqrtrem(root,rem,x) -- Set ROOT to floor(sqrt(X)) and REM - to the remainder, i.e. X - ROOT**2. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#include "gmp.h" -#include "gmp-impl.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_sqrtrem (mpz_ptr root, mpz_ptr rem, mpz_srcptr op) -#else -mpz_sqrtrem (root, rem, op) - mpz_ptr root; - mpz_ptr rem; - mpz_srcptr op; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -msqrt (mpz_srcptr op, mpz_ptr root, mpz_ptr rem) -#else -msqrt (op, root, rem) - mpz_srcptr op; - mpz_ptr root; - mpz_ptr rem; -#endif -#endif /* BERKELEY_MP */ -{ - mp_size_t op_size, root_size, rem_size; - mp_ptr root_ptr, op_ptr; - mp_ptr free_me = NULL; - mp_size_t free_me_size; - TMP_DECL (marker); - - TMP_MARK (marker); - op_size = op->_mp_size; - if (op_size < 0) - SQRT_OF_NEGATIVE; - - if (rem->_mp_alloc < op_size) - _mpz_realloc (rem, op_size); - - /* The size of the root is accurate after this simple calculation. */ - root_size = (op_size + 1) / 2; - - root_ptr = root->_mp_d; - op_ptr = op->_mp_d; - - if (root->_mp_alloc < root_size) - { - if (root_ptr == op_ptr) - { - free_me = root_ptr; - free_me_size = root->_mp_alloc; - } - else - (*_mp_free_func) (root_ptr, root->_mp_alloc * BYTES_PER_MP_LIMB); - - root->_mp_alloc = root_size; - root_ptr = (mp_ptr) (*_mp_allocate_func) (root_size * BYTES_PER_MP_LIMB); - root->_mp_d = root_ptr; - } - else - { - /* Make OP not overlap with ROOT. */ - if (root_ptr == op_ptr) - { - /* ROOT and OP are identical. Allocate temporary space for OP. */ - op_ptr = (mp_ptr) TMP_ALLOC (op_size * BYTES_PER_MP_LIMB); - /* Copy to the temporary space. Hack: Avoid temporary variable - by using ROOT_PTR. */ - MPN_COPY (op_ptr, root_ptr, op_size); - } - } - - rem_size = mpn_sqrtrem (root_ptr, rem->_mp_d, op_ptr, op_size); - - root->_mp_size = root_size; - - /* Write remainder size last, to enable us to define this function to - give only the square root remainder, if the user calls if with - ROOT == REM. */ - rem->_mp_size = rem_size; - - if (free_me != NULL) - (*_mp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB); - TMP_FREE (marker); -} diff --git a/gmp/mpz/sub.c b/gmp/mpz/sub.c deleted file mode 100755 index f3ae7c2..0000000 --- a/gmp/mpz/sub.c +++ /dev/null @@ -1,123 +0,0 @@ -/* mpz_sub -- Subtract two integers. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - -#ifndef BERKELEY_MP -void -#if __STDC__ -mpz_sub (mpz_ptr w, mpz_srcptr u, mpz_srcptr v) -#else -mpz_sub (w, u, v) - mpz_ptr w; - mpz_srcptr u; - mpz_srcptr v; -#endif -#else /* BERKELEY_MP */ -void -#if __STDC__ -msub (mpz_srcptr u, mpz_srcptr v, mpz_ptr w) -#else -msub (u, v, w) - mpz_srcptr u; - mpz_srcptr v; - mpz_ptr w; -#endif -#endif /* BERKELEY_MP */ -{ - mp_srcptr up, vp; - mp_ptr wp; - mp_size_t usize, vsize, wsize; - mp_size_t abs_usize; - mp_size_t abs_vsize; - - usize = u->_mp_size; - vsize = -v->_mp_size; /* The "-" makes the difference from mpz_add */ - abs_usize = ABS (usize); - abs_vsize = ABS (vsize); - - if (abs_usize < abs_vsize) - { - /* Swap U and V. */ - MPZ_SRCPTR_SWAP (u, v); - MP_SIZE_T_SWAP (usize, vsize); - MP_SIZE_T_SWAP (abs_usize, abs_vsize); - } - - /* True: ABS_USIZE >= ABS_VSIZE. */ - - /* If not space for w (and possible carry), increase space. */ - wsize = abs_usize + 1; - if (w->_mp_alloc < wsize) - _mpz_realloc (w, wsize); - - /* These must be after realloc (u or v may be the same as w). */ - up = u->_mp_d; - vp = v->_mp_d; - wp = w->_mp_d; - - if ((usize ^ vsize) < 0) - { - /* U and V have different sign. Need to compare them to determine - which operand to subtract from which. */ - - /* This test is right since ABS_USIZE >= ABS_VSIZE. */ - if (abs_usize != abs_vsize) - { - mpn_sub (wp, up, abs_usize, vp, abs_vsize); - wsize = abs_usize; - MPN_NORMALIZE (wp, wsize); - if (usize < 0) - wsize = -wsize; - } - else if (mpn_cmp (up, vp, abs_usize) < 0) - { - mpn_sub_n (wp, vp, up, abs_usize); - wsize = abs_usize; - MPN_NORMALIZE (wp, wsize); - if (usize >= 0) - wsize = -wsize; - } - else - { - mpn_sub_n (wp, up, vp, abs_usize); - wsize = abs_usize; - MPN_NORMALIZE (wp, wsize); - if (usize < 0) - wsize = -wsize; - } - } - else - { - /* U and V have same sign. Add them. */ - mp_limb_t cy_limb = mpn_add (wp, up, abs_usize, vp, abs_vsize); - wp[abs_usize] = cy_limb; - wsize = abs_usize + cy_limb; - if (usize < 0) - wsize = -wsize; - } - - w->_mp_size = wsize; -} diff --git a/gmp/mpz/sub_ui.c b/gmp/mpz/sub_ui.c deleted file mode 100755 index 327add8..0000000 --- a/gmp/mpz/sub_ui.c +++ /dev/null @@ -1,84 +0,0 @@ -/* mpz_sub_ui -- Subtract an unsigned one-word integer from an MP_INT. - -Copyright (C) 1991, 1993, 1994, 1996, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_sub_ui (mpz_ptr w, mpz_srcptr u, unsigned long int v) -#else -mpz_sub_ui (w, u, v) - mpz_ptr w; - mpz_srcptr u; - unsigned long int v; -#endif -{ - mp_srcptr up; - mp_ptr wp; - mp_size_t usize, wsize; - mp_size_t abs_usize; - - usize = u->_mp_size; - abs_usize = ABS (usize); - - /* If not space for W (and possible carry), increase space. */ - wsize = abs_usize + 1; - if (w->_mp_alloc < wsize) - _mpz_realloc (w, wsize); - - /* These must be after realloc (U may be the same as W). */ - up = u->_mp_d; - wp = w->_mp_d; - - if (abs_usize == 0) - { - wp[0] = v; - w->_mp_size = -(v != 0); - return; - } - - if (usize < 0) - { - mp_limb_t cy; - cy = mpn_add_1 (wp, up, abs_usize, (mp_limb_t) v); - wp[abs_usize] = cy; - wsize = -(abs_usize + cy); - } - else - { - /* The signs are different. Need exact comparison to determine - which operand to subtract from which. */ - if (abs_usize == 1 && up[0] < v) - { - wp[0] = v - up[0]; - wsize = -1; - } - else - { - mpn_sub_1 (wp, up, abs_usize, (mp_limb_t) v); - /* Size can decrease with at most one limb. */ - wsize = abs_usize - (wp[abs_usize - 1] == 0); - } - } - - w->_mp_size = wsize; -} diff --git a/gmp/mpz/swap.c b/gmp/mpz/swap.c deleted file mode 100755 index 0070d6f..0000000 --- a/gmp/mpz/swap.c +++ /dev/null @@ -1,52 +0,0 @@ -/* mpz_swap (dest_integer, src_integer) -- Swap U and V. - -Copyright (C) 1997, 1998 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_swap (mpz_ptr u, mpz_ptr v) -#else -mpz_swap (u, v) - mpz_ptr u; - mpz_ptr v; -#endif -{ - mp_ptr up, vp; - mp_size_t usize, vsize; - mp_size_t ualloc, valloc; - - ualloc = u->_mp_alloc; - valloc = v->_mp_alloc; - v->_mp_alloc = ualloc; - u->_mp_alloc = valloc; - - usize = u->_mp_size; - vsize = v->_mp_size; - v->_mp_size = usize; - u->_mp_size = vsize; - - up = u->_mp_d; - vp = v->_mp_d; - v->_mp_d = up; - u->_mp_d = vp; -} diff --git a/gmp/mpz/tdiv_q.c b/gmp/mpz/tdiv_q.c deleted file mode 100755 index 21db4ab..0000000 --- a/gmp/mpz/tdiv_q.c +++ /dev/null @@ -1,91 +0,0 @@ -/* mpz_tdiv_q -- divide two integers and produce a quotient. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpz_tdiv_q (mpz_ptr quot, mpz_srcptr num, mpz_srcptr den) -#else -mpz_tdiv_q (quot, num, den) - mpz_ptr quot; - mpz_srcptr num; - mpz_srcptr den; -#endif -{ - mp_size_t ql; - mp_size_t ns, ds, nl, dl; - mp_ptr np, dp, qp, rp; - TMP_DECL (marker); - - ns = SIZ (num); - ds = SIZ (den); - nl = ABS (ns); - dl = ABS (ds); - ql = nl - dl + 1; - - if (dl == 0) - DIVIDE_BY_ZERO; - - if (ql <= 0) - { - SIZ (quot) = 0; - return; - } - - MPZ_REALLOC (quot, ql); - - TMP_MARK (marker); - qp = PTR (quot); - rp = (mp_ptr) TMP_ALLOC (dl * BYTES_PER_MP_LIMB); - np = PTR (num); - dp = PTR (den); - - /* FIXME: We should think about how to handle the temporary allocation. - Perhaps mpn_tdiv_qr should handle it, since it anyway often needs to - allocate temp space. */ - - /* Copy denominator to temporary space if it overlaps with the quotient. */ - if (dp == qp) - { - mp_ptr tp; - tp = (mp_ptr) TMP_ALLOC (dl * BYTES_PER_MP_LIMB); - MPN_COPY (tp, dp, dl); - dp = tp; - } - /* Copy numerator to temporary space if it overlaps with the quotient. */ - if (np == qp) - { - mp_ptr tp; - tp = (mp_ptr) TMP_ALLOC (nl * BYTES_PER_MP_LIMB); - MPN_COPY (tp, np, nl); - np = tp; - } - - mpn_tdiv_qr (qp, rp, 0L, np, nl, dp, dl); - - ql -= qp[ql - 1] == 0; - - SIZ (quot) = (ns ^ ds) >= 0 ? ql : -ql; - TMP_FREE (marker); -} diff --git a/gmp/mpz/tdiv_q_2exp.c b/gmp/mpz/tdiv_q_2exp.c deleted file mode 100755 index 03d1e01..0000000 --- a/gmp/mpz/tdiv_q_2exp.c +++ /dev/null @@ -1,68 +0,0 @@ -/* mpz_tdiv_q_2exp -- Divide an integer by 2**CNT. Round the quotient - towards -infinity. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_tdiv_q_2exp (mpz_ptr w, mpz_srcptr u, unsigned long int cnt) -#else -mpz_tdiv_q_2exp (w, u, cnt) - mpz_ptr w; - mpz_srcptr u; - unsigned long int cnt; -#endif -{ - mp_size_t usize, wsize; - mp_size_t limb_cnt; - - usize = u->_mp_size; - limb_cnt = cnt / BITS_PER_MP_LIMB; - wsize = ABS (usize) - limb_cnt; - if (wsize <= 0) - w->_mp_size = 0; - else - { - mp_ptr wp; - mp_srcptr up; - - if (w->_mp_alloc < wsize) - _mpz_realloc (w, wsize); - - wp = w->_mp_d; - up = u->_mp_d; - - cnt %= BITS_PER_MP_LIMB; - if (cnt != 0) - { - mpn_rshift (wp, up + limb_cnt, wsize, cnt); - wsize -= wp[wsize - 1] == 0; - } - else - { - MPN_COPY_INCR (wp, up + limb_cnt, wsize); - } - - w->_mp_size = usize >= 0 ? wsize : -wsize; - } -} diff --git a/gmp/mpz/tdiv_q_ui.c b/gmp/mpz/tdiv_q_ui.c deleted file mode 100755 index a2e3462..0000000 --- a/gmp/mpz/tdiv_q_ui.c +++ /dev/null @@ -1,64 +0,0 @@ -/* mpz_tdiv_q_ui(quot, dividend, divisor_limb) - -- Divide DIVIDEND by DIVISOR_LIMB and store the result in QUOT. - -Copyright (C) 1991, 1993, 1994, 1996, 1998 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_tdiv_q_ui (mpz_ptr quot, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_tdiv_q_ui (quot, dividend, divisor) - mpz_ptr quot; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_ptr quot_ptr; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - /* No need for temporary allocation and copying if QUOT == DIVIDEND as - the divisor is just one limb, and thus no intermediate remainders - need to be stored. */ - - if (quot->_mp_alloc < size) - _mpz_realloc (quot, size); - - quot_ptr = quot->_mp_d; - - remainder_limb - = mpn_divmod_1 (quot_ptr, dividend->_mp_d, size, (mp_limb_t) divisor); - - /* The quotient is SIZE limbs, but the most significant might be zero. */ - size -= size != 0 && quot_ptr[size - 1] == 0; - quot->_mp_size = dividend_size >= 0 ? size : -size; - - return remainder_limb; -} diff --git a/gmp/mpz/tdiv_qr.c b/gmp/mpz/tdiv_qr.c deleted file mode 100755 index d66f57d..0000000 --- a/gmp/mpz/tdiv_qr.c +++ /dev/null @@ -1,130 +0,0 @@ -/* mpz_tdiv_qr(quot,rem,dividend,divisor) -- Set QUOT to DIVIDEND/DIVISOR, - and REM to DIVIDEND mod DIVISOR. - -Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#ifdef BERKELEY_MP -#include "mp.h" -#endif - - -#ifndef BERKELEY_MP - -void -#if __STDC__ -mpz_tdiv_qr (mpz_ptr quot, mpz_ptr rem, mpz_srcptr num, mpz_srcptr den) -#else -mpz_tdiv_qr (quot, rem, num, den) - mpz_ptr quot; - mpz_ptr rem; - mpz_srcptr num; - mpz_srcptr den; -#endif - -#else /* BERKELEY_MP */ - -void -#if __STDC__ -mdiv (mpz_srcptr num, mpz_srcptr den, mpz_ptr quot, mpz_ptr rem) -#else -mdiv (num, den, quot, rem) - mpz_srcptr num; - mpz_srcptr den; - mpz_ptr quot; - mpz_ptr rem; -#endif - -#endif /* BERKELEY_MP */ -{ - mp_size_t ql; - mp_size_t ns, ds, nl, dl; - mp_ptr np, dp, qp, rp; - TMP_DECL (marker); - - ns = SIZ (num); - ds = SIZ (den); - nl = ABS (ns); - dl = ABS (ds); - ql = nl - dl + 1; - - if (dl == 0) - DIVIDE_BY_ZERO; - - MPZ_REALLOC (rem, dl); - - if (ql <= 0) - { - if (num != rem) - { - mp_ptr np, rp; - np = PTR (num); - rp = PTR (rem); - MPN_COPY (rp, np, nl); - SIZ (rem) = SIZ (num); - } - /* This needs to follow the assignment to rem, in case the - numerator and quotient are the same. */ - SIZ (quot) = 0; - return; - } - - MPZ_REALLOC (quot, ql); - - TMP_MARK (marker); - qp = PTR (quot); - rp = PTR (rem); - np = PTR (num); - dp = PTR (den); - - /* FIXME: We should think about how to handle the temporary allocation. - Perhaps mpn_tdiv_qr should handle it, since it anyway often needs to - allocate temp space. */ - - /* Copy denominator to temporary space if it overlaps with the quotient - or remainder. */ - if (dp == rp || dp == qp) - { - mp_ptr tp; - tp = (mp_ptr) TMP_ALLOC (dl * BYTES_PER_MP_LIMB); - MPN_COPY (tp, dp, dl); - dp = tp; - } - /* Copy numerator to temporary space if it overlaps with the quotient or - remainder. */ - if (np == rp || np == qp) - { - mp_ptr tp; - tp = (mp_ptr) TMP_ALLOC (nl * BYTES_PER_MP_LIMB); - MPN_COPY (tp, np, nl); - np = tp; - } - - mpn_tdiv_qr (qp, rp, 0L, np, nl, dp, dl); - - ql -= qp[ql - 1] == 0; - MPN_NORMALIZE (rp, dl); - - SIZ (quot) = (ns ^ ds) >= 0 ? ql : -ql; - SIZ (rem) = ns >= 0 ? dl : -dl; - TMP_FREE (marker); -} diff --git a/gmp/mpz/tdiv_qr_ui.c b/gmp/mpz/tdiv_qr_ui.c deleted file mode 100755 index 10368cd..0000000 --- a/gmp/mpz/tdiv_qr_ui.c +++ /dev/null @@ -1,76 +0,0 @@ -/* mpz_tdiv_qr_ui(quot,rem,dividend,short_divisor) -- - Set QUOT to DIVIDEND / SHORT_DIVISOR - and REM to DIVIDEND mod SHORT_DIVISOR. - -Copyright (C) 1991, 1993, 1994, 1996, 1998 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_tdiv_qr_ui (mpz_ptr quot, mpz_ptr rem, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_tdiv_qr_ui (quot, rem, dividend, divisor) - mpz_ptr quot; - mpz_ptr rem; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_ptr quot_ptr; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - /* No need for temporary allocation and copying if QUOT == DIVIDEND as - the divisor is just one limb, and thus no intermediate remainders - need to be stored. */ - - if (quot->_mp_alloc < size) - _mpz_realloc (quot, size); - - quot_ptr = quot->_mp_d; - - remainder_limb = mpn_divmod_1 (quot_ptr, dividend->_mp_d, size, - (mp_limb_t) divisor); - - if (remainder_limb == 0) - rem->_mp_size = 0; - else - { - /* Store the single-limb remainder. We don't check if there's space - for just one limb, since no function ever makes zero space. */ - rem->_mp_size = dividend_size >= 0 ? 1 : -1; - rem->_mp_d[0] = remainder_limb; - } - - /* The quotient is SIZE limbs, but the most significant might be zero. */ - size -= size != 0 && quot_ptr[size - 1] == 0; - quot->_mp_size = dividend_size >= 0 ? size : -size; - - return remainder_limb; -} diff --git a/gmp/mpz/tdiv_r.c b/gmp/mpz/tdiv_r.c deleted file mode 100755 index 9eb87df..0000000 --- a/gmp/mpz/tdiv_r.c +++ /dev/null @@ -1,98 +0,0 @@ -/* mpz_tdiv_r(rem, dividend, divisor) -- Set REM to DIVIDEND mod DIVISOR. - -Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpz_tdiv_r (mpz_ptr rem, mpz_srcptr num, mpz_srcptr den) -#else -mpz_tdiv_r (rem, num, den) - mpz_ptr rem; - mpz_srcptr num; - mpz_srcptr den; -#endif -{ - mp_size_t ql; - mp_size_t ns, ds, nl, dl; - mp_ptr np, dp, qp, rp; - TMP_DECL (marker); - - ns = SIZ (num); - ds = SIZ (den); - nl = ABS (ns); - dl = ABS (ds); - ql = nl - dl + 1; - - if (dl == 0) - DIVIDE_BY_ZERO; - - MPZ_REALLOC (rem, dl); - - if (ql <= 0) - { - if (num != rem) - { - mp_ptr np, rp; - np = PTR (num); - rp = PTR (rem); - MPN_COPY (rp, np, nl); - SIZ (rem) = SIZ (num); - } - return; - } - - TMP_MARK (marker); - qp = (mp_ptr) TMP_ALLOC (ql * BYTES_PER_MP_LIMB); - rp = PTR (rem); - np = PTR (num); - dp = PTR (den); - - /* FIXME: We should think about how to handle the temporary allocation. - Perhaps mpn_tdiv_qr should handle it, since it anyway often needs to - allocate temp space. */ - - /* Copy denominator to temporary space if it overlaps with the remainder. */ - if (dp == rp) - { - mp_ptr tp; - tp = (mp_ptr) TMP_ALLOC (dl * BYTES_PER_MP_LIMB); - MPN_COPY (tp, dp, dl); - dp = tp; - } - /* Copy numerator to temporary space if it overlaps with the remainder. */ - if (np == rp) - { - mp_ptr tp; - tp = (mp_ptr) TMP_ALLOC (nl * BYTES_PER_MP_LIMB); - MPN_COPY (tp, np, nl); - np = tp; - } - - mpn_tdiv_qr (qp, rp, 0L, np, nl, dp, dl); - - MPN_NORMALIZE (rp, dl); - - SIZ (rem) = ns >= 0 ? dl : -dl; - TMP_FREE (marker); -} diff --git a/gmp/mpz/tdiv_r_2exp.c b/gmp/mpz/tdiv_r_2exp.c deleted file mode 100755 index 91de170..0000000 --- a/gmp/mpz/tdiv_r_2exp.c +++ /dev/null @@ -1,79 +0,0 @@ -/* mpz_tdiv_r_2exp -- Divide a integer by 2**CNT and produce a remainder. - -Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_tdiv_r_2exp (mpz_ptr res, mpz_srcptr in, unsigned long int cnt) -#else -mpz_tdiv_r_2exp (res, in, cnt) - mpz_ptr res; - mpz_srcptr in; - unsigned long int cnt; -#endif -{ - mp_size_t in_size = ABS (in->_mp_size); - mp_size_t res_size; - mp_size_t limb_cnt = cnt / BITS_PER_MP_LIMB; - mp_srcptr in_ptr = in->_mp_d; - - if (in_size > limb_cnt) - { - /* The input operand is (probably) greater than 2**CNT. */ - mp_limb_t x; - - x = in_ptr[limb_cnt] & (((mp_limb_t) 1 << cnt % BITS_PER_MP_LIMB) - 1); - if (x != 0) - { - res_size = limb_cnt + 1; - if (res->_mp_alloc < res_size) - _mpz_realloc (res, res_size); - - res->_mp_d[limb_cnt] = x; - } - else - { - res_size = limb_cnt; - MPN_NORMALIZE (in_ptr, res_size); - - if (res->_mp_alloc < res_size) - _mpz_realloc (res, res_size); - - limb_cnt = res_size; - } - } - else - { - /* The input operand is smaller than 2**CNT. We perform a no-op, - apart from that we might need to copy IN to RES. */ - res_size = in_size; - if (res->_mp_alloc < res_size) - _mpz_realloc (res, res_size); - - limb_cnt = res_size; - } - - if (res != in) - MPN_COPY (res->_mp_d, in->_mp_d, limb_cnt); - res->_mp_size = in->_mp_size >= 0 ? res_size : -res_size; -} diff --git a/gmp/mpz/tdiv_r_ui.c b/gmp/mpz/tdiv_r_ui.c deleted file mode 100755 index 2ea411f..0000000 --- a/gmp/mpz/tdiv_r_ui.c +++ /dev/null @@ -1,63 +0,0 @@ -/* mpz_tdiv_r_ui(rem, dividend, divisor_limb) - -- Set REM to DIVDEND mod DIVISOR_LIMB. - -Copyright (C) 1991, 1993, 1994, 1996, 1998 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_tdiv_r_ui (mpz_ptr rem, mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_tdiv_r_ui (rem, dividend, divisor) - mpz_ptr rem; - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - /* No need for temporary allocation and copying if QUOT == DIVIDEND as - the divisor is just one limb, and thus no intermediate remainders - need to be stored. */ - - remainder_limb = mpn_mod_1 (dividend->_mp_d, size, (mp_limb_t) divisor); - - if (remainder_limb == 0) - rem->_mp_size = 0; - else - { - /* Store the single-limb remainder. We don't check if there's space - for just one limb, since no function ever makes zero space. */ - rem->_mp_size = dividend_size >= 0 ? 1 : -1; - rem->_mp_d[0] = remainder_limb; - } - - return remainder_limb; -} diff --git a/gmp/mpz/tdiv_ui.c b/gmp/mpz/tdiv_ui.c deleted file mode 100755 index 7a40a6a..0000000 --- a/gmp/mpz/tdiv_ui.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mpz_tdiv_ui(dividend, divisor_limb) - -- Return DIVDEND mod DIVISOR_LIMB. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 1998 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -unsigned long int -#if __STDC__ -mpz_tdiv_ui (mpz_srcptr dividend, unsigned long int divisor) -#else -mpz_tdiv_ui (dividend, divisor) - mpz_srcptr dividend; - unsigned long int divisor; -#endif -{ - mp_size_t dividend_size; - mp_size_t size; - mp_limb_t remainder_limb; - - if (divisor == 0) - DIVIDE_BY_ZERO; - - dividend_size = dividend->_mp_size; - size = ABS (dividend_size); - - /* No need for temporary allocation and copying if QUOT == DIVIDEND as - the divisor is just one limb, and thus no intermediate remainders - need to be stored. */ - - remainder_limb = mpn_mod_1 (dividend->_mp_d, size, (mp_limb_t) divisor); - - return remainder_limb; -} diff --git a/gmp/mpz/tests/Makefile.am b/gmp/mpz/tests/Makefile.am deleted file mode 100755 index cd785e1..0000000 Binary files a/gmp/mpz/tests/Makefile.am and /dev/null differ diff --git a/gmp/mpz/tests/Makefile.in b/gmp/mpz/tests/Makefile.in deleted file mode 100755 index ca2cb25..0000000 Binary files a/gmp/mpz/tests/Makefile.in and /dev/null differ diff --git a/gmp/mpz/tests/bit.c b/gmp/mpz/tests/bit.c deleted file mode 100755 index 606bec2..0000000 --- a/gmp/mpz/tests/bit.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Test mpz_setbit, mpz_clrbit, mpz_tstbit. - -Copyright (C) 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 4 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t x, s0, s1, s2, s3, m; - mp_size_t xsize; - int i; - int reps = 100000; - int bit0, bit1, bit2, bit3; - unsigned long int bitindex; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (x); - mpz_init (s0); - mpz_init (s1); - mpz_init (s2); - mpz_init (s3); - mpz_init (m); - - for (i = 0; i < reps; i++) - { - xsize = urandom () % (2 * SIZE) - SIZE; - mpz_random2 (x, xsize); - bitindex = urandom () % SIZE; - - mpz_set (s0, x); - bit0 = mpz_tstbit (x, bitindex); - mpz_setbit (x, bitindex); - MPZ_CHECK_FORMAT (x); - - mpz_set (s1, x); - bit1 = mpz_tstbit (x, bitindex); - mpz_clrbit (x, bitindex); - MPZ_CHECK_FORMAT (x); - - mpz_set (s2, x); - bit2 = mpz_tstbit (x, bitindex); - mpz_setbit (x, bitindex); - MPZ_CHECK_FORMAT (x); - - mpz_set (s3, x); - bit3 = mpz_tstbit (x, bitindex); - - if (bit1 != 1 || bit2 != 0 || bit3 != 1) - abort (); - - if (bit0 == 0) - { - if (mpz_cmp (s0, s1) == 0 || mpz_cmp (s0, s2) != 0 || mpz_cmp (s0, s3) == 0) - abort (); - } - else - { - if (mpz_cmp (s0, s1) != 0 || mpz_cmp (s0, s2) == 0 || mpz_cmp (s0, s3) != 0) - abort (); - } - - if (mpz_cmp (s1, s2) == 0 || mpz_cmp (s1, s3) != 0) - abort (); - if (mpz_cmp (s2, s3) == 0) - abort (); - - mpz_ui_pow_ui (m, 2L, bitindex); - MPZ_CHECK_FORMAT (m); - mpz_ior (x, s2, m); - MPZ_CHECK_FORMAT (x); - if (mpz_cmp (x, s3) != 0) - abort (); - - mpz_com (m, m); - MPZ_CHECK_FORMAT (m); - mpz_and (x, s1, m); - MPZ_CHECK_FORMAT (x); - if (mpz_cmp (x, s2) != 0) - abort (); - } - - exit (0); -} - -void -debug_mp (x, base) - MP_INT *x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/convert.c b/gmp/mpz/tests/convert.c deleted file mode 100755 index 7526092..0000000 --- a/gmp/mpz/tests/convert.c +++ /dev/null @@ -1,80 +0,0 @@ -/* Test conversion using mpz_get_str and mpz_set_str. - -Copyright (C) 1993, 1994, 1996, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 32 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t op1, op2; - mp_size_t size; - int i; - int reps = 100000; - char *str; - int base; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (op1); - mpz_init (op2); - - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE - SIZE/2; - - mpz_random2 (op1, size); - base = urandom () % 36 + 1; - if (base == 1) - base = 0; - - str = mpz_get_str ((char *) 0, base, op1); - mpz_set_str (op2, str, base); - (*_mp_free_func) (str, 0); - - if (mpz_cmp (op1, op2)) - { - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "op1 = "); debug_mp (op1, -16); - fprintf (stderr, "base = %d\n", base); - abort (); - } - } - - exit (0); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/dive.c b/gmp/mpz/tests/dive.c deleted file mode 100755 index d62b6c1..0000000 --- a/gmp/mpz/tests/dive.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Test mpz_mul, mpz_divexact. - -Copyright (C) 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 32 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t op1, op2; - mpz_t prod, quot; - mp_size_t size; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (op1); - mpz_init (op2); - mpz_init (prod); - mpz_init (quot); - - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (op1, size); - - do - { - size = urandom () % SIZE - SIZE/2; - mpz_random2 (op2, size); - } - while (mpz_cmp_ui (op2, 0) == 0); - - mpz_mul (prod, op1, op2); - - mpz_divexact (quot, prod, op2); - if (mpz_cmp (quot, op1) != 0) - dump_abort (quot, op1); - } - - exit (0); -} - -dump_abort (op1, op2) - mpz_t op1, op2; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "ref = "); debug_mp (op1, -16); - fprintf (stderr, "wrong = "); debug_mp (op2, -16); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/io.c b/gmp/mpz/tests/io.c deleted file mode 100755 index e62610c..0000000 --- a/gmp/mpz/tests/io.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Test conversion and I/O using mpz_out_str and mpz_inp_str. - -Copyright (C) 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#define FILENAME "io.tmp" - -#ifndef SIZE -#define SIZE 16 -#endif - -void -debug_mp (mpz_t x, int base) -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} - -int -main (int argc, char **argv) -{ - mpz_t op1, op2; - mp_size_t size; - int i; - int reps = 10000; - FILE *fp; - int base; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (op1); - mpz_init (op2); - - fp = fopen (FILENAME, "w+"); - - for (i = 0; i < reps; i++) - { - size = urandom () % SIZE - SIZE/2; - - mpz_random2 (op1, size); - base = urandom () % 36 + 1; - if (base == 1) - base = 0; - - rewind (fp); - if (mpz_out_str (fp, base, op1) == 0 - || putc (' ', fp) == EOF - || fflush (fp) != 0) - { - fprintf (stderr, "mpz_out_str write error\n"); - abort (); - } - - rewind (fp); - if (mpz_inp_str (op2, fp, base) == 0) - { - fprintf (stderr, "mpz_inp_str read error\n"); - abort (); - } - - if (mpz_cmp (op1, op2)) - { - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "op1 = "); debug_mp (op1, -16); - fprintf (stderr, "op2 = "); debug_mp (op2, -16); - fprintf (stderr, "base = %d\n", base); - abort (); - } - } - - fclose (fp); - - unlink (FILENAME); - - exit (0); -} diff --git a/gmp/mpz/tests/logic.c b/gmp/mpz/tests/logic.c deleted file mode 100755 index ea0de6f..0000000 --- a/gmp/mpz/tests/logic.c +++ /dev/null @@ -1,130 +0,0 @@ -/* Test mpz_com, mpz_and, mpz_ior, and mpz_xor. - -Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t x, y, r1, r2; - mpz_t t1, t2, t3, t4; - mp_size_t xsize, ysize; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (x); - mpz_init (y); - mpz_init (r1); - mpz_init (r2); - mpz_init (t1); - mpz_init (t2); - mpz_init (t3); - mpz_init (t4); - - for (i = 0; i < reps; i++) - { - xsize = urandom () % SIZE - SIZE/2; - mpz_random2 (x, xsize); - - ysize = urandom () % SIZE - SIZE/2; - mpz_random2 (y, ysize); - - mpz_com (r1, x); - MPZ_CHECK_FORMAT (r1); - mpz_com (r1, r1); - MPZ_CHECK_FORMAT (r1); - if (mpz_cmp (r1, x) != 0) - dump_abort (); - - mpz_com (r1, y); - MPZ_CHECK_FORMAT (r1); - mpz_com (r2, r1); - MPZ_CHECK_FORMAT (r2); - if (mpz_cmp (r2, y) != 0) - dump_abort (); - - mpz_com (t1, x); - MPZ_CHECK_FORMAT (t1); - mpz_com (t2, y); - MPZ_CHECK_FORMAT (t2); - mpz_and (t3, t1, t2); - MPZ_CHECK_FORMAT (t3); - mpz_com (r1, t3); - MPZ_CHECK_FORMAT (r1); - mpz_ior (r2, x, y); - MPZ_CHECK_FORMAT (r2); - if (mpz_cmp (r1, r2) != 0) - dump_abort (); - - mpz_com (t1, x); - MPZ_CHECK_FORMAT (t1); - mpz_com (t2, y); - MPZ_CHECK_FORMAT (t2); - mpz_ior (t3, t1, t2); - MPZ_CHECK_FORMAT (t3); - mpz_com (r1, t3); - MPZ_CHECK_FORMAT (r1); - mpz_and (r2, x, y); - MPZ_CHECK_FORMAT (r2); - if (mpz_cmp (r1, r2) != 0) - dump_abort (); - - mpz_ior (t1, x, y); - MPZ_CHECK_FORMAT (t1); - mpz_and (t2, x, y); - MPZ_CHECK_FORMAT (t2); - mpz_com (t3, t2); - MPZ_CHECK_FORMAT (t3); - mpz_and (r1, t1, t3); - MPZ_CHECK_FORMAT (r1); - mpz_xor (r2, x, y); - MPZ_CHECK_FORMAT (r2); - if (mpz_cmp (r1, r2) != 0) - dump_abort (); - } - - exit (0); -} - -dump_abort () -{ - abort(); -} - -void -debug_mp (x, base) - MP_INT *x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/reuse.c b/gmp/mpz/tests/reuse.c deleted file mode 100755 index f241723..0000000 --- a/gmp/mpz/tests/reuse.c +++ /dev/null @@ -1,512 +0,0 @@ -/* Test that routines allow reusing a source variable as destination. - - Test all relevant functions except: - mpz_bin_ui - mpz_nextprime - mpz_mul_si - mpz_addmul_ui (should this really allow a+=a*c?) -Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 50 -#endif - -typedef void (*dss_func) _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); -typedef void (*dsi_func) _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -typedef unsigned long int (*dsi_div_func) _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); -typedef unsigned long int (*ddsi_div_func) _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); -typedef void (*ddss_div_func) _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); -typedef void (*ds_func) _PROTO ((mpz_ptr, mpz_srcptr)); - - -void -#if __STDC__ -mpz_xinvert (mpz_ptr r, mpz_srcptr a, mpz_srcptr b) -#else -mpz_xinvert (r, a, b) - mpz_ptr r; - mpz_srcptr a; - mpz_srcptr b; -#endif -{ - int res; - res = mpz_invert (r, a, b); - if (res == 0) - mpz_set_ui (r, 0); -} - -dss_func dss_funcs[] = -{ - mpz_add, mpz_sub, mpz_mul, - mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r, mpz_tdiv_q, mpz_tdiv_r, - mpz_xinvert, - mpz_gcd, mpz_lcm, mpz_and, mpz_ior, mpz_xor -}; -char *dss_func_names[] = -{ - "mpz_add", "mpz_sub", "mpz_mul", - "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r", "mpz_tdiv_q", "mpz_tdiv_r", - "mpz_xinvert", - "mpz_gcd", "mpz_lcm", "mpz_and", "mpz_ior", "mpz_xor" -}; -char dss_func_division[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}; - -dsi_func dsi_funcs[] = -{ - /* Don't change order here without changing the code in main(). */ - mpz_add_ui, mpz_mul_ui, mpz_sub_ui, - mpz_fdiv_q_2exp, mpz_fdiv_r_2exp, - mpz_tdiv_q_2exp, mpz_tdiv_r_2exp, - mpz_mul_2exp, - mpz_pow_ui -}; -char *dsi_func_names[] = -{ - "mpz_add_ui", "mpz_mul_ui", "mpz_sub_ui", - "mpz_fdiv_q_2exp", "mpz_fdiv_r_2exp", - "mpz_tdiv_q_2exp", "mpz_tdiv_r_2exp", - "mpz_mul_2exp", - "mpz_pow_ui" -}; - -dsi_div_func dsi_div_funcs[] = -{ - mpz_cdiv_q_ui, mpz_cdiv_r_ui, - mpz_fdiv_q_ui, mpz_fdiv_r_ui, - mpz_tdiv_q_ui, mpz_tdiv_r_ui -}; -char *dsi_div_func_names[] = -{ - "mpz_cdiv_q_ui", "mpz_cdiv_r_ui", - "mpz_fdiv_q_ui", "mpz_fdiv_r_ui", - "mpz_tdiv_q_ui", "mpz_tdiv_r_ui" -}; - -ddsi_div_func ddsi_div_funcs[] = -{ - mpz_cdiv_qr_ui, - mpz_fdiv_qr_ui, - mpz_tdiv_qr_ui -}; -char *ddsi_div_func_names[] = -{ - "mpz_cdiv_qr_ui", - "mpz_fdiv_qr_ui", - "mpz_tdiv_qr_ui" -}; - -ddss_div_func ddss_div_funcs[] = -{ - mpz_cdiv_qr, - mpz_fdiv_qr, - mpz_tdiv_qr -}; -char *ddss_div_func_names[] = -{ - "mpz_cdiv_qr", - "mpz_fdiv_qr", - "mpz_tdiv_qr" -}; - -ds_func ds_funcs[] = -{ - mpz_abs, mpz_com, mpz_neg, mpz_sqrt -}; -char *ds_func_names[] = -{ - "mpz_abs", "mpz_com", "mpz_neg", "mpz_sqrt" -}; - - -/* Really use `defined (__STDC__)' here; we want it to be true for Sun C */ -#if defined (__STDC__) || defined (__cplusplus) -#define FAIL(class,indx,op1,op2,op3) \ - do { \ - class##_funcs[indx] = 0; \ - dump_abort (class##_func_names[indx], op1, op2, op3); \ - failures++; \ - } while (0) -#else -#define FAIL(class,indx,op1,op2,op3) \ - do { \ - class/**/_funcs[indx] = 0; \ - dump_abort (class/**/_func_names[indx], op1, op2, op3); \ - failures++; \ - } while (0) -#endif - - -main (argc, argv) - int argc; - char **argv; -{ - int i; - int pass, reps = 1000; - mpz_t in1, in2, in3; - unsigned long int in2i; - mpz_t res1, res2, res3; - mpz_t ref1, ref2, ref3; - mpz_t t; - unsigned long int r1, r2; - long failures = 0; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (in1); - mpz_init (in2); - mpz_init (in3); - mpz_init (ref1); - mpz_init (ref2); - mpz_init (ref3); - mpz_init (res1); - mpz_init (res2); - mpz_init (res3); - mpz_init (t); - - for (pass = 1; pass <= reps; pass++) - { - mpz_random2 (in1, urandom () % (2 * SIZE) - SIZE); - mpz_random2 (in2, urandom () % (2 * SIZE) - SIZE); - mpz_random2 (in3, urandom () % (2 * SIZE) - SIZE); - - for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++) - { - if (dss_funcs[i] == 0) - continue; - if (dss_func_division[i] && mpz_sgn (in2) == 0) - continue; - - (dss_funcs[i]) (ref1, in1, in2); - - mpz_set (res1, in1); - (dss_funcs[i]) (res1, res1, in2); - if (mpz_cmp (ref1, res1) != 0) - FAIL (dss, i, in1, in2, NULL); - - mpz_set (res1, in2); - (dss_funcs[i]) (res1, in1, res1); - if (mpz_cmp (ref1, res1) != 0) - FAIL (dss, i, in1, in2, NULL); - } - - for (i = 0; i < sizeof (ddss_div_funcs) / sizeof (ddss_div_func); i++) - { - if (ddss_div_funcs[i] == 0) - continue; - if (mpz_sgn (in2) == 0) - continue; - - (ddss_div_funcs[i]) (ref1, ref2, in1, in2); - - mpz_set (res1, in1); - (ddss_div_funcs[i]) (res1, res2, res1, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0) - FAIL (ddss_div, i, in1, in2, NULL); - - mpz_set (res2, in1); - (ddss_div_funcs[i]) (res1, res2, res2, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0) - FAIL (ddss_div, i, in1, in2, NULL); - - mpz_set (res1, in2); - (ddss_div_funcs[i]) (res1, res2, in1, res1); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0) - FAIL (ddss_div, i, in1, in2, NULL); - - mpz_set (res2, in2); - (ddss_div_funcs[i]) (res1, res2, in1, res2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0) - FAIL (ddss_div, i, in1, in2, NULL); - } - - for (i = 0; i < sizeof (ds_funcs) / sizeof (ds_func); i++) - { - if (ds_funcs[i] == 0) - continue; - if (strcmp (ds_func_names[i], "mpz_sqrt") == 0 - && mpz_sgn (in1) < 0) - continue; - - (ds_funcs[i]) (ref1, in1); - - mpz_set (res1, in1); - (ds_funcs[i]) (res1, res1); - if (mpz_cmp (ref1, res1) != 0) - FAIL (ds, i, in1, in2, NULL); - } - - in2i = mpz_get_ui (in2); - - for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++) - { - if (dsi_funcs[i] == 0) - continue; - if (strcmp (dsi_func_names[i], "mpz_fdiv_q_2exp") == 0) - /* Limit exponent to something reasonable for the division - functions. Without this, we'd normally shift things off - the end and just generate the trivial values 1, 0, -1. */ - in2i %= 0x1000; - if (strcmp (dsi_func_names[i], "mpz_mul_2exp") == 0) - /* Limit exponent more for mpz_mul_2exp to save time. */ - in2i %= 0x100; - if (strcmp (dsi_func_names[i], "mpz_pow_ui") == 0) - /* Limit exponent yet more for mpz_pow_ui to save time. */ - in2i %= 0x10; - - (dsi_funcs[i]) (ref1, in1, in2i); - - mpz_set (res1, in1); - (dsi_funcs[i]) (res1, res1, in2i); - if (mpz_cmp (ref1, res1) != 0) - FAIL (dsi, i, in1, in2, NULL); - } - - if (in2i != 0) /* Don't divide by 0. */ - { - for (i = 0; i < sizeof (dsi_div_funcs) / sizeof (dsi_div_funcs); i++) - { - r1 = (dsi_div_funcs[i]) (ref1, in1, in2i); - - mpz_set (res1, in1); - r2 = (dsi_div_funcs[i]) (res1, res1, in2i); - if (mpz_cmp (ref1, res1) != 0 || r1 != r2) - FAIL (dsi_div, i, in1, in2, NULL); - } - - for (i = 0; i < sizeof (ddsi_div_funcs) / sizeof (ddsi_div_funcs); i++) - { - r1 = (ddsi_div_funcs[i]) (ref1, ref2, in1, in2i); - - mpz_set (res1, in1); - r2 = (ddsi_div_funcs[i]) (res1, res2, res1, in2i); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 || r1 != r2) - FAIL (ddsi_div, i, in1, in2, NULL); - - mpz_set (res2, in1); - (ddsi_div_funcs[i]) (res1, res2, res2, in2i); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 || r1 != r2) - FAIL (ddsi_div, i, in1, in2, NULL); - } - } - - if (mpz_sgn (in1) >= 0) - { - mpz_sqrtrem (ref1, ref2, in1); - - mpz_set (res1, in1); - mpz_sqrtrem (res1, res2, res1); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0) - dump_abort ("mpz_sqrtrem", in1, NULL, NULL); - - mpz_set (res2, in1); - mpz_sqrtrem (res1, res2, res2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0) - dump_abort ("mpz_sqrtrem", in1, NULL, NULL); - } - - if (mpz_sgn (in1) >= 0) - { - mpz_root (ref1, in1, in2i % 0x100 + 1); - - mpz_set (res1, in1); - mpz_root (res1, res1, in2i % 0x100 + 1); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_root", in1, in2, NULL); - } - - if (pass < reps / 2) /* run fewer tests since gcdext lots of time */ - { - mpz_gcdext (ref1, ref2, ref3, in1, in2); - - mpz_set (res1, in1); - mpz_gcdext (res1, res2, res3, res1, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res2, in1); - mpz_gcdext (res1, res2, res3, res2, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res3, in1); - mpz_gcdext (res1, res2, res3, res3, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res1, in2); - mpz_gcdext (res1, res2, res3, in1, res1); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res2, in2); - mpz_gcdext (res1, res2, res3, in1, res2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res3, in2); - mpz_gcdext (res1, res2, res3, in1, res3); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res1, in1); - mpz_gcdext (res1, res2, NULL, res1, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res2, in1); - mpz_gcdext (res1, res2, NULL, res2, in2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res1, in2); - mpz_gcdext (res1, res2, NULL, in1, res1); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - - mpz_set (res2, in2); - mpz_gcdext (res1, res2, NULL, in1, res2); - if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 - || mpz_cmp (ref3, res3) != 0) - dump_abort ("mpz_gcdext", in1, in2, NULL); - } - - /* Don't run mpz_powm for huge exponents or when undefined. */ - if (mpz_sizeinbase (in2, 2) < 250 && mpz_sgn (in3) != 0) - { - mpz_powm (ref1, in1, in2, in3); - - mpz_set (res1, in1); - mpz_powm (res1, res1, in2, in3); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_powm", in1, in2, in3); - - mpz_set (res1, in2); - mpz_powm (res1, in1, res1, in3); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_powm", in1, in2, in3); - - mpz_set (res1, in3); - mpz_powm (res1, in1, in2, res1); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_powm", in1, in2, in3); - } - - /* Don't run mpz_powm_ui when undefined. */ - if (mpz_sgn (in3) != 0) - { - mpz_powm_ui (ref1, in1, in2i, in3); - - mpz_set (res1, in1); - mpz_powm_ui (res1, res1, in2i, in3); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_powm_ui", in1, in2, in3); - - mpz_set (res1, in3); - mpz_powm_ui (res1, in1, in2i, res1); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_powm_ui", in1, in2, in3); - } - - { - r1 = mpz_gcd_ui (ref1, in1, in2i); - - mpz_set (res1, in1); - r2 = mpz_gcd_ui (res1, res1, in2i); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_gcd_ui", in1, in2, NULL); - } - - if (mpz_cmp_ui (in2, 1L) > 0 && mpz_sgn (in1) != 0) - { - /* Test mpz_remove */ - mpz_remove (ref1, in1, in2); - - mpz_set (res1, in1); - mpz_remove (res1, res1, in2); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_remove", in1, in2, NULL); - - mpz_set (res1, in2); - mpz_remove (res1, in1, res1); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_remove", in1, in2, NULL); - } - - if (mpz_sgn (in2) != 0) - { - /* Test mpz_divexact */ - mpz_mul (t, in1, in2); - mpz_divexact (ref1, t, in2); - - mpz_set (res1, t); - mpz_divexact (res1, res1, in2); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_divexact", t, in2, NULL); - - mpz_set (res1, in2); - mpz_divexact (res1, t, res1); - if (mpz_cmp (ref1, res1) != 0) - dump_abort ("mpz_divexact", t, in2, NULL); - } - } - - if (failures != 0) - { - fprintf (stderr, "mpz/reuse: %d error%s\n", failures, "s" + (failures == 1)); - exit (1); - } - - exit (0); -} - -dump_abort (name, in1, in2, in3) - char *name; - mpz_t in1, in2, in3; -{ - printf ("failure in %s (", name); - mpz_out_str (stdout, -16, in1); - if (in2 != NULL) - { - printf (" "); - mpz_out_str (stdout, -16, in2); - } - if (in3 != NULL) - { - printf (" "); - mpz_out_str (stdout, -16, in3); - } - printf (")\n"); -} diff --git a/gmp/mpz/tests/t-2exp.c b/gmp/mpz/tests/t-2exp.c deleted file mode 100755 index d18e3cb..0000000 --- a/gmp/mpz/tests/t-2exp.c +++ /dev/null @@ -1,77 +0,0 @@ -/* Test mpz_ui_pow_ui, mpz_fdiv_q, mpz_fdiv_q_2exp, mpz_fdiv_r, - mpz_fdiv_r_2exp, and mpz_mul_2exp. - -Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "urandom.h" - -#ifndef SIZE -#define SIZE 8 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t x, r1, r2, q1, q2, d, t; - unsigned long int c; - int test; - int ntests = 100000; - - if (argc == 2) - ntests = atoi (argv[1]); - - mpz_init (x); - mpz_init (q1); - mpz_init (q2); - mpz_init (r1); - mpz_init (r2); - mpz_init (d); - mpz_init (t); - - for (test = 1; test <= ntests; test++) - { - mpz_random2 (x, urandom () % (2 * SIZE) - SIZE); - c = urandom () % (3 * SIZE / 2 * BITS_PER_MP_LIMB); - mpz_ui_pow_ui (d, (unsigned long) 2, c); - - mpz_fdiv_q (q1, x, d); - mpz_fdiv_q_2exp (q2, x, c); - mpz_fdiv_r (r1, x, d); - mpz_fdiv_r_2exp (r2, x, c); - - if (mpz_cmp (q1, q2) != 0 || mpz_cmp (r1, r2) != 0) - abort (); - - mpz_mul_2exp (t, q1, c); - mpz_add (t, t, r1); - if (mpz_cmp (t, x) != 0) - abort (); - - if (mpz_cmp (r1, d) >= 0) - abort (); - } - - exit (0); -} diff --git a/gmp/mpz/tests/t-bin.c b/gmp/mpz/tests/t-bin.c deleted file mode 100755 index 62ef639..0000000 --- a/gmp/mpz/tests/t-bin.c +++ /dev/null @@ -1,217 +0,0 @@ -/* Exercise mpz_bin_ui and mpz_bin_uiui. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - - -void -try_mpz_bin_ui (mpz_srcptr want, mpz_srcptr n, unsigned long k) -{ - mpz_t got; - - mpz_init (got); - mpz_bin_ui (got, n, k); - MPZ_CHECK_FORMAT (got); - if (mpz_cmp (got, want) != 0) - { - printf ("mpz_bin_ui wrong\n"); - printf (" n="); mpz_out_str (stdout, 10, n); printf ("\n"); - printf (" k=%lu\n", k); - printf (" got="); mpz_out_str (stdout, 10, got); printf ("\n"); - printf (" want="); mpz_out_str (stdout, 10, want); printf ("\n"); - abort(); - } - mpz_clear (got); -} - - -void -try_mpz_bin_uiui (mpz_srcptr want, unsigned long n, unsigned long k) -{ - mpz_t got; - - mpz_init (got); - mpz_bin_uiui (got, n, k); - MPZ_CHECK_FORMAT (got); - if (mpz_cmp (got, want) != 0) - { - printf ("mpz_bin_uiui wrong\n"); - printf (" n=%lu\n", n); - printf (" k=%lu\n", k); - printf (" got="); mpz_out_str (stdout, 10, got); printf ("\n"); - printf (" want="); mpz_out_str (stdout, 10, want); printf ("\n"); - abort(); - } - mpz_clear (got); -} - - -void -samples (void) -{ - static const struct { - const char *n; - unsigned long k; - const char *want; - } data[] = { - - { "0", 0, "1" }, - { "0", 1, "0" }, - { "0", 2, "0" }, - { "0", 3, "0" }, - { "0", 4, "0" }, - { "0", 123456, "0" }, - - { "1", 0, "1" }, - { "1", 1, "1" }, - { "1", 2, "0" }, - { "1", 3, "0" }, - { "1", 4, "0" }, - { "1", 123456, "0" }, - - { "2", 0, "1" }, - { "2", 1, "2" }, - { "2", 2, "1" }, - { "2", 3, "0" }, - { "2", 4, "0" }, - { "2", 123456, "0" }, - - { "3", 0, "1" }, - { "3", 1, "3" }, - { "3", 2, "3" }, - { "3", 3, "1" }, - { "3", 4, "0" }, - { "3", 5, "0" }, - { "3", 123456, "0" }, - - { "4", 0, "1" }, - { "4", 1, "4" }, - { "4", 2, "6" }, - { "4", 3, "4" }, - { "4", 4, "1" }, - { "4", 5, "0" }, - { "4", 6, "0" }, - { "4", 123456, "0" }, - - { "10", 0, "1" }, - { "10", 1, "10" }, - { "10", 2, "45" }, - { "10", 3, "120" }, - { "10", 4, "210" }, - { "10", 5, "252" }, - { "10", 6, "210" }, - { "10", 7, "120" }, - { "10", 8, "45" }, - { "10", 9, "10" }, - { "10", 10, "1" }, - { "10", 11, "0" }, - { "10", 12, "0" }, - { "10", 123456, "0" }, - - /* negatives, using bin(-n,k)=bin(n+k-1,k) */ - { "-1", 0, "1" }, - { "-1", 1, "-1" }, - { "-1", 2, "1" }, - { "-1", 3, "-1" }, - { "-1", 4, "1" }, - - { "-2", 0, "1" }, - { "-2", 1, "-2" }, - { "-2", 2, "3" }, - { "-2", 3, "-4" }, - { "-2", 4, "5" }, - { "-2", 5, "-6" }, - { "-2", 6, "7" }, - - { "-3", 0, "1" }, - { "-3", 1, "-3" }, - { "-3", 2, "6" }, - { "-3", 3, "-10" }, - { "-3", 4, "15" }, - { "-3", 5, "-21" }, - { "-3", 6, "28" }, - - { "40", 20, "137846528820" }, - { "60", 30, "118264581564861424" }, - }; - - mpz_t n, want; - int i; - - mpz_init (n); - mpz_init (want); - - for (i = 0; i < numberof (data); i++) - { - mpz_set_str (n, data[i].n, 0); - mpz_set_str (want, data[i].want, 0); - - try_mpz_bin_ui (want, n, data[i].k); - - if (mpz_fits_ulong_p (n)) - try_mpz_bin_uiui (want, mpz_get_ui (n), data[i].k); - } - - mpz_clear (n); - mpz_clear (want); -} - - -/* Test some bin(2k,k) cases. This produces some biggish numbers to - exercise the limb accumulating code. */ -void -twos (void) -{ - mpz_t n, want; - unsigned long k; - - mpz_init (n); - mpz_init (want); - - mpz_set_ui (want, (unsigned long) 2); - for (k = 1; k < 200; k++) - { - mpz_set_ui (n, 2*k); - try_mpz_bin_ui (want, n, k); - - try_mpz_bin_uiui (want, 2*k, k); - - mpz_mul_ui (want, want, 2*(2*k+1)); - mpz_fdiv_q_ui (want, want, k+1); - } - - mpz_clear (n); - mpz_clear (want); -} - - -int -main (void) -{ - samples (); - twos (); - - exit (0); -} diff --git a/gmp/mpz/tests/t-fdiv.c b/gmp/mpz/tests/t-fdiv.c deleted file mode 100755 index fe041d1..0000000 --- a/gmp/mpz/tests/t-fdiv.c +++ /dev/null @@ -1,118 +0,0 @@ -/* Test mpz_abs, mpz_add, mpz_cmp, mpz_cmp_ui, mpz_fdiv_qr, mpz_fdiv_q, - mpz_fdiv_r, mpz_mul. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t dividend, divisor; - mpz_t quotient, remainder; - mpz_t quotient2, remainder2; - mpz_t temp; - mp_size_t dividend_size, divisor_size; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (dividend); - mpz_init (divisor); - mpz_init (quotient); - mpz_init (remainder); - mpz_init (quotient2); - mpz_init (remainder2); - mpz_init (temp); - - for (i = 0; i < reps; i++) - { - dividend_size = urandom () % SIZE - SIZE/2; - mpz_random2 (dividend, dividend_size); - - divisor_size = urandom () % SIZE - SIZE/2; - mpz_random2 (divisor, divisor_size); - if (mpz_cmp_ui (divisor, 0) == 0) - continue; - - mpz_fdiv_qr (quotient, remainder, dividend, divisor); - mpz_fdiv_q (quotient2, dividend, divisor); - mpz_fdiv_r (remainder2, dividend, divisor); - - /* First determine that the quotients and remainders computed - with different functions are equal. */ - if (mpz_cmp (quotient, quotient2) != 0) - dump_abort (dividend, divisor); - if (mpz_cmp (remainder, remainder2) != 0) - dump_abort (dividend, divisor); - - /* Check if the sign of the quotient is correct. */ - if (mpz_cmp_ui (quotient, 0) != 0) - if ((mpz_cmp_ui (quotient, 0) < 0) - != ((mpz_cmp_ui (dividend, 0) ^ mpz_cmp_ui (divisor, 0)) < 0)) - dump_abort (dividend, divisor); - - /* Check if the remainder has the same sign as the divisor - (quotient rounded towards minus infinity). */ - if (mpz_cmp_ui (remainder, 0) != 0) - if ((mpz_cmp_ui (remainder, 0) < 0) != (mpz_cmp_ui (divisor, 0) < 0)) - dump_abort (dividend, divisor); - - mpz_mul (temp, quotient, divisor); - mpz_add (temp, temp, remainder); - if (mpz_cmp (temp, dividend) != 0) - dump_abort (dividend, divisor); - - mpz_abs (temp, divisor); - mpz_abs (remainder, remainder); - if (mpz_cmp (remainder, temp) >= 0) - dump_abort (dividend, divisor); - } - - exit (0); -} - -dump_abort (dividend, divisor) - mpz_t dividend, divisor; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "dividend = "); debug_mp (dividend, -16); - fprintf (stderr, "divisor = "); debug_mp (divisor, -16); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-fdiv_ui.c b/gmp/mpz/tests/t-fdiv_ui.c deleted file mode 100755 index 2442cd8..0000000 --- a/gmp/mpz/tests/t-fdiv_ui.c +++ /dev/null @@ -1,117 +0,0 @@ -/* Test mpz_abs, mpz_add, mpz_cmp, mpz_cmp_ui, mpz_fdiv_qr_ui, mpz_fdiv_q_ui, - mpz_fdiv_r_ui, mpz_mul, mpz_mul_ui. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t dividend; - mpz_t quotient, remainder; - mpz_t quotient2, remainder2; - mpz_t temp; - mp_size_t dividend_size; - mp_limb_t divisor; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (dividend); - mpz_init (quotient); - mpz_init (remainder); - mpz_init (quotient2); - mpz_init (remainder2); - mpz_init (temp); - - for (i = 0; i < reps; i++) - { - dividend_size = urandom () % SIZE - SIZE/2; - mpz_random2 (dividend, dividend_size); - - divisor = urandom (); - if (divisor == 0) - continue; - - mpz_fdiv_qr_ui (quotient, remainder, dividend, divisor); - mpz_fdiv_q_ui (quotient2, dividend, divisor); - mpz_fdiv_r_ui (remainder2, dividend, divisor); - - /* First determine that the quotients and remainders computed - with different functions are equal. */ - if (mpz_cmp (quotient, quotient2) != 0) - dump_abort (dividend, divisor); - if (mpz_cmp (remainder, remainder2) != 0) - dump_abort (dividend, divisor); - - /* Check if the sign of the quotient is correct. */ - if (mpz_cmp_ui (quotient, 0) != 0) - if ((mpz_cmp_ui (quotient, 0) < 0) - != (mpz_cmp_ui (dividend, 0) < 0)) - dump_abort (dividend, divisor); - - /* Check if the remainder has the same sign as the divisor - (quotient rounded towards minus infinity). */ - if (mpz_cmp_ui (remainder, 0) != 0) - if (mpz_cmp_ui (remainder, 0) < 0) - dump_abort (dividend, divisor); - - mpz_mul_ui (temp, quotient, divisor); - mpz_add (temp, temp, remainder); - if (mpz_cmp (temp, dividend) != 0) - dump_abort (dividend, divisor); - - mpz_abs (remainder, remainder); - if (mpz_cmp_ui (remainder, divisor) >= 0) - dump_abort (dividend, divisor); - } - - exit (0); -} - -dump_abort (dividend, divisor) - mpz_t dividend; - mp_limb_t divisor; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "dividend = "); debug_mp (dividend, -16); - fprintf (stderr, "divisor = %lX\n", divisor); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-gcd.c b/gmp/mpz/tests/t-gcd.c deleted file mode 100755 index 0c0104e..0000000 --- a/gmp/mpz/tests/t-gcd.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Test mpz_gcd, mpz_gcdext, mpz_mul, mpz_tdiv_r, mpz_add, mpz_cmp, - mpz_cmp_ui, mpz_init_set, mpz_set, mpz_clear. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 128 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t op1, op2, x; - mpz_t gcd, gcd2, s, t; - mpz_t temp1, temp2; - mp_size_t op1_size, op2_size, x_size; - int i; - int reps = 2000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (op1); - mpz_init (op2); - mpz_init (x); - mpz_init (gcd); - mpz_init (gcd2); - mpz_init (temp1); - mpz_init (temp2); - mpz_init (s); - mpz_init (t); - - for (i = 0; i < reps; i++) - { - op1_size = urandom () % SIZE - SIZE/2; - op2_size = urandom () % SIZE - SIZE/2; - x_size = urandom () % SIZE/2; - - mpz_random2 (op1, op1_size); - mpz_random2 (op2, op2_size); - mpz_random2 (x, x_size); - mpz_mul (op1, op1, x); - mpz_mul (op2, op2, x); - - mpz_gcd (gcd, op1, op2); - /* We know GCD will be at least X, since we multiplied in that factor. */ - if (mpz_cmp (gcd, x) < 0 && mpz_sgn (op1) != 0 && mpz_sgn (op2) != 0) - dump_abort (op1, op2); - - mpz_gcdext (gcd2, s, t, op1, op2); - if (mpz_cmp (gcd, gcd2)) - dump_abort (op1, op2); - - mpz_gcdext (gcd2, s, NULL, op1, op2); - if (mpz_cmp (gcd, gcd2)) - dump_abort (op1, op2); - - mpz_mul (temp1, s, op1); - mpz_mul (temp2, t, op2); - mpz_add (gcd2, temp1, temp2); - if (mpz_cmp (gcd, gcd2)) - dump_abort (op1, op2); - } - - exit (0); -} - -dump_abort (op1, op2) - mpz_t op1, op2; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "op1 = "); debug_mp (op1, -16); - fprintf (stderr, "op2 = "); debug_mp (op2, -16); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-jac.c b/gmp/mpz/tests/t-jac.c deleted file mode 100755 index 9b9c2e2..0000000 --- a/gmp/mpz/tests/t-jac.c +++ /dev/null @@ -1,652 +0,0 @@ -/* Exercise mpz_*_kronecker_*() and mpz_jacobi() functions. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - - -/* With no arguments the various Kronecker/Jacobi symbol routines are - checked against some test data and a lot of derived data. - - To check the test data against PARI-GP, run - - t-jac -p | gp -q - - It takes a while because the output from "t-jac -p" is big. - - - Enhancements: - - More big test cases than those given by check_squares_zi would be good. */ - - -#include -#include "gmp.h" -#include "gmp-impl.h" - - -int option_pari = 0; - - -unsigned long -mpz_mod4 (mpz_srcptr z) -{ - mpz_t m; - unsigned long ret; - - mpz_init (m); - mpz_fdiv_r_2exp (m, z, 2); - ret = mpz_get_ui (m); - mpz_clear (m); - return ret; -} - -int -mpz_fits_ulimb_p (mpz_srcptr z) -{ - return (SIZ(z) == 1 || SIZ(z) == 0); -} - -mp_limb_t -mpz_get_ulimb (mpz_srcptr z) -{ - if (SIZ(z) == 0) - return 0; - else - return PTR(z)[0]; -} - - -void -try_base (mp_limb_t a, mp_limb_t b, int answer) -{ - int got; - - if ((b & 1) == 0 || b == 1 || a > b) - return; - - got = mpn_jacobi_base (a, b, 0); - if (got != answer) - { - printf ("mpn_jacobi_base (%lu, %lu) is %d should be %d\n", - a, b, got, answer); - exit (1); - } -} - - -void -try_zi_ui (mpz_srcptr a, unsigned long b, int answer) -{ - int got; - - got = mpz_kronecker_ui (a, b); - if (got != answer) - { - printf ("mpz_kronecker_ui ("); - mpz_out_str (stdout, 10, a); - printf (", %lu) is %d should be %d\n", b, got, answer); - exit (1); - } -} - - -void -try_zi_si (mpz_srcptr a, long b, int answer) -{ - int got; - - got = mpz_kronecker_si (a, b); - if (got != answer) - { - printf ("mpz_kronecker_si ("); - mpz_out_str (stdout, 10, a); - printf (", %ld) is %d should be %d\n", b, got, answer); - exit (1); - } -} - - -void -try_ui_zi (unsigned long a, mpz_srcptr b, int answer) -{ - int got; - - got = mpz_ui_kronecker (a, b); - if (got != answer) - { - printf ("mpz_ui_kronecker (%lu, ", a); - mpz_out_str (stdout, 10, b); - printf (") is %d should be %d\n", got, answer); - exit (1); - } -} - - -void -try_si_zi (int a, mpz_srcptr b, int answer) -{ - int got; - - got = mpz_si_kronecker (a, b); - if (got != answer) - { - printf ("mpz_si_kronecker (%d, ", a); - mpz_out_str (stdout, 10, b); - printf (") is %d should be %d\n", got, answer); - exit (1); - } -} - - -void -try_zi_zi (mpz_srcptr a, mpz_srcptr b, int answer) -{ - int got; - - /* gmp 2.0.2 mpz_jacobi() doesn't handle negative or even b */ - if (mpz_sgn (b) <= 0 || mpz_even_p (b)) - return; - - got = mpz_jacobi (a, b); - if (got != answer) - { - printf ("mpz_jacobi ("); - mpz_out_str (stdout, 10, a); - printf (", "); - mpz_out_str (stdout, 10, b); - printf (") is %d should be %d\n", got, answer); - exit (1); - } -} - - -void -try_pari (mpz_srcptr a, mpz_srcptr b, int answer) -{ - printf ("try("); - mpz_out_str (stdout, 10, a); - printf (","); - mpz_out_str (stdout, 10, b); - printf (",%d)\n", answer); -} - - -void -try_each (mpz_srcptr a, mpz_srcptr b, int answer) -{ - if (option_pari) - { - try_pari (a, b, answer); - return; - } - - if (mpz_fits_ulimb_p (a) && mpz_fits_ulimb_p (b)) - try_base (mpz_get_ulimb (a), mpz_get_ulimb (b), answer); - - if (mpz_fits_ulong_p (b)) - try_zi_ui (a, mpz_get_ui (b), answer); - - if (mpz_fits_slong_p (b)) - try_zi_si (a, mpz_get_si (b), answer); - - if (mpz_fits_ulong_p (a)) - try_ui_zi (mpz_get_ui (a), b, answer); - - if (mpz_fits_sint_p (a)) - try_si_zi (mpz_get_si (a), b, answer); - - try_zi_zi (a, b, answer); -} - - -/* Try (a/b) and (a/-b). */ -void -try_pn (mpz_srcptr a, mpz_srcptr b_orig, int answer) -{ - mpz_t b; - - mpz_init_set (b, b_orig); - try_each (a, b, answer); - - mpz_neg (b, b); - if (mpz_sgn (a) < 0) - answer = -answer; - - try_each (a, b, answer); - - mpz_clear (b); -} - - -/* Try (a+k*p/b) for various k, using the fact (a/b) is periodic in a with - period p. For b>0, p=b if b!=2mod4 or p=4*b if b==2mod4. */ - -void -try_periodic_num (mpz_srcptr a_orig, mpz_srcptr b, int answer) -{ - mpz_t a, a_period; - int i; - - if (mpz_sgn (b) <= 0) - return; - - mpz_init_set (a, a_orig); - mpz_init_set (a_period, b); - if (mpz_mod4 (b) == 2) - mpz_mul_ui (a_period, a_period, 4); - - /* don't bother with these tests if they're only going to produce - even/even */ - if (mpz_even_p (a) && mpz_even_p (b) && mpz_even_p (a_period)) - goto done; - - for (i = 0; i < 10; i++) - { - mpz_add (a, a, a_period); - try_pn (a, b, answer); - } - - mpz_set (a, a_orig); - for (i = 0; i < 10; i++) - { - mpz_sub (a, a, a_period); - try_pn (a, b, answer); - } - - done: - mpz_clear (a); - mpz_clear (a_period); -} - - -/* Try (a/b+k*p) for various k, using the fact (a/b) is periodic in b of - period p. - - period p - a==0,1mod4 a - a==2mod4 4*a - a==3mod4 and b odd 4*a - a==3mod4 and b even 8*a - - In Henri Cohen's book the period is given as 4*a for all a==2,3mod4, but - a counterexample would seem to be (3/2)=-1 which with (3/14)=+1 doesn't - have period 4*a (but rather 8*a with (3/26)=-1). Maybe the plain 4*a is - to be read as applying to a plain Jacobi symbol with b odd, rather than - the Kronecker extension to b even. */ - -void -try_periodic_den (mpz_srcptr a, mpz_srcptr b_orig, int answer) -{ - mpz_t b, b_period; - int i; - - if (mpz_sgn (a) == 0 || mpz_sgn (b_orig) == 0) - return; - - mpz_init_set (b, b_orig); - - mpz_init_set (b_period, a); - if (mpz_mod4 (a) == 3 && mpz_even_p (b)) - mpz_mul_ui (b_period, b_period, 8); - else if (mpz_mod4 (a) >= 2) - mpz_mul_ui (b_period, b_period, 4); - - /* don't bother with these tests if they're only going to produce - even/even */ - if (mpz_even_p (a) && mpz_even_p (b) && mpz_even_p (b_period)) - goto done; - - for (i = 0; i < 10; i++) - { - mpz_add (b, b, b_period); - try_pn (a, b, answer); - } - - mpz_set (b, b_orig); - for (i = 0; i < 10; i++) - { - mpz_sub (b, b, b_period); - try_pn (a, b, answer); - } - - done: - mpz_clear (b); - mpz_clear (b_period); -} - - -/* Try (a/b*2^k) for various k. If it happens mpz_ui_kronecker() gets (a/2) - wrong it will show up as wrong answers demanded. */ -void -try_2den (mpz_srcptr a, mpz_srcptr b_orig, int answer) -{ - mpz_t b; - int i; - int answer_two; - - /* don't bother when b==0 */ - if (mpz_sgn (b_orig) == 0) - return; - - mpz_init_set (b, b_orig); - answer_two = mpz_kronecker_ui (a, 2); - - for (i = 0; i < 3 * BITS_PER_MP_LIMB; i++) - { - answer *= answer_two; - mpz_mul_2exp (b, b, 1); - try_pn (a, b, answer); - } - - mpz_clear (b); -} - - -/* Try (a*2^k/b) for various k. If it happens mpz_ui_kronecker() gets (2/b) - wrong it will show up as wrong answers demanded. */ -void -try_2num (mpz_srcptr a_orig, mpz_srcptr b, int answer) -{ - mpz_t a; - int i; - int answer_twos; - - /* don't bother when a==0 */ - if (mpz_sgn (a_orig) == 0) - return; - - mpz_init_set (a, a_orig); - answer_twos = mpz_ui_kronecker (2, b); - - for (i = 0; i < 3 * BITS_PER_MP_LIMB; i++) - { - answer *= answer_twos; - mpz_mul_2exp (a, a, 1); - try_pn (a, b, answer); - } - - mpz_clear (a); -} - - -/* The try_2num() and try_2den() routines don't in turn call - try_periodic_num() and try_periodic_den() because it hugely increases the - number of tests performed, without obviously increasing coverage. - - Useful extra derived cases can be added here. */ - -void -try_all (mpz_t a, mpz_t b, int answer) -{ - try_pn (a, b, answer); - try_periodic_num (a, b, answer); - try_periodic_den (a, b, answer); - try_2num (a, b, answer); - try_2den (a, b, answer); -} - - -void -check_data (void) -{ - static const struct { - const char *a; - const char *b; - int answer; - - } data[] = { - - /* Note that the various derived checks in try_all() reduce the cases - that need to be given here. */ - - /* some zeros */ - { "0", "0", 0 }, - { "0", "2", 0 }, - { "0", "6", 0 }, - { "5", "0", 0 }, - { "24", "60", 0 }, - - /* (a/1) = 1, any a - In particular note (0/1)=1 so that (a/b)=(a mod b/b). */ - { "0", "1", 1 }, - { "1", "1", 1 }, - { "2", "1", 1 }, - { "3", "1", 1 }, - { "4", "1", 1 }, - { "5", "1", 1 }, - - /* (0/b) = 0, b != 1 */ - { "0", "3", 0 }, - { "0", "5", 0 }, - { "0", "7", 0 }, - { "0", "9", 0 }, - { "0", "11", 0 }, - { "0", "13", 0 }, - { "0", "15", 0 }, - - /* (1/b) = 1 */ - { "1", "1", 1 }, - { "1", "3", 1 }, - { "1", "5", 1 }, - { "1", "7", 1 }, - { "1", "9", 1 }, - { "1", "11", 1 }, - - /* (-1/b) = (-1)^((b-1)/2) which is -1 for b==3 mod 4 */ - { "-1", "1", 1 }, - { "-1", "3", -1 }, - { "-1", "5", 1 }, - { "-1", "7", -1 }, - { "-1", "9", 1 }, - { "-1", "11", -1 }, - { "-1", "13", 1 }, - { "-1", "15", -1 }, - { "-1", "17", 1 }, - { "-1", "19", -1 }, - - /* (2/b) = (-1)^((b^2-1)/8) which is -1 for b==3,5 mod 8. - try_2num() will exercise multiple powers of 2 in the numerator. */ - { "2", "1", 1 }, - { "2", "3", -1 }, - { "2", "5", -1 }, - { "2", "7", 1 }, - { "2", "9", 1 }, - { "2", "11", -1 }, - { "2", "13", -1 }, - { "2", "15", 1 }, - { "2", "17", 1 }, - - /* (-2/b) = (-1)^((b^2-1)/8)*(-1)^((b-1)/2) which is -1 for b==5,7mod8. - try_2num() will exercise multiple powers of 2 in the numerator, which - will test that the shift in mpz_si_kronecker() uses unsigned not - signed. */ - { "-2", "1", 1 }, - { "-2", "3", 1 }, - { "-2", "5", -1 }, - { "-2", "7", -1 }, - { "-2", "9", 1 }, - { "-2", "11", 1 }, - { "-2", "13", -1 }, - { "-2", "15", -1 }, - { "-2", "17", 1 }, - - /* (a/2)=(2/a). - try_2den() will exercise multiple powers of 2 in the denominator. */ - { "3", "2", -1 }, - { "5", "2", -1 }, - { "7", "2", 1 }, - { "9", "2", 1 }, - { "11", "2", -1 }, - - /* Harriet Griffin, "Elementary Theory of Numbers", page 155, various - examples. */ - { "2", "135", 1 }, - { "135", "19", -1 }, - { "2", "19", -1 }, - { "19", "135", 1 }, - { "173", "135", 1 }, - { "38", "135", 1 }, - { "135", "173", 1 }, - { "173", "5", -1 }, - { "3", "5", -1 }, - { "5", "173", -1 }, - { "173", "3", -1 }, - { "2", "3", -1 }, - { "3", "173", -1 }, - { "253", "21", 1 }, - { "1", "21", 1 }, - { "21", "253", 1 }, - { "21", "11", -1 }, - { "-1", "11", -1 }, - - /* Griffin page 147 */ - { "-1", "17", 1 }, - { "2", "17", 1 }, - { "-2", "17", 1 }, - { "-1", "89", 1 }, - { "2", "89", 1 }, - - /* Griffin page 148 */ - { "89", "11", 1 }, - { "1", "11", 1 }, - { "89", "3", -1 }, - { "2", "3", -1 }, - { "3", "89", -1 }, - { "11", "89", 1 }, - { "33", "89", -1 }, - - /* H. Davenport, "The Higher Arithmetic", page 65, the quadratic - residues and non-residues mod 19. */ - { "1", "19", 1 }, - { "4", "19", 1 }, - { "5", "19", 1 }, - { "6", "19", 1 }, - { "7", "19", 1 }, - { "9", "19", 1 }, - { "11", "19", 1 }, - { "16", "19", 1 }, - { "17", "19", 1 }, - { "2", "19", -1 }, - { "3", "19", -1 }, - { "8", "19", -1 }, - { "10", "19", -1 }, - { "12", "19", -1 }, - { "13", "19", -1 }, - { "14", "19", -1 }, - { "15", "19", -1 }, - { "18", "19", -1 }, - - /* Residues and non-residues mod 13 */ - { "0", "13", 0 }, - { "1", "13", 1 }, - { "2", "13", -1 }, - { "3", "13", 1 }, - { "4", "13", 1 }, - { "5", "13", -1 }, - { "6", "13", -1 }, - { "7", "13", -1 }, - { "8", "13", -1 }, - { "9", "13", 1 }, - { "10", "13", 1 }, - { "11", "13", -1 }, - { "12", "13", 1 }, - - /* various */ - { "5", "7", -1 }, - { "15", "17", 1 }, - { "67", "89", 1 }, - - }; - - int i, answer; - mpz_t a, b; - - mpz_init (a); - mpz_init (b); - - for (i = 0; i < numberof (data); i++) - { - mpz_set_str (a, data[i].a, 0); - mpz_set_str (b, data[i].b, 0); - - answer = data[i].answer; - try_all (a, b, data[i].answer); - } - - mpz_clear (a); - mpz_clear (b); -} - - -/* (a^2/b)=1 if gcd(a,b)=1, or (a^2/b)=0 if gcd(a,b)!=1. */ -void -check_squares_zi (void) -{ - mpz_t a, b, g; - int i, answer; - - mpz_init (a); - mpz_init (b); - mpz_init (g); - - for (i = 0; i < 200; i++) - { - mpz_random2 (a, rand() % 50); - mpz_random2 (b, rand() % 50); - mpz_mul (a, a, b); - - mpz_gcd (g, a, b); - if (mpz_cmp_ui (g, 1) == 0) - answer = 1; - else - answer = 0; - - try_all (a, b, answer); - } - - mpz_clear (a); - mpz_clear (b); - mpz_clear (g); -} - - -int -main (int argc, char *argv[]) -{ - if (argc >= 2 && strcmp (argv[1], "-p") == 0) - { - option_pari = 1; - - printf ("\ -try(a,b,answer) =\n\ -{\n\ - if (kronecker(a,b) != answer,\n\ - print(\"wrong at \", a, \",\", b,\n\ - \" expected \", answer,\n\ - \" pari says \", kronecker(a,b)))\n\ -}\n"); - } - - check_data (); - check_squares_zi (); - - exit (0); -} diff --git a/gmp/mpz/tests/t-misc.c b/gmp/mpz/tests/t-misc.c deleted file mode 100755 index f67acc2..0000000 --- a/gmp/mpz/tests/t-misc.c +++ /dev/null @@ -1,205 +0,0 @@ -/* Exercise various mpz functions. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include "gmp.h" -#include "gmp-impl.h" - -#define SGN(x) ((x) < 0 ? -1 : (x) == 0 ? 0 : 1) - - -void -oddeven (void) -{ - static const struct { - const char *n; - int odd, even; - } data[] = { - { "0", 0, 1 }, - { "1", 1, 0 }, - { "2", 0, 1 }, - { "3", 1, 0 }, - { "4", 0, 1 }, - - { "-4", 0, 1 }, - { "-3", 1, 0 }, - { "-2", 0, 1 }, - { "-1", 1, 0 }, - - { "0x1000000000000000000000000000000000000000000000000000", 0, 1 }, - { "0x1000000000000000000000000000000000000000000000000001", 1, 0 }, - { "0x1000000000000000000000000000000000000000000000000002", 0, 1 }, - { "0x1000000000000000000000000000000000000000000000000003", 1, 0 }, - - { "-0x1000000000000000000000000000000000000000000000000004", 0, 1 }, - { "-0x1000000000000000000000000000000000000000000000000003", 1, 0 }, - { "-0x1000000000000000000000000000000000000000000000000002", 0, 1 }, - { "-0x1000000000000000000000000000000000000000000000000001", 1, 0 }, - }; - - mpz_t n; - int i; - - mpz_init (n); - for (i = 0; i < numberof (data); i++) - { - mpz_set_str (n, data[i].n, 0); - - if ((mpz_odd_p (n) != 0) != data[i].odd) - { - printf ("mpz_odd_p wrong on data[%d]\n", i); - abort(); - } - - if ((mpz_even_p (n) != 0) != data[i].even) - { - printf ("mpz_even_p wrong on data[%d]\n", i); - abort(); - } - } - - mpz_clear (n); -} - - -void -check_mpz_set_si (void) -{ - static const struct { - long n; - mp_size_t want_size; - mp_limb_t want_limb; - } data[] = { - - { 0L, 0 }, - { 1L, 1, 1 }, - { -1L, -1, 1 }, - - { LONG_MAX, 1, LONG_MAX }, - { -LONG_MAX, -1, LONG_MAX }, - - { LONG_HIGHBIT, -1, ULONG_HIGHBIT }, - }; - - mpz_t n; - int i; - - mpz_init (n); - for (i = 0; i < numberof (data); i++) - { - mpz_init (n); - mpz_set_si (n, data[i].n); - if (n->_mp_size != data[i].want_size - || (n->_mp_size != 0 && n->_mp_d[0] != data[i].want_limb)) - { - printf ("mpz_set_si wrong on data[%d]\n", i); - abort(); - } - mpz_clear (n); - - mpz_init_set_si (n, data[i].n); - if (n->_mp_size != data[i].want_size - || (n->_mp_size != 0 && n->_mp_d[0] != data[i].want_limb)) - { - printf ("mpz_init_set_si wrong on data[%d]\n", i); - abort(); - } - mpz_clear (n); - } -} - - -void -check_mpz_cmp_si (void) -{ - static const struct { - const char *a, *b; - int want; - } data[] = { - { "0", "1", -1 }, - { "0", "0", 0 }, - { "0", "-1", 1 }, - - { "1", "1", 0 }, - { "1", "0", 1 }, - { "1", "-1", 1 }, - - { "-1", "1", -1 }, - { "-1", "0", -1 }, - { "-1", "-1", 0 }, - - { "0", "-0x80000000", 1 }, - { "0x80000000", "-0x80000000", 1 }, - { "0x80000001", "-0x80000000", 1 }, - { "-0x80000000", "-0x80000000", 0 }, - { "-0x80000001", "-0x80000000", -1 }, - - { "0", "-0x8000000000000000", 1 }, - { "0x8000000000000000", "-0x8000000000000000", 1 }, - { "0x8000000000000001", "-0x8000000000000000", 1 }, - { "-0x8000000000000000", "-0x8000000000000000", 0 }, - { "-0x8000000000000001", "-0x8000000000000000", -1 }, - }; - - mpz_t a, bz; - long b; - int got; - int i; - - mpz_init (a); - mpz_init (bz); - for (i = 0; i < numberof (data); i++) - { - mpz_set_str (a, data[i].a, 0); - mpz_set_str (bz, data[i].b, 0); - - if (mpz_fits_slong_p (bz)) - { - b = mpz_get_si (bz); - got = mpz_cmp_si (a, b); - if (SGN (got) != data[i].want) - { - printf ("mpz_cmp_si wrong on data[%d]\n", i); - printf (" a="); mpz_out_str (stdout, 10, a); printf ("\n"); - printf (" b=%ld\n", b); - printf (" got=%d\n", got); - printf (" want=%d\n", data[i].want); - abort(); - } - } - } - - mpz_clear (a); - mpz_clear (bz); -} - - -int -main (void) -{ - oddeven (); - check_mpz_set_si (); - check_mpz_cmp_si (); - - exit (0); -} diff --git a/gmp/mpz/tests/t-mul.c b/gmp/mpz/tests/t-mul.c deleted file mode 100755 index 4cd1224..0000000 --- a/gmp/mpz/tests/t-mul.c +++ /dev/null @@ -1,278 +0,0 @@ -/* Test mpz_add, mpz_cmp, mpz_cmp_ui, mpz_divmod, mpz_mul. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" -#include "urandom.h" - -void debug_mp (); -mp_size_t _mpn_mul_classic (); -void mpz_refmul (); - -#ifndef SIZE -#define SIZE 2 * TOOM3_MUL_THRESHOLD -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t multiplier, multiplicand; - mpz_t product, ref_product; - mpz_t quotient, remainder; - mp_size_t multiplier_size, multiplicand_size; - int i; - int reps = 2000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (multiplier); - mpz_init (multiplicand); - mpz_init (product); - mpz_init (ref_product); - mpz_init (quotient); - mpz_init (remainder); - - for (i = 0; i < reps; i++) - { - multiplier_size = urandom () % 2 * SIZE - SIZE; - multiplicand_size = urandom () % 2 * SIZE - SIZE; - - mpz_random2 (multiplier, multiplier_size); - mpz_random2 (multiplicand, multiplicand_size); - - mpz_mul (product, multiplier, multiplicand); - mpz_refmul (ref_product, multiplier, multiplicand); - if (mpz_cmp_ui (multiplicand, 0) != 0) - mpz_divmod (quotient, remainder, product, multiplicand); - - if (mpz_cmp (product, ref_product)) - dump_abort ("incorrect plain product", - multiplier, multiplicand, product, ref_product); - - if (mpz_cmp_ui (multiplicand, 0) != 0) - if (mpz_cmp_ui (remainder, 0) || mpz_cmp (quotient, multiplier)) - { - debug_mp (quotient, -16); - debug_mp (remainder, -16); - dump_abort ("incorrect quotient or remainder", - multiplier, multiplicand, product, ref_product); - } - - /* Test squaring. */ - mpz_mul (product, multiplier, multiplier); - mpz_refmul (ref_product, multiplier, multiplier); - - if (mpz_cmp (product, ref_product)) - dump_abort ("incorrect square product", - multiplier, multiplier, product, ref_product); - } - - exit (0); -} - -void -mpz_refmul (w, u, v) - mpz_t w; - const mpz_t u; - const mpz_t v; -{ - mp_size_t usize = u->_mp_size; - mp_size_t vsize = v->_mp_size; - mp_size_t wsize; - mp_size_t sign_product; - mp_ptr up, vp; - mp_ptr wp; - mp_ptr free_me = NULL; - size_t free_me_size; - TMP_DECL (marker); - - TMP_MARK (marker); - sign_product = usize ^ vsize; - usize = ABS (usize); - vsize = ABS (vsize); - - if (usize < vsize) - { - /* Swap U and V. */ - {const __mpz_struct *t = u; u = v; v = t;} - {mp_size_t t = usize; usize = vsize; vsize = t;} - } - - up = u->_mp_d; - vp = v->_mp_d; - wp = w->_mp_d; - - /* Ensure W has space enough to store the result. */ - wsize = usize + vsize; - if (w->_mp_alloc < wsize) - { - if (wp == up || wp == vp) - { - free_me = wp; - free_me_size = w->_mp_alloc; - } - else - (*_mp_free_func) (wp, w->_mp_alloc * BYTES_PER_MP_LIMB); - - w->_mp_alloc = wsize; - wp = (mp_ptr) (*_mp_allocate_func) (wsize * BYTES_PER_MP_LIMB); - w->_mp_d = wp; - } - else - { - /* Make U and V not overlap with W. */ - if (wp == up) - { - /* W and U are identical. Allocate temporary space for U. */ - up = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB); - /* Is V identical too? Keep it identical with U. */ - if (wp == vp) - vp = up; - /* Copy to the temporary space. */ - MPN_COPY (up, wp, usize); - } - else if (wp == vp) - { - /* W and V are identical. Allocate temporary space for V. */ - vp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB); - /* Copy to the temporary space. */ - MPN_COPY (vp, wp, vsize); - } - } - - wsize = _mpn_mul_classic (wp, up, usize, vp, vsize); - w->_mp_size = sign_product < 0 ? -wsize : wsize; - if (free_me != NULL) - (*_mp_free_func) (free_me, free_me_size * BYTES_PER_MP_LIMB); - - TMP_FREE (marker); -} - -mp_size_t -_mpn_mul_classic (prodp, up, usize, vp, vsize) - mp_ptr prodp; - mp_srcptr up; - mp_size_t usize; - mp_srcptr vp; - mp_size_t vsize; -{ - mp_size_t i, j; - mp_limb_t prod_low, prod_high; - mp_limb_t cy_dig; - mp_limb_t v_limb, c; - - if (vsize == 0) - return 0; - - /* Offset UP and PRODP so that the inner loop can be faster. */ - up += usize; - prodp += usize; - - /* Multiply by the first limb in V separately, as the result can - be stored (not added) to PROD. We also avoid a loop for zeroing. */ - v_limb = vp[0]; - cy_dig = 0; - j = -usize; - do - { - umul_ppmm (prod_high, prod_low, up[j], v_limb); - add_ssaaaa (cy_dig, prodp[j], prod_high, prod_low, 0, cy_dig); - j++; - } - while (j < 0); - - prodp[j] = cy_dig; - prodp++; - - /* For each iteration in the outer loop, multiply one limb from - U with one limb from V, and add it to PROD. */ - for (i = 1; i < vsize; i++) - { - v_limb = vp[i]; - cy_dig = 0; - j = -usize; - - /* Inner loops. Simulate the carry flag by jumping between - these loops. The first is used when there was no carry - in the previois iteration; the second when there was carry. */ - - do - { - umul_ppmm (prod_high, prod_low, up[j], v_limb); - add_ssaaaa (cy_dig, prod_low, prod_high, prod_low, 0, cy_dig); - c = prodp[j]; - prod_low += c; - prodp[j] = prod_low; - if (prod_low < c) - goto cy_loop; - ncy_loop: - j++; - } - while (j < 0); - - prodp[j] = cy_dig; - prodp++; - continue; - - do - { - umul_ppmm (prod_high, prod_low, up[j], v_limb); - add_ssaaaa (cy_dig, prod_low, prod_high, prod_low, 0, cy_dig); - c = prodp[j]; - prod_low += c + 1; - prodp[j] = prod_low; - if (prod_low > c) - goto ncy_loop; - cy_loop: - j++; - } - while (j < 0); - - cy_dig += 1; - prodp[j] = cy_dig; - prodp++; - } - - return usize + vsize - (cy_dig == 0); -} - -dump_abort (s, multiplier, multiplicand, product, ref_product) - char *s; - mpz_t multiplier, multiplicand, product, ref_product; -{ - fprintf (stderr, "ERROR: %s\n", s); - fprintf (stderr, "multiplier = "); debug_mp (multiplier, -16); - fprintf (stderr, "multiplicand = "); debug_mp (multiplicand, -16); - fprintf (stderr, "product = "); debug_mp (product, -16); - fprintf (stderr, "ref_product = "); debug_mp (ref_product, -16); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-pow_ui.c b/gmp/mpz/tests/t-pow_ui.c deleted file mode 100755 index 4bfde0b..0000000 --- a/gmp/mpz/tests/t-pow_ui.c +++ /dev/null @@ -1,122 +0,0 @@ -/* Test mpz_pow_ui and mpz_ui_pow_ui. - -Copyright (C) 1997, 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); -void ref_mpz_pow_ui (); - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t base; - mpz_t result, ref_result; - mp_size_t base_size; - unsigned long int exp; - int i; - int reps = 50000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (base); - mpz_init (result); - mpz_init (ref_result); - - for (i = 0; i < reps; i++) - { - base_size = urandom () % 8 - 4; - exp = urandom () % 16; - - mpz_random2 (base, base_size); - - ref_mpz_pow_ui (ref_result, base, exp); - - mpz_pow_ui (result, base, exp); - if (mpz_cmp (result, ref_result)) - { - fprintf (stderr, "ERROR (mpz_pow_ui):\n"); - debug_mp (" base = ", base, -16); - fprintf (stderr, " exp = %lu (0x%lX)\n", exp, exp); - debug_mp (" result = ", result, -16); - debug_mp ("ref_result = ", ref_result, -16); - abort (); - } - - if (mpz_cmp_ui (base, 0L) >= 0 - && mpz_cmp_ui (base, ~(unsigned long int) 0) <= 0) - { - mpz_ui_pow_ui (result, mpz_get_ui (base), exp); - if (mpz_cmp (result, ref_result)) - { - fprintf (stderr, "ERROR (mpz_ui_pow_ui):\n"); - debug_mp (" base = ", base, -16); - fprintf (stderr, " exp = %lu (0x%lX)\n", exp, exp); - debug_mp (" result = ", result, -16); - debug_mp ("ref_result = ", ref_result, -16); - abort (); - } - } - } - - exit (0); -} - -void -ref_mpz_pow_ui (w, u, e) - mpz_t w; - const mpz_t u; - unsigned long int e; -{ - mpz_t s, t; - unsigned long int i; - - mpz_init_set_ui (t, 1); - mpz_init_set (s, u); - - if ((e & 1) != 0) - mpz_mul (t, t, s); - - for (i = 2; i <= e; i <<= 1) - { - mpz_mul (s, s, s); - if ((i & e) != 0) - mpz_mul (t, t, s); - } - - mpz_set (w, t); - mpz_clear (s); - mpz_clear (t); -} - -void -debug_mp (str, x, base) - char *str; - mpz_t x; - int base; -{ - fprintf (stderr, "%s", str); - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-powm.c b/gmp/mpz/tests/t-powm.c deleted file mode 100755 index 3b36c5f..0000000 --- a/gmp/mpz/tests/t-powm.c +++ /dev/null @@ -1,134 +0,0 @@ -/* Test mpz_powm, mpz_mul. mpz_mod, mpz_mod_ui, mpz_div_ui. - -Copyright (C) 1991, 1993, 1994, 1996, 1999, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 50 -#endif - -#ifndef EXP_SIZE -#define EXP_SIZE 2 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t base, exp, mod; - mpz_t r1, r2, t1, exp2, base2; - mp_size_t base_size, exp_size, mod_size; - int i; - int reps = 2500; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (base); - mpz_init (exp); - mpz_init (mod); - mpz_init (r1); - mpz_init (r2); - mpz_init (t1); - mpz_init (exp2); - mpz_init (base2); - - for (i = 0; i < reps; i++) - { - do - { - base_size = urandom () % 2 * SIZE - SIZE; - mpz_random2 (base, base_size); - - exp_size = urandom () % (EXP_SIZE + 1); - mpz_random2 (exp, exp_size); - - /* Loop until mathematically well-defined. */ - } - while (mpz_cmp_ui (base, 0) == 0 && mpz_cmp_ui (exp, 0) == 0); - - do - { - mod_size = urandom () % SIZE /* - SIZE/2 */; - mpz_random2 (mod, mod_size); - } - while (mpz_cmp_ui (mod, 0) == 0); - -#if 0 - putc ('\n', stderr); - debug_mp (base, -16); - debug_mp (exp, -16); - debug_mp (mod, -16); -#endif - - mpz_powm (r1, base, exp, mod); - - mpz_set_ui (r2, 1); - mpz_set (base2, base); - mpz_set (exp2, exp); - - mpz_mod (r2, r2, mod); /* needed when exp==0 and mod==1 */ - while (mpz_cmp_ui (exp2, 0) != 0) - { - mpz_mod_ui (t1, exp2, 2); - if (mpz_cmp_ui (t1, 0) != 0) - { - mpz_mul (r2, r2, base2); - mpz_mod (r2, r2, mod); - } - mpz_mul (base2, base2, base2); - mpz_mod (base2, base2, mod); - mpz_div_ui (exp2, exp2, 2); - } - -#if 0 - debug_mp (r1, -16); - debug_mp (r2, -16); -#endif - - if (mpz_cmp (r1, r2) != 0) - abort (); - } - - exit (0); -} - -dump_abort (dividend, divisor) - MP_INT *dividend, *divisor; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "dividend = "); debug_mp (dividend, -16); - fprintf (stderr, "divisor = "); debug_mp (divisor, -16); - abort(); -} - -void -debug_mp (x, base) - MP_INT *x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-powm_ui.c b/gmp/mpz/tests/t-powm_ui.c deleted file mode 100755 index dd98828..0000000 --- a/gmp/mpz/tests/t-powm_ui.c +++ /dev/null @@ -1,121 +0,0 @@ -/* Test mpz_powm_ui, mpz_mul. mpz_mod, mpz_mod_ui, mpz_div_ui. - -Copyright (C) 1991, 1993, 1994, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 8 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t base, mod; - mpz_t r1, r2, base2; - mp_size_t base_size, mod_size; - mp_limb_t exp; - unsigned long int exp2; - int i; - int reps = 10000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (base); - mpz_init (mod); - mpz_init (r1); - mpz_init (r2); - mpz_init (base2); - - for (i = 0; i < reps; i++) - { - base_size = urandom () % SIZE /* - SIZE/2 */; - mpz_random2 (base, base_size); - - mpn_random2 (&exp, 1); - - mod_size = urandom () % SIZE /* - SIZE/2 */; - mpz_random2 (mod, mod_size); - if (mpz_cmp_ui (mod, 0) == 0) - continue; - - /* This is mathematically undefined. */ - if (mpz_cmp_ui (base, 0) == 0 && exp == 0) - continue; - -#if 0 - putc ('\n', stderr); - debug_mp (base, -16); - debug_mp (mod, -16); -#endif - - mpz_powm_ui (r1, base, (unsigned long int) exp, mod); - - mpz_set_ui (r2, 1); - mpz_set (base2, base); - exp2 = exp; - - mpz_mod (r2, r2, mod); /* needed when exp==0 and mod==1 */ - while (exp2 != 0) - { - if (exp2 % 2 != 0) - { - mpz_mul (r2, r2, base2); - mpz_mod (r2, r2, mod); - } - mpz_mul (base2, base2, base2); - mpz_mod (base2, base2, mod); - exp2 = exp2 / 2; - } - -#if 0 - debug_mp (r1, -16); - debug_mp (r2, -16); -#endif - - if (mpz_cmp (r1, r2) != 0) - abort (); - } - - exit (0); -} - -dump_abort (dividend, divisor) - MP_INT *dividend, *divisor; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "dividend = "); debug_mp (dividend, -16); - fprintf (stderr, "divisor = "); debug_mp (divisor, -16); - abort(); -} - -void -debug_mp (x, base) - MP_INT *x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-root.c b/gmp/mpz/tests/t-root.c deleted file mode 100755 index 8ed42c9..0000000 --- a/gmp/mpz/tests/t-root.c +++ /dev/null @@ -1,114 +0,0 @@ -/* Test mpz_add, mpz_add_ui, mpz_cmp, mpz_cmp, mpz_mul, mpz_sqrtrem. - -Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 100 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t x2; - mpz_t x; - mpz_t temp, temp2; - mp_size_t x2_size; - int i; - int reps = 10000; - unsigned long nth; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (x2); - mpz_init (x); - mpz_init (temp); - mpz_init (temp2); - - for (i = 0; i < reps; i++) - { - x2_size = urandom () % SIZE + 1; - mpz_random2 (x2, x2_size); - nth = urandom () % mpz_sizeinbase (x2, 2) + 1; - if ((urandom() & 1) == 0) - { - /* With 50% probability, set x2 just below a perfect power. */ - mpz_root (x, x2, nth); - mpz_pow_ui (x2, x, nth); - if (mpz_sgn (x2) != 0) - mpz_sub_ui (x2, x2, 1L); - } - - mpz_root (x, x2, nth); - mpz_pow_ui (temp, x, nth); - - /* Is power of result > argument? */ - if (mpz_cmp (temp, x2) > 0) - { - fprintf (stderr, "ERROR after test %d\n", i); - debug_mp (x2, 10); - debug_mp (x, 10); - fprintf (stderr, "nth: %lu\n", nth); - abort (); - } - - if (nth > 1 && mpz_cmp_ui (temp, 1L) > 0 && ! mpz_perfect_power_p (temp)) - { - fprintf (stderr, "ERROR in mpz_perfect_power_p after test %d\n", i); - debug_mp (temp, 10); - debug_mp (x, 10); - fprintf (stderr, "nth: %lu\n", nth); - abort (); - } - - if (nth > 10000) - continue; /* skip too expensive test */ - - mpz_add_ui (temp2, x, 1L); - mpz_pow_ui (temp2, temp2, nth); - - /* Is square of (result + 1) <= argument? */ - if (mpz_cmp (temp2, x2) <= 0) - { - fprintf (stderr, "ERROR after test %d\n", i); - debug_mp (x2, 10); - debug_mp (x, 10); - fprintf (stderr, "nth: %lu\n", nth); - abort (); - } - } - - exit (0); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-sqrtrem.c b/gmp/mpz/tests/t-sqrtrem.c deleted file mode 100755 index 71960d8..0000000 --- a/gmp/mpz/tests/t-sqrtrem.c +++ /dev/null @@ -1,98 +0,0 @@ -/* Test mpz_add, mpz_add_ui, mpz_cmp, mpz_cmp, mpz_mul, mpz_sqrtrem. - -Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t x2; - mpz_t x, rem; - mpz_t temp, temp2; - mp_size_t x2_size; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (x2); - mpz_init (x); - mpz_init (rem); - mpz_init (temp); - mpz_init (temp2); - - for (i = 0; i < reps; i++) - { - x2_size = urandom () % SIZE; - - mpz_random2 (x2, x2_size); - - mpz_sqrtrem (x, rem, x2); - mpz_mul (temp, x, x); - - /* Is square of result > argument? */ - if (mpz_cmp (temp, x2) > 0) - dump_abort (x2, x, rem); - - mpz_add_ui (temp2, x, 1); - mpz_mul (temp2, temp2, temp2); - - /* Is square of (result + 1) <= argument? */ - if (mpz_cmp (temp2, x2) <= 0) - dump_abort (x2, x, rem); - - mpz_add (temp2, temp, rem); - - /* Is the remainder wrong? */ - if (mpz_cmp (x2, temp2) != 0) - dump_abort (x2, x, rem); - } - - exit (0); -} - -dump_abort (x2, x, rem) - mpz_t x2, x, rem; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "x2 = "); debug_mp (x2, -16); - fprintf (stderr, "x = "); debug_mp (x, -16); - fprintf (stderr, "remainder = "); debug_mp (rem, -16); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-tdiv.c b/gmp/mpz/tests/t-tdiv.c deleted file mode 100755 index ce874df..0000000 --- a/gmp/mpz/tests/t-tdiv.c +++ /dev/null @@ -1,118 +0,0 @@ -/* Test mpz_abs, mpz_add, mpz_cmp, mpz_cmp_ui, mpz_tdiv_qr, mpz_tdiv_q, - mpz_tdiv_r, mpz_mul. - -Copyright (C) 1991, 1993, 1994, 1996, 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 200 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t dividend, divisor; - mpz_t quotient, remainder; - mpz_t quotient2, remainder2; - mpz_t temp; - mp_size_t dividend_size, divisor_size; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (dividend); - mpz_init (divisor); - mpz_init (quotient); - mpz_init (remainder); - mpz_init (quotient2); - mpz_init (remainder2); - mpz_init (temp); - - for (i = 0; i < reps; i++) - { - dividend_size = urandom () % SIZE - SIZE/2; - mpz_random2 (dividend, dividend_size); - - divisor_size = urandom () % SIZE - SIZE/2; - mpz_random2 (divisor, divisor_size); - if (mpz_cmp_ui (divisor, 0) == 0) - continue; - - mpz_tdiv_qr (quotient, remainder, dividend, divisor); - mpz_tdiv_q (quotient2, dividend, divisor); - mpz_tdiv_r (remainder2, dividend, divisor); - - /* First determine that the quotients and remainders computed - with different functions are equal. */ - if (mpz_cmp (quotient, quotient2) != 0) - dump_abort (dividend, divisor); - if (mpz_cmp (remainder, remainder2) != 0) - dump_abort (dividend, divisor); - - /* Check if the sign of the quotient is correct. */ - if (mpz_cmp_ui (quotient, 0) != 0) - if ((mpz_cmp_ui (quotient, 0) < 0) - != ((mpz_cmp_ui (dividend, 0) ^ mpz_cmp_ui (divisor, 0)) < 0)) - dump_abort (dividend, divisor); - - /* Check if the remainder has the same sign as the dividend - (quotient rounded towards 0). */ - if (mpz_cmp_ui (remainder, 0) != 0) - if ((mpz_cmp_ui (remainder, 0) < 0) != (mpz_cmp_ui (dividend, 0) < 0)) - dump_abort (dividend, divisor); - - mpz_mul (temp, quotient, divisor); - mpz_add (temp, temp, remainder); - if (mpz_cmp (temp, dividend) != 0) - dump_abort (dividend, divisor); - - mpz_abs (temp, divisor); - mpz_abs (remainder, remainder); - if (mpz_cmp (remainder, temp) >= 0) - dump_abort (dividend, divisor); - } - - exit (0); -} - -dump_abort (dividend, divisor) - mpz_t dividend, divisor; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "dividend = "); debug_mp (dividend, -16); - fprintf (stderr, "divisor = "); debug_mp (divisor, -16); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tests/t-tdiv_ui.c b/gmp/mpz/tests/t-tdiv_ui.c deleted file mode 100755 index 960ebb8..0000000 --- a/gmp/mpz/tests/t-tdiv_ui.c +++ /dev/null @@ -1,117 +0,0 @@ -/* Test mpz_abs, mpz_add, mpz_cmp, mpz_cmp_ui, mpz_tdiv_qr_ui, mpz_tdiv_q_ui, - mpz_tdiv_r_ui, mpz_mul_ui. - -Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include -#include "gmp.h" -#include "gmp-impl.h" -#include "urandom.h" - -void debug_mp (); - -#ifndef SIZE -#define SIZE 16 -#endif - -main (argc, argv) - int argc; - char **argv; -{ - mpz_t dividend; - mpz_t quotient, remainder; - mpz_t quotient2, remainder2; - mpz_t temp; - mp_size_t dividend_size; - mp_limb_t divisor; - int i; - int reps = 100000; - - if (argc == 2) - reps = atoi (argv[1]); - - mpz_init (dividend); - mpz_init (quotient); - mpz_init (remainder); - mpz_init (quotient2); - mpz_init (remainder2); - mpz_init (temp); - - for (i = 0; i < reps; i++) - { - dividend_size = urandom () % SIZE - SIZE/2; - mpz_random2 (dividend, dividend_size); - - divisor = urandom (); - if (divisor == 0) - continue; - - mpz_tdiv_qr_ui (quotient, remainder, dividend, divisor); - mpz_tdiv_q_ui (quotient2, dividend, divisor); - mpz_tdiv_r_ui (remainder2, dividend, divisor); - - /* First determine that the quotients and remainders computed - with different functions are equal. */ - if (mpz_cmp (quotient, quotient2) != 0) - dump_abort (dividend, divisor); - if (mpz_cmp (remainder, remainder2) != 0) - dump_abort (dividend, divisor); - - /* Check if the sign of the quotient is correct. */ - if (mpz_cmp_ui (quotient, 0) != 0) - if ((mpz_cmp_ui (quotient, 0) < 0) - != (mpz_cmp_ui (dividend, 0) < 0)) - dump_abort (dividend, divisor); - - /* Check if the remainder has the same sign as the dividend - (quotient rounded towards 0). */ - if (mpz_cmp_ui (remainder, 0) != 0) - if ((mpz_cmp_ui (remainder, 0) < 0) != (mpz_cmp_ui (dividend, 0) < 0)) - dump_abort (dividend, divisor); - - mpz_mul_ui (temp, quotient, divisor); - mpz_add (temp, temp, remainder); - if (mpz_cmp (temp, dividend) != 0) - dump_abort (dividend, divisor); - - mpz_abs (remainder, remainder); - if (mpz_cmp_ui (remainder, divisor) >= 0) - dump_abort (dividend, divisor); - } - - exit (0); -} - -dump_abort (dividend, divisor) - mpz_t dividend; - mp_limb_t divisor; -{ - fprintf (stderr, "ERROR\n"); - fprintf (stderr, "dividend = "); debug_mp (dividend, -16); - fprintf (stderr, "divisor = %lX\n", divisor); - abort(); -} - -void -debug_mp (x, base) - mpz_t x; -{ - mpz_out_str (stderr, base, x); fputc ('\n', stderr); -} diff --git a/gmp/mpz/tstbit.c b/gmp/mpz/tstbit.c deleted file mode 100755 index b0a8b0b..0000000 --- a/gmp/mpz/tstbit.c +++ /dev/null @@ -1,70 +0,0 @@ -/* mpz_tstbit -- test a specified bit. Simulate 2's complement representation. - -Copyright (C) 1997 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -int -#if __STDC__ -mpz_tstbit (mpz_srcptr d, unsigned long int bit_index) -#else -mpz_tstbit (d, bit_index) - mpz_srcptr d; - unsigned long int bit_index; -#endif -{ - mp_size_t dsize = d->_mp_size; - mp_ptr dp = d->_mp_d; - mp_size_t limb_index; - - limb_index = bit_index / BITS_PER_MP_LIMB; - if (dsize >= 0) - { - if (limb_index < dsize) - return (dp[limb_index] >> (bit_index % BITS_PER_MP_LIMB)) & 1; - else - /* Testing a bit outside of a positive number. */ - return 0; - } - else - { - mp_size_t zero_bound; - - dsize = -dsize; - - /* Locate the least significant non-zero limb. */ - for (zero_bound = 0; dp[zero_bound] == 0; zero_bound++) - ; - - if (limb_index > zero_bound) - { - if (limb_index < dsize) - return (~dp[limb_index] >> (bit_index % BITS_PER_MP_LIMB)) & 1; - else - /* Testing a bit outside of a negative number. */ - return 1; - } - else if (limb_index == zero_bound) - return (-dp[limb_index] >> (bit_index % BITS_PER_MP_LIMB)) & 1; - else - return 0; - } -} diff --git a/gmp/mpz/ui_pow_ui.c b/gmp/mpz/ui_pow_ui.c deleted file mode 100755 index edd2dee..0000000 --- a/gmp/mpz/ui_pow_ui.c +++ /dev/null @@ -1,139 +0,0 @@ -/* mpz_ui_pow_ui(res, base, exp) -- Set RES to BASE**EXP. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - - -static void mpz_pow2 _PROTO ((mpz_ptr r, mp_limb_t blimb, unsigned long int e, mp_limb_t rl)); - -void -#if __STDC__ -mpz_ui_pow_ui (mpz_ptr r, unsigned long int b, unsigned long int e) -#else -mpz_ui_pow_ui (r, b, e) - mpz_ptr r; - unsigned long int b; - unsigned long int e; -#endif -{ - mp_limb_t blimb = b; - mp_limb_t rl; - - if (e == 0) - { - /* For x^0 we return 1, even if x is 0. */ - r->_mp_d[0] = 1; - r->_mp_size = 1; - return; - } - - /* Compute b^e as (b^n)^(e div n) * b^(e mod n), where n is chosen such that - the latter factor is the largest number small enough to fit in a limb. */ - - rl = 1; - while (e != 0 && blimb < ((mp_limb_t) 1 << BITS_PER_MP_LIMB/2)) - { - if ((e & 1) != 0) - rl = rl * blimb; - blimb = blimb * blimb; - e = e >> 1; - } - - /* rl is now b^(e mod n). (I.e., the latter factor above.) */ - - if (e == 0) - { - r->_mp_d[0] = rl; - r->_mp_size = rl != 0; - return; - } - - mpz_pow2 (r, blimb, e, rl); -} - -/* Multi-precision part of expontialization code. */ -static void -#if __STDC__ -mpz_pow2 (mpz_ptr r, mp_limb_t blimb, unsigned long int e, mp_limb_t rl) -#else -mpz_pow2 (r, blimb, e, rl) - mpz_ptr r; - mp_limb_t blimb; - unsigned long int e; - mp_limb_t rl; -#endif -{ - mp_ptr rp, tp; - mp_size_t ralloc, rsize; - int cnt, i; - TMP_DECL (marker); - - TMP_MARK (marker); - - /* Over-estimate temporary space requirements somewhat. */ - count_leading_zeros (cnt, blimb); - ralloc = e - cnt * e / BITS_PER_MP_LIMB + 1; - - /* The two areas are used to alternatingly hold the input and receive the - product for mpn_mul. (Needed since mpn_mul_n requires that the product - is distinct from either input operand.) */ - rp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - tp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB); - - rp[0] = blimb; - rsize = 1; - - count_leading_zeros (cnt, e); - for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--) - { - mpn_mul_n (tp, rp, rp, rsize); - rsize = 2 * rsize; - rsize -= tp[rsize - 1] == 0; - MP_PTR_SWAP (rp, tp); - - if ((e & ((mp_limb_t) 1 << i)) != 0) - { - mp_limb_t cy; - cy = mpn_mul_1 (rp, rp, rsize, blimb); - rp[rsize] = cy; - rsize += cy != 0; - } - } - - /* We will need rsize or rsize+1 limbs for the result. */ - if (r->_mp_alloc <= rsize) - _mpz_realloc (r, rsize + 1); - - /* Multiply the two factors (in rp,rsize and rl) and put the final result - in place. */ - { - mp_limb_t cy; - cy = mpn_mul_1 (r->_mp_d, rp, rsize, rl); - (r->_mp_d)[rsize] = cy; - rsize += cy != 0; - } - - r->_mp_size = rsize; - TMP_FREE (marker); -} diff --git a/gmp/mpz/urandomb.c b/gmp/mpz/urandomb.c deleted file mode 100755 index caca086..0000000 --- a/gmp/mpz/urandomb.c +++ /dev/null @@ -1,49 +0,0 @@ -/* mpz_urandomb (rop, state, n) -- Generate a uniform pseudorandom - integer in the range 0 to 2^N - 1, inclusive, using STATE as the - random state previously initialized by a call to gmp_randinit(). - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_urandomb (mpz_t rop, gmp_randstate_t rstate, unsigned long int nbits) -#else -mpz_urandomb (rop, rstate, nbits) - mpz_t rop; - gmp_randstate_t rstate; - unsigned long int nbits; -#endif -{ - mp_ptr rp; - mp_size_t size; - - size = (nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - if (ALLOC (rop) < size) - _mpz_realloc (rop, size); - - rp = PTR (rop); - - _gmp_rand (rp, rstate, nbits); - MPN_NORMALIZE (rp, size); - SIZ (rop) = size; -} diff --git a/gmp/mpz/urandomm.c b/gmp/mpz/urandomm.c deleted file mode 100755 index aa57784..0000000 --- a/gmp/mpz/urandomm.c +++ /dev/null @@ -1,73 +0,0 @@ -/* mpz_urandomm (rop, state, n) -- Generate a uniform pseudorandom - integer in the range 0 to N-1, using STATE as the random state - previously initialized by a call to gmp_randinit(). - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -void -#if __STDC__ -mpz_urandomm (mpz_t rop, gmp_randstate_t rstate, mpz_t n) -#else -mpz_urandomm (rop, rstate, n) - mpz_t rop; - gmp_randstate_t rstate; - mpz_t n; -#endif -{ - mpz_t t, p, m; - mp_ptr tp; - mp_size_t nbits, size; - int count; - - /* FIXME: Should check for n == 0 and report error */ - - size = SIZ (n); - count_leading_zeros (count, PTR (n)[size - 1]); - nbits = size * BITS_PER_MP_LIMB - count; - - /* Allocate enough for any mpz function called since a realloc of - these will fail. */ - MPZ_TMP_INIT (t, size); - MPZ_TMP_INIT (m, size + 1); - MPZ_TMP_INIT (p, size + 1); - - /* Let m = highest possible random number plus 1. */ - mpz_set_ui (m, 0); - mpz_setbit (m, nbits); - - /* Let p = floor(m / n) * n. */ - mpz_fdiv_q (p, m, n); - mpz_mul (p, p, n); - - tp = PTR (t); - do - { - _gmp_rand (tp, rstate, nbits); - MPN_NORMALIZE (tp, size); /* FIXME: Really necessary? */ - SIZ (t) = size; - } - while (mpz_cmp (t, p) >= 0); - - mpz_mod (rop, t, n); -} diff --git a/gmp/mpz/xor.c b/gmp/mpz/xor.c deleted file mode 100755 index 69898d1..0000000 --- a/gmp/mpz/xor.c +++ /dev/null @@ -1,217 +0,0 @@ -/* mpz_xor -- Logical xor. - -Copyright (C) 1991, 1993, 1994, 1996, 1997, 2000 Free Software Foundation, -Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -mpz_xor (mpz_ptr res, mpz_srcptr op1, mpz_srcptr op2) -#else -mpz_xor (res, op1, op2) - mpz_ptr res; - mpz_srcptr op1; - mpz_srcptr op2; -#endif -{ - mp_srcptr op1_ptr, op2_ptr; - mp_size_t op1_size, op2_size; - mp_ptr res_ptr; - mp_size_t res_size, res_alloc; - mp_size_t i; - TMP_DECL (marker); - - TMP_MARK (marker); - op1_size = op1->_mp_size; - op2_size = op2->_mp_size; - - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - - if (op1_size >= 0) - { - if (op2_size >= 0) - { - if (op1_size >= op2_size) - { - if (res->_mp_alloc < op1_size) - { - _mpz_realloc (res, op1_size); - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - } - - if (res_ptr != op1_ptr) - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, - op1_size - op2_size); - for (i = op2_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] ^ op2_ptr[i]; - res_size = op1_size; - } - else - { - if (res->_mp_alloc < op2_size) - { - _mpz_realloc (res, op2_size); - op1_ptr = op1->_mp_d; - op2_ptr = op2->_mp_d; - res_ptr = res->_mp_d; - } - - if (res_ptr != op2_ptr) - MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size, - op2_size - op1_size); - for (i = op1_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] ^ op2_ptr[i]; - res_size = op2_size; - } - - MPN_NORMALIZE (res_ptr, res_size); - res->_mp_size = res_size; - return; - } - else /* op2_size < 0 */ - { - /* Fall through to the code at the end of the function. */ - } - } - else - { - if (op2_size < 0) - { - mp_ptr opx; - mp_limb_t cy; - - /* Both operands are negative, the result will be positive. - (-OP1) ^ (-OP2) = - = ~(OP1 - 1) ^ ~(OP2 - 1) = - = (OP1 - 1) ^ (OP2 - 1) */ - - op1_size = -op1_size; - op2_size = -op2_size; - - /* Possible optimization: Decrease mpn_sub precision, - as we won't use the entire res of both. */ - opx = (mp_ptr) TMP_ALLOC (op1_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op1_ptr, op1_size, (mp_limb_t) 1); - op1_ptr = opx; - - opx = (mp_ptr) TMP_ALLOC (op2_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op2_ptr, op2_size, (mp_limb_t) 1); - op2_ptr = opx; - - res_alloc = MAX (op1_size, op2_size); - if (res->_mp_alloc < res_alloc) - { - _mpz_realloc (res, res_alloc); - res_ptr = res->_mp_d; - /* Don't re-read OP1_PTR and OP2_PTR. They point to - temporary space--never to the space RES->_mp_d used - to point to before reallocation. */ - } - - if (op1_size > op2_size) - { - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, - op1_size - op2_size); - for (i = op2_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] ^ op2_ptr[i]; - res_size = op1_size; - } - else - { - MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size, - op2_size - op1_size); - for (i = op1_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] ^ op2_ptr[i]; - res_size = op2_size; - } - - MPN_NORMALIZE (res_ptr, res_size); - res->_mp_size = res_size; - TMP_FREE (marker); - return; - } - else - { - /* We should compute -OP1 ^ OP2. Swap OP1 and OP2 and fall - through to the code that handles OP1 ^ -OP2. */ - MPZ_SRCPTR_SWAP (op1, op2); - MPN_SRCPTR_SWAP (op1_ptr,op1_size, op2_ptr,op2_size); - } - } - - { - mp_ptr opx; - mp_limb_t cy; - mp_size_t count; - - /* Operand 2 negative, so will be the result. - -(OP1 ^ (-OP2)) = -(OP1 ^ ~(OP2 - 1)) = - = ~(OP1 ^ ~(OP2 - 1)) + 1 = - = (OP1 ^ (OP2 - 1)) + 1 */ - - op2_size = -op2_size; - - opx = (mp_ptr) TMP_ALLOC (op2_size * BYTES_PER_MP_LIMB); - mpn_sub_1 (opx, op2_ptr, op2_size, (mp_limb_t) 1); - op2_ptr = opx; - - res_alloc = MAX (op1_size, op2_size) + 1; - if (res->_mp_alloc < res_alloc) - { - _mpz_realloc (res, res_alloc); - op1_ptr = op1->_mp_d; - res_ptr = res->_mp_d; - /* Don't re-read OP2_PTR. It points to temporary space--never - to the space RES->_mp_d used to point to before reallocation. */ - } - - if (op1_size > op2_size) - { - MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size, op1_size - op2_size); - for (i = op2_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] ^ op2_ptr[i]; - res_size = op1_size; - } - else - { - MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size, op2_size - op1_size); - for (i = op1_size - 1; i >= 0; i--) - res_ptr[i] = op1_ptr[i] ^ op2_ptr[i]; - res_size = op2_size; - } - - cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1); - if (cy) - { - res_ptr[res_size] = cy; - res_size++; - } - - MPN_NORMALIZE (res_ptr, res_size); - res->_mp_size = -res_size; - TMP_FREE (marker); - } -} diff --git a/gmp/rand.c b/gmp/rand.c deleted file mode 100755 index d1f9354..0000000 --- a/gmp/rand.c +++ /dev/null @@ -1,171 +0,0 @@ -/* gmp_randinit (state, algorithm, ...) -- Initialize a random state. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include /* for NULL */ -#if __STDC__ -# include -#else -# include -#endif - -#include "gmp.h" -#include "gmp-impl.h" - -/* Array of CL-schemes, ordered in increasing order of the first - member (the 'm2exp' value). The end of the array is indicated with - an entry containing all zeros. */ - -/* All multipliers are in the range 0.01*m and 0.99*m, and are -congruent to 5 (mod 8). -They all pass the spectral test with Vt >= 2^(30/t) and merit >= 1. -(Up to and including 196 bits, merit is >= 3.) */ - -struct __gmp_rand_lc_scheme_struct -{ - unsigned long int m2exp; /* Modulus is 2 ^ m2exp. */ - char *astr; /* Multiplier in string form. */ - unsigned long int c; /* Adder. */ -}; - -struct __gmp_rand_lc_scheme_struct __gmp_rand_lc_scheme[] = -{ - {32, "43840821", 1}, - {33, "85943917", 1}, - {34, "171799469", 1}, - {35, "343825285", 1}, - {36, "687285701", 1}, - {37, "1374564613", 1}, - {38, "2749193437", 1}, - {39, "5497652029", 1}, - {40, "10995212661", 1}, - {56, "47988680294711517", 1}, - {64, "13469374875402548381", 1}, - {100, "203786806069096950756900463357", 1}, - {128, "96573135900076068624591706046897650309", 1}, - {156, "43051576988660538262511726153887323360449035333", 1}, - {196, "1611627857640767981443524165616850972435303571524033586421", 1}, - {200, "491824250216153841876046962368396460896019632211283945747141", 1}, - {256, "79336254595106925775099152154558630917988041692672147726148065355845551082677", 1}, - {0, NULL, 0} /* End of array. */ -}; - -void -#if __STDC__ -gmp_randinit (gmp_randstate_t rstate, - gmp_randalg_t alg, - ...) -#else -gmp_randinit (va_alist) - va_dcl -#endif -{ - va_list ap; -#if __STDC__ -#else - __gmp_randstate_struct *rstate; - gmp_randalg_t alg; -#endif - -#if __STDC__ - va_start (ap, alg); -#else - va_start (ap); - - rstate = va_arg (ap, __gmp_randstate_struct *); - alg = va_arg (ap, gmp_randalg_t); -#endif - - switch (alg) - { - case GMP_RAND_ALG_LC: /* Linear congruential. */ - { - unsigned long int size; - struct __gmp_rand_lc_scheme_struct *sp; - mpz_t a; - - size = va_arg (ap, unsigned long int); - - /* Pick a scheme. */ - for (sp = __gmp_rand_lc_scheme; sp->m2exp != 0; sp++) - if (sp->m2exp / 2 >= size) - break; - - if (sp->m2exp == 0) /* Nothing big enough found. */ - { - gmp_errno |= GMP_ERROR_INVALID_ARGUMENT; - return; - } - - /* Install scheme. */ - mpz_init_set_str (a, sp->astr, 0); - gmp_randinit_lc_2exp (rstate, a, sp->c, sp->m2exp); - mpz_clear (a); - break; - } - -#if 0 - case GMP_RAND_ALG_BBS: /* Blum, Blum, and Shub. */ - { - mpz_t p, q; - mpz_t ztmp; - - /* FIXME: Generate p and q. They must be ``large'' primes, - congruent to 3 mod 4. Should we ensure that they meet some - of the criterias for being ``hard primes''?*/ - - /* These are around 128 bits. */ - mpz_init_set_str (p, "148028650191182616877187862194899201391", 10); - mpz_init_set_str (q, "315270837425234199477225845240496832591", 10); - - /* Allocate algorithm specific data. */ - rstate->data.bbs = (__gmp_rand_data_bbs *) - (*_mp_allocate_func) (sizeof (__gmp_rand_data_bbs)); - - mpz_init (rstate->data.bbs->bi); /* The Blum integer. */ - mpz_mul (rstate->data.bbs->bi, p, q); - - /* Find a seed, x, with gcd (x, bi) == 1. */ - mpz_init (ztmp); - while (1) - { - mpz_gcd (ztmp, seed, rstate->data.bbs->bi); - if (!mpz_cmp_ui (ztmp, 1)) - break; - mpz_add_ui (seed, seed, 1); - } - - rstate->alg = alg; - rstate->size = size; /* FIXME: Remove. */ - mpz_set (rstate->seed, seed); - - mpz_clear (p); - mpz_clear (q); - mpz_clear (ztmp); - break; - } -#endif /* 0 */ - - default: /* Bad choice. */ - gmp_errno |= GMP_ERROR_UNSUPPORTED_ARGUMENT; - } - - va_end (ap); -} diff --git a/gmp/randclr.c b/gmp/randclr.c deleted file mode 100755 index 5cb0291..0000000 --- a/gmp/randclr.c +++ /dev/null @@ -1,54 +0,0 @@ -/* gmp_randclear (state) -- Clear and deallocate random state STATE. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -gmp_randclear (gmp_randstate_t rstate) -#else -gmp_randclear (rstate) - gmp_randstate_t rstate; -#endif -{ - mpz_clear (rstate->seed); - - switch (rstate->alg) - { - case GMP_RAND_ALG_LC: - mpz_clear (rstate->algdata.lc->a); - if (rstate->algdata.lc->m2exp == 0) - mpz_clear (rstate->algdata.lc->m); - (*_mp_free_func) (rstate->algdata.lc, sizeof (*rstate->algdata.lc)); - break; - -#if 0 - case GMP_RAND_ALG_BBS: - mpz_clear (rstate->algdata.bbs->bi); - (*_mp_free_func) (rstate->algdata.bbs, sizeof (*rstate->algdata.bbs)); - break; -#endif /* 0 */ - - default: - gmp_errno |= GMP_ERROR_UNSUPPORTED_ARGUMENT; - } -} diff --git a/gmp/randlc.c b/gmp/randlc.c deleted file mode 100755 index 7079db8..0000000 --- a/gmp/randlc.c +++ /dev/null @@ -1,56 +0,0 @@ -/* gmp_randinit_lc (state, a, c, m) -- Initialize a random state for a - linear congruential generator with multiplier A, adder C, and - modulus M. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -gmp_randinit_lc (gmp_randstate_t rstate, - mpz_t a, - unsigned long int c, - mpz_t m) -#else -gmp_randinit_lc (rstate, a, c, m) - gmp_randstate_t rstate; - mpz_t a; - unsigned long int c; - mpz_t m; -#endif -{ - /* FIXME: Not finished. We don't handle this in _gmp_rand() yet. */ - abort (); - - mpz_init_set_ui (rstate->seed, 1); - _mpz_realloc (rstate->seed, ABSIZ (m)); - - /* Allocate algorithm specific data. */ - rstate->algdata.lc = (__gmp_randata_lc *) - (*_mp_allocate_func) (sizeof (__gmp_randata_lc)); - - mpz_init_set (rstate->algdata.lc->a, a); - rstate->algdata.lc->c = c; - mpz_init_set (rstate->algdata.lc->m, m); - - rstate->alg = GMP_RAND_ALG_LC; -} diff --git a/gmp/randlc2x.c b/gmp/randlc2x.c deleted file mode 100755 index dbd5f04..0000000 --- a/gmp/randlc2x.c +++ /dev/null @@ -1,59 +0,0 @@ -/* gmp_randinit_lc_2exp (state, a, c, m2exp) -- Initialize random - state STATE for a linear congruential generator with multiplier A, - adder C, and modulus 2 ^ M2EXP. - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -gmp_randinit_lc_2exp (gmp_randstate_t rstate, - mpz_t a, - unsigned long int c, - unsigned long int m2exp) -#else -gmp_randinit_lc_2exp (rstate, a, c, m2exp) - gmp_randstate_t rstate; - mpz_t a; - unsigned long int c; - unsigned long int m2exp; -#endif -{ - mpz_init_set_ui (rstate->seed, 1); - _mpz_realloc (rstate->seed, m2exp / BITS_PER_MP_LIMB - + (m2exp % BITS_PER_MP_LIMB != 0)); - - /* Allocate algorithm specific data. */ - rstate->algdata.lc = (__gmp_randata_lc *) - (*_mp_allocate_func) (sizeof (__gmp_randata_lc)); - - mpz_init_set (rstate->algdata.lc->a, a); - rstate->algdata.lc->c = c; - - /* Cover weird case where m2exp is 0, which means that m is used - instead of m2exp. */ - if (m2exp == 0) - mpz_init_set_ui (rstate->algdata.lc->m, 0); - rstate->algdata.lc->m2exp = m2exp; - - rstate->alg = GMP_RAND_ALG_LC; -} diff --git a/gmp/randraw.c b/gmp/randraw.c deleted file mode 100755 index c0c3889..0000000 --- a/gmp/randraw.c +++ /dev/null @@ -1,360 +0,0 @@ -/* _gmp_rand (rp, state, nbits) -- Generate a random bitstream of - length NBITS in RP. RP must have enough space allocated to hold - NBITS. - -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -/* For linear congruential (LC), we use one of algorithms (1) or (2). - (gmp-3.0 uses algorithm (1) with 'm' as a power of 2.) - -LC algorithm (1). - - X = (aX + c) mod m - -[D. Knuth, "The Art of Computer Programming: Volume 2, Seminumerical Algorithms", -Third Edition, Addison Wesley, 1998, pp. 184-185.] - - X is the seed and the result - a is chosen so that - a mod 8 = 5 [3.2.1.2] and [3.2.1.3] - .01m < a < .99m - its binary or decimal digits is not a simple, regular pattern - it has no large quotients when Euclid's algorithm is used to find - gcd(a, m) [3.3.3] - it passes the spectral test [3.3.4] - it passes several tests of [3.3.2] - c has no factor in common with m (c=1 or c=a can be good) - m is large (2^30) - is a power of 2 [3.2.1.1] - -The least significant digits of the generated number are not very -random. It should be regarded as a random fraction X/m. To get a -random integer between 0 and n-1, multiply X/m by n and truncate. -(Don't use X/n [ex 3.4.1-3]) - -The ``accuracy'' in t dimensions is one part in ``the t'th root of m'' [3.3.4]. - -Don't generate more than about m/1000 numbers without changing a, c, or m. - -The sequence length depends on chosen a,c,m. - - -LC algorithm (2). - - X = a * (X mod q) - r * (long) (X/q) - if X<0 then X+=m - -[Knuth, pp. 185-186.] - - X is the seed and the result - as a seed is nonzero and less than m - a is a primitive root of m (which means that a^2 <= m) - q is (long) m / a - r is m mod a - m is a prime number near the largest easily computed integer - -which gives - - X = a * (X % ((long) m / a)) - - (M % a) * ((long) (X / ((long) m / a))) - -Since m is prime, the least-significant bits of X are just as random as -the most-significant bits. */ - -/* Blum, Blum, and Shub. - - [Bruce Schneier, "Applied Cryptography", Second Edition, John Wiley - & Sons, Inc., 1996, pp. 417-418.] - - "Find two large prime numbers, p and q, which are congruent to 3 - modulo 4. The product of those numbers, n, is a blum integer. - Choose another random integer, x, which is relatively prime to n. - Compute - x[0] = x^2 mod n - That's the seed for the generator." - - To generate a random bit, compute - x[i] = x[i-1]^2 mod n - The least significant bit of x[i] is the one we want. - - We can use more than one bit from x[i], namely the - log2(bitlength of x[i]) - least significant bits of x[i]. - - So, for a 32-bit seed we get 5 bits per computation. - - The non-predictability of this generator is based on the difficulty - of factoring n. - */ - -/* -------------------------------------------------- */ - -/* lc (rp, state) -- Generate next number in LC sequence. Return the - number of valid bits in the result. NOTE: If 'm' is a power of 2 - (m2exp != 0), discard the lower half of the result. */ - -static -unsigned long int -#if __STDC__ -lc (mp_ptr rp, gmp_randstate_t rstate) -#else -lc (rp, rstate) - mp_ptr rp; - gmp_randstate_t rstate; -#endif -{ - mp_ptr tp, seedp, ap; - mp_size_t ta; - mp_size_t tn, seedn, an; - mp_size_t retval; - int shiftcount = 0; - unsigned long int m2exp; - mp_limb_t c; - TMP_DECL (mark); - - m2exp = rstate->algdata.lc->m2exp; - c = (mp_limb_t) rstate->algdata.lc->c; - - seedp = PTR (rstate->seed); - seedn = SIZ (rstate->seed); - - if (seedn == 0) - { - /* Seed is 0. Result is C % M. */ - *rp = c; - - if (m2exp != 0) - { - /* M is a power of 2. */ - if (m2exp < BITS_PER_MP_LIMB) - { - /* Only necessary when M may be smaller than C. */ - *rp &= (((mp_limb_t) 1 << m2exp) - 1); - } - } - else - { - /* M is not a power of 2. */ - abort (); /* FIXME. */ - } - - /* Save result as next seed. */ - *seedp = *rp; - SIZ (rstate->seed) = 1; - return BITS_PER_MP_LIMB; - } - - ap = PTR (rstate->algdata.lc->a); - an = SIZ (rstate->algdata.lc->a); - - /* Allocate temporary storage. Let there be room for calculation of - (A * seed + C) % M, or M if bigger than that. */ - - ASSERT_ALWAYS (m2exp != 0); /* FIXME. */ - - TMP_MARK (mark); - ta = an + seedn + 1; - tp = (mp_ptr) TMP_ALLOC (ta * BYTES_PER_MP_LIMB); - MPN_ZERO (tp, ta); - - /* t = a * seed */ - if (seedn >= an) - mpn_mul_basecase (tp, seedp, seedn, ap, an); - else - mpn_mul_basecase (tp, ap, an, seedp, seedn); - tn = an + seedn; - - /* t = t + c */ - mpn_incr_u (tp, c); - - /* t = t % m */ - if (m2exp != 0) - { - /* M is a power of 2. The mod operation is trivial. */ - - tp[m2exp / BITS_PER_MP_LIMB] &= ((mp_limb_t) 1 << m2exp % BITS_PER_MP_LIMB) - 1; - tn = (m2exp + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - } - else - { - abort (); /* FIXME. */ - } - - /* Save result as next seed. */ - MPN_COPY (PTR (rstate->seed), tp, tn); - SIZ (rstate->seed) = tn; - - if (m2exp != 0) - { - /* Discard the lower half of the result. */ - unsigned long int discardb = m2exp / 2; - mp_size_t discardl = discardb / BITS_PER_MP_LIMB; - - tn -= discardl; - if (tn > 0) - { - if (discardb % BITS_PER_MP_LIMB != 0) - { - mpn_rshift (tp, tp + discardl, tn, discardb % BITS_PER_MP_LIMB); - MPN_COPY (rp, tp, (discardb + BITS_PER_MP_LIMB -1) / BITS_PER_MP_LIMB); - } - else /* Even limb boundary. */ - MPN_COPY_INCR (rp, tp + discardl, tn); - } - } - else - { - MPN_COPY (rp, tp, tn); - } - - TMP_FREE (mark); - - /* Return number of valid bits in the result. */ - if (m2exp != 0) - retval = (m2exp + 1) / 2; - else - retval = SIZ (rstate->algdata.lc->m) * BITS_PER_MP_LIMB - shiftcount; - return retval; -} - -#ifdef RAWRANDEBUG -/* Set even bits to EVENBITS and odd bits to ! EVENBITS in RP. - Number of bits is m2exp in state. */ -/* FIXME: Remove. */ -unsigned long int -lc_test (mp_ptr rp, gmp_randstate_t s, const int evenbits) -{ - unsigned long int rn, nbits; - int f; - - nbits = s->algdata.lc->m2exp / 2; - rn = nbits / BITS_PER_MP_LIMB + (nbits % BITS_PER_MP_LIMB != 0); - MPN_ZERO (rp, rn); - - for (f = 0; f < nbits; f++) - { - mpn_lshift (rp, rp, rn, 1); - if (f % 2 == ! evenbits) - rp[0] += 1; - } - - return nbits; -} -#endif /* RAWRANDEBUG */ - -void -#if __STDC__ -_gmp_rand (mp_ptr rp, gmp_randstate_t rstate, unsigned long int nbits) -#else -_gmp_rand (rp, rstate, nbits) - mp_ptr rp; - gmp_randstate_t rstate; - unsigned long int nbits; -#endif -{ - mp_size_t rn; /* Size of R. */ - - rn = (nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - - switch (rstate->alg) - { - case GMP_RAND_ALG_LC: - { - unsigned long int rbitpos; - int chunk_nbits; - mp_ptr tp; - mp_size_t tn; - TMP_DECL (lcmark); - - TMP_MARK (lcmark); - - chunk_nbits = rstate->algdata.lc->m2exp / 2; - tn = (chunk_nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - - tp = (mp_ptr) TMP_ALLOC (tn * BYTES_PER_MP_LIMB); - - rbitpos = 0; - while (rbitpos + chunk_nbits <= nbits) - { - mp_ptr r2p = rp + rbitpos / BITS_PER_MP_LIMB; - - if (rbitpos % BITS_PER_MP_LIMB != 0) - { - mp_limb_t savelimb, rcy; - /* Target of of new chunk is not bit aligned. Use temp space - and align things by shifting it up. */ - lc (tp, rstate); - savelimb = r2p[0]; - rcy = mpn_lshift (r2p, tp, tn, rbitpos % BITS_PER_MP_LIMB); - r2p[0] |= savelimb; -/* bogus */ if ((chunk_nbits % BITS_PER_MP_LIMB + rbitpos % BITS_PER_MP_LIMB) - > BITS_PER_MP_LIMB) - r2p[tn] = rcy; - } - else - { - /* Target of of new chunk is bit aligned. Let `lc' put bits - directly into our target variable. */ - lc (r2p, rstate); - } - rbitpos += chunk_nbits; - } - - /* Handle last [0..chunk_nbits) bits. */ - if (rbitpos != nbits) - { - mp_ptr r2p = rp + rbitpos / BITS_PER_MP_LIMB; - int last_nbits = nbits - rbitpos; - tn = (last_nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; - lc (tp, rstate); - if (rbitpos % BITS_PER_MP_LIMB != 0) - { - mp_limb_t savelimb, rcy; - /* Target of of new chunk is not bit aligned. Use temp space - and align things by shifting it up. */ - savelimb = r2p[0]; - rcy = mpn_lshift (r2p, tp, tn, rbitpos % BITS_PER_MP_LIMB); - r2p[0] |= savelimb; - if (rbitpos + tn * BITS_PER_MP_LIMB - rbitpos % BITS_PER_MP_LIMB < nbits) - r2p[tn] = rcy; - } - else - { - MPN_COPY (r2p, tp, tn); - } - /* Mask off top bits if needed. */ - if (nbits % BITS_PER_MP_LIMB != 0) - rp[nbits / BITS_PER_MP_LIMB] - &= ~ ((~(mp_limb_t) 0) << nbits % BITS_PER_MP_LIMB); - } - - TMP_FREE (lcmark); - break; - } - - default: - gmp_errno |= GMP_ERROR_UNSUPPORTED_ARGUMENT; - break; - } -} diff --git a/gmp/randsd.c b/gmp/randsd.c deleted file mode 100755 index 3bed14b..0000000 --- a/gmp/randsd.c +++ /dev/null @@ -1,37 +0,0 @@ -/* gmp_randseed (state, seed) -- Set initial seed SEED in random state - STATE. - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -gmp_randseed (gmp_randstate_t rstate, - mpz_t seed) -#else -gmp_randseed (rstate, seed) - gmp_randstate_t rstate; - mpz_t seed; -#endif -{ - mpz_set (rstate->seed, seed); -} diff --git a/gmp/randsdui.c b/gmp/randsdui.c deleted file mode 100755 index 92f412f..0000000 --- a/gmp/randsdui.c +++ /dev/null @@ -1,37 +0,0 @@ -/* gmp_randseed_ui (state, seed) -- Set initial seed SEED in random - state STATE. - -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -void -#if __STDC__ -gmp_randseed_ui (gmp_randstate_t rstate, - unsigned long int seed) -#else -gmp_randseed_ui (rstate, seed) - gmp_randstate_t rstate; - mpz_t seed; -#endif -{ - mpz_set_ui (rstate->seed, seed); -} diff --git a/gmp/stack-alloc.c b/gmp/stack-alloc.c deleted file mode 100755 index 9ab98fe..0000000 --- a/gmp/stack-alloc.c +++ /dev/null @@ -1,136 +0,0 @@ -/* Stack allocation routines. This is intended for machines without support - for the `alloca' function. - -Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "stack-alloc.h" - -#define __need_size_t -#include -#undef __need_size_t - -/* gmp-impl.h and stack-alloc.h conflict when not USE_STACK_ALLOC, so these - declarations are copied here */ -#if __STDC__ -extern void * (*__gmp_allocate_func) (size_t); -extern void (*__gmp_free_func) (void *, size_t); -#else -extern void * (*__gmp_allocate_func) (); -extern void (*__gmp_free_func) (); -#endif - -typedef struct tmp_stack tmp_stack; - -static unsigned long max_total_allocation = 0; -static unsigned long current_total_allocation = 0; - -static tmp_stack xxx = {&xxx, &xxx, 0}; -static tmp_stack *current = &xxx; - -/* The rounded size of the header of each allocation block. */ -#define HSIZ ((sizeof (tmp_stack) + __TMP_ALIGN - 1) & -__TMP_ALIGN) - -/* Allocate a block of exactly bytes. This should only be called - through the TMP_ALLOC macro, which takes care of rounding/alignment. */ -void * -#if __STDC__ -__gmp_tmp_alloc (unsigned long size) -#else -__gmp_tmp_alloc (size) - unsigned long size; -#endif -{ - void *that; - - if (size > (char *) current->end - (char *) current->alloc_point) - { - void *chunk; - tmp_stack *header; - unsigned long chunk_size; - unsigned long now; - - /* Allocate a chunk that makes the total current allocation somewhat - larger than the maximum allocation ever. If size is very large, we - allocate that much. */ - - now = current_total_allocation + size; - if (now > max_total_allocation) - { - /* We need more temporary memory than ever before. Increase - for future needs. */ - now = now * 3 / 2; - chunk_size = now - current_total_allocation + HSIZ; - current_total_allocation = now; - max_total_allocation = current_total_allocation; - } - else - { - chunk_size = max_total_allocation - current_total_allocation + HSIZ; - current_total_allocation = max_total_allocation; - } - - chunk = (*__gmp_allocate_func) (chunk_size); - header = (tmp_stack *) chunk; - header->end = (char *) chunk + chunk_size; - header->alloc_point = (char *) chunk + HSIZ; - header->prev = current; - current = header; - } - - that = current->alloc_point; - current->alloc_point = (char *) that + size; - return that; -} - -/* Typically called at function entry. is assigned so that - __gmp_tmp_free can later be used to reclaim all subsequently allocated - storage. */ -void -#if __STDC__ -__gmp_tmp_mark (tmp_marker *mark) -#else -__gmp_tmp_mark (mark) - tmp_marker *mark; -#endif -{ - mark->which_chunk = current; - mark->alloc_point = current->alloc_point; -} - -/* Free everything allocated since was assigned by __gmp_tmp_mark */ -void -#if __STDC__ -__gmp_tmp_free (tmp_marker *mark) -#else -__gmp_tmp_free (mark) - tmp_marker *mark; -#endif -{ - while (mark->which_chunk != current) - { - tmp_stack *tmp; - - tmp = current; - current = tmp->prev; - current_total_allocation -= (((char *) (tmp->end) - (char *) tmp) - HSIZ); - (*__gmp_free_func) (tmp, (char *) tmp->end - (char *) tmp); - } - current->alloc_point = mark->alloc_point; -} diff --git a/gmp/stack-alloc.h b/gmp/stack-alloc.h deleted file mode 100755 index f59beec..0000000 --- a/gmp/stack-alloc.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Stack allocation routines. This is intended for machines without support - for the `alloca' function. - -Copyright (C) 1996, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -struct tmp_stack -{ - void *end; - void *alloc_point; - struct tmp_stack *prev; -}; - -struct tmp_marker -{ - struct tmp_stack *which_chunk; - void *alloc_point; -}; - -typedef struct tmp_marker tmp_marker; - -#if defined (__cplusplus) -extern "C" { -#endif - -#if __STDC__ -void *__gmp_tmp_alloc (unsigned long); -void __gmp_tmp_mark (tmp_marker *); -void __gmp_tmp_free (tmp_marker *); -#else -void *__gmp_tmp_alloc (); -void __gmp_tmp_mark (); -void __gmp_tmp_free (); -#endif - -#if defined (__cplusplus) -} -#endif - -#ifndef __TMP_ALIGN -#define __TMP_ALIGN 8 -#endif - -#define TMP_DECL(marker) tmp_marker marker -#define TMP_ALLOC(size) \ - __gmp_tmp_alloc (((unsigned long) (size) + __TMP_ALIGN - 1) & -__TMP_ALIGN) -#define TMP_MARK(marker) __gmp_tmp_mark (&marker) -#define TMP_FREE(marker) __gmp_tmp_free (&marker) diff --git a/gmp/stamp-h.in b/gmp/stamp-h.in deleted file mode 100755 index a47a4ff..0000000 Binary files a/gmp/stamp-h.in and /dev/null differ diff --git a/gmp/stamp-vti b/gmp/stamp-vti deleted file mode 100755 index 640f602..0000000 Binary files a/gmp/stamp-vti and /dev/null differ diff --git a/gmp/tests/Makefile.am b/gmp/tests/Makefile.am deleted file mode 100755 index 6256b8d..0000000 Binary files a/gmp/tests/Makefile.am and /dev/null differ diff --git a/gmp/tests/Makefile.in b/gmp/tests/Makefile.in deleted file mode 100755 index 4ef47db..0000000 Binary files a/gmp/tests/Makefile.in and /dev/null differ diff --git a/gmp/tests/rand/ChangeLog b/gmp/tests/rand/ChangeLog deleted file mode 100755 index 7493da1..0000000 Binary files a/gmp/tests/rand/ChangeLog and /dev/null differ diff --git a/gmp/tests/rand/Makefile.am b/gmp/tests/rand/Makefile.am deleted file mode 100755 index d9673b5..0000000 Binary files a/gmp/tests/rand/Makefile.am and /dev/null differ diff --git a/gmp/tests/rand/Makefile.in b/gmp/tests/rand/Makefile.in deleted file mode 100755 index d90420a..0000000 Binary files a/gmp/tests/rand/Makefile.in and /dev/null differ diff --git a/gmp/tests/rand/findlc.c b/gmp/tests/rand/findlc.c deleted file mode 100755 index ace8f9f..0000000 --- a/gmp/tests/rand/findlc.c +++ /dev/null @@ -1,255 +0,0 @@ -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include -#include -#include -#include -#include "gmp.h" -#include "gmpstat.h" - -#define RCSID(msg) \ -static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg } - -RCSID("$Id$"); - -int g_debug = 0; - -static mpz_t a; - -static void -sh_status (int sig) -{ - printf ("sh_status: signal %d caught. dumping status.\n", sig); - - printf (" a = "); - mpz_out_str (stdout, 10, a); - printf ("\n"); - fflush (stdout); - - if (SIGSEGV == sig) /* remove SEGV handler */ - signal (SIGSEGV, SIG_DFL); -} - -/* Input is a modulus (m). We shall find multiplyer (a) and adder (c) - conforming to the rules found in the first comment block in file - mpz/urandom.c. - - Then run a spectral test on the generator and discard any - multipliers not passing. */ - -/* TODO: - - . find a better algorithm than a+=8; bigger jumps perhaps? - -*/ - -void -mpz_true_random (mpz_t s, unsigned long int nbits) -{ -#if __FreeBSD__ - FILE *fs; - char c[1]; - int i; - - mpz_set_ui (s, 0); - for (i = 0; i < nbits; i += 8) - { - for (;;) - { - int nread; - fs = fopen ("/dev/random", "r"); - nread = fread (c, 1, 1, fs); - fclose (fs); - if (nread != 0) - break; - sleep (1); - } - mpz_mul_2exp (s, s, 8); - mpz_add_ui (s, s, ((unsigned long int) c[0]) & 0xff); - printf ("%d random bits\n", i + 8); - } - if (nbits % 8 != 0) - mpz_mod_2exp (s, s, nbits); -#endif -} - -int -main (int argc, char *argv[]) -{ - const char usage[] = "usage: findlc [-dv] m2exp [low_merit [high_merit]]\n"; - int f; - int v_lose, m_lose, v_best, m_best; - int c; - int debug = 1; - int cnt_high_merit; - mpz_t m; - unsigned long int m2exp; -#define DIMS 6 /* dimensions run in spectral test */ - mpf_t v[DIMS-1]; /* spectral test result (there's no v - for 1st dimension */ - mpf_t f_merit, low_merit, high_merit; - mpz_t acc, minus8; - mpz_t min, max; - mpz_t s; - - - mpz_init (m); - mpz_init (a); - for (f = 0; f < DIMS-1; f++) - mpf_init (v[f]); - mpf_init (f_merit); - mpf_init_set_d (low_merit, .1); - mpf_init_set_d (high_merit, .1); - - while ((c = getopt (argc, argv, "a:di:hv")) != -1) - switch (c) - { - case 'd': /* debug */ - g_debug++; - break; - - case 'v': /* print version */ - puts (rcsid[1]); - exit (0); - - case 'h': - case '?': - default: - fputs (usage, stderr); - exit (1); - } - - argc -= optind; - argv += optind; - - if (argc < 1) - { - fputs (usage, stderr); - exit (1); - } - - /* Install signal handler. */ - if (SIG_ERR == signal (SIGSEGV, sh_status)) - { - perror ("signal (SIGSEGV)"); - exit (1); - } - if (SIG_ERR == signal (SIGHUP, sh_status)) - { - perror ("signal (SIGHUP)"); - exit (1); - } - - printf ("findlc: version: %s\n", rcsid[1]); - m2exp = atol (argv[0]); - mpz_init_set_ui (m, 1); - mpz_mul_2exp (m, m, m2exp); - printf ("m = 0x"); - mpz_out_str (stdout, 16, m); - puts (""); - - if (argc > 1) /* have low_merit */ - mpf_set_str (low_merit, argv[1], 0); - if (argc > 2) /* have high_merit */ - mpf_set_str (high_merit, argv[2], 0); - - if (debug) - { - fprintf (stderr, "low_merit = "); - mpf_out_str (stderr, 10, 2, low_merit); - fprintf (stderr, "; high_merit = "); - mpf_out_str (stderr, 10, 2, high_merit); - fputs ("\n", stderr); - } - - mpz_init (minus8); - mpz_set_si (minus8, -8L); - mpz_init_set_ui (acc, 0); - mpz_init (s); - mpz_init_set_d (min, 0.01 * pow (2.0, (double) m2exp)); - mpz_init_set_d (max, 0.99 * pow (2.0, (double) m2exp)); - - mpz_true_random (s, m2exp); /* Start. */ - mpz_setbit (s, 0); /* Make it odd. */ - - v_best = m_best = 2*(DIMS-1); - for (;;) - { - mpz_add (acc, acc, s); - mpz_mod_2exp (acc, acc, m2exp); -#if later - mpz_and_si (a, acc, -8L); -#else - mpz_and (a, acc, minus8); -#endif - mpz_add_ui (a, a, 5); - if (mpz_cmp (a, min) <= 0 || mpz_cmp (a, max) >= 0) - continue; - - spectral_test (v, DIMS, a, m); - for (f = 0, v_lose = m_lose = 0, cnt_high_merit = DIMS-1; - f < DIMS-1; f++) - { - merit (f_merit, f + 2, v[f], m); - - if (mpf_cmp_ui (v[f], 1 << (30 / (f + 2) + (f == 2))) < 0) - v_lose++; - - if (mpf_cmp (f_merit, low_merit) < 0) - m_lose++; - - if (mpf_cmp (f_merit, high_merit) >= 0) - cnt_high_merit--; - } - - if (0 == v_lose && 0 == m_lose) - { - mpz_out_str (stdout, 10, a); puts (""); fflush (stdout); - if (0 == cnt_high_merit) - break; /* leave loop */ - } - if (v_lose < v_best) - { - v_best = v_lose; - printf ("best (v_lose=%d; m_lose=%d): ", v_lose, m_lose); - mpz_out_str (stdout, 10, a); puts (""); fflush (stdout); - } - if (m_lose < m_best) - { - m_best = m_lose; - printf ("best (v_lose=%d; m_lose=%d): ", v_lose, m_lose); - mpz_out_str (stdout, 10, a); puts (""); fflush (stdout); - } - } - - mpz_clear (m); - mpz_clear (a); - for (f = 0; f < DIMS-1; f++) - mpf_clear (v[f]); - mpf_clear (f_merit); - mpf_clear (low_merit); - mpf_clear (high_merit); - - printf ("done.\n"); - return 0; -} diff --git a/gmp/tests/rand/gen.c b/gmp/tests/rand/gen.c deleted file mode 100755 index 47b18b7..0000000 --- a/gmp/tests/rand/gen.c +++ /dev/null @@ -1,485 +0,0 @@ -/* gen.c -- Generate pseudorandom numbers. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* Examples: - - $ gen 10 -10 integers 0 <= X < 2^32 generated by mpz_urandomb() - - $ gen -f mpf_urandomb 10 -10 real numbers 0 <= X < 1 - - $ gen -z 127 10 -10 integers 0 <= X < 2^127 - - $ gen -f mpf_urandomb -x .9,1 10 -10 real numbers 0 <= X < .9 - - $ gen -s 1 10 -10 integers, sequence seeded with 1 - -*/ - -#include -#include -#include -#include -#include -#include -#include - -#if !HAVE_DECL_OPTARG -extern char *optarg; -extern int optind, opterr; -#endif - -#include "gmp.h" -#include "gmp-impl.h" - -int main (argc, argv) - int argc; - char *argv[]; -{ - const char usage[] = - "usage: gen [-bhpq] [-a n] [-c a,c,m2exp] [-C a,c,m] [-f func] [-g alg] [-m n] [-s n] " \ - "[-x f,t] [-z n] [n]\n" \ - " n number of random numbers to generate\n" \ - " -a n ASCII output in radix n (default, with n=10)\n" \ - " -b binary output\n" \ - " -c a,c,m2exp use supplied LC scheme\n" \ - " -C a,c,m use supplied LC scheme\n" \ - " -f func random function, one of\n" \ - " mpz_urandomb (default), mpz_urandomm, mpf_urandomb, rand, random\n" \ - " -g alg algorithm, one of lc (default), bbs\n" \ - " -h print this text and exit\n" \ - " -m n maximum size of generated number plus 1 (0<= X < n) for mpz_urandomm\n" \ - " -p print used seed on stderr\n" \ - " -q quiet, no output\n" \ - " -s n initial seed (default: output from time(3))\n" \ - " -x f,t exclude all numbers f <= x <= t\n" \ - " -z n size in bits of generated numbers (0<= X <2^n) (default 32)\n" \ - ""; - - unsigned long int f; - unsigned long int n = 0; - unsigned long int seed; - unsigned long int m2exp = 0; - unsigned int size = 32; - int seed_from_user = 0; - int ascout = 1, binout = 0, printseed = 0; - int output_radix = 10; - int lc_scheme_from_user = 0; - int quiet_flag = 0; - mpz_t z_seed; - mpz_t z1; - mpf_t f1; - gmp_randstate_t rstate; - int c, i; - double drand; - long lrand; - int do_exclude = 0; - mpf_t f_xf, f_xt; /* numbers to exclude from sequence */ - char *str_xf, *str_xt; /* numbers to exclude from sequence */ - char *str_a, *str_adder, *str_m; - mpz_t z_a, z_m, z_mmax; - unsigned long int ul_adder; - - enum - { - RFUNC_mpz_urandomb = 0, - RFUNC_mpz_urandomm, - RFUNC_mpf_urandomb, - RFUNC_rand, - RFUNC_random, - } rfunc = RFUNC_mpz_urandomb; - char *rfunc_str[] = { "mpz_urandomb", "mpz_urandomm", "mpf_urandomb", - "rand", "random" }; - gmp_randalg_t ralg = GMP_RAND_ALG_DEFAULT; - char *ralg_str[] = { "lc", "bbs" }; - - mpf_init (f_xf); - mpf_init (f_xt); - mpf_init (f1); - mpz_init (z1); - mpz_init (z_seed); - mpz_init_set_ui (z_mmax, 0); - - - while ((c = getopt (argc, argv, "a:bc:C:f:g:hm:n:pqs:z:x:")) != -1) - switch (c) - { - case 'a': - ascout = 1; - binout = 0; - output_radix = atoi (optarg); - break; - - case 'b': - ascout = 0; - binout = 1; - break; - - case 'c': /* User supplied LC scheme: a,c,m2exp */ - case 'C': /* User supplied LC scheme: a,c,m */ - if (NULL == (str_a = strtok (optarg, ",")) - || NULL == (str_adder = strtok (NULL, ",")) - || NULL == (str_m = strtok (NULL, ","))) - { - fprintf (stderr, "gen: bad LC scheme parameters: %s\n", optarg); - exit (1); - } -#ifdef HAVE_STRTOUL - ul_adder = strtoul (str_adder, NULL, 0); -#elif HAVE_STRTOL - ul_adder = (unsigned long int) strtol (str_adder, NULL, 0); -#else - ul_adder = (unsigned long int) atoi (str_adder); -#endif - - if (mpz_init_set_str (z_a, str_a, 0)) - { - fprintf (stderr, "gen: bad LC scheme parameter `a': %s\n", str_a); - exit (1); - } - if (ULONG_MAX == ul_adder) - { - fprintf (stderr, "gen: bad LC scheme parameter `c': %s\n", - str_adder); - exit (1); - } - if (c == 'c') - m2exp = atol (str_m); - else - mpz_init_set_str (z_m, str_m, 0); - - lc_scheme_from_user = 1; - break; - - - case 'f': - rfunc = -1; - for (f = 0; f < sizeof (rfunc_str) / sizeof (*rfunc_str); f++) - if (!strcmp (optarg, rfunc_str[f])) - { - rfunc = f; - break; - } - if (rfunc == -1) - { - fputs (usage, stderr); - exit (1); - } - break; - - case 'g': /* algorithm */ - ralg = -1; - for (f = 0; f < sizeof (ralg_str) / sizeof (*ralg_str); f++) - if (!strcmp (optarg, ralg_str[f])) - { - ralg = f; - break; - } - if (ralg == -1) - { - fputs (usage, stderr); - exit (1); - } - break; - - case 'm': /* max for mpz_urandomm() */ - if (mpz_set_str (z_mmax, optarg, 0)) - { - fprintf (stderr, "gen: bad max value: %s\n", optarg); - exit (1); - } - break; - - case 'p': /* print seed on stderr */ - printseed = 1; - break; - - case 'q': /* quiet */ - quiet_flag = 1; - break; - - case 's': /* user provided seed */ - if (mpz_set_str (z_seed, optarg, 0)) - { - fprintf (stderr, "gen: bad seed argument %s\n", optarg); - exit (1); - } - seed_from_user = 1; - break; - - case 'z': - size = atoi (optarg); - if (size < 1) - { - fprintf (stderr, "gen: bad size argument (-z %u)\n", size); - exit (1); - } - break; - - case 'x': /* Exclude. from,to */ - str_xf = optarg; - str_xt = strchr (optarg, ','); - if (NULL == str_xt) - { - fprintf (stderr, "gen: bad exclusion parameters: %s\n", optarg); - exit (1); - } - *str_xt++ = '\0'; - do_exclude = 1; - break; - - case 'h': - case '?': - default: - fputs (usage, stderr); - exit (1); - } - argc -= optind; - argv += optind; - - if (! seed_from_user) - mpz_set_ui (z_seed, (unsigned long int) time (NULL)); - seed = mpz_get_ui (z_seed); - if (printseed) - { - fprintf (stderr, "gen: seed used: "); - mpz_out_str (stderr, output_radix, z_seed); - fprintf (stderr, "\n"); - } - - mpf_set_prec (f1, size); - - /* init random state and plant seed */ - switch (rfunc) - { - case RFUNC_mpf_urandomb: -#if 0 - /* Don't init a too small generator. */ - size = PREC (f1) * BITS_PER_MP_LIMB; - /* Fall through. */ -#endif - case RFUNC_mpz_urandomb: - case RFUNC_mpz_urandomm: - if (! lc_scheme_from_user) - { - gmp_randinit (rstate, ralg, MIN (128, size)); - } - else - { - if (m2exp != 0) - gmp_randinit_lc_2exp (rstate, z_a, ul_adder, m2exp); - else - gmp_randinit_lc (rstate, z_a, ul_adder, z_m); - } - - if (gmp_errno != GMP_ERROR_NONE) - { - if (gmp_errno & GMP_ERROR_INVALID_ARGUMENT) - fprintf (stderr, "gen: asking for too big random state\n"); - if (gmp_errno & GMP_ERROR_UNSUPPORTED_ARGUMENT) - fprintf (stderr, "gen: unsupported algorithm\n"); - exit (1); - } - gmp_randseed (rstate, z_seed); - break; - - case RFUNC_rand: - srand (seed); - break; - - case RFUNC_random: -#ifdef __FreeBSD__ /* FIXME */ - if (seed_from_user) - srandom (seed); - else - srandomdev (); -#else - fprintf (stderr, "gen: unsupported algorithm\n"); -#endif - break; - - default: - fprintf (stderr, "gen: random function not implemented\n"); - exit (1); - } - - /* set up excludes */ - if (do_exclude) - switch (rfunc) - { - case RFUNC_mpf_urandomb: - - if (mpf_set_str (f_xf, str_xf, 10) || - mpf_set_str (f_xt, str_xt, 10)) - { - fprintf (stderr, "gen: bad exclusion-from (\"%s\") " \ - "or exclusion-to (\"%s\") string. no exclusion done.\n", - str_xf, str_xt); - do_exclude = 0; - } - break; - - default: - fprintf (stderr, "gen: exclusion not implemented for chosen " \ - "randomization function. all numbers included in sequence.\n"); - } - - /* generate and print */ - if (argc > 0) - { -#if HAVE_STRTOUL - n = strtoul (argv[0], (char **) NULL, 10); -#elif HAVE_STRTOL - n = (unsigned long int) strtol (argv[0], (char **) NULL, 10); -#else - n = (unsigned long int) atoi (argv[0]); -#endif - } - - for (f = 0; n == 0 || f < n; f++) - { - switch (rfunc) - { - case RFUNC_mpz_urandomb: - mpz_urandomb (z1, rstate, size); - if (quiet_flag) - break; - if (binout) - { - /*fwrite ((unsigned int *) z1->_mp_d, 4, 1, stdout);*/ - fprintf (stderr, "gen: binary output for mpz_urandom* is broken\n"); - exit (1); - } - else - { - mpz_out_str (stdout, output_radix, z1); - puts (""); - } - break; - - case RFUNC_mpz_urandomm: - mpz_urandomm (z1, rstate, z_mmax); - if (quiet_flag) - break; - if (binout) - { - /*fwrite ((unsigned int *) z1->_mp_d, 4, 1, stdout);*/ - fprintf (stderr, "gen: binary output for mpz_urandom* is broken\n"); - exit (1); - } - else - { - mpz_out_str (stdout, output_radix, z1); - puts (""); - } - break; - - case RFUNC_mpf_urandomb: - mpf_urandomb (f1, rstate, size); - if (do_exclude) - if (mpf_cmp (f1, f_xf) >= 0 && mpf_cmp (f1, f_xt) <= 0) - break; - if (quiet_flag) - break; - if (binout) - { - fprintf (stderr, "gen: binary output for floating point numbers "\ - "not implemented\n"); - exit (1); - } - else - { - mpf_out_str (stdout, output_radix, 0, f1); - puts (""); - } - break; - - case RFUNC_rand: - i = rand (); -#ifdef FLOAT_OUTPUT - if (i) - drand = (double) i / (double) RAND_MAX; - else - drand = 0.0; - if (quiet_flag) - break; - if (binout) - fwrite (&drand, sizeof (drand), 1, stdout); - else - printf ("%e\n", drand); -#else - if (quiet_flag) - break; - if (binout) - fwrite (&i, sizeof (i), 1, stdout); - else - printf ("%d\n", i); -#endif - break; - - case RFUNC_random: - lrand = random (); - if (lrand) - drand = (double) lrand / (double) 0x7fffffff; - else - drand = 0; - if (quiet_flag) - break; - if (binout) - fwrite (&drand, sizeof (drand), 1, stdout); - else - printf ("%e\n", drand); - break; - - default: - fprintf (stderr, "gen: random function not implemented\n"); - exit (1); - } - - } - - /* clean up */ - switch (rfunc) - { - case RFUNC_mpz_urandomb: - case RFUNC_mpf_urandomb: - gmp_randclear (rstate); - break; - default: - break; - } - mpf_clear (f1); - mpf_clear (f_xf); - mpf_clear (f_xt); - mpz_clear (z1); - mpz_clear (z_seed); - - return 0; -} - -static void *debug_dummyz = mpz_dump; -static void *debug_dummyf = mpf_dump; diff --git a/gmp/tests/rand/gmpstat.h b/gmp/tests/rand/gmpstat.h deleted file mode 100755 index ab0fd80..0000000 --- a/gmp/tests/rand/gmpstat.h +++ /dev/null @@ -1,78 +0,0 @@ -/* gmpstat.h */ - -/* -Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* This file requires the following header files: gmp.h */ - -#ifndef __GMPSTAT_H__ -#define __GMPSTAT_H__ - -/* Global debug flag. FIXME: Remove. */ -extern int g_debug; -#define DEBUG_1 0 -#define DEBUG_2 1 - -/* Max number of dimensions in spectral test. FIXME: Makw dynamic. */ -#define GMP_SPECT_MAXT 10 - -void -mpf_freqt (mpf_t Kp, - mpf_t Km, - mpf_t X[], - const unsigned long int n); -unsigned long int -mpz_freqt (mpf_t V, - mpz_t X[], - unsigned int imax, - const unsigned long int n); - -/* Low level functions. */ -void -ks (mpf_t Kp, - mpf_t Km, - mpf_t X[], - void (P) (mpf_t, mpf_t), - const unsigned long int n); - -void -ks_table (mpf_t p, mpf_t val, const unsigned int n); - -void -x2_table (double t[], - unsigned int v); - -void -spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m); -void -vz_dot (mpz_t rop, mpz_t V1[], mpz_t V2[], unsigned int n); -void -f_floor (mpf_t rop, mpf_t op); - -void -merit (mpf_t rop, unsigned int t, mpf_t v, mpz_t m); -double -merit_u (unsigned int t, mpf_t v, mpz_t m); - -/* From separate source files: */ -void zdiv_round (mpz_t rop, mpz_t n, mpz_t d); - -#endif /* !__GMPSTAT_H__ */ diff --git a/gmp/tests/rand/spect.c b/gmp/tests/rand/spect.c deleted file mode 100755 index 6a6592a..0000000 --- a/gmp/tests/rand/spect.c +++ /dev/null @@ -1,140 +0,0 @@ -/* spect.c -- the spectral test */ - -/* -Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* T is upper dimension. Z_A is the LC multiplier, which is - relatively prime to Z_M, the LC modulus. The result is put in - rop[] with v[t] in rop[t-2]. */ - -/* BUGS: Due to lazy allocation scheme, maximum T is hard coded to MAXT. */ - -#include -#include -#include -#include -#include "gmp.h" - -#include "gmpstat.h" - -int g_debug = 0; - -int -main (int argc, char *argv[]) -{ - const char usage[] = "usage: spect [-d] a m n\n"; - int c; - unsigned int n; - mpz_t a, m; - mpf_t res[GMP_SPECT_MAXT], res_min[GMP_SPECT_MAXT], f_tmp; - register int f; - - - mpz_init (a); - mpz_init (m); - for (f = 0; f < GMP_SPECT_MAXT; f++) - { - mpf_init (res[f]); - mpf_init (res_min[f]); - } - mpf_init (f_tmp); - mpf_set_ui (res_min[0], 32768); /* 2^15 */ - mpf_set_ui (res_min[1], 1024); /* 2^10 */ - mpf_set_ui (res_min[2], 256); /* 2^8 */ - mpf_set_ui (res_min[3], 64); /* 2^6 */ - mpf_set_ui (res_min[4], 32); /* 2^5 */ - - while ((c = getopt (argc, argv, "dh")) != -1) - switch (c) - { - case 'd': /* debug */ - g_debug++; - break; - case 'h': - default: - fputs (usage, stderr); - exit (1); - } - argc -= optind; - argv += optind; - - if (argc < 3) - { - fputs (usage, stderr); - exit (1); - } - - mpz_set_str (a, argv[0], 0); - mpz_set_str (m, argv[1], 0); - n = (unsigned int) atoi (argv[2]); - if (n + 1 > GMP_SPECT_MAXT) - n = GMP_SPECT_MAXT + 1; - - spectral_test (res, n, a, m); - - for (f = 0; f < n - 1; f++) - { - /* print v */ - printf ("%d: v = ", f + 2); - mpf_out_str (stdout, 10, 4, res[f]); - -#ifdef PRINT_RAISED_BY_TWO_AS_WELL - printf (" (^2 = "); - mpf_mul (f_tmp, res[f], res[f]); - mpf_out_str (stdout, 10, 4, f_tmp); - printf (")"); -#endif /* PRINT_RAISED_BY_TWO_AS_WELL */ - - /* print merit */ - printf (" m = "); - merit (f_tmp, f + 2, res[f], m); - mpf_out_str (stdout, 10, 4, f_tmp); - - if (mpf_cmp (res[f], res_min[f]) < 0) - printf ("\t*** v too low ***"); - if (mpf_get_d (f_tmp) < .1) - printf ("\t*** merit too low ***"); - - puts (""); - } - - mpz_clear (a); - mpz_clear (m); - for (f = 0; f < GMP_SPECT_MAXT; f++) - { - mpf_clear (res[f]); - mpf_clear (res_min[f]); - } - mpf_clear (f_tmp); - - return 0; -} - - -void -debug_foo() -{ - if (0) - { - mpz_dump (0); - mpf_dump (0); - } -} diff --git a/gmp/tests/rand/stat.c b/gmp/tests/rand/stat.c deleted file mode 100755 index bda1a44..0000000 --- a/gmp/tests/rand/stat.c +++ /dev/null @@ -1,415 +0,0 @@ -/* stat.c -- statistical tests of random number sequences. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* Examples: - - $ gen 1000 | stat -Test 1000 real numbers. - - $ gen 30000 | stat -2 1000 -Test 1000 real numbers 30 times and then test the 30 results in a -``second level''. - - $ gen -f mpz_urandomb 1000 | stat -i 0xffffffff -Test 1000 integers 0 <= X <= 2^32-1. - - $ gen -f mpz_urandomb -z 34 1000 | stat -i 0x3ffffffff -Test 1000 integers 0 <= X <= 2^34-1. - -*/ - -#include -#include -#include -#include -#include "gmp.h" -#include "gmpstat.h" - -#if !HAVE_DECL_OPTARG -extern char *optarg; -extern int optind, opterr; -#endif - -#define FVECSIZ (100000L) - -int g_debug = 0; - -static void -print_ks_results (mpf_t f_p, mpf_t f_p_prob, - mpf_t f_m, mpf_t f_m_prob, - FILE *fp) -{ - double p, pp, m, mp; - - p = mpf_get_d (f_p); - m = mpf_get_d (f_m); - pp = mpf_get_d (f_p_prob); - mp = mpf_get_d (f_m_prob); - - fprintf (fp, "%.4f (%.0f%%)\t", p, pp * 100.0); - fprintf (fp, "%.4f (%.0f%%)\n", m, mp * 100.0); -} - -static void -print_x2_table (unsigned int v, FILE *fp) -{ - double t[7]; - int f; - - - fprintf (fp, "Chi-square table for v=%u\n", v); - fprintf (fp, "1%%\t5%%\t25%%\t50%%\t75%%\t95%%\t99%%\n"); - x2_table (t, v); - for (f = 0; f < 7; f++) - fprintf (fp, "%.2f\t", t[f]); - fputs ("\n", fp); -} - - - -/* Pks () -- Distribution function for KS results with a big n (like 1000 - or so): F(x) = 1 - pow(e, -2*x^2) [Knuth, vol 2, p.51]. */ -/* gnuplot: plot [0:1] Pks(x), Pks(x) = 1-exp(-2*x**2) */ - -static void -Pks (mpf_t p, mpf_t x) -{ - double dt; /* temp double */ - - mpf_set (p, x); - mpf_mul (p, p, p); /* p = x^2 */ - mpf_mul_ui (p, p, 2); /* p = 2*x^2 */ - mpf_neg (p, p); /* p = -2*x^2 */ - /* No pow() in gmp. Use doubles. */ - /* FIXME: Use exp()? */ - dt = pow (M_E, mpf_get_d (p)); - mpf_set_d (p, dt); - mpf_ui_sub (p, 1, p); -} - -/* f_freq() -- frequency test on real numbers 0<=f<1*/ -static void -f_freq (const unsigned l1runs, const unsigned l2runs, - mpf_t fvec[], const unsigned long n) -{ - unsigned f; - mpf_t f_p, f_p_prob; - mpf_t f_m, f_m_prob; - mpf_t *l1res; /* level 1 result array */ - - mpf_init (f_p); mpf_init (f_m); - mpf_init (f_p_prob); mpf_init (f_m_prob); - - - /* Allocate space for 1st level results. */ - l1res = (mpf_t *) malloc (l2runs * 2 * sizeof (mpf_t)); - if (NULL == l1res) - { - fprintf (stderr, "stat: malloc failure\n"); - exit (1); - } - - printf ("\nEquidistribution/Frequency test on real numbers (0<=X<1):\n"); - printf ("\tKp\t\tKm\n"); - - for (f = 0; f < l2runs; f++) - { - /* f_printvec (fvec, n); */ - mpf_freqt (f_p, f_m, fvec + f * n, n); - - /* what's the probability of getting these results? */ - ks_table (f_p_prob, f_p, n); - ks_table (f_m_prob, f_m, n); - - if (l1runs == 0) - { - /*printf ("%u:\t", f + 1);*/ - print_ks_results (f_p, f_p_prob, f_m, f_m_prob, stdout); - } - else - { - /* save result */ - mpf_init_set (l1res[f], f_p); - mpf_init_set (l1res[f + l2runs], f_m); - } - } - - /* Now, apply the KS test on the results from the 1st level rounds - with the distribution - F(x) = 1 - pow(e, -2*x^2) [Knuth, vol 2, p.51] */ - - if (l1runs != 0) - { - /*printf ("-------------------------------------\n");*/ - - /* The Kp's. */ - ks (f_p, f_m, l1res, Pks, l2runs); - ks_table (f_p_prob, f_p, l2runs); - ks_table (f_m_prob, f_m, l2runs); - printf ("Kp:\t"); - print_ks_results (f_p, f_p_prob, f_m, f_m_prob, stdout); - - /* The Km's. */ - ks (f_p, f_m, l1res + l2runs, Pks, l2runs); - ks_table (f_p_prob, f_p, l2runs); - ks_table (f_m_prob, f_m, l2runs); - printf ("Km:\t"); - print_ks_results (f_p, f_p_prob, f_m, f_m_prob, stdout); - } - - mpf_clear (f_p); mpf_clear (f_m); - mpf_clear (f_p_prob); mpf_clear (f_m_prob); - free (l1res); -} - -/* z_freq(l1runs, l2runs, zvec, n, max) -- frequency test on integers - 0<=z<=MAX */ -static void -z_freq (const unsigned l1runs, - const unsigned l2runs, - mpz_t zvec[], - const unsigned long n, - unsigned int max) -{ - mpf_t V; /* result */ - double d_V; /* result as a double */ - - mpf_init (V); - - - printf ("\nEquidistribution/Frequency test on integers (0<=X<=%u):\n", max); - print_x2_table (max, stdout); - - mpz_freqt (V, zvec, max, n); - - d_V = mpf_get_d (V); - printf ("V = %.2f (n = %lu)\n", d_V, n); - - mpf_clear (V); -} - -unsigned int stat_debug = 0; - -int -main (argc, argv) - int argc; - char *argv[]; -{ - const char usage[] = - "usage: stat [-d] [-2 runs] [-i max | -r max] [file]\n" \ - " file filename\n" \ - " -2 runs perform 2-level test with RUNS runs on 1st level\n" \ - " -d increase debugging level\n" \ - " -i max input is integers 0 <= Z <= MAX\n" \ - " -r max input is real numbers 0 <= R < 1 and use MAX as\n" \ - " maximum value when converting real numbers to integers\n" \ - ""; - - mpf_t fvec[FVECSIZ]; - mpz_t zvec[FVECSIZ]; - unsigned long int f, n, vecentries; - char *filen; - FILE *fp; - int c; - int omitoutput = 0; - int realinput = -1; /* 1: input is real numbers 0<=R<1; - 0: input is integers 0 <= Z <= MAX. */ - long l1runs = 0, /* 1st level runs */ - l2runs = 1; /* 2nd level runs */ - mpf_t f_temp; - mpz_t z_imax; /* max value when converting between - real number and integer. */ - mpf_t f_imax_plus1; /* f_imax + 1 stored in an mpf_t for - convenience */ - mpf_t f_imax_minus1; /* f_imax - 1 stored in an mpf_t for - convenience */ - - - mpf_init (f_temp); - mpz_init_set_ui (z_imax, 0x7fffffff); - mpf_init (f_imax_plus1); - mpf_init (f_imax_minus1); - - while ((c = getopt (argc, argv, "d2:i:r:")) != -1) - switch (c) - { - case '2': - l1runs = atol (optarg); - l2runs = -1; /* set later on */ - break; - case 'd': /* increase debug level */ - stat_debug++; - break; - case 'i': - if (1 == realinput) - { - fputs ("stat: options -i and -r are mutually exclusive\n", stderr); - exit (1); - } - if (mpz_set_str (z_imax, optarg, 0)) - { - fprintf (stderr, "stat: bad max value %s\n", optarg); - exit (1); - } - realinput = 0; - break; - case 'r': - if (0 == realinput) - { - fputs ("stat: options -i and -r are mutually exclusive\n", stderr); - exit (1); - } - if (mpz_set_str (z_imax, optarg, 0)) - { - fprintf (stderr, "stat: bad max value %s\n", optarg); - exit (1); - } - realinput = 1; - break; - case 'o': - omitoutput = atoi (optarg); - break; - case '?': - default: - fputs (usage, stderr); - exit (1); - } - argc -= optind; - argv += optind; - - if (argc < 1) - fp = stdin; - else - filen = argv[0]; - - if (fp != stdin) - if (NULL == (fp = fopen (filen, "r"))) - { - perror (filen); - exit (1); - } - - if (-1 == realinput) - realinput = 1; /* default is real numbers */ - - /* read file and fill appropriate vec */ - if (1 == realinput) /* real input */ - { - for (f = 0; f < FVECSIZ ; f++) - { - mpf_init (fvec[f]); - if (!mpf_inp_str (fvec[f], fp, 10)) - break; - } - } - else /* integer input */ - { - for (f = 0; f < FVECSIZ ; f++) - { - mpz_init (zvec[f]); - if (!mpz_inp_str (zvec[f], fp, 10)) - break; - } - } - vecentries = n = f; /* number of entries read */ - fclose (fp); - - if (FVECSIZ == f) - fprintf (stderr, "stat: warning: discarding input due to lazy allocation "\ - "of only %ld entries. sorry.\n", FVECSIZ); - - printf ("Got %lu numbers.\n", n); - - /* convert and fill the other vec */ - /* since fvec[] contains 0<=f<1 and we want ivec[] to contain - 0<=z<=imax and we are truncating all fractions when - converting float to int, we have to add 1 to imax.*/ - mpf_set_z (f_imax_plus1, z_imax); - mpf_add_ui (f_imax_plus1, f_imax_plus1, 1); - if (1 == realinput) /* fill zvec[] */ - { - for (f = 0; f < n; f++) - { - mpf_mul (f_temp, fvec[f], f_imax_plus1); - mpz_init (zvec[f]); - mpz_set_f (zvec[f], f_temp); /* truncating fraction */ - if (stat_debug > 1) - { - mpz_out_str (stderr, 10, zvec[f]); - fputs ("\n", stderr); - } - } - } - else /* integer input; fill fvec[] */ - { - /* mpf_set_z (f_imax_minus1, z_imax); - mpf_sub_ui (f_imax_minus1, f_imax_minus1, 1);*/ - for (f = 0; f < n; f++) - { - mpf_init (fvec[f]); - mpf_set_z (fvec[f], zvec[f]); - mpf_div (fvec[f], fvec[f], f_imax_plus1); - if (stat_debug > 1) - { - mpf_out_str (stderr, 10, 0, fvec[f]); - fputs ("\n", stderr); - } - } - } - - /* 2 levels? */ - if (1 != l2runs) - { - l2runs = n / l1runs; - printf ("Doing %ld second level rounds "\ - "with %ld entries in each round", l2runs, l1runs); - if (n % l1runs) - printf (" (discarding %ld entr%s)", n % l1runs, - n % l1runs == 1 ? "y" : "ies"); - puts ("."); - n = l1runs; - } - -#ifndef DONT_FFREQ - f_freq (l1runs, l2runs, fvec, n); -#endif -#ifdef DO_ZFREQ - z_freq (l1runs, l2runs, zvec, n, mpz_get_ui (z_imax)); -#endif - - mpf_clear (f_temp); mpz_clear (z_imax); - mpf_clear (f_imax_plus1); - mpf_clear (f_imax_minus1); - for (f = 0; f < vecentries; f++) - { - mpf_clear (fvec[f]); - mpz_clear (zvec[f]); - } - - return 0; -} - - - - - diff --git a/gmp/tests/rand/statlib.c b/gmp/tests/rand/statlib.c deleted file mode 100755 index b1088c8..0000000 --- a/gmp/tests/rand/statlib.c +++ /dev/null @@ -1,841 +0,0 @@ -/* statlib.c -- Statistical functions for testing the randomness of - number sequences. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* The theories for these functions are taken from D. Knuth's "The Art -of Computer Programming: Volume 2, Seminumerical Algorithms", Third -Edition, Addison Wesley, 1998. */ - -/* Implementation notes. - -The Kolmogorov-Smirnov test. - -Eq. (13) in Knuth, p. 50, says that if X1, X2, ..., Xn are independent -observations arranged into ascending order - - Kp = sqr(n) * max(j/n - F(Xj)) for all 1<=j<=n - Km = sqr(n) * max(F(Xj) - (j-1)/n)) for all 1<=j<=n - -where F(x) = Pr(X <= x) = probability that (X <= x), which for a -uniformly distributed random real number between zero and one is -exactly the number itself (x). - - -The answer to exercise 23 gives the following implementation, which -doesn't need the observations to be sorted in ascending order: - -for (k = 0; k < m; k++) - a[k] = 1.0 - b[k] = 0.0 - c[k] = 0 - -for (each observation Xj) - Y = F(Xj) - k = floor (m * Y) - a[k] = min (a[k], Y) - b[k] = max (b[k], Y) - c[k] += 1 - - j = 0 - rp = rm = 0 - for (k = 0; k < m; k++) - if (c[k] > 0) - rm = max (rm, a[k] - j/n) - j += c[k] - rp = max (rp, j/n - b[k]) - -Kp = sqr (n) * rp -Km = sqr (n) * rm - -*/ - -#include -#include -#include - -#include "gmp.h" -#include "gmpstat.h" - -/* ks (Kp, Km, X, P, n) -- Perform a Kolmogorov-Smirnov test on the N - real numbers between zero and one in vector X. P is the - distribution function, called for each entry in X, which should - calculate the probability of X being greater than or equal to any - number in the sequence. (For a uniformly distributed sequence of - real numbers between zero and one, this is simply equal to X.) The - result is put in Kp and Km. */ - -void -ks (mpf_t Kp, - mpf_t Km, - mpf_t X[], - void (P) (mpf_t, mpf_t), - unsigned long int n) -{ - mpf_t Kt; /* temp */ - mpf_t f_x; - mpf_t f_j; /* j */ - mpf_t f_jnq; /* j/n or (j-1)/n */ - unsigned long int j; - - /* Sort the vector in ascending order. */ - qsort (X, n, sizeof (__mpf_struct), mpf_cmp); - - /* K-S test. */ - /* Kp = sqr(n) * max(j/n - F(Xj)) for all 1<=j<=n - Km = sqr(n) * max(F(Xj) - (j-1)/n)) for all 1<=j<=n - */ - - mpf_init (Kt); mpf_init (f_x); mpf_init (f_j); mpf_init (f_jnq); - mpf_set_ui (Kp, 0); mpf_set_ui (Km, 0); - for (j = 1; j <= n; j++) - { - P (f_x, X[j-1]); - mpf_set_ui (f_j, j); - - mpf_div_ui (f_jnq, f_j, n); - mpf_sub (Kt, f_jnq, f_x); - if (mpf_cmp (Kt, Kp) > 0) - mpf_set (Kp, Kt); - if (g_debug > DEBUG_2) - { - printf ("j=%lu ", j); - printf ("P()="); mpf_out_str (stdout, 10, 2, f_x); printf ("\t"); - - printf ("jnq="); mpf_out_str (stdout, 10, 2, f_jnq); printf (" "); - printf ("diff="); mpf_out_str (stdout, 10, 2, Kt); printf (" "); - printf ("Kp="); mpf_out_str (stdout, 10, 2, Kp); printf ("\t"); - } - mpf_sub_ui (f_j, f_j, 1); - mpf_div_ui (f_jnq, f_j, n); - mpf_sub (Kt, f_x, f_jnq); - if (mpf_cmp (Kt, Km) > 0) - mpf_set (Km, Kt); - - if (g_debug > DEBUG_2) - { - printf ("jnq="); mpf_out_str (stdout, 10, 2, f_jnq); printf (" "); - printf ("diff="); mpf_out_str (stdout, 10, 2, Kt); printf (" "); - printf ("Km="); mpf_out_str (stdout, 10, 2, Km); printf (" "); - printf ("\n"); - } - } - mpf_sqrt_ui (Kt, n); - mpf_mul (Kp, Kp, Kt); - mpf_mul (Km, Km, Kt); - - mpf_clear (Kt); mpf_clear (f_x); mpf_clear (f_j); mpf_clear (f_jnq); -} - -/* ks_table(val, n) -- calculate probability for Kp/Km less than or - equal to VAL with N observations. See [Knuth section 3.3.1] */ - -void -ks_table (mpf_t p, mpf_t val, const unsigned int n) -{ - /* We use Eq. (27), Knuth p.58, skipping O(1/n) for simplicity. - This shortcut will result in too high probabilities, especially - when n is small. - - Pr(Kp(n) <= s) = 1 - pow(e, -2*s^2) * (1 - 2/3*s/sqrt(n) + O(1/n)) */ - - /* We have 's' in variable VAL and store the result in P. */ - - mpf_t t1, t2; - - mpf_init (t1); mpf_init (t2); - - /* t1 = 1 - 2/3 * s/sqrt(n) */ - mpf_sqrt_ui (t1, n); - mpf_div (t1, val, t1); - mpf_mul_ui (t1, t1, 2); - mpf_div_ui (t1, t1, 3); - mpf_ui_sub (t1, 1, t1); - - /* t2 = pow(e, -2*s^2) */ -#ifndef OLDGMP - mpf_pow_ui (t2, val, 2); /* t2 = s^2 */ - mpf_set_d (t2, exp (-(2.0 * mpf_get_d (t2)))); -#else - /* hmmm, gmp doesn't have pow() for floats. use doubles. */ - mpf_set_d (t2, pow (M_E, -(2 * pow (mpf_get_d (val), 2)))); -#endif - - /* p = 1 - t1 * t2 */ - mpf_mul (t1, t1, t2); - mpf_ui_sub (p, 1, t1); - - mpf_clear (t1); mpf_clear (t2); -} - -static double x2_table_X[][7] = { - { -2.33, -1.64, -.674, 0.0, 0.674, 1.64, 2.33 }, /* x */ - { 5.4289, 2.6896, .454276, 0.0, .454276, 2.6896, 5.4289} /* x^2 */ -}; - -#define _2D3 ((double) .6666666666) - -/* x2_table (t, v, n) -- return chi-square table row for V in T[]. */ -void -x2_table (double t[], - unsigned int v) -{ - int f; - - - /* FIXME: Do a table lookup for v <= 30 since the following formula - [Knuth, vol 2, 3.3.1] is only good for v > 30. */ - - /* value = v + sqrt(2*v) * X[p] + (2/3) * X[p]^2 - 2/3 + O(1/sqrt(t) */ - /* NOTE: The O() term is ignored for simplicity. */ - - for (f = 0; f < 7; f++) - t[f] = - v + - sqrt (2 * v) * x2_table_X[0][f] + - _2D3 * x2_table_X[1][f] - _2D3; -} - - -/* P(p, x) -- Distribution function. Calculate the probability of X -being greater than or equal to any number in the sequence. For a -random real number between zero and one given by a uniformly -distributed random number generator, this is simply equal to X. */ - -static void -P (mpf_t p, mpf_t x) -{ - mpf_set (p, x); -} - -/* mpf_freqt() -- Frequency test using KS on N real numbers between zero - and one. See [Knuth vol 2, p.61]. */ -void -mpf_freqt (mpf_t Kp, - mpf_t Km, - mpf_t X[], - const unsigned long int n) -{ - ks (Kp, Km, X, P, n); -} - - -/* The Chi-square test. Eq. (8) in Knuth vol. 2 says that if Y[] - holds the observations and p[] is the probability for.. (to be - continued!) - - V = 1/n * sum((s=1 to k) Y[s]^2 / p[s]) - n */ - -void -x2 (mpf_t V, /* result */ - unsigned long int X[], /* data */ - unsigned int k, /* #of categories */ - void (P) (mpf_t, unsigned long int, void *), /* probability func */ - void *x, /* extra user data passed to P() */ - unsigned long int n) /* #of samples */ -{ - unsigned int f; - mpf_t f_t, f_t2; /* temp floats */ - - mpf_init (f_t); mpf_init (f_t2); - - - mpf_set_ui (V, 0); - for (f = 0; f < k; f++) - { - if (g_debug > DEBUG_2) - fprintf (stderr, "%u: P()=", f); - mpf_set_ui (f_t, X[f]); - mpf_mul (f_t, f_t, f_t); /* f_t = X[f]^2 */ - P (f_t2, f, x); /* f_t2 = Pr(f) */ - if (g_debug > DEBUG_2) - mpf_out_str (stderr, 10, 2, f_t2); - mpf_div (f_t, f_t, f_t2); - mpf_add (V, V, f_t); - if (g_debug > DEBUG_2) - { - fprintf (stderr, "\tV="); - mpf_out_str (stderr, 10, 2, V); - fprintf (stderr, "\t"); - } - } - if (g_debug > DEBUG_2) - fprintf (stderr, "\n"); - mpf_div_ui (V, V, n); - mpf_sub_ui (V, V, n); - - mpf_clear (f_t); mpf_clear (f_t2); -} - -/* Pzf(p, s, x) -- Probability for category S in mpz_freqt(). It's - 1/d for all S. X is a pointer to an unsigned int holding 'd'. */ -static void -Pzf (mpf_t p, unsigned long int s, void *x) -{ - mpf_set_ui (p, 1); - mpf_div_ui (p, p, *((unsigned int *) x)); -} - -/* mpz_freqt(V, X, imax, n) -- Frequency test on integers. [Knuth, - vol 2, 3.3.2]. Keep IMAX low on this one, since we loop from 0 to - IMAX. 128 or 256 could be nice. - - X[] must not contain numbers outside the range 0 <= X <= IMAX. - - Return value is number of observations actally used, after - discarding entries out of range. - - Since X[] contains integers between zero and IMAX, inclusive, we - have IMAX+1 categories. - - Note that N should be at least 5*IMAX. Result is put in V and can - be compared to output from x2_table (v=IMAX). */ - -unsigned long int -mpz_freqt (mpf_t V, - mpz_t X[], - unsigned int imax, - const unsigned long int n) -{ - unsigned long int *v; /* result */ - unsigned int f; - unsigned int d; /* number of categories = imax+1 */ - unsigned int uitemp; - unsigned long int usedn; - - - d = imax + 1; - - v = (unsigned long int *) calloc (imax + 1, sizeof (unsigned long int)); - if (NULL == v) - { - fprintf (stderr, "mpz_freqt(): out of memory\n"); - exit (1); - } - - /* count */ - usedn = n; /* actual number of observations */ - for (f = 0; f < n; f++) - { - uitemp = mpz_get_ui(X[f]); - if (uitemp > imax) /* sanity check */ - { - if (g_debug) - fprintf (stderr, "mpz_freqt(): warning: input insanity: %u, "\ - "ignored.\n", uitemp); - usedn--; - continue; - } - v[uitemp]++; - } - - if (g_debug > DEBUG_2) - { - fprintf (stderr, "counts:\n"); - for (f = 0; f <= imax; f++) - fprintf (stderr, "%u:\t%lu\n", f, v[f]); - } - - /* chi-square with k=imax+1 and P(x)=1/(imax+1) for all x.*/ - x2 (V, v, d, Pzf, (void *) &d, usedn); - - free (v); - return (usedn); -} - -/* debug dummy to drag in dump funcs */ -void -foo_debug () -{ - if (0) - { - mpf_dump (0); -#ifndef OLDGMP - mpz_dump (0); -#endif - } -} - -/* merit (rop, t, v, m) -- calculate merit for spectral test result in - dimension T, see Knuth p. 105. BUGS: Only valid for 2 <= T <= - 6. */ -void -merit (mpf_t rop, unsigned int t, mpf_t v, mpz_t m) -{ - int f; - mpf_t f_m, f_const, f_pi; - - mpf_init (f_m); - mpf_set_z (f_m, m); - mpf_init_set_d (f_const, M_PI); - mpf_init_set_d (f_pi, M_PI); - - switch (t) - { - case 2: /* PI */ - break; - case 3: /* PI * 4/3 */ - mpf_mul_ui (f_const, f_const, 4); - mpf_div_ui (f_const, f_const, 3); - break; - case 4: /* PI^2 * 1/2 */ - mpf_mul (f_const, f_const, f_pi); - mpf_div_ui (f_const, f_const, 2); - break; - case 5: /* PI^2 * 8/15 */ - mpf_mul (f_const, f_const, f_pi); - mpf_mul_ui (f_const, f_const, 8); - mpf_div_ui (f_const, f_const, 15); - break; - case 6: /* PI^3 * 1/6 */ - mpf_mul (f_const, f_const, f_pi); - mpf_mul (f_const, f_const, f_pi); - mpf_div_ui (f_const, f_const, 6); - break; - default: - fprintf (stderr, - "spect (merit): can't calculate merit for dimensions > 6\n"); - mpf_set_ui (f_const, 0); - break; - } - - /* rop = v^t */ - mpf_set (rop, v); - for (f = 1; f < t; f++) - mpf_mul (rop, rop, v); - mpf_mul (rop, rop, f_const); - mpf_div (rop, rop, f_m); - - mpf_clear (f_m); - mpf_clear (f_const); - mpf_clear (f_pi); -} - -double -merit_u (unsigned int t, mpf_t v, mpz_t m) -{ - mpf_t rop; - double res; - - mpf_init (rop); - merit (rop, t, v, m); - res = mpf_get_d (rop); - mpf_clear (rop); - return res; -} - -/* f_floor (rop, op) -- Set rop = floor (op). */ -void -f_floor (mpf_t rop, mpf_t op) -{ - mpz_t z; - - mpz_init (z); - - /* No mpf_floor(). Convert to mpz and back. */ - mpz_set_f (z, op); - mpf_set_z (rop, z); - - mpz_clear (z); -} - - -/* vz_dot (rop, v1, v2, nelem) -- compute dot product of z-vectors V1, - V2. N is number of elements in vectors V1 and V2. */ - -void -vz_dot (mpz_t rop, mpz_t V1[], mpz_t V2[], unsigned int n) -{ - mpz_t t; - - mpz_init (t); - mpz_set_ui (rop, 0); - while (n--) - { - mpz_mul (t, V1[n], V2[n]); - mpz_add (rop, rop, t); - } - - mpz_clear (t); -} - -void -spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) -{ - /* Knuth "Seminumerical Algorithms, Third Edition", section 3.3.4 - (pp. 101-103). */ - - /* v[t] = min { sqrt (x[1]^2 + ... + x[t]^2) | - x[1] + a*x[2] + ... + pow (a, t-1) * x[t] is congruent to 0 (mod m) } */ - - - /* Variables. */ - unsigned int ui_t; - unsigned int ui_i, ui_j, ui_k, ui_l; - mpf_t f_tmp1, f_tmp2; - mpz_t tmp1, tmp2, tmp3; - mpz_t U[GMP_SPECT_MAXT][GMP_SPECT_MAXT], - V[GMP_SPECT_MAXT][GMP_SPECT_MAXT], - X[GMP_SPECT_MAXT], - Y[GMP_SPECT_MAXT], - Z[GMP_SPECT_MAXT]; - mpz_t h, hp, r, s, p, pp, q, u, v; - - /* GMP inits. */ - mpf_init (f_tmp1); - mpf_init (f_tmp2); - for (ui_i = 0; ui_i < GMP_SPECT_MAXT; ui_i++) - { - for (ui_j = 0; ui_j < GMP_SPECT_MAXT; ui_j++) - { - mpz_init_set_ui (U[ui_i][ui_j], 0); - mpz_init_set_ui (V[ui_i][ui_j], 0); - } - mpz_init_set_ui (X[ui_i], 0); - mpz_init_set_ui (Y[ui_i], 0); - mpz_init (Z[ui_i]); - } - mpz_init (tmp1); - mpz_init (tmp2); - mpz_init (tmp3); - mpz_init (h); - mpz_init (hp); - mpz_init (r); - mpz_init (s); - mpz_init (p); - mpz_init (pp); - mpz_init (q); - mpz_init (u); - mpz_init (v); - - /* Implementation inits. */ - if (T > GMP_SPECT_MAXT) - T = GMP_SPECT_MAXT; /* FIXME: Lazy. */ - - /* S1 [Initialize.] */ - ui_t = 2 - 1; /* NOTE: `t' in description == ui_t + 1 - for easy indexing */ - mpz_set (h, a); - mpz_set (hp, m); - mpz_set_ui (p, 1); - mpz_set_ui (pp, 0); - mpz_set (r, a); - mpz_pow_ui (s, a, 2); - mpz_add_ui (s, s, 1); /* s = 1 + a^2 */ - - /* S2 [Euclidean step.] */ - while (1) - { - if (g_debug > DEBUG_1) - { - mpz_mul (tmp1, h, pp); - mpz_mul (tmp2, hp, p); - mpz_sub (tmp1, tmp1, tmp2); - if (mpz_cmpabs (m, tmp1)) - { - printf ("***BUG***: h*pp - hp*p = "); - mpz_out_str (stdout, 10, tmp1); - printf ("\n"); - } - } - if (g_debug > DEBUG_2) - { - printf ("hp = "); - mpz_out_str (stdout, 10, hp); - printf ("\nh = "); - mpz_out_str (stdout, 10, h); - printf ("\n"); - fflush (stdout); - } - - if (mpz_sgn (h)) - mpz_tdiv_q (q, hp, h); /* q = floor(hp/h) */ - else - mpz_set_ui (q, 1); - - if (g_debug > DEBUG_2) - { - printf ("q = "); - mpz_out_str (stdout, 10, q); - printf ("\n"); - fflush (stdout); - } - - mpz_mul (tmp1, q, h); - mpz_sub (u, hp, tmp1); /* u = hp - q*h */ - - mpz_mul (tmp1, q, p); - mpz_sub (v, pp, tmp1); /* v = pp - q*p */ - - mpz_pow_ui (tmp1, u, 2); - mpz_pow_ui (tmp2, v, 2); - mpz_add (tmp1, tmp1, tmp2); - if (mpz_cmp (tmp1, s) < 0) - { - mpz_set (s, tmp1); /* s = u^2 + v^2 */ - mpz_set (hp, h); /* hp = h */ - mpz_set (h, u); /* h = u */ - mpz_set (pp, p); /* pp = p */ - mpz_set (p, v); /* p = v */ - } - else - break; - } - - /* S3 [Compute v2.] */ - mpz_sub (u, u, h); - mpz_sub (v, v, p); - - mpz_pow_ui (tmp1, u, 2); - mpz_pow_ui (tmp2, v, 2); - mpz_add (tmp1, tmp1, tmp2); - if (mpz_cmp (tmp1, s) < 0) - { - mpz_set (s, tmp1); /* s = u^2 + v^2 */ - mpz_set (hp, u); - mpz_set (pp, v); - } - mpf_set_z (f_tmp1, s); - mpf_sqrt (rop[ui_t - 1], f_tmp1); - - /* S4 [Advance t.] */ - mpz_neg (U[0][0], h); - mpz_set (U[0][1], p); - mpz_neg (U[1][0], hp); - mpz_set (U[1][1], pp); - - mpz_set (V[0][0], pp); - mpz_set (V[0][1], hp); - mpz_neg (V[1][0], p); - mpz_neg (V[1][1], h); - if (mpz_cmp_ui (pp, 0) > 0) - { - mpz_neg (V[0][0], V[0][0]); - mpz_neg (V[0][1], V[0][1]); - mpz_neg (V[1][0], V[1][0]); - mpz_neg (V[1][1], V[1][1]); - } - - while (ui_t + 1 != T) /* S4 loop */ - { - ui_t++; - mpz_mul (r, a, r); - mpz_mod (r, r, m); - - /* Add new row and column to U and V. They are initialized with - all elements set to zero, so clearing is not necessary. */ - - mpz_neg (U[ui_t][0], r); /* U: First col in new row. */ - mpz_set_ui (U[ui_t][ui_t], 1); /* U: Last col in new row. */ - - mpz_set (V[ui_t][ui_t], m); /* V: Last col in new row. */ - - /* "Finally, for 1 <= i < t, - set q = round (vi1 * r / m), - vit = vi1*r - q*m, - and Ut=Ut+q*Ui */ - - for (ui_i = 0; ui_i < ui_t; ui_i++) - { - mpz_mul (tmp1, V[ui_i][0], r); /* tmp1=vi1*r */ - zdiv_round (q, tmp1, m); /* q=round(vi1*r/m) */ - mpz_mul (tmp2, q, m); /* tmp2=q*m */ - mpz_sub (V[ui_i][ui_t], tmp1, tmp2); - - for (ui_j = 0; ui_j <= ui_t; ui_j++) /* U[t] = U[t] + q*U[i] */ - { - mpz_mul (tmp1, q, U[ui_i][ui_j]); /* tmp=q*uij */ - mpz_add (U[ui_t][ui_j], U[ui_t][ui_j], tmp1); /* utj = utj + q*uij */ - } - } - - /* s = min (s, zdot (U[t], U[t]) */ - vz_dot (tmp1, U[ui_t], U[ui_t], ui_t + 1); - if (mpz_cmp (tmp1, s) < 0) - mpz_set (s, tmp1); - - ui_k = ui_t; - ui_j = 0; /* WARNING: ui_j no longer a temp. */ - - /* S5 [Transform.] */ - if (g_debug > DEBUG_2) - printf ("(t, k, j, q1, q2, ...)\n"); - do - { - if (g_debug > DEBUG_2) - printf ("(%u, %u, %u", ui_t + 1, ui_k + 1, ui_j + 1); - - for (ui_i = 0; ui_i <= ui_t; ui_i++) - { - if (ui_i != ui_j) - { - vz_dot (tmp1, V[ui_i], V[ui_j], ui_t + 1); /* tmp1=dot(Vi,Vj). */ - mpz_abs (tmp2, tmp1); - mpz_mul_ui (tmp2, tmp2, 2); /* tmp2 = 2*abs(dot(Vi,Vj) */ - vz_dot (tmp3, V[ui_j], V[ui_j], ui_t + 1); /* tmp3=dot(Vj,Vj). */ - - if (mpz_cmp (tmp2, tmp3) > 0) - { - zdiv_round (q, tmp1, tmp3); /* q=round(Vi.Vj/Vj.Vj) */ - if (g_debug > DEBUG_2) - { - printf (", "); - mpz_out_str (stdout, 10, q); - } - - for (ui_l = 0; ui_l <= ui_t; ui_l++) - { - mpz_mul (tmp1, q, V[ui_j][ui_l]); - mpz_sub (V[ui_i][ui_l], V[ui_i][ui_l], tmp1); /* Vi=Vi-q*Vj */ - mpz_mul (tmp1, q, U[ui_i][ui_l]); - mpz_add (U[ui_j][ui_l], U[ui_j][ui_l], tmp1); /* Uj=Uj+q*Ui */ - } - - vz_dot (tmp1, U[ui_j], U[ui_j], ui_t + 1); /* tmp1=dot(Uj,Uj) */ - if (mpz_cmp (tmp1, s) < 0) /* s = min(s,dot(Uj,Uj)) */ - mpz_set (s, tmp1); - ui_k = ui_j; - } - else if (g_debug > DEBUG_2) - printf (", #"); /* 2|Vi.Vj| <= Vj.Vj */ - } - else if (g_debug > DEBUG_2) - printf (", *"); /* i == j */ - } - - if (g_debug > DEBUG_2) - printf (")\n"); - - /* S6 [Advance j.] */ - if (ui_j == ui_t) - ui_j = 0; - else - ui_j++; - } - while (ui_j != ui_k); /* S5 */ - - /* From Knuth p. 104: "The exhaustive search in steps S8-S10 - reduces the value of s only rarely." */ -#ifdef DO_SEARCH - /* S7 [Prepare for search.] */ - /* Find minimum in (x[1], ..., x[t]) satisfying condition - x[k]^2 <= f(y[1], ...,y[t]) * dot(V[k],V[k]) */ - - ui_k = ui_t; - if (g_debug > DEBUG_2) - { - printf ("searching..."); - /*for (f = 0; f < ui_t*/ - fflush (stdout); - } - - /* Z[i] = floor (sqrt (floor (dot(V[i],V[i]) * s / m^2))); */ - mpz_pow_ui (tmp1, m, 2); - mpf_set_z (f_tmp1, tmp1); - mpf_set_z (f_tmp2, s); - mpf_div (f_tmp1, f_tmp2, f_tmp1); /* f_tmp1 = s/m^2 */ - for (ui_i = 0; ui_i <= ui_t; ui_i++) - { - vz_dot (tmp1, V[ui_i], V[ui_i], ui_t + 1); - mpf_set_z (f_tmp2, tmp1); - mpf_mul (f_tmp2, f_tmp2, f_tmp1); - f_floor (f_tmp2, f_tmp2); - mpf_sqrt (f_tmp2, f_tmp2); - mpz_set_f (Z[ui_i], f_tmp2); - } - - /* S8 [Advance X[k].] */ - do - { - if (g_debug > DEBUG_2) - { - printf ("X[%u] = ", ui_k); - mpz_out_str (stdout, 10, X[ui_k]); - printf ("\tZ[%u] = ", ui_k); - mpz_out_str (stdout, 10, Z[ui_k]); - printf ("\n"); - fflush (stdout); - } - - if (mpz_cmp (X[ui_k], Z[ui_k])) - { - mpz_add_ui (X[ui_k], X[ui_k], 1); - for (ui_i = 0; ui_i <= ui_t; ui_i++) - mpz_add (Y[ui_i], Y[ui_i], U[ui_k][ui_i]); - - /* S9 [Advance k.] */ - while (++ui_k <= ui_t) - { - mpz_neg (X[ui_k], Z[ui_k]); - mpz_mul_ui (tmp1, Z[ui_k], 2); - for (ui_i = 0; ui_i <= ui_t; ui_i++) - { - mpz_mul (tmp2, tmp1, U[ui_k][ui_i]); - mpz_sub (Y[ui_i], Y[ui_i], tmp2); - } - } - vz_dot (tmp1, Y, Y, ui_t + 1); - if (mpz_cmp (tmp1, s) < 0) - mpz_set (s, tmp1); - } - } - while (--ui_k); -#endif /* DO_SEARCH */ - mpf_set_z (f_tmp1, s); - mpf_sqrt (rop[ui_t - 1], f_tmp1); -#ifdef DO_SEARCH - if (g_debug > DEBUG_2) - printf ("done.\n"); -#endif /* DO_SEARCH */ - } /* S4 loop */ - - /* Clear GMP variables. */ - - mpf_clear (f_tmp1); - mpf_clear (f_tmp2); - for (ui_i = 0; ui_i < GMP_SPECT_MAXT; ui_i++) - { - for (ui_j = 0; ui_j < GMP_SPECT_MAXT; ui_j++) - { - mpz_clear (U[ui_i][ui_j]); - mpz_clear (V[ui_i][ui_j]); - } - mpz_clear (X[ui_i]); - mpz_clear (Y[ui_i]); - mpz_clear (Z[ui_i]); - } - mpz_clear (tmp1); - mpz_clear (tmp2); - mpz_clear (tmp3); - mpz_clear (h); - mpz_clear (hp); - mpz_clear (r); - mpz_clear (s); - mpz_clear (p); - mpz_clear (pp); - mpz_clear (q); - mpz_clear (u); - mpz_clear (v); - - return; -} - diff --git a/gmp/tests/rand/t-rand.c b/gmp/tests/rand/t-rand.c deleted file mode 100755 index 302e07a..0000000 --- a/gmp/tests/rand/t-rand.c +++ /dev/null @@ -1,299 +0,0 @@ -/* t-rand -- Test random number generators. */ - -/* -Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include -#include "gmp.h" - -#define SEED 1 -#define BASE 16 -#define ENTS 10 /* Number of entries in array when - printing. */ - -/* These were generated by this very program. Do not edit! */ -/* Integers. */ -char *z1[ENTS] = {"0", "1", "1", "1", "1", "0", "1", "1", "1", "1"}; -char *z2[ENTS] = {"0", "3", "1", "3", "3", "0", "3", "3", "3", "1"}; -char *z3[ENTS] = {"4", "3", "1", "7", "3", "0", "3", "3", "3", "1"}; -char *z4[ENTS] = {"c", "3", "1", "f", "b", "8", "3", "3", "3", "1"}; -char *z5[ENTS] = {"1c", "13", "11", "1f", "b", "18", "3", "13", "3", "1"}; - -char *z10[ENTS] = {"29c", "213", "f1", "17f", "12b", "178", "383", "d3", "3a3", "281"}; - -char *z15[ENTS] = {"29c", "1a13", "74f1", "257f", "592b", "4978", "4783", "7cd3", "5ba3", "4681"}; -char *z16[ENTS] = {"29c", "9a13", "74f1", "a57f", "d92b", "4978", "c783", "fcd3", "5ba3", "c681"}; -char *z17[ENTS] = {"51e", "f17a", "54ff", "1a335", "cf65", "5d6f", "583f", "618f", "1bc6", "98ff"}; - -char *z31[ENTS] = {"3aecd515", "13ae8ec6", "518c8090", "81ca077", "70b7134", "7ee78d71", "323a7636", "2122cb1a", "19811941", "41fd605"}; -char *z32[ENTS] = {"baecd515", "13ae8ec6", "518c8090", "881ca077", "870b7134", "7ee78d71", "323a7636", "a122cb1a", "99811941", "841fd605"}; -char *z33[ENTS] = {"1faf4cca", "15d6ef83b", "9095fe72", "1b6a3dff6", "b17cbddd", "16e5209d4", "6f65b12c", "493bbbc6", "abf2a5d5", "6d491a3c"}; - -char *z63[ENTS] = {"48a74f367fa7b5c8", "3ba9e9dc1b263076", "1e0ac84e7678e0fb", "11416581728b3e35", "36ab610523f0f1f7", "3e540e8e95c0eb4b", "439ae16057dbc9d3", "734fb260db243950", "7d3a317effc289bf", "1d80301fb3d1a0d1"}; -char *z64[ENTS] = {"48a74f367fa7b5c8", "bba9e9dc1b263076", "9e0ac84e7678e0fb", "11416581728b3e35", "b6ab610523f0f1f7", "be540e8e95c0eb4b", "439ae16057dbc9d3", "f34fb260db243950", "fd3a317effc289bf", "1d80301fb3d1a0d1"}; -char *z65[ENTS] = {"1ff77710d846d49f0", "1b1411701d709ee10", "31ffa81a208b6af4", "446638d431d3c681", "df5c569d5baa8b55", "197d99ea9bf28e5a0", "191ade09edd94cfae", "194acefa6dde5e18d", "1afc1167c56272d92", "d092994da72f206f"}; - -char *z127[ENTS] = {"2f66ba932aaf58a071fd8f0742a99a0c", "73cfa3c664c9c1753507ca60ec6b8425", "53ea074ca131dec12cd68b8aa8e20278", "3cf5ac8c343532f8a53cc0eb47581f73", "50c11d5869e208aa1b9aa317b8c2d0a9", "b23163c892876472b1ef19642eace09", "489f4c03d41f87509c8d6c90ce674f95", "2ab8748c96aa6762ea1932b44c9d7164", "98cb5591fc05ad31afbbc1d67b90edd", "77848bb991fd0be331adcf1457fbc672"}; -char *z128[ENTS] = {"af66ba932aaf58a071fd8f0742a99a0c", "73cfa3c664c9c1753507ca60ec6b8425", "53ea074ca131dec12cd68b8aa8e20278", "3cf5ac8c343532f8a53cc0eb47581f73", "50c11d5869e208aa1b9aa317b8c2d0a9", "8b23163c892876472b1ef19642eace09", "489f4c03d41f87509c8d6c90ce674f95", "aab8748c96aa6762ea1932b44c9d7164", "98cb5591fc05ad31afbbc1d67b90edd", "f7848bb991fd0be331adcf1457fbc672"}; - -/* Floats. */ -char *f1[ENTS] = {"0.@0", "0.8@0", "0.8@0", "0.8@0", "0.8@0", "0.@0", "0.8@0", "0.8@0", "0.8@0", "0.8@0"}; -char *f2[ENTS] = {"0.@0", "0.c@0", "0.4@0", "0.c@0", "0.c@0", "0.@0", "0.c@0", "0.c@0", "0.c@0", "0.4@0"}; -char *f3[ENTS] = {"0.8@0", "0.6@0", "0.2@0", "0.e@0", "0.6@0", "0.@0", "0.6@0", "0.6@0", "0.6@0", "0.2@0"}; -char *f4[ENTS] = {"0.c@0", "0.3@0", "0.1@0", "0.f@0", "0.b@0", "0.8@0", "0.3@0", "0.3@0", "0.3@0", "0.1@0"}; -char *f5[ENTS] = {"0.e@0", "0.98@0", "0.88@0", "0.f8@0", "0.58@0", "0.c@0", "0.18@0", "0.98@0", "0.18@0", "0.8@-1"}; - -char *f10[ENTS] = {"0.a7@0", "0.84c@0", "0.3c4@0", "0.5fc@0", "0.4ac@0", "0.5e@0", "0.e0c@0", "0.34c@0", "0.e8c@0", "0.a04@0"}; - -char *f15[ENTS] = {"0.538@-1", "0.3426@0", "0.e9e2@0", "0.4afe@0", "0.b256@0", "0.92f@0", "0.8f06@0", "0.f9a6@0", "0.b746@0", "0.8d02@0"}; -char *f16[ENTS] = {"0.29c@-1", "0.9a13@0", "0.74f1@0", "0.a57f@0", "0.d92b@0", "0.4978@0", "0.c783@0", "0.fcd3@0", "0.5ba3@0", "0.c681@0"}; -char *f17[ENTS] = {"0.28f@-1", "0.78bd@0", "0.2a7f8@0", "0.d19a8@0", "0.67b28@0", "0.2eb78@0", "0.2c1f8@0", "0.30c78@0", "0.de3@-1", "0.4c7f8@0"}; - -char *f31[ENTS] = {"0.75d9aa2a@0", "0.275d1d8c@0", "0.a319012@0", "0.103940ee@0", "0.e16e268@-1", "0.fdcf1ae2@0", "0.6474ec6c@0", "0.42459634@0", "0.33023282@0", "0.83fac0a@-1"}; -char *f32[ENTS] = {"0.baecd515@0", "0.13ae8ec6@0", "0.518c809@0", "0.881ca077@0", "0.870b7134@0", "0.7ee78d71@0", "0.323a7636@0", "0.a122cb1a@0", "0.99811941@0", "0.841fd605@0"}; -char *f33[ENTS] = {"0.fd7a665@-1", "0.aeb77c1d8@0", "0.484aff39@0", "0.db51effb@0", "0.58be5eee8@0", "0.b72904ea@0", "0.37b2d896@0", "0.249ddde3@0", "0.55f952ea8@0", "0.36a48d1e@0"}; - -char *f63[ENTS] = {"0.914e9e6cff4f6b9@0", "0.7753d3b8364c60ec@0", "0.3c15909cecf1c1f6@0", "0.2282cb02e5167c6a@0", "0.6d56c20a47e1e3ee@0", "0.7ca81d1d2b81d696@0", "0.8735c2c0afb793a6@0", "0.e69f64c1b64872a@0", "0.fa7462fdff85137e@0", "0.3b00603f67a341a2@0"}; -char *f64[ENTS] = {"0.48a74f367fa7b5c8@0", "0.bba9e9dc1b263076@0", "0.9e0ac84e7678e0fb@0", "0.11416581728b3e35@0", "0.b6ab610523f0f1f7@0", "0.be540e8e95c0eb4b@0", "0.439ae16057dbc9d3@0", "0.f34fb260db24395@0", "0.fd3a317effc289bf@0", "0.1d80301fb3d1a0d1@0"}; -char *f65[ENTS] = {"0.ffbbb886c236a4f8@0", "0.d8a08b80eb84f708@0", "0.18ffd40d1045b57a@0", "0.22331c6a18e9e3408@0", "0.6fae2b4eadd545aa8@0", "0.cbeccf54df9472d@0", "0.c8d6f04f6eca67d7@0", "0.ca5677d36ef2f0c68@0", "0.d7e08b3e2b1396c9@0", "0.68494ca6d39790378@0"}; - -char *f127[ENTS] = {"0.5ecd7526555eb140e3fb1e0e85533418@0", "0.e79f478cc99382ea6a0f94c1d8d7084a@0", "0.a7d40e994263bd8259ad171551c404f@0", "0.79eb5918686a65f14a7981d68eb03ee6@0", "0.a1823ab0d3c411543735462f7185a152@0", "0.16462c791250ec8e563de32c85d59c12@0", "0.913e9807a83f0ea1391ad9219cce9f2a@0", "0.5570e9192d54cec5d4326568993ae2c8@0", "0.13196ab23f80b5a635f7783acf721dba@0", "0.ef09177323fa17c6635b9e28aff78ce4@0"}; -char *f128[ENTS] = {"0.af66ba932aaf58a071fd8f0742a99a0c@0", "0.73cfa3c664c9c1753507ca60ec6b8425@0", "0.53ea074ca131dec12cd68b8aa8e20278@0", "0.3cf5ac8c343532f8a53cc0eb47581f73@0", "0.50c11d5869e208aa1b9aa317b8c2d0a9@0", "0.8b23163c892876472b1ef19642eace09@0", "0.489f4c03d41f87509c8d6c90ce674f95@0", "0.aab8748c96aa6762ea1932b44c9d7164@0", "0.98cb5591fc05ad31afbbc1d67b90edd@-1", "0.f7848bb991fd0be331adcf1457fbc672@0"}; - - -struct rt -{ - char **s; - int nbits; -}; - -static struct rt zarr[] = -{ - {z1, 1}, - {z2, 2}, - {z3, 3}, - {z4, 4}, - {z5, 5}, - {z10, 10}, - {z15, 15}, - {z16, 16}, - {z17, 17}, - {z31, 31}, - {z32, 32}, - {z33, 33}, - {z63, 63}, - {z64, 64}, - {z65, 65}, - {z127, 127}, - {z128, 128}, - {0, NULL} -}; - -static struct rt farr[] = -{ - {f1, 1}, - {f2, 2}, - {f3, 3}, - {f4, 4}, - {f5, 5}, - {f10, 10}, - {f15, 15}, - {f16, 16}, - {f17, 17}, - {f31, 31}, - {f32, 32}, - {f33, 33}, - {f63, 63}, - {f64, 64}, - {f65, 65}, - {f127, 127}, - {f128, 128}, - {0, NULL} -}; - - -int -#if __STDC__ -main (int argc, char *argv[]) -#else -main (argc, argv) - int argc; - char *argv[]; -#endif -{ - static char usage[] = "\ -usage: t-rand [function nbits]\n\ - function is one of z, f\n\ - nbits is number of bits\n\ -"; - gmp_randstate_t rstate; - mpz_t z, rz; - mpf_t f, rf; - enum { Z, F } func = Z; - int nbits = 1; - int verify_mode_flag = 1; - register int i; - struct rt *a; - - - if (argc > 1) - { - if (argc < 3) - { - fputs (usage, stderr); - exit (1); - } - verify_mode_flag = 0; - if (*argv[1] == 'z') - func = Z; - if (*argv[1] == 'f') - func = F; - nbits = atoi (argv[2]); - } - - mpz_init (rz); - - if (verify_mode_flag) - { -#ifdef VERBOSE - printf ("%s: verifying random numbers: ", argv[0]); -#endif - - /* Test z. */ - mpz_init (z); - for (a = zarr; a->s != NULL; a++) - { - gmp_randinit (rstate, GMP_RAND_ALG_LC, a->nbits); - if (gmp_errno != GMP_ERROR_NONE) - exit (1); - gmp_randseed_ui (rstate, SEED); - - for (i = 0; i < ENTS; i++) - { - mpz_urandomb (rz, rstate, a->nbits); - mpz_set_str (z, a->s[i], BASE); - if (mpz_cmp (z, rz) != 0) - { - printf ("z%d: ", a->nbits); - mpz_out_str (stdout, BASE, rz); - printf (" should be "); - mpz_out_str (stdout, BASE, z); - puts (""); - exit (1); - } - } -#ifdef VERBOSE - printf ("z%d ", a->nbits); -#endif - gmp_randclear (rstate); - } - mpz_clear (z); - - - /* Test f. */ - for (a = farr; a->s != NULL; a++) - { - gmp_randinit (rstate, GMP_RAND_ALG_LC, a->nbits); - if (gmp_errno != GMP_ERROR_NONE) - exit (1); - gmp_randseed_ui (rstate, SEED); - - mpf_init2 (f, a->nbits); - mpf_init2 (rf, a->nbits); - for (i = 0; i < ENTS; i++) - { - mpf_urandomb (rf, rstate, a->nbits); - mpf_set_str (f, a->s[i], BASE); - if (mpf_cmp (f, rf) != 0) - { - printf ("f%d: ", a->nbits); - mpf_out_str (stdout, BASE, a->nbits, rf); - printf (" should be "); - mpf_out_str (stdout, BASE, a->nbits, f); - puts (""); - exit (1); - } - } -#ifdef VERBOSE - printf ("f%d ", a->nbits); -#endif - gmp_randclear (rstate); - mpf_clear (f); - mpf_clear (rf); - } - -#ifdef VERBOSE - puts (""); -#endif - } - else /* Print mode. */ - { - gmp_randinit (rstate, GMP_RAND_ALG_LC, nbits); - if (gmp_errno != GMP_ERROR_NONE) - exit (1); - gmp_randseed_ui (rstate, SEED); - - switch (func) - { - case Z: - printf ("char *z%d[ENTS] = {", nbits); - for (i = 0; i < ENTS; i++) - { - mpz_urandomb (rz, rstate, nbits); - printf ("\""); - mpz_out_str (stdout, BASE, rz); - printf ("\""); - if (i != ENTS - 1) - printf (", "); - } - printf ("};\n"); - printf (" {z%d, %d},\n", nbits, nbits); - break; - - case F: - printf ("char *f%d[ENTS] = {", nbits); - mpf_init2 (rf, nbits); - for (i = 0; i < ENTS; i++) - { - mpf_urandomb (rf, rstate, nbits); - printf ("\""); - mpf_out_str (stdout, BASE, nbits, rf); - printf ("\""); - if (i != ENTS - 1) - printf (", "); - } - printf ("};\n"); - printf (" {f%d, %d},\n", nbits, nbits); - mpf_clear (rf); - break; - - default: - exit (1); - } - - gmp_randclear (rstate); - } - - mpz_clear (rz); - - return 0; -} diff --git a/gmp/tests/rand/zdiv_round.c b/gmp/tests/rand/zdiv_round.c deleted file mode 100755 index 8827e9a..0000000 --- a/gmp/tests/rand/zdiv_round.c +++ /dev/null @@ -1,47 +0,0 @@ -/* zdiv_round() -- divide integers, round to nearest */ - -/* -Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" - -void -zdiv_round (mpz_t rop, mpz_t n, mpz_t d) -{ - mpf_t f_n, f_d; - - mpf_init (f_n); - mpf_init (f_d); - - mpf_set_z (f_d, d); - mpf_set_z (f_n, n); - - mpf_div (f_n, f_n, f_d); - mpf_set_d (f_d, .5); - if (mpf_sgn (f_n) < 0) - mpf_neg (f_d, f_d); - mpf_add (f_n, f_n, f_d); - mpz_set_f (rop, f_n); - - mpf_clear (f_n); - mpf_clear (f_d); - return; -} diff --git a/gmp/texinfo.tex b/gmp/texinfo.tex deleted file mode 100755 index acbe156..0000000 Binary files a/gmp/texinfo.tex and /dev/null differ diff --git a/gmp/tune/Makefile.am b/gmp/tune/Makefile.am deleted file mode 100755 index ef1c0fa..0000000 Binary files a/gmp/tune/Makefile.am and /dev/null differ diff --git a/gmp/tune/Makefile.in b/gmp/tune/Makefile.in deleted file mode 100755 index 52dd724..0000000 Binary files a/gmp/tune/Makefile.in and /dev/null differ diff --git a/gmp/tune/README b/gmp/tune/README deleted file mode 100755 index f7d6600..0000000 Binary files a/gmp/tune/README and /dev/null differ diff --git a/gmp/tune/alpha.asm b/gmp/tune/alpha.asm deleted file mode 100755 index eb4c031..0000000 Binary files a/gmp/tune/alpha.asm and /dev/null differ diff --git a/gmp/tune/common.c b/gmp/tune/common.c deleted file mode 100755 index ca6964d..0000000 --- a/gmp/tune/common.c +++ /dev/null @@ -1,1319 +0,0 @@ -/* Shared speed subroutines. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include -#include -#include -#include -#include /* for qsort */ -#include -#include -#if 0 -#include -#endif - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#include "speed.h" - -/* Change this to "#define TRACE(x) x" to get traces. */ -#define TRACE(x) - - -typedef int (*qsort_function_t) _PROTO ((const void *, const void *)); - - -int speed_option_addrs = 0; - - -void -pentium_wbinvd(void) -{ -#if 0 - { - static int fd = -2; - - if (fd == -2) - { - fd = open ("/dev/wbinvd", O_RDWR); - if (fd == -1) - perror ("open /dev/wbinvd"); - } - - if (fd != -1) - ioctl (fd, 0, 0); - } -#endif - -#if 0 -#define WBINVDSIZE 1024*1024*2 - { - static char *p = NULL; - int i, sum; - - if (p == NULL) - p = malloc (WBINVDSIZE); - -#if 0 - for (i = 0; i < WBINVDSIZE; i++) - p[i] = i & 0xFF; -#endif - - sum = 0; - for (i = 0; i < WBINVDSIZE; i++) - sum += p[i]; - - mpn_cache_fill_dummy (sum); - } -#endif -} - -static int -double_cmp_ptr (const double *p, const double *q) -{ - if (*p > *q) return 1; - if (*p < *q) return -1; - return 0; -} - - -/* Measure the speed of a given routine. - - The routine is run with enough repetitions to make it take at least - speed_precision * speed_unittime. This aims to minimize the effects of a - limited accuracy time base and the overhead of the measuring itself. - - Measurements are made looking for 4 results within TOLERANCE of each - other (or 3 for routines taking longer than 2 seconds). This aims to get - an accurate reading even if some runs are bloated by interrupts or task - switches or whatever. - - The given (*fun)() is expected to run its function "s->reps" many times - and return the total elapsed time measured using speed_starttime() and - speed_endtime(). If the function doesn't support the given s->size or - s->r, -1.0 should be returned. See the various base routines below. */ - -double -speed_measure (double (*fun) _PROTO ((struct speed_params *s)), - struct speed_params *s) -{ -#define TOLERANCE 1.005 /* 0.5% */ - - struct speed_params s_dummy; - int i, j, e; - double t[30]; - double t_unsorted[30]; - - /* Use dummy parameters if caller doesn't provide any. Only a few special - "fun"s will cope with this, speed_noop() is one. */ - if (s == NULL) - { - memset (&s_dummy, '\0', sizeof (s_dummy)); - s = &s_dummy; - } - - s->reps = 1; - s->time_divisor = 1.0; - for (i = 0; i < numberof (t); i++) - { - for (;;) - { - s->src_num = 0; - s->dst_num = 0; - - t[i] = (*fun) (s); - t_unsorted[i] = t[i]; - - TRACE (printf("size=%ld reps=%u r=%d attempt=%d %.9f\n", - s->size, s->reps, s->r, i, t[i])); - - if (t[i] == -1.0) - return -1.0; - - if (t[i] >= speed_unittime * speed_precision) - break; - - /* go to a value of reps to make t[i] >= precision */ - s->reps = (unsigned) ceil (1.1 * s->reps - * speed_unittime * speed_precision - / MAX (t[i], speed_unittime)); - } - t[i] /= s->reps; - - if (speed_precision == 0) - return t[i]; - - /* require 3 values within TOLERANCE when >= 2 secs, 4 when below */ - if (t[0] >= 2.0) - e = 3; - else - e = 4; - - /* Look for e many t[]'s within TOLERANCE of each other to consider a - valid measurement. Return smallest among them. */ - if (i >= e) - { - qsort (t, i+1, sizeof(t[0]), (qsort_function_t) double_cmp_ptr); - for (j = e-1; j < i; j++) - if (t[j] <= t[j-e+1] * TOLERANCE) - return t[j-e+1] / s->time_divisor; - } - } - - fprintf (stderr, "speed_measure() could not get %d results within %.1f%%\n", - e, (TOLERANCE-1.0)*100.0); - fprintf (stderr, " %.12f is about 0.5%%\n", t[0]*(TOLERANCE-1.0)); - for (i = 0; i < numberof (t); i++) - fprintf (stderr, " %.09f\n", t_unsorted[i]); - - return -1.0; -} - - -/* Read all of ptr,size to get it into the CPU memory cache. - - A call to mpn_cache_fill_dummy() is used to make sure the compiler - doesn't optimize away the whole loop. Using "volatile mp_limb_t sum" - would work too, but the function call means we don't rely on every - compiler actually implementing volatile properly. - - mpn_cache_fill_dummy() is in a separate source file to stop gcc thinking - it can inline it. */ - -void -mpn_cache_fill (mp_srcptr ptr, mp_size_t size) -{ - mp_limb_t sum = 0; - mp_size_t i; - - for (i = 0; i < size; i++) - sum += ptr[i]; - - mpn_cache_fill_dummy(sum); -} - - -void -mpn_cache_fill_write (mp_ptr ptr, mp_size_t size) -{ - mpn_cache_fill (ptr, size); - -#if 0 - mpn_random (ptr, size); -#endif - -#if 0 - mp_size_t i; - - for (i = 0; i < size; i++) - ptr[i] = i; -#endif -} - - -void -speed_operand_src (struct speed_params *s, mp_ptr ptr, mp_size_t size) -{ - if (s->src_num >= numberof (s->src)) - { - fprintf (stderr, "speed_operand_src: no room left in s->src[]\n"); - abort (); - } - s->src[s->src_num].ptr = ptr; - s->src[s->src_num].size = size; - s->src_num++; -} - - -void -speed_operand_dst (struct speed_params *s, mp_ptr ptr, mp_size_t size) -{ - if (s->dst_num >= numberof (s->dst)) - { - fprintf (stderr, "speed_operand_dst: no room left in s->dst[]\n"); - abort (); - } - s->dst[s->dst_num].ptr = ptr; - s->dst[s->dst_num].size = size; - s->dst_num++; -} - - -void -speed_cache_fill (struct speed_params *s) -{ - static struct speed_params prev; - int i; - - /* FIXME: need a better way to get the format string for a pointer */ - - if (speed_option_addrs) - { - int different; - - different = (s->dst_num != prev.dst_num || s->src_num != prev.src_num); - for (i = 0; i < s->dst_num; i++) - different |= (s->dst[i].ptr != prev.dst[i].ptr); - for (i = 0; i < s->src_num; i++) - different |= (s->src[i].ptr != prev.src[i].ptr); - - if (different) - { - if (s->dst_num != 0) - { - printf ("dst"); - for (i = 0; i < s->dst_num; i++) - printf (" %08lX", (unsigned long) s->dst[i].ptr); - printf (" "); - } - - if (s->src_num != 0) - { - printf ("src"); - for (i = 0; i < s->src_num; i++) - printf (" %08lX", (unsigned long) s->src[i].ptr); - printf (" "); - } - printf (" (cf sp approx %08lX)\n", (unsigned long) &different); - - } - - memcpy (&prev, s, sizeof(prev)); - } - - switch (s->cache) { - case 0: - for (i = 0; i < s->dst_num; i++) - mpn_cache_fill_write (s->dst[i].ptr, s->dst[i].size); - for (i = 0; i < s->src_num; i++) - mpn_cache_fill (s->src[i].ptr, s->src[i].size); - break; - case 1: - pentium_wbinvd(); - break; - } -} - - -/* Return p advanced to the next multiple of "align" bytes. "align" must be - a power of 2. Care is taken not to assume sizeof(int)==sizeof(pointer). - Using "unsigned long" avoids a warning on hpux. */ -void * -align_pointer (void *p, size_t align) -{ - unsigned long d; - d = ((unsigned long) p) & (align-1); - d = (d != 0 ? align-d : 0); - return (void *) (((char *) p) + d); -} - -/* Note that memory allocated with this function can never be freed, because - the start address of the block allocated is discarded. */ -void * -_mp_allocate_func_aligned (size_t bytes, size_t align) -{ - return align_pointer ((*_mp_allocate_func) (bytes + align-1), align); -} - - -void * -_mp_allocate_or_reallocate (void *ptr, size_t oldsize, size_t newsize) -{ - if (ptr == NULL) - return (*_mp_allocate_func) (newsize); - else - return (*_mp_reallocate_func) (ptr, oldsize, newsize); -} - - -/* Adjust ptr to align to CACHE_LINE_SIZE bytes plus "align" limbs. ptr - needs to have room for up to CACHE_LINE_SIZE-4 extra bytes. */ - -mp_ptr -speed_tmp_alloc_adjust (void *ptr, mp_size_t align) -{ - /* - printf("%p %ld -> %p %X %X\n", ptr, align, - (mp_ptr) ptr - + ((align - ((mp_size_t) ptr >> 2)) & - SPEED_TMP_ALLOC_ADJUST_MASK), - ((mp_size_t) ptr >> 2) & SPEED_TMP_ALLOC_ADJUST_MASK, - SPEED_TMP_ALLOC_ADJUST_MASK); - */ - - return (mp_ptr) ptr - + ((align - ((mp_size_t) ptr >> 2)) & SPEED_TMP_ALLOC_ADJUST_MASK); -} - - -void -mpz_set_n (mpz_ptr z, mp_srcptr p, mp_size_t size) -{ - ASSERT (size >= 0); - MPN_NORMALIZE (p, size); - MPZ_REALLOC (z, size); - MPN_COPY (PTR(z), p, size); - SIZ(z) = size; -} - - -/* Miscellanous options accepted by tune and speed programs under -o. */ - -void -speed_option_set (const char *s) -{ - if (strcmp (s, "addrs") == 0) speed_option_addrs = 1; - else - { - printf ("Unrecognised -o option: %s\n", s); - exit (1); - } -} - - -/* The following are basic speed running routines for various gmp functions. - Many are very similar and use speed.h macros. - - Each routine allocates it's own destination space for the result of the - function, because only it can know what the function needs. - - speed_starttime() and speed_endtime() are put tight around the code to be - measured. Any setups are done outside the timed portion. - - Each routine is responsible for its own cache priming. - speed_cache_fill() is a good way to do this, see examples in speed.h. - One cache priming possibility, for CPUs with write-allocate cache, and - functions that don't take too long, is to do one dummy call before timing - so as to cache everything that gets used. But speed_measure() runs a - routine at least twice and will take the smaller time, so this might not - be necessary. - - Data alignment will be important, for source, destination and temporary - workspace. A routine can align its destination and workspace. Programs - using the routines will ensure s->xp and s->yp are aligned. Aligning - onto a CACHE_LINE_SIZE boundary is suggested. s->align_wp and - s->align_wp2 should be respected where it makes sense to do so. - SPEED_TMP_ALLOC_LIMBS is a good way to do this. - - A loop of the following form can be expected to turn into good assembler - code on most CPUs, thereby minimizing overhead in the measurement. It - can always be assumed s->reps >= 1. - - i = s->reps - do - foo(); - while (--i != 0); - - Additional parameters might be added to "struct speed_params" in the - future. Routines should ignore anything they don't use. - - s->size can be used creatively, and s->xp and s->yp can be ignored. For - example, speed_mpz_fac_ui() uses s->size as n for the factorial. s->r is - just a user-supplied parameter. speed_mpn_lshift() uses it as a shift, - speed_mpn_mul_1() uses it as a multiplier. */ - - -/* MPN_COPY etc can be macros, so the _CALL forms are necessary */ -double -speed_MPN_COPY (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_COPY_CALL (MPN_COPY (wp, s->xp, s->size)); -} -double -speed_MPN_COPY_INCR (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_COPY_CALL (MPN_COPY_INCR (wp, s->xp, s->size)); -} -double -speed_MPN_COPY_DECR (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_COPY_CALL (MPN_COPY_DECR (wp, s->xp, s->size)); -} -double -speed_memcpy (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_COPY_CALL - (memcpy (wp, s->xp, s->size * BYTES_PER_MP_LIMB)); -} - - -double -speed_mpn_addmul_1 (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_UNARY_1 (mpn_addmul_1); -} -double -speed_mpn_submul_1 (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_UNARY_1 (mpn_submul_1); -} - - -double -speed_mpn_mul_1 (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_UNARY_1 (mpn_mul_1); -} - - -double -speed_mpn_lshift (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_UNARY_1 (mpn_lshift); -} -double -speed_mpn_rshift (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_UNARY_1 (mpn_rshift); -} - - -/* The carry-in variants (if available) are good for measuring because they - won't skip a division if highxp, s->size)); -} - - -double -speed_mpn_bz_divrem_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BZ_DIVREM_N (mpn_bz_divrem_n); -} -double -speed_mpn_bz_divrem_sb (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BZ_DIVREM_SB (mpn_sb_divrem_mn); -} -double -speed_mpn_bz_tdiv_qr (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BZ_TDIV_QR (mpn_tdiv_qr); -} - - -double -speed_mpn_popcount (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_POPCOUNT (mpn_popcount); -} -double -speed_mpn_hamdist (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_HAMDIST (mpn_hamdist); -} - - -double -speed_mpn_add_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N (mpn_add_n); -} -double -speed_mpn_sub_n (struct speed_params *s) -{ -SPEED_ROUTINE_MPN_BINARY_N (mpn_sub_n); -} -double -speed_mpn_add_n_self (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_SELF (mpn_add_n); -} -double -speed_mpn_add_n_inplace (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_INPLACE (mpn_add_n); -} - - -/* mpn_and_n etc can be macros and so have to be handled with - SPEED_ROUTINE_MPN_BINARY_N_CALL forms */ -double -speed_mpn_and_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_and_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_andn_n (struct speed_params *s) -{ -SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_andn_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_nand_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_nand_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_ior_n (struct speed_params *s) -{ -SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_ior_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_iorn_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_iorn_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_nior_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_nior_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_xor_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_xor_n (wp, s->xp, s->yp, s->size)); -} -double -speed_mpn_xnor_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_BINARY_N_CALL (mpn_xnor_n (wp, s->xp, s->yp, s->size)); -} - - -double -speed_mpn_mul_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_MUL_N (mpn_mul_n); -} -double -speed_mpn_sqr_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_SQR (mpn_sqr_n); -} -double -speed_mpn_mul_n_sqr (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_SQR_CALL (mpn_mul_n (wp, s->xp, s->xp, s->size)); -} - -double -speed_mpn_mul_basecase (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_MUL_BASECASE(mpn_mul_basecase); -} -double -speed_mpn_sqr_basecase (struct speed_params *s) -{ - /* FIXME: size restrictions on some versions of sqr_basecase */ - SPEED_ROUTINE_MPN_SQR (mpn_sqr_basecase); -} - -double -speed_mpn_kara_mul_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_KARA_MUL_N (mpn_kara_mul_n); -} -double -speed_mpn_kara_sqr_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_KARA_SQR_N (mpn_kara_sqr_n); -} - -double -speed_mpn_toom3_mul_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_TOOM3_MUL_N (mpn_toom3_mul_n); -} -double -speed_mpn_toom3_sqr_n (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_TOOM3_SQR_N (mpn_toom3_sqr_n); -} - -double -speed_mpn_mul_fft_full (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_MUL_N_CALL - (mpn_mul_fft_full (wp, s->xp, s->size, s->yp, s->size)); -} -double -speed_mpn_mul_fft_full_sqr (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_SQR_CALL - (mpn_mul_fft_full (wp, s->xp, s->size, s->xp, s->size)); -} - - -/* These are mod 2^N+1 multiplies and squares. If s->r is supplied it's - used as k, otherwise the best k for the size is used. If s->size isn't a - multiple of 2^k it's rounded up to make the effective operation size. */ - -#define SPEED_ROUTINE_MPN_MUL_FFT_CALL(call, sqr) \ - { \ - mp_ptr wp; \ - mp_size_t pl; \ - int k; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - if (s->r != 0) \ - k = s->r; \ - else \ - k = mpn_fft_best_k (s->size, sqr); \ - \ - TMP_MARK (marker); \ - pl = mpn_fft_next_size (s->size, k); \ - wp = SPEED_TMP_ALLOC_LIMBS (pl+1, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - if (!sqr) \ - speed_operand_src (s, s->yp, s->size); \ - speed_operand_dst (s, wp, pl+1); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -double -speed_mpn_mul_fft (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_MUL_FFT_CALL - (mpn_mul_fft (wp, pl, s->xp, s->size, s->yp, s->size, k), 0); -} - -double -speed_mpn_mul_fft_sqr (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_MUL_FFT_CALL - (mpn_mul_fft (wp, pl, s->xp, s->size, s->xp, s->size, k), 1); -} - - -double -speed_mpn_gcd (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_GCD (mpn_gcd); -} -double -speed_mpn_gcdext (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_GCDEXT (mpn_gcdext); -} -double -speed_mpn_gcd_1 (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_GCD_1 (mpn_gcd_1); -} - - -double -speed_mpn_jacobi_base (struct speed_params *s) -{ - SPEED_ROUTINE_MPN_JACBASE (mpn_jacobi_base); -} - - -double -speed_mpz_fac_ui (struct speed_params *s) -{ - SPEED_ROUTINE_MPZ_UI (mpz_fac_ui); -} -double -speed_mpz_fib_ui (struct speed_params *s) -{ - SPEED_ROUTINE_MPZ_UI (mpz_fib_ui); -} - - -double -speed_mpz_powm (struct speed_params *s) -{ - SPEED_ROUTINE_MPZ_POWM (mpz_powm); -} - - -double -speed_modlimb_invert (struct speed_params *s) -{ - SPEED_ROUTINE_MODLIMB_INVERT (modlimb_invert); -} - - -double -speed_noop (struct speed_params *s) -{ - unsigned i; - - speed_starttime (); - i = s->reps; - do - noop (); - while (--i != 0); - return speed_endtime (); -} - -double -speed_noop_wxs (struct speed_params *s) -{ - mp_ptr wp; - unsigned i; - double t; - TMP_DECL (marker); - - TMP_MARK (marker); - wp = TMP_ALLOC_LIMBS (1); - - speed_starttime (); - i = s->reps; - do - noop_wxs (wp, s->xp, s->size); - while (--i != 0); - t = speed_endtime (); - - TMP_FREE (marker); - return t; -} - -double -speed_noop_wxys (struct speed_params *s) -{ - mp_ptr wp; - unsigned i; - double t; - TMP_DECL (marker); - - TMP_MARK (marker); - wp = TMP_ALLOC_LIMBS (1); - - speed_starttime (); - i = s->reps; - do - noop_wxys (wp, s->xp, s->yp, s->size); - while (--i != 0); - t = speed_endtime (); - - TMP_FREE (marker); - return t; -} - - -#define SPEED_ROUTINE_ALLOC_FREE(variables, calls) \ - { \ - unsigned i; \ - variables; \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - { \ - calls; \ - } \ - while (--i != 0); \ - return speed_endtime (); \ - } - - -/* Compare these to see how much malloc/free costs and then how much - _mp_default_allocate/free and mpz_init/clear add. mpz_init/clear or - mpq_init/clear will be doing a 1 limb allocate, so use that as the size - when including them in comparisons. */ - -double -speed_malloc_free (struct speed_params *s) -{ - size_t bytes = s->size * BYTES_PER_MP_LIMB; - SPEED_ROUTINE_ALLOC_FREE (void *p, - p = malloc (bytes); - free (p)); -} - -double -speed_malloc_realloc_free (struct speed_params *s) -{ - size_t bytes = s->size * BYTES_PER_MP_LIMB; - SPEED_ROUTINE_ALLOC_FREE (void *p, - p = malloc (BYTES_PER_MP_LIMB); - p = realloc (p, bytes); - free (p)); -} - -double -speed_mp_allocate_free (struct speed_params *s) -{ - size_t bytes = s->size * BYTES_PER_MP_LIMB; - SPEED_ROUTINE_ALLOC_FREE (void *p, - p = (*_mp_allocate_func) (bytes); - (*_mp_free_func) (p, bytes)); -} - -double -speed_mp_allocate_reallocate_free (struct speed_params *s) -{ - size_t bytes = s->size * BYTES_PER_MP_LIMB; - SPEED_ROUTINE_ALLOC_FREE - (void *p, - p = (*_mp_allocate_func) (BYTES_PER_MP_LIMB); - p = (*_mp_reallocate_func) (p, bytes, BYTES_PER_MP_LIMB); - (*_mp_free_func) (p, bytes)); -} - -double -speed_mpz_init_clear (struct speed_params *s) -{ - SPEED_ROUTINE_ALLOC_FREE (mpz_t z, - mpz_init (z); - mpz_clear (z)); -} - -double -speed_mpz_init_realloc_clear (struct speed_params *s) -{ - SPEED_ROUTINE_ALLOC_FREE (mpz_t z, - mpz_init (z); - _mpz_realloc (z, s->size); - mpz_clear (z)); -} - -double -speed_mpq_init_clear (struct speed_params *s) -{ - SPEED_ROUTINE_ALLOC_FREE (mpq_t q, - mpq_init (q); - mpq_clear (q)); -} - -double -speed_mpf_init_clear (struct speed_params *s) -{ - SPEED_ROUTINE_ALLOC_FREE (mpf_t f, - mpf_init (f); - mpf_clear (f)); -} - - -/* Compare this to mpn_add_n to see how much overhead mpz_add adds. Note - that repeatedly calling mpz_add with the same data gives branch predition - in it an advantage. */ - -double -speed_mpz_add (struct speed_params *s) -{ - mpz_t w, x, y; - unsigned i; - double t; - - mpz_init (w); - mpz_init (x); - mpz_init (y); - - mpz_set_n (x, s->xp, s->size); - mpz_set_n (y, s->yp, s->size); - mpz_add (w, x, y); - - speed_starttime (); - i = s->reps; - do - { - mpz_add (w, x, y); - } - while (--i != 0); - t = speed_endtime (); - - mpz_clear (w); - mpz_clear (x); - mpz_clear (y); - return t; -} - - -/* If r==0, calculate (size,size/2), - otherwise calculate (size,r). */ - -double -speed_mpz_bin_uiui (struct speed_params *s) -{ - mpz_t w; - unsigned long k; - unsigned i; - double t; - - mpz_init (w); - if (s->r != 0) - k = s->r; - else - k = s->size/2; - - speed_starttime (); - i = s->reps; - do - { - mpz_bin_uiui (w, s->size, k); - } - while (--i != 0); - t = speed_endtime (); - - mpz_clear (w); - return t; -} - - -/* The multiplies are successively dependent so the latency is measured, not - the issue rate. There's only 10 per loop so the code doesn't get too big - since umul_ppmm is several instructions on some cpus. - - Putting the arguments as "h,l,l,h" gets slightly better code from gcc - 2.95.2 on x86, it puts only one mov between each mul, not two. That mov - though will probably show up as a bogus extra cycle though. - - The measuring function macros are into three parts to avoid overflowing - preprocessor expansion space if umul_ppmm is big. - - Limitations: - - Don't blindly use this to set UMUL_TIME in gmp-mparam.h, check the code - generated first, especially on CPUs with low latency multipliers. - - The default umul_ppmm doing h*l will be getting increasing numbers of - high zero bits in the calculation. CPUs with data-dependent multipliers - will want to use umul_ppmm.1 to get some randomization into the - calculation. The extra xors and fetches will be a slowdown of course. */ - -#define SPEED_MACRO_UMUL_PPMM_A \ - { \ - mp_limb_t h, l; \ - unsigned i; \ - double t; \ - \ - s->time_divisor = 10; \ - \ - h = s->xp[0]; \ - l = s->yp[0]; \ - \ - switch (s->r) { \ - case 1: \ - speed_starttime (); \ - i = s->reps; \ - do \ - { - -#define SPEED_MACRO_UMUL_PPMM_B \ - } \ - while (--i != 0); \ - t = speed_endtime (); \ - break; \ - \ - default: \ - speed_starttime (); \ - i = s->reps; \ - do \ - { - -#define SPEED_MACRO_UMUL_PPMM_C \ - } \ - while (--i != 0); \ - t = speed_endtime (); \ - break; \ - } \ - \ - /* stop the compiler optimizing away the whole calculation! */ \ - noop_1 (h); \ - noop_1 (l); \ - \ - return t; \ - } - - -double -speed_umul_ppmm (struct speed_params *s) -{ - SPEED_MACRO_UMUL_PPMM_A; - { - umul_ppmm (h, l, l, h); h ^= s->xp_block[0]; l ^= s->yp_block[0]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[1]; l ^= s->yp_block[1]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[2]; l ^= s->yp_block[2]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[3]; l ^= s->yp_block[3]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[4]; l ^= s->yp_block[4]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[5]; l ^= s->yp_block[5]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[6]; l ^= s->yp_block[6]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[7]; l ^= s->yp_block[7]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[8]; l ^= s->yp_block[8]; - umul_ppmm (h, l, l, h); h ^= s->xp_block[9]; l ^= s->yp_block[9]; - } - SPEED_MACRO_UMUL_PPMM_B; - { - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - umul_ppmm (h, l, l, h); - } - SPEED_MACRO_UMUL_PPMM_C; -} - - -#if HAVE_NATIVE_mpn_umul_ppmm - -#if defined (__hppa) && W_TYPE_SIZE == 64 -#define CALL_MPN_UMUL_PPMM (h = __MPN (umul_ppmm) (h, l, &l)) -#else -#define CALL_MPN_UMUL_PPMM (h = __MPN (umul_ppmm) (&l, h, l)) -#endif - -double -speed_mpn_umul_ppmm (struct speed_params *s) -{ - SPEED_MACRO_UMUL_PPMM_A; - { - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[0]; l ^= s->yp_block[0]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[1]; l ^= s->yp_block[1]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[2]; l ^= s->yp_block[2]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[3]; l ^= s->yp_block[3]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[4]; l ^= s->yp_block[4]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[5]; l ^= s->yp_block[5]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[6]; l ^= s->yp_block[6]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[7]; l ^= s->yp_block[7]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[8]; l ^= s->yp_block[8]; - CALL_MPN_UMUL_PPMM; h ^= s->xp_block[9]; l ^= s->yp_block[9]; - } - SPEED_MACRO_UMUL_PPMM_B; - { - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - CALL_MPN_UMUL_PPMM; - } - SPEED_MACRO_UMUL_PPMM_C; -} -#endif - - -/* The divisions are successively dependent so latency is measured, not - issue rate. There's only 10 per loop so the code doesn't get too big, - especially for udiv_qrnnd_preinv and preinv2norm, which are several - instructions each. - - Note that it's only the division which is measured here, there's no data - fetching and no shifting if the divisor gets normalized. - - In speed_udiv_qrnnd with gcc 2.95.2 on x86 the parameters "q,r,r,q,d" - generate x86 div instructions with nothing in between. - - The measuring function macros are in two parts to avoid overflowing - preprocessor expansion space if udiv_qrnnd etc are big. - - Limitations: - - Don't blindly use this to set UDIV_TIME in gmp-mparam.h, check the code - generated first. - - CPUs with data-dependent divisions may want more attention paid to the - randomness of the data used. Probably the measurement wanted is over - uniformly distributed numbers, but what's here might not be giving that. */ - -#define SPEED_ROUTINE_UDIV_QRNND_A(normalize) \ - { \ - double t; \ - unsigned i; \ - mp_limb_t q, r, d; \ - mp_limb_t dinv; \ - \ - s->time_divisor = 10; \ - \ - /* divisor from "r" parameter, or a default */ \ - d = s->r; \ - if (d == 0) \ - d = 0x12345678; \ - \ - if (normalize) \ - { \ - unsigned norm; \ - count_leading_zeros (norm, d); \ - d <<= norm; \ - invert_limb (dinv, d); \ - } \ - \ - q = s->xp[0]; \ - r = s->yp[0] % d; \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - { - -#define SPEED_ROUTINE_UDIV_QRNND_B \ - } \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - /* stop the compiler optimizing away the whole calculation! */ \ - noop_1 (q); \ - noop_1 (r); \ - \ - return t; \ - } - -double -speed_udiv_qrnnd (struct speed_params *s) -{ - SPEED_ROUTINE_UDIV_QRNND_A (UDIV_NEEDS_NORMALIZATION); - { - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - udiv_qrnnd (q, r, r, q, d); - } - SPEED_ROUTINE_UDIV_QRNND_B; -} - -double -speed_udiv_qrnnd_preinv (struct speed_params *s) -{ - SPEED_ROUTINE_UDIV_QRNND_A (1); - { - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - udiv_qrnnd_preinv (q, r, r, q, d, dinv); - } - SPEED_ROUTINE_UDIV_QRNND_B; -} - -double -speed_udiv_qrnnd_preinv2norm (struct speed_params *s) -{ - SPEED_ROUTINE_UDIV_QRNND_A (1); - { - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - udiv_qrnnd_preinv2norm (q, r, r, q, d, dinv); - } - SPEED_ROUTINE_UDIV_QRNND_B; -} - -#if HAVE_NATIVE_mpn_udiv_qrnnd - -#if defined (__hppa) && W_TYPE_SIZE == 64 -#define CALL_MPN_UDIV_QRNND (q = __MPN (udiv_qrnnd) (r, q, d, &r)) -#else -#define CALL_MPN_UDIV_QRNND (q = __MPN (udiv_qrnnd) (&r, r, q, d)) -#endif - -double -speed_mpn_udiv_qrnnd (struct speed_params *s) -{ - - SPEED_ROUTINE_UDIV_QRNND_A (1); - { - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - CALL_MPN_UDIV_QRNND; - } - SPEED_ROUTINE_UDIV_QRNND_B; -} -#endif diff --git a/gmp/tune/hppa.asm b/gmp/tune/hppa.asm deleted file mode 100755 index 16e5ad2..0000000 Binary files a/gmp/tune/hppa.asm and /dev/null differ diff --git a/gmp/tune/hppa2.asm b/gmp/tune/hppa2.asm deleted file mode 100755 index 6415410..0000000 Binary files a/gmp/tune/hppa2.asm and /dev/null differ diff --git a/gmp/tune/noop.c b/gmp/tune/noop.c deleted file mode 100755 index b585ab7..0000000 --- a/gmp/tune/noop.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Noop routines. - - These are in a separate file to stop gcc recognising do-nothing functions - and optimizing away calls to them. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#include "gmp.h" -#include "gmp-impl.h" - -#include "speed.h" - - -void -noop (void) -{ -} - -/*ARGSUSED*/ -void -noop_1 (mp_limb_t n) -{ -} - -/*ARGSUSED*/ -void -noop_wxs (mp_ptr wp, mp_srcptr xp, mp_size_t size) -{ -} - -/*ARGSUSED*/ -void -noop_wxys (mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size) -{ -} - -/*ARGSUSED*/ -void -mpn_cache_fill_dummy (mp_limb_t n) -{ -} diff --git a/gmp/tune/pentium.asm b/gmp/tune/pentium.asm deleted file mode 100755 index 309da31..0000000 Binary files a/gmp/tune/pentium.asm and /dev/null differ diff --git a/gmp/tune/sparcv9.asm b/gmp/tune/sparcv9.asm deleted file mode 100755 index a33d4ba..0000000 Binary files a/gmp/tune/sparcv9.asm and /dev/null differ diff --git a/gmp/tune/speed-ext.c b/gmp/tune/speed-ext.c deleted file mode 100755 index a846a15..0000000 --- a/gmp/tune/speed-ext.c +++ /dev/null @@ -1,226 +0,0 @@ -/* An example of extending the speed program to measure routines not in GMP. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - - -/* The extension here is three versions of an mpn arithmetic mean. These - aren't meant to be particularly useful, just examples. - - You can run something like the following to compare their speeds. - - ./speed-ext -s 1-20 -c mean_calls mean_open mean_open2 - - On RISC chips, mean_open() might be fastest if the compiler is doing a - good job. On the register starved x86s, mean_calls will be fastest. - - - Notes: - - SPEED_EXTRA_PROTOS and SPEED_EXTRA_ROUTINES are macros that get expanded - by speed.c in useful places. SPEED_EXTRA_PROTOS goes after the header - files, and SPEED_EXTRA_ROUTINES goes in the array of available routines. - - The advantage of this #include "speed.c" scheme is that there's no - editing of a copy of that file, and new features in new versions of it - will be immediately available. - - In a real program the routines mean_calls() etc would probably be in - separate C or assembler source files, and just the measuring - speed_mean_calls() etc would be here. Linking against other libraries - for things to measure is perfectly possible too. - - When attempting to compare two versions of the same named routine, say - like the generic and assembler versions of mpn_add_n(), creative use of - cc -D or #define is suggested, so one or both can be renamed and linked - into the same program. It'll be much easier to compare them side by side - than with separate programs for each. - - common.c has notes on writing speed measuring routines. - - Remember to link against tune/libspeed.la (or tune/.libs/libspeed.a if - not using libtool) to get common.o and other objects needed by speed.c. */ - - -#define SPEED_EXTRA_PROTOS \ - double speed_mean_calls (struct speed_params *s); \ - double speed_mean_open (struct speed_params *s); \ - double speed_mean_open2 (struct speed_params *s); - -#define SPEED_EXTRA_ROUTINES \ - { "mean_calls", speed_mean_calls }, \ - { "mean_open", speed_mean_open }, \ - { "mean_open2", speed_mean_open2 }, - -#include "speed.c" - - -/* A straightforward implementation calling mpn subroutines. - - wp,size is set to (xp,size + yp,size) / 2. The return value is the - remainder from the division. The other versions are the same. */ - -mp_limb_t -mean_calls (mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size) -{ - mp_limb_t c, ret; - - ASSERT (size >= 1); - - c = mpn_add_n (wp, xp, yp, size); - ret = mpn_rshift (wp, wp, size, 1) >> (BITS_PER_MP_LIMB-1); - wp[size-1] |= (c << (BITS_PER_MP_LIMB-1)); - return ret; -} - - -/* An open-coded version, making one pass over the data. The right shift is - done as the added limbs are produced. The addition code follows - mpn/generic/add_n.c. */ - -mp_limb_t -mean_open (mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size) -{ - mp_limb_t w, wprev, x, y, c, ret; - mp_size_t i; - - ASSERT (size >= 1); - - x = xp[0]; - y = yp[0]; - - wprev = x + y; - c = (wprev < x); - ret = (wprev & 1); - -#define RSHIFT(hi,lo) (((lo) >> 1) | ((hi) << (BITS_PER_MP_LIMB-1))) - - for (i = 1; i < size; i++) - { - x = xp[i]; - y = yp[i]; - - w = x + c; - c = (w < x); - w += y; - c += (w < y); - - wp[i-1] = RSHIFT (w, wprev); - wprev = w; - } - - wp[i-1] = RSHIFT (c, wprev); - - return ret; -} - - -/* Another one-pass version, but right shifting the source limbs rather than - the result limbs. There's not much chance of this being better than the - above, but it's an alternative at least. */ - -mp_limb_t -mean_open2 (mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size) -{ - mp_limb_t w, x, y, xnext, ynext, c, ret; - mp_size_t i; - - ASSERT (size >= 1); - - x = xp[0]; - y = yp[0]; - - /* ret is the low bit of x+y, c is the carry out of that low bit add */ - ret = (x ^ y) & 1; - c = (x & y) & 1; - - for (i = 0; i < size-1; i++) - { - xnext = xp[i+1]; - ynext = yp[i+1]; - x = RSHIFT (xnext, x); - y = RSHIFT (ynext, y); - - w = x + c; - c = (w < x); - w += y; - c += (w < y); - wp[i] = w; - - x = xnext; - y = ynext; - } - - wp[i] = (x >> 1) + (y >> 1) + c; - - return ret; -} - - -/* The speed measuring routines are the same apart from which function they - run, so a macro is used. Actually this macro is the same as - SPEED_ROUTINE_MPN_BINARY_N. */ - -#define SPEED_ROUTINE_MEAN(mean_fun) \ - { \ - unsigned i; \ - mp_ptr wp; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_src (s, s->yp, s->size); \ - speed_operand_dst (s, wp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - mean_fun (wp, s->xp, s->yp, s->size); \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -double -speed_mean_calls (struct speed_params *s) -{ - SPEED_ROUTINE_MEAN (mean_calls); -} - -double -speed_mean_open (struct speed_params *s) -{ - SPEED_ROUTINE_MEAN (mean_open); -} - -double -speed_mean_open2 (struct speed_params *s) -{ - SPEED_ROUTINE_MEAN (mean_open2); -} diff --git a/gmp/tune/speed.c b/gmp/tune/speed.c deleted file mode 100755 index a86f738..0000000 --- a/gmp/tune/speed.c +++ /dev/null @@ -1,997 +0,0 @@ -/* Speed measuring program. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* Usage message is in the code below, run with no arguments to print it. - See README for interesting applications. - - To add a new routine foo(), create a speed_foo() function in the style of - the existing ones and add an entry in the routine[] array. Put FLAG_R if - speed_foo() wants an "r" parameter. - - The routines don't have help messages or descriptions, but most have - suggestive names. See the source code for full details. - -*/ - -#include "config.h" - -#if HAVE_GETOPT_H -#include /* for getopt_long() */ -#endif -#include -#include -#include -#include -#include /* for getpid() */ -#include /* for struct timeval for sys/resource.h */ -#include /* for getrusage() */ - -#include "gmp.h" -#include "gmp-impl.h" - -#include "speed.h" - -#if !HAVE_DECL_OPTARG -extern char *optarg; -extern int optind, opterr; -#endif - -#if !HAVE_STRTOUL -#define strtoul(p,e,b) (unsigned long) strtol(p,e,b) -#endif - -#ifdef SPEED_EXTRA_PROTOS -SPEED_EXTRA_PROTOS -#endif - - -#define MPN_FILL(ptr, size, n) \ - do { \ - mp_size_t i; \ - for (i = 0; i < size; i++) \ - ptr[i] = n; \ - } while (0) - -#define CMP_ABSOLUTE 1 -#define CMP_RATIO 2 -#define CMP_DIFFERENCE 3 -#define CMP_DIFFPREV 4 -int option_cmp = CMP_ABSOLUTE; - -#define UNIT_SECONDS 1 -#define UNIT_CYCLES 2 -#define UNIT_CYCLESPERLIMB 3 -int option_unit = UNIT_SECONDS; - -#define DATA_RANDOM 1 -#define DATA_RANDOM2 2 -#define DATA_ZEROS 3 -#define DATA_FFS 4 -#define DATA_2FD 5 -int option_data = DATA_RANDOM; - -int option_square = 0; -double option_factor = 0.0; -mp_size_t option_step = 1; -int option_gnuplot = 0; -char *option_gnuplot_basename; -struct size_array_t { - mp_size_t start, end; -} *size_array = NULL; -mp_size_t size_num = 0; -mp_size_t size_allocnum = 0; -int option_resource_usage = 0; -long option_seed = 123456789; - -struct speed_params sp; - -#define COLUMN_WIDTH 13 /* for the free-form output */ - -#define FLAG_R (1<<0) -#define FLAG_R_OPTIONAL (1<<1) -#define FLAG_RSIZE (1<<2) - -const struct routine_t { - /* constants */ - const char *name; - speed_function_t fun; - int flag; - -} routine[] = { - - { "noop", speed_noop }, - { "noop_wxs", speed_noop_wxs }, - { "noop_wxys", speed_noop_wxys }, - - { "mpn_add_n", speed_mpn_add_n }, - { "mpn_sub_n", speed_mpn_sub_n }, - { "mpn_add_n_self", speed_mpn_add_n_self }, - { "mpn_add_n_inplace", speed_mpn_add_n_inplace }, - - { "mpn_addmul_1", speed_mpn_addmul_1, FLAG_R }, - { "mpn_submul_1", speed_mpn_submul_1, FLAG_R }, - { "mpn_mul_1", speed_mpn_mul_1, FLAG_R }, - - { "mpn_divrem_1", speed_mpn_divrem_1, FLAG_R }, - { "mpn_divrem_1f", speed_mpn_divrem_1f, FLAG_R }, -#if HAVE_NATIVE_mpn_divrem_1c - { "mpn_divrem_1c", speed_mpn_divrem_1c, FLAG_R }, - { "mpn_divrem_1cf", speed_mpn_divrem_1cf,FLAG_R }, -#endif - { "mpn_mod_1", speed_mpn_mod_1, FLAG_R }, -#if HAVE_NATIVE_mpn_mod_1c - { "mpn_mod_1c", speed_mpn_mod_1c, FLAG_R }, -#endif - - { "mpn_divrem_2", speed_mpn_divrem_2, }, - { "mpn_divexact_by3", speed_mpn_divexact_by3 }, - - { "mpn_bz_divrem_n", speed_mpn_bz_divrem_n }, - { "mpn_bz_divrem_sb", speed_mpn_bz_divrem_sb }, - { "mpn_bz_tdiv_qr", speed_mpn_bz_tdiv_qr }, - - { "mpn_lshift", speed_mpn_lshift, FLAG_R }, - { "mpn_rshift", speed_mpn_rshift, FLAG_R }, - - { "mpn_and_n", speed_mpn_and_n }, - { "mpn_andn_n", speed_mpn_andn_n }, - { "mpn_nand_n", speed_mpn_nand_n }, - { "mpn_ior_n", speed_mpn_ior_n }, - { "mpn_iorn_n", speed_mpn_iorn_n }, - { "mpn_nior_n", speed_mpn_nior_n }, - { "mpn_xor_n", speed_mpn_xor_n }, - { "mpn_xnor_n", speed_mpn_xnor_n }, - - { "mpn_popcount", speed_mpn_popcount }, - { "mpn_hamdist", speed_mpn_hamdist }, - - { "mpn_gcdext", speed_mpn_gcdext }, - { "mpn_gcd", speed_mpn_gcd }, - { "mpn_gcd_1", speed_mpn_gcd_1, FLAG_R_OPTIONAL }, - - { "mpn_jacobi_base", speed_mpn_jacobi_base }, - - { "mpn_mul_basecase", speed_mpn_mul_basecase, FLAG_R_OPTIONAL }, - { "mpn_sqr_basecase", speed_mpn_sqr_basecase }, - - { "mpn_mul_n", speed_mpn_mul_n }, - { "mpn_sqr_n", speed_mpn_sqr_n }, - - { "mpn_kara_mul_n", speed_mpn_kara_mul_n }, - { "mpn_kara_sqr_n", speed_mpn_kara_sqr_n }, - { "mpn_toom3_mul_n", speed_mpn_toom3_mul_n }, - { "mpn_toom3_sqr_n", speed_mpn_toom3_sqr_n }, - { "mpn_mul_fft_full", speed_mpn_mul_fft_full }, - { "mpn_mul_fft_full_sqr", speed_mpn_mul_fft_full_sqr }, - - { "mpn_mul_fft", speed_mpn_mul_fft, FLAG_R_OPTIONAL }, - { "mpn_mul_fft_sqr", speed_mpn_mul_fft_sqr, FLAG_R_OPTIONAL }, - - { "mpz_add", speed_mpz_add }, - { "mpz_bin_uiui", speed_mpz_bin_uiui, FLAG_R_OPTIONAL }, - { "mpz_fac_ui", speed_mpz_fac_ui }, - { "mpz_fib_ui", speed_mpz_fib_ui }, - { "mpz_powm", speed_mpz_powm }, - - { "MPN_COPY", speed_MPN_COPY }, - { "MPN_COPY_INCR", speed_MPN_COPY_INCR }, - { "MPN_COPY_DECR", speed_MPN_COPY_DECR }, - { "memcpy", speed_memcpy }, - - { "modlimb_invert", speed_modlimb_invert }, - - { "malloc_free", speed_malloc_free }, - { "malloc_realloc_free", speed_malloc_realloc_free }, - { "mp_allocate_free", speed_mp_allocate_free }, - { "mp_allocate_reallocate_free", speed_mp_allocate_reallocate_free }, - { "mpz_init_clear", speed_mpz_init_clear }, - { "mpq_init_clear", speed_mpq_init_clear }, - { "mpf_init_clear", speed_mpf_init_clear }, - { "mpz_init_realloc_clear", speed_mpz_init_realloc_clear }, - - { "umul_ppmm", speed_umul_ppmm, FLAG_R_OPTIONAL }, -#if HAVE_NATIVE_mpn_umul_ppmm - { "mpn_umul_ppmm", speed_mpn_umul_ppmm, FLAG_R_OPTIONAL }, -#endif - - { "udiv_qrnnd", speed_udiv_qrnnd, FLAG_R_OPTIONAL }, - { "udiv_qrnnd_preinv", speed_udiv_qrnnd_preinv, FLAG_R_OPTIONAL }, - { "udiv_qrnnd_preinv2norm", speed_udiv_qrnnd_preinv2norm, FLAG_R_OPTIONAL }, -#if HAVE_NATIVE_mpn_udiv_qrnnd - { "mpn_udiv_qrnnd", speed_mpn_udiv_qrnnd, FLAG_R_OPTIONAL }, -#endif - -#ifdef SPEED_EXTRA_ROUTINES - SPEED_EXTRA_ROUTINES -#endif -}; - - -struct choice_t { - const struct routine_t *p; - int r; - double time; - int no_time; - double prev_time; - const char *name; -}; -struct choice_t *choice; -int num_choices = 0; - - -void -data_fill (mp_ptr ptr, mp_size_t size) -{ - switch (option_data) { - case DATA_RANDOM: - mpn_random (ptr, size); - break; - case DATA_RANDOM2: - mpn_random2 (ptr, size); - break; - case DATA_ZEROS: - MPN_ZERO (ptr, size); - break; - case DATA_FFS: - MPN_FILL (ptr, size, MP_LIMB_T_MAX); - break; - case DATA_2FD: - MPN_FILL (ptr, size, MP_LIMB_T_MAX); - ptr[0] -= 2; - break; - default: - abort(); - /*NOTREACHED*/ - } -} - -/* The code here handling the various combinations of output options isn't - too attractive, but it works and is fairly clean. */ - -#define SIZE_TO_DIVISOR(n) \ - (option_square == 1 ? (n)*(n) \ - : option_square == 2 ? (n)*((n)+1)/2 \ - : (n)) - -void -run_one (FILE *fp, struct speed_params *s, mp_size_t prev_size) -{ - const char *first_open_fastest, *first_open_notfastest, *first_close; - int i, fastest; - double fastest_time; - TMP_DECL (marker); - - TMP_MARK (marker); - sp.xp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_xp); - sp.yp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_yp); - - data_fill (s->xp, s->size); - data_fill (s->yp, s->size); - - if (prev_size == -1 && option_cmp == CMP_DIFFPREV) - { - first_open_fastest = "(#"; - first_open_notfastest = " ("; - first_close = ")"; - } - else - { - first_open_fastest = "#"; - first_open_notfastest = " "; - first_close = ""; - } - - fastest = -1; - fastest_time = -1.0; - for (i = 0; i < num_choices; i++) - { - s->r = choice[i].r; - choice[i].time = speed_measure (choice[i].p->fun, s); - choice[i].no_time = (choice[i].time == -1.0); - - - /* Apply the effect of CMP_DIFFPREV, but the new choice[i].prev_time - is before any differences. */ - { - double t; - t = choice[i].time; - if (t != -1.0 && option_cmp == CMP_DIFFPREV && prev_size != -1) - { - if (choice[i].prev_time == -1.0) - choice[i].no_time = 1; - else - choice[i].time = choice[i].time - choice[i].prev_time; - } - choice[i].prev_time = t; - } - - if (choice[i].no_time) - continue; - - /* Look for the fastest after CMP_DIFFPREV has been applied, but - before CMP_RATIO or CMP_DIFFERENCE. There's only a fastest shown - if there's more than one routine. */ - if (num_choices > 1 && (fastest == -1 || choice[i].time < fastest_time)) - { - fastest = i; - fastest_time = choice[i].time; - } - - if (option_cmp == CMP_DIFFPREV) - { - /* Conversion for UNIT_CYCLESPERLIMB differs in CMP_DIFFPREV. */ - if (option_unit == UNIT_CYCLES) - choice[i].time /= speed_cycletime; - else if (option_unit == UNIT_CYCLESPERLIMB) - { - if (prev_size == -1) - choice[i].time /= speed_cycletime; - else - choice[i].time /= (speed_cycletime - * (SIZE_TO_DIVISOR(s->size) - - SIZE_TO_DIVISOR(prev_size))); - } - } - else - { - if (option_unit == UNIT_CYCLES) - choice[i].time /= speed_cycletime; - else if (option_unit == UNIT_CYCLESPERLIMB) - choice[i].time /= (speed_cycletime * SIZE_TO_DIVISOR(s->size)); - - if (option_cmp == CMP_RATIO && i > 0) - { - /* A ratio isn't affected by the units chosen. */ - if (choice[0].no_time || choice[0].time == 0.0) - choice[i].no_time = 1; - else - choice[i].time /= choice[0].time; - } - else if (option_cmp == CMP_DIFFERENCE && i > 0) - { - if (choice[0].no_time) - { - choice[i].no_time = 1; - continue; - } - choice[i].time -= choice[0].time; - } - } - } - - if (option_gnuplot) - { - /* In CMP_DIFFPREV, don't print anything for the first size, start - with the second where an actual difference is available. - - In CMP_RATIO, print the first column as 1.0. - - The 9 decimals printed is much more than the expected precision of - the measurements actually. */ - - if (! (option_cmp == CMP_DIFFPREV && prev_size == -1)) - { - fprintf (fp, "%-6ld ", s->size); - for (i = 0; i < num_choices; i++) - fprintf (fp, " %.9e", - choice[i].no_time ? 0.0 - : (option_cmp == CMP_RATIO && i == 0) ? 1.0 - : choice[i].time); - fprintf (fp, "\n"); - } - } - else - { - fprintf (fp, "%-6ld ", s->size); - for (i = 0; i < num_choices; i++) - { - char buf[128]; - int decimals; - - if (choice[i].no_time) - decimals = 0, choice[i].time = 0.0; - else if (option_unit == UNIT_CYCLESPERLIMB - || (option_cmp == CMP_RATIO && i > 0)) - decimals = 4; - else if (option_unit == UNIT_CYCLES) - decimals = 2; - else - decimals = 9; - - sprintf (buf, "%s%.*f%s", - i == fastest ? first_open_fastest : first_open_notfastest, - decimals, choice[i].time, first_close); - fprintf (fp, " %*s", COLUMN_WIDTH, buf); - } - fprintf (fp, "\n"); - } - - TMP_FREE (marker); -} - -void -run_all (FILE *fp) -{ - mp_size_t prev_size; - int i; - TMP_DECL (marker); - - TMP_MARK (marker); - sp.xp_block = SPEED_TMP_ALLOC_LIMBS (SPEED_BLOCK_SIZE, sp.align_xp); - sp.yp_block = SPEED_TMP_ALLOC_LIMBS (SPEED_BLOCK_SIZE, sp.align_yp); - - data_fill (sp.xp_block, SPEED_BLOCK_SIZE); - data_fill (sp.yp_block, SPEED_BLOCK_SIZE); - - for (i = 0; i < size_num; i++) - { - sp.size = size_array[i].start; - prev_size = -1; - for (;;) - { - mp_size_t step; - - if (option_data == DATA_2FD && sp.size >= 2) - sp.xp[sp.size-1] = 2; - - run_one (fp, &sp, prev_size); - prev_size = sp.size; - - if (option_data == DATA_2FD && sp.size >= 2) - sp.xp[sp.size-1] = MP_LIMB_T_MAX; - - if (option_factor != 0.0) - { - step = (mp_size_t) (sp.size * option_factor - sp.size); - if (step < 1) - step = 1; - } - else - step = 1; - if (step < option_step) - step = option_step; - - sp.size += step; - if (sp.size > size_array[i].end) - break; - } - } - - TMP_FREE (marker); -} - - -FILE * -fopen_for_write (const char *filename) -{ - FILE *fp; - if ((fp = fopen (filename, "w")) == NULL) - { - fprintf (stderr, "Cannot create %s\n", filename); - exit(1); - } - return fp; -} - -void -fclose_written (FILE *fp, const char *filename) -{ - int err; - - err = ferror (fp); - err |= fclose (fp); - - if (err) - { - fprintf (stderr, "Error writing %s\n", filename); - exit(1); - } -} - - -void -run_gnuplot (void) -{ - char *plot_filename; - char *data_filename; - FILE *fp; - int i; - - plot_filename = (char *) (*_mp_allocate_func) - (strlen (option_gnuplot_basename) + 20); - data_filename = (char *) (*_mp_allocate_func) - (strlen (option_gnuplot_basename) + 20); - - sprintf (plot_filename, "%s.gnuplot", option_gnuplot_basename); - sprintf (data_filename, "%s.data", option_gnuplot_basename); - - fp = fopen_for_write (plot_filename); - - /* Putting the key at the top left is usually good, and you can change it - interactively if it's not. */ - fprintf (fp, "set key left\n"); - - /* designed to make it possible to see crossovers easily */ - fprintf (fp, "set data style linespoints\n"); - - fprintf (fp, "plot "); - for (i = 0; i < num_choices; i++) - { - fprintf (fp, " \"%s\" using 1:%d", data_filename, i+2); - fprintf (fp, " title \"%s\"", choice[i].name); - - if (i != num_choices-1) - fprintf (fp, ", \\"); - fprintf (fp, "\n"); - } - - fprintf (fp, "load \"-\"\n"); - fclose_written (fp, plot_filename); - - fp = fopen_for_write (data_filename); - - /* Unbuffered so you can see where the program was up to if it crashes or - you kill it. */ - setbuf (fp, NULL); - - run_all (fp); - fclose_written (fp, data_filename); -} - - -/* Return a long with n many one bits (starting from the least significant) */ -#define LONG_ONES(n) \ - ((n) == BITS_PER_LONGINT ? -1L : (n) == 0 ? 0L : (1L << (n)) - 1) - -long -r_string (const char *s) -{ - const char *s_orig = s; - long n; - - if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) - n = strtoul (s+2, (char **) &s, 16); - else - n = strtol (s, (char **) &s, 10); - - if (strcmp (s, "bits") == 0) - { - mp_limb_t l; - if (n > BITS_PER_LONGINT) - { - fprintf (stderr, "%ld bit parameter invalid (max %d bits)\n", - n, BITS_PER_LONGINT); - exit (1); - } - mpn_random (&l, 1); - return (l | (1 << (n-1))) & LONG_ONES(n); - } - else if (strcmp (s, "ones") == 0) - { - if (n > BITS_PER_LONGINT) - { - fprintf (stderr, "%ld bit parameter invalid (max %d bits)\n", - n, BITS_PER_LONGINT); - exit (1); - } - return LONG_ONES (n); - } - else if (*s != '\0') - { - fprintf (stderr, "invalid r parameter: %s\n", s_orig); - exit (1); - } - - return n; -} - - -void -routine_find (struct choice_t *c, const char *s) -{ - int i; - size_t nlen; - - for (i = 0; i < numberof (routine); i++) - { - nlen = strlen (routine[i].name); - if (memcmp (s, routine[i].name, nlen) != 0) - continue; - - if (s[nlen] == '.') - { - /* match, with a .r parameter */ - - if (! (routine[i].flag & (FLAG_R|FLAG_R_OPTIONAL))) - { - fprintf (stderr, "Choice %s bad: doesn't take a \".\" paramater\n", s); - exit (1); - } - - c->p = &routine[i]; - c->r = r_string (s + nlen + 1); - c->name = s; - return; - } - - if (s[nlen] == '\0') - { - /* match, with no parameter */ - - if (routine[i].flag & FLAG_R) - { - fprintf (stderr, "Choice %s bad: needs a \".\" paramater\n", s); - exit (1); - } - - c->p = &routine[i]; - c->r = 0; - c->name = s; - return; - } - } - - fprintf (stderr, "Choice %s unrecognised\n", s); - exit (1); -} - - -void -usage (void) -{ - int i; - - printf ("\ -Usage: speed [-options] -s size ...\n\ -Measure the speed of some routines.\n\ -Times are in seconds, accuracy is shown.\n\ -\n\ - -p num set precision as number of time units each routine must run\n\ - -s size[-end][,size[-end]]... sizes to measure\n\ - single sizes or ranges, sep with comma or use multiple -s\n\ - -t step step through sizes by given amount\n\ - -f factor step through sizes by given factor (eg. 1.05)\n\ - -r show times as ratios of the first routine\n\ - -d show times as difference from the first routine\n\ - -D show times as difference from previous size shown\n\ - -c show times in CPU cycles\n\ - -C show times in cycles per limb\n\ - -u print resource usage (memory) at end\n\ - -P name output plot files \"name.gnuplot\" and \"name.data\"\n\ - -a use given data: random(default), random2, zeros, ffs\n\ - -x, -y, -w, -W specify data alignments, sources and dests\n\ - -o addrs print addresses of data blocks\n\ -\n\ -If both -t and -f are used, it means step by the factor or the step, whichever\n\ -is greater.\n\ -If both -C and -D are used, it means cycles per however many limbs between a\n\ -size and the previous size.\n\ -\n\ -After running with -P, plots can be viewed with Gnuplot or Quickplot.\n\ -\"gnuplot name.gnuplot\" (use \"set logscale xy; replot\" at the prompt for\n\ -a log/log plot).\n\ -\"quickplot -s name.data\" (has interactive zooming, and note -s is important\n\ -when viewing more than one routine, it means same axis scales for all data).\n\ -\n\ -The available routines are as follows.\n\ -\n\ -"); - - for (i = 0; i < numberof (routine); i++) - { - if (routine[i].flag & FLAG_R) - printf ("\t%s.r\n", routine[i].name); - else if (routine[i].flag & FLAG_R_OPTIONAL) - printf ("\t%s (optional .r)\n", routine[i].name); - else - printf ("\t%s\n", routine[i].name); - } - - printf ("\n\ -Routines with a \".r\" need an extra parameter, for example mpn_lshift.6\n\ -r should be in decimal, or use 0xN for hexadecimal.\n\ -Special forms for r are Nbits for a random N bit number, and Nones for N one\n\ -bits.\n\ -\n\ -Times for sizes out of the range accepted by a routine are shown as 0.\n\ -The fastest routine at each size is marked with a # (free form output only).\n\ -\n\ -%s\ -\n\ -Gnuplot home page http://www.cs.dartmouth.edu/gnuplot_info.html\n\ -Quickplot home page http://www.kachinatech.com/~quickplot\n\ -", speed_time_string); -} - -int -main (int argc, char *argv[]) -{ -#define OPTION_ALIGN 1000 -#if HAVE_GETOPT_LONG - static const struct option longopts[] = { - { "align", required_argument, NULL, OPTION_ALIGN }, - { "align-x", required_argument, NULL, 'x' }, - { "align-y", required_argument, NULL, 'y' }, - { "align-w", required_argument, NULL, 'w' }, - { "align-w2", required_argument, NULL, 'W' }, - { "data", required_argument, NULL, 'a' }, - { "cycles", no_argument, NULL, 'c' }, - { "cycles-per-limb", no_argument, NULL, 'C' }, - { "diff", no_argument, NULL, 'd' }, - { "diff-prev", no_argument, NULL, 'D' }, - { "difference", no_argument, NULL, 'd' }, - { "difference-prev", no_argument, NULL, 'D' }, - { "factor", required_argument, NULL, 'f' }, - { "plot", no_argument, NULL, 'P' }, - { "precision", required_argument, NULL, 'p' }, - { "ratio", no_argument, NULL, 'r' }, - { "randomize", no_argument, NULL, 'R' }, - { "sizes", required_argument, NULL, 's' }, - { "step", required_argument, NULL, 't' }, - { "resources", required_argument, NULL, 'u' }, - { "uncached", no_argument, NULL, 'z' }, - { NULL } - }; -#endif - - int i; - int opt; - - /* Unbuffered so output goes straight out when directed to a pipe or file - and isn't lost if you kill the program half way. */ - setbuf (stdout, NULL); - -#define OPTSTRING "a:CcDdEFf:o:p:P:rRs:t:ux:y:w:W:z" -#if HAVE_GETOPT_LONG - while ((opt = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) - != EOF) -#else - while ((opt = getopt(argc, argv, OPTSTRING)) != EOF) -#endif - { - switch (opt) { - case 'a': - if (strcmp (optarg, "random") == 0) option_data = DATA_RANDOM; - else if (strcmp (optarg, "random2") == 0) option_data = DATA_RANDOM2; - else if (strcmp (optarg, "zeros") == 0) option_data = DATA_ZEROS; - else if (strcmp (optarg, "ffs") == 0) option_data = DATA_FFS; - else if (strcmp (optarg, "2fd") == 0) option_data = DATA_2FD; - else - { - fprintf (stderr, "unrecognised data option: %s\n", optarg); - exit (1); - } - break; - case 'C': - if (option_unit != UNIT_SECONDS) goto bad_unit; - option_unit = UNIT_CYCLESPERLIMB; - break; - case 'c': - if (option_unit != UNIT_SECONDS) - { - bad_unit: - fprintf (stderr, "cannot use more than one of -c, -C\n"); - exit (1); - } - option_unit = UNIT_CYCLES; - break; - case 'D': - if (option_cmp != CMP_ABSOLUTE) goto bad_cmp; - option_cmp = CMP_DIFFPREV; - break; - case 'd': - if (option_cmp != CMP_ABSOLUTE) - { - bad_cmp: - fprintf (stderr, "cannot use more than one of -d, -D, -r\n"); - exit (1); - } - option_cmp = CMP_DIFFERENCE; - break; - case 'E': - option_square = 1; - break; - case 'F': - option_square = 2; - break; - case 'f': - option_factor = atof (optarg); - if (option_factor <= 1.0) - { - fprintf (stderr, "-f factor must be > 1.0\n"); - exit (1); - } - break; - case 'o': - speed_option_set (optarg); - break; - case 'P': - option_gnuplot = 1; - option_gnuplot_basename = optarg; - break; - case 'p': - speed_precision = atoi (optarg); - break; - case 'R': - option_seed = time (NULL); - break; - case 'r': - if (option_cmp != CMP_ABSOLUTE) - goto bad_cmp; - option_cmp = CMP_RATIO; - break; - case 's': - { - char *s; - for (s = strtok (optarg, ","); s != NULL; s = strtok (NULL, ",")) - { - if (size_num == size_allocnum) - { - size_array = (struct size_array_t *) - _mp_allocate_or_reallocate - (size_array, - size_allocnum * sizeof(size_array[0]), - (size_allocnum+10) * sizeof(size_array[0])); - size_allocnum += 10; - } - if (sscanf (s, "%ld-%ld", - &size_array[size_num].start, - &size_array[size_num].end) != 2) - { - size_array[size_num].start = size_array[size_num].end - = atol (s); - } - - if (size_array[size_num].start < 1 - || size_array[size_num].end < 1 - || size_array[size_num].start > size_array[size_num].end) - { - fprintf (stderr, "invalid size parameter: %s\n", s); - exit (1); - } - - size_num++; - } - } - break; - case 't': - option_step = atol (optarg); - if (option_step < 1) - { - fprintf (stderr, "-t step must be >= 1\n"); - exit (1); - } - break; - case 'u': - option_resource_usage = 1; - break; - case 'z': - sp.cache = 1; - break; - case OPTION_ALIGN: - abort(); - case 'x': - sp.align_xp = atol (optarg); - break; - case 'y': - sp.align_yp = atol (optarg); - break; - case 'w': - sp.align_wp = atol (optarg); - break; - case 'W': - sp.align_wp2 = atol (optarg); - break; - case '?': - exit(1); - } - } - - if (optind >= argc) - { - usage (); - exit (1); - } - - if (size_num == 0) - { - fprintf (stderr, "-s must be specified\n"); - exit (1); - } - - srand (option_seed); - srandom (option_seed); - srand48 (option_seed); - - choice = (struct choice_t *) (*_mp_allocate_func) - ((argc - optind) * sizeof(choice[0])); - for ( ; optind < argc; optind++) - { - struct choice_t c; - routine_find (&c, argv[optind]); - choice[num_choices] = c; - num_choices++; - } - - if ((option_cmp == CMP_RATIO || option_cmp == CMP_DIFFERENCE) && - num_choices < 2) - { - fprintf (stderr, "WARNING, -d or -r does nothing when only one routine requested\n"); - } - - speed_time_init (); - - if ((option_unit == UNIT_CYCLES || option_unit == UNIT_CYCLESPERLIMB) - && speed_cycletime == 1.0) - { - fprintf (stderr, "Times in cycles requested, but CPU frequency unknown.\n"); - fprintf (stderr, "Use environment variable GMP_CPU_FREQUENCY in Hertz, eg. 450e6\n"); - exit (1); - } - - if (option_gnuplot) - { - run_gnuplot (); - } - else - { - if (option_unit == UNIT_SECONDS) - printf ("overhead %.9f secs", speed_measure (speed_noop, NULL)); - else - printf ("overhead %.2f cycles", - speed_measure (speed_noop, NULL) / speed_cycletime); - printf (", precision %d units of %.2e secs, cycle %.1e\n", - speed_precision, speed_unittime, speed_cycletime); - - printf (" "); - for (i = 0; i < num_choices; i++) - printf (" %*s", COLUMN_WIDTH, choice[i].name); - printf ("\n"); - - run_all (stdout); - } - - if (option_resource_usage) - { -#if defined(linux) - /* This is Linux kernel specific. */ - char buf[128]; - sprintf (buf, "cat /proc/%d/status", getpid()); - system (buf); - -#else - /* This doesn't give data sizes on Linux 2.0.36, only utime. */ - struct rusage r; - if (getrusage (RUSAGE_SELF, &r) != 0) - perror ("getrusage"); - else - printf ("utime %ld.%06ld data %ld stack %ld maxresident %ld\n", - r.ru_utime.tv_sec, r.ru_utime.tv_usec, - r.ru_idrss, r.ru_isrss, r.ru_ixrss); -#endif - } - - return 0; -} - - diff --git a/gmp/tune/speed.h b/gmp/tune/speed.h deleted file mode 100755 index 5fc50bb..0000000 --- a/gmp/tune/speed.h +++ /dev/null @@ -1,1015 +0,0 @@ -/* Header for speed and threshold things. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -#ifndef __SPEED_H__ -#define __SPEED_H__ - - -/* sizes of temporary space required */ -#define MPN_KARA_MUL_N_TSIZE(n) (2*((n)+BITS_PER_MP_LIMB)) -#define MPN_KARA_SQR_N_TSIZE(n) (2*((n)+BITS_PER_MP_LIMB)) -#define MPN_TOOM3_MUL_N_TSIZE(n) (2*(n) + 3*BITS_PER_MP_LIMB) -#define MPN_TOOM3_SQR_N_TSIZE(n) (2*((n) + BITS_PER_MP_LIMB)) - - -/* Pad ptr,oldsize with zero limbs (at the most significant end) to make it - newsize long. */ -#define MPN_ZERO_EXTEND(ptr, oldsize, newsize) \ - do { \ - ASSERT ((newsize) >= (oldsize)); \ - MPN_ZERO ((ptr)+(oldsize), (newsize)-(oldsize)); \ - } while (0) - -/* A mask of the least significant n bits. Note 1<<32 doesn't give zero on - x86 family CPUs, hence the separate case for BITS_PER_MP_LIMB. */ -#define MP_LIMB_T_LOWBITMASK(n) \ - ((n) == BITS_PER_MP_LIMB ? MP_LIMB_T_MAX : ((mp_limb_t) 1 << (n)) - 1) - - -/* align must be a power of 2 here, usually CACHE_LINE_SIZE is a good choice */ - -#define TMP_ALLOC_ALIGNED(bytes, align) \ - align_pointer (TMP_ALLOC ((bytes) + (align)-1), (align)) -#define TMP_ALLOC_LIMBS_ALIGNED(limbs, align) \ - ((mp_ptr) TMP_ALLOC_ALIGNED ((limbs)*sizeof(mp_limb_t), align)) - -/* 32 for pentium, 64 for athlon, might want to configure this for other - CPUs. In truth though nothing has yet shown up that cares about cache - line boundaries. The only practical effect of this is to restrict the - range that s->align_xp can take. Perhaps this could be a variable - instead. */ -#define CACHE_LINE_SIZE 64 /* bytes */ - -#define SPEED_TMP_ALLOC_ADJUST_MASK (CACHE_LINE_SIZE/BYTES_PER_MP_LIMB - 1) - -#define SPEED_TMP_ALLOC_LIMBS(limbs, align) \ - (speed_tmp_alloc_adjust \ - (TMP_ALLOC_LIMBS((limbs) + SPEED_TMP_ALLOC_ADJUST_MASK), (align))) - - -/* This is the size for s->xp_block and s->yp_block, used in certain - routines that want to run across many different data values and use - s->size for a different purpose, eg. SPEED_ROUTINE_MPN_GCD_1. - - 512 means 2kbytes of data for each of xp_block and yp_block, making 4k - total, which should fit easily in any L1 data cache. */ - -#define SPEED_BLOCK_SIZE 512 /* limbs */ - - -extern double speed_unittime; -extern double speed_cycletime; -extern int speed_precision; -extern const char *speed_time_string; -void speed_time_init _PROTO ((void)); -void speed_starttime _PROTO ((void)); -double speed_endtime _PROTO ((void)); - -struct speed_params { - unsigned reps; /* how many times to run the routine */ - mp_ptr xp; /* first argument */ - mp_ptr yp; /* second argument */ - mp_size_t size; /* size of both arguments */ - long r; /* user supplied parameter */ - mp_size_t align_xp; /* alignment of xp */ - mp_size_t align_yp; /* alignment of yp */ - mp_size_t align_wp; /* intended alignment of wp */ - mp_size_t align_wp2; /* intended alignment of wp2 */ - mp_ptr xp_block; /* first special SPEED_BLOCK_SIZE block */ - mp_ptr yp_block; /* second special SPEED_BLOCK_SIZE block */ - - double time_divisor; /* optionally set by the speed routine */ - - /* used by the cache priming things */ - int cache; - unsigned src_num, dst_num; - struct { - mp_ptr ptr; - mp_size_t size; - } src[2], dst[3]; -}; - -typedef double (*speed_function_t) _PROTO ((struct speed_params *s)); - -double speed_measure _PROTO ((speed_function_t fun, struct speed_params *s)); - -/* Prototypes for speed measuring routines */ - -double speed_malloc_free _PROTO ((struct speed_params *s)); -double speed_malloc_realloc_free _PROTO ((struct speed_params *s)); -double speed_memcpy _PROTO ((struct speed_params *s)); -double speed_modlimb_invert _PROTO ((struct speed_params *s)); -double speed_mp_allocate_free _PROTO ((struct speed_params *s)); -double speed_mp_allocate_reallocate_free _PROTO ((struct speed_params *s)); - -double speed_mpf_init_clear _PROTO ((struct speed_params *s)); - -double speed_mpn_add_n _PROTO ((struct speed_params *s)); -double speed_mpn_add_n_self _PROTO ((struct speed_params *s)); -double speed_mpn_add_n_inplace _PROTO ((struct speed_params *s)); -double speed_mpn_and_n _PROTO ((struct speed_params *s)); -double speed_mpn_andn_n _PROTO ((struct speed_params *s)); -double speed_mpn_addmul_1 _PROTO ((struct speed_params *s)); -double speed_mpn_bz_divrem_n _PROTO ((struct speed_params *s)); -double speed_mpn_bz_divrem_sb _PROTO ((struct speed_params *s)); -double speed_mpn_bz_tdiv_qr _PROTO ((struct speed_params *s)); -double speed_MPN_COPY _PROTO ((struct speed_params *s)); -double speed_MPN_COPY_DECR _PROTO ((struct speed_params *s)); -double speed_MPN_COPY_INCR _PROTO ((struct speed_params *s)); -double speed_mpn_divexact_by3 _PROTO ((struct speed_params *s)); -double speed_mpn_divmod_1 _PROTO ((struct speed_params *s)); -double speed_mpn_divrem_1 _PROTO ((struct speed_params *s)); -double speed_mpn_divrem_1f _PROTO ((struct speed_params *s)); -double speed_mpn_divrem_1c _PROTO ((struct speed_params *s)); -double speed_mpn_divrem_1cf _PROTO ((struct speed_params *s)); -double speed_mpn_divrem_2 _PROTO ((struct speed_params *s)); -double speed_mpn_gcd _PROTO ((struct speed_params *s)); -double speed_mpn_gcd_1 _PROTO ((struct speed_params *s)); -double speed_mpn_gcdext _PROTO ((struct speed_params *s)); -double speed_mpn_hamdist _PROTO ((struct speed_params *s)); -double speed_mpn_ior_n _PROTO ((struct speed_params *s)); -double speed_mpn_iorn_n _PROTO ((struct speed_params *s)); -double speed_mpn_jacobi_base _PROTO ((struct speed_params *s)); -double speed_mpn_kara_mul_n _PROTO ((struct speed_params *s)); -double speed_mpn_kara_sqr_n _PROTO ((struct speed_params *s)); -double speed_mpn_lshift _PROTO ((struct speed_params *s)); -double speed_mpn_mod_1 _PROTO ((struct speed_params *s)); -double speed_mpn_mod_1c _PROTO ((struct speed_params *s)); -double speed_mpn_mul_1 _PROTO ((struct speed_params *s)); -double speed_mpn_mul_basecase _PROTO ((struct speed_params *s)); -double speed_mpn_mul_fft _PROTO ((struct speed_params *s)); -double speed_mpn_mul_fft_sqr _PROTO ((struct speed_params *s)); -double speed_mpn_mul_fft_full _PROTO ((struct speed_params *s)); -double speed_mpn_mul_fft_full_sqr _PROTO ((struct speed_params *s)); -double speed_mpn_mul_n _PROTO ((struct speed_params *s)); -double speed_mpn_mul_n_sqr _PROTO ((struct speed_params *s)); -double speed_mpn_mul_n_toom3 _PROTO ((struct speed_params *s)); -double speed_mpn_nand_n _PROTO ((struct speed_params *s)); -double speed_mpn_nior_n _PROTO ((struct speed_params *s)); -double speed_mpn_popcount _PROTO ((struct speed_params *s)); -double speed_mpn_rshift _PROTO ((struct speed_params *s)); -double speed_mpn_sqr_basecase _PROTO ((struct speed_params *s)); -double speed_mpn_sqr_n _PROTO ((struct speed_params *s)); -double speed_mpn_sqr_toom3 _PROTO ((struct speed_params *s)); -double speed_mpn_sub_n _PROTO ((struct speed_params *s)); -double speed_mpn_submul_1 _PROTO ((struct speed_params *s)); -double speed_mpn_toom3_mul_n _PROTO ((struct speed_params *s)); -double speed_mpn_toom3_sqr_n _PROTO ((struct speed_params *s)); -double speed_mpn_udiv_qrnnd _PROTO ((struct speed_params *s)); -double speed_mpn_umul_ppmm _PROTO ((struct speed_params *s)); -double speed_mpn_xnor_n _PROTO ((struct speed_params *s)); -double speed_mpn_xor_n _PROTO ((struct speed_params *s)); - -double speed_mpq_init_clear _PROTO ((struct speed_params *s)); - -double speed_mpz_add _PROTO ((struct speed_params *s)); -double speed_mpz_bin_uiui _PROTO ((struct speed_params *s)); -double speed_mpz_fac_ui _PROTO ((struct speed_params *s)); -double speed_mpz_fib_ui _PROTO ((struct speed_params *s)); -double speed_mpz_init_clear _PROTO ((struct speed_params *s)); -double speed_mpz_init_realloc_clear _PROTO ((struct speed_params *s)); -double speed_mpz_powm _PROTO ((struct speed_params *s)); - -double speed_noop _PROTO ((struct speed_params *s)); -double speed_noop_wxs _PROTO ((struct speed_params *s)); -double speed_noop_wxys _PROTO ((struct speed_params *s)); - -double speed_udiv_qrnnd _PROTO ((struct speed_params *s)); -double speed_udiv_qrnnd_preinv _PROTO ((struct speed_params *s)); -double speed_udiv_qrnnd_preinv2norm _PROTO ((struct speed_params *s)); -double speed_umul_ppmm _PROTO ((struct speed_params *s)); - - -/* Prototypes for other routines */ - -/* low 32-bits in p[0], high 32-bits in p[1] */ -void speed_cyclecounter _PROTO ((unsigned p[2])); - -void pentium_wbinvd _PROTO ((void)); - -void noop _PROTO ((void)); -void noop_1 _PROTO ((mp_limb_t n)); -void noop_wxs _PROTO ((mp_ptr wp, mp_srcptr xp, mp_size_t size)); -void noop_wxys _PROTO ((mp_ptr wp, mp_srcptr xp, mp_srcptr yp, - mp_size_t size)); -void mpn_cache_fill _PROTO ((mp_srcptr ptr, mp_size_t size)); -void mpn_cache_fill_dummy _PROTO ((mp_limb_t n)); -mp_ptr speed_tmp_alloc_adjust _PROTO ((void *ptr, mp_size_t align)); -void *_mp_allocate_or_reallocate _PROTO ((void *ptr, - size_t oldsize, size_t newsize)); -void *align_pointer _PROTO ((void *p, size_t align)); -void *_mp_allocate_func_aligned _PROTO ((size_t bytes, size_t align)); -void speed_cache_fill _PROTO ((struct speed_params *s)); -void speed_operand_src _PROTO ((struct speed_params *s, - mp_ptr ptr, mp_size_t size)); -void speed_operand_dst _PROTO ((struct speed_params *s, - mp_ptr ptr, mp_size_t size)); -void mpz_set_n _PROTO ((mpz_ptr z, mp_srcptr p, mp_size_t size)); - -extern int speed_option_addrs; -void speed_option_set _PROTO((const char *s)); - - -#define SPEED_RESTRICT_COND(cond) if (!(cond)) return -1.0; - -/* For mpn_copy or similar. */ -#define SPEED_ROUTINE_MPN_COPY_CALL(call) \ - { \ - mp_ptr wp; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 0); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_dst (s, wp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_COPY(function) \ - SPEED_ROUTINE_MPN_COPY_CALL(function (wp, s->xp, s->size)) -#define SPEED_ROUTINE_MPN_COPYC(function) \ - SPEED_ROUTINE_MPN_COPY_CALL(function (wp, s->xp, s->size, 0)) - - -/* For mpn_add_n, mpn_sub_n, or similar. */ -#define SPEED_ROUTINE_MPN_BINARY_N_CALL(call) \ - { \ - mp_ptr wp; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_src (s, s->yp, s->size); \ - speed_operand_dst (s, wp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_BINARY_N(function) \ - SPEED_ROUTINE_MPN_BINARY_N_CALL ((*function) (wp, s->xp, s->yp, s->size)) - -#define SPEED_ROUTINE_MPN_BINARY_NC(function) \ - SPEED_ROUTINE_MPN_BINARY_N_CALL ((*function) (wp, s->xp, s->yp, s->size, 0)) - -#define SPEED_ROUTINE_MPN_BINARY_N_SELF(function) \ - SPEED_ROUTINE_MPN_BINARY_N_CALL ((*function) (wp, s->xp, s->xp, s->size)) - -#define SPEED_ROUTINE_MPN_BINARY_N_INPLACE(function) \ - SPEED_ROUTINE_MPN_BINARY_N_CALL ((*function) (wp, wp, s->xp, s->size)) - - -/* For mpn_lshift, mpn_rshift, mpn_mul_1, with r, or similar. */ -#define SPEED_ROUTINE_MPN_UNARY_1_CALL(call) \ - { \ - mp_ptr wp; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_dst (s, wp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_UNARY_1(function) \ - SPEED_ROUTINE_MPN_UNARY_1_CALL ((*function) (wp, s->xp, s->size, s->r)) - -#define SPEED_ROUTINE_MPN_UNARY_1C(function) \ - SPEED_ROUTINE_MPN_UNARY_1_CALL ((*function) (wp, s->xp, s->size, s->r, 0)) - -#define SPEED_ROUTINE_MPN_DIVREM_1(function) \ - SPEED_ROUTINE_MPN_UNARY_1_CALL ((*function) (wp, 0, s->xp, s->size, s->r)) - -#define SPEED_ROUTINE_MPN_DIVREM_1C(function) \ - SPEED_ROUTINE_MPN_UNARY_1_CALL ((*function) (wp, 0, s->xp, s->size, s->r, 0)) - -#define SPEED_ROUTINE_MPN_DIVREM_1F(function) \ - SPEED_ROUTINE_MPN_UNARY_1_CALL ((*function) (wp, s->size, s->xp, 0, s->r)) - -#define SPEED_ROUTINE_MPN_DIVREM_1CF(function) \ - SPEED_ROUTINE_MPN_UNARY_1_CALL ((*function) (wp, s->size, s->xp, 0, s->r, 0)) - - -/* For mpn_mul_basecase, xsize=r, ysize=s->size. */ -#define SPEED_ROUTINE_MPN_MUL_BASECASE(function) \ - { \ - mp_ptr wp; \ - mp_size_t size1; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - size1 = (s->r == 0 ? s->size : s->r); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - SPEED_RESTRICT_COND (size1 >= s->size); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (size1 + s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, size1); \ - speed_operand_src (s, s->yp, s->size); \ - speed_operand_dst (s, wp, size1 + s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (wp, s->xp, size1, s->yp, s->size); \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - - -#define SPEED_ROUTINE_MPN_MUL_N_CALL(call) \ - { \ - mp_ptr wp; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (2*s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_src (s, s->yp, s->size); \ - speed_operand_dst (s, wp, 2*s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_MUL_N(function) \ - SPEED_ROUTINE_MPN_MUL_N_CALL (function (wp, s->xp, s->yp, s->size)); - - -#define SPEED_ROUTINE_MPN_MUL_N_TSPACE(call, tsize) \ - { \ - mp_ptr wp, tspace; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (2*s->size, s->align_wp); \ - tspace = SPEED_TMP_ALLOC_LIMBS (tsize, s->align_wp2); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_src (s, s->yp, s->size); \ - speed_operand_dst (s, wp, 2*s->size); \ - speed_operand_dst (s, tspace, tsize); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -/* FIXME: size restrictions */ -#define SPEED_ROUTINE_MPN_KARA_MUL_N(function) \ - SPEED_ROUTINE_MPN_MUL_N_TSPACE \ - (function (wp, s->xp, s->xp, s->size, tspace), \ - MPN_KARA_MUL_N_TSIZE (s->size)) - -/* FIXME: size restrictions */ -#define SPEED_ROUTINE_MPN_TOOM3_MUL_N(function) \ - SPEED_ROUTINE_MPN_MUL_N_TSPACE \ - (function (wp, s->xp, s->yp, s->size, tspace), \ - MPN_TOOM3_MUL_N_TSIZE (s->size)) - - -#define SPEED_ROUTINE_MPN_SQR_CALL(call) \ - { \ - mp_ptr wp; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (2*s->size, s->align_wp); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_dst (s, wp, 2*s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_SQR(function) \ - SPEED_ROUTINE_MPN_SQR_CALL (function (wp, s->xp, s->size)) - - -#define SPEED_ROUTINE_MPN_SQR_TSPACE(call, tsize) \ - { \ - mp_ptr wp, tspace; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (2*s->size, s->align_wp); \ - tspace = SPEED_TMP_ALLOC_LIMBS (tsize, s->align_wp2); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_dst (s, wp, 2*s->size); \ - speed_operand_dst (s, tspace, tsize); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -/* FIXME: size restrictions */ -#define SPEED_ROUTINE_MPN_KARA_SQR_N(function) \ - SPEED_ROUTINE_MPN_SQR_TSPACE (function (wp, s->xp, s->size, tspace), \ - MPN_KARA_SQR_N_TSIZE (s->size)) - -/* FIXME: size restrictions */ -#define SPEED_ROUTINE_MPN_TOOM3_SQR_N(function) \ - SPEED_ROUTINE_MPN_SQR_TSPACE (function (wp, s->xp, s->size, tspace), \ - MPN_TOOM3_SQR_N_TSIZE (s->size)) - - -#define SPEED_ROUTINE_MPN_MOD_CALL(call) \ - { \ - unsigned i; \ - \ - SPEED_RESTRICT_COND (s->size >= 0); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - return speed_endtime (); \ - } - -#define SPEED_ROUTINE_MPN_MOD_1(function) \ - SPEED_ROUTINE_MPN_MOD_CALL ((*function) (s->xp, s->size, s->r)) - -#define SPEED_ROUTINE_MPN_MOD_1C(function) \ - SPEED_ROUTINE_MPN_MOD_CALL ((*function) (s->xp, s->size, s->r, 0)) - - -/* A division of 2*s->size by s->size limbs */ - -#define SPEED_ROUTINE_MPN_BZ_DIVREM_CALL(call) \ - { \ - unsigned i; \ - mp_ptr a, d, q, r; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - a = SPEED_TMP_ALLOC_LIMBS (2*s->size, s->align_xp); \ - d = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_yp); \ - q = SPEED_TMP_ALLOC_LIMBS (s->size+1, s->align_wp); \ - r = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp2); \ - \ - MPN_COPY (a, s->xp, s->size); \ - MPN_COPY (a+s->size, s->xp, s->size); \ - \ - MPN_COPY (d, s->yp, s->size); \ - \ - /* normalize the data */ \ - d[s->size-1] |= MP_LIMB_T_HIGHBIT; \ - a[2*s->size-1] = d[s->size-1] - 1; \ - \ - speed_operand_src (s, a, 2*s->size); \ - speed_operand_src (s, d, s->size); \ - speed_operand_dst (s, q, s->size+1); \ - speed_operand_dst (s, r, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_BZ_DIVREM_N(function) \ - SPEED_ROUTINE_MPN_BZ_DIVREM_CALL((*function) (q, a, d, s->size)) - -#define SPEED_ROUTINE_MPN_BZ_DIVREM_SB(function) \ - SPEED_ROUTINE_MPN_BZ_DIVREM_CALL \ - ((*function) (q, a, 2*s->size, d, s->size)) - -#define SPEED_ROUTINE_MPN_BZ_TDIV_QR(function) \ - SPEED_ROUTINE_MPN_BZ_DIVREM_CALL \ - ((*function) (q, r, 0, a, 2*s->size, d, s->size)) - - -#define SPEED_ROUTINE_MPN_POPCOUNT(function) \ - { \ - unsigned i; \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (s->xp, s->size); \ - while (--i != 0); \ - return speed_endtime (); \ - } - -#define SPEED_ROUTINE_MPN_HAMDIST(function) \ - { \ - unsigned i; \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_operand_src (s, s->yp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (s->xp, s->yp, s->size); \ - while (--i != 0); \ - return speed_endtime (); \ - } - - -/* For mpz_fib_ui, mpz_fac_ui, etc */ - -#define SPEED_ROUTINE_MPZ_UI(function) \ - { \ - mpz_t z; \ - unsigned i; \ - double t; \ - \ - SPEED_RESTRICT_COND (s->size >= 0); \ - \ - mpz_init (z); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (z, s->size); \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - mpz_clear (z); \ - return t; \ - } - - -/* Calculate 2^(m-1) mod m for random odd m of s->size limbs. Having m odd - allows redc to be used. Actually the exponent (m-1) is cut down to at - most 6 limbs so the calculation doesn't take too long. */ -#define SPEED_ROUTINE_MPZ_POWM(function) \ - { \ - mpz_t r, b, e, m; \ - unsigned i; \ - double t; \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - mpz_init (r); \ - mpz_init_set_ui (b, 2); \ - \ - /* force m to odd */ \ - mpz_init (m); \ - mpz_set_n (m, s->xp, s->size); \ - PTR(m)[0] |= 1; \ - \ - mpz_init_set (e, m); \ - mpz_sub_ui (e, e, 1); \ - SIZ(e) = MIN (SIZ(e), 6); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (r, b, e, m); \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - mpz_clear (r); \ - mpz_clear (b); \ - mpz_clear (e); \ - mpz_clear (m); \ - return t; \ - } - - -#define SPEED_ROUTINE_MPN_ADDSUB_CALL(call) \ - { \ - mp_ptr wp, wp2, xp, yp; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 0); \ - \ - TMP_MARK (marker); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - wp2 = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp2); \ - xp = s->xp; \ - yp = s->yp; \ - \ - switch (s->r) { \ - case 0: break; \ - case 1: xp = wp; break; \ - case 2: yp = wp2; break; \ - case 3: xp = wp; yp = wp2; break; \ - case 4: xp = wp2; yp = wp; break; \ - default: \ - fprintf (stderr, "Unrecognised r=%ld in addsub measuring\n", s->r); \ - abort (); \ - } \ - if (xp != s->xp) MPN_COPY (xp, s->xp, s->size); \ - if (yp != s->yp) MPN_COPY (yp, s->yp, s->size); \ - \ - speed_operand_src (s, xp, s->size); \ - speed_operand_src (s, yp, s->size); \ - speed_operand_dst (s, wp, s->size); \ - speed_operand_dst (s, wp2, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - call; \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_ADDSUB_N(function) \ - SPEED_ROUTINE_MPN_ADDSUB_CALL \ - (function (wp, wp2, xp, yp, s->size)); - -#define SPEED_ROUTINE_MPN_ADDSUB_NC(function) \ - SPEED_ROUTINE_MPN_ADDSUB_CALL \ - (function (wp, wp2, xp, yp, s->size, 0)); - - -#define SPEED_ROUTINE_MPN_GCD_1xN(function) \ - { \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - SPEED_RESTRICT_COND (s->r != 0); \ - \ - TMP_MARK (marker); \ - \ - speed_operand_src (s, s->xp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (s->xp, s->size, s->r); \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - - -/* SPEED_BLOCK_SIZE many one GCDs of s->size bits each. */ - -#define SPEED_ROUTINE_MPN_GCD_1_CALL(setup, call) \ - { \ - unsigned i, j; \ - mp_ptr px, py; \ - mp_limb_t x_mask, y_mask; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - SPEED_RESTRICT_COND (s->size <= mp_bits_per_limb); \ - \ - TMP_MARK (marker); \ - px = SPEED_TMP_ALLOC_LIMBS (SPEED_BLOCK_SIZE, s->align_xp); \ - py = SPEED_TMP_ALLOC_LIMBS (SPEED_BLOCK_SIZE, s->align_yp); \ - MPN_COPY (px, s->xp_block, SPEED_BLOCK_SIZE); \ - MPN_COPY (py, s->yp_block, SPEED_BLOCK_SIZE); \ - \ - x_mask = MP_LIMB_T_LOWBITMASK (s->size); \ - y_mask = MP_LIMB_T_LOWBITMASK (s->r != 0 ? s->r : s->size); \ - for (i = 0; i < SPEED_BLOCK_SIZE; i++) \ - { \ - px[i] &= x_mask; px[i] += (px[i] == 0); \ - py[i] &= y_mask; py[i] += (py[i] == 0); \ - setup; \ - } \ - \ - speed_operand_src (s, px, SPEED_BLOCK_SIZE); \ - speed_operand_src (s, py, SPEED_BLOCK_SIZE); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - { \ - j = SPEED_BLOCK_SIZE; \ - do \ - { \ - call; \ - } \ - while (--j != 0); \ - } \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - \ - s->time_divisor = SPEED_BLOCK_SIZE; \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_GCD_1(function) \ - SPEED_ROUTINE_MPN_GCD_1_CALL( , function (&px[j-1], 1, py[j-1])) - -#define SPEED_ROUTINE_MPN_JACBASE(function) \ - SPEED_ROUTINE_MPN_GCD_1_CALL \ - ({ \ - px[i] %= py[i]; \ - px[i] |= 1; \ - py[i] |= 1; \ - if (py[i]==1) py[i]=3; \ - }, \ - function (px[j-1], py[j-1], 0)) - - -/* Run some GCDs of s->size limbs each. The number of different data values - is decreased as s->size**2, since GCD is a quadratic algorithm. - SPEED_ROUTINE_MPN_GCD runs more times than SPEED_ROUTINE_MPN_GCDEXT - though, because the plain gcd is about twice as fast as gcdext. */ - -#define SPEED_ROUTINE_MPN_GCD_CALL(datafactor, call) \ - { \ - unsigned i; \ - mp_size_t j, pieces, psize; \ - mp_ptr wp, wp2, xtmp, ytmp, px, py; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - xtmp = SPEED_TMP_ALLOC_LIMBS (s->size+1, s->align_xp); \ - ytmp = SPEED_TMP_ALLOC_LIMBS (s->size+1, s->align_yp); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - wp2 = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp2); \ - \ - pieces = SPEED_BLOCK_SIZE * datafactor / s->size / s->size; \ - pieces = MAX (pieces, 1); \ - pieces = MIN (pieces, SPEED_BLOCK_SIZE / s->size); \ - \ - psize = pieces * s->size; \ - px = TMP_ALLOC_LIMBS (psize); \ - py = TMP_ALLOC_LIMBS (psize); \ - MPN_COPY (px, pieces==1 ? s->xp : s->xp_block, psize); \ - MPN_COPY (py, pieces==1 ? s->yp : s->yp_block, psize); \ - \ - /* y must be odd, x must have at least as many bits as y */ \ - for (j = 0; j < pieces; j++) \ - { \ - mp_ptr x = px+j*s->size; \ - mp_ptr y = py+j*s->size; \ - y[0] |= 1; \ - if (x[s->size-1] == 0) x[s->size-1] = 1; \ - if (y[s->size-1] == 0) y[s->size-1] = 1; \ - x[s->size-1] = MAX (x[s->size-1], y[s->size-1]); \ - } \ - \ - speed_operand_src (s, px, psize); \ - speed_operand_src (s, py, psize); \ - speed_operand_dst (s, xtmp, s->size); \ - speed_operand_dst (s, ytmp, s->size); \ - speed_operand_dst (s, wp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - { \ - j = pieces; \ - do \ - { \ - MPN_COPY (xtmp, px+(j-1)*s->size, s->size); \ - MPN_COPY (ytmp, py+(j-1)*s->size, s->size); \ - call; \ - } \ - while (--j != 0); \ - } \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - \ - s->time_divisor = pieces; \ - return t; \ - } - -#define SPEED_ROUTINE_MPN_GCD(function) \ - SPEED_ROUTINE_MPN_GCD_CALL (8, function (wp, xtmp, s->size, ytmp, s->size)) - -#define SPEED_ROUTINE_MPN_GCDEXT(function) \ - SPEED_ROUTINE_MPN_GCD_CALL \ - (4, { mp_size_t wp2size; \ - function (wp, wp2, &wp2size, xtmp, s->size, ytmp, s->size); }) - - -#define SPEED_ROUTINE_MPN_DIVREM_2(function) \ - { \ - mp_ptr wp, xp; \ - mp_limb_t yp[2]; \ - unsigned i; \ - double t; \ - TMP_DECL (marker); \ - \ - SPEED_RESTRICT_COND (s->size >= 1); \ - \ - TMP_MARK (marker); \ - xp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_xp); \ - wp = SPEED_TMP_ALLOC_LIMBS (s->size, s->align_wp); \ - \ - /* source is destroyed */ \ - MPN_COPY (xp, s->xp, s->size); \ - \ - /* divisor must be normalized */ \ - MPN_COPY (yp, s->yp_block, 2); \ - yp[1] |= MP_LIMB_T_HIGHBIT; \ - \ - speed_operand_src (s, xp, s->size); \ - speed_operand_src (s, yp, 2); \ - speed_operand_dst (s, wp, s->size); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - function (wp, 0, xp, s->size, yp); \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - TMP_FREE (marker); \ - return t; \ - } - - -#define SPEED_ROUTINE_MODLIMB_INVERT(function) \ - { \ - unsigned i, j; \ - mp_ptr xp; \ - mp_limb_t n = 1; \ - double t; \ - \ - xp = s->xp_block-1; \ - \ - speed_operand_src (s, s->xp_block, SPEED_BLOCK_SIZE); \ - speed_cache_fill (s); \ - \ - speed_starttime (); \ - i = s->reps; \ - do \ - { \ - j = SPEED_BLOCK_SIZE; \ - do \ - { \ - /* randomized but successively dependent */ \ - n += (xp[j] << 1); \ - \ - function (n, n); \ - } \ - while (--j != 0); \ - } \ - while (--i != 0); \ - t = speed_endtime (); \ - \ - /* make sure the compiler won't optimize away n */ \ - noop_1 (n); \ - \ - s->time_divisor = SPEED_BLOCK_SIZE; \ - return t; \ - } - -#endif diff --git a/gmp/tune/time.c b/gmp/tune/time.c deleted file mode 100755 index 269910c..0000000 --- a/gmp/tune/time.c +++ /dev/null @@ -1,552 +0,0 @@ -/* Time routines for speed measurments. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* speed_time_init() - initialize timing things. speed_starttime() calls - this if it hasn't been done yet, so you only need to call this explicitly - if you want to use the global variables before the first measurement. - - speed_starttime() - start a time measurment. - - speed_endtime() - end a time measurment, return time taken, in seconds. - - speed_unittime - global variable with the unit of time measurement - accuracy, in seconds. - - speed_precision - global variable which is the intended accuracy of time - measurements. speed_measure() for instance runs target routines with - enough repetitions so it takes at least speed_unittime*speed_precision - seconds. A program can provide an option so the user can set this. - - speed_cycletime - the time in seconds for each CPU cycle, for example on - a 100 MHz CPU this would be 1.0e-8. If the CPU frequency is unknown, - speed_cycletime is 1.0. See speed_cycletime_init(). - - speed_time_string - a string describing the time method in use. - - - Enhancements: - - Add support for accurate timing on more CPUs, machines and systems. - - Extend automatic CPU frequency determination to more kernels and systems. - - */ - - -#include -#include /* for getenv */ -#if HAVE_UNISTD_H -#include -#endif - -#include -#if HAVE_SYS_SYSCTL_H -#include -#endif - -#include "gmp.h" -#include "gmp-impl.h" -#include "longlong.h" - -#include "speed.h" - - -#if HAVE_SPEED_CYCLECOUNTER -#define SPEED_USE_CYCLECOUNTER 1 -#else -#define SPEED_USE_MICROSECOND_GETRUSAGE 0 -#define SPEED_USE_MICROSECOND_GETTIMEOFDAY 1 -#define SPEED_USE_TMS_UTIME 0 -#endif - - -#define TIMEVAL_SECS(tp) \ - ((double) (tp)->tv_sec + (double) (tp)->tv_usec * 1.0e-6) - - -/* Look for an environment variable for CPU clock frequency. - GMP_CPU_FREQUENCY should be in Hertz, in floating point form, - eg. "450e6". */ -int -speed_cpu_frequency_environment (void) -{ - char *e; - - e = getenv ("GMP_CPU_FREQUENCY"); - if (e == NULL) - return 0; - - speed_cycletime = 1.0 / atof (e); - return 1; -} - - -/* On FreeBSD 3.3 the headers have #defines like CPU_WALLCLOCK under - CTL_MACHDEP but don't seem to have anything for machdep.tsc_freq or - machdep.i586_freq. Using the string forms with sysctlbyname() works - though, and lets libc worry about the defines and headers. - - FreeBSD 3.3 has tsc_freq, FreeBSD 2.2.8 has i586_freq instead. - The "sysctl -a" command prints everything available. */ - -#if HAVE_SYSCTLBYNAME -int -speed_cpu_frequency_sysctlbyname (void) -{ - unsigned val; - size_t valsize; - - valsize = sizeof(val); - if (sysctlbyname ("machdep.tsc_freq", &val, &valsize, NULL, 0) != 0 - || valsize != sizeof(val)) - { - valsize = sizeof(val); - if (sysctlbyname ("machdep.i586_freq", &val, &valsize, NULL, 0) != 0 - || valsize != sizeof(val)) - return 0; - } - - speed_cycletime = 1.0 / (double) val; - return 1; -} -#endif - - -/* Linux doesn't seem to have any system call to get the CPU frequency, at - least not in 2.0.x or 2.2.x, so it's necessary to read /proc/cpuinfo. - - i386 2.0.36 - "bogomips" is the CPU frequency. - - i386 2.2.13 - has both "cpu MHz" and "bogomips", and it's "cpu MHz" which - is the frequency. - - alpha 2.2.5 - "cycle frequency [Hz]" seems to be right, "BogoMIPS" is - very slightly different. */ - -int -speed_cpu_frequency_proc_cpuinfo (void) -{ - FILE *fp; - char buf[128]; - double val; - int ret = 0; - - if ((fp = fopen ("/proc/cpuinfo", "r")) != NULL) - { - while (fgets (buf, sizeof (buf), fp) != NULL) - { - if (sscanf (buf, "cycle frequency [Hz] : %lf est.\n", &val) == 1) - { - speed_cycletime = 1.0 / val; - ret = 1; - break; - } - if (sscanf (buf, "cpu MHz : %lf\n", &val) == 1) - { - speed_cycletime = 1e-6 / val; - ret = 1; - break; - } - if (sscanf (buf, "bogomips : %lf\n", &val) == 1) - { - speed_cycletime = 1e-6 / val; - ret = 1; - break; - } - } - fclose (fp); - } - return ret; -} - - -/* SunOS /bin/sysinfo prints a line like: - cpu0 is a "75 MHz TI,TMS390Z55" CPU */ - -#if HAVE_POPEN -int -speed_cpu_frequency_sunos_sysinfo (void) -{ - FILE *fp; - char buf[128]; - double val; - int ret = 0; - - /* Error messages are sent to /dev/null in case /bin/sysinfo doesn't - exist. The brackets are necessary for some shells (eg. ash). */ - if ((fp = popen ("(/bin/sysinfo) 2>/dev/null", "r")) != NULL) - { - while (fgets (buf, sizeof (buf), fp) != NULL) - { - if (sscanf (buf, " cpu0 is a \"%lf MHz", &val) == 1) - { - speed_cycletime = 1e-6 / val; - ret = 1; - break; - } - } - pclose (fp); - } - return ret; -} -#endif - - -/* This is for Solaris. "psrinfo" is the command-line interface to - processor_info(). "prtconf -vp" gives similar information. */ - -#if HAVE_PROCESSOR_INFO -#include /* for _SC_NPROCESSORS_CONF */ -#include /* for processor_info_t */ -int -speed_cpu_frequency_processor_info (void) -{ - processor_info_t p; - int i, n, mhz = 0; - - n = sysconf (_SC_NPROCESSORS_CONF); - for (i = 0; i < n; i++) - { - if (processor_info (i, &p) != 0) - continue; - if (p.pi_state != P_ONLINE) - continue; - - if (mhz != 0 && p.pi_clock != mhz) - { - fprintf (stderr, - "speed_cpu_frequency_processor_info(): There's more than one CPU and they have different clock speeds\n"); - return 0; - } - - mhz = p.pi_clock; - } - - speed_cycletime = 1.0e-6 / (double) mhz; - return 1; -} -#endif - - -/* Each function returns 1 if it succeeds in setting speed_cycletime, or 0 - if not. */ - -static const struct { - int (*fun) _PROTO ((void)); - const char *description; - -} speed_cpu_frequency_table[] = { - - /* This should be first, so an environment variable can override anything - the system gives. */ - { speed_cpu_frequency_environment, - "environment variable GMP_CPU_FREQUENCY (in Hertz)" }, - -#if HAVE_SYSCTLBYNAME - { speed_cpu_frequency_sysctlbyname, - "sysctlbyname() machdep.tsc_freq or machdep.i586_freq" }, -#endif - -#if HAVE_PROCESSOR_INFO - { speed_cpu_frequency_processor_info, - "processor_info() pi_clock" }, -#endif - - { speed_cpu_frequency_proc_cpuinfo, - "linux kernel /proc/cpuinfo file, cpu MHz or bogomips" }, - -#if HAVE_POPEN - { speed_cpu_frequency_sunos_sysinfo, - "SunOS /bin/sysinfo program cpu0 output" }, -#endif -}; - - -int -speed_cycletime_init (void) -{ - int i; - - for (i = 0; i < numberof (speed_cpu_frequency_table); i++) - if ((*speed_cpu_frequency_table[i].fun)()) - return 1; - - fprintf (stderr, - "Cannot determine CPU frequency, need one of the following\n"); - for (i = 0; i < numberof (speed_cpu_frequency_table); i++) - fprintf (stderr, "\t- %s\n", speed_cpu_frequency_table[i].description); - - return 0; -} - - -/* ---------------------------------------------------------------------- */ -#if SPEED_USE_CYCLECOUNTER - -const char *speed_time_string - = "Time measurements using CPU cycle counter.\n"; - -/* bigish value because we have a fast timer */ -int speed_precision = 10000; - -double speed_unittime; -double speed_cycletime; - -static int speed_time_initialized = 0; -static unsigned speed_starttime_save[2]; - -/* Knowing the CPU frequency is mandatory, so cycles can be converted to - seconds. */ -void -speed_time_init (void) -{ - if (speed_time_initialized) - return; - speed_time_initialized = 1; - - if (!speed_cycletime_init ()) - exit (1); - - speed_unittime = speed_cycletime; -} - -void -speed_starttime (void) -{ - if (!speed_time_initialized) - speed_time_init (); - speed_cyclecounter (speed_starttime_save); -} - -#define M_2POWU ((double) (1L << (BITS_PER_INT-2)) * 4.0) -#define M_2POW32 4294967296.0 - -double -speed_endtime (void) -{ - unsigned endtime[2], e0; - double t; - - speed_cyclecounter (endtime); - - /* This still works even if speed_cyclecounter() puts a value bigger than - 32-bits in the low word. The start and end values are allowed to - cancel in uints in case a uint is more than the 53 bits that will - normally fit in a double. */ - e0 = endtime[0] - speed_starttime_save[0]; - t = e0 - (e0 > endtime[0] ? M_2POWU : 0); - t += (endtime[1] - speed_starttime_save[1]) * M_2POW32; - - return t * speed_unittime; -} - -#endif - - -/* ---------------------------------------------------------------------- */ -#if SPEED_USE_MICROSECOND_GETRUSAGE -#include -#include -#include - -const char *speed_time_string - = "Time measurements using microsecond accurate getrusage.\n"; - -int speed_precision = 1000; - -double speed_unittime = 1.0e-6; -double speed_cycletime = 1.0; - -static struct rusage speed_starttime_save; -static int speed_time_initialized = 0; - -void -speed_time_init (void) -{ - if (speed_time_initialized) - return; - speed_time_initialized = 1; - - speed_cycletime_init (); -} - -void -speed_starttime (void) -{ - if (!speed_time_initialized) - speed_time_init (); - - getrusage (0, &speed_starttime_save); -} - -double -speed_endtime (void) -{ - struct rusage r; - - getrusage (0, &r); - return TIMEVAL_SECS (&r.ru_utime) - - TIMEVAL_SECS (&speed_starttime_save.ru_utime); -} -#endif - - -/* ---------------------------------------------------------------------- */ -#if SPEED_USE_MICROSECOND_GETTIMEOFDAY -/* This method is for systems with a microsecond accurate gettimeofday(). - - A dummy timezone parameter is always given to gettimeofday(), in case it - doesn't allow NULL. */ - -#include - -const char *speed_time_string - = "Time measurements using microsecond accurate gettimeofday.\n"; - -/* highish value because we have an accurate timer */ -int speed_precision = 1000; - -double speed_unittime = 1.0e-6; -double speed_cycletime = 1.0; - -static struct timeval speed_starttime_save; -static int speed_time_initialized = 0; - -void -speed_time_init (void) -{ - if (speed_time_initialized) - return; - speed_time_initialized = 1; - - speed_cycletime_init (); -} - -void -speed_starttime (void) -{ - struct timezone tz; - if (!speed_time_initialized) - speed_time_init (); - - gettimeofday (&speed_starttime_save, &tz); -} - -double -speed_endtime (void) -{ - struct timeval t; - struct timezone tz; - - gettimeofday (&t, &tz); - return TIMEVAL_SECS (&t) - TIMEVAL_SECS (&speed_starttime_save); -} - -#endif - - -/* ---------------------------------------------------------------------- */ -#if SPEED_USE_TMS_UTIME -/* You're in trouble if you have to use this method. Speed measurments and - threshold tuning are going to take a long time. */ - -#if STDC_HEADERS -#include /* for errno */ -#include /* for strerror */ -#endif -#if HAVE_UNISTD_H -#include /* for sysconf */ -#endif -#include /* for times */ - -const char *speed_time_string - = "Time measurements using tms_utime.\n"; - - -/* lowish default value so we don't take days and days to do tuning */ -int speed_precision = 200; - -double speed_unittime; -double speed_cycletime = 1.0; - -static struct tms speed_starttime_save; -static int speed_time_initialized = 0; - -void -speed_time_init (void) -{ - long clk_tck; - - if (speed_time_initialized) - return; - speed_time_initialized = 1; - - speed_cycletime_init (); - -#if HAVE_SYSCONF - clk_tck = sysconf (_SC_CLK_TCK); - if (clk_tck == -1L) - { - fprintf (stderr, "sysconf(_SC_CLK_TCK) not available: %s\n", - strerror(errno)); - fprintf (stderr, "\tusing CLK_TCK instead\n"); - clk_tck = CLK_TCK; - } -#else - clk_tck = CLK_TCK; -#endif - - speed_unittime = 1.0 / (double) clk_tck; -} - -/* Burn up CPU until a times() tms_utime tick boundary. - Doing so lets you know a measurement has started on a tick boundary, - effectively halving the uncertainty in the measurement. - *t1 gets the start times() values the caller should use. */ -void -times_utime_boundary (struct tms *t1) -{ - struct tms t2; - times (&t2); - do - times (t1); - while (t1->tms_utime == t2.tms_utime); -} - -void -speed_starttime (void) -{ - if (!speed_time_initialized) - speed_time_init (); - times_utime_boundary (&speed_starttime_save); -} - -double -speed_endtime (void) -{ - struct tms t; - times (&t); - return (t.tms_utime - speed_starttime_save.tms_utime) * speed_unittime; -} - -#endif diff --git a/gmp/tune/tuneup.c b/gmp/tune/tuneup.c deleted file mode 100755 index ada92aa..0000000 --- a/gmp/tune/tuneup.c +++ /dev/null @@ -1,746 +0,0 @@ -/* Create tuned thresholds for various algorithms. */ - -/* -Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. -*/ - -/* Usage: tune [-t] [-t] [-p precision] - - -t turns on some diagnostic traces, a second -t turns on more traces. - - The thresholds are determined as follows. A crossover may not be a - single size but rather a range where it oscillates between method A or - method B faster. If the threshold is set making B used where A is faster - (or vice versa) that's bad. Badness is the percentage time lost and - total badness is the sum of this over all sizes measured. The threshold - is set to minimize total badness. - - Suppose, as sizes increase, method B becomes faster than method A. The - effect of the rule is that, as you look at increasing sizes, isolated - points where B is faster are ignored, but when it's consistently faster, - or faster on balance, then the threshold is set there. The same result - is obtained thinking in the other direction of A becoming faster at - smaller sizes. - - In practice the thresholds tend to be chosen to bring on the next - algorithm fairly quickly. - - This rule is attractive because it's got a basis in reason and is fairly - easy to implement, but no work has been done to actually compare it in - absolute terms to other possibilities. - - Sometimes running the program twice produces slightly different results. - This is probably because there's so little separating algorithms near - their crossover, and on that basis it should make little or no difference - to the final speed of the relevant routines, but nothing has been done to - check that carefully. - - Limitations: - - The FFTs aren't subject to the same badness rule as the other thresholds, - so each k is probably being brought on a touch early. This isn't likely - to make a difference, and the simpler probing means fewer tests. - -*/ - -#define TUNE_PROGRAM_BUILD 1 - -#include -#include -#include -#include -#include - -#include "gmp.h" -#include "gmp-impl.h" - -#include "speed.h" -#include "sqr_basecase.h" - -#if !HAVE_DECL_OPTARG -extern char *optarg; -extern int optind, opterr; -#endif - - -#define MAX_SIZE 1000 /* limbs */ -#define STEP_FACTOR 0.01 /* how much to step sizes by (rounded down) */ -#define MAX_TABLE 2 /* threshold entries */ - - -#if WANT_FFT -mp_size_t option_fft_max_size = 50000; /* limbs */ -#else -mp_size_t option_fft_max_size = 0; -#endif -int option_trace = 0; -int option_fft_trace = 0; -struct speed_params s; - -struct dat_t { - mp_size_t size; - double d; -} *dat = NULL; -int ndat = 0; -int allocdat = 0; - - -/* Each "_threshold" array must be 1 bigger than the number of thresholds - being tuned in a set, because one() stores an value in the entry above - the one it's determining. */ - -mp_size_t mul_threshold[MAX_TABLE+1] = { MP_SIZE_T_MAX }; -mp_size_t fft_modf_mul_threshold = MP_SIZE_T_MAX; -mp_size_t sqr_threshold[MAX_TABLE+1] = { MP_SIZE_T_MAX }; -mp_size_t fft_modf_sqr_threshold = MP_SIZE_T_MAX; -mp_size_t bz_threshold[2] = { MP_SIZE_T_MAX }; -mp_size_t fib_threshold[2] = { MP_SIZE_T_MAX }; -mp_size_t powm_threshold[2] = { MP_SIZE_T_MAX }; -mp_size_t gcd_accel_threshold[2] = { MP_SIZE_T_MAX }; -mp_size_t gcdext_threshold[2] = { MP_SIZE_T_MAX }; - - -#ifndef KARATSUBA_SQR_MAX -#define KARATSUBA_SQR_MAX 0 /* meaning no limit */ -#endif - -struct param_t { - const char *name[MAX_TABLE]; - int stop_since_change; - mp_size_t min_size; - mp_size_t max_size[MAX_TABLE]; -}; - - -/* Add an entry to the end of the dat[] array, reallocing to make it bigger - if necessary. */ -void -add_dat (mp_size_t size, double d) -{ -#define ALLOCDAT_STEP 500 - - ASSERT_ALWAYS (ndat <= allocdat); - - if (ndat == allocdat) - { - dat = (struct dat_t *) _mp_allocate_or_reallocate - (dat, allocdat * sizeof(dat[0]), - (allocdat+ALLOCDAT_STEP) * sizeof(dat[0])); - allocdat += ALLOCDAT_STEP; - } - - dat[ndat].size = size; - dat[ndat].d = d; - ndat++; -} - - -/* Return the threshold size based on the data accumulated. */ -mp_size_t -analyze_dat (int i, int final) -{ - double x, min_x; - int j, min_j; - - /* If the threshold is set at dat[0].size, any positive values are bad. */ - x = 0.0; - for (j = 0; j < ndat; j++) - if (dat[j].d > 0.0) - x += dat[j].d; - - if (option_trace >= 2 && final) - { - printf ("\n"); - printf ("x is the sum of the badness from setting thresh at given size\n"); - printf (" (minimum x is sought)\n"); - printf ("i=%d size=%ld first x=%.4f\n", i, dat[j].size, x); - } - - min_x = x; - min_j = 0; - - - /* When stepping to the next dat[j].size, positive values are no longer - bad (so subtracted), negative values become bad (so add the absolute - value, meaning subtract). */ - for (j = 0; j < ndat; x -= dat[j].d, j++) - { - if (option_trace >= 2 && final) - printf ("i=%d size=%ld x=%.4f\n", i, dat[j].size, x); - - if (x < min_x) - { - min_x = x; - min_j = j; - } - } - - return min_j; -} - - -double -tuneup_measure (speed_function_t fun, struct speed_params *s) -{ - static mp_ptr xp, yp; - double t; - TMP_DECL (marker); - - TMP_MARK (marker); - s->xp = SPEED_TMP_ALLOC_LIMBS (s->size, 0); - s->yp = SPEED_TMP_ALLOC_LIMBS (s->size, 0); - - mpn_random (s->xp, s->size); - mpn_random (s->yp, s->size); - - t = speed_measure (fun, s); - - TMP_FREE (marker); - return t; -} - - -void -print_define (const char *name, mp_size_t value) -{ - printf ("#ifndef %s\n", name); - printf ("#define %-23s ", name); - if (value == MP_SIZE_T_MAX) - printf ("MP_SIZE_T_MAX\n"); - else - printf ("%5ld\n", value); - printf ("#endif\n"); -} - - -/* table[i+1] needs to be set to a sensible value when testing method i+1 - because mpn_mul_n uses TOOM3_MUL_THRESHOLD to size the temporary - workspace for mpn_kara_mul_n. */ - -void -one (speed_function_t function, mp_size_t table[], size_t max_table, - struct param_t *param) -{ - static struct param_t dummy; - int i; - - if (param == NULL) param = &dummy; - -#define DEFAULT(x,n) if (param->x == 0) param->x = (n); - - DEFAULT (stop_since_change, 80); - DEFAULT (min_size, 10); - for (i = 0; i < numberof (param->max_size); i++) - DEFAULT (max_size[i], MAX_SIZE); - - s.size = param->min_size; - - for (i = 0; i < max_table && s.size < MAX_SIZE; i++) - { - int since_positive, since_thresh_change; - int thresh_idx, new_thresh_idx; - - ndat = 0; - since_positive = 0; - since_thresh_change = 0; - thresh_idx = 0; - - if (option_trace >= 2) - { - printf (" algorithm-A algorithm-B ratio possible\n"); - printf (" (seconds) (seconds) diff thresh\n"); - } - - for ( ; s.size < MAX_SIZE; - s.size += MAX ((mp_size_t) floor (s.size * STEP_FACTOR), 1)) - { - double ti, tiplus1, d; - - /* If there's a size limit and it's reached then it should still - be sensible to analyze the data since we want the threshold put - either at or near the limit. */ - if (s.size >= param->max_size[i]) - { - if (option_trace) - printf ("Reached maximum size (%ld) without otherwise stopping\n", - param->max_size[i]); - break; - } - - /* - FIXME: check minimum size requirements are met, possibly by just - checking for the -1 returns from the speed functions. - if (s.size < MPN_TOOM_TABLE_TO_MINSIZE (i)) - continue; - */ - - /* using method i at this size */ - table[i] = s.size+1; - table[i+1] = MAX_SIZE; - ti = tuneup_measure (function, &s); - if (ti == -1.0) - abort (); - - /* using method i+1 at this size */ - table[i] = s.size; - table[i+1] = s.size+1; - tiplus1 = tuneup_measure (function, &s); - if (tiplus1 == -1.0) - abort (); - - /* Calculate the fraction by which the one or the other routine is - slower. */ - if (tiplus1 >= ti) - d = (tiplus1 - ti) / tiplus1; /* negative */ - else - d = (tiplus1 - ti) / ti; /* positive */ - - add_dat (s.size, d); - - new_thresh_idx = analyze_dat (i, 0); - - - if (option_trace >= 2) - printf ("i=%d size=%ld %.9f %.9f % .4f %c %d\n", - i, s.size, ti, tiplus1, d, - ti > tiplus1 ? '#' : ' ', - dat[new_thresh_idx].size); - - /* Stop if the last time method i was faster was more than a - certain number of measurements ago. */ -#define STOP_SINCE_POSITIVE 200 - if (d >= 0) - since_positive = 0; - else - if (++since_positive > STOP_SINCE_POSITIVE) - { - if (option_trace >= 1) - printf ("i=%d stopped due to since_positive (%d)\n", - i, STOP_SINCE_POSITIVE); - break; - } - - /* Stop if method i has become slower by a certain factor. */ -#define STOP_FACTOR 1.2 - if (ti >= tiplus1 * STOP_FACTOR) - { - if (option_trace >= 1) - printf ("i=%d stopped due to ti >= tiplus1 * factor (%.1f)\n", - i, STOP_FACTOR); - break; - } - - /* Stop if the threshold implied hasn't changed in a certain - number of measurements. (It's this condition that ususally - stops the loop.) */ - if (thresh_idx != new_thresh_idx) - since_thresh_change = 0, thresh_idx = new_thresh_idx; - else - if (++since_thresh_change > param->stop_since_change) - { - if (option_trace >= 1) - printf ("i=%d stopped due to since_thresh_change (%d)\n", - i, param->stop_since_change); - break; - } - - /* Stop if the threshold implied is more than a certain number of - measurements ago. */ -#define STOP_SINCE_AFTER 500 - if (ndat - thresh_idx > STOP_SINCE_AFTER) - { - if (option_trace >= 1) - printf ("i=%d stopped due to ndat - thresh_idx > amount (%d)\n", - i, STOP_SINCE_AFTER); - break; - } - } - - /* Stop when the size limit is reached before the end of the - crossover, without a specified param->max_size[i]. */ - if (s.size >= MAX_SIZE) - { - fprintf (stderr, "%s\n", param->name[i]); - fprintf (stderr, "i=%d sizes %ld to %ld total %d measurements\n", - i, dat[0].size, dat[ndat-1].size, ndat); - fprintf (stderr, " max size reached before end of crossover\n"); - break; - } - - if (option_trace >= 1) - printf ("i=%d sizes %ld to %ld total %d measurements\n", - i, dat[0].size, dat[ndat-1].size, ndat); - - if (ndat == 0) - break; - - table[i] = dat[analyze_dat (i, 1)].size; - - print_define (param->name[i], table[i]); - - /* Look for the next threshold starting from the current one, but back - a bit. */ - s.size = table[i]+1; - } -} - - -/* Special probing for the fft thresholds. The size restrictions on the - FFTs mean the graph of time vs size has a step effect. See this for - example using - - ./speed -s 4096-16384 -t 128 -P foo mpn_mul_fft.8 mpn_mul_fft.9 - gnuplot foo.gnuplot - - The current approach is to compare routines at the midpoint of relevant - steps. Arguably a more sophisticated system of threshold data is wanted - if this step effect remains. */ - -struct fft_param_t { - const char *table_name; - const char *threshold_name; - const char *modf_threshold_name; - mp_size_t *p_threshold; - mp_size_t *p_modf_threshold; - mp_size_t first_size; - mp_size_t max_size; - speed_function_t function; - speed_function_t mul_function; - mp_size_t sqr; -}; - -/* mpn_mul_fft requires pl a multiple of 2^k limbs, but with - N=pl*BIT_PER_MP_LIMB it internally also pads out so N/2^k is a multiple - of 2^(k-1) bits. */ - -mp_size_t -fft_step_size (int k) -{ - if (2*k-1 > BITS_PER_INT) - { - printf ("Can't handle k=%d\n", k); - abort (); - } - return (1<", k, m, pl); */ - - if (pl == 0 || (pl & (m-1)) != 0) - pl = (pl | (m-1)) + 1; - -/* printf (" %ld\n", pl); */ - return pl; -} - -void -fft (struct fft_param_t *p) -{ - mp_size_t size; - int i, k; - - for (i = 0; i < numberof (mpn_fft_table[p->sqr]); i++) - mpn_fft_table[p->sqr][i] = MP_SIZE_T_MAX; - - *p->p_threshold = MP_SIZE_T_MAX; - *p->p_modf_threshold = MP_SIZE_T_MAX; - - option_trace = MAX (option_trace, option_fft_trace); - - printf ("#ifndef %s\n", p->table_name); - printf ("#define %s {", p->table_name); - if (option_trace >= 2) - printf ("\n"); - - k = FFT_FIRST_K; - size = p->first_size; - for (;;) - { - double tk, tk1; - - size = fft_next_size (size+1, k+1); - - if (size >= p->max_size) - break; - if (k >= FFT_FIRST_K + numberof (mpn_fft_table[p->sqr])) - break; - - usleep(10000); - - /* compare k to k+1 in the middle of the current k+1 step */ - s.size = size + fft_step_size (k+1) / 2; - s.r = k; - tk = tuneup_measure (p->function, &s); - if (tk == -1.0) - abort (); - - usleep(10000); - - s.r = k+1; - tk1 = tuneup_measure (p->function, &s); - if (tk1 == -1.0) - abort (); - - if (option_trace >= 2) - printf ("at %ld size=%ld k=%d %.9lf k=%d %.9lf\n", - size, s.size, k, tk, k+1, tk1); - - /* declare the k+1 threshold as soon as it's faster at its midpoint */ - if (tk1 < tk) - { - mpn_fft_table[p->sqr][k-FFT_FIRST_K] = s.size; - printf (" %ld,", s.size); - if (option_trace >= 2) printf ("\n"); - k++; - } - } - - mpn_fft_table[p->sqr][k-FFT_FIRST_K] = 0; - printf (" 0 }\n"); - printf ("#endif\n"); - - - size = p->first_size; - - /* Declare an FFT faster than a plain toom3 etc multiplication found as - soon as one faster measurement obtained. A multiplication in the - middle of the FFT step is tested. */ - for (;;) - { - int modf = (*p->p_modf_threshold == MP_SIZE_T_MAX); - double tk, tm; - - /* k=7 should be the first FFT which can beat toom3 on a full - multiply, so jump to that threshold and save some probing after the - modf threshold is found. */ - if (!modf && size < mpn_fft_table[p->sqr][2]) - { - size = mpn_fft_table[p->sqr][2]; - if (option_trace >= 2) - printf ("jump to size=%ld\n", size); - } - - size = fft_next_size (size+1, mpn_fft_best_k (size, p->sqr)); - k = mpn_fft_best_k (size, p->sqr); - - if (size >= p->max_size) - break; - - usleep(10000); - - s.size = size + fft_step_size (k) / 2; - s.r = k; - tk = tuneup_measure (p->function, &s); - if (tk == -1.0) - abort (); - - usleep(10000); - - if (!modf) s.size /= 2; - tm = tuneup_measure (p->mul_function, &s); - if (tm == -1.0) - abort (); - - if (option_trace >= 2) - printf ("at %ld size=%ld k=%d %.9lf size=%ld %s mul %.9lf\n", - size, - size + fft_step_size (k) / 2, k, tk, - s.size, modf ? "modf" : "full", tm); - - if (tk < tm) - { - if (modf) - { - *p->p_modf_threshold = s.size; - print_define (p->modf_threshold_name, *p->p_modf_threshold); - } - else - { - *p->p_threshold = s.size; - print_define (p->threshold_name, *p->p_threshold); - break; - } - } - } - -} - - -void -all (void) -{ - TMP_DECL (marker); - - TMP_MARK (marker); - s.xp_block = SPEED_TMP_ALLOC_LIMBS (SPEED_BLOCK_SIZE, 0); - s.yp_block = SPEED_TMP_ALLOC_LIMBS (SPEED_BLOCK_SIZE, 0); - - speed_time_init (); - fprintf (stderr, "speed_precision %d, speed_unittime %.2e\n", - speed_precision, speed_unittime); - fprintf (stderr, "MAX_SIZE %ld, fft_max_size %ld, STEP_FACTOR %.3f\n", - MAX_SIZE, option_fft_max_size, STEP_FACTOR); - fprintf (stderr, "\n"); - - { - struct tm *tp; - time_t t; - time (&t); - tp = localtime (&t); - printf ("/* Generated by tuneup.c, %d-%02d-%02d. */\n\n", - tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday); - } - - { - static struct param_t param; - param.name[0] = "KARATSUBA_MUL_THRESHOLD"; - param.name[1] = "TOOM3_MUL_THRESHOLD"; - param.max_size[1] = TOOM3_MUL_THRESHOLD_LIMIT; - one (speed_mpn_mul_n, mul_threshold, numberof(mul_threshold)-1, ¶m); - } - printf("\n"); - - { - static struct param_t param; - param.name[0] = "KARATSUBA_SQR_THRESHOLD"; - param.name[1] = "TOOM3_SQR_THRESHOLD"; - param.max_size[0] = KARATSUBA_SQR_MAX; - one (speed_mpn_sqr_n, sqr_threshold, numberof(sqr_threshold)-1, ¶m); - } - printf("\n"); - - { - static struct param_t param; - param.name[0] = "BZ_THRESHOLD"; - one (speed_mpn_bz_tdiv_qr, bz_threshold, 1, ¶m); - } - printf("\n"); - - { - static struct param_t param; - param.name[0] = "FIB_THRESHOLD"; - one (speed_mpz_fib_ui, fib_threshold, 1, ¶m); - } - printf("\n"); - - /* mpz_powm becomes slow before long, so stop soon after the determined - threshold stops changing. */ - { - static struct param_t param; - param.name[0] = "POWM_THRESHOLD"; - param.stop_since_change = 15; - one (speed_mpz_powm, powm_threshold, 1, ¶m); - } - printf("\n"); - - { - static struct param_t param; - param.name[0] = "GCD_ACCEL_THRESHOLD"; - param.min_size = 1; - one (speed_mpn_gcd, gcd_accel_threshold, 1, ¶m); - } - { - static struct param_t param; - param.name[0] = "GCDEXT_THRESHOLD"; - param.min_size = 1; - param.max_size[0] = 200; - one (speed_mpn_gcdext, gcdext_threshold, 1, ¶m); - } - printf("\n"); - - if (option_fft_max_size != 0) - { - { - static struct fft_param_t param; - param.table_name = "FFT_MUL_TABLE"; - param.threshold_name = "FFT_MUL_THRESHOLD"; - param.p_threshold = &FFT_MUL_THRESHOLD; - param.modf_threshold_name = "FFT_MODF_MUL_THRESHOLD"; - param.p_modf_threshold = &FFT_MODF_MUL_THRESHOLD; - param.first_size = TOOM3_MUL_THRESHOLD / 2; - param.max_size = option_fft_max_size; - param.function = speed_mpn_mul_fft; - param.mul_function = speed_mpn_mul_n; - param.sqr = 0; - fft (¶m); - } - printf("\n"); - { - static struct fft_param_t param; - param.table_name = "FFT_SQR_TABLE"; - param.threshold_name = "FFT_SQR_THRESHOLD"; - param.p_threshold = &FFT_SQR_THRESHOLD; - param.modf_threshold_name = "FFT_MODF_SQR_THRESHOLD"; - param.p_modf_threshold = &FFT_MODF_SQR_THRESHOLD; - param.first_size = TOOM3_SQR_THRESHOLD / 2; - param.max_size = option_fft_max_size; - param.function = speed_mpn_mul_fft_sqr; - param.mul_function = speed_mpn_sqr_n; - param.sqr = 0; - fft (¶m); - } - printf ("\n"); - } - - TMP_FREE (marker); -} - - -int -main (int argc, char *argv[]) -{ - int opt; - - /* Unbuffered so if output is redirected to a file it isn't lost if the - program is killed part way through. */ - setbuf (stdout, NULL); - setbuf (stderr, NULL); - - while ((opt = getopt(argc, argv, "f:o:p:t")) != EOF) - { - switch (opt) { - case 'f': - if (optarg[0] == 't') - option_fft_trace = 2; - else - option_fft_max_size = atol (optarg); - break; - case 'o': - speed_option_set (optarg); - break; - case 'p': - speed_precision = atoi (optarg); - break; - case 't': - option_trace++; - break; - case '?': - exit(1); - } - } - - all (); - return 0; -} diff --git a/gmp/urandom.h b/gmp/urandom.h deleted file mode 100755 index fa15837..0000000 --- a/gmp/urandom.h +++ /dev/null @@ -1,76 +0,0 @@ -/* urandom.h -- define urandom returning a full unsigned long random value. - -Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#if defined (__hpux) || defined (__svr4__) || defined (__SVR4) -/* HPUX lacks random(). */ -static inline mp_limb_t -urandom () -{ - return mrand48 (); -} -#define __URANDOM -#endif - -#if defined (__alpha) && !defined (__URANDOM) -/* DEC OSF/1 1.2 random() returns a double. */ -long mrand48 (); -static inline mp_limb_t -urandom () -{ - return mrand48 () | (mrand48 () << 32); -} -#define __URANDOM -#endif - -#if BITS_PER_MP_LIMB == 32 && !defined (__URANDOM) -#if defined (__cplusplus) -extern "C" { -#endif -long random (); -#if defined (__cplusplus) -} -#endif -static inline mp_limb_t -urandom () -{ - /* random() returns 31 bits, we want 32. */ - return random () ^ (random () << 1); -} -#define __URANDOM -#endif - -#if BITS_PER_MP_LIMB == 64 && !defined (__URANDOM) -#if defined (__cplusplus) -extern "C" { -#endif -long random (); -#if defined (__cplusplus) -} -#endif -static inline mp_limb_t -urandom () -{ - /* random() returns 31 bits, we want 64. */ - return random () ^ ((mp_limb_t) random () << 31) ^ ((mp_limb_t) random () << 62); -} -#define __URANDOM -#endif - diff --git a/gmp/version.c b/gmp/version.c deleted file mode 100755 index 9d544ee..0000000 --- a/gmp/version.c +++ /dev/null @@ -1,26 +0,0 @@ -/* gmp_version -- version number compiled into the library */ - -/* -Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -The GNU MP Library 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. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#include "gmp.h" -#include "gmp-impl.h" - -const char *gmp_version = VERSION; diff --git a/gmp/version.texi b/gmp/version.texi deleted file mode 100755 index a555c4d..0000000 Binary files a/gmp/version.texi and /dev/null differ diff --git a/lsh/ANNOUNCE b/lsh/ANNOUNCE deleted file mode 100755 index 4f355a4..0000000 Binary files a/lsh/ANNOUNCE and /dev/null differ diff --git a/lsh/AUTHORS b/lsh/AUTHORS deleted file mode 100755 index 8f6abb5..0000000 Binary files a/lsh/AUTHORS and /dev/null differ diff --git a/lsh/COPYING b/lsh/COPYING deleted file mode 100755 index e29d371..0000000 Binary files a/lsh/COPYING and /dev/null differ diff --git a/lsh/ChangeLog b/lsh/ChangeLog deleted file mode 100755 index 00fe5a0..0000000 --- a/lsh/ChangeLog +++ /dev/null @@ -1,2343 +0,0 @@ -2001-09-04 Niels Möller - - * Released lsh-1.3.4. - -2001-09-04 Niels Möller - - * doc/lsh.texinfo: Updated for 1.3.4. In particular, added doc on - X forwarding, -x, -B, and --log-file options, and encrypted - private keys. Deleted the paragraph about the obsolete --userauth - option. - - * src/client.c (client_command_session): Ask for a pty also for - (supposedly non-interactive) exec sessions. - -2001-09-03 Niels Möller - - * src/xauth.c (xauth_process): New function, using XauReadAuth. - (xauth_lookup): Use xauth_process instead of XauGetAuthByAddr. - - * src/client_x11.c (make_client_x11_display): Initialize the fake - cookie properly. - - * src/xauth.h: New file with the xauth_lookup prototype. - - * src/xauth.c (xauth_lookup): Deleted address_length argument. Bug - fixes. - -2001-09-03 Niels Möller - - * src/xauth.c: Rewrote to use libXau. - - * src/client_x11.c (client_x11_auth_info): Deleted class; merged - with client_x11_display. - (parse_display): Take a client_x11_display as argument. Do xauth lookup. - (get_client_x11_auth_info): Deleted function. - - * src/client.c (DEFINE_CALLBACK): Declare self argument as UNUSED. - - * src/Makefile.am.in (liblsh_a_SOURCES): Added xauth.c. - - * configure.in: Check for X, libXau and XauGetAuthByAddr. - - * src/client_x11.c (client_x11_channel): New fields auth_length - and name_length, for recording the decoded lengths in the setup - message. - (X11_SETUP_MAX_LENGTH): Defined as 48, which is the size of a message - with a 16 octet cookie. - Updated description of the X11 connection setup message. - (LE_READ_UINT16, LE_WRITE_UINT16): New macros. - (do_client_channel_x11_receive): Bug fixes, seems to work now. - - * src/suspend.h: Declare suspend_callback as extern. Noticed by - Jean-Pierre. - -2001-09-03 Niels Möller - - * src/client_x11.c: Added comment about observed X11 packets (that - seem contrary to the documentation in RFC 1013. - (do_client_channel_x11_receive): Print received cookie, for - debugging purposes. - (make_forward_x11): Print generated fake cookie, for debugging - purposes. - (parse_display): Fixed ssh_format invocation creating the local - socket name. - (do_channel_open_x11): Fixed invocation of verbose(). - (do_format_request_x11_forward): Get the connection from the - channel, now that the connection pointer is available there. - (do_format_request_x11_forward): Hex encode the cookie. That's - ugly, but needed for compatibility. - - * src/client_pty.c: Dropped lsh:-prefix on messages, it's added - automatically in werror.c. - - * src/client.c (client_maybe_x11): Write a message if DISPLAY not - set or it's value doesn't make sense. - -2001-09-02 Niels Möller - - * src/client.c (make_client_session): Added escape sequences q, v - and d, for controlling the verbosity flags. - (client_argp_parser): Look at used_x11 after setting up the shell - session. - - * src/lshg.c (make_options): Pass NULL random to - init_client_options. - - * src/client_x11.c (make_client_x11_display): Free the fake cookie - if we fail. - (make_forward_x11): Make up a random cookie. - - * src/client.c (init_client_options): New argument RANDOM. - (client_maybe_x11): Pass on RANDOM to make_forward_x11. - - * src/client.h (client_options): Moved RANDOM attribute here, from - lsh_options. - -2001-09-01 Niels Möller - - * src/client.c: Moved -x option to lsh.c. - - * src/channel.c (register_channel): Deleted connection argument. - - * src/channel.h (ssh_channel): Replaced the write pointer with a - pointer to the connection. - (channel_request): Deleted connection argument. - * src/channel.h (CHANNEL_REQUEST): Likewise. - - * src/resource.c (init_resource): Renamed from resource_init, for - consistency. Updated all callers. - - * src/lsh.h (struct client_x11_display): Forward declare. - - * src/client_x11.h: Deleted, prototypes moved to client.h. - - * src/client.h (client_options): New attributes with_x11 and - used_x11. - - * src/client.c (client_maybe_pty): New function. - (client_maybe_x11): New function. - (client_shell_session): Use client_maybe_pty and client_maybe_x11. - (client_command_session): Use client_maybe_x11. - (client_argp_parser): --x11-forward should be a modifier option, - not an action. - - * src/channel.h (channel_table): Added attribute x11_display. - - * src/Makefile.am.in (liblsh_a_SOURCES): Added client_x11.c. - -2001-08-31 Niels Möller - - * src/client.c (client_argp_parser): Implemented -X flag. - -2001-08-30 Niels Möller - - * src/xauth.c: New file. - - * src/client_x11.c: Work in progress. - (client_x11_auth_info): New class. - - * src/channel_forward.c (init_channel_forward): New function, - extracted from make_channel_forward. - -2001-08-30 Niels Möller - - * configure.in: Bumped version to 1.3.4. - -2001-08-29 Niels Möller - - * Released lsh-1.3.3. - -2001-08-29 Niels Möller - - * src/sftp/testsuite: Fixed scripts to work outside of $srcdir. - - * src/sftp/buffer.c, src/sftp/client.c: Include string.h. - - * src/algorithms.c (all_symmetric_algorithms): Use aes256-cbc as - an alias for rijndael. - (lookup_crypto): Recognize aes256-cbc, aes-cbc and aes. - -2001-08-23 Niels Möller - - * src/connection.c (do_exc_connection_handler): Display exception - message. Suggested by Jonas Bofjäll. XXX: Fix in 1.2 branch. - -2001-08-28 Niels Möller - - * src/sftp/testsuite/run-tests: Use srcdir when starting scripts. - - * src/Makefile.am.in (liblsh_a_SOURCES): Added channel_forward.c. - - * src/channel_forward.h: Renamed the tcpip_channel to - channel_forward, and moved it to a separate file. It's not really - tcpip-forwarding specific, and can be reused for x11-forwarding. - - * src/lsh_types.h (READ_UINT16): Fixed shift count. XXX: Fix in - 1.2 branch. - - * src/parse.c (parse_uint16): New function. - (parse_string16): New function. - -2001-08-27 Niels Möller - - * src/sftp/testsuite/Makefile.am (EXTRA_DIST): Use EXTRA_DIST, not - DISTFILES. cd to $srcdir when running the tests. - - * src/sftp/Makefile.am (EXTRA_DIST): Include header files in the - dist. - - * buffer.c, buffer.h, client.c, client.h: Added copyright notices. - - * src/sftp/testsuite/Makefile.am: New file. - - * src/sftp/sftp-server.c (struct sftp_file): New struct with fd - and position. - (enum struct sftp_handle_type): Renamed constants to - HANDLE_TYPE_FILE and HANDLE_TYPE_DIRECTORY. - (handle_t): Deleted typedef. - (HANDLE_FILE): New macro replacing HANDLE_FD. - (sftp_read): New function. Keep track of position, and use - seek/pread only when appropriate. - (sftp_write): Likewise. - - * src/sftp/configure.in (AC_OUTPUT): Generate testsuite/Makefile. - - * src/sftp/client.c: Minor fixes; deleted unused variables, static - declared functions. - - * src/sftp/Makefile.am (SUBDIRS): Added testsuite. - - * src/Makefile.am.in (SUBDIRS): Added sftp. - - * misc/bootstrap.sh: Bootstrap the src/sftp subdirectory. - - * configure.in: Configure the src/sftp subdirectory. - -2001-08-26 Niels Möller - - * src/testsuite/export-1-test: Don't use $srcdir for finding - lsh-export-key. - - * src/zlib.c (do_zlib): Don't print any message if Z_BUF_ERROR - happens with avail_in = 0. - - * src/lshd.c (main_options): New experimental option --subsystems. - (parse_subsystem_list): New function. - (main_argp_parser): Handle --subsystems. - (main): Install a subsystems handler, if appropriate. - - * src/server_session.c (shell_request): Deleted unused reaper - attribute. - (lookup_subsystem): New function. - (do_spawn_subsystem): New function. - (make_subsystem_handler): New function. - -2001-08-21 Niels Möller - - * src/client_userauth.c (make_client_publickey_auth): Initialize - TYPE attribute properly. - - * src/server_userauth.c (server_userauth_none): New authentication - method. - - * src/lshd.c (main_argp_parser): Install a handler for the "none" - authentication method. - (main): Always require user authentication (used to allow clients - to start the ssh-connection service directly, under the same - restrictions as for "none" authentication). - - * src/lsh.c (main_options): Deleted options --userauth and - --no-userauth. - (lsh_login_command): Try the "none" authentication method. - - * src/handshake.c (handshake_command): Use CAST_SUBTYPE. - - * src/connection_commands.c (connection_if_srp): Deleted command. - - * src/command.c (do_command_4): Use CAST_SUBTYPE, in case - command_4 is inherited. - (do_command_3): Use CAST_SUBTYPE, in case command_3 is inherited. - (do_command_2): Use CAST_SUBTYPE, command_2 is inherited by - sexp_print_command. - - * src/client_userauth.c (format_userauth_none): New function. - (make_client_none_auth): New function. - -2001-08-12 Niels Möller - - * src/client.c (do_exit): New callback function. - (make_client_session): Bind the sequence . to exit. - (client_options): New action option -B, --background. - (background_process): New command. - (client_argp_parser): Implement -B. - - * src/lshg.c (main_argp_parser): Check that make_gateway_address - doesn't return NULL. XXX: Fix in 1.2 branch. - (options2info): Use self->gateway. XXX: Fix in 1.2 branch. - -2001-07-30 Niels Möller - - * src/testsuite/export-1-test: Fixed invocation of compare_output. - -2001-07-06 Niels Möller - - * src/io_commands.c (io_write_file_command): Bugfix. - - * src/command.h (command_simple): Deleted class. - (STATIC_COMMAND_SIMPLE): Deleted macro. - (DEFINE_COMMAND_SIMPLE): Deleted macro. - (catch_command): Inherit command, not command_simple. - - * src/command.c (do_call_simple_command): Deleted. - (catch_collect_body): Inherit command, not command_simple. - - * src/sexp_commands.h (sexp_print_command): Inherit command_2. - - * src/lsh_proxy.c (proxy_destination): Use DEFINE_COMMAND2. - - * src/lsh-writekey.c: Don't use DEFINE_COMMAND_SIMPLE. - * src/lsh.c: Likewise. - * src/lshd.c: Likewise. - * src/lshg.c: Likewise. - * src/proxy.c: Likewise. - * src/spki_commands.c: Likewise. - - * src/keyexchange.c (kexinit_filter): Redefined using - DEFINE_COMMAND2. - - * src/io_commands.c (io_write_file_command): Use DEFINE_COMMAND. - (connect_local_command): Likewise. - (io_log_peer_command): Likewise. - - * src/gateway_commands.c (gateway_setup_command): Use - DEFINE_COMMAND. - (gateway_accept): Use DEFINE_COMMAND2. - - * src/lsh-writekey.c: Don't use command_simple. - - * src/connection_commands.c (connection_remember): Redefined using - DEFINE_COMMAND2. - - * src/channel.c (connection_service_command): Use DEFINE_COMMAND, - not DEFINE_COMMAND_SIMPLE. - * src/client.c (client_options2remote): Likewise. - (client_options2actions) Likewise. - -2001-07-05 Niels Möller - - * src/testsuite/Makefile.am (TS_SH): Added export-1-test. - - * src/lsh-export-key.c (ssh2_print_command): Inherit command_2. - Don't use command_simple. - -2001-07-04 Niels Möller - - * src/command.c (collect_state_1): Deleted class. - (collect_state_1): Deleted class. - (collect_state_2): Deleted class. - (collect_state_3): Deleted class. - (make_collect_state_1): Deleted function. - (make_collect_state_2): Deleted function. - - * src/command.h (command_2): Made invoke a method, not a function - pointer. Updated users. - (COMMAND_2_INVOKE): New macro. - (collect_info_3): Deleted class. - (collect_info_2): Deleted class. - (collect_info_1): Deleted class. - (STATIC_COLLECT_1): Deleted macro. - (STATIC_COLLECT_2): Deleted macro. - (STATIC_COLLECT_2_FINAL): Deleted macro. - (STATIC_COLLECT_3_FINAL): Deleted macro. - - * src/channel_commands.h (install_info): Inherit command_2, - instead of collect_info_2. - - * src/testsuite/functions.sh (spawn_lshd): Pass --no-syslog to - lshd, not --log-file. - - * src/tcpforward_commands.c (open_forwarded_tcpip): Redefined - using DEFINE_COMMAND2. - (open_direct_tcpip): Likewise. - (remote_listen_command): Likewise. - (make_request_tcpip_forward_command): Deleted function. Moved code - to remote_listen_command. - (make_direct_tcpip_handler): Redefined using DEFINE_COMMAND. - (make_tcpip_forward_handler): Likewise. - - * src/sexp_commands.c (sexp_print_raw_hash): Redefined using - DEFINE_COMMAND3. - - * src/proxy.c (chain_connections): Redefined using DEFINE_COMMAND3. - - * src/command.c (do_trace_continuation): Use trace(... %t ...). - - * src/werror.c (logfile_flag): Deleted global variable. - (werror_vformat): Added %t, for printing the object type. - - * src/lshd.c: New option --no-syslog. - - * src/io_commands.c (listen_with_callback): Redefined using - DEFINE_COMMAND3. - - * src/handshake.c (handshake_command): Redefined using - DEFINE_COMMAND4. - - * src/connection_commands.c (connection_if_srp): Redefined using - DEFINE_COMMAND3. - (make_connection_if_srp): Use make_command_3_invoke_2. - - * src/combinators.c (command_Cp): Bugfix, changed argument order. - -2001-07-03 Niels Möller - - * src/testsuite/runtests (srcdir): By default, use `pwd`, not ".". - - * src/testsuite/functions.sh: Don't set srcdir here. - (spawn_lshd): Send messages to lshd.log. - - * src/werror.c (logfile_flag): New global variable. - (syslog_flag): Deleted. - (werror_argp_parser): Set logfile_flag of a log file option is - encountered. - - * src/lshd.c (main): Don't use syslog if the user provided an - explicit log-file option. - - * src/combinators.c (command_C): Redefined using DEFINE_COMMAND3. - (command_Cp): Redefined using DEFINE_COMMAND4, but disabled the - new version as it doesn't quite work. - - * src/testsuite/macros.m4: Include string.h. - - * src/combinators.c (command_Sp): Redefined using - DEFINE_COMMAND4. - (command_B): Redefined using DEFINE_COMMAND3. - (command_Bp): Redefined using - DEFINE_COMMAND4. - - * src/command.c (command_4_invoke_3): New class. - (make_command_4_invoke_3): New function. - (command_4_invoke_2): New class. - (make_command_4_invoke_2): New function. - (command_4_invoke): New class. - (make_command_4_invoke): New function. - - * src/command.h (command_4): New class. - (DEFINE_COMMAND4): New macro. - - * src/gateway_commands.c: Include string.h. - - * configure.in: Bumped version to 1.3.3. - -2001-07-02 Niels Möller - - * src/combinators.c (command_I): Redefined using DEFINE_COMMAND. - Updated users as the type was changed in the process. - (command_K): Redefined using DEFINE_COMMAND2. - (command_S): Redefined using DEFINE_COMMAND3. - - * src/command.c: New class. - (make_command_2_invoke): New function. - (command_3_invoke_2): New class. - (make_command_3_invoke_2): New function. - (command_3_invoke): New class. - (make_command_3_invoke): New function. - (progn_command): Use DEFINE_COMMAND isntead of - DEFINE_COMMAND_SIMPLE. - - * src/command.h: Started replacing command_simple and the - collect_info_n classes with simpler schemes. - (command_2): New class. - (DEFINE_COMMAND2): New macro. - (command_3): New class. - (DEFINE_COMMAND3): New macro. - - * src/connection_commands.c (connection_require_userauth): Changed - invocation of DEFINE_COMMAND. - * src/gateway_commands.c (gateway_init): Likewise. - - * src/command.h (DEFINE_COMMAND): Changed macro to not take the - function arguments as arguments. - - * src/command.c (gaba_apply): Rewrote to not use - COMMAND_SIMPLE_CALL. - (do_command_unimplemented): Deleted function. - -2001-06-27 Niels Möller - - * acinclude.m4: Added template for socklen_t definition. - - * acconfig.h: Deleted definitions, use AH_TEMPLATE in configure.in - instead. Can this file be removed completely now? - - * configure.in: Added AH_TEMPLATE calls. Deleted test for - offsetof. - - * src/client_escape.c (newlinep): New function. - Treat NL and CR equivalently. - (scan_escape): Simplified. Also doesn't use memchr anymore. - - * src/io.c (io_listen_local): Use plain offsetof. - (io_connect_local): Likewise. - - * src/lsh_types.h (OFFSET_OF): Deleted definition, simply trust - stddef.h. - - * src/server_userauth.c (do_exc_userauth_handler): Let the - connection's exception handler deal with EXC_PROTOCOL (fixed - somewhat differently in the 1.2.x branch). - -2001-06-26 Niels Möller - - * configure.in: Deleted IDEA support. - - * src/process_atoms (atom2define): Changed invocation of tr to be - compatible with the Solaris 8 tr. - -2001-06-26 Niels Möller - - * src/client_escape.c (NEWLINE): New macro. - (do_escape_handler): Reset state to GOT_NONE appropriately. - - * src/client.c (client_argp_parser): Added empty statement after - label. - (make_client_session): Bind ^Z to suspend. - -2001-06-24 Niels Möller - - * src/xalloc.h (CHECK_TYPE) [DEBUG_ALLOC]: Added parentheses. - * src/xalloc.h (CHECK_SUBTYPE) [DEBUG_ALLOC]: Likewise. - - * src/werror.c (werror_vformat): Implemented the 'p' (paranoia) - modifier for %c. - - * src/client_escape.c (escape_dispatch): Use %pc with werror. - - * src/client.c (make_client_session): Check if stdin is a tty, - when deciding on the default for escape char handling. - -2001-06-20 Niels Möller - - * src/client_escape.c (do_escape_handler): Fixed the EOF case. - -2001-06-19 Niels Möller - - * src/client_session.c (client_read_stdin): New function, for - installing the escape-char handler on stdin. - (do_client_io): Use client_read_stdin. - (make_client_session_channel): Added argument escape. - - * src/client_escape.c: Moved suspend-related code to suspend.c. - - * src/client.c (client_escape_info): New function. - (client_options): New option ---escape-char or 'e'. - (make_client_session): Seet up escape char info. - (client_argp_parser): Handle escape-char option. Call - suspend_install_handler. - - * src/Makefile.am.in (liblsh_a_SOURCES): Added suspend.c. - - * src/unix_interact.c: Moved suspend-related code to suspend.c. - - * src/suspend.c, src/suspend.h: New files. - - * configure.in: Bumped version to 1.3.2. - -2001-06-17 Niels Möller - - * src/rsync/rsync.h: Include , not . - - * src/channel.c (alloc_channel): Initialize new channel-entries to - NULL. - - * src/cast.c: Adapted to nettle. - - * Makefile.am.in (DOTDISTS): Deleted references to the symmetric - subdirectory. - (MAKEFILESAM): Likewise. - * configure.in (AC_CONFIG_FILES): Likewise. - - * doc/HACKING (ROAD MAP): Updated to mention nettle. - - * doc/lsh.texinfo: Added @dircategory and @direntry. - - * src/twofish.c: Adapted to nettle. - -2001-06-15 Niels Möller - - * src/blowfish.c: nettle updates. - * src/serpent.c: Likewise. - - * configure.in: Configure in the src/nettle sub directory. - - * misc/bootstrap.sh: Invoke the nettle .bootstrap script. - -2001-06-13 Niels Möller - - * misc/bootstrap.sh: Bootstrap the nettle subdirectory. - - * src/rsync/: Updated to libnettle conventions. - - * configure.in (CPPFLAGS): Add -LSH and -I$srcdir/src, needed by - src/rsync/. - -2001-06-12 Niels Möller - - * src/dsa.c, src/dsa_keygen.c, src/md5.c, src/rijndael.c, - src/sha.c: Adapted to the nettle API. - - * configure.in: Use src/nettle instead of src/symmetric. - * src/Makefile.am.in: Likewise. - * src/testsuite/Makefile.am: Likewise. - -2001-06-09 Niels Möller - - * src/io.c (do_consuming_read): In the EOF case, call - close_fd_read after A_WRITE. - -2001-06-07 Niels Möller - - * src/io.c (do_kill_io_backend): Let close_fd do it's work. - -2001-06-06 Niels Möller - - * src/io.c (close_fd): Really close the fd, and invoke any close - callback. - (io_iter): Simplified handling of closed files. Simply unlink - them, close_fd has to do the rest of the work. - -2001-05-29 Niels Möller - - * acinclude.m4: AC_CHECK_MEMBER: Deleted definition (a similar - macro is included in autoconf-2.50). - AC_CHECK_VAR: Deleted. - (AC_CHECK_KRB_LIB): Don't use changequote. - - * configure.in: Set SRP_PROGRAM. - Require autoconf-2.50. - Use the new AC_CHECK_MEMBERS macro. - - * src/unix_user.c: Update for autoconf-2.50, changed HAVE_UT_NAME - to HAVE_STRUCT_UTMP_NAME, and similarly for other defines. - -2001-05-23 Niels Möller - - * configure.in: Some cleanup, and update for autoconf-2.50. Some - more work needed. - -2001-05-17 Niels Möller - - * configure.in: Set SRP_PROGRAM. - - * src/Makefile.am.in (EXTRA_PROGRAMS): Added srp-gen. - (bin_PROGRAMS): Use SRP_PROGRAM, don't compile srp-gen if - SRP-support is disabled. - - * src/testsuite/write-key-2-test: Fixed test; check for output - files in the testhome directory. - - * src/unix_user.c: Fixed dummy definition of struct utmp (spotted - by Tomi Ollila). - -2001-05-16 Niels Möller - - * configure.in: Bumped version to 1.3.1. - - * Released 1.3.0. - -2001-05-15 Niels Möller - - * src/scm/gaba.scm: Some more cleanup. - - * src/lshd.c (do_exc_lshd_handler): Handle EXC_RESOLVE. - - * src/testsuite/functions.sh (spawn_lshd): Use 127.0.0.1 instead - of localhost. - - * src/scm/gaba.scm (append-deep): Deleted. - (type->category): Deleted. - (type->declaration): Deleted. - (type->mark): Deleted. - (type->free): Deleted. - (fix-method): Deleted. - (do-instance-struct): Deleted. - (do-struct): Deleted. - (do-mark-function): Deleted. - (do-free-function): Deleted. - (do-struct-mark-function): Deleted. - (do-struct-free-function): Deleted. - (do-class): Deleted. - -2001-05-15 Niels Möller - - * src/scm/gaba.scm: Rewrote the functions for generating C code. - -2001-05-15 Niels Möller - - * configure.in: Updated version number to 1.3.0. - -2001-05-14 Niels Möller - - * src/gc.c (gc) [!DEBUG_ALLOC]: Don't use number_of_strings. - -2001-05-11 Niels Möller - - * src/testsuite/functions.sh (PIDFILE): New variable, with - absolute path to the pid-file. FIXED in 1.2 branch. - (spawn_lshd): $PIDFILE. FIXED in 1.2 branch. - -2001-05-03 Niels Möller - - * src/lshd.c (main): Start the background randomness poll *after* - forking into the background. FIXED in 1.2 branch. - - * src/testsuite/functions.sh (spawn_lshd): Use --daemon flag. - -2001-05-02 Niels Möller - - * sexp_streamed_parser.c: Deleted file. - - * src/unix_user.c (format_env_pair): Return const char *. - (format_env_pair_c): Likewise. - (do_exec_shell): Use const char ** for argv and envp. - - * src/xalloc.c (lsh_free): Cast to void * before calling free, as - free doesn't accept const void *. - (lsh_string_free): Changed argument type to const struct - lsh_string *. - (lsh_space_free): Bug-fix. - (lsh_space_alloc): Use lsh_malloc, not xalloc directly. - (lsh_space_free): Changed argument type to const void *. - - * src/userauth.h (lsh_user): Use const char ** for argv. - -2001-05-01 Niels Möller - - * src/unix_interact.c (unix_read_password): Use const prompt - string. - (unix_yes_or_no): Likewise. - - * src/srp_exchange.c (make_srp_entry): Use const struct lsh_string - for the salt. - - * src/spki_commands.c (do_spki_decrypt): Use const struct lsh_string. - - * src/spki.c (subject_match_hash): Use const struct lsh_string. - (do_spki_tag_prefix_match): Likewise. - (spki_subject_by_hash): Likewise. - (do_spki_lookup): Likewise. - - * src/sexp_parser.c (skip_space): New function, skipping - whitespace and comments. - (sexp_parse_transport): Allow whitespace and comments. - - * src/sexp_commands.c: Don't use the streamed sexp parser. - (sexp_parser): New class. - (do_sexp_parse_once): New function. - (do_sexp_parse_many): New function. - (do_read_sexp_continue): Deleted function. - (make_read_sexp_continuation): Deleted function. - (read_sexp_exception_handler): Deleted class. - (do_read_sexp_exception_handler): Deleted function. - (make_read_sexp_exception_handler): Deleted function. - (make_sexp_parser): New function. - (make_read_sexp_command): New argument MAX_SIZE. - - * src/sexp.c: Constification, use const struct lsh_string for all - sexp-related strings. - -2001-04-26 Niels Möller - - * src/scm/gaba.scm: Added const type modifier. - - * src/sexp-conv.c (MAX_SEXP_SIZE): New constant, used with - make_read_sexp_command. - - * src/server_session.c (do_spawn_exec): Use const char * for argv - entries. - - * src/server_keyexchange.c (MAX_SRP_SIZE): New constant, used with - make_read_sexp_command. - - * src/lsh-writekey.c (MAX_SEXP_SIZE): New constant. Used with - STATIC_READ_SEXP. - - * src/lsh-export-key.c (MAX_KEY_SIZE): New constant. Use with - make_read_sexp_command. - - * src/io.c (do_buffered_read): Call close_fd_read on error. This - way, the user doensn't have to use an exception handler just for - closing the file. - - * src/interact.h (interact): Use const for prompt arguments. - - * src/format.c (lsh_get_cstring): Use const for input and output. - - * src/pkcs5.c (pkcs5_derive_key): Declare password and salt input - as const. - - * src/abstract_crypto.c (crypt_string): Declare the input string - const. Nevertheless, reuse it for output in case FREE is true. - (crypt_string_pad): Declare input string const. - (crypt_string_unpad): Likewise. - - * src/Makefile.am.in (liblsh_a_SOURCES): Deleted - sexp_streamed_parser.c. - -2001-04-25 Niels Möller - - * src/keyexchange.c (do_handle_newkeys): Added verbose message - when receiving NEWKEYS. - (do_handle_kexinit): Added verbose message when receiving KEXINIT - message. - - * src/parse.c (parse_next_atom): Tolerate empty atoms, for - compatibility with "SSH-1.99-2.0.13 (non-commercial)". XXX Fix in - 1.2 branch? - -2001-04-17 Niels Möller - - * src/testsuite/Makefile.am (TS_MORE_SH): Added tests - lshg-cat-test, lshg-cat-2-test and ssh1-fallback-test. - - * src/testsuite/functions.sh: Renamed SERVERFLAGS to LSHD_FLAGS, - CLIENTFLAGS to LSH_FLAGS, and added LSHG_FLAGS. - - * src/testsuite/lshg-cat-2-test: New test. - - * src/testsuite/lshg-cat-test: Sleep some, waiting for lsh to - connect. - - * src/sftp/.bootstrap: Don't run ./configure. - - * src/werror.c (werror_argp_parser): Initialize program_name at - ARGP_KEY_INIT time. - - * src/resource.c (dont_free_live_resource): Be more quiet during - gc_final. - - * src/lshg.c (do_exc_lshg_handler): Fixed werror format string. - Fixed in 1.2 branch. - - * src/lsh.c (do_lsh_lookup): If the user decides to trust the key, - add it to the spki_context. - - * src/lcp: Replaced the bashism "==" with "=". - - * src/gc.c (gc_final_p): New variable, non-zero during gc_final(). - - * src/client_session.c (make_client_session_channel): Register - stdio files as resources. - -2001-04-12 Niels Möller - - * src/lshd.c (main_argp_parser): Bugfix: Use the supplied - interface! Fixed in 1.2 branch. - - * src/testsuite/ssh1-fallback-test: New test. - - * src/testsuite/lshg-cat-test: New test. - - * src/testsuite/fake-sshd1: New file. - - * src/testsuite/functions.sh (spawn_lshd): Pass arguments to lshd. - Fixed in 1.2 branch. - (exec_lshg): New function. - - * src/ssh1_fallback.c (fall_back_to_ssh1): Reset the fd to - blocking mode. Fixed in 1.2 branch. - - * src/io.c (io_set_blocking): New function. Added in 1.2 branch. - (do_exc_finish_read_handler): Close fd immediately on - EXC_FINISH_IO. Fixed in 1.2 branch. - -2001-04-11 Niels Möller - - * src/userauth.h (lsh_process): New class. - (lsh_user): The fork_method now returns the child as an - lsh_process. - - * src/unix_user.c (process_resource): Inherit lsh_process. - (do_signal_process): New function. - - * src/unix_interact.c (install_suspend_handler): New function. - (stop_handler): New signal handler for TSTP, that sets and resets - the tty modes. - - * src/tty.c (tty_getwinsize): Take a struct terminal_dimensions * - as argument. - (tty_setwinsize): Likewise. - - * src/server_session.c (server_session): Changed type of process - attribute to lsh_process. Updated uses. - (do_alloc_pty): Check request syntax in all cases, even if there's - no pty. - (do_window_change_request): New function. - - * src/interact.h (struct terminal_dimensions): Moved definition... - * src/tty.h (struct terminal_dimensions): ...to here. - - * src/client_pty.c: Include tty.h. - - * src/client.h (escape_info): New class. - - * src/Makefile.am.in (liblsh_a_SOURCES): Added client_escape.c. - - * src/client_escape.c: New file. - -2001-04-10 Niels Möller - - * src/client.c (make_client_session): Use set_error_nonblocking. - -2001-04-09 Niels Möller - - * src/werror.c (set_error_nonblocking): New function. - (set_error_stream): Deleted WITH_POLL argument. - (werror_options): Aded option --log-file. - (werror_argp_parser): Process --log-file option. - - * ANNOUNCE: Changed "COPYRIGHT" to "LICENSE", by rms' request. - Fixed in 1.2 branch. - -2001-04-08 Niels Möller - - * src/lsh.c (main_argp_parser): Deleted old -L handling (moved to - client.c). - - * src/sexp_commands.c (do_print_raw_hash_simple): Deleted unused - function. - - * src/sexp.c (sexp_sn): Deleted unused function. - - * src/io.c (make_listen_callback_no_peer): Deleted unused function. - - * src/gc.c (gc): Display number of strings. - - * src/client_session.c (do_client_session_eof): Deleted old code - that closed stdin here. - - * src/client.c (do_exit_status): Deleted old code sending - CHANNEL_EOF here. - (do_exit_signal): Likewise. - (do_exit_signal): Signals in the exit-signal message are no longer - encoded as integers. XXX Fix in 1.2 branch? - - * src/channel.c (do_exc_finish_channel_handler): Deleted old - (#if:ed out) code for raising EXC_FINISH_READ. - (channel_close_handler): Deleted old code calling the channel's - EOF handler here. - - * src/lsh.c (main): Call io_final. - - * src/io.h (lsh_fd): Added label attribute. - - * src/io.c (kill_fd): Deleted. - (io_backend): Inherit resource. - (do_kill_io_backend): New function. - (make_io_backend): Call resource_init. - (io_final): New function. - (init_file): New argument LABEL. - (make_lsh_fd): New rgument LABEL. Updated callers. - (close_fd): Display label. - (io_iter): Display label. - - * src/lsh-writekey.c (make_writekey): Deleted unneeded global - definitions. - - * src/resource.c (dont_free_live_resource): Changed again, to - issue a fatal error. - - * src/sexp_parser.h: Deleted unused file. - - * src/testsuite/Makefile.am (TS_PROGS): Added string-test. - - * src/testsuite/macros.m4 (TS_CHECK): New macro. - - * src/testsuite/string-test.m4: New tests for string related - functions, currently only lsh_get_cstring. - - * src/format.c (ssh_cformat): Deleted. Replaced all uses with - ssh_format. - (make_cstring_l): Deleted. - (make_cstring): Deleted. - (lsh_get_cstring): New function. - - * src/werror.c (write_syslog): Don't use make_cstring_l. - - * src/unix_user.c (do_verify_password): Use lsh_get_cstring. - (do_read_file): Likewise. - (do_read_file): Likewise. - (format_env_pair): Likewise. - (do_exec_shell): Likewise. - (make_unix_user): Likewise. - (do_lookup_user): Likewise. - - * src/unix_interact.c (unix_read_password): Use lsh_get_cstring. - - * src/server_session.c (do_spawn_exec): Use lsh_get_cstring. - - * src/lsh.h (NUL_TERMINATED): Deleted. - - * src/format.h (format_cstring, make_string): Renamed function. - And made it a macro. Updated callers. - - * src/adns.c (do_resolve): Use lsh_get_cstring. Don't use - NUL_TERMINATED. - * src/io.c (address_info2sockaddr): Likewise. - (make_local_info): Likewise. - (io_listen_local): Likewise. - (io_connect_local): Likewise. - -2001-04-05 Niels Möller - - * src/testsuite/functions.sh (run_lsh): Quote the command better. - - * src/xalloc.c (lsh_string_alloc): Fixes, now compiles both with - and without DEBUG_ALLOC. - - * src/werror.c (werror_argp_parser): Added missing break. - (werror): Handle the case where both verbose_flag and quiet_flag - are set. - - * src/io.c (do_consuming_read): Free the string properly on EOF or - error. XXX Fix in 1.2 branch? - - * src/client_userauth.c (make_client_userauth): Convert username - to utf8 once, here. Updated callers. Previously, the converted - strings leaked. - - * src/client_session.c (do_client_session_eof): Use - close_fd_nicely. Otherwise we lose data. FIXED in 1.2 branch. - - * src/Makefile.am.in (atoms_gperf.c): Massage gperf output to - reduce the number of compilation warnings. - -2001-04-05 Niels Möller - - * src/gc.c (gc_final): Check for leaked strings, and write any - clues. - - * src/lsh.h (struct lsh_string_header): Added more debug info. - - * src/xalloc.c (all_strings): New variable, for debugging. - (sanity_check_string_list): New function. - (lsh_string_alloc_clue): New function, remembering allocated - strings. - (lsh_string_free): Unregister string. - - * src/werror.c (werror_vformat): Pass arguments to werror_write in - the correct order. - (werror_vformat): Likewise. - -2001-04-04 Niels Möller - - * src/testsuite/Makefile.am (CFLAGS): Reintroduced -O0, to make - compilation faster. - - * src/client.c, src/client_keyexchange.c, src/client_userauth.c, - src/debug.c, src/disconnect.c, src/proxy.c, - src/proxy_x11forward.c, src/server.c, src/server_keyexchange.c, - src/server_userauth.c: Packet handlers should no longer free - packets. - - * src/xalloc.c (number_of_strings): Define only if DEBUG_ALLOC. - (lsh_string_alloc): NUL-terminate strings, for simplicity. - (lsh_string_free): Check that string is still NUL-terminated. - - * src/werror.c (program_name): New variable. - (werror_argp_parser): Initialize program_name. - (werror_vformat): Prefix messages with program_name. - (werror_vformat): Simplified code in 'z' case. - - * src/proxy_userauth.c (do_forward_success): dup packet before - forwarding it. - Packet handlers should no longer free packets. - - * src/channel.c (RETURN, END): Deleted macros. - Packet handlers should no longer free packets. - - * src/keyexchange.c (do_handle_kexinit): dup packet when storing - it in the connection struct. - (do_handle_newkeys): Packet handlers should no longer free packets. - - * src/write_buffer.c (make_write_buffer): Renamed - write_buffer_alloc to make_write_buffer. Updated callers. - - * src/gc.c (gc_final): Check number_of_objects and - number_of_strings. - - * src/connection.c (connection_handle_packet): Always free the - packet here. Packet handlers no longer needs to do that. - (connection_handle_packet): Accept SSH_MSG_IGNORE and - SSH_MSG_DEBUG in the KEX_STATE_NEWKEYS state. - - * configure.in: Bumped version to 1.3. - - * lsh-1.2 released. - - * distribution-key.gpg: Updated key, more signatures and later - expiration date. - - * src/sftp/Makefile.am (sftp_test_client_SOURCES): Added werror.c - and client.c - - * src/sftp/sftp-test-client.c (struct client_ctx): Moved to - client.h - (werror_program_name): Defined here. - - * src/sftp/client.c, src/sftp/client.h, src/sftp/werror.c, - src/sftp/werror.h: New files. - -2001-04-03 Niels Möller - - * src/sftp/testsuite/put-1-test: Check that the new file exists. - Use $TESTHOME for referring to the local file. - - * src/sftp/sftp-test-client.c (do_put): Fixes and simplifications. - -2001-04-03 Niels Möller - - * src/sftp/sftp-test-client.c (do_open): New function. - (do_close): New function. - (do_get): Use do_open and do_close. - -2001-04-02 Niels Möller - - * configure.in: Bumped version to 1.2. - - * src/Makefile.am.in (EXTRA_DIST): Added lcp. - - * src/Makefile.am.in (noinst_SCRIPTS): Added the experimental lcp - script. - -2001-04-02 Niels Möller - - * src/sftp/sftp-server.c (sftp_process_read): Fixed size passed to - pread. - (debug): Added a prototype saying that it takes printf-style - arguments. - -2001-04-02 Niels Möller - - * src/sftp/sftp-server.c (sftp_process_realpath): Fixed invocation - of pathconf(). - Include stdarg.h. - - * src/sftp/testsuite: Adapted shell scripts to /bin/sh. Removed - uses of the "function" keyword, and use a full path when sourcing - common.sh. - - * src/sftp/testsuite/run-tests: Use /bin/bash, as we use - bash-specific parameter expansion. - -2001-04-01 Niels Möller - - * src/sftp/Makefile.am (sftp_server_SOURCES, - sftp_test_client_SOURCES): Added xmalloc.c. - - * src/sftp/xmalloc.c: New file. Defines xmalloc, xrealloc and - xstrdup. - - * src/sftp/sftp-test-client.c (do_put): Use xmalloc. - - * src/sftp/sftp-server.c (sftp_get_user): New function. - (sftp_get_group): Likewise. - (struct sftp_ctx): Added user_cache and group_cache. - (sftp_init): Initialize user_cache and group_cache. - (sftp_put_longname): Take a sftp_ctx * as argument. Use - sftp_get_user and sftp_get_group. - - * src/sftp/buffer.c: Use xmalloc and xrealloc. - - * src/sftp/idcache.c: Rewrite. - - * src/sftp/Makefile.am (sftp_server_SOURCES): Added idcache.c. - - * src/sftp/sftp-server.c: Use the functions from idcache.c. - - * src/sftp/idcache.c: #include idcache.h. #if:ed out prototypes - and functions that aren't needed. Use malloc instead of xmalloc. - - * src/sftp/idcache.h: New file. - - * src/sftp/testsuite/setup-env: Clean up first. - - * src/sftp/testsuite/get-1-test: New testcase. - * src/sftp/testsuite/ls-1-test: Likewise. - * src/sftp/testsuite/ls-2-test: Likewise - - * src/sftp/testsuite/common.sh (PROGRAMDIR): New variable, holding - an absolute path to the directory where the programs are. - - * src/sftp/sftp-test-client.c (sftp_client_get_id): New function. - (do_ls): Fixes and some simplification. - (do_get): Simplified. The old more featureful implementation left - #if:ed out. - - * src/sftp/sftp-server.c (debug): New function. - (sftp_get_name): New function. - (struct sftp_dir): New struct. - (sftp_lstat_in_dir): New function. - (sftp_process_readdir): Handle directories that are not our - current working directory. - (parse_options): New function, currently only handling -d. - - * src/sftp/buffer.c (sftp_check_input): Don't modify i->left here. - (sftp_get_data): ...but do it here instead. - (sftp_free_string): Reintroduced this function. - (sftp_get_string): This function now requires the user to - deallocate the string. - (sftp_get_string_auto): Simpler function, that deallocates strings - automatically. - (sftp_read_packet): Return failure (0), rather than crashing, if - there is data leftover from the previous packet. - (sftp_put_final_length): Calculate the length correctly. - (sftp_put_reset): Fixed assertion. - (sftp_put_attrib): Likewise. - - * src/sftp/Makefile.am (noinst_PROGRAMS): Added dump-hex. - - * src/sftp/sftp.h: Converted from #define:s to enums. - - * src/sftp/dump-hex.c: New program that copies data from stdin to - stdout, and writes a hex dump to stderr in the process. - - * src/sftp/debug-server: New script to dump communication between - sftp-server and sftp-test-client. - - * src/sftp/configure.in: Added to cvs. - -2001-03-31 Niels Möller - - * src/sftp/acconfig.h: Added HAVE_GCC_ATTRIBUTE. - - * src/sftp/.bootstrap: New file. - -2001-03-30 Niels Möller - - * src/sftp/sftp-test-client.c (do_ls): Print the long name. - - * src/sftp/sftp-server.c (sftp_get_name): New function. - (HANDLE_TYPE, HANDLE_DIR, HANDLE_FD): New macros. - Fixed handles. Simplified, deleting all sftp_free_string calls. - Use pread and pwrite, where available. - - * src/sftp/buffer.c (struct sftp_input): Added array of strings, - so that callers don't have to free them explicitly. - (sftp_put_reset): New funtion. - (sftp_get_uint64): Use off_t, conditionalized on its size. - (sftp_put_uint64): Likewise. - - * src/sftp/Makefile.am: Use AUTOMAKE_OPTIONS = foreign, added - sftp-test-client. - -2001-03-28 Niels Möller - - * src/lcp (split spec): New function for splitting arguments. - Checked in first working version. - -2001-03-27 Niels Möller - - * doc/srp-spec.nroff: Bumped version number, updated dates, and - added a section Further questions. - -2001-03-26 Niels Möller - - * Released lsh-1.1.9. - - * misc/Makefile.am.in (EXTRA_DIST): Added more files to the dist: - libgcc2.c-patch, bootstrap.sh and make-dist. - - * configure.in: By default, disable debug-alloc and debug-trace. - - * src/testsuite/keygen-2-test: Use a smaller key size, 777 bits, - for speed. - - * src/testsuite/keygen-1-test: Use NIST security level 2 (640 - bits), for speed. - - * src/argp/configure.in: Bumped argp version to standalone-1.1. - -2001-03-26 Niels Möller - - * src/argp/configure.in (CPPFLAGS): Added -D_GNU_SOURCE. - -2001-03-25 Niels Möller - - * src/testsuite/functions.sh (spawn_lshd): Use kill -9 to stop - lshd; otherwise lshd catching SIGTERM leads to timing problems. - - * Released lsh-1.1.9. - - * misc/libgcc2.c-patch: gcc patch. - - * src/crypto.c: Deleted obsolete file. - - * src/testsuite/Makefile.am (CFLAGS): -O0 is not needed anymore, - since most of the rijndael tests were deleted. - - * src/proxy_userauth.c (do_proxy_userauth_continuation): Don't use - FORCE_APPLY. - - * src/command.h (delayed_apply): Deleted class. - - * configure.in: Bumped version to 1.1.9. - - * src/testsuite/rijndael-test.m4: Deleted most tests, left 4 for - each key size. - - * src/werror.c (fatal): If compiling with gcov, use exit(255) - instead of abort. - - * src/spki_commands.c (parse_private_key): Use fatal instead of - abort. - - * src/sexp.c (sexp_sn): #if:ed out. - - * src/resource.c (dont_free_live_resource): Call werror, not - fatal. Currently, this is normal iff it happens during - gc_final. - - * src/proxy_userauth.c (do_handle_userauth): Don't use - make_delay_continuation. - - * src/lshg.c (main): Call gc_final. - - * src/lshd.c (main): Call gc_final. When compiling with gcov, - catch the TERM signal and call exit() sometime later. - - * src/lsh.c: Call gc_final(). - - * src/lsh-keygen.c: Use fatal(), not abort(). - - * src/io_commands.c (remember_continuation): Deleted class. - (do_remember_continuation): Deleted function. - (make_remember_continuation): Deleted function. - (do_listen): Deleted arguments resources and lookup. Updated - callers. - (do_simple_listen): Deleted function. - (make_simple_listen): Deleted function. - - * src/gc.c (gc_final): New function. - - * src/command.c (make_delayed_apply): Deleted function. - (delay_continuation): Deleted class. - (do_delay_continuation): Deleted function. - (make_delay_continuation): Deleted function. - - * src/channel.c (connection_service): Deleted class. - - * doc/lsh.texinfo (Invoking lsh): Added a note saying that - ordering is important. - - * doc/TODO (TESTING): Added info on missing tests. - - * configure.in: Define WITH_GCOV when compiling for gcov. - - * acconfig.h (WITH_GCOV): New symbol. - -2001-03-24 Niels Möller - - * src/lsh_proxy.c (main): Use listen_callback instead of - simple_listen. - -2001-03-22 Niels Möller - - * src/alist.c (alist_add): #if:ed out unused function. - -2001-03-21 Niels Möller - - * src/client_password.c: Deleted. - - * src/lshd.c (install_terminate_handler): Catch SIGTERM and - arrange for exit(0) to be called on termination. - -2001-03-20 Niels Möller - - * src/lshg.c: Include client.h (used to include client.c. Argh!). - - * src/lsh.h: Forward-declare struct interact. - - * src/lsh.c: Don't include client_pty.h. - - * src/client_session.c: Include client.h, not client_session.h. - - * src/client_pty.c: Include client.h, not client_pty.h. - - * src/client.h (make_pty_request): Moved declaration here. - - * src/client.c: Don't include client_pty.h. - - * src/client_session.h, src/client_pty.h: Deleted. - - * src/Makefile.am.in (class-map): Let the shell find the awk - program. - -2001-03-19 Niels Möller - - * src/scm/gaba.scm (class-annotate): New function. - - * src/make-class-map: Beautified output. - - * src/lsh-keygen.c (main): Don't use blocking_write. - - * src/blocking_write.h, src/blocking_write.c: Deleted. - - * src/Makefile.am.in (liblsh_a_SOURCES): Removed blocking_write.c. - -2001-03-16 Niels Möller - - * ANNOUNCE: Updated, preparing for lsh-1.2. - - * src/server_session.c (format_exit_signal): Represent a signal - as a string, not an integer. - * src/translate_signal.c: Likewise. - - * src/client.c (do_exit_signal): Don't use the signal name from - the packet, only the message. - - * src/atoms.in: Added standard signals. - - * src/resource.c (do_remember_resource): Bugfix: Use - KILL_RESOURCE, not KILL. - -2001-03-15 Niels Möller - - * doc/srp-spec.nroff: Fixed definition of m2, pointed out by Tom - Holroyd. - -2001-03-14 Niels Möller - - * src/Makefile.am.in (class-map): Added rule for generating - class-map. - - * src/make-class-map: New awk script for describing the class - hierarchy. Almost working. - -2001-03-14 Niels Möller - - * src/tcpforward.h (remote_port): Deleted c attribute. - - * src/string_buffer.c (string_buffer_length): Deleted. - - * src/spki_commands.h (make_spki_parse_key): Deleted. - - * src/spki_commands.c (spki_read_acls_command): Deleted. - - * src/sexp.h (sexp_iterator): Deleted set method. - (SEXP_SET): Deleted. - - * src/sexp.c (do_nil_get): New function. - (do_nil_assoc): New function. - (do_nil_left): New function. - (do_nil_next): New function. - (make_iter_nil): New function. - (do_format_nil): New function. - (sexp_nil): New definition, that isn't a cons. - (do_vector_set): Deleted. - (sexp_iter_cons): deleted. - (do_cons_get): Deleted. - (do_cons_set): Deleted. - (do_cons_assoc): Deleted. - (do_cons_left): Deleted. - (do_cons_next): Deleted. - (make_iter_cons): Deleted. - (do_format_sexp_tail): Deleted. - (do_format_sexp_cons): Deleted. - (sexp_c): Deleted. - - * src/server_session.h (make_server_connection_service): Deleted. - - * src/proxy_userauth.c (do_userauth_proxy): Don't use - make_once_continuation. - - * src/lsh.c (do_lsh_default_handler): Don't use EXC_SERVICE. - - * src/keyexchange.h (make_install_new_keys: Deleted. - - * src/io_commands.c (collect_connect_port): Deleted. - (connect_with_port): Deleted. - - * src/handshake.c: Adapted to change in collect_info_3. - - * src/gateway.c (gateway): Disabled unused class. - - * src/exception.c (dummy_exception): Deleted. - - * src/digits.c (simple_decode_base64): Deleted. - - * src/command.h (collect_info_4): Deleted. - - * src/combinators.c: Adapted to change in collect_info_3. - - * src/command.c (do_collect_4): Deleted. - (make_collect_state_3): Deleted. - (make_once_continuation): Deleted. - (make_catch_report_collect_body): Deleted. - (collect_state_2): Deleted attribute next. - - * src/client.c (make_client_options): Deleted, as it wasn't used. - - * src/channel_commands.h (channel_command): Deleted, it wasn't - used. - - * src/channel.h: Deleted old code (CONNECTION_START and - format_channel_open_a). - - * src/alist.h: Deleted ALIST_KEYS. - -2001-03-13 Niels Möller - - * src/dsa_keygen.h, src/packet_ignore.c, src/packet_ignore.h, - src/password.c, src/password.h, src/proxy_channel.h, - src/session.c, src/session.h:Removed obsolete files. - -2001-03-12 Niels Möller - - * configure.in: Bumped version to 1.1.8. - - * src/client_session.c (do_client_session_eof): Close stdout and - stderr, not stdin. - - * src/client.c (do_exit_status): Don't call channel_eof. This way, - the behavior is more similar to other ssh clients. - - * src/channel.c (channel_request_handler): Display more info about - unexpected packets. - (channel_close_handler): Don't display the "unexpected channel - close" message if CHANNEL_NO_WAIT_FOR_EOF is set. - Don't invoke the CHANNEL_EOF callback. - (channel_eof): Use the new CHANNEL_NO_WAIT_FOR_EOF flag. - (init_channel): Set CHANNEL_CLOSE_AT_EOF by default. - (channel_read_close_callback): Improved comment. - - * src/channel.h (CHANNEL_NO_WAIT_FOR_EOF): New flag. - - * src/tcpforward.c (do_tcpip_eof): Use the SHUT_WR constant, which - is defined in io.h if needed. - - * src/server_session.c (spawn_process): Clear - CHANNEL_CLOSE_AT_EOF. - (do_exit_shell): Set CHANNEL_CLOSE_AT_EOF and - CHANNEL_NO_WAIT_FOR_EOF. - - * src/gateway_channel.c (make_gateway_channel): Clear - CHANNEL_CLOSE_AT_EOF. - - * src/io.h (SHUTDOWN_UNIX): Moved shutdown workaround from io.c, - and added a _UNIX-suffix on the macros to indicate that they are - for AF_UNIX sockets only. - - * src/scm/gaba.scm (string-upcase): Moved definition to - guile-compat.scm. scsh already provides string-upcase, and the - definition here trigs a bug in string->list in scsh-0.5.2. - -2001-03-12 Niels Möller - - * src/io.c (io_iter): Handle POLLERR. - -2001-03-07 Niels Möller - - * doc/TODO: scsh-0.5.2 is truly free software! Removed paragraph - describing the scsh situation. - - * README: Say that scsh-0.5.2 is needed. - - * src/scm/guile-compat.scm (char-set=): New function, - for compatibility with scsh-0.5.2. - (char-set:empty): New variable, likewise. - - * src/scm/make-char-classes.scm (char-set-assoc): A real function - now, as I'm not sure that the usual assoc handles char-sets. - (char-set-empty?): Use char-set:empty (new in scsh-0.5.2). - (char-set=?): Removed function, scsh-0.5.2 provides a similar - function named char-set=. - -2001-02-28 Niels Möller - - * src/client.c (init_client_options): Initialize stderr_fork = 1. - (client_options): New option --no-cvs-workaround. - (client_argp_parser): Handle --no-cvs-workaround. - -2001-02-25 Niels Möller - - * Refer to a function foo as "foo", not "foo()", in messages and - comments. (GNU coding standard). - -2001-02-22 Niels Möller - - * src/randomness.c (do_arcfour_random): Spelling fix. - - * Released lsh-1.1.7. - -2001-02-22 Niels Möller - - * src/io.c (close_fd_read): New function. - (do_buffered_read): Call close_fd_read on EOF. This stops reading - from the file, and also marks it for closing unless it has a write - callback. - (do_consuming_read): Likewise. - -2001-02-21 Niels Möller - - * src/io.c (do_consuming_read): Added an assert do check that - want_read is true. Check fd->hanged_up first. - -2001-02-21 Niels Möller - - * src/srp_exchange.c (srp_format_proofs): First argument to - MAKE_MAC must not have side effects. - - * src/lsh-keygen.c (main): First argument to A_WRITE must not have - side effects. - - * src/gateway_channel.c (do_gateway_channel_request): First - argument to COMMAND_CALL must not have side effects. - (do_channel_open_forward): Likewise. - * src/lsh.c (do_options2identities): Likewise. - - * src/connection_commands.c (do_connection_if_srp): Don't use a - complex expression as the first argument to COMMAND_CALL. - - * src/command.h (COMMAND_CALL): Generate a compile error if the - first argument is not an lvalue. - -2001-02-20 Niels Möller - - * doc/HACKING: Added section CAVEAT. - -2001-02-20 Niels Möller - - * src/io.c, src/io.h, src/reaper.c, src/unix_interact.c: Added - volatile modifier to all uses of sig_atomic_t. - - * src/client_userauth.c (do_userauth_success): Use verbose, not - werror, for success message. - -2001-02-19 Niels Möller - - * src/testsuite/Makefile.am (TS_MORE_PROGS): Added - lshg-tcpip-local-test. - -2001-02-18 Niels Möller - - * src/testsuite/tcpip-local-test: Don't pass -r to tcpconnect. - grep the output from tcpconnect. - * src/testsuite/tcpip-remote-test: Likewise. - - * src/testsuite/lshg-tcpip-local-test: New test case. - - * src/testsuite/functions.sh (spawn_lshg): New function. - - * src/argp/argp-parse.c (argp_default_parser): Let OPT_HANG print - the process id to stderr. - - * src/resource.c (do_remember_resource): If the resource list is - dead, immediately kill any resources added to it. - - * src/lsh.c (main_argp_parser): Check if the action list is empty - at ARGP_KEY_END. - * src/lshg.c (main_argp_parser): Likewise. - - * src/io.c (do_consuming_read): Don't close the fd on EOF. - (do_buffered_read): Likewise. - (sockaddr2info): Silently return NULL for AF_UNIX addresses. - - * src/client.c (client_argp_parser): Don't check that the length - of the action list is non-zero at ARGP_KEY_END. lsh.c may add a - gatewaying action later. - - * configure.in: Bumped version to 1.1.7. - -2001-02-13 Niels Möller - - * src/sftp/sftp-test-client.c: Added more code from Pontus Sköld. - -2001-02-13 Niels Möller - - * src/channel.c (do_exc_finish_channel_handler): Check - channel_count to determine if there are channels left. The code - used to just check next_channel, which was broken. - (alloc_channel): Update channel_count. - (dealloc_channel): Likewise. - (do_exc_finish_channel_handler): The handler for - EXC_FINISH_PENDING shouldn't raise EXC_FINISH_READ. - - * src/channel.h (channel_table): New attribute channel_count. - - * src/bignum.c (bignum_random): Added a comment about biased - numbers. - -2001-02-11 Niels Möller - - * src/sftp/sftp-server.c: Updated copyright notice to mention - Markus Friedl. - - * src/sftp/filemode.c, src/sftp/filemode.h, src/sftp/idcache.c: - New files, copied from GNU Fileutils-4.0. - - * src/sftp/sftp-test-client.c: Added dummy functions do_ls, - do_get, do_put and do_stat, and call them from main. - - * src/sftp/sftp-server.c: Merged code from Pontus Sköld. - (sftp_put_longname_mode): New function. - (sftp_put_longname): New function. - (sftp_put_filename): New function. - (getuser): New dummy function. - (getgroup): New dummy function. - - * src/sftp/buffer.c: Let most output-related functions call exit() - directly on failure. - (sftp_put_reserve_length): New function, replacing sftp_put_reserve. - (sftp_put_length): New function. - (sftp_put_final_length): New function. - (sftp_put_printf): New function. - (sftp_put_strftime): New function. - (sftp_clear_attrib): Moved here from sftp-server.c. - (sftp_skip_extension): Likewise. - (sftp_get_attrib): Likewise. - (sftp_put_attrib): Likewise. - -2001-02-11 Pavel Roskin - - * acinclude.m4: Always quote first argument to AC_DEFUN - to allow redefining existing macros. - * configure.in: Quote the second argument to AC_SEARCH_LIBGMP. - -2001-02-08 Niels Möller - - * src/keyexchange.c (do_kexinit_filter): Don't crash if there are - no appropriate hostkeys. - -2001-02-08 Niels Möller - - * src/dsa.c (generic_dsa_sign): Commented out debug statement that - leaks information about the secret key. - -2001-02-07 Niels Möller - - * src/algorithms.c (filter_algorithms): Document that the - functions may return NULL, and never returns an empty list. - -2001-02-04 Niels Möller - - * Released lsh-1.1.6. - - * src/ssh-conv (SSH_CONV): Got rid of the bash:isms "if !" and - "&>". - -2001-02-04 Niels Möller - - * doc/lsh.texinfo (Action options): Edited the description of the - -g, not calling it "gateway mode", as the word "gateway" is - associated with the '-G' option. - (Invoking lshd): Documented --kerberos-passwords, - --password-helper and --login-shell. - Changed UPDATED-FOR to 1.1.6. - - * configure.in: Bumped version to 1.1.6. - - * src/testsuite/Makefile.am (TS_SH, TS_MORE_SH): Added a few more - tests. - - * src/testsuite/functions.sh: New variable HOSTKEY for configuring - which hostkey to use. - - * src/unix_user.c (unix_user_db): New attribute login_shell. - (do_lookup_user): Let self->login_shell, if non-NULL, override the - login shell in the passwd database. - (make_unix_user_db): New argument login_shell. - - * src/rsa_keygen.c (rsa_generate_key): Changed "e not invertible" - message from werror() to debug(). - - * src/lshd.c (main_options): New option --login-shell. - - * src/lsh-keygen.c (main): When generating an rsa key, display a - better message before trying again. - - * src/client_keyexchange.c (do_handle_dh_reply): If the server's - signature doesn't verify, display a warning message before - disconnecting. - - * src/rsa.c (parse_ssh_rsa_public): Call rsa_check_size, to make - sure that the ->size attribute is initialized. - - * src/testsuite/key-2.private: Created an RSA testkey. - - * src/testsuite/write-key-1-test, src/testsuite/write-key-2-test: - Renamed keygen-test and keygen-2-test. - - * src/testsuite/conv-2-test: New test for reading an openssh rsa - key. - - * src/testsuite/conv-1-test: Renamed conv-test. - -2001-01-31 Niels Möller - - * src/server_publickey.c (do_authenticate): Include algorithm atom - in "Unknown publickey algorithm"-message. - - * src/process_atoms (table): Fixed first reverse entry, { - "UNKNOWN", 7}. - - * src/lsh-authorize: Redirect output from the type command to - /dev/null. - - * src/server_password.c (do_authenticate): Don't free the username - twice. - - * src/server_authorization.c (do_key_lookup): Support ssh-rsa - keys. - - * src/lshd.c (main_argp_parser): Support RSA keys for publickey - userauth. - - * src/io.c (io_iter): Changed POLLHUP handling some more. Now - POLLHUP && !POLLIN is treated as EOF. - -2001-01-31 Niels Möller - - * src/testsuite/lsh-cat-test: Use compare_output. - - * src/testsuite/lsh-1-test: Use test_success. - * src/testsuite/lsh-2-test: Likewise. - * src/testsuite/lsh-3-test: Likewise. - * src/testsuite/lsh-4-test: Likewise. - * src/testsuite/tcpip-local-test: Likewise. - * src/testsuite/tcpip-remote-test: Likewise. - - * src/testsuite/keygen-2-test: Use functions.sh and test_success. - * src/testsuite/keygen-test: Likewise. - - * src/testsuite/functions.sh (at_exit): Fixed the at_exit - mechanism. The previous code always exited successfully. - (test_result): New variable for keeping the desired exit status. - (test_fail): New function. - (test_success): Likewise. - (compare_output): Likewise. - - * src/testsuite/Makefile.am (TS_SH): Added conv-test. - - * src/testsuite/conv-test: New test program. - - * src/unix_random.c (background_poll): Changed werror() to debug(). - (start_background_poll): Changed werror() to verbose(). - - * src/tcpforward.c (do_tcpip_eof): Removed channel close logic, - now in channel.c, channel_of_handler. - - * src/ssh-conv: Don't look for lsh-decode-key in the current - directory. Added command line options --help, --usage, - --decode-with. - - * src/server_session.c (do_eof): Removed channel close logic, now - in channel.c, channel_of_handler. - (do_exit_shell): Added a verbose() message. - - * src/lsh-decode-key.c: Include rsa.h. Added program name prefix - to the diagnostic messages. - - * src/io.c (do_buffered_read, do_consuming_read): Don't call - read() if fd->hanged_up is set. - (init_file): Initialize hanged_up. - -2001-01-30 Niels Möller - - * src/io.c (io_iter): Improved handling of POLLHUP. Set the - fd->hanged_up flag before calling FD_READ(). - - * src/io.h (lsh_fd): New attribute hanged_up. - - * src/client.c (do_exit_status): Added a verbose() message. - - * src/channel.c (channel_read_close_callback): Call channel_eof, not - channel_close. - (channel_eof_handler): Moved the channel close decision here. - -2001-01-29 Niels Möller - - * src/ssh-conv: Support ssh-rsa keys. - - * src/lsh-decode-key.c (do_decode_key): Support ssh-rsa keys. - -2001-01-24 Niels Möller - - * src/spki_commands.c (parse_private_key): Generate keypairs with - algorithms ATOM_SSH_RSA, ATOM_SPKI_SIGN_RSA and ATOM_SPKI_SIGN_DSS. - - * src/rsa.c (do_rsa_verify): Replaced ATOM_RSA_PKCS1_SHA1 with - ATOM_SSH_RSA, and replaced ATOM_SPKI with ATOM_SPKI_SIGN_RSA and - ATOM_SPKI_SIGN_DSS. - (do_rsa_sign): Likewise. - (parse_ssh_rsa_public): New function. - (make_ssh_rsa_verifier): New function. - - * src/pkcs5-test.c: Include both unistd.h and stdlib.h, do get a - declaration of getopt(). - - * src/lsh.c (do_lsh_lookup): Handle ATOM_SSH_RSA. - (do_lsh_lookup): Replace ATOM_SPKI with ATOM_SPKI_SIGN_RSA and - ATOM_SPKI_SIGN_DSS. - - * src/dsa.c (do_dsa_verify): Check that there's no trailing - garbage. - (do_dsa_verify): Replace ATOM_SPKI with ATOM_SPKI_SIGN_RSA and - ATOM_SPKI_SIGN_DSS. - (do_dsa_sign): Likewise. - - * src/atoms.in: Updated algorithm names to match - draft-ietf-secsh-transport-09.txt. - - * src/algorithms.c (algorithms_argp_parser): Replace ATOM_SPKI - with ATOM_SPKI_SIGN_RSA and ATOM_SPKI_SIGN_DSS. - (lookup_hostkey_algorithm): Likewise. - - * src/Makefile.am.in: Removed $(srcdir) prefixes from targets. - * src/testsuite/Makefile.am (%.c): Likewise. - - * configure.in (PREFIX): Replace NONE with $ac_default_prefix. - (SBINDIR): MAke a #define from sbindin. Currently broken. - - * acconfig.h: Added SBINDIR. - -2001-01-23 Niels Möller - - * src/tcpforward.c (do_tcpip_eof): Call shutdown(socket, SHUT_WR), - to signal to the local peer that there's no more data. - -2001-01-18 Niels Möller - - * src/lshd.c (KERBEROS_HELPER): Added /sbin/ between PREFIX and the - program name. Note that PREFIX seems to get a bogus value "NONE" - if the default prefix is used. - - * src/sftp: New directory. Not compiled or used by default. - -2001-01-17 Niels Möller - - * src/lsh_types.h: Improved formatting. - - * src/channel.c (alloc_channel): Use UINT32, not int, for - new_size. - -2001-01-15 Niels Möller - - * misc/bootstrap.sh: Fixed comment. - - * src/argp/argp.h: #define PRINTF_STYLE, and use it instead of - using __attribute__ directly. - - * src/lsh-keygen.c (main_argp_parser): Don't use optarg (reported - by jps). - - * Added Markus Friedl's sftp-server.c to contrib, for some random - hacking. - -2001-01-10 Niels Möller - - * src/pkcs5-test.c: Include stdlib.h instead of getopt.h. - -2001-01-10 Niels Möller - - * Released lsh-1.1.5. - - * configure.in: Bumped version to 1.1.5. - -2001-01-09 Niels Möller - - * src/rsync/send.c: Deleted old code. - - * src/rsync/send.c (rsync_send_init): Rewrote. Allocates a - slightly larger buffer. - (rsync_send_eof): New function. - (rsync_send_copy_in): Deleted th dst argument. Update sum_md5 and - size. - (rsync_send_read): New function. - (rsync_send_search): New function. - (rsync_send_flush): New function. - (rsync_send_write): New function. - (rsync_send): Rewrote and simplified. Now uses fewer states, - simpler eof handling, and calls several smaller functions. - - * src/rsync/rsync.h (RSYNC_SUM_SIZE): Rename RSYNC_SUM_LENGTH. - (rsync_result_t): New enum for return types. - (struct rsync_receive_state): Renamed attribute full_sum to - sum_md5. - (struct rsync_receive_state): Made the state attribute an enum. - Moved the constants from receive.c, and renamed them to use a - RSYNC_RECIEVE_-prefix. - (struct rsync_send_state): Changed state and buffering. - - * src/rsync/generate.c, src/rsync/receive.c, src/rsync/send.c, - src/rsync/rsync.h: Changed return types from int to enum - rsync_result_t. - - * src/rsync/checksum.c (rsync_search): Renamed argument FOUND to - DONE, and set it properly for both successful and unsuccessful - searches. - - * src/rsync/receive.c (rsync_receive_mode): Use an enum instead of - defines. - (rsync_update): Hash data on output. - (rsync_receive) STATE_LITERAL: Update avail_in and next_in after calling rsync_update. - -2001-01-07 Niels Möller - - * src/argp/argp.h: Added _argp_short_program_name and - __argp_short_program_name. - - * src/argp/argp-parse.c (parser_init): Use - argp_short_program_name. - (parser_parse_next): Removed old permutation handling code. - -2001-01-06 Niels Möller - - * src/argp/argp-namefrob.h: Added _argp_short_program_name. - -2001-01-02 Niels Möller - - * src/argp/argp-help.c (hol_entry_help): Avoid using a - non-constant struct initializer. - (UNUSED): Define as a macro expanding to __attribute__ ..., if - compiling with gcc. - - * src/argp/argp-fmtstream.h (PRINTF_STYLE): Define this macro, - to expand to __attribute__ ... if compiling with gcc. - - * src/argp/argp-fmtstream.c (__argp_fmtstream_write, - __argp_fmtstream_puts, __argp_fmtstream_putc): Duplicate the - inline definitions in argp-fmtstream.h, for compilers that don't - do inlining. - - * src/unix_random.c (random_sources): Fixed bug in initialization - of the HAS_ALTERNATIVE fields. Noted by jps. - -2000-12-28 Niels Möller - - * src/lsh.c: Don't include unistd.h. - (main_argp_parser): Fixed bogus references to optarg (reported by - jps). - - * src/argp/argp-help.c (fill_in_uparams): Use unsigned char * for - VAR and ARG. Fixed calls of isalnum, isspace and friends, reported - by Kalle Olavi Niemitalo. - (canon_doc_option): Fixed calls of isalnum, isspace and friends, - reported by Kalle Olavi Niemitalo. - (hol_entry_cmp): Fixed calls of tolower, reported by Kalle Olavi - Niemitalo. - -2000-12-23 Niels Möller - - * Released lsh-1.1.4. - -2000-12-23 Niels Möller - - * src/argp/acinclude.m4: New file. - * src/argp/acinclude.m4: Reverted the definition of AC_CHECK_VAR - to take includes as argument, and renamed it to ARGP_CHECK_VAR. - -2000-12-23 Niels Möller - - * src/Makefile.am.in (EXTRA_DIST): Removed references to the - getopt files getopt.c, getopt.h and getopt1.c. - - * configure.in: Removed getopt-related tests (previously just - commented out). - -2000-12-23 Niels Möller - - * src/getopt.c, src/getopt1.c, src/getopt.h: Removed. - -2000-12-22 Niels Möller - - * src/testsuite/Makefile.am (LDADD): Link with libargp. - ($(srcdir)/%.c): Fix $(srcdir)-handling. - - * src/Makefile.am.in (bootstrap): New target, replaces the - post-configure work previously done by misc/bootstrap.sh - - * Makefile.am.in (bootstrap): New target. - -2000-12-11 Niels Möller - - * Removed getopt.c, getopt.h and getopt1.c from the src/argp - directory. - - * src/lsh.c (do_options2identities): Pass two alists to - make_spki_read_userkeys (reported by jps). - - * src/spki_commands.c (make_spki_read_userkeys): Use separate - alists for symmetric algorithms and signature algorithms (reported - by jps). - - * src/abstract_crypto.c (crypt_string_unpad): Adjust length - properly (reported by jps). - - * src/argp/argp-parse.c (match_option, ARGP_COMPLETE): #if:ed out - completion code for long options. - -2000-12-09 Niels Möller - - * src/Makefile.am.in (LDADD, lshg_LDADD): Use @LIBARGP@ - - * misc/bootstrap.sh: Use set -e. Bootstrap in the src/argp - subdirectory. - -2000-11-30 Niels Möller - - * src/argp/argp-parse.c (match_option): Better abbreviations. - Replaced try_getopt with args_only, changed calling convention for - parser_parse_arg. - - * src/argp/configure.in: Don't check for getopt. - - * src/argp/argp.h: Don't include getopt.h. - - * src/argp/argp-parse.c (calc_sizes): Updated comment. - -2000-11-29 Niels Möller - - * src/argp/configure.in: Use AC_REPLACE_FUNCS for mempcpy, strndup - and strchrnul. - (AC_CHECK_VAR): Changed second argument to take the type of the - variable. - - * src/argp/argp-parse.c (struct parser): New fields - posixly_correct and ordering. - (parser_init): Choose ordering. - (enum arg_type): New value ARG_LONG_ONLY. - (parser_parse_next): Added error messages similar to getopt's. - - * src/argp/argp-help.c (STRNDUP): New macro to refer to strndup - or __strndup, as appropriate. - (STRERROR): Define this macro as a wrapper for strerror or - sys_errlist. - (__argp_basename): New function. - - * src/argp/argp-namefrob.h (__argp_basename): Added - __argp_basename. - - * src/argp/Makefile.am (libargp_a_LIBADD): Include LIBOBJS in - libargp.a. - - * src/argp/argp.h: Added prototype for _argp_basename and - __argp_basename. - - * src/argp/strndup.c, src/argp/strchrnul.c src/argp/mempcpy.c: - Moved replacement functions to separate files. - -2000-11-28 Niels Möller - - * src/argp/argp-parse.c: Deleted getopt-related code. - (struct parser): New field nextchar. Deleted fields try_getotp and long_opts. - (find_short_option): New function. - (match_option): New function. - (find_long_option): New function. - (struct parser_convert_state): Deleted field long_end. - (convert_options): Don't build getopt_long-style option array. - (parser_convert): Deleted FLAGS arument. - (struct parser_sizes): Deleted field long_len. - (parser_init): Set short_opts to NULL, unless ARGP_LONG_ONLY is - used. - (classify_arg): New function. - (parser_parse_next): Don't use getopt_long(). - -2000-11-27 Niels Möller - - * configure.in: Use AC_LIB_ARGP. - - * acinclude.m4 (AC_LIB_ARGP): New test. - - * src/argp/argp-help.c (argp_doc): Use the name strndup, not - __strndup. That probably breaks glibc builds. - -2000-11-27 Niels Möller - - * src/argp/argp-test.c (asprintf): Bug fix. - - * src/argp/argp.h: Dummy definition of __THROW. - - * src/argp/argp-test.c: Fixed asprintf implementation. - - * src/argp/argp-parse.c (__argp_usage, __option_is_short, - __option_is_end): Define these function, in case the user isn't - inlining them. - - * src/argp/argp-help.c: #define __mempcpy if needed. Use unsigned - arguments to the ctype macros. Handle systems where - program_invocation_name and program_invocation_short_name doesn't - exist. - * src/argp/argp-help.c (short_program_name): New function. - - * src/argp/Makefile.am: Use @LIBOBJS@ when building test program. - - * src/argp/configure.in: Check for getopt_long. Substitute - LIBOBJS. Add -I$srcdir to CPPFLAGS. - - * src/argp: Added getopt.h, getopt.c and getopt1.c, which are - needed for separate compilation of argp. - -2000-11-27 Niels Möller - - * Updated argp from glibc-2.2. - - * Released lsh-1.1.3. - - * src/client.c (client_argp_parser): Handle remote_forward - properly, and install a channel_open_forwarded_tcpip handler if - needed (recovered from an earlier lsh.c). Some other cleanup. - - * src/abstract_crypto.h: Some cleanup. - * src/abstract_io.h: Likewise. - * src/channel.c: Likewise. - * src/channel.h: Likewise. - * src/channel_commands.h: Likewise. - * src/connection.h: Likewise. - * src/connection_commands.c: Likewise. - * src/dh_exchange.c: Likewise. - * src/exception.h: Likewise. - * src/gateway.c: Likewise. - * src/gateway_channel.c: Likewise. - * src/gateway_commands.c: Likewise. - * src/handshake.c: Likewise. - * src/handshake.h: Likewise. - * src/io.h: Likewise. - * src/io_commands.c: Likewise. - * src/io_commands.h: Likewise. - * src/keyexchange.h: Likewise. - * src/lsh.c: Likewise. - * src/lsh_proxy.c: Likewise. - * src/lshg.c: Likewise. - * src/publickey_crypto.h: Likewise. - * src/randomness.c: Likewise. - * src/randomness.h: Likewise. - * src/read_packet.c: Likewise. - * src/rsa.c: Likewise. - * src/server_pty.h: Likewise. - * src/server_session.c: Likewise. - * src/sexp.h: Likewise. - * src/sexp_parser.c: Likewise. - * src/sexp_streamed_parser.c: Likewise. - * src/sexp_test.c: Likewise. - * src/spki_commands.c: Likewise. - * src/spki_commands.h: Likewise. - * src/ssh1_fallback.c: Likewise. - * src/tcpforward.c: Likewise. - * src/unix_random.c: Likewise. - * src/zlib.c: Likewise. - -2000-11-26 Niels Möller - - * src/parse.c (parse_rest, parse_rest_copy): Renamed parse_rest to - parse_rest_copy. New function parse_rest. - - * src/gateway_channel.c (do_gateway_channel_request): Use - format_channel_request_i(). - (gateway_channel_open_continuation): New attribute fallback. - (do_gateway_channel_open_continuation): Set the target channel's - request_fallback pointer. - (do_channel_open_forward): Set the origin channel's - request_fallback pointer. - - * src/channel.h (ssh_channel): Added request_fallback attribute. - (channel_request_info): New struct. - (channel_request): Use a channel_request_info argument. - - * src/channel.c (parse_channel_request): New function. - (DEFINE_PACKET_HANDLER): Use parse_channel_request. Invoke request - fallback if appropriate. - (init_channel): Initialize request_fallback = NULL. - (format_channel_open_s): Use a struct lsh_string for the type - argument. - (format_channel_request_i): New function. - - * src/spki_commands.c (spki_read_userkeys): Try to decrypt the key. - (make_spki_read_userkeys): New argument tty. If supplied, try to - decrypt password protected keys. - - * src/proxy_agentforward.c (do_proxy_open_auth_agent): Updated to - use struct channel_open_info. - * src/proxy_x11forward.c (do_proxy_open_x11): Likewise. - * src/proxy_tcpforward.c (do_proxy_open_direct_tcpip): Likewise. - * src/proxy_session.c (do_proxy_open_session): Likewise. - * src/server_session.c (do_open_session): Likewise. - * src/tcpforward.c: Likewise. - - * src/parse.c (parse_rest): New function. - - * src/lshg.c: Use new client.c option parsing. - - * src/lsh_proxy.c: Adapted to stricter alist typing. - * src/lshd.c: Likewise. - * src/reaper.c: Likewise. - * src/server_publickey.c: Likewise. - * src/spki.c: Likewise. - - * src/lsh.c: Moved some of the option parsing to client.c. - - * src/gateway_commands.c (gateway_make_connection): Install an - open_fallback. - - * src/gateway_channel.c (gateway_channel_open_command): Use a - string instead of an atom to represent the chennel type. - (do_gateway_channel_open): Use format_channel_opn_s(). - (make_gateway_channel_open_command): Take an struct - channel_open_info * as argument. - (do_channel_open_forward): New function. - (gateway_channel_open_forward): Channel open handler that forwards - any channel open request, of any type. - - * src/client_session.c (client_session_channel): Renamed the - class client_session. - - * src/client.h (CLIENT_ARGP_ACTION_GROUP): New constant. - (CLIENT_ARGP_MODIFIER_GROUP): New constant. - (client_options): New class. - - * src/client.c: Moved most of the option parsing from lsh.c to - this file. - - * src/channel.c (make_channel_table): Initialize open_fallback = - NULL; - (global_request_handler): Prepared for using a fallback handler. - (channel_request_handler): Likewise. - (channel_open_continuation): Renamed attributes to - send_window_size and send_max_packet. - (parse_channel_open): New function. - (DEFINE_PACKET_HANDLER): Use parse_channel_open. Invoke - open_fallback if there's no more specific handler for the channel - type. - (format_channel_open_s): New function. - (format_channel_open_a): New function (currently #if:ed out). - - * src/channel.h (struct channel_open_info): New struct to - represent the common information in SSH_MSH_CHANNEL_OPEN. - (channel_table): New attribute open_fallback. - (channel_open): Use a channel_open_info for the arguments. - - * src/alist.h (alist): Use struct lsh_object *, not void *, to - pass values. - - * src/alist.c (alist_select): New function. - - * src/algorithms.c (make_algorithms_options): New function. - - * doc/TODO: Some updates. - - * configure.in: Bumped version to 1.1.3. - -2000-11-20 Niels Möller - - * src/algorithms.h, src/client.h, src/client_keyexchange.c, - src/client_userauth.c, src/connection.c, src/format.h, - src/interact.c, src/interact.h, src/io.c, src/io.h, - src/lsh-writekey.c, src/lsh.c, src/lshd.c, src/reaper.c, - src/reaper.h, src/server_session.c, src/spki.c, - src/spki_commands.c, src/srp-gen.c, src/tty.c, src/tty.h: Removed - old #if:ed out code. - - * ChangeLog: Rotated ChangeLog, creating ChangeLog.2. - diff --git a/lsh/ChangeLog.1 b/lsh/ChangeLog.1 deleted file mode 100755 index d9677ee..0000000 Binary files a/lsh/ChangeLog.1 and /dev/null differ diff --git a/lsh/FAQ b/lsh/FAQ deleted file mode 100755 index df3539c..0000000 Binary files a/lsh/FAQ and /dev/null differ diff --git a/lsh/MacOS/.cvsignore b/lsh/MacOS/.cvsignore deleted file mode 100644 index 07a1f25..0000000 --- a/lsh/MacOS/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -libs -*Data -apps diff --git a/lsh/MacOS/desdata/desdata.mcp.xml b/lsh/MacOS/desdata/desdata.mcp.xml deleted file mode 100755 index dc7c744..0000000 Binary files a/lsh/MacOS/desdata/desdata.mcp.xml and /dev/null differ diff --git a/lsh/MacOS/desdata/prefix.h b/lsh/MacOS/desdata/prefix.h deleted file mode 100755 index b4754cf..0000000 --- a/lsh/MacOS/desdata/prefix.h +++ /dev/null @@ -1,320 +0,0 @@ -/* prefix.h */ - -/* Define if using alloca.c. */ -#undef C_ALLOCA - -/* Define to empty if the keyword does not work. */ -#undef const - -/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. - This function is required for alloca.c support on those systems. */ -#undef CRAY_STACKSEG_END - -/* Define if the `getpgrp' function takes no argument. */ -#undef GETPGRP_VOID - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define if you have alloca, as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define if you have and it should be used (not on Ultrix). */ -#undef HAVE_ALLOCA_H - -/* Define if you don't have vprintf but do have _doprnt. */ -#undef HAVE_DOPRNT - -/* Define if you have the vprintf function. */ -#undef HAVE_VPRINTF - -/* Define as __inline if that's what the C compiler calls it. */ -#undef inline - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown - */ -#undef STACK_DIRECTION - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - -/* Define to enable sanity checking on memory allocation and casting */ -#undef DEBUG_ALLOC - -/* Define to enable tracing */ -#undef DEBUG_TRACE - -/* Define if zlib should be used */ -#undef WITH_ZLIB - -/* Define to enable pty support */ -#undef WITH_PTY_SUPPORT - -/* Define to enable fallback to SSH1 */ -#undef WITH_SSH1_FALLBACK - -/* Location of the SSH1 daemon */ -#undef SSHD1 - -/* Define if IDEA should be used */ -#undef WITH_IDEA - -/* Define if SRP should be supported */ -#undef WITH_SRP - -/* Define to enable tcp forwarding */ -#undef WITH_TCP_FORWARD - -/* For Ipv6 support */ -#undef WITH_IPV6 - -/* Define if AI_NUMERICHOST exists */ -#undef HAVE_AI_NUMERICHOST - -/* For utmp support */ -#undef WITH_UTMP - -/* Define to indicate that shutdown seems to work properly */ -#undef SHUTDOWN_WORKS_WITH_UNIX_SOCKETS - -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE - -/* Define if the compiler understands __FUNCTION__ */ -#undef HAVE_GCC_FUNCTION - -/* Define if the compiler understands offsetof(TYPE, MEMBER) */ -#define HAVE_C_OFFSETOF 1 - -/* Define if a we have working UNIX98 pty handling */ -#undef HAVE_UNIX98_PTYS - -/* For BSD-style pty allocation */ -#undef PTY_BSD_SCHEME_FIRST_CHARS -#undef PTY_BSD_SCHEME_SECOND_CHARS - -#undef PTY_BSD_SCHEME - -/* syslog() available? */ -#undef HAVE_SYSLOG - -/* struct utmp has a ut_host member */ -#undef HAVE_UT_HOST - -/* struct utmp has a ut_name member */ -#undef HAVE_UT_NAME - -/* struct utmp has a ut_user member */ -#undef HAVE_UT_USER - -/* struct utmp has a ut_addr member */ -#undef HAVE_UT_ADDR - -/* struct utmp has a ut_addr_v6 member */ -#undef HAVE_UT_ADDR_V6 - -/* Length type used by getsockopt() */ -/* #undef socklen_t */ - -/* Define to support non-standard packets of ssh2 */ -#undef DATAFELLOWS_WORKAROUNDS - -/* Global variables needed by argp */ -#undef HAVE_PROGRAM_INVOCATION_NAME -#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME - -/* Define to enable x11 forwarding */ -#undef WITH_X11_FORWARD - -/* Define to enable authentication agent forwarding */ -#undef WITH_AGENT_FORWARD - -/* The number of bytes in a int. */ -#define SIZEOF_INT 4 - -/* The number of bytes in a long. */ -#define SIZEOF_LONG 4 - -/* The number of bytes in a short. */ -#define SIZEOF_SHORT 2 - -/* Define if you have the argp_parse function. */ -#undef HAVE_ARGP_PARSE - -/* Define if you have the cfmakeraw function. */ -#undef HAVE_CFMAKERAW - -/* Define if you have the flockfile function. */ -#undef HAVE_FLOCKFILE - -/* Define if you have the fputs_unlocked function. */ -#undef HAVE_FPUTS_UNLOCKED - -/* Define if you have the fwrite_unlocked function. */ -#undef HAVE_FWRITE_UNLOCKED - -/* Define if you have the gai_strerror function. */ -#undef HAVE_GAI_STRERROR - -/* Define if you have the getaddrinfo function. */ -#undef HAVE_GETADDRINFO - -/* Define if you have the getnameinfo function. */ -#undef HAVE_GETNAMEINFO - -/* Define if you have the getopt_long function. */ -#undef HAVE_GETOPT_LONG - -/* Define if you have the getspnam function. */ -#undef HAVE_GETSPNAM - -/* Define if you have the inet_aton function. */ -#undef HAVE_INET_ATON - -/* Define if you have the login function. */ -#undef HAVE_LOGIN - -/* Define if you have the logout function. */ -#undef HAVE_LOGOUT - -/* Define if you have the logwtmp function. */ -#undef HAVE_LOGWTMP - -/* Define if you have the mempcpy function. */ -#undef HAVE_MEMPCPY - -/* Define if you have the memxor function. */ -#undef HAVE_MEMXOR - -/* Define if you have the openpty function. */ -#undef HAVE_OPENPTY - -/* Define if you have the poll function. */ -#undef HAVE_POLL - -/* Define if you have the putc_unlocked function. */ -#undef HAVE_PUTC_UNLOCKED - -/* Define if you have the select function. */ -#undef HAVE_SELECT - -/* Define if you have the socket function. */ -#undef HAVE_SOCKET - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strndup function. */ -#undef HAVE_STRNDUP - -/* Define if you have the strsignal function. */ -#define HAVE_STRSIGNAL 1 -#define strsignal(x) (sys_signame[x]) - -/* Define if you have the strtol function. */ -#undef HAVE_STRTOL - -/* Define if you have the syslog function. */ -#undef HAVE_SYSLOG - -/* Define if you have the vsnprintf function. */ -#undef HAVE_VSNPRINTF - -/* Define if you have the header file. */ -#undef HAVE_ARGP_H - -/* Define if you have the header file. */ -#undef HAVE_CRYPT_H - -/* Define if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define if you have the header file. */ -#define HAVE_GMP_H 1 - -/* Define if you have the header file. */ -#undef HAVE_GMP2_GMP_H - -/* Define if you have the header file. */ -#undef HAVE_LIBUTIL_H - -/* Define if you have the header file. */ -#undef HAVE_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_PTY_H - -/* Define if you have the header file. */ -#undef HAVE_SHADOW_H - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STROPTS_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define if you have the header file. */ -#undef HAVE_UTMP_H - -/* Define if you have the header file. */ -#undef HAVE_UTMPX_H - -/* Define if you have the header file. */ -#undef HAVE_ZLIB_H - -/* Define if you have the crypt library (-lcrypt). */ -#undef HAVE_LIBCRYPT - -/* Define if you have the nsl library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define if you have the socket library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define if you have the util library (-lutil). */ -#undef HAVE_LIBUTIL - -/* Define if you have the xnet library (-lxnet). */ -#undef HAVE_LIBXNET - -/* Define if you have the z library (-lz). */ -#undef HAVE_LIBZ - -/* Name of package */ -#define PACKAGE "lsh" - -/* Version number of package */ -#define VERSION "1.0" - -/* MacOS Library */ - -#define MACOS 1 - -#define LSH 1 - diff --git a/lsh/MacOS/digit_table/digit_table.mcp.xml b/lsh/MacOS/digit_table/digit_table.mcp.xml deleted file mode 100755 index 8c2b0ba..0000000 Binary files a/lsh/MacOS/digit_table/digit_table.mcp.xml and /dev/null differ diff --git a/lsh/MacOS/digit_table/prefix.h b/lsh/MacOS/digit_table/prefix.h deleted file mode 100755 index b4754cf..0000000 --- a/lsh/MacOS/digit_table/prefix.h +++ /dev/null @@ -1,320 +0,0 @@ -/* prefix.h */ - -/* Define if using alloca.c. */ -#undef C_ALLOCA - -/* Define to empty if the keyword does not work. */ -#undef const - -/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. - This function is required for alloca.c support on those systems. */ -#undef CRAY_STACKSEG_END - -/* Define if the `getpgrp' function takes no argument. */ -#undef GETPGRP_VOID - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define if you have alloca, as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define if you have and it should be used (not on Ultrix). */ -#undef HAVE_ALLOCA_H - -/* Define if you don't have vprintf but do have _doprnt. */ -#undef HAVE_DOPRNT - -/* Define if you have the vprintf function. */ -#undef HAVE_VPRINTF - -/* Define as __inline if that's what the C compiler calls it. */ -#undef inline - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown - */ -#undef STACK_DIRECTION - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - -/* Define to enable sanity checking on memory allocation and casting */ -#undef DEBUG_ALLOC - -/* Define to enable tracing */ -#undef DEBUG_TRACE - -/* Define if zlib should be used */ -#undef WITH_ZLIB - -/* Define to enable pty support */ -#undef WITH_PTY_SUPPORT - -/* Define to enable fallback to SSH1 */ -#undef WITH_SSH1_FALLBACK - -/* Location of the SSH1 daemon */ -#undef SSHD1 - -/* Define if IDEA should be used */ -#undef WITH_IDEA - -/* Define if SRP should be supported */ -#undef WITH_SRP - -/* Define to enable tcp forwarding */ -#undef WITH_TCP_FORWARD - -/* For Ipv6 support */ -#undef WITH_IPV6 - -/* Define if AI_NUMERICHOST exists */ -#undef HAVE_AI_NUMERICHOST - -/* For utmp support */ -#undef WITH_UTMP - -/* Define to indicate that shutdown seems to work properly */ -#undef SHUTDOWN_WORKS_WITH_UNIX_SOCKETS - -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE - -/* Define if the compiler understands __FUNCTION__ */ -#undef HAVE_GCC_FUNCTION - -/* Define if the compiler understands offsetof(TYPE, MEMBER) */ -#define HAVE_C_OFFSETOF 1 - -/* Define if a we have working UNIX98 pty handling */ -#undef HAVE_UNIX98_PTYS - -/* For BSD-style pty allocation */ -#undef PTY_BSD_SCHEME_FIRST_CHARS -#undef PTY_BSD_SCHEME_SECOND_CHARS - -#undef PTY_BSD_SCHEME - -/* syslog() available? */ -#undef HAVE_SYSLOG - -/* struct utmp has a ut_host member */ -#undef HAVE_UT_HOST - -/* struct utmp has a ut_name member */ -#undef HAVE_UT_NAME - -/* struct utmp has a ut_user member */ -#undef HAVE_UT_USER - -/* struct utmp has a ut_addr member */ -#undef HAVE_UT_ADDR - -/* struct utmp has a ut_addr_v6 member */ -#undef HAVE_UT_ADDR_V6 - -/* Length type used by getsockopt() */ -/* #undef socklen_t */ - -/* Define to support non-standard packets of ssh2 */ -#undef DATAFELLOWS_WORKAROUNDS - -/* Global variables needed by argp */ -#undef HAVE_PROGRAM_INVOCATION_NAME -#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME - -/* Define to enable x11 forwarding */ -#undef WITH_X11_FORWARD - -/* Define to enable authentication agent forwarding */ -#undef WITH_AGENT_FORWARD - -/* The number of bytes in a int. */ -#define SIZEOF_INT 4 - -/* The number of bytes in a long. */ -#define SIZEOF_LONG 4 - -/* The number of bytes in a short. */ -#define SIZEOF_SHORT 2 - -/* Define if you have the argp_parse function. */ -#undef HAVE_ARGP_PARSE - -/* Define if you have the cfmakeraw function. */ -#undef HAVE_CFMAKERAW - -/* Define if you have the flockfile function. */ -#undef HAVE_FLOCKFILE - -/* Define if you have the fputs_unlocked function. */ -#undef HAVE_FPUTS_UNLOCKED - -/* Define if you have the fwrite_unlocked function. */ -#undef HAVE_FWRITE_UNLOCKED - -/* Define if you have the gai_strerror function. */ -#undef HAVE_GAI_STRERROR - -/* Define if you have the getaddrinfo function. */ -#undef HAVE_GETADDRINFO - -/* Define if you have the getnameinfo function. */ -#undef HAVE_GETNAMEINFO - -/* Define if you have the getopt_long function. */ -#undef HAVE_GETOPT_LONG - -/* Define if you have the getspnam function. */ -#undef HAVE_GETSPNAM - -/* Define if you have the inet_aton function. */ -#undef HAVE_INET_ATON - -/* Define if you have the login function. */ -#undef HAVE_LOGIN - -/* Define if you have the logout function. */ -#undef HAVE_LOGOUT - -/* Define if you have the logwtmp function. */ -#undef HAVE_LOGWTMP - -/* Define if you have the mempcpy function. */ -#undef HAVE_MEMPCPY - -/* Define if you have the memxor function. */ -#undef HAVE_MEMXOR - -/* Define if you have the openpty function. */ -#undef HAVE_OPENPTY - -/* Define if you have the poll function. */ -#undef HAVE_POLL - -/* Define if you have the putc_unlocked function. */ -#undef HAVE_PUTC_UNLOCKED - -/* Define if you have the select function. */ -#undef HAVE_SELECT - -/* Define if you have the socket function. */ -#undef HAVE_SOCKET - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strndup function. */ -#undef HAVE_STRNDUP - -/* Define if you have the strsignal function. */ -#define HAVE_STRSIGNAL 1 -#define strsignal(x) (sys_signame[x]) - -/* Define if you have the strtol function. */ -#undef HAVE_STRTOL - -/* Define if you have the syslog function. */ -#undef HAVE_SYSLOG - -/* Define if you have the vsnprintf function. */ -#undef HAVE_VSNPRINTF - -/* Define if you have the header file. */ -#undef HAVE_ARGP_H - -/* Define if you have the header file. */ -#undef HAVE_CRYPT_H - -/* Define if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define if you have the header file. */ -#define HAVE_GMP_H 1 - -/* Define if you have the header file. */ -#undef HAVE_GMP2_GMP_H - -/* Define if you have the header file. */ -#undef HAVE_LIBUTIL_H - -/* Define if you have the header file. */ -#undef HAVE_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_PTY_H - -/* Define if you have the header file. */ -#undef HAVE_SHADOW_H - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STROPTS_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define if you have the header file. */ -#undef HAVE_UTMP_H - -/* Define if you have the header file. */ -#undef HAVE_UTMPX_H - -/* Define if you have the header file. */ -#undef HAVE_ZLIB_H - -/* Define if you have the crypt library (-lcrypt). */ -#undef HAVE_LIBCRYPT - -/* Define if you have the nsl library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define if you have the socket library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define if you have the util library (-lutil). */ -#undef HAVE_LIBUTIL - -/* Define if you have the xnet library (-lxnet). */ -#undef HAVE_LIBXNET - -/* Define if you have the z library (-lz). */ -#undef HAVE_LIBZ - -/* Name of package */ -#define PACKAGE "lsh" - -/* Version number of package */ -#define VERSION "1.0" - -/* MacOS Library */ - -#define MACOS 1 - -#define LSH 1 - diff --git a/lsh/MacOS/generate_q/generate_q.mcp.xml b/lsh/MacOS/generate_q/generate_q.mcp.xml deleted file mode 100755 index c0f2560..0000000 Binary files a/lsh/MacOS/generate_q/generate_q.mcp.xml and /dev/null differ diff --git a/lsh/MacOS/generate_q/prefix.h b/lsh/MacOS/generate_q/prefix.h deleted file mode 100755 index b4754cf..0000000 --- a/lsh/MacOS/generate_q/prefix.h +++ /dev/null @@ -1,320 +0,0 @@ -/* prefix.h */ - -/* Define if using alloca.c. */ -#undef C_ALLOCA - -/* Define to empty if the keyword does not work. */ -#undef const - -/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. - This function is required for alloca.c support on those systems. */ -#undef CRAY_STACKSEG_END - -/* Define if the `getpgrp' function takes no argument. */ -#undef GETPGRP_VOID - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define if you have alloca, as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define if you have and it should be used (not on Ultrix). */ -#undef HAVE_ALLOCA_H - -/* Define if you don't have vprintf but do have _doprnt. */ -#undef HAVE_DOPRNT - -/* Define if you have the vprintf function. */ -#undef HAVE_VPRINTF - -/* Define as __inline if that's what the C compiler calls it. */ -#undef inline - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown - */ -#undef STACK_DIRECTION - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - -/* Define to enable sanity checking on memory allocation and casting */ -#undef DEBUG_ALLOC - -/* Define to enable tracing */ -#undef DEBUG_TRACE - -/* Define if zlib should be used */ -#undef WITH_ZLIB - -/* Define to enable pty support */ -#undef WITH_PTY_SUPPORT - -/* Define to enable fallback to SSH1 */ -#undef WITH_SSH1_FALLBACK - -/* Location of the SSH1 daemon */ -#undef SSHD1 - -/* Define if IDEA should be used */ -#undef WITH_IDEA - -/* Define if SRP should be supported */ -#undef WITH_SRP - -/* Define to enable tcp forwarding */ -#undef WITH_TCP_FORWARD - -/* For Ipv6 support */ -#undef WITH_IPV6 - -/* Define if AI_NUMERICHOST exists */ -#undef HAVE_AI_NUMERICHOST - -/* For utmp support */ -#undef WITH_UTMP - -/* Define to indicate that shutdown seems to work properly */ -#undef SHUTDOWN_WORKS_WITH_UNIX_SOCKETS - -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE - -/* Define if the compiler understands __FUNCTION__ */ -#undef HAVE_GCC_FUNCTION - -/* Define if the compiler understands offsetof(TYPE, MEMBER) */ -#define HAVE_C_OFFSETOF 1 - -/* Define if a we have working UNIX98 pty handling */ -#undef HAVE_UNIX98_PTYS - -/* For BSD-style pty allocation */ -#undef PTY_BSD_SCHEME_FIRST_CHARS -#undef PTY_BSD_SCHEME_SECOND_CHARS - -#undef PTY_BSD_SCHEME - -/* syslog() available? */ -#undef HAVE_SYSLOG - -/* struct utmp has a ut_host member */ -#undef HAVE_UT_HOST - -/* struct utmp has a ut_name member */ -#undef HAVE_UT_NAME - -/* struct utmp has a ut_user member */ -#undef HAVE_UT_USER - -/* struct utmp has a ut_addr member */ -#undef HAVE_UT_ADDR - -/* struct utmp has a ut_addr_v6 member */ -#undef HAVE_UT_ADDR_V6 - -/* Length type used by getsockopt() */ -/* #undef socklen_t */ - -/* Define to support non-standard packets of ssh2 */ -#undef DATAFELLOWS_WORKAROUNDS - -/* Global variables needed by argp */ -#undef HAVE_PROGRAM_INVOCATION_NAME -#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME - -/* Define to enable x11 forwarding */ -#undef WITH_X11_FORWARD - -/* Define to enable authentication agent forwarding */ -#undef WITH_AGENT_FORWARD - -/* The number of bytes in a int. */ -#define SIZEOF_INT 4 - -/* The number of bytes in a long. */ -#define SIZEOF_LONG 4 - -/* The number of bytes in a short. */ -#define SIZEOF_SHORT 2 - -/* Define if you have the argp_parse function. */ -#undef HAVE_ARGP_PARSE - -/* Define if you have the cfmakeraw function. */ -#undef HAVE_CFMAKERAW - -/* Define if you have the flockfile function. */ -#undef HAVE_FLOCKFILE - -/* Define if you have the fputs_unlocked function. */ -#undef HAVE_FPUTS_UNLOCKED - -/* Define if you have the fwrite_unlocked function. */ -#undef HAVE_FWRITE_UNLOCKED - -/* Define if you have the gai_strerror function. */ -#undef HAVE_GAI_STRERROR - -/* Define if you have the getaddrinfo function. */ -#undef HAVE_GETADDRINFO - -/* Define if you have the getnameinfo function. */ -#undef HAVE_GETNAMEINFO - -/* Define if you have the getopt_long function. */ -#undef HAVE_GETOPT_LONG - -/* Define if you have the getspnam function. */ -#undef HAVE_GETSPNAM - -/* Define if you have the inet_aton function. */ -#undef HAVE_INET_ATON - -/* Define if you have the login function. */ -#undef HAVE_LOGIN - -/* Define if you have the logout function. */ -#undef HAVE_LOGOUT - -/* Define if you have the logwtmp function. */ -#undef HAVE_LOGWTMP - -/* Define if you have the mempcpy function. */ -#undef HAVE_MEMPCPY - -/* Define if you have the memxor function. */ -#undef HAVE_MEMXOR - -/* Define if you have the openpty function. */ -#undef HAVE_OPENPTY - -/* Define if you have the poll function. */ -#undef HAVE_POLL - -/* Define if you have the putc_unlocked function. */ -#undef HAVE_PUTC_UNLOCKED - -/* Define if you have the select function. */ -#undef HAVE_SELECT - -/* Define if you have the socket function. */ -#undef HAVE_SOCKET - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strndup function. */ -#undef HAVE_STRNDUP - -/* Define if you have the strsignal function. */ -#define HAVE_STRSIGNAL 1 -#define strsignal(x) (sys_signame[x]) - -/* Define if you have the strtol function. */ -#undef HAVE_STRTOL - -/* Define if you have the syslog function. */ -#undef HAVE_SYSLOG - -/* Define if you have the vsnprintf function. */ -#undef HAVE_VSNPRINTF - -/* Define if you have the header file. */ -#undef HAVE_ARGP_H - -/* Define if you have the header file. */ -#undef HAVE_CRYPT_H - -/* Define if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define if you have the header file. */ -#define HAVE_GMP_H 1 - -/* Define if you have the header file. */ -#undef HAVE_GMP2_GMP_H - -/* Define if you have the header file. */ -#undef HAVE_LIBUTIL_H - -/* Define if you have the header file. */ -#undef HAVE_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_PTY_H - -/* Define if you have the header file. */ -#undef HAVE_SHADOW_H - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STROPTS_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define if you have the header file. */ -#undef HAVE_UTMP_H - -/* Define if you have the header file. */ -#undef HAVE_UTMPX_H - -/* Define if you have the header file. */ -#undef HAVE_ZLIB_H - -/* Define if you have the crypt library (-lcrypt). */ -#undef HAVE_LIBCRYPT - -/* Define if you have the nsl library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define if you have the socket library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define if you have the util library (-lutil). */ -#undef HAVE_LIBUTIL - -/* Define if you have the xnet library (-lxnet). */ -#undef HAVE_LIBXNET - -/* Define if you have the z library (-lz). */ -#undef HAVE_LIBZ - -/* Name of package */ -#define PACKAGE "lsh" - -/* Version number of package */ -#define VERSION "1.0" - -/* MacOS Library */ - -#define MACOS 1 - -#define LSH 1 - diff --git a/lsh/MacOS/include/grp.h b/lsh/MacOS/include/grp.h deleted file mode 100755 index 7a28961..0000000 --- a/lsh/MacOS/include/grp.h +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright (C) 1991, 92, 95, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* - * POSIX Standard: 9.2.1 Group Database Access - */ - -#ifndef _GRP_H -#define _GRP_H 1 - -/*#include */ - -__BEGIN_DECLS - -#ifndef _BITS_TYPES_H -/*#include */ -#ifndef __uid_t__gid_t -#define __uid_t__gid_t -typedef unsigned long __uid_t; -typedef unsigned long __gid_t; -#endif -#endif - -#define __need_size_t -#include - - -/* For the Single Unix specification we must define this type here. */ -#if defined __USE_XOPEN && !defined gid_t -typedef __gid_t gid_t; -# define gid_t gid_t -#endif - -/* The group structure. */ -struct group - { - char *gr_name; /* Group name. */ - char *gr_passwd; /* Password. */ - __gid_t gr_gid; /* Group ID. */ - char **gr_mem; /* Member list. */ - }; - - -#if defined __USE_SVID || defined __USE_GNU -# define __need_FILE -# include -#endif - - -#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED -/* Rewind the group-file stream. */ -extern void setgrent __P ((void)); - -/* Close the group-file stream. */ -extern void endgrent __P ((void)); - -/* Read an entry from the group-file stream, opening it if necessary. */ -extern struct group *getgrent __P ((void)); -#endif - -#ifdef __USE_SVID -/* Read a group entry from STREAM. */ -extern struct group *fgetgrent __P ((FILE *__stream)); -#endif - -#ifdef __USE_GNU -/* Write the given entry onto the given stream. */ -extern int putgrent __P ((__const struct group *__restrict __p, - FILE *__restrict __f)); -#endif - -/* Search for an entry with a matching group ID. */ -extern struct group *getgrgid __P ((__gid_t __gid)); - -/* Search for an entry with a matching group name. */ -extern struct group *getgrnam __P ((__const char *__name)); - -#if defined __USE_POSIX || defined __USE_MISC - -# ifdef __USE_MISC -/* Reasonable value for the buffer sized used in the reentrant - functions below. But better use `sysconf'. */ -# define NSS_BUFLEN_GROUP 1024 -# endif - -/* Reentrant versions of some of the functions above. - - PLEASE NOTE: the `getgrent_r' function is not (yet) standardized. - The interface may change in later versions of this library. But - the interface is designed following the principals used for the - other reentrant functions so the chances are good this is what the - POSIX people would choose. */ - -# if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED -extern int getgrent_r __P ((struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result)); -# endif - -/* Search for an entry with a matching group ID. */ -extern int getgrgid_r __P ((__gid_t __gid, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result)); - -/* Search for an entry with a matching group name. */ -extern int getgrnam_r __P ((__const char *__restrict __name, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result)); - -# ifdef __USE_SVID -/* Read a group entry from STREAM. This function is not standardized - an probably never will. */ -extern int fgetgrent_r __P ((FILE *__restrict __stream, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result)); -# endif - -#endif /* POSIX or reentrant */ - - -#ifdef __USE_BSD - -# define __need_size_t -# include - -/* Set the group set for the current user to GROUPS (N of them). */ -extern int setgroups __P ((size_t __n, __const __gid_t *__groups)); - -/* Initialize the group set for the current user - by reading the group database and using all groups - of which USER is a member. Also include GROUP. */ -extern int initgroups __P ((__const char *__user, __gid_t __group)); - -#endif /* Use BSD. */ - -__END_DECLS - -#endif /* grp.h */ diff --git a/lsh/MacOS/include/netinet/in_systm.h b/lsh/MacOS/include/netinet/in_systm.h deleted file mode 100755 index 443dd90..0000000 --- a/lsh/MacOS/include/netinet/in_systm.h +++ /dev/null @@ -1,41 +0,0 @@ -/* System specific type definitions for networking code. - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _NETINET_IN_SYSTM_H -#define _NETINET_IN_SYSTM_H 1 - -#include -#include - -__BEGIN_DECLS - -/* - * Network order versions of various data types. Unfortunately, BSD - * assumes specific sizes for shorts (16 bit) and longs (32 bit) which - * don't hold in general. As a consequence, the network order versions - * may not reflect the actual size of the native data types. - */ - -typedef uint16_t n_short; /* short as received from the net */ -typedef uint32_t n_long; /* long as received from the net */ -typedef uint32_t n_time; /* ms since 00:00 GMT, byte rev */ - -__END_DECLS - -#endif /* netinet/in_systm.h */ diff --git a/lsh/MacOS/include/netinet/ip.h b/lsh/MacOS/include/netinet/ip.h deleted file mode 100755 index a083c34..0000000 --- a/lsh/MacOS/include/netinet/ip.h +++ /dev/null @@ -1,30 +0,0 @@ -/* System specific type definitions for networking code. - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _NETINET_IP_H -#define _NETINET_IP_H 1 - -#include -#include - -__BEGIN_DECLS - -__END_DECLS - -#endif /* netinet/ip.h */ diff --git a/lsh/MacOS/include/pwd.h b/lsh/MacOS/include/pwd.h deleted file mode 100755 index 4818679..0000000 --- a/lsh/MacOS/include/pwd.h +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright (C) 1991, 92, 95, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* - * POSIX Standard: 9.2.2 User Database Access - */ - -#ifndef _PWD_H -#define _PWD_H 1 - -/*#include */ - -#ifndef __const -#define __const const -#endif - -__BEGIN_DECLS - -#ifndef _BITS_TYPES_H -/*#include */ -#ifndef __uid_t__gid_t -#define __uid_t__gid_t -typedef unsigned long __uid_t; -typedef unsigned long __gid_t; -#endif -#endif - -#define __need_size_t -#include - -#ifdef __USE_XOPEN -/* The Single Unix specification says that some more types are - available here. */ -# ifndef gid_t -typedef __gid_t gid_t; -# define gid_t gid_t -# endif - -# ifndef uid_t -typedef __uid_t uid_t; -# define uid_t uid_t -# endif -#endif - -/* The passwd structure. */ -struct passwd -{ - char *pw_name; /* Username. */ - char *pw_passwd; /* Password. */ - __uid_t pw_uid; /* User ID. */ - __gid_t pw_gid; /* Group ID. */ - char *pw_gecos; /* Real name. */ - char *pw_dir; /* Home directory. */ - char *pw_shell; /* Shell program. */ -}; - - -#if defined __USE_SVID || defined __USE_GNU -# define __need_FILE -# include -#endif - - -#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN_EXTENDED -/* Rewind the password-file stream. */ -extern void setpwent __P ((void)); - -/* Close the password-file stream. */ -extern void endpwent __P ((void)); - -/* Read an entry from the password-file stream, opening it if necessary. */ -extern struct passwd *getpwent __P ((void)); -#endif - -#ifdef __USE_SVID -/* Read an entry from STREAM. */ -extern struct passwd *fgetpwent __P ((FILE *__stream)); - -/* Write the given entry onto the given stream. */ -extern int putpwent __P ((__const struct passwd *__restrict __p, - FILE *__restrict __f)); -#endif - -/* Search for an entry with a matching user ID. */ -extern struct passwd *getpwuid __P ((__uid_t __uid)); - -/* Search for an entry with a matching username. */ -extern struct passwd *getpwnam __P ((__const char *__name)); - -#if defined __USE_POSIX || defined __USE_MISC - -# ifdef __USE_MISC -/* Reasonable value for the buffer sized used in the reentrant - functions below. But better use `sysconf'. */ -# define NSS_BUFLEN_PASSWD 1024 -# endif - -/* Reentrant versions of some of the functions above. - - PLEASE NOTE: the `getpwent_r' function is not (yet) standardized. - The interface may change in later versions of this library. But - the interface is designed following the principals used for the - other reentrant functions so the chances are good this is what the - POSIX people would choose. */ - -# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN_EXTENDED -extern int getpwent_r __P ((struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result)); -# endif - -extern int getpwuid_r __P ((__uid_t __uid, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result)); - -extern int getpwnam_r __P ((__const char *__restrict __name, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result)); - - -# ifdef __USE_SVID -/* Read an entry from STREAM. This function is not standardized and - probably never will. */ -extern int fgetpwent_r __P ((FILE *__restrict __stream, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result)); -# endif - -#endif /* POSIX or reentrant */ - -#ifdef __USE_GNU -/* Re-construct the password-file line for the given uid - in the given buffer. This knows the format that the caller - will expect, but this need not be the format of the password file. */ -extern int getpw __P ((__uid_t __uid, char *__buffer)); -#endif - -__END_DECLS - -#endif /* pwd.h */ diff --git a/lsh/MacOS/include/sys/param.h b/lsh/MacOS/include/sys/param.h deleted file mode 100755 index bbc33bc..0000000 --- a/lsh/MacOS/include/sys/param.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _SYS_PARAM_H - -#define _SYS_PARAM_H 1 - -/* -#include -#include -#include -*/ - -/* BSD names for some values. */ - -/* -#define NBBY CHAR_BIT -#ifndef NGROUPS -# define NGROUPS NGROUPS_MAX -#endif -#define MAXSYMLINKS 5 -#define CANBSIZ MAX_CANON -#define NCARGS ARG_MAX -*/ -#define MAXPATHLEN 255 -/* -#define NOFILE OPEN_MAX -*/ - -#include - -/* Bit map related macros. */ -#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) -#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) -#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) -#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) - -/* Macros for counting and rounding. */ -#ifndef howmany -# define howmany(x, y) (((x)+((y)-1))/(y)) -#endif -#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) -#define powerof2(x) ((((x)-1)&(x))==0) - -/* Macros for min/max. */ -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) - - -/* Unit of `st_blocks'. */ -#define DEV_BSIZE 512 - - -#endif /* sys/param.h */ diff --git a/lsh/MacOS/include/sys/syslog.h b/lsh/MacOS/include/sys/syslog.h deleted file mode 100755 index 42e3332..0000000 --- a/lsh/MacOS/include/sys/syslog.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)syslog.h 8.1 (Berkeley) 6/2/93 - */ - -#ifndef _SYS_SYSLOG_H -#define _SYS_SYSLOG_H 1 - -#include -/* -#include -#define __need___va_list -#include -*/ - -#ifndef __const -#define __const const -#endif - -#define _PATH_LOG "/dev/log" - -/* - * priorities/facilities are encoded into a single 32-bit quantity, where the - * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility - * (0-big number). Both the priorities and the facilities map roughly - * one-to-one to strings in the syslogd(8) source code. This mapping is - * included in this file. - * - * priorities (these are ordered) - */ -#define LOG_EMERG 0 /* system is unusable */ -#define LOG_ALERT 1 /* action must be taken immediately */ -#define LOG_CRIT 2 /* critical conditions */ -#define LOG_ERR 3 /* error conditions */ -#define LOG_WARNING 4 /* warning conditions */ -#define LOG_NOTICE 5 /* normal but significant condition */ -#define LOG_INFO 6 /* informational */ -#define LOG_DEBUG 7 /* debug-level messages */ - -#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ - /* extract priority */ -#define LOG_PRI(p) ((p) & LOG_PRIMASK) -#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) - -#ifdef SYSLOG_NAMES -#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ - /* mark "facility" */ -#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) -typedef struct _code { - char *c_name; - int c_val; -} CODE; - -CODE prioritynames[] = - { - { "alert", LOG_ALERT }, - { "crit", LOG_CRIT }, - { "debug", LOG_DEBUG }, - { "emerg", LOG_EMERG }, - { "err", LOG_ERR }, - { "error", LOG_ERR }, /* DEPRECATED */ - { "info", LOG_INFO }, - { "none", INTERNAL_NOPRI }, /* INTERNAL */ - { "notice", LOG_NOTICE }, - { "panic", LOG_EMERG }, /* DEPRECATED */ - { "warn", LOG_WARNING }, /* DEPRECATED */ - { "warning", LOG_WARNING }, - { NULL, -1 } - }; -#endif - -/* facility codes */ -#define LOG_KERN (0<<3) /* kernel messages */ -#define LOG_USER (1<<3) /* random user-level messages */ -#define LOG_MAIL (2<<3) /* mail system */ -#define LOG_DAEMON (3<<3) /* system daemons */ -#define LOG_AUTH (4<<3) /* security/authorization messages */ -#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ -#define LOG_LPR (6<<3) /* line printer subsystem */ -#define LOG_NEWS (7<<3) /* network news subsystem */ -#define LOG_UUCP (8<<3) /* UUCP subsystem */ -#define LOG_CRON (9<<3) /* clock daemon */ -#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ -#define LOG_FTP (11<<3) /* ftp daemon */ - - /* other codes through 15 reserved for system use */ -#define LOG_LOCAL0 (16<<3) /* reserved for local use */ -#define LOG_LOCAL1 (17<<3) /* reserved for local use */ -#define LOG_LOCAL2 (18<<3) /* reserved for local use */ -#define LOG_LOCAL3 (19<<3) /* reserved for local use */ -#define LOG_LOCAL4 (20<<3) /* reserved for local use */ -#define LOG_LOCAL5 (21<<3) /* reserved for local use */ -#define LOG_LOCAL6 (22<<3) /* reserved for local use */ -#define LOG_LOCAL7 (23<<3) /* reserved for local use */ - -#define LOG_NFACILITIES 24 /* current number of facilities */ -#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ - /* facility of pri */ -#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) - -#ifdef SYSLOG_NAMES -CODE facilitynames[] = - { - { "auth", LOG_AUTH }, - { "authpriv", LOG_AUTHPRIV }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "mark", INTERNAL_MARK }, /* INTERNAL */ - { "news", LOG_NEWS }, - { "security", LOG_AUTH }, /* DEPRECATED */ - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, - { NULL, -1 } - }; -#endif - -/* - * arguments to setlogmask. - */ -#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ -#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ - -/* - * Option flags for openlog. - * - * LOG_ODELAY no longer does anything. - * LOG_NDELAY is the inverse of what it used to be. - */ -#define LOG_PID 0x01 /* log the pid with each message */ -#define LOG_CONS 0x02 /* log on the console if errors in sending */ -#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ -#define LOG_NDELAY 0x08 /* don't delay open */ -#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ -#define LOG_PERROR 0x20 /* log to stderr as well */ - -__BEGIN_DECLS - -/* Close desriptor used to write to system logger. */ -extern void closelog __P ((void)); - -/* Open connection to system logger. */ -extern void openlog __P ((__const char *__ident, int _option, - int __facility)); - -/* Set the log mask level. */ -extern int setlogmask __P ((int __mask)); - -/* Generate a log message using FMT string and option arguments. */ -extern void syslog __P ((int __pri, __const char *__fmt, ...)); - -#ifdef __USE_BSD -/* Generate a log message using FMT and using arguments pointed to by AP. */ -extern void vsyslog __P ((int __pri, __const char *__fmt, - __gnuc_va_list __ap)); -#endif - -__END_DECLS - -#endif /* sys/syslog.h */ diff --git a/lsh/MacOS/include/sysexits.h b/lsh/MacOS/include/sysexits.h deleted file mode 100755 index 0fbf157..0000000 --- a/lsh/MacOS/include/sysexits.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __SYSEXITS__ -#define __SYSEXITS__ - -#define EX_USAGE 64 /* command line usage error */ - -#endif diff --git a/lsh/MacOS/include/syslog.h b/lsh/MacOS/include/syslog.h deleted file mode 100755 index eff2c7e..0000000 --- a/lsh/MacOS/include/syslog.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _SYSLOG_H -#define _SYSLOG_H -#include -#endif diff --git a/lsh/MacOS/include/termios.h b/lsh/MacOS/include/termios.h deleted file mode 100755 index d75b45f..0000000 --- a/lsh/MacOS/include/termios.h +++ /dev/null @@ -1,320 +0,0 @@ -#ifndef __TERMIOS__ -#define __TERMIOS__ - -#ifndef __const -#define __const const -#endif - -typedef unsigned char cc_t; -typedef unsigned int speed_t; -typedef unsigned int tcflag_t; - -/* Return the output baud rate stored in *TERMIOS_P. */ -extern speed_t cfgetospeed __P ((__const struct termios *__termios_p)); - -/* Return the input baud rate stored in *TERMIOS_P. */ -extern speed_t cfgetispeed __P ((__const struct termios *__termios_p)); - -/* Set the output baud rate stored in *TERMIOS_P to SPEED. */ -extern int cfsetospeed __P ((struct termios *__termios_p, speed_t __speed)); - -/* Set the input baud rate stored in *TERMIOS_P to SPEED. */ -extern int cfsetispeed __P ((struct termios *__termios_p, speed_t __speed)); - -/* Put the state of FD into *TERMIOS_P. */ -extern int tcgetattr __P ((int __fd, struct termios *__termios_p)); - -/* Set the state of FD to *TERMIOS_P. - Values for OPTIONAL_ACTIONS (TCSA*) are in . */ -extern int tcsetattr __P ((int __fd, int __optional_actions, - __const struct termios *__termios_p)); - -#if PRAGMA_STRUCT_ALIGN -#pragma options align=mac68k -#endif -/* - * termios type and macro definitions. Be careful about adding stuff - * to this file since it's used in GNU libc and there are strict rules - * concerning namespace pollution. - */ - -#define NCCS 32 -struct termios { - tcflag_t c_iflag; /* input mode flags */ - tcflag_t c_oflag; /* output mode flags */ - tcflag_t c_cflag; /* control mode flags */ - tcflag_t c_lflag; /* local mode flags */ - cc_t c_line; /* line discipline (== c_cc[19]) */ - cc_t c_cc[NCCS]; /* control characters */ - speed_t c_ispeed; /* input speed */ - speed_t c_ospeed; /* output speed */ -}; -#if PRAGMA_STRUCT_ALIGN -#pragma options align=reset -#endif - -/* c_cc characters */ -#define VINTR 0 -#define VQUIT 1 -#define VERASE 2 -#define VKILL 3 -#define VEOF 4 -#define VMIN 5 -#define VEOL 6 -#define VTIME 7 -#define VEOL2 8 -#define VSWTC 9 - -#define VWERASE 10 -#define VREPRINT 11 -#define VSUSP 12 -#define VSTART 13 -#define VSTOP 14 -#define VLNEXT 15 -#define VDISCARD 16 - -/* c_iflag bits */ -#define IGNBRK 0000001 -#define BRKINT 0000002 -#define IGNPAR 0000004 -#define PARMRK 0000010 -#define INPCK 0000020 -#define ISTRIP 0000040 -#define INLCR 0000100 -#define IGNCR 0000200 -#define ICRNL 0000400 -#define IXON 0001000 -#define IXOFF 0002000 -/* POSIX.1 doesn't want these... */ -#ifdef __USE_BSD -# define IXANY 0004000 -# define IUCLC 0010000 -# define IMAXBEL 0020000 -#endif - -/* c_oflag bits */ -#define OPOST 0000001 -#define ONLCR 0000002 -#define OLCUC 0000004 - -#define OCRNL 0000010 -#define ONOCR 0000020 -#define ONLRET 0000040 - -#define OFILL 00000100 -#define OFDEL 00000200 -#define NLDLY 00001400 -#define NL0 00000000 -#define NL1 00000400 -#define NL2 00001000 -#define NL3 00001400 -#define TABDLY 00006000 -#define TAB0 00000000 -#define TAB1 00002000 -#define TAB2 00004000 -#define TAB3 00006000 -#define CRDLY 00030000 -#define CR0 00000000 -#define CR1 00010000 -#define CR2 00020000 -#define CR3 00030000 -#define FFDLY 00040000 -#define FF0 00000000 -#define FF1 00040000 -#define BSDLY 00100000 -#define BS0 00000000 -#define BS1 00100000 -#define VTDLY 00200000 -#define VT0 00000000 -#define VT1 00200000 -#define XTABS 01000000 /* Hmm.. Linux/i386 considers this part of TABDLY.. */ - -/* c_cflag bit meaning */ -#define CBAUD 0000377 -#define B0 0000000 /* hang up */ -#define B50 0000001 -#define B75 0000002 -#define B110 0000003 -#define B134 0000004 -#define B150 0000005 -#define B200 0000006 -#define B300 0000007 -#define B600 0000010 -#define B1200 0000011 -#define B1800 0000012 -#define B2400 0000013 -#define B4800 0000014 -#define B9600 0000015 -#define B19200 0000016 -#define B38400 0000017 -#define EXTA B19200 -#define EXTB B38400 -#define CBAUDEX 0000020 -#define B57600 00020 -#define B115200 00021 -#define B230400 00022 -#define B460800 00023 -#define B500000 00024 -#define B576000 00025 -#define B921600 00026 -#define B1000000 00027 -#define B1152000 00030 -#define B1500000 00031 -#define B2000000 00032 -#define B2500000 00033 -#define B3000000 00034 -#define B3500000 00035 -#define B4000000 00036 - -#define CSIZE 00001400 -#define CS5 00000000 -#define CS6 00000400 -#define CS7 00001000 -#define CS8 00001400 - -#define CSTOPB 00002000 -#define CREAD 00004000 -#define PARENB 00010000 -#define PARODD 00020000 -#define HUPCL 00040000 - -#define CLOCAL 00100000 -#define CRTSCTS 020000000000 /* flow control */ - -/* c_lflag bits */ -#define ISIG 0x00000080 -#define ICANON 0x00000100 -#define XCASE 0x00004000 -#define ECHO 0x00000008 -#define ECHOE 0x00000002 -#define ECHOK 0x00000004 -#define ECHONL 0x00000010 -#define NOFLSH 0x80000000 -#define TOSTOP 0x00400000 -#define ECHOCTL 0x00000040 -#define ECHOPRT 0x00000020 -#define ECHOKE 0x00000001 -#define FLUSHO 0x00800000 -#define PENDIN 0x20000000 -#define IEXTEN 0x00000400 - -/* Values for the ACTION argument to `tcflow'. */ -#define TCOOFF 0 -#define TCOON 1 -#define TCIOFF 2 -#define TCION 3 - -/* Values for the QUEUE_SELECTOR argument to `tcflush'. */ -#define TCIFLUSH 0 -#define TCOFLUSH 1 -#define TCIOFLUSH 2 - -/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'. */ -#define TCSANOW 0 -#define TCSADRAIN 1 -#define TCSAFLUSH 2 - -struct sgttyb { - char sg_ispeed; - char sg_ospeed; - char sg_erase; - char sg_kill; - short sg_flags; -}; - -struct tchars { - char t_intrc; - char t_quitc; - char t_startc; - char t_stopc; - char t_eofc; - char t_brkc; -}; - -struct ltchars { - char t_suspc; - char t_dsuspc; - char t_rprntc; - char t_flushc; - char t_werasc; - char t_lnextc; -}; - -/* Used for packet mode */ -/* already defined in ttycom.h -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -*/ - -/* already defined in ttycom.h -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; -*/ - -#define NCC 10 -struct termio { - unsigned short c_iflag; /* input mode flags */ - unsigned short c_oflag; /* output mode flags */ - unsigned short c_cflag; /* control mode flags */ - unsigned short c_lflag; /* local mode flags */ - unsigned char c_line; /* line discipline */ - unsigned char c_cc[NCC]; /* control characters */ -}; - -/* c_cc characters */ -#define _VINTR 0 -#define _VQUIT 1 -#define _VERASE 2 -#define _VKILL 3 -#define _VEOF 4 -#define _VMIN 5 -#define _VEOL 6 -#define _VTIME 7 -#define _VEOL2 8 -#define _VSWTC 9 - -/* modem lines */ -/* already defined in ttycom.h -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -*/ - -/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */ -#define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ - -/* line disciplines */ -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 /* X.25 async */ -#define N_6PACK 7 -#define N_MASC 8 /* Mobitex module */ -#define N_R3964 9 /* Simatic R3964 module */ -#define N_PROFIBUS_FDL 10 /* Profibus */ -#define N_IRDA 11 /* Linux IR */ -#define N_SMSBLOCK 12 /* SMS block mode */ -#define N_HDLC 13 /* synchronous HDLC */ -#define N_SYNC_PPP 14 /* synchronous PPP */ - -#endif /* __TERMIOS__ */ diff --git a/lsh/MacOS/lsh.CWPro6.mcp b/lsh/MacOS/lsh.CWPro6.mcp deleted file mode 100644 index fb8c2b2..0000000 Binary files a/lsh/MacOS/lsh.CWPro6.mcp and /dev/null differ diff --git a/lsh/MacOS/lsh.CWPro7.mcp b/lsh/MacOS/lsh.CWPro7.mcp deleted file mode 100644 index b6c25bb..0000000 Binary files a/lsh/MacOS/lsh.CWPro7.mcp and /dev/null differ diff --git a/lsh/MacOS/lsh.mcp b/lsh/MacOS/lsh.mcp deleted file mode 100755 index ae6d62c..0000000 Binary files a/lsh/MacOS/lsh.mcp and /dev/null differ diff --git a/lsh/MacOS/lshdll.CWPro6.mcp b/lsh/MacOS/lshdll.CWPro6.mcp deleted file mode 100644 index 8efff94..0000000 Binary files a/lsh/MacOS/lshdll.CWPro6.mcp and /dev/null differ diff --git a/lsh/MacOS/lshdll.mcp b/lsh/MacOS/lshdll.mcp deleted file mode 100755 index 9ea602e..0000000 Binary files a/lsh/MacOS/lshdll.mcp and /dev/null differ diff --git a/lsh/MacOS/lshdll.mcp.exp b/lsh/MacOS/lshdll.mcp.exp deleted file mode 100644 index 31c78e9..0000000 --- a/lsh/MacOS/lshdll.mcp.exp +++ /dev/null @@ -1,12 +0,0 @@ -lsh_new -lsh_delete -lsh_yield -lsh_read -lsh_canread -lsh_write -lsh_canwrite -lsh_getprefsd -lsh_current -lsh_running -lsh_init -lsh_terminate diff --git a/lsh/MacOS/lshmaccvs.CWPro6.mcp b/lsh/MacOS/lshmaccvs.CWPro6.mcp deleted file mode 100644 index 62da5c2..0000000 Binary files a/lsh/MacOS/lshmaccvs.CWPro6.mcp and /dev/null differ diff --git a/lsh/MacOS/lshmaccvs.mcp b/lsh/MacOS/lshmaccvs.mcp deleted file mode 100644 index 60555a1..0000000 Binary files a/lsh/MacOS/lshmaccvs.mcp and /dev/null differ diff --git a/lsh/MacOS/lshmaccvs.mcp.exp b/lsh/MacOS/lshmaccvs.mcp.exp deleted file mode 100755 index d58b06f..0000000 --- a/lsh/MacOS/lshmaccvs.mcp.exp +++ /dev/null @@ -1,16 +0,0 @@ -lsh_new -lsh_delete -lsh_yield -lsh_read -lsh_canread -lsh_write -lsh_canwrite -lsh_getprefsd -lsh_current -lsh_running -lsh_init -lsh_terminate -GusiLSHSetWriteConsole -GusiLSHSetErrConsole -GusiLSHSetInConsole -GusiLSHSetHandleEvent diff --git a/lsh/MacOS/prime_table/prefix.h b/lsh/MacOS/prime_table/prefix.h deleted file mode 100755 index b4754cf..0000000 --- a/lsh/MacOS/prime_table/prefix.h +++ /dev/null @@ -1,320 +0,0 @@ -/* prefix.h */ - -/* Define if using alloca.c. */ -#undef C_ALLOCA - -/* Define to empty if the keyword does not work. */ -#undef const - -/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. - This function is required for alloca.c support on those systems. */ -#undef CRAY_STACKSEG_END - -/* Define if the `getpgrp' function takes no argument. */ -#undef GETPGRP_VOID - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define if you have alloca, as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define if you have and it should be used (not on Ultrix). */ -#undef HAVE_ALLOCA_H - -/* Define if you don't have vprintf but do have _doprnt. */ -#undef HAVE_DOPRNT - -/* Define if you have the vprintf function. */ -#undef HAVE_VPRINTF - -/* Define as __inline if that's what the C compiler calls it. */ -#undef inline - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown - */ -#undef STACK_DIRECTION - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - -/* Define to enable sanity checking on memory allocation and casting */ -#undef DEBUG_ALLOC - -/* Define to enable tracing */ -#undef DEBUG_TRACE - -/* Define if zlib should be used */ -#undef WITH_ZLIB - -/* Define to enable pty support */ -#undef WITH_PTY_SUPPORT - -/* Define to enable fallback to SSH1 */ -#undef WITH_SSH1_FALLBACK - -/* Location of the SSH1 daemon */ -#undef SSHD1 - -/* Define if IDEA should be used */ -#undef WITH_IDEA - -/* Define if SRP should be supported */ -#undef WITH_SRP - -/* Define to enable tcp forwarding */ -#undef WITH_TCP_FORWARD - -/* For Ipv6 support */ -#undef WITH_IPV6 - -/* Define if AI_NUMERICHOST exists */ -#undef HAVE_AI_NUMERICHOST - -/* For utmp support */ -#undef WITH_UTMP - -/* Define to indicate that shutdown seems to work properly */ -#undef SHUTDOWN_WORKS_WITH_UNIX_SOCKETS - -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE - -/* Define if the compiler understands __FUNCTION__ */ -#undef HAVE_GCC_FUNCTION - -/* Define if the compiler understands offsetof(TYPE, MEMBER) */ -#define HAVE_C_OFFSETOF 1 - -/* Define if a we have working UNIX98 pty handling */ -#undef HAVE_UNIX98_PTYS - -/* For BSD-style pty allocation */ -#undef PTY_BSD_SCHEME_FIRST_CHARS -#undef PTY_BSD_SCHEME_SECOND_CHARS - -#undef PTY_BSD_SCHEME - -/* syslog() available? */ -#undef HAVE_SYSLOG - -/* struct utmp has a ut_host member */ -#undef HAVE_UT_HOST - -/* struct utmp has a ut_name member */ -#undef HAVE_UT_NAME - -/* struct utmp has a ut_user member */ -#undef HAVE_UT_USER - -/* struct utmp has a ut_addr member */ -#undef HAVE_UT_ADDR - -/* struct utmp has a ut_addr_v6 member */ -#undef HAVE_UT_ADDR_V6 - -/* Length type used by getsockopt() */ -/* #undef socklen_t */ - -/* Define to support non-standard packets of ssh2 */ -#undef DATAFELLOWS_WORKAROUNDS - -/* Global variables needed by argp */ -#undef HAVE_PROGRAM_INVOCATION_NAME -#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME - -/* Define to enable x11 forwarding */ -#undef WITH_X11_FORWARD - -/* Define to enable authentication agent forwarding */ -#undef WITH_AGENT_FORWARD - -/* The number of bytes in a int. */ -#define SIZEOF_INT 4 - -/* The number of bytes in a long. */ -#define SIZEOF_LONG 4 - -/* The number of bytes in a short. */ -#define SIZEOF_SHORT 2 - -/* Define if you have the argp_parse function. */ -#undef HAVE_ARGP_PARSE - -/* Define if you have the cfmakeraw function. */ -#undef HAVE_CFMAKERAW - -/* Define if you have the flockfile function. */ -#undef HAVE_FLOCKFILE - -/* Define if you have the fputs_unlocked function. */ -#undef HAVE_FPUTS_UNLOCKED - -/* Define if you have the fwrite_unlocked function. */ -#undef HAVE_FWRITE_UNLOCKED - -/* Define if you have the gai_strerror function. */ -#undef HAVE_GAI_STRERROR - -/* Define if you have the getaddrinfo function. */ -#undef HAVE_GETADDRINFO - -/* Define if you have the getnameinfo function. */ -#undef HAVE_GETNAMEINFO - -/* Define if you have the getopt_long function. */ -#undef HAVE_GETOPT_LONG - -/* Define if you have the getspnam function. */ -#undef HAVE_GETSPNAM - -/* Define if you have the inet_aton function. */ -#undef HAVE_INET_ATON - -/* Define if you have the login function. */ -#undef HAVE_LOGIN - -/* Define if you have the logout function. */ -#undef HAVE_LOGOUT - -/* Define if you have the logwtmp function. */ -#undef HAVE_LOGWTMP - -/* Define if you have the mempcpy function. */ -#undef HAVE_MEMPCPY - -/* Define if you have the memxor function. */ -#undef HAVE_MEMXOR - -/* Define if you have the openpty function. */ -#undef HAVE_OPENPTY - -/* Define if you have the poll function. */ -#undef HAVE_POLL - -/* Define if you have the putc_unlocked function. */ -#undef HAVE_PUTC_UNLOCKED - -/* Define if you have the select function. */ -#undef HAVE_SELECT - -/* Define if you have the socket function. */ -#undef HAVE_SOCKET - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strndup function. */ -#undef HAVE_STRNDUP - -/* Define if you have the strsignal function. */ -#define HAVE_STRSIGNAL 1 -#define strsignal(x) (sys_signame[x]) - -/* Define if you have the strtol function. */ -#undef HAVE_STRTOL - -/* Define if you have the syslog function. */ -#undef HAVE_SYSLOG - -/* Define if you have the vsnprintf function. */ -#undef HAVE_VSNPRINTF - -/* Define if you have the header file. */ -#undef HAVE_ARGP_H - -/* Define if you have the header file. */ -#undef HAVE_CRYPT_H - -/* Define if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define if you have the header file. */ -#define HAVE_GMP_H 1 - -/* Define if you have the header file. */ -#undef HAVE_GMP2_GMP_H - -/* Define if you have the header file. */ -#undef HAVE_LIBUTIL_H - -/* Define if you have the header file. */ -#undef HAVE_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_PTY_H - -/* Define if you have the header file. */ -#undef HAVE_SHADOW_H - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STROPTS_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define if you have the header file. */ -#undef HAVE_UTMP_H - -/* Define if you have the header file. */ -#undef HAVE_UTMPX_H - -/* Define if you have the header file. */ -#undef HAVE_ZLIB_H - -/* Define if you have the crypt library (-lcrypt). */ -#undef HAVE_LIBCRYPT - -/* Define if you have the nsl library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define if you have the socket library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define if you have the util library (-lutil). */ -#undef HAVE_LIBUTIL - -/* Define if you have the xnet library (-lxnet). */ -#undef HAVE_LIBXNET - -/* Define if you have the z library (-lz). */ -#undef HAVE_LIBZ - -/* Name of package */ -#define PACKAGE "lsh" - -/* Version number of package */ -#define VERSION "1.0" - -/* MacOS Library */ - -#define MACOS 1 - -#define LSH 1 - diff --git a/lsh/MacOS/prime_table/prime_table.mcp.xml b/lsh/MacOS/prime_table/prime_table.mcp.xml deleted file mode 100755 index d4d02b7..0000000 Binary files a/lsh/MacOS/prime_table/prime_table.mcp.xml and /dev/null differ diff --git a/lsh/MacOS/src/GUSIConfig.cpp b/lsh/MacOS/src/GUSIConfig.cpp deleted file mode 100755 index 5fb359c..0000000 --- a/lsh/MacOS/src/GUSIConfig.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************** BEGIN GUSI CONFIGURATION **************************** - * - * GUSI Configuration section generated by GUSI Configurator - * last modified: Sat Jul 15 19:32:39 2000 - * - * This section will be overwritten by the next run of Configurator. - */ - -#define GUSI_SOURCE -#include -#include - -/* Declarations of Socket Factories */ - -__BEGIN_DECLS -void GUSIwithInetSockets(); -void GUSIwithLocalSockets(); -void GUSIwithMTInetSockets(); -void GUSIwithMTTcpSockets(); -void GUSIwithMTUdpSockets(); -void GUSIwithOTInetSockets(); -void GUSIwithOTTcpSockets(); -void GUSIwithOTUdpSockets(); -void GUSIwithPPCSockets(); -void GUSISetupFactories(); -__END_DECLS - -/* Configure Socket Factories */ - -void GUSISetupFactories() -{ -#ifdef GUSISetupFactories_BeginHook - GUSISetupFactories_BeginHook -#endif - GUSIwithOTInetSockets(); -#ifdef GUSISetupFactories_EndHook - GUSISetupFactories_EndHook -#endif -} - -/* Declarations of File Devices */ - -__BEGIN_DECLS -void GUSIwithDConSockets(); -void GUSIwithNullSockets(); -void GUSIwithTTYSockets(); -void GUSISetupDevices(); -__END_DECLS - -/* Configure File Devices */ - -void GUSISetupDevices() -{ -#ifdef GUSISetupDevices_BeginHook - GUSISetupDevices_BeginHook -#endif - GUSIwithNullSockets(); - GUSIwithTTYSockets(); -#ifdef GUSISetupDevices_EndHook - GUSISetupDevices_EndHook -#endif -} - -#ifndef __cplusplus -#error GUSISetupConfig() needs to be written in C++ -#endif - -GUSIConfiguration::FileSuffix sSuffices[] = { - "", '????', '????' -}; - -extern "C" void GUSISetupConfig() -{ - GUSIConfiguration * config = - GUSIConfiguration::CreateInstance(GUSIConfiguration::kNoResource); - - config->ConfigureDefaultTypeCreator('TEXT', 'CWIE'); - config->ConfigureSuffices( - sizeof(sSuffices)/sizeof(GUSIConfiguration::FileSuffix)-1, sSuffices); - config->ConfigureSharedOpen(true); -} - -/**************** END GUSI CONFIGURATION *************************/ diff --git a/lsh/MacOS/src/GUSIPatches.cp b/lsh/MacOS/src/GUSIPatches.cp deleted file mode 100755 index a4e3058..0000000 --- a/lsh/MacOS/src/GUSIPatches.cp +++ /dev/null @@ -1,307 +0,0 @@ -/* - * GUSIPatches.cp - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#ifndef __CONSOLE__ -#include -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -void ssh2_init(); -void ssh2_terminate(); - -int open(const char * path, int mode, ...); -int dup(int s); -int socket(int domain, int type, int protocol); -int close(int s); - -void add_one_file(struct lshcontext *context, int fd); -void remove_one_file(struct lshcontext *context, int fd); - -#ifdef __cplusplus -} -#endif - - -/* - * default GUSIProcess::Yield has 20 ticks to remain in same state - * we use 0. - */ - -/* GUSI 2.1.3 -void GUSIProcess::Yield(GUSIYieldMode wait) -{ - ProcessSerialNumber front; - Boolean same; - - if (wait == kGUSIBlock) { - fWillSleep = true; - if (fReadyThreads > 1 || fDontSleep) - wait = kGUSIYield; - } - if (wait == kGUSIYield && LMGetTicks() - fResumeTicks < 0) { - return; - } - if (fClosing) - fClosing->CheckClose(); - if (gGUSISpinHook) { - gGUSISpinHook(wait == kGUSIBlock); - } else { - GUSI_SMESSAGE("Suspend\n"); - GUSIHandleNextEvent(wait == kGUSIBlock ? 600 : 0); - GUSI_SMESSAGE("Resume\n"); - } - - fWillSleep = false; - fDontSleep = false; - fResumeTicks = LMGetTicks(); -} -*/ - -/* GUSI 2.1.5 */ -void GUSIProcess::Yield(GUSIYieldMode wait) -{ - if (wait == kGUSIBlock) { - fWillSleep = true; - if (fReadyThreads > 1 || fDontSleep) { - GUSI_SMESSAGE("Don't Sleep\n"); - wait = kGUSIYield; - } - } - if (fExistingThreads < 2) // Single threaded process skips sleep only once - fDontSleep = false; - if (wait == kGUSIYield && LMGetTicks() - fResumeTicks < 1) { - fWillSleep = false; - return; - } - if (gGUSISpinHook) { - gGUSISpinHook(wait == kGUSIBlock); - } else { - GUSI_SMESSAGE("Suspend\n"); - GUSIHandleNextEvent(wait == kGUSIBlock ? 60 : 0); - GUSI_SMESSAGE("Resume\n"); - } - if (fExistingThreads < 2) // Single threaded process skips sleep only once - fDontSleep = false; - fWillSleep = false; - fResumeTicks = LMGetTicks(); - if (fClosing) - fClosing->CheckClose(); -} - -/* - * default GUSIContext::Yield has 12 ticks to remain in same state - * we use 0. - */ - -bool GUSIContext::Yield(GUSIYieldMode wait) -{ - if (wait == kGUSIYield && LMGetTicks() - sCurrentContext->fEntryTicks < 0) - return false; - - bool mainThread = sCurrentContext->fThreadID == kApplicationThreadID; - bool block = wait == kGUSIBlock && !mainThread; - GUSIProcess * process = GUSIProcess::Instance(); - bool interrupt = false; - - do { - if (mainThread) - process->Yield(wait); - - if (interrupt = Raise()) - goto done; - - if (sHasThreading) { - if (block) - SetThreadState(kCurrentThreadID, kStoppedThreadState, kNoThreadID); - else - YieldToAnyThread(); - } - } while (wait == kGUSIBlock && !sCurrentContext->fWakeup); -done: - sCurrentContext->fWakeup = false; - - return interrupt; -} - - -/* - * we need to track open()/dup()/close()/socket() calls to close files/sockets - * upon abort/exit - */ - -/* - * open. - */ - -int open(const char * path, int mode, ...) -{ - GUSIErrorSaver saveError; - GUSIDeviceRegistry * factory = GUSIDeviceRegistry::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISocket * sock; - int fd; - - if (sock = factory->open(path, mode)) { - if ((fd = table->InstallSocket(sock)) > -1) { - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( context ) { - add_one_file(context, fd); - } - return fd; - } - sock->close(); - } - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} - -/* - * dup. - */ - -int dup(int s) -{ - GUSIDescriptorTable *table = GUSIDescriptorTable::Instance(); - GUSISocket *sock = GUSIDescriptorTable::LookupSocket(s); - int fd; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if (!sock) - return -1; - - fd = table->InstallSocket(sock); - if ( context ) { - add_one_file(context, fd); - } - return fd; -} - -/* - * dup2. - */ - -int dup2(int s, int s1) -{ - GUSIDescriptorTable *table = GUSIDescriptorTable::Instance(); - GUSISocket *sock = GUSIDescriptorTable::LookupSocket(s); - int fd; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if (!sock) - return -1; - - table->RemoveSocket(s1); - fd = table->InstallSocket(sock, s1); - if ( context && s1 != fd ) { - remove_one_file(context, s1); - add_one_file(context, fd); - } - return fd; -} - -/* - * socket. - */ - -int socket(int domain, int type, int protocol) -{ - GUSIErrorSaver saveError; - GUSISocketFactory * factory = GUSISocketDomainRegistry::Instance(); - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISocket * sock; - int fd; - - if (sock = factory->socket(domain, type, protocol)) { - if ((fd = table->InstallSocket(sock)) > -1) { - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( context ) { - add_one_file(context, fd); - } - return fd; - } - sock->close(); - } - if (!errno) - return GUSISetPosixError(ENOMEM); - else - return -1; -} - -/* - * close. - */ - -int close(int s) -{ - if ( s > STDERR_FILENO ) { - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( context ) { - remove_one_file(context, s); - } - return table->RemoveSocket(s); - } else { - /* we don't close stdin/stdout/stderr */ - return 0; - } -} - -#pragma mark - - -static Boolean sGUSISetup = false; - -/* - * ssh2_init - */ -extern "C" short SIOUXHandleOneEvent(EventRecord *userevent); - -void ssh2_init() -{ - if ( !sGUSISetup ) { - GUSIContext::Setup(true); - GUSISetupConsole(); - GUSISetHook(GUSI_EventHook+keyDown, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+keyUp, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+autoKey, (GUSIHook)SIOUXHandleOneEvent); - sGUSISetup = true; - } -} - -/* - * ssh2_terminate - */ - -void ssh2_terminate() -{ - - if ( sGUSISetup ) { - sGUSISetup = false; - } -} diff --git a/lsh/MacOS/src/GUSISIOUX.cp b/lsh/MacOS/src/GUSISIOUX.cp deleted file mode 100644 index dcf8018..0000000 --- a/lsh/MacOS/src/GUSISIOUX.cp +++ /dev/null @@ -1,247 +0,0 @@ -// = -#include "GUSIInternal.h" -#include "GUSISIOUX.h" -#include "GUSIDevice.h" -#include "GUSIDescriptor.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" - -#include - -#include -#include -#include -#include -#include - -// \section{Definition of [[GUSISIOUXSocket]]} -// -// A [[GUSISIOUXSocket]] is another singleton class: There is only one SIOUX -// console per application. -// -// -// = -class GUSISIOUXSocket : public GUSISocket { -public: - ~GUSISIOUXSocket(); - - // Some member functions are fairly trivial wrappers. - // - // = - ssize_t read(const GUSIScatterer & buffer); - // = - ssize_t write(const GUSIGatherer & buffer); - // = - virtual int ioctl(unsigned int request, va_list arg); - // Since we know we're running on a pseudodevice, we can pass on that fact. - // - // = - virtual int fstat(struct stat * buf); - // And we also know we're a TTY. - // - // = - virtual int isatty(); - // [[select]] requires a walk of the event queue. - // - // = - virtual bool pre_select(bool wantRead, bool wantWrite, bool wantExcept); - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - virtual void post_select(bool wantRead, bool wantWrite, bool wantExcept); - - static GUSISIOUXSocket * Instance(); -private: - static GUSISIOUXSocket * sInstance; - - GUSISIOUXSocket(); -}; - - - -extern "C" void GUSIWakeupSIOUXSocket() -{ - GUSISIOUXSocket::Instance()->Wakeup(); -} - - -// \section{Definition of [[GUSISIOUXDevice]]} -// -// A [[GUSISIOUXDevice]] is a singleton class supporting the standard [[open]] -// operation. -// -// = -class GUSISIOUXDevice : public GUSIDevice { -public: - static GUSISIOUXDevice * Instance(); - - // [[GUSISIOUXDevice]] is prepared to handle an [[open]] on a limited set of names. - // - // = - virtual bool Want(GUSIFileToken & file); - // [[open]] returns the sole instance of [[GUSISIOUXSocket]]. - // - // = - virtual GUSISocket * open(GUSIFileToken &, int flags); -private: - GUSISIOUXDevice() {} - - static GUSISIOUXDevice * sInstance; -}; -// \section{Implementation of [[GUSISIOUXSocket]]} -// -// A [[GUSISIOUXSocket]] is a dataless wrapper for the SIOUX -// library. To protect the sole instance from ever being deleted -// again, we artificially raise its reference count. -// -// = -GUSISIOUXSocket * GUSISIOUXSocket::sInstance; - -GUSISIOUXSocket * GUSISIOUXSocket::Instance() -{ - if (!sInstance) - if (sInstance = new GUSISIOUXSocket) - sInstance->AddReference(); - - return sInstance; -} -// On construction, we make sure to install the SIOUX event handler for all -// relevant elements. -// -// = -// This declaration lies about the return type -extern "C" void SIOUXHandleOneEvent(EventRecord *userevent); - -GUSISIOUXSocket::GUSISIOUXSocket() -{ - InstallConsole(0); - GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent); -} -GUSISIOUXSocket::~GUSISIOUXSocket() -{ - RemoveConsole(); -} -// = -ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer) -{ - GUSIStdioFlush(); - return buffer.SetLength( - ReadCharsFromConsole((char *) buffer.Buffer(), (int)buffer.Length())); -} -// = -ssize_t GUSISIOUXSocket::write(const GUSIGatherer & buffer) -{ - return WriteCharsToConsole((char *) buffer.Buffer(), (int)buffer.Length()); -} -// = -int GUSISIOUXSocket::ioctl(unsigned int request, va_list) -{ - switch (request) { - case FIOINTERACTIVE: - return 0; - default: - return GUSISetPosixError(EOPNOTSUPP); - } -} -// = -int GUSISIOUXSocket::fstat(struct stat * buf) -{ - GUSISocket::fstat(buf); - buf->st_mode = S_IFCHR | 0666; - - return 0; -} -// = -int GUSISIOUXSocket::isatty() -{ - return 1; -} -// = -static bool input_pending() -{ - QHdrPtr eventQueue = LMGetEventQueue(); - EvQElPtr element = (EvQElPtr)eventQueue->qHead; - - // now, count the number of pending keyDown events. - while (element != nil) { - if (element->evtQWhat == keyDown || element->evtQWhat == autoKey) - return true; - element = (EvQElPtr)element->qLink; - } - - return false; -} - -// [[pre_select]] and [[post_select]] often don't have to do anything. By default, -// we assume that a socket can sleep. - -bool GUSISIOUXSocket::pre_select(bool wantRead, bool wantWrite, bool wantExcept) -{ - return GUSISocket::pre_select(wantRead, wantWrite, wantExcept); -} - -void GUSISIOUXSocket::post_select(bool wantRead, bool wantWrite, bool wantExcept) -{ - GUSISocket::post_select(wantRead, wantWrite, wantExcept); -} - -extern Boolean gSIOUXTerminalMode; -extern short gSIOUXBufSize; - -bool GUSISIOUXSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = /*input_pending()*/ - ((gSIOUXTerminalMode && gSIOUXBufSize != 0) || input_pending()) ) - cond = true; - if (canWrite) - cond = *canWrite = true; - - return cond; -} - -// \section{Implementation of [[GUSISIOUXDevice]]} -// -// [[GUSISIOUXDevice]] is a singleton class. -// -// = -GUSISIOUXDevice * GUSISIOUXDevice::sInstance; -// = -GUSISIOUXDevice * GUSISIOUXDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSISIOUXDevice(); - return sInstance; -} -// = -bool GUSISIOUXDevice::Want(GUSIFileToken & file) -{ - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - return file.IsDevice() && (file.StrStdStream(file.Path()) > -1); - default: - return false; - } -} -// = -GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int) -{ - return GUSISIOUXSocket::Instance(); -} -// A SIOUX application connects to the three standard descriptors on startup. -// -// = -void GUSISetupConsoleDescriptors() -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - GUSISIOUXSocket * SIOUX = GUSISIOUXSocket::Instance(); - - table->InstallSocket(SIOUX); - table->InstallSocket(SIOUX); - table->InstallSocket(SIOUX); -} diff --git a/lsh/MacOS/src/GUSITTY.cp b/lsh/MacOS/src/GUSITTY.cp deleted file mode 100644 index 0b5c351..0000000 --- a/lsh/MacOS/src/GUSITTY.cp +++ /dev/null @@ -1,282 +0,0 @@ -/* - * GUSITTY.cp - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#include "GUSIInternal.h" -#include "GUSITTY.h" -#include "GUSIDevice.h" -#include "GUSIDescriptor.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" - -#include - -#include -#include -#include - - -class GUSITTYDevice : public GUSIDevice { -public: - static GUSITTYDevice * Instance(); - - // [[GUSITTYDevice]] is prepared to handle an [[open]] on a limited set of names. - // - // = - virtual bool Want(GUSIFileToken & file); - // [[open]] returns instance of [[GUSITTYSocket]]. - // - // = - virtual GUSISocket * open(GUSIFileToken &, int flags); -private: - GUSITTYDevice() {} - - static GUSITTYDevice * sInstance; -}; - - - -class GUSITTYSocket : public GUSISocket { -public: - ~GUSITTYSocket(); - - // Some member functions are fairly trivial wrappers. - // - // = - ssize_t read(const GUSIScatterer & buffer); - // = - ssize_t write(const GUSIGatherer & buffer); - // = - virtual int ioctl(unsigned int request, va_list arg); - // Since we know we're running on a pseudodevice, we can pass on that fact. - // - // = - virtual int fstat(struct stat * buf); - // And we also know we're a TTY. - // - // = - virtual int isatty(); - // [[select]] requires a walk of the event queue. - // - // = - virtual bool pre_select(bool wantRead, bool wantWrite, bool wantExcept); - virtual bool select(bool * canRead, bool * canWrite, bool * exception); - virtual void post_select(bool wantRead, bool wantWrite, bool wantExcept); - -protected: - GUSITTYSocket(int id, void *context); - - int mId; - void *mContext; - - friend class GUSITTYDevice; -}; - - - -/* - * GUSIwithTTYSockets - */ -extern "C" void GUSIwithTTYSockets() -{ - GUSIDeviceRegistry::Instance()->AddDevice(GUSITTYDevice::Instance()); -} - -/* - * GUSIwithoutTTYSockets - */ -extern "C" void GUSIwithoutTTYSockets() -{ - GUSIDeviceRegistry::Instance()->RemoveDevice(GUSITTYDevice::Instance()); -} - -/* - * GUSIWakeupTTYSocket - */ -extern "C" void GUSIWakeupTTYSocket( void *insock ) -{ - GUSISocket *sock = (GUSISocket *)insock; - sock->Wakeup(); -} - - -/* - * GUSITTYDevice::Instance - */ - -GUSITTYDevice * GUSITTYDevice::sInstance; - -GUSITTYDevice * GUSITTYDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSITTYDevice(); - return sInstance; -} - -/* - * GUSITTYDevice::Want - */ -bool GUSITTYDevice::Want(GUSIFileToken &file) -{ - const char *path = file.Path(); - - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - return file.IsDevice() && file.StrFragEqual(path+4, "tty") - && (!path[7] - || (file.StrFragEqual(path+7, "in") && !path[9]) - || (file.StrFragEqual(path+7, "out") && !path[10]) - || (file.StrFragEqual(path+7, "err") && !path[10])); - default: - return false; - } -} - -/* - * GUSITTYDevice::open - */ -GUSISocket * GUSITTYDevice::open(GUSIFileToken &file, int flags) -{ - GUSISocket *sock; - const char *path = file.Path(); - int id; - - if (!path[7]) { - id = 3; - } else if (!path[9]) { - id = 0; - } else if (file.StrFragEqual(path+7, "out")) { - id = 1; - } else /*if (file.StrFragEqual(path+7, "err"))*/ { - id = 2; - } - if ( !(sock = new GUSITTYSocket(id, pthread_getspecific(ssh2threadkey)) )) { - GUSISetPosixError(ENOMEM); - } - return sock; -} - - - -/* - * GUSITTYSocket::GUSITTYSocket - */ -GUSITTYSocket::GUSITTYSocket(int id, void *context) : mId(id), mContext(context) -{ - InstallTTY(id, context, this); -} - - -/* - * GUSITTYSocket::~GUSITTYSocket - */ -GUSITTYSocket::~GUSITTYSocket() -{ - RemoveTTY(mId, mContext, this); -} - -/* - * GUSITTYSocket::read - */ -ssize_t GUSITTYSocket::read(const GUSIScatterer & buffer) -{ - /* FIXME: flush pending output */ - /*FlushTTY(mId);*/ - return buffer.SetLength( - ReadCharsFromTTY(mId, mContext, (char *) buffer.Buffer(), (int)buffer.Length())); -} - -/* - * GUSITTYSocket::write - */ -ssize_t GUSITTYSocket::write(const GUSIGatherer & buffer) -{ - return WriteCharsToTTY(mId, mContext, (char *) buffer.Buffer(), (int)buffer.Length()); -} - -/* - * GUSITTYSocket::ioctl - */ -int GUSITTYSocket::ioctl(unsigned int request, va_list) -{ - switch (request) { - case FIOINTERACTIVE: - return 0; - default: - return GUSISetPosixError(EOPNOTSUPP); - } -} - -/* - * GUSITTYSocket::fstat - */ -int GUSITTYSocket::fstat(struct stat * buf) -{ - GUSISocket::fstat(buf); - buf->st_mode = S_IFCHR | 0666; - - return 0; -} - -/* - * GUSITTYSocket::isatty - */ -int GUSITTYSocket::isatty() -{ - return 1; -} - -extern "C" int get_context_listener(); - -/* - * GUSITTYSocket::pre_select - */ -bool GUSITTYSocket::pre_select(bool wantRead, bool wantWrite, bool wantExcept) -{ - /* we can't sleep when in pseudo-port forwarding mode */ - /* because the select functions polls for the connection */ - if (get_context_listener() == -1) { - return GUSISocket::pre_select(wantRead, wantWrite, wantExcept); - } - return false; -} - -/* - * GUSITTYSocket::post_select - */ -void GUSITTYSocket::post_select(bool wantRead, bool wantWrite, bool wantExcept) -{ - if (get_context_listener() == -1) { - GUSISocket::post_select(wantRead, wantWrite, wantExcept); - } -} - -/* - * GUSITTYSocket::select - */ -bool GUSITTYSocket::select(bool * canRead, bool * canWrite, bool *) -{ - bool cond = false; - if (canRead) - if (*canRead = AvailableFromTTY(mId, mContext)) - cond = true; - if (canWrite) - cond = *canWrite = true; - - return cond; -} diff --git a/lsh/MacOS/src/GUSITTY.h b/lsh/MacOS/src/GUSITTY.h deleted file mode 100644 index 26e20f6..0000000 --- a/lsh/MacOS/src/GUSITTY.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _GUSITTY_ -#define _GUSITTY_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern pthread_key_t ssh2threadkey; - -extern void GUSIWakeupTTYSocket( void *sock ); - -extern int InstallTTY(int id, void *context, void *sock); -extern void RemoveTTY(int id, void *context, void *sock); -extern int ReadCharsFromTTY(int id, void *context, char * buffer, int length); -extern int WriteCharsToTTY(int id, void *context, char * buffer, int length); -extern int AvailableFromTTY(int id, void *context); - -#ifdef __cplusplus -} -#endif - -#endif /* _GUSITTY_ */ diff --git a/lsh/MacOS/src/MemPool.c b/lsh/MacOS/src/MemPool.c deleted file mode 100755 index a0463ba..0000000 --- a/lsh/MacOS/src/MemPool.c +++ /dev/null @@ -1,402 +0,0 @@ -/* - * MemPool.c - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#define XTERN_POOL 1 -#define GROW_POOL 1 -#define USENEEDED 1 -#define GETSTATS 1 -#define MASK_INT 0 -#define DEBUG_MEM 1 - -/*--------------- CIncludes --------------------------------------------------*/ - -#ifndef __MEMORY__ -#include -#endif -#ifndef __ERRORS__ -#include -#endif -#include - -/*--------------- Includes ---------------------------------------------------*/ - -#ifndef __MEMPOOL__ -#include "MemPool.h" -#endif - -/*--------------- Local Declarations -----------------------------------------*/ - -#if DEBUG_MEM -#define DEBUGSTRING(x) DebugStr("\p"x) -#else -#define DEBUGSTRING(x) -#endif - -#if MASK_INT - -#pragma parameter __D0 DisInt -unsigned short DisInt(void) = {0x40c0,0x007C,0x0700}; // move.w sr,d0 ori.w #$700,sr - -#pragma parameter EnInt(__D0) -void EnInt(unsigned short) = {0x46C0}; // move.w d0,sr - -#else - -#define DisInt() 0 -#define EnInt(x) - -#endif - -struct mem { - unsigned long size; -#if USENEEDED - unsigned long neededSize; -#endif - struct mem *nextBlock; -}; - -#define MEMHSIZE (sizeof(struct mem)) - -#if USENEEDED -#define SETUSED(mp, wanted) mp->neededSize = wanted -#define GETUSED(mp) mp->neededSize -#else -#define SETUSED(mp, wanted) -#define GETUSED(mp) -#endif - -#if GETSTATS -#define ADDSIZE(memPool, mp) memPool->f_CurrSize += mp->size; \ - if (memPool->f_PeakSize < memPool->f_CurrSize) \ - memPool->f_PeakSize = memPool->f_CurrSize -#define REMOVESIZE(memPool, mp) memPool->f_CurrSize -= mp->size -#else -#define ADDSIZE(memPool, mp) -#define REMOVESIZE(memPool, mp) -#endif - -#define BADBLOCK(memPool, mp) \ - ((mp) < memPool->f_LoMem || (mp) > memPool->f_HiMem - MEMHSIZE \ - || !(mp)->size || (mp)->size > memPool->f_PoolSize) - - -//------------------------------------------------------------------------------ - -OSErr MPInit(long allocsize, Ptr *priv, Ptr prev) -{ -#if XTERN_POOL - OSErr err; -#endif - Handle privH; - MemPool *memPool; - Handle poolH; - - privH = NewHandle(sizeof(MemPool)); - if ( privH == nil ) { - //return MemError(); - return memFullErr; - } - MoveHHi(privH); - HLock(privH); - - memPool = (MemPool *)*privH; - -#if XTERN_POOL - poolH = TempNewHandle((Size)allocsize + MEMHSIZE, &err); -#else - poolH = NewHandle((Size)allocsize + MEMHSIZE); -#endif - if ( poolH == nil ) { - DisposeHandle(privH); - //return MemError(); - return memFullErr; - } -#if !XTERN_POOL - MoveHHi(poolH); -#endif - HLock(poolH); - - memPool->f_LoMem = *poolH; - memPool->f_Top = memPool->f_LoMem; - memPool->f_Free = (char *)0L; - memPool->f_HiMem = memPool->f_LoMem + allocsize + MEMHSIZE; - memPool->f_PoolSize = allocsize; - memPool->f_HandleRec = privH; - memPool->f_HandleMem = poolH; - memPool->next = nil; - memPool->prev = (MemPool *)prev; -#if GETSTATS - memPool->f_CurrSize = 0L; - memPool->f_PeakSize = 0L; -#endif - *priv = (Ptr)memPool; - - return noErr; -} - -//------------------------------------------------------------------------------ - -void MPDispose(Ptr priv) -{ -#if XTERN_POOL - OSErr err; -#endif - MemPool *memPool = (MemPool *)priv; - -#if DEBUG_MEM - assert(memPool == (MemPool *)*memPool->f_HandleRec); - assert(memPool->f_LoMem == *memPool->f_HandleMem); -#endif -#if GROW_POOL - if (memPool->next != nil) { - MPDispose(memPool->next); - memPool->next = nil; - } -#endif - if (memPool->f_LoMem != nil) { -#if XTERN_POOL - TempDisposeHandle(memPool->f_HandleMem, &err); -#else - DisposeHandle(memPool->f_HandleMem); -#endif - memPool->f_LoMem = nil; - DisposeHandle(memPool->f_HandleRec); - } -} - -//------------------------------------------------------------------------------ -// to always clear the buffers upon allocation, replace this bzero by the real one - -#define bzero(pointer, size) pointer - -//------------------------------------------------------------------------------ - -void *MPmalloc(Ptr priv, long size) -{ - MemPool *memPool = (MemPool *)priv; - register struct mem *mp, *tmp; - long wanted; - unsigned short oldLevel; - -#if DEBUG_MEM - assert(memPool == (MemPool *)*memPool->f_HandleRec); - assert(memPool->f_LoMem == *memPool->f_HandleMem); -#endif - if ((wanted = size) == 0) - return (char *)0; - else { - // align to four bytes - if (size % 4) - size += 4 - (size % 4); - size += MEMHSIZE; - } - oldLevel = DisInt(); - // search into the free blocks list if size needed is found - for (tmp = 0, mp = (struct mem *)memPool->f_Free; mp; tmp = mp, mp = mp->nextBlock) { - assert(!BADBLOCK(memPool, mp)); - if (mp && mp->size >= size) { - // this block is at least big enough for the size needed - if (mp->size >= size + MEMHSIZE + 4) { // free the begining - // this block is much bigger, let's create a new free block - tmp = (struct mem *)((unsigned)mp + mp->size - size); - tmp->size = size; - mp->size -= size; - SETUSED(tmp, wanted); - ADDSIZE(memPool, tmp); - EnInt(oldLevel); - return bzero((char *)tmp + MEMHSIZE, wanted); - } - if (tmp) { - tmp->nextBlock = mp->nextBlock; - } - else - memPool->f_Free = (char *)mp->nextBlock; - SETUSED(mp, wanted); - ADDSIZE(memPool, mp); - EnInt(oldLevel); - return bzero((char *)mp + MEMHSIZE, wanted); - } - } - if (memPool->f_Top + size > memPool->f_HiMem) { -#if GROW_POOL - if (memPool->next == nil) { - OSErr err; - long poolsize = size > memPool->f_PoolSize ? size : memPool->f_PoolSize; - err = MPInit(poolsize, &memPool->next, (Ptr)memPool); - if (err == noErr) { - EnInt(oldLevel); - return MPmalloc((Ptr)memPool->next, wanted); - } - } else { - EnInt(oldLevel); - return MPmalloc((Ptr)memPool->next, wanted); - } -#endif - EnInt(oldLevel); - return nil; - } - mp = (struct mem *)memPool->f_Top; - memPool->f_Top += size; - mp->size = size; - SETUSED(mp, wanted); - ADDSIZE(memPool, mp); - EnInt(oldLevel); - return bzero((char *)mp + MEMHSIZE, wanted); -} - -//------------------------------------------------------------------------------ - -void MPfree(Ptr priv, void *addr) -{ - MemPool *memPool = (MemPool *)priv; - register struct mem *memAddr; - register struct mem *mp, *tmp; - unsigned short oldLevel; - -#if DEBUG_MEM - assert(memPool == (MemPool *)*memPool->f_HandleRec); - assert(memPool->f_LoMem == *memPool->f_HandleMem); -#endif - // check the addr - if (addr < memPool->f_LoMem + MEMHSIZE || addr >= memPool->f_HiMem) { -#if GROW_POOL - if (memPool->next != nil) { - MPfree(memPool->next, addr); - } else { -#endif - DEBUGSTRING("### MPfree : outbounds"); -#if GROW_POOL - } -#endif - return; - } - memAddr = (struct mem *)((char *)addr - MEMHSIZE); - if (!memAddr->size || memAddr->size > memPool->f_PoolSize) { - DEBUGSTRING("### MPfree : bad size"); - return; - } - -#if USENEEDED - if (!GETUSED(memAddr) || GETUSED(memAddr) > memPool->f_PoolSize) { - DEBUGSTRING("### MPfree : bad user size"); - return; - } - SETUSED(memAddr, 0); -#endif - - REMOVESIZE(memPool, memAddr); - - oldLevel = DisInt(); - - // insert the block in the free list - if (memPool->f_Free == nil) { - memPool->f_Free = (char *)memAddr; - memAddr->nextBlock = nil; - } else { - // get previous free block - for (tmp = nil, mp = (struct mem *)memPool->f_Free; mp; tmp = mp, mp = mp->nextBlock) { - assert(!BADBLOCK(memPool, mp)); - // this block is between memPool->f_LoMem and previous free block - if (tmp < memAddr && memAddr < mp) - break; - } - - // hook mp block to the just freed "memAddr" one - memAddr->nextBlock = mp; - - // if we had previous blocks - if (tmp) { - tmp->nextBlock = memAddr; - } else { - memPool->f_Free = (char *)memAddr; - } - } - // now compact the free blocks list - // try assembling adjacent free blocks - for (tmp = (struct mem *)memPool->f_Free, - mp = ((struct mem *)memPool->f_Free)->nextBlock; mp; tmp=mp, mp=mp->nextBlock) { - assert(!BADBLOCK(memPool, mp)); - if ((char *)tmp + tmp->size == (char *)mp) { - tmp->size += mp->size; - tmp->nextBlock = mp->nextBlock; - mp = tmp; - } - } - // now try to free blocks in the list - // tmp points to the last free block - if (memPool->f_Top == (char *)tmp + tmp->size) { - // memPool->f_Top is just after the last free block - // remove the last free block off the list and ajust memPool->f_Top - memPool->f_Top = (char *)tmp; - if (memPool->f_Free == (char *)tmp) { - // last free block was the first of the list : the list is empty - memPool->f_Free = nil; - } else { - // remove the last block off the list - for (mp = (struct mem *)memPool->f_Free; mp->nextBlock != tmp; mp = mp->nextBlock) - ; - mp->nextBlock = nil; - } - } -#if GROW_POOL - /* don't kill first mempool: it's the only one known by the caller... */ - if ( memPool->prev && memPool->f_Free == nil && memPool->f_Top == memPool->f_LoMem ) { - if ( memPool->prev ) - memPool->prev->next = memPool->next; - if ( memPool->next ) - memPool->next->prev = memPool->prev; - memPool->next = nil; - MPDispose(priv); - } -#endif - EnInt(oldLevel); -} - -//------------------------------------------------------------------------------ -#if USENEEDED -long MPsize(Ptr priv, void *addr) -{ - MemPool *memPool = (MemPool *)priv; - register struct mem *memAddr; - - // check the addr - if (addr < memPool->f_LoMem + MEMHSIZE || addr >= memPool->f_HiMem) { -#if GROW_POOL - if (memPool->next != nil) { - return MPsize((Ptr)memPool->next, addr); - } else { -#endif - DEBUGSTRING("### MPsize : outbounds"); -#if GROW_POOL - } -#endif - return NULL; - } - memAddr = (struct mem *)((char *)addr - MEMHSIZE); - if (!memAddr->size || memAddr->size > memPool->f_PoolSize) { - DEBUGSTRING("### MPsize : bad size"); - return NULL; - } - if (!GETUSED(memAddr) || GETUSED(memAddr) > memPool->f_PoolSize) { - DEBUGSTRING("### MPsize : bad user size"); - return NULL; - } - return GETUSED(memAddr); -} -#endif diff --git a/lsh/MacOS/src/MemPool.h b/lsh/MacOS/src/MemPool.h deleted file mode 100755 index 6f8c92c..0000000 --- a/lsh/MacOS/src/MemPool.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * MemPool.c - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#ifndef __MEMPOOL__ -#define __MEMPOOL__ - -#ifndef __MEMORY__ -#include -#endif - -typedef struct MemPool { - char *f_Top; - char *f_Free; - char *f_HiMem; - char *f_LoMem; - long f_PoolSize; - Handle f_HandleRec; - Handle f_HandleMem; - struct MemPool *next; - struct MemPool *prev; -#if GETSTATS - long f_CurrSize; - long f_PeakSize; -#endif -} MemPool; - -#ifdef __cplusplus -extern "C" { -#endif - - OSErr MPInit(long allocsize, Ptr *priv, Ptr prev); - void MPDispose(Ptr priv); - - void *MPmalloc(Ptr priv, long size); - void MPfree(Ptr priv, void *addr); - long MPsize(Ptr priv, void *addr); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lsh/MacOS/src/PasswordDialog.c b/lsh/MacOS/src/PasswordDialog.c deleted file mode 100755 index eee7383..0000000 --- a/lsh/MacOS/src/PasswordDialog.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - File: PasswordDialog.c - - Contains: This file contains all the interesting password stuff - - Written by: Tim Dierks - - Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved. - - You may incorporate this Apple sample source code into your program(s) without - restriction. This Apple sample source code has been provided "AS IS" and the - responsibility for its operation is yours. You are not permitted to redistribute - this Apple sample source code as "Apple sample source code" after having made - changes. If you're going to re-distribute the source, we require that you make - it clear in the source that the code was descended from Apple sample source - code, but that you've made changes. - - Change History (most recent first): - 8/9/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 - - -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PasswordDialog.h" -/* -#include "movableModal.h" -#include "DlogUtils.proto.h" -*/ - -static pascal Boolean InternalBufferFilter(DialogPtr dlog,EventRecord *event,short *itemHit); -static void DeleteRange(char *buffer,short start,short end); -static void InsertChar(char *buffer,short pos,char c); - -#define kMaxPasswordLen 128 - -Boolean YesNoDialog(StringPtr prompt) -{ - Boolean result = false; - DialogPtr dlog; - short item; - /*ModalFilterUPP yesNoFilterUPP;*/ - - /*yesNoFilterUPP = NewModalFilterProc(YesNoFilter);*/ - dlog = GetNewDialog(rYesNoDialog, 0L, (WindowPtr)-1L); - if ( dlog ) { - ParamText(prompt, "\p", "\p", "\p"); - ShowWindow(dlog); - SetDialogDefaultItem(dlog, 1); - SetDialogCancelItem(dlog, 2); - do { - ModalDialog(NULL, &item); - } while (item != 1 && item != 2); // Until the OK/Cancel button is hit - result = (item == 2); - DisposeDialog(dlog); - } - /*DisposeRoutineDescriptor(yesNoFilterUPP);*/ - return result; -} - -/* -Boolean SSH2PasswordDialog(StringPtr prompt, StringPtr password) -{ - DialogPtr dlog; - short item; - ModalFilterUPP internalBufferFilterUPP; - - SetUpMovableModalMenus(); - internalBufferFilterUPP = NewModalFilterProc(InternalBufferFilter); - *password = '\0'; - //dlog = GetNewDialog(rSSH2PasswordDialog, 0L, (WindowPtr)-1L); - dlog = GetNewMyDialog(rSSH2PasswordDialog, 0L, (WindowPtr)-1L, (void *)ThirdCenterDialog); - if ( dlog ) { - SInt16 itemType; - Handle itemHandle; - Rect itemRect; - GetDialogItem(dlog, 5, &itemType, &itemHandle, &itemRect); - SetDialogItemText(itemHandle, prompt); - //ParamText(prompt, "\p", "\p", "\p"); - ShowWindow(dlog); - SetWRefCon(dlog, (long)password); // Stash the buffer's address - SetDialogDefaultItem(dlog, 1); - SetDialogCancelItem(dlog, 2); - do { - //ModalDialog(internalBufferFilterUPP, &item); - movableModalDialog(internalBufferFilterUPP, &item); - } while (item != 1 && item != 2); // Until the OK button is hit - DisposeDialog(dlog); - } - DisposeRoutineDescriptor(internalBufferFilterUPP); - ResetMenus(); -} -*/ - -void InternalBufferDialog(StringPtr prompt, StringPtr password) -{ - DialogPtr dlog; - short item; - ModalFilterUPP internalBufferFilterUPP; - - internalBufferFilterUPP = NewModalFilterProc(InternalBufferFilter); - *password = '\0'; // Zero out the buffered password - dlog = GetNewDialog(rInternalBufferDialog, 0L, (WindowPtr)-1L); - if ( dlog ) { - ParamText(prompt, "\p", "\p", "\p"); - ShowWindow(dlog); - SetWRefCon(dlog, (long)password); // Stash the buffer's address - SetDialogDefaultItem(dlog, 1); - do { - ModalDialog(internalBufferFilterUPP, &item); - } while (item != 1); // Until the OK button is hit - DisposeDialog(dlog); - } - DisposeRoutineDescriptor(internalBufferFilterUPP); -} - -static pascal Boolean -InternalBufferFilter(DialogPtr dlog,EventRecord *event,short *itemHit) -{ char key; - short start,end; - char *buffer; - - if (event->what != keyDown && event->what != autoKey) - return false; // We don't want to deal with them - - key = event->message & charCodeMask; - - switch (key) { - case '\r': // Return - case '\003': // Enter - *itemHit = 1; // OK Button - return true; // We handled the event - case '.': // Cmd-. - if (!(event->modifiers & cmdKey)) - break; - case '\033': // Esc - *itemHit = 2; // Cancel Button - return true; // We handled the event - case '\t': // Tab - case '\034': // Left arrow - case '\035': // Right arrow - case '\036': // Up arrow - case '\037': // Down arrow - return false; // Let ModalDialog handle them - default: // Everything else falls through to be dealt with - break; // below - } - - start = (**((DialogPeek)dlog)->textH).selStart; // Get the current selection - end = (**((DialogPeek)dlog)->textH).selEnd; - - buffer = (char*)GetWRefCon(dlog); // Get the buffer's address - - if (start != end) { // If there's a selection, delete it - DeleteRange(buffer,start,end); - } - if (key == '\010') { // Backspace - if (start != 0) { - DeleteRange(buffer,start-1,start); // Delete the character to the left - } - } else { - if ((event->modifiers & cmdKey)) { - if (key == 'v' || key == 'V') { - // get scrap - Handle hText; - OSErr err; - if ((err = GetScrapHandle('TEXT', &hText)) == noErr) { - int len = GetHandleSize(hText); - if (len + *buffer <= kMaxPasswordLen) { - int i; - for (i = 0; i < len; i++) { - InsertChar(buffer,start++,(*hText)[i]); // Insert the real key into the buffer - TEKey('¥', ((DialogPeek)dlog)->textH); - } - } - // add scrap to textedit view - DisposeHandle(hText); - event->what = nullEvent; - } - } - } else { - InsertChar(buffer,start,key); // Insert the real key into the buffer - event->message = '¥'; // Character to use in field - } - } - - return false; // Let ModalDialog insert the fake char -} - -static void -DeleteRange(char *buffer,short start,short end) -{ register char *src,*dest,*last; - - last = buffer + *buffer; - - src = buffer + end + 1; - dest = buffer + start + 1; - - while (src <= last) // Shift character to the left over the removed characters - *(dest++) = *(src++); - - (*buffer) -= (end-start); // Adjust the buffer's length -} - -static void -InsertChar(char *buffer,short pos,char c) -{ register short index,len; - - len = *buffer; - - if (len == 0xFF) // if the string is full, return - return; - - for (index = len;index > pos;index--) // Shift characters to the right to make room - buffer[index+1] = buffer[index]; - - buffer[pos+1] = c; // Fill in the new character - - (*buffer)++; // Add one to the length of the string -} - -OSErr -GetScrapHandle( FlavorType dataFlavor, Handle *dataHandle ) -{ - SInt32 scrapOffset; - SInt32 scrapResult; - OSErr err; - - *dataHandle = NewHandle(0); - - // allocate a temporary handle - if ( ( err = MemError() ) != noErr ) - { - goto cleanup; - } - - // look for an item with the specified flavor on the desk scrap - if ( ( scrapResult = GetScrap( *dataHandle, dataFlavor, &scrapOffset ) ) < 0 ) - { - // a negative result from GetScrap is an error code - err = scrapResult; - DisposeHandle( *dataHandle ); - goto cleanup; - } - - // clear result code - err = noErr; - -cleanup: - // return result code - return err; -} - diff --git a/lsh/MacOS/src/PasswordDialog.h b/lsh/MacOS/src/PasswordDialog.h deleted file mode 100755 index 9a537b8..0000000 --- a/lsh/MacOS/src/PasswordDialog.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - File: Password.h - - Contains: This file contains all the interesting password stuff - - Written by: Tim Dierks - - Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved. - - You may incorporate this Apple sample source code into your program(s) without - restriction. This Apple sample source code has been provided "AS IS" and the - responsibility for its operation is yours. You are not permitted to redistribute - this Apple sample source code as "Apple sample source code" after having made - changes. If you're going to re-distribute the source, we require that you make - it clear in the source that the code was descended from Apple sample source - code, but that you've made changes. - - Change History (most recent first): - 8/9/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 - - -*/ -#include - -#define rInternalBufferDialog 256 -#define rYesNoDialog 257 - -#ifdef __cplusplus -extern "C" { -#endif - -void InternalBufferDialog (StringPtr inprompt, StringPtr outpassword); -Boolean YesNoDialog (StringPtr inprompt); -OSErr GetScrapHandle( FlavorType dataFlavor, Handle *dataHandle ); - -#ifdef __cplusplus -} -#endif - - diff --git a/lsh/MacOS/src/PasswordDialog.rsrc b/lsh/MacOS/src/PasswordDialog.rsrc deleted file mode 100755 index f3c4d7a..0000000 Binary files a/lsh/MacOS/src/PasswordDialog.rsrc and /dev/null differ diff --git a/lsh/MacOS/src/SIOUX.c b/lsh/MacOS/src/SIOUX.c deleted file mode 100755 index 98e5e33..0000000 --- a/lsh/MacOS/src/SIOUX.c +++ /dev/null @@ -1,2365 +0,0 @@ -/* Metrowerks Standard Library */ - -/* $Date$ - * $Revision$ - * $NoKeywords: $ - * - * Copyright © 1995-2000 Metrowerks, Inc. - * All rights reserved. - */ - -/*******************************************************************************/ -/* Project...: C++ and ANSI-C Compiler Environment ********/ -/* Name......: SIOUX.c ********/ -/* Purpose...: Interface functions to SIOUX ********/ -/*******************************************************************************/ -/* -*/ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include - -#include "SIOUXGlobals.h" -#include "SIOUXMenus.h" -#include "SIOUXWindows.h" - -#if SIOUX_USE_WASTE - #include "LongControls.h" /* ¥¥¥LC */ -#endif /* SIOUX_USE_WASTE */ - -#include -#include -#include -#include -/*#include */ - -#include -#include -#include -#include /*bkoz*/ -#include /* mm 971006 */ -#include -#include -#include -#include - - -/* defined in unix.c ...*/ -#ifdef __cplusplus -extern "C" { -#endif - -#if ! __MSL__ - extern char __system7present; - extern void __CheckForSystem7(void); - extern void (*__RemoveConsoleHandler__)(void); -#else - int __system7present(void); -#endif /* ! __MSL__ */ - -/*extern long __myraise(long signal); now an inline */ - __inline long __myraise(long _a) {return (__std(raise)(_a));} - - extern void GUSIWakeupSIOUXSocket(); - - extern void sched_yield(); - -#ifdef __cplusplus -} -#endif - -/* Local Defines*/ -//#define SIOUX_BUFSIZ 512U /* SIOUX's internal buffer size ...*/ -#define SIOUX_BUFSIZ 2048U /* SIOUX's internal buffer size ...*/ -#define TICK_DELTA 30UL /* Max ticks allowed between tests for UserBreak()*/ -/*#define EOF (-1L) /* End Of File marker */ - -/* Local Globals */ -static Boolean toolBoxDone = false; /* set to true when the TB is setup */ -static unsigned long LastTick = 0UL; /* The tickcount of the last UserBreak test ...*/ -static short inputBuffersize = 0; /* Used by GetCharsFromSIOUX and DoOneEvent ...*/ -static CursHandle iBeamCursorH = NULL; /* Contains the iBeamCursor ... */ -/*static Boolean atEOF = false;*/ /* Is the stream at EOF? */ -Boolean atEOF = false; /* Is the stream at EOF? */ -Boolean gSIOUXTerminalMode = false; - -char gSIOUXChars[SIOUX_BUFSIZ]; -const short gSIOUXMaxSize = SIOUX_BUFSIZ; -short gSIOUXBufSize = 0; - -typedef struct tSIOUXBuffer -{ - char *startpos, /* pointer to a block of memory which will serve as the buffer */ - *curpos, /* pointer to insertion point in the buffer */ - *endpos; /* pointer to end of text in the buffer */ - long tepos; /* current offset in TEHandle (0 if at end) */ -} tSIOUXBuffer; -static tSIOUXBuffer SIOUXBuffer; - -#define ZEROSIOUXBUFFER() { \ - SIOUXBuffer.curpos = \ - SIOUXBuffer.endpos = \ - SIOUXBuffer.startpos; \ - } - /* SIOUXBuffer.tepos = -1; \ mm 971229 */ -#define CURRENTBUFSIZE() (SIOUXBuffer.endpos - SIOUXBuffer.startpos) -#define CHECKFOROVERFLOW(c) { \ - if (CURRENTBUFSIZE() + (c) >= SIOUX_BUFSIZ) \ - InsertSIOUXBuffer(); \ - } -#define DELETEFROMBUFFER(num) { \ - if (SIOUXBuffer.curpos != SIOUXBuffer.endpos) \ - BlockMoveData(SIOUXBuffer.curpos, \ - SIOUXBuffer.curpos - (num), \ - SIOUXBuffer.endpos - SIOUXBuffer.curpos); \ - SIOUXBuffer.endpos -= (num); \ - SIOUXBuffer.curpos -= (num); \ - } -/* mm 970626 begin */ -#define ROLLBACKBUFFER(num) { \ - SIOUXBuffer.curpos = SIOUXBuffer.endpos - (num); \ - SIOUXBuffer.endpos = SIOUXBuffer.curpos; \ - } -/* mm 970626 end */ -#if SIOUX_USE_WASTE -#define INSERTCHAR(c) { \ - if (SIOUXBuffer.tepos == -1) { \ - *SIOUXBuffer.curpos = (c); \ - if (SIOUXBuffer.curpos == SIOUXBuffer.endpos) \ - SIOUXBuffer.endpos++; \ - SIOUXBuffer.curpos++; \ - } else { \ - WEReference theTEH = SIOUXTextWindow->edit; \ - WESetSelection(SIOUXBuffer.tepos, \ - SIOUXBuffer.tepos + 1, \ - theTEH); \ - WEKey(c, nil, theTEH); \ - SIOUXBuffer.tepos++; \ - if (SIOUXBuffer.tepos == WEGetTextLength(theTEH )) \ - SIOUXBuffer.tepos = -1; \ - } \ - } - /*if (SIOUXBuffer.tepos == WEGetTextLength( theTEH ) - 1) \ mm 971229 */ -#else -#define INSERTCHAR(c) { \ - if (SIOUXBuffer.tepos == -1) { \ - *SIOUXBuffer.curpos = (c); \ - if (SIOUXBuffer.curpos == SIOUXBuffer.endpos) \ - SIOUXBuffer.endpos++; \ - SIOUXBuffer.curpos++; \ - } else { \ - TEHandle theTEH = SIOUXTextWindow->edit; \ - TESetSelect(SIOUXBuffer.tepos, \ - SIOUXBuffer.tepos + 1, \ - theTEH); \ - TEKey(c, theTEH); \ - SIOUXBuffer.tepos++; \ - if (SIOUXBuffer.tepos == (*theTEH)->teLength) \ - SIOUXBuffer.tepos = -1; \ - } \ - } - /* if (SIOUXBuffer.tepos == (*theTEH)->teLength - 1) \ mm 971229 */ -#endif /* SIOUX_USE_WASTE */ -#define INSERTLINEFEED() { \ - *SIOUXBuffer.curpos = 0x0d; \ - SIOUXBuffer.curpos++; \ - SIOUXBuffer.endpos = SIOUXBuffer.curpos; \ - SIOUXBuffer.tepos = -1; \ - } - -/************************************************************************/ -/* Purpose..: Setup the toolbox */ -/* Input....: --- */ -/* Returns..: --- */ -/************************************************************************/ -static void DoSetupToolbox(void) -{ -#if TARGET_API_MAC_OS8 - /* Initialize the ToolBox (not necessary with Carbon)...*/ - InitGraf(&qd.thePort); - InitFonts(); - InitWindows(); - InitMenus(); - TEInit(); - InitDialogs(0L); - FlushEvents(everyEvent, 0L); - - MaxApplZone(); -#endif /* TARGET_API_MAC_OS8 */ - MoreMasters(); - - InitCursor(); - toolBoxDone = true; -} - -#if SIOUX_USE_WASTE -static pascal void ScrollProc ( WEReference /*edit*/ ) -{ - SIOUXUpdateScrollbar ( ) ; -} -#endif - -/************************************************************************/ -/* Purpose..: Initialize the SIOUX textWindow */ -/* Input....: Number of columns */ -/* Input....: Number of rows */ -/* Returns..: TRUE the window was initialized */ -/************************************************************************/ -Boolean SIOUXSetupTextWindow(void) -{ - Rect aRect = {0,0,1,1}; - FontInfo fi; - -#if SIOUX_USE_WASTE - static WEScrollUPP scrollProc = nil ; - LongRect tempLongRect; - long lineHeight, screenHeight, screenWidth; - UInt32 weFeatures;/*SInt32 response; */ /* ¥¥¥MP */ -#else - short lineHeight, screenHeight, screenWidth; -#endif /* SIOUX_USE_WASTE */ - - ProcessSerialNumber psn; - ProcessInfoRec pinfo; - OSErr err; - Str63 AppName = "\p"; - FSSpec spec; - GrafPtr saveport; -#if TARGET_API_MAC_CARBON - BitMap screenBitMap; - Rect screenBits; - GetQDGlobalsScreenBits(&screenBitMap); - screenBits = screenBitMap.bounds; -#else - Rect screenBits = qd.screenBits.bounds; -#endif /* TARGET_API_MAC_CARBON */ - - /* Get process Info*/ - - GetPort(&saveport); - -#if ! __MSL__ - if (__system7present == -1) - __CheckForSystem7(); - - if (__system7present) -#else - if (__system7present()) -#endif /* __MSL__ */ - { - err = GetCurrentProcess(&psn); - pinfo.processName = AppName; - pinfo.processInfoLength = sizeof(pinfo); - pinfo.processAppSpec = &spec; - err = GetProcessInformation(&psn,&pinfo); - - if (spec.name[0] <= 59) { - spec.name[++(spec.name[0])] = '.'; - spec.name[++(spec.name[0])] = 'o'; - spec.name[++(spec.name[0])] = 'u'; - spec.name[++(spec.name[0])] = 't'; - } - if (SIOUXSettings.userwindowtitle != NULL) /* mm 980609 */ - BlockMoveData(SIOUXSettings.userwindowtitle, spec.name, - (long)SIOUXSettings.userwindowtitle[0]+1); - - } - - if (*AppName == 0) - BlockMoveData("\pSIOUX TextWindow", AppName, 17L); - - /* Initialize the TextWindPtr ...*/ - SIOUXTextWindow = (pSIOUXWin)NewPtr(sizeof(tSIOUXWin)); - if (SIOUXTextWindow == 0) - return false; -/* SIOUXTextWindow = &SIOUXTextWindowBuf*/ - - /* jd 980923 */ - SIOUXTextWindow->window = NewWindow(NULL, - &aRect, - spec.name, - false, - documentProc, - (WindowPtr)-1L, - false, - 0L); - if ( SIOUXTextWindow->window == NULL ) { - return (false); - } - - SetPortWindowPort(SIOUXTextWindow->window); /* ra 990612 UI 3.2 */ - - /* Set the font information ...*/ - TextFont(SIOUXSettings.fontid); - TextSize(SIOUXSettings.fontsize); - TextFace(SIOUXSettings.fontface); - GetFontInfo(&fi); - lineHeight = fi.ascent + fi.descent + fi.leading; - - /* Size the window ...*/ - SIOUXSettings.columns = (SIOUXSettings.columns <= 0) ? 80 : SIOUXSettings.columns; - SIOUXSettings.rows = (SIOUXSettings.rows <= 0) ? 24 : SIOUXSettings.rows; - if (SIOUXSettings.showstatusline) - aRect.bottom = 2*4 + (SIOUXSettings.rows + 1)*lineHeight + 4; /* 2*indent + ... + titlebar*/ - else - aRect.bottom = 2*4 + (SIOUXSettings.rows)*lineHeight + 4; /* 2*indent + ... + titlebar*/ - aRect.right = 2*4 + SIOUXSettings.columns*CharWidth('0') + 16, /* 2*indent + ... + scrollbar*/ - -#if TARGET_API_MAC_CARBON - screenHeight = screenBits.bottom - screenBits.top - GetMBarHeight() - 24; /* screen height ...*/ - screenWidth = screenBits.right - screenBits.left; -#else - screenHeight = screenBits.bottom - screenBits.top - LMGetMBarHeight() - 24; /* screen height ...*/ - screenWidth = screenBits.right - screenBits.left; -#endif /* TARGET_API_MAC_CARBON */ - - if (aRect.bottom > screenHeight) - aRect.bottom = ((screenHeight - 2*4 - 4) / lineHeight) * lineHeight + 2*4 + 4; - - /* Move the window to the correct place ...*/ - if (SIOUXSettings.toppixel == 0 && SIOUXSettings.leftpixel == 0) { - if (aRect.right > screenWidth) /* The window is wider than the screen*/ - aRect.right = ((screenWidth - 2*4 - 16 - 20) / CharWidth('0')) * CharWidth('0') + 2*4 + 16; - - #if TARGET_API_MAC_CARBON - MoveWindow (SIOUXTextWindow->window, - ((screenBits.right - screenBits.left - aRect.right) / 2), - ((screenHeight - aRect.bottom) / 5 + GetMBarHeight() + 24), - false); - #else - MoveWindow (SIOUXTextWindow->window, - ((screenBits.right - screenBits.left - aRect.right) / 2), - ((screenHeight - aRect.bottom) / 5 + LMGetMBarHeight() + 24), - false); - #endif /* TARGET_API_MAC_CARBON */ - } else - MoveWindow (SIOUXTextWindow->window, - SIOUXSettings.leftpixel, SIOUXSettings.toppixel, - false); - /* Now make it the correct size ...*/ - SizeWindow(SIOUXTextWindow->window, aRect.right, aRect.bottom, true); - - /* Create the vertical scrollbar ...*/ -#if TARGET_API_MAC_CARBON - GetWindowPortBounds(SIOUXTextWindow->window, &aRect); -#else - aRect = SIOUXTextWindow->window->portRect; -#endif /* TARGET_API_MAC_CARBON */ - aRect.left = aRect.right - 15; - aRect.right += 1; - aRect.bottom -= 14; - aRect.top -= 1; - if (SIOUXSettings.showstatusline) - aRect.top += lineHeight + 4; /* factor in the status window ...*/ - - SIOUXTextWindow->vscroll = NewControl(SIOUXTextWindow->window, &aRect, "\p", - true, 0, 0, 0, scrollBarProc, 0L); - -#if SIOUX_USE_WASTE /* ¥¥¥LC */ - /* Attach a LongControls record to the scrollbar */ - err = LCAttach(SIOUXTextWindow->vscroll); /* what do I do with the error code? */ -#endif - - ShowWindow(SIOUXTextWindow->window); - - /* Create the TEHandle ...*/ -#if TARGET_API_MAC_CARBON - GetPortBounds(GetQDGlobalsThePort(),&aRect); -#else - aRect = qd.thePort->portRect; -#endif /* TARGET_API_MAC_CARBON */ - aRect.right -= 15; - if (SIOUXSettings.showstatusline) - aRect.top += lineHeight + 4; - InsetRect(&aRect, 4, 4); - -#if SIOUX_USE_WASTE - WERectToLongRect( &aRect, &tempLongRect ); - weFeatures = ( weDoAutoScroll | weDoDrawOffscreen | weDoMonoStyled ); - if ( SIOUXSettings.wasteusetempmemory ) - weFeatures |= weDoUseTempMem; - if ( SIOUXSettings.enabledraganddrop ) - weFeatures |= ( weDoDragAndDrop | weDoOutlineHilite ); - if ( SIOUXSettings.outlinehilite ) - weFeatures |= weDoOutlineHilite; - err = WENew(&tempLongRect, &tempLongRect, weFeatures, &SIOUXTextWindow->edit); - - /* install the scroll callback */ - if ( scrollProc == nil ) - { - scrollProc = NewWEScrollUPP( ScrollProc ); /* RA/1/9/99 NewWEScrollProc */ - } - err = WESetInfo( weScrollProc, & scrollProc, SIOUXTextWindow->edit ); - -#else - SIOUXTextWindow->edit = TENew(&aRect, &aRect); - - TEAutoView(true, SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - - SIOUXTextWindow->linesInFolder = SIOUXSettings.rows; /* Number of lines visible ...*/ - SIOUXTextWindow->dirty = 0; /* Window is clean ...*/ - SIOUXTextWindow->dirid = 0; /* Window hasn't been saved yet ...*/ - - SIOUXUpdateWindow(SIOUXTextWindow->window); - - SetPort(saveport); - return(true); -} - -/************************************************************************/ -/* Purpose..: Determines value of current top line */ -/* Input....: TextEdit Handle */ -/* Return...: Position on current line */ -/************************************************************************/ -static long CurrentTopLine( -#if SIOUX_USE_WASTE - WEReference theTEH -#else - TEHandle theTEH -#endif /* SIOUX_USE_WASTE */ -) -{ -#if SIOUX_USE_WASTE - long topLineNumber; - long height; - - LongRect weViewRect, weDestRect; - WEGetViewRect( &weViewRect, theTEH ); - WEGetDestRect( &weDestRect, theTEH ); - - height = WEGetHeight( 0, 1, theTEH ); - topLineNumber = (weViewRect.top - weDestRect.top) / - WEGetHeight( 0, 1, theTEH ); -#else - short topLineNumber; - topLineNumber = ((*theTEH)->viewRect.top - (*theTEH)->destRect.top) / - ((*theTEH)->lineHeight); -#endif /* SIOUX_USE_WASTE */ - return topLineNumber; -} - -/************************************************************************/ -/* Purpose..: Determines position on current line (in chars) */ -/* Input....: TextEdit Handle */ -/* Return...: Position on current line */ -/************************************************************************/ -static long OffsetOnCurrentLine( -#if SIOUX_USE_WASTE - WEReference theTEH, -#else - TEHandle theTEH, -#endif /* SIOUX_USE_WASTE */ - Boolean buf -) -{ - char *ptr, *start; - long result; -#if SIOUX_USE_WASTE - long i, lastCharIndex; - SInt32 weSelStart, weSelEnd; -#endif /* SIOUX_USE_WASTE */ - - /* Check for a CR in the buffer ...*/ - if (buf && SIOUXBuffer.endpos != SIOUXBuffer.startpos) - { - for (start = SIOUXBuffer.startpos, ptr = SIOUXBuffer.endpos; ptr > start; ptr--) - /*if (*ptr == 0x0d) return (SIOUXBuffer.endpos - ptr - 1); /*mm 970903*/ - if (ptr[-1] == 0x0d) /*mm 980112 */ - return (SIOUXBuffer.endpos - ptr); /*mm 980112*/ - } - -#if SIOUX_USE_WASTE - WEGetSelection( &weSelStart, &weSelEnd, theTEH ); - - lastCharIndex = WEGetTextLength( theTEH ) - 1; - i = 0; - /*while ( ( lastCharIndex > weSelStart ) && WEGetChar( lastCharIndex - i, theTEH ) != 0x0d ) mm 971230 */ - while ( ( lastCharIndex >= i ) && WEGetChar( lastCharIndex - i, theTEH ) != 0x0d ) /* mm 971230 */ - /*i--;*/ /* mm 971230 */ - i++; /* mm 971230 */ - - /*result = weSelStart - i + ( SIOUXBuffer.endpos - SIOUXBuffer.startpos );*/ /* mm 971230 */ - result = i + ( SIOUXBuffer.endpos - SIOUXBuffer.startpos); /* mm 971230 */ -#else - HLock((Handle)theTEH); - HLock((*theTEH)->hText); - - start = *(*theTEH)->hText; - ptr = *(*theTEH)->hText + (*theTEH)->selStart; - while (ptr > start && ptr[-1] != 0x0d) - ptr--; - - result = *(*theTEH)->hText + (*theTEH)->selStart - ptr + SIOUXBuffer.endpos - SIOUXBuffer.startpos; - - HUnlock((*theTEH)->hText); - HUnlock((Handle)theTEH); -#endif /* SIOUX_USE_WASTE */ - - return result; -} - -/************************************************************************/ -/* Purpose..: Handle a mouseDown event */ -/* Input....: pointer to an Event */ -/* Return...: true/false */ -/************************************************************************/ -static Boolean HandleMouseDownEvent(EventRecord *theEvent) -{ - WindowPtr window; - short part; - Boolean isSIOUXwindow; -/* Point theWhere; */ - - part = FindWindow(theEvent->where, &window); - isSIOUXwindow = SIOUXIsAppWindow(window); - - switch (part) - { - case inMenuBar: - if (SIOUXSettings.setupmenus) - { - SIOUXUpdateMenuItems(); - /* jd 980923 - should update this to MenuEvent?? */ - SIOUXDoMenuChoice(MenuSelect(theEvent->where)); - return true; - } - break; - - #if TARGET_API_MAC_OS8 /*instead of !TARGET_API_MAC_CARBON*/ /* cc 991111 */ - case inSysWindow: - if (SIOUXSettings.standalone) - SystemClick(theEvent, window); - break; - #endif /* cc 991111 */ - - case inContent: - /* mm 980605a - ** SIOUX should only select windows that it knows about so - ** that the app embedding a SIOUx window can decide whether or - ** not to select the window. - */ - if (isSIOUXwindow) - { - - if (window != FrontWindow()) - SelectWindow(window); - else - { - if (SIOUXState == PRINTFING) - { - if (StillDown()) - { - while (WaitMouseUp()) - ; /* Pause output while mouse is down ...*/ - } - } else - SIOUXDoContentClick(window, theEvent); - } - - return true; - } - break; - - case inDrag: - /* mm 980605b - ** SIOUX should select its window when the user clicks in - ** the drag region if it's not the FrontWindow. - */ - if (isSIOUXwindow) - { - if (window != FrontWindow()) - SelectWindow(window); - else - DragWindow(window, theEvent->where, &SIOUXBigRect); - return true; - } - break; - - case inGrow: - /* mm 980605b - ** SIOUX should select its window when the user clicks in - ** the grow region if it's not the FrontWindow. - */ - if (isSIOUXwindow) - { - if (window != FrontWindow()) - SelectWindow(window); - else - SIOUXMyGrowWindow(window, theEvent->where); - return true; - } - break; - } - - return false; -} - -/************************************************************************/ -/* Purpose..: Handle update and activate/deactivate events */ -/* Input....: pointer to an Event */ -/* Return...: true/false */ -/************************************************************************/ -static Boolean HandleUpdateActivateEvent(EventRecord *theEvent) -{ - if (SIOUXIsAppWindow((WindowPtr)theEvent->message)) - { - if (theEvent->what == updateEvt) - SIOUXUpdateWindow((WindowPtr)theEvent->message); - else - { /* must be an activate/deactivate event */ - if (theEvent->modifiers & activeFlag) - { -#if SIOUX_USE_WASTE - WEActivate(SIOUXTextWindow->edit); -#else - TEActivate(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - ShowControl(SIOUXTextWindow->vscroll); - } - else - { -#if SIOUX_USE_WASTE - WEDeactivate(SIOUXTextWindow->edit); -#else - TEDeactivate(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - HideControl(SIOUXTextWindow->vscroll); - } - SIOUXDrawGrowBox(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - SIOUXUpdateStatusLine(SIOUXTextWindow->window); - } - return true; - } - - return false; -} - -/************************************************************************/ -/* Purpose..: Handle update and activate/deactivate events */ -/* Input....: pointer to an Event */ -/* Return...: true/false */ -/************************************************************************/ -static Boolean HandleOSEvents(EventRecord *theEvent) -{ - switch ((theEvent->message >> 24) & 0xff) - { - case resumeFlag: - if (theEvent->message & suspendResumeMessage) - { -#if SIOUX_USE_WASTE - WEActivate(SIOUXTextWindow->edit); -#else - TEActivate(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - ShowControl(SIOUXTextWindow->vscroll); - } - else - { -#if SIOUX_USE_WASTE - WEDeactivate(SIOUXTextWindow->edit); -#else - TEDeactivate(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - HideControl(SIOUXTextWindow->vscroll); - } - SIOUXDrawGrowBox(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - SIOUXUpdateStatusLine(SIOUXTextWindow->window); - return(true); - - default: - return(false); - } -} - -/************************************************************************/ -/* Purpose..: Detect a user break (Command-'.') */ -/* Input....: pointers an size of block */ -/* Return...: true/false */ -/************************************************************************/ -static void UserBreak(void) -{ - EventRecord ev; - - if (TickCount() - LastTick < TICK_DELTA) - return; - - LastTick = TickCount(); - - if (SIOUXUseWaitNextEvent) - WaitNextEvent(everyEvent, &ev, GetCaretTime(), NULL); - else - { - #if TARGET_API_MAC_OS8 /*instead of !TARGET_API_MAC_CARBON*/ /* cc 991111 */ - /* Keep the system happy ...*/ - SystemTask(); - #endif /* cc 991111 */ - - GetNextEvent(everyEvent, &ev); - } - - switch (ev.what) - { - case nullEvent: /* ignore it ...*/ - break; - - case keyDown: - case autoKey: /* check for break ...*/ - if (ev.modifiers & cmdKey) - { - if ((ev.message & charCodeMask) == '.') - __myraise(SIGINT); - if ((ev.message & charCodeMask) == 'q' || (ev.message & charCodeMask) == 'Q') { - SIOUXQuitting = true; - __myraise(SIGINT); - } - } - if ((ev.message & charCodeMask) == 0x03 && (ev.message & keyCodeMask) >> 8 != 0x4c) - __myraise(SIGINT); /* enter and control c have same char code*/ - break; - - case mouseDown: - HandleMouseDownEvent(&ev); - break; - - case activateEvt: - case updateEvt: - HandleUpdateActivateEvent(&ev); - break; - - case osEvt: - HandleOSEvents(&ev); - break; - - case kHighLevelEvent: -#if ! __MSL__ - if (__system7present == -1) - __CheckForSystem7(); - - if (__system7present) -#else - if (__system7present()) -#endif /* ! __MSL__ */ - { - AEProcessAppleEvent(&ev); - } - break; - - #if TARGET_API_MAC_OS8 /*instead of !TARGET_API_MAC_CARBON*/ /* cc 991111 */ - case diskEvt: - if (HiWord(ev.message) != noErr) { - Point pt = {100, 100}; - DIBadMount(pt, ev.message); - } - break; - #endif /* cc 991111 */ - - case mouseUp: - case keyUp: - default: - break; - } -} - -/************************************************************************/ -/* Purpose..: Insert the current SIOUX buffer into the TE Handle */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static void InsertSIOUXBuffer(void) -{ -#if SIOUX_USE_WASTE - WEReference theTEH = SIOUXTextWindow->edit; - long teLength; - -/* the following variables were used for the aborted error-handling code found later in this function --pcg */ -/* long weToDelete; - SInt16 autoScrollFlag; -*/ - teLength = WEGetTextLength( theTEH ); -#else - TEHandle theTEH = SIOUXTextWindow->edit; - short teLength; - - HLock((Handle)theTEH); - teLength = (*theTEH)->teLength; -#endif /* SIOUX_USE_WASTE */ - -#if ! SIOUX_USE_WASTE - /* this isn't necessary w/ WASTE -pcg */ - if ((teLength + CURRENTBUFSIZE()) > 32767) - { - /* Insert will grow TEHandle past 32K so we cut out excess from top ...*/ - char *ptr; - short todelete = (short) ((teLength + CURRENTBUFSIZE()) - 32767) + 8*SIOUX_BUFSIZ; - - /* Make sure that the text to be cut ends on a CR ...*/ - HLock((*theTEH)->hText); - for (ptr = *(*theTEH)->hText + todelete; *ptr != 0x0d; ptr++) ; - - /* We now point at the CR, increment ptr to point after it ...*/ - todelete += ++ptr - (*(*theTEH)->hText + todelete); - HUnlock((*theTEH)->hText); - - /* We hit the fields directly to keep TE from redrawing twice*/ - (*theTEH)->selStart = 0; - (*theTEH)->selEnd = todelete; - TEDelete(theTEH); - - /* Now fix things up...*/ - teLength = (*theTEH)->teLength; - } -#endif /* ! SIOUX_USE_WASTE */ - - /* Now insert the new text ...*/ -#if SIOUX_USE_WASTE - /* aborted code to handle WASTE buffer size limiting. I'll leave it here - for future generations to try their hand at. --pcg */ -/* if ( SIOUXSettings.wastemaxbuffersize > 0 ) - { - if ( teLength + CURRENTBUFSIZE() > SIOUXSettings.wastemaxbuffersize ) - { - autoScrollFlag = WEFeatureFlag( weFAutoScroll, weBitTest, theTEH ); - weToDelete = CURRENTBUFSIZE(); - while ( ( weToDelete < teLength ) && ( WEGetChar( weToDelete, theTEH ) != 0x0d ) ) - weToDelete++; - WEFeatureFlag( weFAutoScroll, weBitClear, theTEH ); - WESetSelection( 0, weToDelete + 1, theTEH ); - WEDelete( theTEH ); - SIOUXUpdateScrollbar(); - LCSetValue( SIOUXTextWindow->vscroll, */ /*¥¥¥LC */ -/* LCGetMax( SIOUXTextWindow->vscroll ) ); */ /*¥¥¥LC */ -/* AdjustText(); - WEFeatureFlag( weFAutoScroll, autoScrollFlag, theTEH ); - - teLength = WEGetTextLength( theTEH ); - } - } -*/ - if (!gSIOUXTerminalMode) - WESetSelection( teLength, teLength, theTEH ); - else { - // need to replace current line if it's not empty - SInt32 weSelStart, weSelEnd; - int i; - WEGetSelection( &weSelStart, &weSelEnd, theTEH ); - i = weSelStart; - while ( i < teLength - && i - weSelStart < CURRENTBUFSIZE() - && WEGetChar( i, theTEH ) != 0x0d ) - ++i; - weSelEnd = i; - WESetSelection( weSelStart, weSelEnd, theTEH ); - } - WEInsert(SIOUXBuffer.startpos, CURRENTBUFSIZE(), nil, nil, theTEH); - - teLength = WEGetTextLength( theTEH ); -#else - if (!gSIOUXTerminalMode) - TESetSelect(teLength, teLength, theTEH); - TEInsert(SIOUXBuffer.startpos, CURRENTBUFSIZE(), theTEH); - teLength = (*theTEH)->teLength; -#endif /* SIOUX_USE_WASTE */ - - SIOUXTextWindow->dirty = true; - ZEROSIOUXBUFFER(); - -#if SIOUX_USE_WASTE - if (!gSIOUXTerminalMode) - WESetSelection(teLength, teLength, theTEH); -#else - if (!gSIOUXTerminalMode) - TESetSelect(teLength, teLength, theTEH); - - HUnlock((Handle)theTEH); -#endif /* SIOUX_USE_WASTE */ - - if (SIOUXSettings.standalone) - UserBreak(); - else - SIOUXUpdateScrollbar(); -} - -/************************************************************************/ -/* Purpose..: Determine the user's theoretical menuchoice */ -/* Input....: Character typed */ -/* Return...: Menuchoice */ -/************************************************************************/ -static long myMenuKey(char key) -{ - short theMenu = 0; - short theMenuItem = 0; - - switch (key) - { - /* File menu choices*/ - case 's': case 'S': - theMenu = FILEID; - theMenuItem = FILESAVE; - break; - - case 'p': case 'P': - theMenu = FILEID; - theMenuItem = FILEPRINT; - break; - - case 'q': case 'Q': - theMenu = FILEID; - theMenuItem = FILEQUIT; - break; - - case 'x': case 'X': - theMenu = EDITID; - theMenuItem = EDITCUT; - break; - - case 'c': case 'C': - theMenu = EDITID; - theMenuItem = EDITCOPY; - break; - - case 'v': case 'V': - theMenu = EDITID; - theMenuItem = EDITPASTE; - break; - - case 'a': case 'A': - theMenu = EDITID; - theMenuItem = EDITSELECTALL; - break; - } - - return (((long)theMenu << 16) | theMenuItem); -} - -/************************************************************************/ -/* Purpose..: Check if insertion range is in edit range */ -/* Input....: first character in edit range */ -/* Input....: Handle to textedit */ -/* Return...: true/false */ -/************************************************************************/ -Boolean SIOUXisinrange( -#if SIOUX_USE_WASTE - long first, WEReference te -#else - short first, TEHandle te -#endif /* SIOUX_USE_WASTE */ -) -{ -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd; - - WEGetSelection( &weSelStart, &weSelEnd, te ); - if (!gSIOUXTerminalMode && ((weSelStart < first) || (weSelEnd < first) )) -#else - if (!gSIOUXTerminalMode && (((*te)->selStart < first) || (*te)->selEnd < first)) -#endif /* SIOUX_USE_WASTE */ - { - SysBeep(10); - return false; - } else - return true; -} - -/************************************************************************/ -/* Purpose..: Handles a single event ... */ -/* Input....: If non-zero then pointer to an event */ -/* Returns..: --- */ -/************************************************************************/ -short SIOUXHandleOneEvent(EventRecord *userevent) -{ - EventRecord theEvent; - WindowPtr window; - char aChar; -#if SIOUX_USE_WASTE - LongRect weViewRect; - long scrollAdjust, directionMultiplier; -#else - short scrollAdjust, directionMultiplier; -#endif /* SIOUX_USE_WASTE */ - - if (SIOUXState == OFF) - return false; - - if (userevent) /* External call of the function ...*/ - theEvent = *userevent; - else if (SIOUXUseWaitNextEvent) /* Internal with WNE allowed ...*/ - WaitNextEvent(everyEvent, &theEvent, GetCaretTime(), NULL); - else - { /* Internal with no WNE allowed ...*/ - #if TARGET_API_MAC_OS8 /*instead of !TARGET_API_MAC_CARBON*/ /*cc 991111 */ - SystemTask(); - #endif /*cc 991111 */ - - GetNextEvent(everyEvent, &theEvent); - } - - window = FrontWindow(); - - switch (theEvent.what) - { - case nullEvent: - /* Maintain the cursor*/ - if (SIOUXIsAppWindow(window)) - { - GrafPtr savePort;Point localMouse; /* ¥¥¥MP */ -#if SIOUX_USE_WASTE - Rect tempRect; - LongRect weViewRect; -#endif /* SIOUX_USE_WASTE */ - - GetPort(&savePort); - SetPortWindowPort(window); /* ra 990612 UI 3.2 */ - localMouse = theEvent.where;GlobalToLocal(&localMouse); /* ¥¥¥MP */ -#if SIOUX_USE_WASTE - WEGetViewRect( &weViewRect, SIOUXTextWindow->edit ); - WELongRectToRect( &weViewRect, &tempRect ); - if (PtInRect(localMouse, &tempRect) && iBeamCursorH ) /* ¥¥¥MP */ -#else - if (PtInRect(localMouse, &(*SIOUXTextWindow->edit)->viewRect) && /* ¥¥¥MP */ - iBeamCursorH) -#endif /* SIOUX_USE_WASTE */ - { -#if SIOUX_USE_WASTE - WEAdjustCursor( theEvent.where, nil, SIOUXTextWindow->edit ); -#else - SetCursor(*iBeamCursorH); -#endif /* SIOUX_USE_WASTE */ - } - else - { - #if TARGET_API_MAC_CARBON - Cursor theArrow; - SetCursor(GetQDGlobalsArrow(&theArrow)); - #else - SetCursor(&qd.arrow); - #endif /* TARGET_API_MAC_CARBON */ - } - /*LocalToGlobal(&theEvent.where); */ /* ¥¥¥MP */ -#if SIOUX_USE_WASTE - WEAdjustCursor( theEvent.where, nil, SIOUXTextWindow->edit ); - WEIdle( nil, SIOUXTextWindow->edit ); -#else - TEIdle(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - SetPort(savePort); - /* mm 980605c - ** SIOUX should return false so that an app embedding - ** SIOUX that looks at the result of SIOUXHandleOneEvent() - ** will be able to process the NULL event as well. - */ - return false; - } - else - { - if (SIOUXSettings.standalone) /* JWW - only set cursor when standalone */ - { - #if TARGET_API_MAC_CARBON - Cursor theArrow; - SetCursor(GetQDGlobalsArrow(&theArrow)); - #else - SetCursor(&qd.arrow); - #endif /* TARGET_API_MAC_CARBON */ - - if (SIOUXTextWindow != NULL) -#if SIOUX_USE_WASTE - WEIdle( nil, SIOUXTextWindow->edit ); -#else - TEIdle(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } - } - break; - - case mouseDown: - if (HandleMouseDownEvent(&theEvent)) - return true; - break; - - case keyDown: - case autoKey: - if (SIOUXIsAppWindow(window)) { - aChar = (theEvent.message & charCodeMask); - if ((theEvent.modifiers & cmdKey) && (aChar > 0x20)) - { /*¥¥¥MP */ - /* Check first for command - '.'*/ - if (SIOUXState != TERMINATED && aChar == '.') - __myraise(SIGINT); - if (SIOUXSettings.setupmenus) - { - SIOUXUpdateMenuItems(); - SIOUXDoMenuChoice(MenuKey(aChar)); - } - else - SIOUXDoMenuChoice(myMenuKey(aChar)); - return true; - } else { - if (((theEvent.message & keyCodeMask) >> 8 == 0x4c) || /* mm 980413 */ - ((theEvent.message & keyCodeMask) >> 8 == 0x34)) /* mm 980413 */ - aChar = 0x0d; /* map enter key to return key ...*/ - if (SIOUXState == SCANFING) { - /* If there are too many characters on the line already then just return ...*/ -#if SIOUX_USE_WASTE - if (!gSIOUXTerminalMode && (WEGetTextLength( SIOUXTextWindow->edit ) - SIOUXselstart + 1) >= inputBuffersize) -#else - if (!gSIOUXTerminalMode && ((*SIOUXTextWindow->edit)->teLength - SIOUXselstart + 1) >= inputBuffersize) -#endif /* SIOUX_USE_WASTE */ - { - SysBeep(10); - return false; - } - switch (aChar) - { - case 0x1a: /* Control - 'z'*/ - case 0x04: /* Control - 'd'*/ - /* Place in the enter key char which will become the EOF*/ - aChar = 0x03; - case 0x0d: /* Carriage Return*/ - SIOUXState = IDLE; - break; - - case 0x03: /* Control - 'c'*/ - __myraise(SIGINT); - break; - - case 0x08: /* Delete*/ - if (!gSIOUXTerminalMode) { - if (!SIOUXisinrange(SIOUXselstart + 1, SIOUXTextWindow->edit)) - return false; - } - break; - - default: - break; - } - - /* if the cursor is currently outside the typeable region then move it ...*/ - if ((aChar >= ' ') && !SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit)) { -#if SIOUX_USE_WASTE - WESetSelection(WEGetTextLength( SIOUXTextWindow->edit ), - WEGetTextLength( SIOUXTextWindow->edit ), - SIOUXTextWindow->edit); -#else - TESetSelect((*SIOUXTextWindow->edit)->teLength, - (*SIOUXTextWindow->edit)->teLength, - SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } - - } - - directionMultiplier = 1; - switch ( aChar ) - { - case 0x0C: /* pageDown */ - directionMultiplier = -1; - case 0x0B: /* pageUp */ -#if SIOUX_USE_WASTE - WEGetViewRect( &weViewRect, SIOUXTextWindow->edit ); - scrollAdjust = (weViewRect.bottom - weViewRect.top) / - WEGetHeight( 0, 1, SIOUXTextWindow->edit ); -#else - scrollAdjust = ( (*SIOUXTextWindow->edit)->viewRect.bottom - - (*SIOUXTextWindow->edit)->viewRect.top ) / - (*SIOUXTextWindow->edit)->lineHeight; -#endif /* SIOUX_USE_WASTE */ - scrollAdjust *= directionMultiplier; - MoveScrollBox(SIOUXTextWindow->vscroll, scrollAdjust); - AdjustText(); - break; - - case 0x01: /* home */ -#if SIOUX_USE_WASTE - LCSetValue( SIOUXTextWindow->vscroll, /* ¥¥¥LC */ - LCGetMin( SIOUXTextWindow->vscroll ) ); -#else - SetControlValue( SIOUXTextWindow->vscroll, - GetControlMinimum( SIOUXTextWindow->vscroll ) ); -#endif /* SIOUX_USE_WASTE */ - AdjustText(); - break; - - case 0x04: /* end */ -#if SIOUX_USE_WASTE - LCSetValue( SIOUXTextWindow->vscroll, /* ¥¥¥LC */ - LCGetMax( SIOUXTextWindow->vscroll ) ); -#else - SetControlValue( SIOUXTextWindow->vscroll, - GetControlMaximum( SIOUXTextWindow->vscroll ) ); -#endif /* SIOUX_USE_WASTE */ - AdjustText(); - break; - - default: - if ( !gSIOUXTerminalMode ) { -#if SIOUX_USE_WASTE - WEKey(aChar, theEvent.modifiers, SIOUXTextWindow->edit); -#else - TEKey(aChar, SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } else { - gSIOUXChars[gSIOUXBufSize++] = aChar; - GUSIWakeupSIOUXSocket(); - SIOUXState = IDLE; - } - SIOUXUpdateScrollbar(); - if (aChar < 0x1c || aChar > 0x1f) { - SIOUXTextWindow->dirty = true; - } - } - return true; - } - } - break; - - case activateEvt: - case updateEvt: - if (HandleUpdateActivateEvent(&theEvent)) - return true; - break; - - case osEvt: - if (HandleOSEvents(&theEvent)) - /* mm 980605c - ** SIOUX should return false so that an app embedding - ** SIOUX that looks at the result of SIOUXHandleOneEvent() - ** will be able to process the OS event as well. - */ - return false; - break; - - case kHighLevelEvent: -#if ! __MSL__ - if (__system7present == -1) - __CheckForSystem7(); - - if (__system7present) -#else - if (__system7present()) -#endif /* ! __MSL__ */ - { - AEProcessAppleEvent(&theEvent); - } - break; - - #if TARGET_API_MAC_OS8 /*instead of !TARGET_API_MAC_CARBON*/ /*cc 991111 */ - case diskEvt: - if (HiWord(theEvent.message) != noErr) - { - Point pt = {100, 100}; - DIBadMount(pt, theEvent.message); - } - break; - #endif /*cc 991111 */ - - case mouseUp: - case keyUp: - default: - break; - } - return false; -} - -/************************************************************************/ -/* Purpose..: Cleans up the data for a quit ... */ -/* Input....: --- */ -/* Returns..: true killed everything/false user cancelled ... */ -/************************************************************************/ -static Boolean SIOUXCleanUp(void) -{ - short item; - Str255 aString; - - if (SIOUXTextWindow) - { - if (SIOUXTextWindow->dirty && SIOUXSettings.asktosaveonclose) - { - GetWTitle(SIOUXTextWindow->window, aString); /* ra 990612 Use WindowPtr */ - - #if TARGET_API_MAC_CARBON - { - Cursor arrowCursor; - SetCursor(GetQDGlobalsArrow(&arrowCursor)); - } - #else - SetCursor(&qd.arrow); - #endif /* TARGET_API_MAC_CARBON */ - - item = SIOUXYesNoCancelAlert(aString); - - switch (item) - { - case 1: /* Yes*/ - if (SIOUXDoSaveText() != noErr && SIOUXSettings.standalone) - { /* Save the textWindow ...*/ - SIOUXQuitting = false; - return (false); - } - break; - - case 3: /* Cancel*/ - SIOUXQuitting = false; - return (false); - - case 2: /* No*/ - default: /* error*/ - break; - } - } - -#if SIOUX_USE_WASTE /* ¥¥¥LC */ - /* before killing the scrollbar, be sure to dispose of the LongControls record */ - LCDetach(SIOUXTextWindow->vscroll); -#endif /* SIOUX_USE_WASTE */ - - - /* Kill the textWindow ...*/ - KillControls(SIOUXTextWindow->window); -#if SIOUX_USE_WASTE - WEDispose(SIOUXTextWindow->edit); -#else - TEDispose(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - - #if TARGET_API_MAC_OS8 - /* CloseWindow doesn't exist under Carbon since you cannot allocate - your own storage anyways */ - CloseWindow(SIOUXTextWindow->window); - #else - DisposeWindow(SIOUXTextWindow->window); /* jd */ - #endif /* TARGET_API_MAC_OS8 */ - - DisposePtr((Ptr)SIOUXTextWindow); - SIOUXTextWindow = 0L; - ZEROSIOUXBUFFER(); - } - - return (true); -} - -/************************************************************************/ -/* Purpose..: Make sure all required Apple Event parameters are used */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static OSErr GotRequiredParams(const AppleEvent *theEvent) -{ - OSErr theErr; - DescType theType; - Size theSize; - - theErr = AEGetAttributePtr(theEvent, keyMissedKeywordAttr, typeWildCard, &theType, - NULL, 0, &theSize); - - if (theErr == errAEDescNotFound) - theErr = noErr; - else - theErr = errAEParamMissed; - - return theErr; -} - -/************************************************************************/ -/* Purpose..: Handle Apple Event for when application is launched */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static pascal OSErr DoHandleOpenApplication(const AppleEvent *theEvent, AppleEvent *theReply, - UInt32 refCon) -{ -#pragma unused(theReply, refCon) - OSErr theErr; - - theErr = GotRequiredParams(theEvent); - - return theErr; -} - -/************************************************************************/ -/* Purpose..: Process open and print Apple Event */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static OSErr DoHandleOpenPrint(const AppleEvent *theEvent, Boolean isOpen) -{ -#pragma unused(isOpen) - OSErr theErr; - AEDescList theDocuments; - - theErr = AEGetParamDesc(theEvent, keyDirectObject, typeAEList, &theDocuments); - - if (theErr == noErr) - { - theErr = GotRequiredParams(theEvent); - - AEDisposeDesc(&theDocuments); - } - - return theErr; -} - -/************************************************************************/ -/* Purpose..: Handler for Open Document Apple Event */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static pascal OSErr DoHandleOpenDocuments(const AppleEvent *theEvent, AppleEvent *theReply, - UInt32 refCon) -{ -#pragma unused(theReply, refCon) - OSErr theErr; - - theErr = DoHandleOpenPrint(theEvent, true); - - return theErr; -} - -/************************************************************************/ -/* Purpose..: Handler for Print Document Apple Event */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static pascal OSErr DoHandlePrintDocuments(const AppleEvent *theEvent, AppleEvent *theReply, - UInt32 refCon) -{ -#pragma unused(theReply, refCon) - OSErr theErr; - - theErr = DoHandleOpenPrint(theEvent, false); - - return theErr; -} - -/************************************************************************/ -/* Purpose..: Handle Apple Event for quit application requests */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static pascal OSErr DoHandleQuit(const AppleEvent *theEvent, AppleEvent *theReply, - UInt32 refCon) -{ -#pragma unused(theReply, refCon) - OSErr theErr; - - theErr = GotRequiredParams(theEvent); - - if (theErr == noErr) - { - SIOUXQuitting = true; - - if (SIOUXCleanUp() == false) - theErr = userCanceledErr; - } - - return theErr; -} - -/************************************************************************/ -/* Purpose..: Install the console package */ -/* Input....: The stream to install (ignored) */ -/* Returns..: 0 no error / -1 error occurred */ -/************************************************************************/ -short InstallConsole(short fd) -{ - -#pragma unused (fd) - - if (SIOUXQuitting || SIOUXState != OFF) return 0; - - if (SIOUXSettings.initializeTB && !toolBoxDone) - DoSetupToolbox(); - - /* Initialize Space for the SIOUX buffer ...*/ - if ((SIOUXBuffer.startpos = (char *)NewPtr(SIOUX_BUFSIZ)) == NULL) - return -1; - ZEROSIOUXBUFFER(); - SIOUXBuffer.tepos = -1; /* mm 980108 */ - /* Setup the menus ...*/ - if (SIOUXSettings.setupmenus) - SIOUXSetupMenus(); - - /* JWW - Install Apple Event handlers for standalone SIOUX appliation */ - if (SIOUXSettings.standalone == true) - { -#if ! __MSL__ - if (__system7present == -1) - __CheckForSystem7(); - - if (__system7present) -#else - if (__system7present()) -#endif /* ! __MSL__ */ - { - AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, - NewAEEventHandlerProc(&DoHandleOpenApplication), 0, false); - - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, - NewAEEventHandlerProc(&DoHandleOpenDocuments), 0, false); - - AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, - NewAEEventHandlerProc(&DoHandlePrintDocuments), 0, false); - - AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - NewAEEventHandlerProc(&DoHandleQuit), 0, false); - } - } - - /* Setup the textWindow ...*/ - if (SIOUXSetupTextWindow()) - { - if (SIOUXSettings.standalone == false) - { - SIOUXSettings.autocloseonquit = true; - } - - SIOUXState = IDLE; - - /* Test for WaitNextEvent ...*/ - - #if !TARGET_API_MAC_OS8 - SIOUXUseWaitNextEvent = true; - #else - if (GetToolTrapAddress(_WaitNextEvent) != GetToolTrapAddress(_Unimplemented)) - SIOUXUseWaitNextEvent = true; - #endif /* !TARGET_API_MAC_OS8 */ - - iBeamCursorH = GetCursor(iBeamCursor); - - return 0; - } - -#if ! __MSL__ - __RemoveConsoleHandler__ = RemoveConsole; -#endif /* ! __MSL__ */ - - return(-1); -} - -/************************************************************************/ -/* Purpose..: Remove the console package */ -/* Input....: --- */ -/* Returns..: --- */ -/************************************************************************/ -void RemoveConsole(void) -{ - extern int __aborting; - - if (SIOUXState == OFF || !SIOUXTextWindow) - return; - - if (__aborting) - SIOUXState = ABORTED; - else - SIOUXState = TERMINATED; - SIOUXUpdateStatusLine(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - - SIOUXselstart = 0; -#if SIOUX_USE_WASTE - WEActivate(SIOUXTextWindow->edit); -#else - TEActivate(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - SIOUXUpdateScrollbar(); - - if (SIOUXSettings.autocloseonquit) - SIOUXQuitting = true; - - while (!SIOUXQuitting) - { -BackInTheLoop: - SIOUXHandleOneEvent(NULL); - } - - if (!SIOUXCleanUp()) - goto BackInTheLoop; - -#if ! __MSL__ - __RemoveConsoleHandler__ = NULL; -#endif /* ! __MSL__ */ - - SIOUXState = OFF; -} - -/************************************************************************/ -/* Purpose..: Write a string to the console */ -/* Input....: pointer to buffer */ -/* Input....: number of chars in buffer */ -/* Return...: 0 no error / -1 error occurred */ -/************************************************************************/ -long WriteCharsToConsole(char *buffer, long n) -{ - long counter, i, spacestoinsert; - char aChar; - GrafPtr saveport; - static int mode = 1; - static int paramindex; - static const int maxparams = 16; - static int params[maxparams]; - static int tempindex; - static unsigned int attrib = 0; - static int unknown = -1; - char buf[256]; - - if (SIOUXQuitting) - return 0; - - GetPort(&saveport); - SetPortWindowPort(SIOUXTextWindow->window); /* ra 990612 UI 3.2 */ - - /*plnt_dump("WriteCharsToConsole", buffer, n);*/ - - SIOUXState = PRINTFING; - SIOUXUpdateStatusLine(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - - for(counter = n; counter > 0; counter--) - { - aChar = *buffer++; - switch (mode) { - case 1: - switch(aChar) - { - case 0x0d: - #if !__option(mpwc_newline) /* Line Feed (Mac newline)*/ - INSERTLINEFEED(); - break; - - #else /* Carriage Return (move to start of line)*/ - i = OffsetOnCurrentLine(SIOUXTextWindow->edit, 1); - if (i <= CURRENTBUFSIZE()) - { - ROLLBACKBUFFER(i); - } - else - { - SIOUXBuffer.tepos = (*SIOUXTextWindow->edit)->teLength - (i - CURRENTBUFSIZE()); - } - break; - #endif - - case 0x0a: - #if !__option(mpwc_newline) /* Carriage Return (move to start of line)*/ - if (convertLFs || (counter < n && buffer[-2] != 0x0d)) { - INSERTLINEFEED(); - } - i = OffsetOnCurrentLine(SIOUXTextWindow->edit, 1); - if (i <= CURRENTBUFSIZE()) - { - ROLLBACKBUFFER(i); - } - else - { -#if SIOUX_USE_WASTE - SIOUXBuffer.tepos = WEGetTextLength( SIOUXTextWindow->edit ) - (i - CURRENTBUFSIZE()); -#else - SIOUXBuffer.tepos = (*SIOUXTextWindow->edit)->teLength - (i - CURRENTBUFSIZE()); -#endif /* SIOUX_USE_WASTE */ - ROLLBACKBUFFER(CURRENTBUFSIZE()); /*mm 980109*/ - } - break; - #else /* Line Feed (Mac newline)*/ - INSERTLINEFEED(); - break; - #endif - - case 0x1b: /* Start escape mode*/ - if ( gSIOUXTerminalMode ) { - // need to flush data - InsertSIOUXBuffer(); - mode = 2; - { - int len = counter-1; - if (len > 10) - len = 10; - /*plnt_printf("### Start escape mode : %.*s\n", len, buffer);*/ - } - } - break; - - case '\t': /* Tab character*/ - if (SIOUXSettings.tabspaces) - { - /* insert spaces for tabs*/ - CHECKFOROVERFLOW(SIOUXSettings.tabspaces); - - i = OffsetOnCurrentLine(SIOUXTextWindow->edit, 1); - - spacestoinsert = SIOUXSettings.tabspaces - - (i % SIOUXSettings.tabspaces); - for (i = 0; i < spacestoinsert; i++) INSERTCHAR(' '); - } - else - INSERTCHAR('\t'); - break; - - case '\f': /* Form Feed*/ - CHECKFOROVERFLOW(SIOUXTextWindow->linesInFolder); - for (i = SIOUXTextWindow->linesInFolder; i > 0; i--) INSERTLINEFEED(); - break; - - case '\a': /* Audible Alert*/ - SysBeep(1); - break; - - case '\b': /* Backspace*/ - if (CURRENTBUFSIZE() != 0) - { - /*DELETEFROMBUFFER(1); mm 970212 */ - SIOUXBuffer.curpos -= 1; /* mm 970212 */ - SIOUXBuffer.endpos -= 1; /* mm 981210 */ - } - else - { /* Need to delete the last character from the TextEdit Handle*/ -#if SIOUX_USE_WASTE - long teLength = WEGetTextLength( SIOUXTextWindow->edit ); -#else - short teLength = (*SIOUXTextWindow->edit)->teLength; -#endif /* SIOUX_USE_WASTE */ - if (teLength > 0) - { -#if SIOUX_USE_WASTE - OSErr err; - WESetSelection(teLength-1, teLength, SIOUXTextWindow->edit); - err = WEDelete(SIOUXTextWindow->edit); -#else - TESetSelect(teLength-1, teLength, SIOUXTextWindow->edit); - TEDelete(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } - } - break; - - case '\v': /* Vertical Tab*/ - break; - - default: /* just add it to SIOUX ...*/ - INSERTCHAR(aChar); - break; - } - CHECKFOROVERFLOW(0); - break; - - case 2: - switch (aChar) { - case '[': - paramindex = maxparams; - while (--paramindex >= 0) - params[paramindex] = -1; - paramindex = 0; - mode = 3; // go to control sequence processing mode - break; - default: - /*plnt_printf("### unknown escape seq : %c\n", aChar);*/ - mode = 1; // back to plain input - break; - } - break; - - case 3: // control sequence processing - if ( aChar >= '0' && aChar <= '9' ) { - if ( params[paramindex] == -1 ) - params[paramindex] = 0; - params[paramindex] *= 10; - params[paramindex] += aChar - '0'; - break; - } - mode = 1; // back to plain input by default - - switch (aChar) { - - case '?': /* ???????????? */ - unknown = -1; - mode = 4; // ??? 25l, 25h ??? - break; - - case ';': /* parameter separator */ - paramindex++; - mode = 3; // remain in current mode - break; - - case 'A': /* cursor up */ - /*plnt_printf("cursor up\n");*/ - break; - - case 'B': /* cursor down */ - /*plnt_printf("cursor down\n");*/ - break; - - case 'C': /* cursor right */ - /*plnt_printf("cursor right\n");*/ - break; - - case 'c': /* request identification */ - /*plnt_printf("request identification\n");*/ - break; - - case 'D': /* cursor left */ - /*plnt_printf("cursor left\n");*/ - break; - - case 'f': - case 'H': /* absolute cursor positioning */ - { - int ypos, xpos; - SInt32 lineStart, lineEnd; - SInt32 topLineNumber; - SInt32 maxLineNumber; - SInt32 length; - SInt32 offset; - int crcount; - int spacecount; - - ypos = params[0] - 1; - if ( ypos < 0 ) - ypos = 0; - else if ( ypos >= SIOUXSettings.rows ) - ypos = SIOUXSettings.rows - 1; - - xpos = params[1] - 1; - if ( xpos < 0 ) - xpos = 0; - else if ( xpos >= SIOUXSettings.columns ) - xpos = SIOUXSettings.columns - 1; - - /*plnt_printf("absolute cursor positioning to (x:%d,y:%d)\n", xpos, ypos);*/ - - topLineNumber = CurrentTopLine(SIOUXTextWindow->edit); - length = WEGetTextLength( SIOUXTextWindow->edit ); - if (length > 0) { - maxLineNumber = WECountLines(SIOUXTextWindow->edit); - if (WEGetChar( length-1, SIOUXTextWindow->edit ) == 0x0d ) { - maxLineNumber++; - } - } else { - maxLineNumber = 0; - } - - /*plnt_printf("topLineNumber:%d, maxLineNumber:%d\n", topLineNumber, maxLineNumber);*/ - crcount = ypos - (maxLineNumber - topLineNumber); - if (crcount > 0) { - /*plnt_printf("need to add %d crs\n", crcount);*/ - WESetSelection( length-1, length-1, SIOUXTextWindow->edit ); - for (i = 0; i < crcount; i++) { - buf[i] = 0x0d; - } - WEInsert(buf, crcount, nil, nil, SIOUXTextWindow->edit); - maxLineNumber += crcount; - lineStart = length + crcount - 1; - lineEnd = lineStart; - } else { - WEGetLineRange(topLineNumber + ypos, &lineStart, &lineEnd, SIOUXTextWindow->edit ); - } - /*plnt_printf("line %d begins at %d\n", topLineNumber + ypos, lineStart);*/ - - offset = 0; - spacecount = 0; - length = WEGetTextLength( SIOUXTextWindow->edit ); - while ( offset < xpos ) { - if ( lineStart + offset >= length - || WEGetChar( lineStart + offset, SIOUXTextWindow->edit ) == 0x0d ) { - // need to add spaces... - spacecount = xpos - offset; - break; - } - offset++; - } - if (spacecount) { -/* - if (lineEnd == length - && lineStart == lineEnd - 1 - && WEGetChar( lineEnd-1, SIOUXTextWindow->edit ) == 0x0d) { - offset++; - } -*/ - /*plnt_printf("need to add %d spaces at %d\n", spacecount, lineStart+offset);*/ - WESetSelection( lineStart+offset, lineStart+offset, SIOUXTextWindow->edit ); - for (i = 0; i < spacecount; i++) { - buf[i] = ' '; - } - WEInsert(buf, spacecount, nil, nil, SIOUXTextWindow->edit); - } else { - WESetSelection( lineStart+offset, lineStart+offset, SIOUXTextWindow->edit ); - } - - - maxLineNumber = WECountLines(SIOUXTextWindow->edit) - 1; - WEGetLineRange(maxLineNumber, &lineStart, &lineEnd, SIOUXTextWindow->edit ); - /*plnt_printf("line max %d begins at %d\n", maxLineNumber, lineStart);*/ - - } - break; - - case 'J': /* erase to beginning/end/whole of screen */ - switch (params[0]) { - case -1: - case 0: /* erases characters from cursor to end of screen */ - /*plnt_printf("erases characters from cursor to end of screen\n");*/ - { -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd, lastCharIndex; - OSErr err; - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - lastCharIndex = WEGetTextLength( SIOUXTextWindow->edit ); - WESetSelection( weSelStart, lastCharIndex, SIOUXTextWindow->edit ); - err = WEDelete(SIOUXTextWindow->edit); -#else - SInt32 weSelStart, weSelEnd, lastCharIndex; - weSelStart = (*SIOUXTextWindow->edit)->selStart; - weSelEnd = (*SIOUXTextWindow->edit)->selEnd; - lastCharIndex = (*SIOUXTextWindow->edit)->teLength; - TESetSelect( weSelStart, lastCharIndex, SIOUXTextWindow->edit ); - TEDelete(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } - break; - case 1: /* erases characters from beginning of screen to cursor */ - /*plnt_printf("erases characters from beginning of screen to cursor\n");*/ - break; - case 2: /* clears the screen */ - /*plnt_printf("clears the screen\n");*/ - { -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd, lastCharIndex; - OSErr err; - //WEGetLineRange(CurrentTopLine(SIOUXTextWindow->edit), &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - lastCharIndex = WEGetTextLength( SIOUXTextWindow->edit ); - WESetSelection( weSelStart, lastCharIndex, SIOUXTextWindow->edit ); - err = WEDelete(SIOUXTextWindow->edit); -#else - SInt32 weSelStart, weSelEnd, lastCharIndex; - weSelStart = (*SIOUXTextWindow->edit)->selStart; - weSelEnd = (*SIOUXTextWindow->edit)->selEnd; - lastCharIndex = (*SIOUXTextWindow->edit)->teLength; - TESetSelect( weSelStart, lastCharIndex, SIOUXTextWindow->edit ); - TEDelete(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } - break; - } - break; - - case 'K': /* erase to beginning/end/whole of line */ - switch (params[0]) { - case -1: - case 0: /* erases characters to the end of the current line */ - /*plnt_printf("erases characters to the end of the current line\n");*/ - { -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd, lastCharIndex; - OSErr err; - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - lastCharIndex = WEGetTextLength( SIOUXTextWindow->edit ) - 1; - i = weSelStart; - while ( i < lastCharIndex && WEGetChar( i, SIOUXTextWindow->edit ) != 0x0d ) - ++i; - weSelEnd = i+1; - WESetSelection( weSelStart, weSelEnd, SIOUXTextWindow->edit ); - err = WEDelete(SIOUXTextWindow->edit); -#else - SInt32 weSelStart, weSelEnd, lastCharIndex; - char *ptr; - weSelStart = (*SIOUXTextWindow->edit)->selStart; - weSelEnd = (*SIOUXTextWindow->edit)->selEnd; - lastCharIndex = (*SIOUXTextWindow->edit)->teLength - 1; - i = weSelStart; - ptr = *(*SIOUXTextWindow->edit)->hText; - while ( i < lastCharIndex && ptr[i] != 0x0d ) - ++i; - weSelEnd = i+1; - TESetSelect( weSelStart, weSelEnd, SIOUXTextWindow->edit ); - TEDelete(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } - break; - case 1: /* erases characters from beginning of line to cursor */ - /*plnt_printf("erases characters from beginning of line to cursor\n");*/ - - break; - case 2: /* erases the specified line */ - /*plnt_printf("erases the specified line\n");*/ - break; - } - break; - - case 'L': /* ???????????? */ - break; - - case 'm': /* set/clear attributes */ - tempindex = -1; - while (++tempindex <= paramindex) { - if ( params[tempindex] == -1 ) - params[tempindex] = 0; - if (params[tempindex] == 0) { - attrib &= 0x80; // all off - } else if (params[tempindex] < 8) { - attrib |= 1 << (params[tempindex] - 1); // set an attribute - } else if (params[tempindex] > 21 && params[tempindex] < 28) { - attrib &= ~(1 << (params[tempindex] - 21)); // clear an attribute - } - } - break; - - case 'q': /* flash dem LEDs. What LEDs? */ - break; - - case 'r': /* set scrolling region */ - { - int top, bottom; - top = params[0]; - if ( top < 1 ) - top = 1; - else if ( top > SIOUXSettings.rows ) - top = SIOUXSettings.rows; - bottom = params[1]; - if ( bottom < 1 || bottom > SIOUXSettings.rows ) - bottom = SIOUXSettings.rows; - /*plnt_printf("set scrolling region to (%d,%d)\n", top, bottom);*/ - } - break; - - default: - /*plnt_printf("### unknown control seq : %c\n", aChar);*/ - break; - } - break; - - case 4: // ??? 25l, 25h ??? - if ( aChar >= '0' && aChar <= '9' ) { - if ( unknown == -1 ) - unknown = 0; - unknown *= 10; - unknown += aChar - '0'; - break; - } - mode = 1; // back to plain input by default - switch (aChar) { - case 'l': - // turn something on ??? - break; - case 'h': - // turn something off ??? - break; - } - break; - - } - } - InsertSIOUXBuffer(); - - SIOUXState = IDLE; - SIOUXUpdateStatusLine(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - - SetPort(saveport); - - return n; -} - -/************************************************************************/ -/* Purpose..: Read characters into the buffer */ -/* Input....: pointer to buffer */ -/* Input....: max length of buffer */ -/* Return...: number of characters read / -1 error occurred */ -/************************************************************************/ -long ReadCharsFromConsole(char *buffer, long n) -{ - long charsread; - GrafPtr saveport; -#if SIOUX_USE_WASTE - Handle textHandle; -#endif /* SIOUX_USE_WASTE */ - OSErr err; - - if (SIOUXQuitting) - return 0; - - if (atEOF) - { - if (gSIOUXTerminalMode) - atEOF = 0; - buffer[0] = EOF; - return 0; - } - - GetPort(&saveport); - SetPortWindowPort(SIOUXTextWindow->window); /* ra 990612 Use UI 3.2 and WindowPtr */ - - if ( !gSIOUXTerminalMode || !gSIOUXBufSize ) - SIOUXState = SCANFING; - - inputBuffersize = n; -#if SIOUX_USE_WASTE - SIOUXselstart = WEGetTextLength( SIOUXTextWindow->edit ); -#else - SIOUXselstart = (*SIOUXTextWindow->edit)->teLength; -#endif /* SIOUX_USE_WASTE */ - - SelectWindow(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - SIOUXUpdateStatusLine(SIOUXTextWindow->window); - - if (!gSIOUXTerminalMode) { -#if SIOUX_USE_WASTE - WESetSelection(SIOUXselstart, SIOUXselstart, SIOUXTextWindow->edit); - WEActivate(SIOUXTextWindow->edit); -#else - TESetSelect(SIOUXselstart, SIOUXselstart, SIOUXTextWindow->edit); - TEActivate(SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - } else { - - } - - SIOUXUpdateScrollbar(); - - while (SIOUXState == SCANFING && !SIOUXQuitting) - { -BackInTheLoop: - SIOUXHandleOneEvent(NULL); - } - - if (SIOUXQuitting) - { - if (!SIOUXCleanUp()) - { - SIOUXQuitting = false; - goto BackInTheLoop; - } - SetPort(saveport); - exit(0); - } - - if (!gSIOUXTerminalMode) { - - /* put the string into the buffer ...*/ -#if SIOUX_USE_WASTE - charsread = WEGetTextLength(SIOUXTextWindow->edit ) - SIOUXselstart; - textHandle = WEGetText(SIOUXTextWindow->edit); - HLock( textHandle ); - BlockMoveData( *textHandle + SIOUXselstart, buffer, charsread); - HUnlock( textHandle ); - -#else - charsread = (*SIOUXTextWindow->edit)->teLength - SIOUXselstart; -#ifndef __NO_WIDE_CHAR /* mm 981020 */ - if (fwide(stdin, 0) <= 0) /* mm 980208 */ -#endif /* #ifndef __NO_WIDE_CHAR */ /* mm 981020 */ - BlockMoveData((*(*SIOUXTextWindow->edit)->hText) + SIOUXselstart, - buffer, - charsread); -#ifndef __NO_WIDE_CHAR /* mm 981020 */ - else /* mm 980208 */ - { /* mm 980208 */ - char tempbuf[256]; - long count; /* mm 980208 */ - BlockMoveData((*(*SIOUXTextWindow->edit)->hText) + SIOUXselstart, /* mm 980208 */ - tempbuf, /* mm 980208 */ - charsread); /* mm 980208 */ - for (count = 0; count <= charsread; count++) /* mm 980208 */ - { /* mm 980208 */ - buffer[2*count] = '\0'; /* mm 980208 */ - buffer[2*count+1] = tempbuf[count]; /* mm 980208 */ - } /* mm 980208 */ - - charsread *= 2; /* mm 980208 */ - } /* mm 980208 */ -#endif /* #ifndef __NO_WIDE_CHAR */ /* mm 981020 */ - -#endif /* SIOUX_USE_WASTE */ - err = MemError(); - - } else { - - /* get data from blind buffer */ - if ( gSIOUXBufSize ) { - charsread = gSIOUXBufSize; - if (charsread > n) { - charsread = n; - } - BlockMoveData(gSIOUXChars, buffer, charsread); - gSIOUXBufSize -= charsread; - if ( gSIOUXBufSize ) { - BlockMoveData( gSIOUXChars + charsread, gSIOUXChars, gSIOUXBufSize ); - } - err = noErr; - } else { - err = -1; - } - } - - /* if no error occurred continue else return 0 characters read ...*/ - if (err == noErr) - { - if (buffer[charsread - 1L] == 0x03) /* The user did a Control - Z or control - D (ie an EOF) */ - charsread--, atEOF = 1; - else if (!gSIOUXTerminalMode) - buffer[charsread - 1L] = 0x0d; - } - else - { - charsread = 0; - } - - SIOUXUpdateStatusLine(SIOUXTextWindow->window); /* ra 990612 Use WindowPtr */ - - SetPort(saveport); - - /*plnt_dump("ReadCharsFromConsole", buffer, charsread);*/ - - return charsread; -} - -/* - * return the name of the current terminal ... - */ -char *__ttyname(long fildes) -{ - /* all streams have the same name ...*/ - static char *__SIOUXDeviceName = "SIOUX"; - - if (fildes >= 0 && fildes <= 2) - return (__SIOUXDeviceName); - - return (NULL); -} - -/* - * Set SIOUX's window title ... - */ -void SIOUXSetTitle(unsigned char title[256]) -{ - - if (SIOUXTextWindow != NULL) - SetWTitle(SIOUXTextWindow->window, title); /* ra 990612 Use WindowPtr */ - else /* mm 980609 */ - { - SIOUXSettings.userwindowtitle = malloc(title[0]+1); - if (SIOUXSettings.userwindowtitle != NULL) - BlockMoveData(title, SIOUXSettings.userwindowtitle, (long)title[0] + 1); - } -} - -/* -* -* int kbhit() -* -* returns true if any keyboard key is pressed without retrieving the key -* used for stopping a loop by pressing any key -*/ -int kbhit(void) -{ - EventRecord event; - return EventAvail(keyDownMask,&event); -} - -/* -* -* int getch() -* -* returns the keyboard character pressed when an ascii key is pressed -* used for console style menu selections for immediate actions. -*/ -int getch(void) -{ - int c; - EventRecord event; - fflush(stdout); - /* Allow SIOUX response for the mouse, drag, zoom, or resize. */ - while(!GetNextEvent(keyDownMask,&event)) - { - if (GetNextEvent(updateMask | osMask | mDownMask | mUpMask, &event)) /* mm 980506 */ - SIOUXHandleOneEvent(&event); - } - c = event.message&charCodeMask; - if (c == '.' && (event.modifiers&cmdKey)) - exit(1); - - return c; -} - -/* -* void clrscr() -* -* clears screen and empties buffer. -*/ -void clrscr(void) /* mm 980427 */ /* mm 981218 */ -{ - EventRecord rEvent; - - fflush(stdout); - rEvent.what = keyDown; - rEvent.when = TickCount( ); - rEvent.message = 'a'; - rEvent.modifiers = cmdKey; - SIOUXHandleOneEvent(&rEvent); - - rEvent.what = keyDown; - rEvent.when = TickCount( ); - rEvent.message = 0x7F; - rEvent.modifiers = 0; - SIOUXHandleOneEvent(&rEvent); -} - - - -/* Change Record -// BB 01/10/93 removed diskEvt from switch statement since this called -// DIBadMount which is not glue code and hence required importing -// MacOS.lib ... -// BB 21/01/94 removed the direct call to GrowDrawIcon and replaced it -// with a call to a clipping function which doesn't draw the -// lines. -// BB 25/01/94 Added support for command - '.', also changed calls to -// ExitToShell() to exit() which allows the ANSI libs to close -// any open file streams. -// BB 25/01/94 Added support for tab characters. -// BB 22/07/94 Added support for EOF, through control - z -// BB 11/09/94 Added support for control - c, also both control-c and command-. -// call raise SIGABRT rather than calling exit. -// Added support for mouse down to pause output. -// Added support for setting tab behaviour in SIOUX. -// Fixed support for characters >128 -// BB 20/10/94 Fixed behaviour of replacing tabs for spaces ... -// BB 25/10/94 Added support for '\r' to move cursor to beginning of line -// BB 26/10/94 Changed command-'.' and control - c to raise SIGINT instead of -// SIGABRT. -// BB 01/12/94 Extended EOF support to include control - d -// JH 01/09/95 Modified to run with new ANSI C library -// JH 12/10/95 Moved __system7present() back to unix.c -// JH 29/01/96 Added missing return in SIOUXHandleOneEvent's keyDown/autoKey -// Cmd-key handling -// JH 19/02/96 Eliminated local definition of EOF. -// bk 09/02/96 added Universal Headers incase macheaders not the prefix -// bk 961228 line 752-772 switched LF/CR if __option(mpwc_newline) -// mm 970212 Changed backspace to just move cursor when text still in buffer. -// mm 970626 Modification to allow correct function of '\r' -// mm 970903 Correction to calculation of OffsetOnCurrentLine MW00396 -// mm 971006 Added #include of Sound.h because of change in universal headers -// mm 971229 Corrected semantics of \r in errors revealed by MW03003 -// mm 971230 Changes to OffsetOnCurrentLine for WASTE to correct semantics of \r in errors revealed by MW03003 -// mm 980108 Change to InstallConsole to correct behaviour of \r on first line of output -// mm 980109 A further fix to \r -// mm 980112 Yet another fix to \r -// mm 980208 Support for reading wide characters from console for wscanf. Not yet done for WASTE -// mm 980331 Fix to insert linefeed to make the sequence \b\n work correctly. -// mm 980413 Fix to make the enter key work as return on input on a PowerBook where its virtual key code is 0x34. -// mm 980427 Added SIOUXclrscr MW06847 -// mm 980506 Modified getch() so that the window is repainted if necessary. MW03278 -// mm 980605a Change from Michael Bishop to make SIOUX only select windows it knows about MW06855 -// mm 980605b Change from Michael Bishop to make SIOUX select windows when user clicks in drag or grow region -// if it's not the FrontWindow. MW06856 -// mm 980605c Change from Michael Bishop to return false from SIOUXHandleOneEvent() so that an app that embeds -// SIOUX will be able to process a NULL event as well. MM06857 -// mm 980609 Changes that allow user to specify window title before the SIOUX window is created. -// vss 980629 moved variable into code block that uses it to remove warning -// mm 981020 Added #ifndef __NO_WIDE_CHAR wrappers -// mm 981210 Corrected backspace behaviour for stderr (non-buffered) MW08661 -// mm 981218 Changed name SIOUXclrscr to clrscr MW08237 -// cc 991108 added ra Carbon Changes done 990611 -// cc 991109 changed TARGET_CARBON to TARGET_API_MAC_CARBON -// cc 991111 added ra & JWW suggestions for functions no longer in carbon -// cc 991115 updated and deleted carbon outdated comments -// JWW 000413 Call DisposeWindow or CloseWindow -- never both -// cc 000516 __myraise is now an inline in unix.h -// JWW 000531 Added Apple Event handlers for standalone application (necessary to catch Quit on OS X, but also nice to have overall) -*/ \ No newline at end of file diff --git a/lsh/MacOS/src/SIOUXMenus.c b/lsh/MacOS/src/SIOUXMenus.c deleted file mode 100755 index 1e1e868..0000000 --- a/lsh/MacOS/src/SIOUXMenus.c +++ /dev/null @@ -1,740 +0,0 @@ -/* Metrowerks Standard Library */ - -/* $Date$ - * $Revision$ + Carbon Changes - * $NoKeywords: $ - * - * Copyright © 1995-1999 Metrowerks, Inc. - * All rights reserved. - */ - -/*****************************************************************************/ -/* Project...: C++ and ANSI-C Compiler Environment */ -/* Name......: SIOUXMenus.c */ -/* Purpose...: Menu related functions for SIOUX */ -/*****************************************************************************/ - - - #include - -#include "SIOUXGlobals.h" -#include "SIOUXMenus.h" -#include "SIOUXPrinter.h" -#include "SIOUXWindows.h" - -#include "PasswordDialog.h" /* just for GetScrapHandle() */ - -#if SIOUX_USE_WASTE - #include -#endif - -/*#include */ -extern long _fcreator, _ftype; - -#include -#include -#include /*bkoz*/ -#include -#include - -#if TARGET_API_MAC_CARBON - #include /* ra 990612 */ - #include - #include - #include /* ra 990612 */ -#endif /* TARGET_API_MAC_CARBON */ - -#pragma bool on -#ifndef TRUE /* ra 990611 Carbon */ -#define TRUE true -#endif - -/* Menuhandles ...*/ -static MenuHandle appleMenu; -static MenuHandle fileMenu; -static MenuHandle editMenu; - -extern Boolean gSIOUXTerminalMode; -extern char gSIOUXChars[]; -extern short gSIOUXBufSize; -extern const short gSIOUXMaxSize; - -extern void GUSIWakeupSIOUXSocket(); - -#if ! SIOUX_USE_WASTE - -/************************************************************************/ -/* Purpose..: Replacement for mac TE glue */ -/* Input....: --- */ -/* Return...: --- */ -/************************************************************************/ -static OSErr MyTEFromScrap(void) -{ - long length; /* cc 991111 */ -#if TARGET_API_MAC_CARBON /* cc 991111 */ - ScrapRef theScrapRef; -#else - long scrapOffset; /* cc 991111 */ -#endif - -#if TARGET_API_MAC_CARBON - GetCurrentScrap(&theScrapRef); - GetScrapFlavorSize(theScrapRef, 'TEXT', &length); -#else - if ((length = GetScrap(0L,'TEXT',&scrapOffset))<0) - return (length); -#endif /* cc 991111 */ - - if (length>32000) - return (teScrapSizeErr); - -#if TARGET_API_MAC_CARBON /* cc 991111 */ - HUnlock(TEScrapHandle()); - SetHandleSize(TEScrapHandle(), length); - HLock(TEScrapHandle()); - GetScrapFlavorData(theScrapRef, 'TEXT', &length, *TEScrapHandle()); -#else /* cc 991111 */ - HLock(TEScrapHandle()); - if ((length = GetScrap(TEScrapHandle(),'TEXT',&scrapOffset))<0) { - HUnlock(TEScrapHandle()); - return (length); - } -#endif - - HUnlock(TEScrapHandle()); /* cc 991111 */ - TESetScrapLength(length); - - return (noErr); -} - -static OSErr MyTEToScrap(void) -{ - long error; -#if TARGET_API_MAC_CARBON /*cc 991111 */ - ScrapRef theScrapRef; -#endif - - HLock(TEScrapHandle()); - -#if TARGET_API_MAC_CARBON - error = ClearCurrentScrap(); - error = GetCurrentScrap(&theScrapRef); - error = PutScrapFlavor(theScrapRef, 'TEXT', kScrapFlavorMaskNone, TEGetScrapLength(), - *TEScrapHandle()); -#else - ZeroScrap(); - error = PutScrap(LMGetTEScrpLength(), 'TEXT', *TEScrapHandle()); -#endif /* TARGET_API_MAC_CARBON */ /*cc 991111 */ - - HUnlock(TEScrapHandle()); - - return error; -} -#endif /* ! SIOUX_USE_WASTE */ - -/****************************************************************/ -/* Purpose..: Setup SIOUX's menus */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXSetupMenus(void) -{ -#if TARGET_API_MAC_CARBON - long result; -#endif /* TARGET_API_MAC_CARBON */ - unsigned char appleString[2] = "\001\024"; - - /* Create the Apple menu ...*/ - appleMenu = NewMenu(APPLEID, appleString); -#if SIOUX_USE_WASTE - AppendMenu( appleMenu, "\pAbout SIOUX-WASTE;(-"); -#else - AppendMenu(appleMenu, "\pAbout SIOUX;(-"); -#endif /* SIOUX_USE_WASTE */ - AppendResMenu(appleMenu, 'DRVR'); - InsertMenu(appleMenu, 0); - - /* Create the File menu ...*/ - fileMenu = NewMenu(FILEID, "\pFile"); -#if TARGET_API_MAC_CARBON - Gestalt(gestaltMenuMgrAttr, &result); - if ((result & gestaltMenuMgrAquaLayoutMask) == gestaltMenuMgrAquaLayoutMask) - /* JWW - On OS X, the Quit item is automaticaly in the application menu, not in File */ - AppendMenu(fileMenu, "\p(New...;(Open...;(Close...;Save/S;(-;Page Setup;Print.../P"); - else - /* JWW - Be careful if you modify this area -- the else clause is after the #endif */ -#endif /* TARGET_API_MAC_CARBON */ - AppendMenu(fileMenu, "\p(New...;(Open...;(Close...;Save/S;(-;Page Setup;Print.../P;(-;Quit/Q"); - InsertMenu(fileMenu, 0); - - /* Create the Edit menu ...*/ - editMenu = NewMenu(EDITID, "\pEdit"); - AppendMenu(editMenu, "\p(Undo/Z;(-;(Cut/X;(Copy/C;Paste/V;(Clear;(-;Select All/A"); - InsertMenu(editMenu, 0); - - InvalMenuBar(); /* Instead of DrawMenuBar to allow Carbon to fill in the Apple menu */ -} - -/****************************************************************/ -/* Purpose..: Setup SIOUX's menus */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXUpdateMenuItems(void) -{ -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd; -#endif - /* First disable all possible items ...*/ - -#if TARGET_API_MAC_CARBON - DisableMenuItem(fileMenu, FILESAVE); - DisableMenuItem(fileMenu, FILEPRINT); - DisableMenuItem(editMenu, EDITCUT); - DisableMenuItem(editMenu, EDITCOPY); - DisableMenuItem(editMenu, EDITPASTE); - DisableMenuItem(editMenu, EDITCLEAR); - DisableMenuItem(editMenu, EDITSELECTALL); -#else - DisableItem(fileMenu, FILESAVE); - DisableItem(fileMenu, FILEPRINT); - DisableItem(editMenu, EDITCUT); - DisableItem(editMenu, EDITCOPY); - DisableItem(editMenu, EDITPASTE); - DisableItem(editMenu, EDITCLEAR); - DisableItem(editMenu, EDITSELECTALL); -#endif /* TARGET_API_MAC_CARBON */ - - if (SIOUXState != PRINTFING && SIOUXIsAppWindow(FrontWindow())) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(fileMenu, FILEPRINT); - #else - EnableItem(fileMenu, FILEPRINT); - #endif /* TARGET_API_MAC_CARBON */ -#if SIOUX_USE_WASTE - if ( WECanPaste( SIOUXTextWindow->edit ) ) { -#endif - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITPASTE); - #else - EnableItem(editMenu, EDITPASTE); - #endif -#if SIOUX_USE_WASTE - } -#endif - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITSELECTALL); - #else - EnableItem(editMenu, EDITSELECTALL); - #endif /* TARGET_API_MAC_CARBON */ - -#if SIOUX_USE_WASTE - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - - if ( weSelStart != weSelEnd ) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITCUT); - #else - EnableItem(editMenu, EDITCUT); - #endif /* TARGET_API_MAC_CARBON */ - } - if ( weSelStart != weSelEnd ) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITCOPY); - #else - EnableItem(editMenu, EDITCOPY); - #endif /* TARGET_API_MAC_CARBON */ - } - if ( weSelStart != weSelEnd ) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITCLEAR); - #else - EnableItem(editMenu, EDITCLEAR); - #endif /* TARGET_API_MAC_CARBON */ - } -#else - if ((*SIOUXTextWindow->edit)->selStart != (*SIOUXTextWindow->edit)->selEnd) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITCUT); - #else - EnableItem(editMenu, EDITCUT); - #endif /* TARGET_API_MAC_CARBON */ - } - if ((*SIOUXTextWindow->edit)->selStart != (*SIOUXTextWindow->edit)->selEnd) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITCOPY); - #else - EnableItem(editMenu, EDITCOPY); - #endif /* TARGET_API_MAC_CARBON */ - } - if ((*SIOUXTextWindow->edit)->selStart != (*SIOUXTextWindow->edit)->selEnd) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(editMenu, EDITCLEAR); - #else - EnableItem(editMenu, EDITCLEAR); - #endif /* TARGET_API_MAC_CARBON */ - } -#endif /* SIOUX_USE_WASTE */ - - if (SIOUXTextWindow->dirty) { - #if TARGET_API_MAC_CARBON - EnableMenuItem(fileMenu, FILESAVE); - #else - EnableItem(fileMenu, FILESAVE); - #endif /* TARGET_API_MAC_CARBON */ - } - } -} - - -/****************************************************************/ -/* Purpose..: Setup SIOUX's menus */ -/* Input....: --- */ -/* Returns..: noErr text saved correctly / -1 error or cancel */ -/****************************************************************/ - -#if TARGET_API_MAC_CARBON -/* Prototype for routine in SIOUXWindows.c */ -void SIOUXUpdateWindow(WindowPtr theWindow); - -static pascal void NavEventProc2(NavEventCallbackMessage inSelector, NavCBRecPtr ioParams, - NavCallBackUserData ioUserData) /* cc 991111 */ -{ -#pragma unused(ioParams, ioUserData) - - if (inSelector == kNavCBEvent) { - SIOUXUpdateWindow(SIOUXTextWindow->window); - } -} -#endif /* TARGET_API_MAC_CARBON */ - -short SIOUXDoSaveText(void) -{ - short error; - HParamBlockRec pb; - StandardFileReply sfReply; /* ra 990612 Change to support NavServ. */ - -#if SIOUX_USE_WASTE - WEReference theTE = SIOUXTextWindow->edit; - long textLength = WEGetTextLength( theTE ); - Handle textHandle = WEGetText( theTE ); -#else - TEHandle theTE = SIOUXTextWindow->edit; - long textLength = (long)(*theTE)->teLength; -#endif /* SIOUX_USE_WASTE */ - - Point aPoint = {100, 100}; - -#if SIOUX_USE_WASTE - HLock( textHandle ); -#else - HLock((*theTE)->hText); -#endif /* SIOUX_USE_WASTE */ - - if (SIOUXTextWindow->dirid) { - /* Open the file ...*/ - pb.ioParam.ioCompletion = 0L; - pb.ioParam.ioNamePtr = SIOUXTextWindow->fname; - pb.ioParam.ioVRefNum = SIOUXTextWindow->vrefnum; - pb.ioParam.ioPermssn = fsWrPerm; - pb.fileParam.ioDirID = SIOUXTextWindow->dirid; - if (PBHOpenDFSync(&pb) != noErr) - /* Couldn't open the file so we try resaving it ...*/ - goto RenameFile; - /* Write the text ...*/ -#if SIOUX_USE_WASTE - pb.ioParam.ioBuffer = *textHandle; -#else - pb.ioParam.ioBuffer = *(*theTE)->hText; -#endif /* SIOUX_USE_WASTE */ - pb.ioParam.ioReqCount = textLength; - pb.ioParam.ioPosMode = fsFromStart; - pb.ioParam.ioPosOffset = 0; - if (PBWriteSync((ParmBlkPtr)&pb) != noErr) - goto SaveError; -#if SIOUX_USE_WASTE - if (pb.ioParam.ioActCount != (long)WEGetTextLength( theTE ) ) -#else - if (pb.ioParam.ioActCount != (long)(*theTE)->teLength) -#endif /* SIOUX_USE_WASTE */ - goto SaveError; - pb.ioParam.ioMisc = (Ptr)pb.ioParam.ioActCount; - if (PBSetEOFSync((ParmBlkPtr)&pb) != noErr) - goto SaveError; - /* Close file ...*/ - if (PBCloseSync((ParmBlkPtr)&pb) != noErr) - goto SaveError; - goto Saved; - } else { - Str255 theTitle; - -RenameFile: - GetWTitle(SIOUXTextWindow->window, theTitle); - - sfReply.sfGood = false; - - #if TARGET_API_MAC_CARBON - { - NavDialogOptions NavOptions; - NavReplyRecord NavReply; - AEDesc specDesc; - OSErr err; - - NavEventUPP myEventUPP = NewNavEventUPP(NavEventProc2); - - err = NavLoad(); - if (err != noErr) - goto NotSaved; - - NavGetDefaultDialogOptions(&NavOptions); - BlockMoveData(theTitle, NavOptions.savedFileName, sizeof(sfReply.sfFile.name)); - - err = NavPutFile(NULL, &NavReply, &NavOptions, myEventUPP, 'TEXT', 'CWIE', NULL); - if (err != noErr) - goto NotSaved; - - AECoerceDesc(&NavReply.selection, typeFSS, &specDesc); - - DisposeNavEventUPP(myEventUPP); - - sfReply.sfGood = NavReply.validRecord; - if (sfReply.sfGood) { - NavTranslationOptions Options = kNavTranslateInPlace; - sfReply.sfFile = **(FSSpec**) specDesc.dataHandle; - NavCompleteSave(&NavReply, Options); - } - NavDisposeReply(&NavReply); - NavUnload(); - AEDisposeDesc(&specDesc); - - if (err == userCanceledErr) - goto NotSaved; - } - #else - StandardPutFile("\pSave document as...", theTitle, &sfReply); /* ra 990612 UI 3.2 */ - if (!sfReply.sfGood) - goto NotSaved; - #endif /* TARGET_API_MAC_CARBON */ - - /* Make the FSSpec ...*/ - SIOUXTextWindow->vrefnum = sfReply.sfFile.vRefNum; - #if TARGET_API_MAC_CARBON - SIOUXTextWindow->dirid = sfReply.sfFile.parID; - #else - SIOUXTextWindow->dirid = LMGetCurDirStore(); /* jd- why is this even being done??? */ - #endif /* TARGET_API_MAC_CARBON */ - BlockMoveData(sfReply.sfFile.name, SIOUXTextWindow->fname, sfReply.sfFile.name[0] + 1); - - pb.ioParam.ioCompletion = 0L; - pb.ioParam.ioNamePtr = SIOUXTextWindow->fname; - pb.ioParam.ioVRefNum = SIOUXTextWindow->vrefnum; - pb.fileParam.ioFlVersNum = 0; - pb.fileParam.ioDirID = SIOUXTextWindow->dirid; - error = PBHCreateSync(&pb); - if (error != noErr && error != dupFNErr) - goto SaveError; - /* Set the finder info ...*/ - GetDateTime(&pb.fileParam.ioFlCrDat); /* cc 991111 */ - GetDateTime(&pb.fileParam.ioFlMdDat); /* cc 991111 */ - if ( _ftype != '\0' ) - pb.fileParam.ioFlFndrInfo.fdType = _ftype; - else - pb.fileParam.ioFlFndrInfo.fdType = 'TEXT'; - - if ( _fcreator != '\0' ) - pb.fileParam.ioFlFndrInfo.fdCreator = _fcreator; - else - pb.fileParam.ioFlFndrInfo.fdCreator = 'CWIE'; - pb.fileParam.ioFlFndrInfo.fdFlags = 0; - if (PBHSetFInfoSync(&pb) != noErr) - goto SaveError; - /* Open the file ...*/ - pb.ioParam.ioPermssn = fsWrPerm; - if (PBHOpenDFSync(&pb) != noErr) - goto SaveError; - /* Write the text ...*/ -#if SIOUX_USE_WASTE - pb.ioParam.ioBuffer = *textHandle; -#else - pb.ioParam.ioBuffer = *(*theTE)->hText; -#endif /* SIOUX_USE_WASTE */ - pb.ioParam.ioReqCount = textLength; - pb.ioParam.ioPosMode = fsFromStart; - pb.ioParam.ioPosOffset = 0; - if (PBWriteSync((ParmBlkPtr)&pb) != noErr) - goto SaveError; -#if SIOUX_USE_WASTE - if (pb.ioParam.ioActCount != (long)WEGetTextLength( theTE ) ) -#else - if (pb.ioParam.ioActCount != (long)(*theTE)->teLength) -#endif /* SIOUX_USE_WASTE */ - goto SaveError; - pb.ioParam.ioMisc = (Ptr)pb.ioParam.ioActCount; - if (PBSetEOFSync((ParmBlkPtr)&pb) != noErr) - goto SaveError; - /* Close file ...*/ - if (PBCloseSync((ParmBlkPtr)&pb) != noErr) - goto SaveError; - /* Rename the window ...*/ - SetWTitle(SIOUXTextWindow->window, SIOUXTextWindow->fname); - - goto Saved; - } -SaveError: -#if SIOUX_USE_WASTE - HUnlock( textHandle ); -#else - HUnlock((*theTE)->hText); -#endif /* SIOUX_USE_WASTE */ - -#if TARGET_API_MAC_CARBON - { - Cursor theArrow; - SetCursor(GetQDGlobalsArrow(&theArrow)); - } -#else - SetCursor(&qd.arrow); -#endif /* TARGET_API_MAC_CARBON */ - SIOUXCantSaveAlert(SIOUXTextWindow->fname); -NotSaved: - return (-1); -Saved: -#if SIOUX_USE_WASTE - HUnlock( textHandle ); -#else - HUnlock((*theTE)->hText); -#endif /* SIOUX_USE_WASTE */ - SIOUXTextWindow->dirty = 0; - return (noErr); -} - -/****************************************************************/ -/* Purpose..: Handle the cut menu command */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXDoEditCut(void) -{ -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd; - OSErr err; - - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - if (SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit) && weSelStart != weSelEnd) { - err = WECut(SIOUXTextWindow->edit); - SIOUXTextWindow->dirty = TRUE; - SIOUXUpdateScrollbar(); - } -#else - if (SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit) && (*SIOUXTextWindow->edit)->selStart != (*SIOUXTextWindow->edit)->selEnd) { - TECut(SIOUXTextWindow->edit); - MyTEToScrap(); - SIOUXTextWindow->dirty = TRUE; - SIOUXUpdateScrollbar(); - } -#endif /* SIOUX_USE_WASTE */ -} - -/****************************************************************/ -/* Purpose..: Handle the copy menu command */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXDoEditCopy(void) -{ -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd; - OSErr err; - - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - if (weSelStart != weSelEnd) { - err = WECopy(SIOUXTextWindow->edit); - } -#else - if ((*SIOUXTextWindow->edit)->selStart != (*SIOUXTextWindow->edit)->selEnd) - { - TECopy(SIOUXTextWindow->edit); - MyTEToScrap(); /* mm 970428 */ - } -#endif /* SIOUX_USE_WASTE */ -} - -/****************************************************************/ -/* Purpose..: Handle the paste menu command */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXDoEditPaste(void) -{ -#if SIOUX_USE_WASTE - OSErr err; - - if (SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit) && WECanPaste( SIOUXTextWindow->edit ) ) { - if (!gSIOUXTerminalMode) { - err = WEPaste(SIOUXTextWindow->edit); - SIOUXTextWindow->dirty = 1; - SIOUXUpdateScrollbar(); - } else { - Handle hText = nil ; - OSErr err; - // look for a text flavor - if ( ( err = GetScrapHandle ( 'TEXT', &hText ) ) == noErr ) { - SInt32 size = GetHandleSize ( hText ); - if (size > gSIOUXMaxSize - gSIOUXBufSize) { - size = gSIOUXMaxSize - gSIOUXBufSize; - } - BlockMoveData(* hText, gSIOUXChars + gSIOUXBufSize, size); - gSIOUXBufSize += size; - SIOUXState = IDLE; - GUSIWakeupSIOUXSocket(); - DisposeHandle( hText ); - } - } - } -#else - if (SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit) && MyTEFromScrap() == noErr) { - TEPaste(SIOUXTextWindow->edit); - SIOUXTextWindow->dirty = 1; - SIOUXUpdateScrollbar(); - } -#endif /* SIOUX_USE_WASTE */ -} - - -/****************************************************************/ -/* Purpose..: Handle the clear menu command */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXDoEditClear(void) -{ -#if SIOUX_USE_WASTE - SInt32 weSelStart, weSelEnd; - - WEGetSelection( &weSelStart, &weSelEnd, SIOUXTextWindow->edit ); - if (SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit) && weSelStart != weSelEnd) { - WEDelete(SIOUXTextWindow->edit); - SIOUXTextWindow->dirty = TRUE; - SIOUXUpdateScrollbar(); - } -#else - if (SIOUXisinrange(SIOUXselstart, SIOUXTextWindow->edit) && (*SIOUXTextWindow->edit)->selStart != (*SIOUXTextWindow->edit)->selEnd) { - TEDelete(SIOUXTextWindow->edit); - SIOUXTextWindow->dirty = TRUE; - SIOUXUpdateScrollbar(); - } -#endif /* SIOUX_USE_WASTE */ -} - -/****************************************************************/ -/* Purpose..: Handle the select all menu command */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXDoEditSelectAll(void) -{ -#if SIOUX_USE_WASTE - WESetSelection( 0, LONG_MAX, SIOUXTextWindow->edit ); -#else - TESetSelect(0, 32767, SIOUXTextWindow->edit); -#endif /* SIOUX_USE_WASTE */ - - SIOUXUpdateScrollbar(); -} - -/****************************************************************/ -/* Purpose..: Setup SIOUX's menus */ -/* Input....: --- */ -/* Returns..: --- */ -/****************************************************************/ -void SIOUXDoMenuChoice(long menuValue) -{ - short theMenu = HiWord(menuValue); - short theMenuItem = LoWord(menuValue); -#if TARGET_API_MAC_OS8 - Str255 accName; -#endif /* TARGET_API_MAC_OS8 */ - - if (!SIOUXIsAppWindow(FrontWindow())) - return; - - switch(theMenu) { - case APPLEID: - switch (theMenuItem) { - case APPLEABOUT: - SIOUXDoAboutBox(); - break; - default: /* ie the apple menu items ...*/ - #if TARGET_API_MAC_OS8 - GetMenuItemText(appleMenu, theMenuItem, accName); - OpenDeskAcc(accName); - #endif /* TARGET_API_MAC_OS8 */ - break; - } - break; - case FILEID: - switch (theMenuItem) { - case FILESAVE: - SIOUXDoSaveText(); - break; - case FILEPAGESETUP: - SIOUXDoPageSetup(); - break; - case FILEPRINT: - SIOUXDoPrintText(); - break; - case FILEQUIT: - if (SIOUXSettings.standalone) - SIOUXQuitting = TRUE; - break; - default: - break; - } - break; - case EDITID: - switch (theMenuItem) { - case EDITCUT: - SIOUXDoEditCut(); - break; - case EDITCOPY: - SIOUXDoEditCopy(); - break; - case EDITPASTE: - SIOUXDoEditPaste(); - break; - case EDITCLEAR: - SIOUXDoEditClear(); - break; - case EDITSELECTALL: - SIOUXDoEditSelectAll(); - break; - default: - break; - } - break; - default: - break; - } - - if (SIOUXSettings.standalone) - HiliteMenu(0); -} - -#pragma bool reset - -/* Change Record - * BB 01/10/93 removed all TextEdit calls which called toolbox glue - * so that users no longer needed to include MacOS.lib ... - * BB 04/10/93 rewrote savetext so that all file saving was done using - * inline toolbox calls therefore no MacOS.lib ... - * JH 30/12/95 removed uses of OLDROUTINENAMES - * bk 09/02/96 added Universal Headers incase macheaders not the prefix - * mm 970428 Replaced missing statement allowing copying to take place. - * cc 991108 added ra Carbon Changes done 990611 - * cc 991109 changed TARGET_CARBON to TARGET_API_MAC_CARBON - * cc 991111 added ra & jww suggestions for functions no longer in carbon - * cc 991115 updated and deleted outdated carbon comments - * cc 991116 bug fix (IR9907-1420) - changed line 398 to if (!sfReply.sfGood) - * ra 000114 SIOUXSetupMenus calls InvalMenuBar for Carbon - * JWW 000531 Don't add a Quit item in the File menu if running on OS X -*/ \ No newline at end of file diff --git a/lsh/MacOS/src/console.stubs.c b/lsh/MacOS/src/console.stubs.c deleted file mode 100755 index 20803c6..0000000 --- a/lsh/MacOS/src/console.stubs.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * console.stubs.c - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#ifndef __CONSOLE__ -#include -#endif -#include -#include -#include -#include - -/* - * The following four functions provide the UI for the console package. - * Users wishing to replace SIOUX with their own console package need - * only provide the four functions below in a library. - */ - -/* - * extern short InstallConsole(short fd); - * - * Installs the Console package, this function will be called right - * before any read or write to one of the standard streams. - * - * short fd: The stream which we are reading/writing to/from. - * returns short: 0 no error occurred, anything else error. - */ - -short InstallConsole(short fd) -{ -#pragma unused (fd) - - return 0; -} - -/* - * extern void RemoveConsole(void); - * - * Removes the console package. It is called after all other streams - * are closed and exit functions (installed by either atexit or _atexit) - * have been called. Since there is no way to recover from an error, - * this function doesn't need to return any. - */ - -void RemoveConsole(void) -{ -} - - -/* - * can_read - */ - -Boolean can_read() -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( !context ) { - return 0; - } - return context->_gConsoleInBufLen || context->_gConsoleInEOF; -} - -/* - * extern long WriteCharsToConsole(char *buffer, long n); - * - * Writes a stream of output to the Console window. This function is - * called by write. - * - * char *buffer: Pointer to the buffer to be written. - * long n: The length of the buffer to be written. - * returns short: Actual number of characters written to the stream, - * -1 if an error occurred. - */ - -long WriteCharsToConsole(char *buffer, long n) -{ - long written = 0; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - char *buf = buffer; - char c; - - if ( !context ) { - return 0; - } - - if ( context->_gConsoleOutBufMax ) { - if ( context->_socket == -1 ) { - while (n > 0) { - if ( context->_gConsoleOutBufLen < context->_gConsoleOutBufMax ) { - long len = n; - if ( len > context->_gConsoleOutBufMax - context->_gConsoleOutBufLen ) { - len = context->_gConsoleOutBufMax - context->_gConsoleOutBufLen; - } - if ( context->_convertLFs ) { - long inlen = 0; - long outlen = context->_gConsoleOutBufLen; -/* - while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) { - c = buf[inlen++]; - if ( c == 0x0a ) { - context->_gConsoleOutBuf[outlen++] = 0x0d; - } - context->_gConsoleOutBuf[outlen++] = c; - } -*/ - while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) { - c = buf[inlen++]; - if ( context->_lastCR ) { - if ( c != 0x0a && c != 0x1b ) - context->_gConsoleOutBuf[outlen++] = 0x0a; - } else { - if ( c == 0x0a ) - context->_gConsoleOutBuf[outlen++] = 0x0d; - } - context->_gConsoleOutBuf[outlen++] = c; - context->_lastCR = (c == 0x0d); - } - - context->_gConsoleOutBufLen = outlen; - buf += inlen; - written += inlen; - n -= inlen; - } else { - BlockMoveData( buf, context->_gConsoleOutBuf + context->_gConsoleOutBufLen, len); - /*context->_lastCR = (buf[len-1] == 0x0d);*/ - context->_gConsoleOutBufLen += len; - buf += len; - written += len; - n -= len; - } - if ( context->_port != -1 ) { - /*netputuev(CONCLASS, CONDATA, context->_port,0);*/ - } - } - ssh2_sched(); - } - } - } else { - written = n; - } -/* - syslog( 0, "write\n"); - dumpln(0, 0, buffer, written); -*/ - return written; -} - -/* - * extern long ReadCharsFromConsole(char *buffer, long n); - * - * Reads from the Console into a buffer. This function is called by - * read. - * - * char *buffer: Pointer to the buffer which will recieve the input. - * long n: The maximum amount of characters to be read (size of - * buffer). - * returns short: Actual number of characters read from the stream, - * -1 if an error occurred. - */ - -long ReadCharsFromConsole(char *buffer, long n) -{ - long len = 0; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( !context ) { - return 0; - } - - if ( context->_gConsoleInBufMax ) { - if ( context->_socket == -1 ) { - while (!len && n > 0) { - if (context->_gConsoleInEOF) { - buffer[0] = -1; - return 0; - } - if (context->_gConsoleInBufLen) { - len = context->_gConsoleInBufLen; - if ( len > n ) { - len = n; - } - BlockMoveData( context->_gConsoleInBuf, buffer, len ); - context->_gConsoleInBufLen -= len; - if ( context->_gConsoleInBufLen ) { - BlockMoveData( context->_gConsoleInBuf + len, context->_gConsoleInBuf, context->_gConsoleInBufLen ); - } - } - ssh2_sched(); - } - } - } else { - buffer[0] = -1; - } -/* - syslog( 0, "read\n"); - dumpln(0, 0, buffer, len); -*/ - return len; -} - -/* - * extern char *__ttyname(long fildes); - * - * Return the name of the current terminal (only valid terminals are - * the standard stream (ie stdin, stdout, stderr). - * - * long fildes: The stream to query. - * - * returns char*: A pointer to static global data which contains a C string - * or NULL if the stream is not valid. - */ - -extern char *__ttyname(long fildes) -{ -#pragma unused (fildes) - /* all streams have the same name */ - static char *__devicename = "null device"; - - if (fildes >= 0 && fildes <= 2) - return (__devicename); - - return (0L); -} - -/* Begin mm 981218 */ -/* -* -* int kbhit() -* -* returns true if any keyboard key is pressed without retrieving the key -* used for stopping a loop by pressing any key -*/ -int kbhit(void) -{ - return 0; -} - -/* -* -* int getch() -* -* returns the keyboard character pressed when an ascii key is pressed -* used for console style menu selections for immediate actions. -*/ -int getch(void) -{ - return 0; -} - -/* -* void clrscr() -* -* clears screen -*/ -void clrscr() -{ - return; -} -/* End mm 981218 */ - -/* Change record - * mm 981218 Added stubs for kbhit(), getch(), and clrscr() -*/ diff --git a/lsh/MacOS/src/dlltest.c b/lsh/MacOS/src/dlltest.c deleted file mode 100755 index 1a3dc6d..0000000 --- a/lsh/MacOS/src/dlltest.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * dlltest.c - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#include -#include -#include -#include -#include - -#include - -#include "lsh_dll.h" - -struct tctx { - lshctx *lsh_ctx; -}; - - -char password[64]; - -void my_hdlevt(long userData, EventRecord *userEvent, long sleepTime) -{ - EventRecord theEvent; - lshctx *lsh_ctx = ((struct tctx *)userData)->lsh_ctx; - char buf[4096]; - int count; - char c; - - if ( userEvent == NULL ) { - if ( SIOUXUseWaitNextEvent ) { - WaitNextEvent( everyEvent, &theEvent, 0, NULL ); - } else { - #if TARGET_API_MAC_OS8 - SystemTask(); - #endif - GetNextEvent( everyEvent, &theEvent ); - } - userEvent = &theEvent; - } - - /* something to send ? */ - if ( (userEvent->what != keyDown && userEvent->what != autoKey) && !(userEvent->modifiers & cmdKey) ) { - SIOUXHandleOneEvent( userEvent ); - } else { - c = userEvent->message & charCodeMask; - lsh_write( lsh_ctx, &c, 1 ); - } - - /* something received ? */ - while ((count = lsh_read(lsh_ctx, buf, 4096)) != 0) { - printf("%.*s", count, buf); - fflush(stdout); - } - -} - -void my_log(long userData, const char *message) -{ - printf("%s", message); -} - -char *my_getpass(long userData, const char *prompt) -{ - printf("%s", prompt); - fflush(stdout); - fgets(password, sizeof(password), stdin); - password[strlen(password) - 1] = 0; - return password; -} - - -int my_yes_or_no(long userData, const char *prompt, int def) -{ - char input[32]; - - printf("%s", prompt); - fflush(stdout); - do { - fgets(input, sizeof(input), stdin); - if (input[0] == 'y' || input[0] == 'Y') - return 1; - else if (input[0] == 'n' || input[0] == 'N') - return 0; - printf("please anwser with 'y' or 'n' : "); - fflush(stdout); - } while (1); - return def; -} - - -int main(void) -{ - struct tctx my_ctx; - lshctx *lsh_ctx; - char argstr[1024]; - - SIOUXSettings.autocloseonquit = 0; - SIOUXSettings.asktosaveonclose = 0; - SIOUXSettings.showstatusline = 1; - SIOUXSettings.columns = 80; - SIOUXSettings.rows = 48; - SIOUXSettings.toppixel = 50; - SIOUXSettings.leftpixel = 20; - SIOUXSettings.tabspaces = 8; - - strcpy(argstr, "lsh"); - strcat(argstr, " -ljps"); - - strcat(argstr, " --host-db \""); - strcat(argstr, lsh_getprefsd()); - strcat(argstr, "known_hosts\""); - - strcat(argstr, " --capture-to \""); - strcat(argstr, lsh_getprefsd()); - strcat(argstr, "known_hosts\""); - - strcat(argstr, " --sloppy-host-authentication"); - - strcat(argstr, " -call -zzlib"); - - //strcat(argstr, " --verbose --trace --debug"); - strcat(argstr, " --verbose"); - - strcat(argstr, " --stdin dev:ttyin --stdout dev:ttyout --stderr dev:ttyerr"); - - strcat(argstr, " 192.168.1.41"); - - //strcat(argstr, " cvs -d/home/macssh server"); - - printf("argstr : %s\n", argstr); - fflush(stdout); - - lsh_ctx = lsh_new(argstr, my_hdlevt, my_log, my_getpass, my_yes_or_no, 0L, (long)&my_ctx); - - if ( lsh_ctx != NULL ) { - - my_ctx.lsh_ctx = lsh_ctx; - - printf("lsh_new ok\n"); - fflush(stdout); - - while (!SIOUXQuitting && lsh_running(lsh_ctx)) { - - lsh_yield(); - - my_hdlevt((long)&my_ctx, NULL, 0L); - - } - - /* this kills the thread if still running */ - lsh_delete(lsh_ctx ); - - } else { - printf("lsh_new failed\n"); - fflush(stdout); - } - - printf("done\n"); - fflush(stdout); - - return 0; -} diff --git a/lsh/MacOS/src/lsh_context.h b/lsh/MacOS/src/lsh_context.h deleted file mode 100755 index a183811..0000000 --- a/lsh/MacOS/src/lsh_context.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef _LSH_CONTEXT_H -#define _LSH_CONTEXT_H - -#include - -#include -#include -#include -#include - -#include "lsh_types.h" -#include "lsh.h" -#include "exception.h" - -#define MAXFILESCOUNT 64 -#define CONSOLEBUFSIZE 16384 -#define ERROR_BUF_SIZE 512 - -typedef struct lshcontext { - int _port; // for BetterTelnet's networking - void *_userdata; // available for callers - pthread_t _thread; - int _forward; - int _localport; - int _listener; // for cvs - int _socket; // for cvs - int _rcmdline; // for cvs - jmp_buf *_pexitbuf; - char *_gMemPool; - int _filesTable[MAXFILESCOUNT]; - struct termios _mactermios; - - Boolean _gConsoleInEOF; - Boolean _convertLFs; - Boolean _stripCRs; - char _lastCR; - - void *_insock; - long _gConsoleInBufLen; - long _gConsoleInBufMax; - char _gConsoleInBuf[CONSOLEBUFSIZE]; - long _gConsoleOutBufLen; - long _gConsoleOutBufMax; - char _gConsoleOutBuf[CONSOLEBUFSIZE]; - - struct lsh_object *_all_objects; - unsigned _number_of_objects; - unsigned _number_of_strings; - unsigned _live_objects; - - int _quiet_flag; - int _verbose_flag; - int _trace_flag; - int _debug_flag; - - int _error_fd; - UINT8 _error_buffer[ERROR_BUF_SIZE]; - UINT32 _error_pos; - const struct exception *(*_error_write)(int fd, UINT32 length, const UINT8 *data); - - int _tracing; - int _verbosing; - int _debugging; - - sig_atomic_t _window_changed; - - char *_envv[4]; // "HOME", "LOGNAME", "TERM", "DISPLAY" - char _term[64]; // home and logname never change - char _display[64]; // home and logname never change - char _kpassword[64]; - int _kindex; - int _pindex; - char _keychainprompt[256]; - - struct lshcontext *_self; - -} lshcontext; - -extern pthread_key_t ssh2threadkey; - - -#define all_objects (((lshcontext *)pthread_getspecific(ssh2threadkey))->_all_objects) -#define number_of_objects (((lshcontext *)pthread_getspecific(ssh2threadkey))->_number_of_objects) -#define number_of_strings (((lshcontext *)pthread_getspecific(ssh2threadkey))->_number_of_strings) - -#define live_objects (((lshcontext *)pthread_getspecific(ssh2threadkey))->_live_objects) - -#define quiet_flag (((lshcontext *)pthread_getspecific(ssh2threadkey))->_quiet_flag) -#define verbose_flag (((lshcontext *)pthread_getspecific(ssh2threadkey))->_verbose_flag) -#define trace_flag (((lshcontext *)pthread_getspecific(ssh2threadkey))->_trace_flag) -#define debug_flag (((lshcontext *)pthread_getspecific(ssh2threadkey))->_debug_flag) - -#define error_fd (((lshcontext *)pthread_getspecific(ssh2threadkey))->_error_fd) -#define error_buffer (((lshcontext *)pthread_getspecific(ssh2threadkey))->_error_buffer) -#define error_pos (((lshcontext *)pthread_getspecific(ssh2threadkey))->_error_pos) -#define error_write (((lshcontext *)pthread_getspecific(ssh2threadkey))->_error_write) - -#define tracing (((lshcontext *)pthread_getspecific(ssh2threadkey))->_tracing) -#define verbosing (((lshcontext *)pthread_getspecific(ssh2threadkey))->_verbosing) -#define debugging (((lshcontext *)pthread_getspecific(ssh2threadkey))->_debugging) -#define convertLFs (((lshcontext *)pthread_getspecific(ssh2threadkey))->_convertLFs) -#define stripCRs (((lshcontext *)pthread_getspecific(ssh2threadkey))->_stripCRs) - - -#define window_changed (((lshcontext *)pthread_getspecific(ssh2threadkey))->_window_changed) - -#endif diff --git a/lsh/MacOS/src/lsh_dll.c b/lsh/MacOS/src/lsh_dll.c deleted file mode 100755 index 78b696f..0000000 --- a/lsh/MacOS/src/lsh_dll.c +++ /dev/null @@ -1,1501 +0,0 @@ -/* - * lsh_dll.c - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include "format.h" -#include "io.h" -#include "tty.h" -#include "xalloc.h" -#include "werror.h" - -#include -/*#include */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include - - - -#include "MemPool.h" - - -extern pascal OSErr __initialize(CFragConnectionID connID); -extern pascal void __terminate(void); - -pascal OSErr __lsh_initialize(const CFragInitBlock * theInitBlock); -pascal void __lsh_terminate(void); - -FSSpec gDLLFileSpec; - -Boolean gLogStdIO = 0; - -extern int appl_main(int argc, char **argv); -extern char *applname; -extern char *defargstr; - -extern void ssh2_init(); -extern void ssh2_terminate(); -extern void ssh2_sched(); -extern void ssh2_doevent(EventRecord *theEvent, long sleepTime); - -extern void close_all_files(); - -extern char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *parID); - -extern const struct exception *write_raw(int fd, UINT32 length, const UINT8 *data); - -typedef void(*hdlevtfunc)( long userData, EventRecord *userEvent, long sleepTime); -typedef void(*logfunc)( long userData, const char *message); -typedef char *(*getpassfunc)( long userData, const char *prompt); -typedef int (*yesornofunc)( long userData, const char *prompt, int def); - -typedef struct lshctx { - pthread_t pthread; - lshcontext *context; - char *argstr; - unsigned long flags; - hdlevtfunc hdlevt; - getpassfunc getpass; - logfunc log; - yesornofunc yes_or_no; - long userData; -} lshctx; - -enum { - kLSHConvertLFs = 0x1, - kLSHStripCRs = 0x2 -}; - -lshctx *lsh_new(char *argstr, hdlevtfunc hdlevt, logfunc log, getpassfunc getpass, - yesornofunc yes_or_no, unsigned long flags, long userData); -void lsh_delete(lshctx *ctx); -void lsh_yield(); -int lsh_read(lshctx *ctx, void *buffer, long inbytes); -long lsh_write(lshctx *ctx, const void *buffer, long inbytes); -char *lsh_getprefsd(); -lshctx *lsh_current(); -Boolean lsh_running(lshctx *ctx); - - -const struct termios defaulttermios = { - 0x00000300, /* c_iflag; input mode flags */ - 0x00000003, /* c_oflag; output mode flags */ - 0x00000b0d, /* c_cflag; control mode flags */ - 0x000005cf, /* c_lflag; local mode flags */ - 0, /* c_line; line discipline (== c_cc[19]) */ - { - 0x03,0x1c,0x7f,0x15,0x04,0x01,0x00,0x00, - 0x00,0x00,0x17,0x12,0x1a,0x11,0x13,0x16, - 0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 - }, /* c_cc[NCCS]; control characters */ - 0, /* c_ispeed; input speed */ - 0 /* c_ospeed; output speed */ -}; - -static char *envp[] = { - "HOME", - "LOGNAME", - "TERM" -}; - -static char *envv[] = { - "", - "", - "vt220" -}; - -char homepath[256]; -char username[256]; - - -pthread_key_t ssh2threadkey = NULL; - - -/* - * getenv - */ - -char *getenv(const char *var) -{ - int i; - for (i = 0; i < sizeof(envp) / sizeof(char *); i++) { - if (strcmp(var, envp[i]) == 0) { - return envv[i]; - } - } - return NULL; -} - -/* - * openlog - */ - -void openlog(const char *id, int flags, int type) -{ -} - -#define BUF_SIZE 1024 -/* - * syslog - */ - -void syslog( int priority, const char *format, ...) -{ - lshctx *ctx = lsh_current(); - if ( ctx && ctx->log ) { - va_list args; - char string_buf[BUF_SIZE]; - int len; - - va_start(args, format); - len = vsnprintf(string_buf, BUF_SIZE - 2, format, args); - assert(len < BUF_SIZE - 1); - va_end(args); - if ( len > 0 ) { -/* -#if TRACE_IT - // add CR if string is not finished - if (string_buf[len - 1] != '\r' && string_buf[len - 1] != '\n') { - string_buf[len++] = '\r'; - } - plnt_putbuf(string_buf, len, 'TEXT', NULL, 0); -#else - string_buf[len++] = 0; - printf("%s", string_buf); -#endif -*/ - (*ctx->log)( ctx->userData, string_buf ); - } - } -} - -/* - * strerror - */ - -char * strerror(int errnum) -{ - static char errstr[64]; - - return(__strerror(errnum, errstr)); -} - -/* - * __strerror - */ - -char * __strerror(int errnum, char * str) -{ - switch (errnum) - { - //123456789_123456789_123456789_123456789_123456789_ - case EPERM: strcpy(str, "Operation not permitted"); break; - case ENOENT: strcpy(str, "No such file or directory"); break; - case ESRCH: strcpy(str, "No such process"); break; - case EINTR: strcpy(str, "Interrupted system call"); break; - case EIO: strcpy(str, "Input/output error"); break; - case ENXIO: strcpy(str, "Device not configured"); break; - case E2BIG: strcpy(str, "Argument list too long"); break; - case ENOEXEC: strcpy(str, "Exec format error"); break; - case EBADF: strcpy(str, "Bad file descriptor"); break; - case ECHILD: strcpy(str, "No child processes"); break; - case EDEADLK: strcpy(str, "Resource deadlock avoided"); break; - /* 11 was EAGAIN */ - case ENOMEM: strcpy(str, "Cannot allocate memory"); break; - case EACCES: strcpy(str, "Permission denied"); break; - case EFAULT: strcpy(str, "Bad address"); break; - case ECANCELED: strcpy(str, "Operation cancelled"); break; - case EBUSY: strcpy(str, "Device busy"); break; - case EEXIST: strcpy(str, "File exists"); break; - case EXDEV: strcpy(str, "Cross-device link"); break; - case ENODEV: strcpy(str, "Operation not supported by device"); break; - case ENOTDIR: strcpy(str, "Not a directory"); break; - case EISDIR: strcpy(str, "Is a directory"); break; - case EINVAL: strcpy(str, "Invalid argument"); break; - case ENFILE: strcpy(str, "Too many open files in system"); break; - case EMFILE: strcpy(str, "Too many open files"); break; - case ENOTTY: strcpy(str, "Inappropriate ioctl for device"); break; - case EFBIG: strcpy(str, "File too large"); break; - case ENOSPC: strcpy(str, "No space left on device"); break; - case ESPIPE: strcpy(str, "Illegal seek"); break; - case EROFS: strcpy(str, "Read-only file system"); break; - case EMLINK: strcpy(str, "Too many links"); break; - case EPIPE: strcpy(str, "Broken pipe"); break; - -/* math software */ - case EDOM: strcpy(str, "Numerical argument out of domain"); break; - case ERANGE: strcpy(str, "Result too large"); break; - -/* non-blocking and interrupt i/o */ - case EAGAIN: strcpy(str, "Resource temporarily unavailable"); break; - /*case EWOULDBLOCK: strcpy(str, "Operation would block"); break;*/ - case EINPROGRESS: strcpy(str, "Operation now in progress"); break; - case EALREADY: strcpy(str, "Operation already in progress"); break; - -/* ipc/network software -- argument errors */ - case ENOTSOCK: strcpy(str, "Socket operation on non-socket"); break; - case EDESTADDRREQ: strcpy(str, "Destination address required"); break; - case EMSGSIZE: strcpy(str, "Message too long"); break; - case EPROTOTYPE: strcpy(str, "Protocol wrong type for socket"); break; - case ENOPROTOOPT: strcpy(str, "Protocol not available"); break; - case EPROTONOSUPPORT: strcpy(str, "Protocol not supported"); break; - case ESOCKTNOSUPPORT: strcpy(str, "Socket type not supported"); break; - case EOPNOTSUPP: strcpy(str, "Operation not supported"); break; - case EPFNOSUPPORT: strcpy(str, "Protocol family not supported"); break; - case EAFNOSUPPORT: strcpy(str, "Address family not supported by protocol family"); break; - case EADDRINUSE: strcpy(str, "Address already in use"); break; - case EADDRNOTAVAIL: strcpy(str, "Can't assign requested address"); break; - -/* ipc/network software -- operational errors */ - case ENETDOWN: strcpy(str, "Network is down"); break; - case ENETUNREACH: strcpy(str, "Network is unreachable"); break; - case ENETRESET: strcpy(str, "Network dropped connection on reset"); break; - case ECONNABORTED: strcpy(str, "Software caused connection abort"); break; - case ECONNRESET: strcpy(str, "Connection reset by peer"); break; - case ENOBUFS: strcpy(str, "No buffer space available"); break; - case EISCONN: strcpy(str, "Socket is already connected"); break; - case ENOTCONN: strcpy(str, "Socket is not connected"); break; - case ESHUTDOWN: strcpy(str, "Can't send after socket shutdown"); break; - case ETOOMANYREFS: strcpy(str, "Too many references: can't splice"); break; - case ETIMEDOUT: strcpy(str, "Operation timed out"); break; - case ECONNREFUSED: strcpy(str, "Connection refused"); break; - - case ELOOP: strcpy(str, "Too many levels of symbolic links"); break; - case ENAMETOOLONG: strcpy(str, "File name too long"); break; - -/* should be rearranged */ - case EHOSTDOWN: strcpy(str, "Host is down"); break; - case EHOSTUNREACH: strcpy(str, "No route to host"); break; - case ENOTEMPTY: strcpy(str, "Directory not empty"); break; - - case ENOLCK: strcpy(str, "No locks available"); break; - case ENOSYS: strcpy(str, "Function not implemented"); break; - -#ifndef _POSIX_SOURCE - /*case ELAST: strcpy(str, "Must be equal largest errno"); break;*/ -#endif /* _POSIX_SOURCE */ - default: sprintf(str, "Unknown Error (%d)", errnum); break; - } - - return(str); -} - -/* - * __assertion_failed - */ -void __assertion_failed(char const *condition, char const *filename, int lineno) -{ - fprintf(stderr, "Assertion (%s) failed in \"%s\" on line %d\n", condition, filename, lineno); - if ( pthread_getspecific(ssh2threadkey) ) { - abort(); - } else { - Debugger(); - #undef abort - abort(); - #define abort macosabort - } -} - -/* - * strsignal - */ - -char * strsignal(int signo) -{ - static char errstr[__max_errstr]; - - sprintf(errstr, "Signal no (%d)", signo); - return 0L; -} - -/* - * get_context_listener - */ - -int get_context_listener() -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( context ) { - return context->_listener; - } - return -1; -} - -/* - * getexitbuf - */ - -void setexitbuf(jmp_buf *exitbuf) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( context && context->_self == context ) { - context->_pexitbuf = exitbuf; - } -} - -/* - * getexitbuf - */ - -jmp_buf *getexitbuf() -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( context && context->_self == context ) { - return context->_pexitbuf; - } - return NULL; -} - -/* - * exit - */ - -void exit(int result UNUSED) -{ - jmp_buf *exitbuf; - - if (exitbuf = getexitbuf()) { - longjmp( *exitbuf, 1 ); - } - /* should never go here... */ - Debugger(); -} - -/* - * abort - */ - -void abort(void) -{ -/* - extern int __aborting; - - raise(SIGABRT); - - __aborting = 1; -*/ - exit(EXIT_FAILURE); -} - -/* - * random - */ - -long random() -{ - return rand(); -} - - -#pragma mark - - -#undef malloc -#undef calloc -#undef realloc -#undef free -extern void *malloc(unsigned long size); -extern void *calloc(unsigned long items, unsigned long size); -extern void *realloc(void *addr, unsigned long size); -extern void free(void *addr); - -/* - * lshmalloc - */ -void *lshmalloc(unsigned long size) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - return MPmalloc(context->_gMemPool, size); - } else { - return malloc(size); - } -} - -/* - * lshcalloc - */ -void *lshcalloc(unsigned long items, unsigned long size) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - size_t tsize; - void *p; - tsize = items * size; - p = MPmalloc( context->_gMemPool, tsize ); - if ( p ) { - memset(p, '\0', tsize); - } - } else { - return calloc(items, size); - } - return NULL; -} - -/* - * lshrealloc - */ -void *lshrealloc(void *addr, unsigned long size) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - size_t orig_size; - void* p; - if (addr == 0) - return MPmalloc(context->_gMemPool, size); - orig_size = MPsize(context->_gMemPool, addr); - p = MPmalloc(context->_gMemPool, size); - orig_size = orig_size < size ? orig_size : size; - memcpy(p, addr, orig_size); - MPfree(context->_gMemPool, addr); - return p; - } else { - return realloc(addr, size); - } - return NULL; -} - -/* - * lshfree - */ -void lshfree(void *addr) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - MPfree(context->_gMemPool, addr); - } else { - free(addr); - } -} - - -#pragma mark - -/* - * we need to track open()/close()/socket() calls to close files/sockets - * upon abort/exit - */ - -/* - * add_one_file - */ - -void add_one_file(struct lshcontext *context, int fd) -{ - int i; - - /* - * GUSI problem : the sockets when closed are instead pushed in a - * queue for later removal (GUSIProcess::Instance()->QueueForClose). - * However a linger value tends to correct this behavior and wait for - * the socket to die for a maximum of 2 seconds) (alexp) - */ - { - struct linger ling = {1, 2}; - setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)); - } - - if ( fd != -1 ) { - for (i = 0; i < MAXFILESCOUNT; i++) { - if (context->_filesTable[i] == -1) { - context->_filesTable[i] = fd; - break; - } - } - } -} - -/* - * remove_one_file - */ - -void remove_one_file(struct lshcontext *context, int fd) -{ - int i; - - if ( fd != -1 ) { - for (i = 0; i < MAXFILESCOUNT; i++) { - if (context->_filesTable[i] == fd) { - context->_filesTable[i] = -1; - break; - } - } - } -} - -/* - * close_all_files - */ - -void close_all_files(lshcontext *context) -{ - int i; - - for (i = 0; i < MAXFILESCOUNT; i++) { - if (context->_filesTable[i] != -1) { - close(context->_filesTable[i]); - } - } -} - - -#pragma mark - - -/* - * my PLstrcpy - */ - -pascal StringPtr PLstrcpy(StringPtr d, ConstStr255Param s) -{ - int size; - - size = s[0] + 1; - while (size--) { - d[size] = s[size]; - } - return d; -} - - -/* - * my PLstrrchr in CWPro6 (last MPTP release) crashes in 68k ??? - */ - -pascal Ptr PLstrrchr(ConstStr255Param s, short c) -{ - int size; - - size = s[0]; - while ( size > 0 ) { - if ( s[size] == (unsigned char)c ) { - return (char *)s + size; - } - size--; - } - return NULL; -} - - -#pragma mark - - -/* - * InstallTTY - */ -int InstallTTY(int id, void *ctx, void *sock) -{ - if ( id == 0 ) { - lshcontext *context = ctx; - context->_insock = sock; - } - return 0; -} - -/* - * RemoveTTY - */ -void RemoveTTY(int id, void *ctx, void *sock) -{ - if ( id == 0 ) { - lshcontext *context = ctx; - context->_insock = NULL; - } -} - -/* - * WriteCharsToTTY - */ -int WriteCharsToTTY(int id, void *ctx, char *buffer, int n) -{ - long written = 0; - lshcontext *context = (lshcontext *)ctx; - char *buf = buffer; - char c; - - ssh2_doevent(NULL, 0L); - - if ( id == 2 ) { - // log stderr to console - syslog( 0, "%.*s", n, buffer ); - /*putlln( buffer, n );*/ - return n; - } - - if ( !context ) { - return 0; - } - - if ( context->_gConsoleOutBufMax ) { - if ( context->_socket == -1 ) { - while (n > 0) { - if ( context->_gConsoleOutBufLen < context->_gConsoleOutBufMax ) { - long len = n; - if ( len > context->_gConsoleOutBufMax - context->_gConsoleOutBufLen ) { - len = context->_gConsoleOutBufMax - context->_gConsoleOutBufLen; - } - if ( context->_stripCRs ) { - long inlen = 0; - long outlen = context->_gConsoleOutBufLen; - while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) { - c = buf[inlen++]; - if ( c != 0x0d ) - context->_gConsoleOutBuf[outlen++] = c; - } - context->_gConsoleOutBufLen = outlen; - buf += inlen; - written += inlen; - n -= inlen; - } else if ( context->_convertLFs ) { - long inlen = 0; - long outlen = context->_gConsoleOutBufLen; -/* - while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) { - c = buf[inlen++]; - if ( c == 0x0a ) { - context->_gConsoleOutBuf[outlen++] = 0x0d; - } - context->_gConsoleOutBuf[outlen++] = c; - } -*/ - while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) { - c = buf[inlen++]; - if ( context->_lastCR ) { - if ( c != 0x0a && c != 0x1b ) - context->_gConsoleOutBuf[outlen++] = 0x0a; - } else { - if ( c == 0x0a ) - context->_gConsoleOutBuf[outlen++] = 0x0d; - } - context->_gConsoleOutBuf[outlen++] = c; - context->_lastCR = (c == 0x0d); - } - - context->_gConsoleOutBufLen = outlen; - buf += inlen; - written += inlen; - n -= inlen; - } else { - BlockMoveData( buf, context->_gConsoleOutBuf + context->_gConsoleOutBufLen, len); - /*context->_lastCR = (buf[len-1] == 0x0d);*/ - context->_gConsoleOutBufLen += len; - buf += len; - written += len; - n -= len; - } - } - ssh2_sched(); - } - } - } else { - written = n; - } -/* - syslog( 0, "write\n"); - dumpln(0, 0, buffer, written); -*/ - return written; -} - -/* - * ReadCharsFromTTY - */ -int ReadCharsFromTTY(int id, void *ctx, char *buffer, int n) -{ -#pragma unused (id) - long len = 0; - lshcontext *context = (lshcontext *)ctx; - - ssh2_doevent(NULL, 0L); - - if ( !context ) { - return 0; - } - - if ( context->_gConsoleInBufMax ) { - while (!len && n > 0) { - if (context->_gConsoleInEOF) { - buffer[0] = EOF; - return 0; - } - if (context->_gConsoleInBufLen && context->_socket == -1 ) { - len = context->_gConsoleInBufLen; - if ( len > n ) { - len = n; - } - BlockMoveData( context->_gConsoleInBuf, buffer, len ); - context->_gConsoleInBufLen -= len; - if ( context->_gConsoleInBufLen ) { - BlockMoveData( context->_gConsoleInBuf + len, context->_gConsoleInBuf, context->_gConsoleInBufLen ); - } - } - ssh2_sched(); - } - } else { - buffer[0] = EOF; - } -/* - syslog( 0, "read\n"); - dumpln(0, 0, buffer, len); -*/ - return len; -} - -/* - * AvailableFromTTY - */ -int AvailableFromTTY(int id, void *ctx) -{ -#pragma unused (id) - lshcontext *context = (lshcontext *)ctx; - - ssh2_doevent(NULL, 0L); - - if ( !context ) { - return 0; - } - return context->_gConsoleInBufLen || context->_gConsoleInEOF; -} - -#pragma mark - - -/* - * tty_getwinsize : replaces tty_getwinsize from liblsh - */ -int -tty_getwinsize(int fd, struct terminal_dimensions *dims) -{ - dims->char_width = 80; - dims->char_height = 24; - dims->pixel_width = 0; - dims->pixel_height = 0; - return 1; -} - - -/* - * tcgetattr : replaces tty_getattr from liblsh - */ - -int -tcgetattr(int fd, struct termios *ios) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( context ) { - memcpy( ios, &context->_mactermios, sizeof(struct termios) ); - return 1; - } - return 0; -} - -/* - * tcsetattr : replaces tty_setattr from liblsh - */ - -int -tcsetattr(int fd, int optional_actions, const struct termios *ios) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( context ) { - memcpy( &context->_mactermios, ios, sizeof(struct termios) ); - return 1; - } - return 0; -} - - - -/* - * getpass - */ - -char *getpass( const char *prompt ) -{ - lshctx *ctx = lsh_current(); - if ( ctx && ctx->getpass ) { - return (*ctx->getpass)( ctx->userData, prompt ); - } - return NULL; -} - - -/* - * yes_or_no - */ - -int yes_or_no(struct lsh_string *s, int def, int free) -{ - lshctx *ctx = lsh_current(); - if ( ctx && ctx->yes_or_no ) { - const char *prompt = lsh_get_cstring(s); - if ( prompt ) { - def = (*ctx->yes_or_no)( ctx->userData, prompt, def ); - } - } - if ( free ) { - lsh_string_free(s); - } - return def; -} - - -/* - * ssh2_doevent - */ - -void ssh2_doevent(EventRecord *theEvent, long sleepTime) -{ - lshctx *ctx = lsh_current(); - if ( ctx && ctx->hdlevt ) { - (*ctx->hdlevt)( ctx->userData, theEvent, sleepTime ); - } -} - - -/* - * SIOUXHandleOneEvent - */ -/* moved to lsh_evt.c -short SIOUXHandleOneEvent(EventRecord *userEvent) -{ - lshctx *ctx = lsh_current(); - if ( ctx && ctx->hdlevt ) { - (*ctx->hdlevt)( ctx->userData, userEvent, 0L ); - return 1; - } - return 0; -} -*/ - -#pragma mark - - - -/* - * make_args - */ - -void make_args( char *argstr, char **tabargv, int *argc, char ***argv ) -{ - int i = 0; - int j = 0; - int quoted1 = 0; - int quoted2 = 0; - - tabargv[i++] = argstr; - - #define SEPARATOR(x) ((x) == ' ' || (x) == '\t' || (x) == 10 || (x) == 13 || (x) == 0) - #define QUOTE1(x) ((x) == '"') - #define QUOTE2(x) ((x) == '\'') - while (argstr[j]) { - if (!quoted1 && !quoted2 && SEPARATOR(argstr[j])) { - argstr[j++] = 0; - if (!SEPARATOR(argstr[j])) { - tabargv[i++] = argstr + j; - } - } else if (!quoted2 && QUOTE1(argstr[j])) { - strcpy(argstr + j, argstr + j + 1); - if (!QUOTE1(argstr[j])) - quoted1 = !quoted1; - else - j++; - } else if (!quoted1 && QUOTE2(argstr[j])) { - strcpy(argstr + j, argstr + j + 1); - if (!QUOTE2(argstr[j])) - quoted2 = !quoted2; - else - j++; - } else { - j++; - } - } - #undef SEPARATOR - #undef QUOTE - - tabargv[i] = NULL; - - *argc = i; - *argv = tabargv; -} - -/* - * make_env - */ - -void make_env( lshcontext *context ) -{ - StringHandle hstr; - int i; - - context->_envv[0] = lsh_getprefsd(); /* set home pathname */ - - /*hstr = GetString( -16413 );*/ /* get computer name */ - hstr = GetString( -16096 ); /* get user name */ - if ( hstr && *hstr ) { - i = **hstr; - BlockMoveData( *hstr + 1, username, i ); - username[i] = 0; - ReleaseResource( (Handle)hstr ); - context->_envv[1] = username; /* set user name */ - } else { - context->_envv[1] = NULL; - } - - /* set TERM variable */ - context->_envv[2] = "vt220"; -} - - - - -#pragma mark - - -/* - * lsh_key_del - */ - -void lsh_key_del(void *) -{ -} - -/* - * lsh_sighandler - */ - -void lsh_sighandler(int sig) -{ - switch (sig) { - case SIGCHLD: - case SIGCONT: - case SIGSTOP: - case SIGTSTP: - case SIGTTIN: - case SIGTTOU: - break; /* Ignore */ - default: - exit(1); - } -} - -/* - * lsh_thread - */ - -void *lsh_thread(lshctx *ctx) -{ - lshcontext *context; - jmp_buf exitbuf; - OSErr err; - char *tabargv[64]; - int argc; - char **argv; - - context = (lshcontext *)NewPtr(sizeof(lshcontext)); - if (context == NULL) { - printf("### main_thread, NewPtr lshcontext failed\n"); - return 0L; - } - if (pthread_setspecific(ssh2threadkey, context)) { - printf("### main_thread, pthread_setspecific failed\n"); - DisposePtr((Ptr)context); - return 0L; - } - - /* allocate memory pool */ - err = MPInit(65564, &context->_gMemPool, NULL); - if (err != noErr) { - printf("### main_thread, MPInit failed\n"); - DisposePtr((Ptr)context); - return 0L; - } - - context->_port = -1; - context->_userdata = ctx; - context->_thread = pthread_self(); - context->_forward = 0; - context->_localport = 0; - context->_listener = -1; - context->_socket = -1; - //context->_exitbuf = 0; - //context->_gMemPool = NULL; - memset(context->_filesTable, 0xff, sizeof(context->_filesTable)); - memcpy(&context->_mactermios, &defaulttermios, sizeof(struct termios)); - context->_gConsoleInEOF = 0; - context->_convertLFs = (ctx->flags & kLSHConvertLFs) != 0; - context->_stripCRs = (ctx->flags & kLSHStripCRs) != 0; - context->_lastCR = 0; - context->_insock = NULL; - context->_gConsoleInBufLen = 0; - context->_gConsoleInBufMax = CONSOLEBUFSIZE; - context->_gConsoleOutBufLen = 0; - context->_gConsoleOutBufMax = CONSOLEBUFSIZE; - context->_all_objects = NULL; - context->_number_of_objects = 0; - context->_live_objects = 0; - context->_quiet_flag = 0; - context->_verbose_flag = 0; - context->_trace_flag = 0; - context->_debug_flag = 0; - context->_error_fd = STDERR_FILENO; - context->_error_pos = 0; - context->_error_write = write_raw; - context->_tracing = 0; - context->_verbosing = 0; - context->_debugging = 0; - context->_window_changed = 0; - context->_kpassword[0] = 0; - context->_kindex = 0; - context->_self = context; - - ctx->context = context; - - make_args( ctx->argstr, tabargv, &argc, &argv ); - - make_env( context ); - - context->_pexitbuf = &exitbuf; - if ( !setjmp(exitbuf) ) { - /* we need to intercept SIGINT to fake 'exit' */ - struct sigaction interrupt; - memset(&interrupt, 0, sizeof(interrupt)); - interrupt.sa_handler = lsh_sighandler; - sigemptyset(&interrupt.sa_mask); - interrupt.sa_flags = 0; - if (sigaction(SIGINT, &interrupt, NULL) < 0) { - werror("warning: failed to install ssh2_sighandler for SIGINT\n"); - } - set_error_syslog(applname); - appl_main(argc, argv); - } - - ctx->context = NULL; - ctx->pthread = NULL; - - close_all_files(context); - MPDispose(context->_gMemPool); - DisposePtr((Ptr)context); - - return NULL; -} - -#pragma mark - - -/* - * lsh_new - * - * input: - * - * - argstr: argument string (see Usage below). - * - hdlevt callback to main event handler - * - log: callback for lsh logs - * - getpass: called upon password request - * - yes_or_no: called upon new host keys confirmation request - * - * returns: - * - * - opaque lshctx struct to use for further calls - * - * -------------------------------------------------------------------------------- - * - * Usage: lsh [OPTION...] host - * or: lsh [OPTION...] host command ... - * Connects to a remote machine - * - * --capture-to=File When a new hostkey is received, append an ACL - * expressing trust in the key. In sloppy mode, the - * default is captured_keys. - * --dh-keyexchange Enable DH support (default, unless SRP is being - * used). - * --host-db=Filename By default, known_hosts - * -i, --identity=Identity key Use this key to authenticate. - * --no-dh-keyexchange Disable DH support. - * --no-publickey Don't try publickey user authentication. - * --no-srp-keyexchange Disable experimental SRP support (default). - * --no-userauth Request the ssh-userauth service (default if SRP - * is used). - * --publickey Try publickey user authentication (default). - * --sloppy-host-authentication - * Allow untrusted hostkeys. - * --srp-keyexchange Enable experimental SRP support. - * --strict-host-authentication - * Never, never, ever trust an unknown hostkey. - * (default) - * --userauth Request the ssh-userauth service (default, unless - * SRP is being used). - * --debug Print huge amounts of debug information - * -q, --quiet Suppress all warnings and diagnostic messages - * --trace Detailed trace - * -v, --verbose Verbose diagnostic messages - * - * Algorithm selection: - * -c, --crypto=Algorithm - * --hostkey-algorithm=Algorithm - * --list-algorithms List supported algorithms. - * -m, --mac=Algorithm - * -z, --compression[=Algorithm] Default is zlib. - * - * -l, --user=User name Login as this user. - * -p, --port=Port Connect to this port. - * - * Actions: - * -E, --execute=command Execute a command on the remote machine - * -L, --forward-local-port=local-port:target-host:target-port - * -N, --nop No operation (suppresses the default action, which - * is to spawn a remote shell) - * -S, --shell=command Spawn a remote shell - * - * Universal not: - * -n, --no Inverts the effect of the next modifier - * - * Modifiers that apply to port forwarding: - * -g, --remote-peers Allow remote access to forwarded ports - * --no-remote-peers Disallow remote access to forwarded ports - * (default). - * - * Modifiers that apply to remote execution: - * --no-pty Don't request a remote pty. - * --no-stderr Redirect stderr to /dev/null - * --no-stdin Redirect stdin from /dev/null - * --no-stdout Redirect stdout to /dev/null - * --stderr=Filename Redirect stderr - * --stdin=Filename Redirect stdin - * --stdout=Filename Redirect stdout - * -t, --pty Request a remote pty (default). - * - * -R, --forward-remote-port=remote-port:target-host:target-port - * - * -?, --help Give this help list - * --usage Give a short usage message - * -V, --version Print program version - * - * Mandatory or optional arguments to long options are also mandatory or optional - * for any corresponding short options. - * - * Connects to the remote machine, and then performs one or more actions, i.e. - * command execution, various forwarding services. The default action is to start - * a remote interactive shell or execute a given command on the remote machine. - * - * -------------------------------------------------------------------------------- - * Sample argstr: - * - * lsh -lusername -iidentityfile --sloppy-host-authentication 192.168.1.41 - * - * *IMPORTANT* all the data after the first argument (i.e. the hostname) - * are passed as a command to launch on the server. - */ - -lshctx *lsh_new(char *argstr, hdlevtfunc hdlevt, logfunc log, getpassfunc getpass, - yesornofunc yes_or_no, unsigned long flags, long userData) -{ - pthread_attr_t attr = NULL; - lshctx *ctx = NULL; - - ssh2_init(); - - /* allocate new record */ - ctx = NewPtr(sizeof(lshctx)); - if (ctx == NULL) { - goto failed; - } - - ctx->pthread = NULL; - ctx->context = NULL; - ctx->flags = flags; - ctx->userData = userData; - - /* save argument string */ - ctx->argstr = NewPtr(strlen(argstr) + 1); - if (ctx->argstr == NULL) { - goto failed; - } - strcpy(ctx->argstr, argstr); - - ctx->hdlevt = hdlevt; - ctx->log = log; - ctx->getpass = getpass; - ctx->yes_or_no = yes_or_no; - - if (pthread_attr_init(&attr)) { - printf("### main, pthread_attr_init failed\n"); - goto failed; - } - if (pthread_key_create(&ssh2threadkey, lsh_key_del)) { - printf("### main, pthread_key_create failed\n"); - goto failed; - } - if (pthread_attr_setstacksize(&attr, 64*1024)) { - printf("### main, pthread_attr_setstacksize failed\n"); - goto failed; - } - - if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) { - printf("### main, pthread_attr_setdetachstate failed\n"); - goto failed; - } - - if (pthread_create(&ctx->pthread, &attr, (GUSIPThreadProc)lsh_thread, ctx)) { - printf("### main, pthread_create failed\n"); - goto failed; - } - pthread_attr_destroy(&attr); - - /* add this thread to local thread pool */ - /* TODO */ - - return ctx; - -failed: - if ( attr != NULL ) { - pthread_attr_destroy(&attr); - } - if ( ctx != NULL ) { - if ( ctx->argstr != NULL ) { - DisposePtr( ctx->argstr ); - } - DisposePtr( ctx ); - } - return NULL; -} - - -/* - * lsh_delete - */ - -void lsh_delete(lshctx *ctx) -{ - assert(ctx != NULL); - if ( ctx->context != NULL && ctx->pthread != NULL ) { - lshcontext *context = ctx->context; - context->_gConsoleInEOF = true; - pthread_kill( ctx->pthread, SIGINT ); - while (ctx->pthread) { - /* wait for thread to die */ - ssh2_sched(); - } - } - if ( ctx->argstr != NULL ) { - DisposePtr( ctx->argstr ); - } - DisposePtr( ctx ); -} - - -/* - * lsh_yield - */ - -void lsh_yield() -{ - ssh2_sched(); -} - - -/* - * lsh_read - */ - -/* should it be blocking ? */ - -int lsh_read(lshctx *ctx, void *buffer, long inbytes) -{ - lshcontext *context = (lshcontext *)ctx->context; - long n = inbytes; - long outbytes; - - outbytes = 0; - if ( context && context->_gConsoleOutBufLen ) { - outbytes = context->_gConsoleOutBufLen; - if ( outbytes > n ) { - outbytes = n; - } - BlockMoveData( context->_gConsoleOutBuf, buffer, outbytes ); - context->_gConsoleOutBufLen -= outbytes; - if ( context->_gConsoleOutBufLen ) { - BlockMoveData( context->_gConsoleOutBuf + outbytes, context->_gConsoleOutBuf, context->_gConsoleOutBufLen ); - /*netputuev( CONCLASS, CONDATA, pnum,0);*/ /* more data to get */ - } - } - return outbytes; -} - - -int lsh_canread(lshctx *ctx) -{ - lshcontext *context = (lshcontext *)ctx->context; - long outbytes = 0; - - if ( context && context->_gConsoleOutBufLen ) - { - outbytes = context->_gConsoleOutBufLen; - } - return outbytes; -} - - -/* - * lsh_write - */ - -long lsh_write(lshctx *ctx, const void *buffer, long inbytes) -{ - lshcontext *context = (lshcontext *)ctx->context; - long n = inbytes; - long outbytes; - - outbytes = 0; - if ( context ) { - while ( n ) { - if ( context->_gConsoleInBufLen < context->_gConsoleInBufMax ) { - long len = n; - if ( len > context->_gConsoleInBufMax - context->_gConsoleInBufLen ) - len = context->_gConsoleInBufMax - context->_gConsoleInBufLen; - BlockMoveData( buffer, context->_gConsoleInBuf + context->_gConsoleInBufLen, len); - context->_gConsoleInBufLen += len; - (char *)buffer += len; - n -= len; - outbytes += len; - - if (context->_insock) { - extern void GUSIWakeupTTYSocket( void *insock ); - GUSIWakeupTTYSocket(context->_insock); - } - - } else { - ssh2_sched(); - } - } - } - return outbytes; -} - -int lsh_canwrite(lshctx *ctx) -{ - lshcontext *context = (lshcontext *)ctx->context; - long outbytes = 0; - - if ( context && context->_gConsoleInBufLen ) - { - outbytes = context->_gConsoleInBufLen; - } - return outbytes; -} - - -/* - * lsh_getprefsd - */ - -char *lsh_getprefsd() -{ - char *buf; - short vRefNum; - long dirID; - - buf = getprefsd( "MacSSH", homepath, sizeof(homepath), &vRefNum, &dirID ); - if ( !buf ) { - buf = getcwd(homepath, sizeof(homepath)); - } - return buf; -} - -/* - * lsh_current - */ - -lshctx *lsh_current() -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context ) { - return (lshctx *)context->_userdata; - } - return NULL; -} - -/* - * lsh_running - */ - -Boolean lsh_running(lshctx *ctx) -{ - return ctx->pthread != NULL; -} - -void lsh_init(void) -{ - ssh2_init(); -} - -void lsh_terminate(void) -{ - ssh2_terminate(); -} - -/* - * __lsh_initialize - */ - -pascal OSErr __lsh_initialize(const CFragInitBlock * theInitBlock) -{ - OSErr result = noErr; - - if(CFragHasFileLocation(theInitBlock->fragLocator.where) && - theInitBlock->fragLocator.u.onDisk.fileSpec != 0L) - { - gDLLFileSpec = *theInitBlock->fragLocator.u.onDisk.fileSpec; - } - - /* check for OT 1.1.1 */ - /* TODO */ - - /* check for Thread Manager */ - /* TODO */ - - srand(time(NULL)); - - result = __initialize(theInitBlock->connectionID); - - return result; -} - - -/* - * __lsh_terminate - */ - -pascal void __lsh_terminate(void) -{ - __terminate(); - - /* kill pending threads in local thread pool */ - /* TODO */ -} - diff --git a/lsh/MacOS/src/lsh_dll.cp b/lsh/MacOS/src/lsh_dll.cp deleted file mode 100755 index 130f04c..0000000 --- a/lsh/MacOS/src/lsh_dll.cp +++ /dev/null @@ -1,310 +0,0 @@ -#include "lshprefix.h" -#include "lsh_context.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *dirID); - -void ssh2_sched(); - -void ssh2_doevent(EventRecord *theEvent, long sleepTime); - -#ifdef __cplusplus -} -#endif - - -/* - * getprefsd return the full path of prefs directory - */ - -char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *dirID) -{ - GUSIFileSpec prefs(kPreferencesFolderType, kOnSystemDisk); - char * res; - char * out = buf; - const GUSICatInfo *info; - - if (prefs.Error()) - return GUSISetMacError(prefs.Error()), static_cast(nil); - - prefs.SetName(name); - res = prefs.FullPath(); - - if (size < strlen(res)+1) - return GUSISetPosixError(size > 0 ? ERANGE : EINVAL), - static_cast(nil); - if (!out && !(out = (char *) malloc(size))) - return GUSISetPosixError(ENOMEM), static_cast(nil); - - strcpy(out, res); - - if ( (access( out, R_OK ) == 0 || mkdir( out ) == 0) && (info = prefs.CatInfo()) != nil ) { - *vRefNum = info->DirInfo().ioVRefNum; - *dirID = info->DirInfo().ioDrDirID; - } else { - if (!buf) - free(out); - return static_cast(nil); - } - return out; -} - - -// [[select]] is quite complex, so we break it up. [[select_once]] polls all -// file descriptors once. -// -// = -static int select_once(int width, - fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - fd_set *readres, fd_set *writeres, fd_set *exceptres) -{ - bool r, w, e; - bool * canRead; - bool * canWrite; - bool * canExcept; - int count = 0; - - for (int s = 0; s < width ; ++s) { - canRead = (readfds && FD_ISSET(s,readfds)) ? &r : nil; - canWrite = (writefds && FD_ISSET(s,writefds)) ? &w : nil; - canExcept = (exceptfds && FD_ISSET(s,exceptfds)) ? &e : nil; - if (canRead || canWrite || canExcept) { - GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s); - - if (!GUSI_ASSERT_EXTERNAL(sock, ("Socket %d closed in select\n", s))) - return count ? count : -1; - - r = w = e = false; - if (sock->select(canRead, canWrite, canExcept)) - count += (canRead && *canRead)+(canWrite && *canWrite)+(canExcept && *canExcept); - if (r) - FD_SET(s,readres); - if (w) - FD_SET(s,writeres); - if (e) - FD_SET(s,exceptres); - } - } - - return count; -} -// [[select_sleep]] sleeps as long as [[canSleep]] allows. -// -// = -static bool select_sleep(bool canSleep) -{ - if (canSleep) { - return GUSIContext::Yield(kGUSIBlock); - } else { - return GUSIContext::Yield(kGUSIPoll); - } -} -// [[select_forever]] keeps calling [[select_once]] until one of the file -// descriptors triggers. -// -// = -static int select_forever(bool canSleep, int width, - fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - fd_set *readres, fd_set *writeres, fd_set *exceptres) -{ - int count; - - for (;;) { - count = - select_once(width, - readfds, writefds, exceptfds, - readres, writeres, exceptres); - if (count) - break; - if (select_sleep(canSleep)) - return GUSISetPosixError(EINTR); - } - - return count; -} - -extern "C" jmp_buf *getexitbuf(); -extern "C" void *setexitbuf(jmp_buf *exitbuf); - -// [[select_timed]] keeps calling [[select_once]] until one of the file -// descriptors triggers or the timer runs out. -// -// = -static int select_timed(bool canSleep, int width, - fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - fd_set *readres, fd_set *writeres, fd_set *exceptres, - struct timeval *timeout) -{ - int count; - - // we must delete the timer before exiting current thread - // otherwise, bad things occur. - jmp_buf *oldexitbuf = getexitbuf(); - jmp_buf exitbuf; - setexitbuf(&exitbuf); - int result; - { - GUSITimer timer; - if ( !(result = setjmp(exitbuf)) ) { - timer.MicroSleep(GUSITime(*timeout).Get(GUSITime::usecs)); - for (;;) { - count = - select_once(width, - readfds, writefds, exceptfds, - readres, writeres, exceptres); - if (count || timer.Expired()) - break; - if (select_sleep(canSleep)) - return GUSISetPosixError(EINTR); - } - } - } - setexitbuf(oldexitbuf); - if ( result ) { - longjmp( *oldexitbuf, result ); - } -/* - GUSITimer timer; - - timer.MicroSleep(GUSITime(*timeout).Get(GUSITime::usecs)); - for (;;) { - count = - select_once(width, - readfds, writefds, exceptfds, - readres, writeres, exceptres); - if (count || timer.Expired()) - break; - if (select_sleep(canSleep)) - return GUSISetPosixError(EINTR); - } -*/ - return count; -} -// Even so, [[select]] is still a heavyweight. -// - -// = -int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -{ - bool canSleep = true; - int count = 0; - fd_set readres; FD_ZERO(&readres); - fd_set writeres; FD_ZERO(&writeres); - fd_set exceptres; FD_ZERO(&exceptres); - - // = - for (int s = 0; s < width ; ++s) - if ( (readfds && FD_ISSET(s,readfds)) - || (writefds && FD_ISSET(s,writefds)) - || (exceptfds && FD_ISSET(s,exceptfds)) - ) - if (!GUSIDescriptorTable::LookupSocket(s)) - return -1; - // = - for (int s = 0; s < width ; ++s) - if (GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s)) { - bool r = readfds && FD_ISSET(s,readfds); - bool w = writefds && FD_ISSET(s,writefds); - bool e = exceptfds && FD_ISSET(s,exceptfds); - - if (r || w || e) - canSleep = sock->pre_select(r, w, e) && canSleep; - } - - // we must call post_select before exiting current thread - // to remove the contexts. otherwise, bad things occur. - jmp_buf *oldexitbuf = getexitbuf(); - jmp_buf exitbuf; - setexitbuf(&exitbuf); - int result; - if ( !(result = setjmp(exitbuf)) ) { - - if (!timeout) { - count = - select_forever(canSleep, width, - readfds, writefds, exceptfds, - &readres, &writeres, &exceptres); - } else if (timeout->tv_sec || timeout->tv_usec) { - count = - select_timed(canSleep, width, - readfds, writefds, exceptfds, - &readres, &writeres, &exceptres, - timeout); - } else { - count = - select_once(width, - readfds, writefds, exceptfds, - &readres, &writeres, &exceptres); - GUSIContext::Yield(kGUSIYield); - } - - } - - // = - - // this is needed because next loop always exits with errno = EBADF - // which overwrite potential EINTR signal. - int saveErrno = errno; - - for (int s = 0; s < width ; ++s) - if (GUSISocket * sock = GUSIDescriptorTable::LookupSocket(s)) { - bool r = readfds && FD_ISSET(s,readfds); - bool w = writefds && FD_ISSET(s,writefds); - bool e = exceptfds && FD_ISSET(s,exceptfds); - - if (r || w || e) - sock->post_select(r, w, e); - } - - errno = saveErrno; - - setexitbuf(oldexitbuf); - if ( result ) { - longjmp( *oldexitbuf, result ); - } - - // = - if (readfds) - *readfds = readres; - if (writefds) - *writefds = writeres; - if (exceptfds) - *exceptfds = exceptres; - - return count; -} - -/* - * ssh2_sched - */ - -void ssh2_sched() -{ - sched_yield(); -} - -/* - * GUSIHandleNextEvent - */ - -void GUSIHandleNextEvent(long sleepTime) -{ - ssh2_doevent(NULL, sleepTime); -} diff --git a/lsh/MacOS/src/lsh_dll.h b/lsh/MacOS/src/lsh_dll.h deleted file mode 100755 index 2b77109..0000000 --- a/lsh/MacOS/src/lsh_dll.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - * lsh_dll.h - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ -#ifndef LSH_DLL_H_ -#define LSH_DLL_H_ - -#include - -typedef void *lshctx; - -typedef void (*hdlevtfunc)(long userData, EventRecord *userEvent, long sleepTime); -typedef void (*logfunc)(long userData, const char *message); -typedef char *(*getpassfunc)(long userData, const char *prompt); -typedef int (*yesornofunc)(long userData, const char *prompt, int def); - -enum { - kLSHConvertLFs = 0x1, - kLSHStripCRs = 0x2 -}; - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * lsh_new - * - * input: - * - * - argstr: argument string (see Usage below). - * - hdlevt callback to main event handler - * - log: callback for lsh logs - * - getpass: called upon password request - * - yes_or_no: called upon new host keys confirmation request - * - * returns: - * - * - opaque lshctx struct to use for further calls - * - * -------------------------------------------------------------------------------- - * - * Usage: lsh [OPTION...] host - * or: lsh [OPTION...] host command ... - * Connects to a remote machine - * - * --capture-to=File When a new hostkey is received, append an ACL - * expressing trust in the key. In sloppy mode, the - * default is captured_keys. - * --dh-keyexchange Enable DH support (default, unless SRP is being - * used). - * --host-db=Filename By default, known_hosts - * -i, --identity=Identity key Use this key to authenticate. - * --no-dh-keyexchange Disable DH support. - * --no-publickey Don't try publickey user authentication. - * --no-srp-keyexchange Disable experimental SRP support (default). - * --no-userauth Request the ssh-userauth service (default if SRP - * is used). - * --publickey Try publickey user authentication (default). - * --sloppy-host-authentication - * Allow untrusted hostkeys. - * --srp-keyexchange Enable experimental SRP support. - * --strict-host-authentication - * Never, never, ever trust an unknown hostkey. - * (default) - * --userauth Request the ssh-userauth service (default, unless - * SRP is being used). - * --debug Print huge amounts of debug information - * -q, --quiet Suppress all warnings and diagnostic messages - * --trace Detailed trace - * -v, --verbose Verbose diagnostic messages - * - * Algorithm selection: - * -c, --crypto=Algorithm - * --hostkey-algorithm=Algorithm - * --list-algorithms List supported algorithms. - * -m, --mac=Algorithm - * -z, --compression[=Algorithm] Default is zlib. - * - * -l, --user=User name Login as this user. - * -p, --port=Port Connect to this port. - * - * Actions: - * -E, --execute=command Execute a command on the remote machine - * -L, --forward-local-port=local-port:target-host:target-port - * -N, --nop No operation (suppresses the default action, which - * is to spawn a remote shell) - * -S, --shell=command Spawn a remote shell - * - * Universal not: - * -n, --no Inverts the effect of the next modifier - * - * Modifiers that apply to port forwarding: - * -g, --remote-peers Allow remote access to forwarded ports - * --no-remote-peers Disallow remote access to forwarded ports - * (default). - * - * Modifiers that apply to remote execution: - * --no-pty Don't request a remote pty. - * --no-stderr Redirect stderr to /dev/null - * --no-stdin Redirect stdin from /dev/null - * --no-stdout Redirect stdout to /dev/null - * --stderr=Filename Redirect stderr - * --stdin=Filename Redirect stdin - * --stdout=Filename Redirect stdout - * -t, --pty Request a remote pty (default). - * - * -R, --forward-remote-port=remote-port:target-host:target-port - * - * -?, --help Give this help list - * --usage Give a short usage message - * -V, --version Print program version - * - * Mandatory or optional arguments to long options are also mandatory or optional - * for any corresponding short options. - * - * Connects to the remote machine, and then performs one or more actions, i.e. - * command execution, various forwarding services. The default action is to start - * a remote interactive shell or execute a given command on the remote machine. - * - * -------------------------------------------------------------------------------- - * Sample argstr: - * - * lsh -lusername -iidentityfile --sloppy-host-authentication 192.168.1.41 - * - * *IMPORTANT* all the data after the first argument (i.e. the hostname) - * are passed as a command to launch on the server. - */ - -lshctx *lsh_new(char *argstr, hdlevtfunc hdlevt, logfunc log, getpassfunc getpass, - yesornofunc yes_or_no, unsigned long flags, long userData); - -void lsh_delete(lshctx *ctx); - -void lsh_yield(); - -int lsh_read(lshctx *ctx, void *buffer, long inbytes); - -long lsh_write(lshctx *ctx, const void *buffer, long inbytes); - -int lsh_canread(lshctx *ctx); - -int lsh_canwrite(lshctx *ctx); - -char *lsh_getprefsd(); - -lshctx *lsh_current(); - -Boolean lsh_running(lshctx *ctx); - -void lsh_init(void); - -void lsh_terminate(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lsh/MacOS/src/lsh_evt.c b/lsh/MacOS/src/lsh_evt.c deleted file mode 100644 index 0463968..0000000 --- a/lsh/MacOS/src/lsh_evt.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * lsh_evt.c - * (c) 2000 Jean-Pierre Stierlin. - * - * 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 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 should 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 - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include - -/* - * SIOUXHandleOneEvent - */ - -short SIOUXHandleOneEvent(EventRecord *userEvent) -{ - ssh2_doevent(userEvent, 0L); - return 1; -} - diff --git a/lsh/MacOS/src/lsh_maccvs.cpp b/lsh/MacOS/src/lsh_maccvs.cpp deleted file mode 100644 index 4490f01..0000000 --- a/lsh/MacOS/src/lsh_maccvs.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * GUSIPatches.cp - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include -#include -#include - -#include "GUSIMSLSetup.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void GUSIwithTTYSockets(); -void GUSIwithoutTTYSockets(); - -void ssh2_init(); -void ssh2_terminate(); - -#ifdef __cplusplus -} -#endif - -/* - * - This project is intended to work with MacCvs (http://www.cvsgui.org) - * - It exports the lsh program as a shared library, thanks to Jean-Pierre. - * - The lsh API is hooked up to the cvs shared library of cvs and provide - * the SSH2 authentication. - * - * Questions : alexandre parenteau (aubonbeurre@hotmail.com) - */ - -/* - * ssh2_init - */ - -static Boolean sGUSISetup = false; - -void ssh2_init() -{ - - if ( !sGUSISetup ) { - - GUSIwithTTYSockets(); - - sGUSISetup = true; - } -} - -void ssh2_terminate() -{ - if ( sGUSISetup ) { - - GUSIwithoutTTYSockets(); - - sGUSISetup = false; - } -} diff --git a/lsh/MacOS/src/lshprefix.carb.h b/lsh/MacOS/src/lshprefix.carb.h deleted file mode 100644 index 8fbf81d..0000000 --- a/lsh/MacOS/src/lshprefix.carb.h +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "lshprefix.h" diff --git a/lsh/MacOS/src/lshprefix.h b/lsh/MacOS/src/lshprefix.h deleted file mode 100755 index 44fae10..0000000 --- a/lsh/MacOS/src/lshprefix.h +++ /dev/null @@ -1,380 +0,0 @@ -/* prefix.h */ - -/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP - systems. This function is required for `alloca.c' support on those systems. - */ -/* #undef CRAY_STACKSEG_END */ - -/* Define if using alloca.c. */ -/* #undef C_ALLOCA */ - -/* Define to support non-standard packets of ssh2 */ -#define DATAFELLOWS_WORKAROUNDS 1 - -/* Define to enable sanity checking on memory allocation and casting */ -#define DEBUG_ALLOC 0 - -/* Define to enable tracing */ -#define DEBUG_TRACE 1 - -/* Define if the `getpgrp' function takes no argument. */ -/* #undef GETPGRP_VOID */ - -/* Define if AI_NUMERICHOST exists */ -/* #undef HAVE_AI_NUMERICHOST */ - -/* Define if you have alloca, as a function or macro. */ -#define HAVE_ALLOCA 1 - -/* Define if you have and it should be used (not on Ultrix). */ -#define HAVE_ALLOCA_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_ARGP_H */ - -/* Define if you have the cfmakeraw function. */ -/* #undef HAVE_CFMAKERAW */ - -/* Define if you have the header file. */ -/* #undef HAVE_CRYPT_H */ - -/* Define if you don't have vprintf but do have _doprnt. */ -/* #undef HAVE_DOPRNT */ - -/* Define if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define if you have the gai_strerror function. */ -/* #undef HAVE_GAI_STRERROR */ - -/* Define if the compiler understands __attribute__ */ -/* #undef HAVE_GCC_ATTRIBUTE */ - -/* Define if the compiler understands __FUNCTION__ */ -/* #define HAVE_GCC_FUNCTION 1 */ - -/* Define if you have the getaddrinfo function. */ -/* #undef HAVE_GETADDRINFO */ - -/* Define if you have the getnameinfo function. */ -/* #undef HAVE_GETNAMEINFO */ - -/* Define if you have the getrusage function. */ -/* #undef HAVE_GETRUSAGE */ - -/* Define if you have the getspnam function. */ -/* #undef HAVE_GETSPNAM */ - -/* Define if you have the gettimeofday function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define if you have the header file. */ -/* #undef HAVE_GMP2_GMP_H */ - -/* Define if you have the header file. */ -#define HAVE_GMP_H 1 - -/* Define if you have the inet_aton function. */ -#define HAVE_INET_ATON 1 - -/* Define if you have the header file. */ -/* #undef HAVE_INTTYPES_H */ - -/* Define if you have the header file. */ -/* #undef HAVE_KRB5_H */ - -/* Define if you have the crypt library (-lcrypt). */ -/* #undef HAVE_LIBCRYPT */ - -/* Define if you have the nsl library (-lnsl). */ -/* #undef HAVE_LIBNSL */ - -/* Define if you have the socket library (-lsocket). */ -/* #undef HAVE_LIBSOCKET */ - -/* Define if you have the util library (-lutil). */ -/* #undef HAVE_LIBUTIL */ - -/* Define if you have the header file. */ -/* #undef HAVE_LIBUTIL_H */ - -/* Define if you have the `Xau' library (-lXau). */ -/* #undef HAVE_LIBXAU */ - -/* Define if you have the `xnet' library (-lxnet). */ -/* #undef HAVE_LIBXNET */ - -/* Define if you have the z library (-lz). */ -/* #undef HAVE_LIBZ */ - -/* Define if you have the login function. */ -/* #undef HAVE_LOGIN */ - -/* Define if you have the logout function. */ -/* #undef HAVE_LOGOUT */ - -/* Define if you have the logwtmp function. */ -/* #undef HAVE_LOGWTMP */ - -/* Define if you have the header file. */ -/* #undef HAVE_MEMORY_H */ - -/* Define if you have the memxor function. */ -/* #undef HAVE_MEMXOR */ - -/* Define if you have the openpty function. */ -/* #undef HAVE_OPENPTY */ - -/* Define if you have the poll function. */ -/* #undef HAVE_POLL */ - -/* Define if you have the header file. */ -/* #undef HAVE_POLL_H */ - -/* Define if you have the header file. */ -/* #undef HAVE_PTY_H */ - -/* Define if you have the select function. */ -#define HAVE_SELECT 1 - -/* Define if you have the header file. */ -/* #undef HAVE_SHADOW_H */ - -/* Define if you have the socket function. */ -#define HAVE_SOCKET 1 - -/* Define if you have the strerror function. */ -/* #undef HAVE_STDLIB_H */ - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the header file. */ -/* #undef HAVE_STRINGS_H */ - -/* Define if you have the header file. */ -/* #undef HAVE_STRING_H */ - -/* Define if you have the header file. */ -/* #undef HAVE_STROPTS_H */ - -/* Define if you have the strsignal function. */ -#define HAVE_STRSIGNAL 1 - -/* Define if you have the strtol function. */ -#define HAVE_STRTOL 1 - -/* Define if `ut_addr' is member of `struct utmp'. */ -/* #undef HAVE_STRUCT_UTMP_UT_ADDR */ - -/* Define if `ut_addr_v6' is member of `struct utmp'. */ -/* #undef HAVE_STRUCT_UTMP_UT_ADDR_V6 */ - -/* Define if `ut_host' is member of `struct utmp'. */ -/* #undef HAVE_STRUCT_UTMP_UT_HOST */ - -/* Define if `ut_name' is member of `struct utmp'. */ -/* #undef HAVE_STRUCT_UTMP_UT_NAME */ - -/* Define if `ut_user' is member of `struct utmp'. */ -/* #undef HAVE_STRUCT_UTMP_UT_USER */ - -/* syslog() available? */ -#define HAVE_SYSLOG 1 - -/* Define if you have the header file. */ -/* #define HAVE_SYSLOG_H 1 */ - -/* Define if you have the header file. */ -/* #undef HAVE_SYS_POLL_H */ - -/* Define if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define if a we have working UNIX98 pty handling */ -/* #undef HAVE_UNIX98_PTYS */ - -/* Define if you have the header file. */ -/* #undef HAVE_UTMPX_H */ - -/* Define if you have the header file. */ -/* #undef HAVE_UTMP_H */ - -/* Define if you have the vprintf function. */ -#define HAVE_VPRINTF 1 - -/* Define if you have the vsnprintf function. */ -#define HAVE_VSNPRINTF 1 - -/* Define if you have the header file. */ -/* #undef HAVE_X11_XAUTH_H */ - -/* Define if you have the header file. */ -#define HAVE_ZLIB_H 1 - -/* Name of package */ -#define PACKAGE "lsh" - -/* The installation prefix. */ -/* #undef PREFIX */ - -/* Traditional BSD pty handling */ -/* #undef PTY_BSD_SCHEME */ - -/* Possible first characters in a /dev/ptyXX name */ -/* #undef PTY_BSD_SCHEME_FIRST_CHARS */ - -/* Possible second characters in a /dev/ptyXX name */ -/* #undef PTY_BSD_SCHEME_SECOND_CHARS */ - -/* sbin directory */ -/* #undef SBINDIR */ - -/* Define to indicate that shutdown seems to work properly */ -#define SHUTDOWN_WORKS_WITH_UNIX_SOCKETS 1 - -/* The number of bytes in a int. */ -#define SIZEOF_INT 4 - -/* The number of bytes in a long. */ -#define SIZEOF_LONG 4 - -/* The number of bytes in a short. */ -#define SIZEOF_SHORT 2 - -/* Location of the SSH1 daemon */ -/* #undef SSHD1 */ - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ -/* #undef STACK_DIRECTION */ - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define if you can safely include both and . */ -#define TIME_WITH_SYS_TIME 1 - -/* Version number of package */ -#define VERSION "1.3.4" - -/* Define to enable authentication agent forwarding */ -/* #undef WITH_AGENT_FORWARD */ - -/* Use gcov */ -/* #undef WITH_GCOV */ - -/* Define if IDEA should be used */ -/* #define WITH_IDEA 1 */ - -/* For Ipv6 support */ -/* #undef WITH_IPV6 */ - -/* For kerberos */ -/* #undef WITH_KERBEROS */ - -/* Define to enable pty support */ -#define WITH_PTY_SUPPORT 1 - -/* Define if SRP should be supported */ -#define WITH_SRP 1 - -/* Define to enable fallback to SSH1 */ -/* #undef WITH_SSH1_FALLBACK */ - -/* Define to enable tcp forwarding */ -#define WITH_TCP_FORWARD 1 - -/* For utmp support */ -/* #undef WITH_UTMP */ - -/* Define to enable x11 forwarding */ -#define WITH_X11_FORWARD 1 - -/* Define if zlib should be used */ -#define WITH_ZLIB 1 - -/* Define if your processor stores words with the most significant - byte first (like Motorola and SPARC, unlike Intel and VAX). */ -#define WORDS_BIGENDIAN 1 - - -/* Define to empty if the keyword does not work. */ -/* #undef const */ - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define as __inline if that's what the C compiler calls it. */ -/* #undef inline */ - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* Length type used by getsockopt */ -/* #undef socklen_t */ - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - - -/* MacOS Specific */ - -#define MACOS 1 -#define LSH 1 -/*#define HAVE_STDTTY_FILENO 1*/ -/*#define STDTTY_FILENO 0*/ -#define SIOUX_USE_WASTE 1 - -#define exit macosexit -#define abort macosabort - -#define zlib_alloc ssh_xcalloc -#define zlib_free ssh_xfree - -#define malloc lshmalloc -#define calloc lshcalloc -#define realloc lshrealloc -#define free lshfree - -#include -#include - -#include "version.h" - -/* -#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN -#define WORDS_BIGENDIAN 1 -#endif -*/ - -extern char *strsignal(int signo); - -/* bug in metrowerks 68k alloca function */ -#ifndef powerc -#define ALLOCA_68K_BUG 1 -//#if __MWERKS__ -#if __MC68K__ /* begin mm 980512 */ -#include -extern void *__alloca(size_t size:__d0) : __d0; -#endif /* end mm 980512 */ -//#endif -#endif - -#if ALLOCA_68K_BUG -inline asm long GetSP() { - move.l sp,d0 -} -#define ALLOCA_START(x) register long x = GetSP() -#define ALLOCA_FREE(x) asm { move.l x,sp } -#else -#define ALLOCA_START(x) -#define ALLOCA_FREE(x) -#endif diff --git a/lsh/MacOS/src/macos_random.c b/lsh/MacOS/src/macos_random.c deleted file mode 100755 index eabf0be..0000000 --- a/lsh/MacOS/src/macos_random.c +++ /dev/null @@ -1,288 +0,0 @@ -/* unix_random.c - * - * $Id$ - * - * Randomness polling on unix, using ideas from Peter Gutmann's - * cryptlib. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "randomness.h" - -#include "crypto.h" -#include "reaper.h" -#include "xalloc.h" -#include "werror.h" - -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include -#include -#include -#include - -#ifdef HAVE_POLL -# if HAVE_POLL_H -# include -# elif HAVE_SYS_POLL_H -# include -# endif -#else -# include "jpoll.h" -#endif - -/* Workaround for some version of FreeBSD. */ -#ifdef POLLRDNORM -# define MY_POLLIN (POLLIN | POLLRDNORM) -#else /* !POLLRDNORM */ -# define MY_POLLIN POLLIN -#endif /* !POLLRDNORM */ - -#include - -enum poll_status { POLL_NO_POLL, POLL_RUNNING, POLL_FINISHED, POLL_FAILED }; - -#include "unix_random.c.x" - - -#ifdef MACOS -#include -#include -#include -#include -#include -#ifdef __powerc -// The timebase is available through mfspr on 601, mftb on later chips. -// Motorola recommends that an 601 implementation map mftb to mfspr -// through an exception, but I haven't tested to see if MacOS actually -// does this. We only sample the lower 32 bits of the timer (i.e. a -// few minutes of resolution) -unsigned long GetPPCTimer(); -asm unsigned long GetPPCTimer() -{ - mftb r3 // Available on 603 and later. -} -#endif -#endif - - -#define HASH_OBJECT(h, x) HASH_UPDATE((h), sizeof(x), (UINT8 *) &(x)) - - -static unsigned long -GetUSecLow() -{ -#ifdef __powerc - return GetPPCTimer(); -#else - UnsignedWide usec; - Microseconds(&usec); - return usec.lo; -#endif -} - -#if TARGET_API_MAC_CARBON -typedef struct -{ - unsigned *count; - struct hash_instance *hash; -} flattenTravInfos; - -static pascal OSErr collectionFlattenProc(SInt32 size, void *data, void *refCon) -{ - flattenTravInfos *infos = (flattenTravInfos *)refCon; - HASH_UPDATE(infos->hash, size, (UINT8 *)data); - *infos->count += size / 8; - return noErr; -} -#endif - - - -static unsigned -do_unix_random_slow(struct random_poll *s, struct hash_instance *hash) -{ - CAST(unix_random, self, s); - - unsigned count; - time_t now; - unsigned long tick; - Point mouseLoc; - ProcessSerialNumber psn; - ProcessInfoRec pinfo; - Str255 pname; - FSSpec pfspec; -#if TARGET_API_MAC_CARBON - WindowPtr window; - Collection collection = NewCollection(); - CollectionFlattenUPP coltraversal = NewCollectionFlattenUPP(collectionFlattenProc); - flattenTravInfos flattenInfos; -#else - const WindowRecord *window; - const VCB *vcb; -#endif - - now = time( NULL ); - tick = GetUSecLow(); - GetMouse( &mouseLoc ); - - count = 0; - - HASH_OBJECT(hash, now); - HASH_OBJECT(hash, tick); - HASH_OBJECT(hash, mouseLoc); - count += 12; - - psn.highLongOfPSN = 0; - psn.lowLongOfPSN = kNoProcess; - if ( GetNextProcess( &psn ) == noErr ) { - do { - pinfo.processInfoLength = sizeof(ProcessInfoRec); - pinfo.processName = pname; - pinfo.processAppSpec = &pfspec; - if ( GetProcessInformation(&psn, &pinfo) == noErr ) { - HASH_OBJECT(hash, pinfo); - HASH_UPDATE(hash, *pname + 1, (UINT8 *)pname); - HASH_OBJECT(hash, pfspec); - count += (sizeof(pinfo) + *pname + 1 + sizeof(pfspec)) / 8; - } - } while ( GetNextProcess(&psn) == noErr ); - } - -#if TARGET_API_MAC_CARBON - flattenInfos.count = &count; - flattenInfos.hash = hash; - window = GetWindowList(); - while ( window && collection && coltraversal ) { - EmptyCollection(collection); - StoreWindowIntoCollection(window, collection); - FlattenCollection(collection, coltraversal, &flattenInfos); - window = GetNextWindow(window); - } - - if(collection) - DisposeCollection(collection); - if(coltraversal) - DisposeCollectionFlattenUPP(coltraversal); -#else - window = (const WindowRecord *)LMGetWindowList(); - while ( window ) { - HASH_OBJECT(hash, *window); - count += sizeof(WindowRecord) / 8; - window = window->nextWindow; - } - - vcb = (const VCB *) GetVCBQHdr()->qHead; - while ( vcb ) { - HASH_OBJECT(hash, *vcb); - count += sizeof(VCB) / 8; - vcb = (const VCB *)vcb->qLink; - } -#endif - - return count; -} - -static unsigned -do_unix_random_fast(struct random_poll *s, struct hash_instance *hash) -{ - CAST(unix_random, self, s); - unsigned count = 0; - -#if HAVE_GETRUSAGE - { - struct rusage rusage; - if (getrusage(RUSAGE_SELF, &rusage) < 0) - fatal("do_unix_random_fast: getrusage() failed: (errno = %i) %z\n", - errno, STRERROR(errno)); - - HASH_OBJECT(hash, rusage); - count += 1; - } -#endif /* HAVE_GETRUSAGE */ -#if HAVE_GETTIMEOFDAY - { - struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) - fatal("do_unix_random_fast: gettimeofday failed(errno = %i) %z\n", - errno, STRERROR(errno)); - - HASH_OBJECT(hash, tv); - } -#endif /* HAVE_GETTIMEOFDAY */ - - { - /* Fallback that is useful if nothing else works. Count the number - * of slow polls between time() ticks, and count one bit of - * entropy if we have more than 2 calls or more than two seconds - * between calls. */ - - time_t now = time(NULL); - unsigned long tick = GetUSecLow(); - self->time_count++; - if (now != self->previous_time) - { - if ( (self->time_count > 2) || ((now - self->previous_time) > 2)) - count++; - - HASH_OBJECT(hash, now); - HASH_OBJECT(hash, tick); - HASH_OBJECT(hash, self->time_count); - - self->time_count = 0; - self->previous_time = now; - } - } - - return count; -} - -static void do_unix_random_background(struct random_poll *s) -{ - CAST(unix_random, self, s); - -} - -/* Using a NULL reaper argument is ok. It must be supplied only if the - * application is using a reaper, as that may get to our child process - * before we can waitpid it. */ - -struct random_poll * -make_unix_random(struct reap *reaper) -{ - NEW(unix_random, self); - - self->super.slow = do_unix_random_slow; - self->super.fast = do_unix_random_fast; - self->super.background = do_unix_random_background; - - self->reaper = reaper; - - self->status = POLL_NO_POLL; - self->previous_time = time(NULL); - self->time_count = 0; - - return &self->super; -} diff --git a/lsh/MacOS/src/macosmain.c b/lsh/MacOS/src/macosmain.c deleted file mode 100755 index 14b8a45..0000000 --- a/lsh/MacOS/src/macosmain.c +++ /dev/null @@ -1,956 +0,0 @@ -/* macosmain.c - * - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include "format.h" -#include "io.h" -#include "tty.h" -#include "xalloc.h" -#include "werror.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "PasswordDialog.h" -#include "MemPool.h" - -// we need atEOF to re-enable stdin after ctrl-d -extern Boolean atEOF; -extern Boolean gSIOUXTerminalMode; -extern Boolean SIOUXQuitting; - -Boolean gLogStdIO = 0; - -extern int appl_main(int argc, char **argv); -extern char *applname; -extern char *defargstr; - -extern void ssh2_init(); -extern void close_all_files(); - -extern const struct exception * -write_raw(int fd, UINT32 length, const UINT8 *data); - - -const struct termios defaulttermios = { - 0x00000300, /* c_iflag; input mode flags */ - 0x00000003, /* c_oflag; output mode flags */ - 0x00000b0d, /* c_cflag; control mode flags */ - 0x000005cf, /* c_lflag; local mode flags */ - 0, /* c_line; line discipline (== c_cc[19]) */ - { - 0x03,0x1c,0x7f,0x15,0x04,0x01,0x00,0x00, - 0x00,0x00,0x17,0x12,0x1a,0x11,0x13,0x16, - 0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 - }, /* c_cc[NCCS]; control characters */ - 0, /* c_ispeed; input speed */ - 0 /* c_ospeed; output speed */ -}; - -static char *envp[] = { - "HOME", - "LOGNAME", - "TERM" -}; - -static char *envv[] = { - "", - "", - "vt220" -}; - -static char *tabargv[128]; -static char argstr[1024]; -static char currentdir[1024]; - -pthread_key_t ssh2threadkey = NULL; - - -/* - * getenv - */ - -char *getenv(const char *var) -{ - int i; - for (i = 0; i < sizeof(envp) / sizeof(char *); i++) { - if (strcmp(var, envp[i]) == 0) { - return envv[i]; - } - } - return NULL; -} - -/* - * openlog - */ - -void openlog(const char *id, int flags, int type) -{ -} - -#define BUF_SIZE 1024 -/* - * syslog - */ - -void syslog( int priority, const char *format, ...) -{ - va_list args; - char string_buf[BUF_SIZE]; - int len; - - va_start(args, format); - len = vsnprintf(string_buf, BUF_SIZE - 2, format, args); - assert(len < BUF_SIZE - 1); - va_end(args); - if ( len > 0 ) { -#if TRACE_IT - // add CR if string is not finished - if (string_buf[len - 1] != '\r' && string_buf[len - 1] != '\n') { - string_buf[len++] = '\r'; - } - plnt_putbuf(string_buf, len, 'TEXT', NULL, 0); -#else - string_buf[len++] = 0; - printf("%s", string_buf); -#endif - } -} - -/* - * strerror - */ - -char * strerror(int errnum) -{ - static char errstr[64]; - - return(__strerror(errnum, errstr)); -} - -/* - * __strerror - */ - -char * __strerror(int errnum, char * str) -{ - switch (errnum) - { - //123456789_123456789_123456789_123456789_123456789_ - case EPERM: strcpy(str, "Operation not permitted"); break; - case ENOENT: strcpy(str, "No such file or directory"); break; - case ESRCH: strcpy(str, "No such process"); break; - case EINTR: strcpy(str, "Interrupted system call"); break; - case EIO: strcpy(str, "Input/output error"); break; - case ENXIO: strcpy(str, "Device not configured"); break; - case E2BIG: strcpy(str, "Argument list too long"); break; - case ENOEXEC: strcpy(str, "Exec format error"); break; - case EBADF: strcpy(str, "Bad file descriptor"); break; - case ECHILD: strcpy(str, "No child processes"); break; - case EDEADLK: strcpy(str, "Resource deadlock avoided"); break; - /* 11 was EAGAIN */ - case ENOMEM: strcpy(str, "Cannot allocate memory"); break; - case EACCES: strcpy(str, "Permission denied"); break; - case EFAULT: strcpy(str, "Bad address"); break; - case ECANCELED: strcpy(str, "Operation cancelled"); break; - case EBUSY: strcpy(str, "Device busy"); break; - case EEXIST: strcpy(str, "File exists"); break; - case EXDEV: strcpy(str, "Cross-device link"); break; - case ENODEV: strcpy(str, "Operation not supported by device"); break; - case ENOTDIR: strcpy(str, "Not a directory"); break; - case EISDIR: strcpy(str, "Is a directory"); break; - case EINVAL: strcpy(str, "Invalid argument"); break; - case ENFILE: strcpy(str, "Too many open files in system"); break; - case EMFILE: strcpy(str, "Too many open files"); break; - case ENOTTY: strcpy(str, "Inappropriate ioctl for device"); break; - case EFBIG: strcpy(str, "File too large"); break; - case ENOSPC: strcpy(str, "No space left on device"); break; - case ESPIPE: strcpy(str, "Illegal seek"); break; - case EROFS: strcpy(str, "Read-only file system"); break; - case EMLINK: strcpy(str, "Too many links"); break; - case EPIPE: strcpy(str, "Broken pipe"); break; - -/* math software */ - case EDOM: strcpy(str, "Numerical argument out of domain"); break; - case ERANGE: strcpy(str, "Result too large"); break; - -/* non-blocking and interrupt i/o */ - case EAGAIN: strcpy(str, "Resource temporarily unavailable"); break; - /*case EWOULDBLOCK: strcpy(str, "Operation would block"); break;*/ - case EINPROGRESS: strcpy(str, "Operation now in progress"); break; - case EALREADY: strcpy(str, "Operation already in progress"); break; - -/* ipc/network software -- argument errors */ - case ENOTSOCK: strcpy(str, "Socket operation on non-socket"); break; - case EDESTADDRREQ: strcpy(str, "Destination address required"); break; - case EMSGSIZE: strcpy(str, "Message too long"); break; - case EPROTOTYPE: strcpy(str, "Protocol wrong type for socket"); break; - case ENOPROTOOPT: strcpy(str, "Protocol not available"); break; - case EPROTONOSUPPORT: strcpy(str, "Protocol not supported"); break; - case ESOCKTNOSUPPORT: strcpy(str, "Socket type not supported"); break; - case EOPNOTSUPP: strcpy(str, "Operation not supported"); break; - case EPFNOSUPPORT: strcpy(str, "Protocol family not supported"); break; - case EAFNOSUPPORT: strcpy(str, "Address family not supported by protocol family"); break; - case EADDRINUSE: strcpy(str, "Address already in use"); break; - case EADDRNOTAVAIL: strcpy(str, "Can't assign requested address"); break; - -/* ipc/network software -- operational errors */ - case ENETDOWN: strcpy(str, "Network is down"); break; - case ENETUNREACH: strcpy(str, "Network is unreachable"); break; - case ENETRESET: strcpy(str, "Network dropped connection on reset"); break; - case ECONNABORTED: strcpy(str, "Software caused connection abort"); break; - case ECONNRESET: strcpy(str, "Connection reset by peer"); break; - case ENOBUFS: strcpy(str, "No buffer space available"); break; - case EISCONN: strcpy(str, "Socket is already connected"); break; - case ENOTCONN: strcpy(str, "Socket is not connected"); break; - case ESHUTDOWN: strcpy(str, "Can't send after socket shutdown"); break; - case ETOOMANYREFS: strcpy(str, "Too many references: can't splice"); break; - case ETIMEDOUT: strcpy(str, "Operation timed out"); break; - case ECONNREFUSED: strcpy(str, "Connection refused"); break; - - case ELOOP: strcpy(str, "Too many levels of symbolic links"); break; - case ENAMETOOLONG: strcpy(str, "File name too long"); break; - -/* should be rearranged */ - case EHOSTDOWN: strcpy(str, "Host is down"); break; - case EHOSTUNREACH: strcpy(str, "No route to host"); break; - case ENOTEMPTY: strcpy(str, "Directory not empty"); break; - - case ENOLCK: strcpy(str, "No locks available"); break; - case ENOSYS: strcpy(str, "Function not implemented"); break; - -#ifndef _POSIX_SOURCE - /*case ELAST: strcpy(str, "Must be equal largest errno"); break;*/ -#endif /* _POSIX_SOURCE */ - default: sprintf(str, "Unknown Error (%d)", errnum); break; - } - - return(str); -} - -/* - * __assertion_failed - */ -void __assertion_failed(char const *condition, char const *filename, int lineno) -{ - fprintf(stderr, "Assertion (%s) failed in \"%s\" on line %d\n", condition, filename, lineno); - if ( pthread_getspecific(ssh2threadkey) ) { - abort(); - } else { - #undef abort - abort(); - #define abort macosabort - } -} - -/* - * __msl_assertion_failed - */ -void __msl_assertion_failed(char const *condition, char const *filename, char const *funcname, int lineno) -{ - fprintf(stderr, "Assertion (%s) failed in \"%s\" on line %d\n", condition, filename, lineno); - if ( pthread_getspecific(ssh2threadkey) ) { - abort(); - } else { - #undef abort - abort(); - #define abort macosabort - } -} - - -/* - * strsignal - */ - -char * strsignal(int signo) -{ - static char errstr[__max_errstr]; - - sprintf(errstr, "Signal no (%d)", signo); -} - - - -/* - * get_context_listener - */ - -int get_context_listener() -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( context ) { - return context->_listener; - } - return -1; -} - -/* - * getexitbuf - */ - -void setexitbuf(jmp_buf *exitbuf) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( context && context->_self == context ) { - context->_pexitbuf = exitbuf; - } -} - -/* - * getexitbuf - */ - -jmp_buf *getexitbuf() -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - - if ( context && context->_self == context ) { - return context->_pexitbuf; - } - return NULL; -} - -/* - * exit - */ - -void exit(int result UNUSED) -{ - extern Boolean SIOUXQuitting; - jmp_buf *exitbuf; - - fflush(stdout); - trace("*** exit ***\n"); - fflush(stdout); - - if ( !SIOUXQuitting && (exitbuf = getexitbuf()) != NULL ) { - longjmp( *exitbuf, 1 ); - } - ExitToShell(); -} - - -/* - * abort - */ - -void abort(void) -{ -/* - extern int __aborting; - - raise(SIGABRT); - - __aborting = 1; -*/ - exit(EXIT_FAILURE); -} - -/* - * random - */ - -long random() -{ - return rand(); -} - - -#pragma mark - - -void ssh2_sched() -{ - sched_yield(); -} - -#pragma mark - - -#undef malloc -#undef calloc -#undef realloc -#undef free -extern void *malloc(unsigned long size); -extern void *calloc(unsigned long items, unsigned long size); -extern void *realloc(void *addr, unsigned long size); -extern void free(void *addr); - -/* - * lshmalloc - */ -void *lshmalloc(unsigned long size) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - return MPmalloc(context->_gMemPool, size); - } else { - return malloc(size); - } -} - -/* - * lshcalloc - */ -void *lshcalloc(unsigned long items, unsigned long size) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - size_t tsize; - void *p; - assert(context->_self == context); - tsize = items * size; - p = MPmalloc( context->_gMemPool, tsize ); - if ( p ) { - memset(p, '\0', tsize); - } - return p; - } else { - return calloc(items, size); - } - return NULL; -} - -/* - * lshrealloc - */ -void *lshrealloc(void *addr, unsigned long size) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - size_t orig_size; - void* p; - if (addr == 0) - return MPmalloc(context->_gMemPool, size); - orig_size = MPsize(context->_gMemPool, addr); - p = MPmalloc(context->_gMemPool, size); - orig_size = orig_size < size ? orig_size : size; - memcpy(p, addr, orig_size); - MPfree(context->_gMemPool, addr); - return p; - } else { - return realloc(addr, size); - } - return NULL; -} - -/* - * lshfree - */ -void lshfree(void *addr) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context && context->_gMemPool ) { - MPfree(context->_gMemPool, addr); - } else { - free(addr); - } -} - - -#pragma mark - -/* - * we need to track open()/close()/socket() calls to close files/sockets - * upon abort/exit - */ - -void add_one_file(int fd) -{ - if ( fd != -1 ) { - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context ) { - int i; - for (i = 0; i < MAXFILESCOUNT; i++) { - if (context->_filesTable[i] == -1) { - context->_filesTable[i] = fd; - break; - } - } - } - } -} - -void remove_one_file(int fd) -{ - if ( fd != -1 ) { - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context ) { - int i; - for (i = 0; i < MAXFILESCOUNT; i++) { - if (context->_filesTable[i] == fd) { - context->_filesTable[i] = -1; - break; - } - } - } - } -} - -void close_all_files() -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if ( context ) { - int i; - for (i = 0; i < MAXFILESCOUNT; i++) { - if (context->_filesTable[i] != -1) { - close(context->_filesTable[i]); - } - } - } -} - -#pragma mark - - -/* - * my PLstrcpy - */ - -pascal StringPtr PLstrcpy(StringPtr d, ConstStr255Param s) -{ - int size; - - size = s[0] + 1; - while (size--) { - d[size] = s[size]; - } - return d; -} - - -/* - * my PLstrrchr in CWPro6 (last MPTP release) crashes in 68k ??? - */ - -pascal Ptr PLstrrchr(ConstStr255Param s, short c) -{ - int size; - - size = s[0]; - while ( size > 0 ) { - if ( s[size] == (unsigned char)c ) { - return (char *)s + size; - } - size--; - } - return NULL; -} - -#pragma mark - - -/* - * InstallTTY - */ -int InstallTTY(int id, void *context) -{ -#pragma unused (id, context) - return 0; -} - -/* - * RemoveTTY - */ -void RemoveTTY(int id, void *context) -{ -#pragma unused (id, context) -} - -/* - * WriteCharsToTTY - */ -int WriteCharsToTTY(int id, void *context, char *buffer, int n) -{ -#pragma unused (id, context) - return WriteCharsToConsole(buffer, n); -} - -/* - * ReadCharsFromTTY - */ -int ReadCharsFromTTY(int id, void *context, char *buffer, int n) -{ -#pragma unused (id, context) - return ReadCharsFromConsole(buffer, n); -} - -/* - * AvailableFromTTY - */ -int AvailableFromTTY(int id, void *context) -{ -#pragma unused (id, context) - extern short gSIOUXBufSize; - if ( !gSIOUXBufSize ) { - QHdrPtr eventQueue = LMGetEventQueue(); - EvQElPtr element = (EvQElPtr)eventQueue->qHead; - // now, count the number of pending keyDown events. - while (element != nil) { - if (element->evtQWhat == keyDown || element->evtQWhat == autoKey) - return true; - element = (EvQElPtr)element->qLink; - } - return false; - } - return true; -} - -#pragma mark - - -/* - * tty_getwinsize : replaces tty_getwinsize from liblsh - */ -int -tty_getwinsize(int fd, struct terminal_dimensions *dims) -{ - FontInfo info; - - dims->char_width = SIOUXSettings.columns; - dims->char_height = SIOUXSettings.rows; - dims->pixel_width = 0; - dims->pixel_height = 0; -/* - if (!FetchFontInfo(SIOUXSettings.fontid,SIOUXSettings.fontsize,SIOUXSettings.fontface, &info)) { - dims->pixel_width = info.widMax; - dims->pixel_height = info.ascent + info.descent; - } else { - // just guess... - dims->pixel_width = 12; - dims->pixel_height = 16; - } -*/ - return 1; -} - - -/* - * tcgetattr : replaces tty_getattr from liblsh - */ -int -tcgetattr(int fd, struct termios *ios) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if (context) { - memcpy(ios, &context->_mactermios, sizeof(struct termios)); - } - return 1; -} - -/* - * tcsetattr : replaces tty_setattr from liblsh - */ -int -tcsetattr(int fd, int optional_actions, const struct termios *ios) -{ - lshcontext *context = pthread_getspecific(ssh2threadkey); - if (context) { - memcpy(&context->_mactermios, ios, sizeof(struct termios)); - } - return 1; -} - - -/* - * getpass - */ - -char *getpass( const char *prompt ) -{ - Str255 pprompt; - Str255 ppassword; - static char password[128]; - - pprompt[0] = strlen(prompt); - memcpy(pprompt + 1, prompt, pprompt[0]); - ppassword[0] = 0; - InternalBufferDialog(pprompt, ppassword); - memcpy(password, ppassword + 1, ppassword[0]); - password[ppassword[0]] = '\0'; -} - - -/* - * yes_or_no - */ - -int yes_or_no(const struct lsh_string *s, int def, int free) -{ - if (!quiet_flag) { - const char *prompt = lsh_get_cstring(s); - if (prompt) { - Str255 pprompt; - int i; - pprompt[0] = strlen(prompt); - memcpy(pprompt + 1, prompt, pprompt[0]); - for (i = 1; i <= pprompt[0]; i++) { - if (pprompt[i] == 0x0a) { - pprompt[i] = 0x0d; - } - } - def = YesNoDialog( pprompt ); - } - } - return def; -} - -#pragma mark - - - -/* - * make_args - */ - -void make_args( char *argstr, int *argc, char ***argv ) -{ - int i = 0; - int j = 0; - int quoted1 = 0; - int quoted2 = 0; - - tabargv[i++] = argstr; - - #define SEPARATOR(x) ((x) == ' ' || (x) == '\t' || (x) == 10 || (x) == 13 || (x) == 0) - #define QUOTE1(x) ((x) == '"') - #define QUOTE2(x) ((x) == '\'') - while (argstr[j]) { - if (!quoted1 && !quoted2 && SEPARATOR(argstr[j])) { - argstr[j++] = 0; - if (!SEPARATOR(argstr[j])) { - tabargv[i++] = argstr + j; - } - } else if (!quoted2 && QUOTE1(argstr[j])) { - strcpy(argstr + j, argstr + j + 1); - if (!QUOTE1(argstr[j])) - quoted1 = !quoted1; - else - j++; - } else if (!quoted1 && QUOTE2(argstr[j])) { - strcpy(argstr + j, argstr + j + 1); - if (!QUOTE2(argstr[j])) - quoted2 = !quoted2; - else - j++; - } else { - j++; - } - } - #undef SEPARATOR - #undef QUOTE - - tabargv[i] = NULL; - - *argc = i; - *argv = tabargv; - - getcwd(currentdir, 1024); // set home pathname -} - -/* - * run_app - */ - -static void run_app() -{ - lshcontext *context; - jmp_buf exitbuf; - extern Boolean SIOUXQuitting; - char moreargs[1024]; - char *pmoreargs; - int argc; - char **argv; - OSErr err; - - context = (lshcontext *)NewPtr(sizeof(lshcontext)); - if (context == NULL) { - printf("### main_thread, NewPtr lshcontext failed\n"); - return; - } - if (pthread_setspecific(ssh2threadkey, context)) { - printf("### main_thread, pthread_setspecific failed\n"); - DisposePtr((Ptr)context); - return; - } - - /* allocate memory pool */ - err = MPInit(65564, &context->_gMemPool, NULL); - if (err != noErr) { - printf("### main_thread, MPInit failed\n"); - DisposePtr((Ptr)context); - return; - } - - context->_port = -1; - context->_userdata = NULL; - context->_thread = pthread_self(); - context->_forward = 0; - context->_localport = 0; - context->_listener = -1; - context->_socket = -1; - //context->_exitbuf = 0; - //context->_gMemPool = NULL; - memset(context->_filesTable, 0xff, sizeof(context->_filesTable)); - memcpy(&context->_mactermios, &defaulttermios, sizeof(struct termios)); - context->_gConsoleInEOF = 0; - context->_convertLFs = 0; - context->_stripCRs = 0; - context->_lastCR = 0; - context->_insock = NULL; - context->_gConsoleInBufLen = 0; - context->_gConsoleInBufMax = CONSOLEBUFSIZE; - context->_gConsoleOutBufLen = 0; - context->_gConsoleOutBufMax = CONSOLEBUFSIZE; - context->_all_objects = NULL; - context->_number_of_objects = 0; - context->_number_of_strings = 0; - context->_live_objects = 0; - context->_quiet_flag = 0; - context->_verbose_flag = 0; - context->_trace_flag = 0; - context->_debug_flag = 0; - context->_error_fd = STDERR_FILENO; - context->_error_pos = 0; - context->_error_write = write_raw; - context->_tracing = 0; - context->_verbosing = 0; - context->_debugging = 0; - context->_window_changed = 0; - context->_kpassword[0] = 0; - context->_kindex = 0; - context->_self = context; - - context->_pexitbuf = &exitbuf; - if (!setjmp(&exitbuf)) { - - printf("\n\nlsh shell application\nargs (--help for info): "); - - fflush(stdout); - strcpy(argstr, applname); - strcat(argstr, " "); - atEOF = false; - gSIOUXTerminalMode = false; - fgets(moreargs, sizeof(moreargs), stdin); - gSIOUXTerminalMode = true; - moreargs[strlen(moreargs) - 1] = '\0'; - pmoreargs = moreargs; - if ( moreargs[0] == '+' || !moreargs[0] ) { - strcat(argstr, defargstr); - if ( moreargs[0] ) { - strcat(argstr, " "); - pmoreargs++; - } - } - strcat(argstr, pmoreargs); - - make_args( argstr, &argc, &argv ); - //set_error_syslog(applname); - appl_main(argc, argv); - } - - close_all_files(); - MPDispose(context->_gMemPool); - DisposePtr((Ptr)context); -} - -/* - * main_thread - */ - -void *main_thread() -{ - while (!SIOUXQuitting) { - run_app(); - } -} - -void KeyDestructor(void *) -{ -} - -/* - * main - */ - -int main() -{ - char moreargs[1024]; - char *pmoreargs; - int argc; - char **argv; - pthread_attr_t attr; - pthread_t mainthread; - -#if TARGET_CPU_68K - SetApplLimit(GetApplLimit() - 128000); /* We need more stack */ - MaxApplZone(); -#endif - - SIOUXSettings.autocloseonquit = 1; - SIOUXSettings.asktosaveonclose = 0; - SIOUXSettings.showstatusline = 1; - SIOUXSettings.columns = 80; - SIOUXSettings.rows = 48; - SIOUXSettings.toppixel = 50; - SIOUXSettings.leftpixel = 20; - SIOUXSettings.tabspaces = 8; - - srand(time(NULL)); - - ssh2_init(); - -#if 1 - - // need to flush stdout to open the window from the main thread - printf("\n"); - fflush(stdout); - - if (pthread_attr_init(&attr)) { - printf("### main, pthread_attr_init failed\n"); - return 2; - } - if (pthread_key_create(&ssh2threadkey, KeyDestructor)) { - printf("### main, pthread_key_create failed\n"); - return 2; - } - if (pthread_attr_setstacksize(&attr, 64*1024)) { - printf("### main, pthread_attr_setstacksize failed\n"); - return 2; - } - if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) { - printf("### main, pthread_attr_setdetachstate failed\n"); - return 2; - } - if (pthread_create(&mainthread, &attr, (GUSIPThreadProc)main_thread, NULL)) { - printf("### main, pthread_create failed\n"); - return 2; - } - pthread_attr_destroy(&attr); - - while (!SIOUXQuitting) { - sched_yield(); - } - -#else - while (!SIOUXQuitting) { - run_app(); - } -#endif - return 0; -} - diff --git a/lsh/MacOS/src/strcase.c b/lsh/MacOS/src/strcase.c deleted file mode 100755 index 692a9cb..0000000 --- a/lsh/MacOS/src/strcase.c +++ /dev/null @@ -1,177 +0,0 @@ -/* Metrowerks Standard Library */ - -/* - * strcase.c - * - * - * Routines - * -------- - * strcasecmp - * strncasecmp - * - * - */ - -#include -#include -#include -#include - - -#pragma ANSI_strict off -int strcasecmp(const char * str1, const char * str2) -{ -#if !__POWERPC__ && !__MIPS__ - - const unsigned char * p1 = (unsigned char *) str1; - const unsigned char * p2 = (unsigned char *) str2; - unsigned char c1, c2; - - while (toupper((c1 = *p1++)) == toupper((c2 = *p2++))) - if (!c1) - return(0); - - return(toupper(c1) - toupper(c2)); - -#elif __PPC_EABI__ || __MIPS__ - - /* - * strcmp routine designed to minimized the number of - * loads and stores. We make sure that all the loads and - * stores are properly aligned. - * - */ - register unsigned char *left = (unsigned char *)str1; - register unsigned char *right = (unsigned char *)str2; - unsigned int k1, k2, align, l1, r1, x; - - /* Check the simple case of the first byte being different. */ - l1 = toupper(*left); - r1 = toupper(*right); - if (l1 - r1) { - return (l1 - r1); - } - - /* - * If either the destination or the source are not - * aligned on the same boundary, we do a byte copy. - * Otherwise we align them to a word boundary. - */ - if ((align = ((int)left & 3)) != ((int)right & 3)) { - goto bytecopy; - } - if (align) { - /* Continuation of test of first byte. */ - if (l1 == 0) { - return (0); - } - for (align = 3 - align; align; align--) { - l1 = toupper(*(++left)); - r1 = toupper(*(++right)); - if (l1 - r1) { - return (l1 - r1); - } - if (l1 == 0) { - return (0); - } - } - left++; - right++; - } - - /* Strings are word aligned */ - - k1 = K1; - k2 = K2; -<> - /* Load a word from each string. */ - l1 = *(int*)left; - r1 = *(int*)right; - /* See comments in strcpy function. */ - x = l1 + k2; - if (x & k1) { - goto adjust; - } - while(l1 == r1) { - /* Load a word and increment strings. */ - l1 = *(++((int*)(left))); - r1 = *(++((int*)(right))); - x = l1 + k2; - if (x & k1) { - goto adjust; - } - } - /* l1 and r1 are not equal. */ - if (l1 > r1) - return (1); - return (-1); - -adjust: - l1 = *left; - r1 = *right; - if (l1 - r1) { - return (l1 - r1); - } -bytecopy: - if (l1 == 0) { - return (0); - } - do { - l1 = toupper(*(++left)); - r1 = toupper(*(++right)); - if (l1 - r1) { - return (l1 - r1); - } - if (l1 == 0) { - return (0); - } - } while (1); - -#else - - const unsigned char * p1 = (unsigned char *) str1 - 1; - const unsigned char * p2 = (unsigned char *) str2 - 1; - unsigned long c1, c2; - - while (toupper(c1 = *++p1) == toupper(c2 = *++p2)) - if (!c1) - return(0); - - return(toupper(c1) - toupper(c2)); -#endif -} -#pragma ANSI_strict reset -int strncasecmp(const char * str1, const char * str2, size_t n) -{ -#if !__POWERPC__ - - const unsigned char * p1 = (unsigned char *) str1; - const unsigned char * p2 = (unsigned char *) str2; - unsigned char c1, c2; - - n++; - - while (--n) - if (toupper(c1 = *p1++) != toupper(c2 = *p2++)) - return(toupper(c1) - toupper(c2)); - else if (!c1) - break; - -#else - - const unsigned char * p1 = (unsigned char *) str1 - 1; - const unsigned char * p2 = (unsigned char *) str2 - 1; - unsigned long c1, c2; - - n++; - - while (--n) - if (toupper(c1 = *++p1) != toupper(c2 = *++p2)) - return(toupper(c1) - toupper(c2)); - else if (!c1) - break; - -#endif - - return(0); -} diff --git a/lsh/MacOS/src/werror.c b/lsh/MacOS/src/werror.c deleted file mode 100755 index afd87fe..0000000 --- a/lsh/MacOS/src/werror.c +++ /dev/null @@ -1,759 +0,0 @@ -/* werror.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "lshprefix.h" -#include "lsh_context.h" - -#include "werror.h" - -#include "charset.h" - -/* For format_size_in_decimal */ -#include "format.h" - -#include "gc.h" -#include "io.h" -#include "parse.h" -#include "xalloc.h" - -#include -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include -#include -#include - -#if HAVE_SYSLOG_H -#include -#endif - -#ifdef MACOS -extern void abort(); -#if !HAVE_SYSLOG_H -extern void openlog( const char *id, int flags, int type ); -extern void syslog( int priority, const char *format, ... ); -#define LOG_NOTICE 1 -#define LOG_PID 1 -#define LOG_CONS 2 -#define LOG_DAEMON 1 -#endif -#endif - -/* Global flags */ -#ifndef MACOS -int trace_flag = 0; -int debug_flag = 0; -int quiet_flag = 0; -int verbose_flag = 0; -int syslog_flag = 0; -#else -extern Boolean gLogStdIO; -#endif -static const char *program_name = NULL; - -#define WERROR_TRACE -1 -#define WERROR_DEBUG -2 -#define WERROR_LOG -3 - -static const struct argp_option -werror_options[] = -{ - { "quiet", 'q', NULL, 0, "Suppress all warnings and diagnostic messages", 0 }, - { "verbose", 'v', NULL, 0, "Verbose diagnostic messages", 0}, - { "trace", WERROR_TRACE, NULL, 0, "Detailed trace", 0 }, - { "debug", WERROR_DEBUG, NULL, 0, "Print huge amounts of debug information", 0 }, - { "log-file", WERROR_LOG, "File name", 0, - "Append messages to this file.", 0}, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static error_t -werror_argp_parser(int key, char *arg, - struct argp_state *state) -{ - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_END: - case ARGP_KEY_INIT: - program_name = state->name; - break; - case 'q': - quiet_flag = 1; - break; - case 'v': - verbose_flag = 1; - break; - case WERROR_TRACE: - trace_flag = 1; - break; - case WERROR_DEBUG: - debug_flag = 1; - break; - case WERROR_LOG: - { - /* FIXME: For clients, this is right: We only get lsh-related - * messages to the log file, and child processes are not - * affected. But for the server, perhaps we should also dup - * the logfile over stderr? */ - - int fd = open(arg, O_WRONLY | O_CREAT | O_APPEND, 0666); - if (fd < 0) - argp_error(state, "Failed to open log file `%s'.", arg); - else - set_error_stream(fd); - } - } - return 0; -} - -const struct argp werror_argp = -{ - werror_options, - werror_argp_parser, - NULL, NULL, NULL, NULL, NULL -}; - -#ifndef MACOS -static int error_fd = STDERR_FILENO; - -#define BUF_SIZE 500 -static UINT8 error_buffer[BUF_SIZE]; -static UINT32 error_pos = 0; - -static const struct exception * -(*error_write)(int fd, UINT32 length, const UINT8 *data) = write_raw; -#else -#define BUF_SIZE ERROR_BUF_SIZE -#endif - -#if HAVE_SYSLOG -static const struct exception * -write_syslog(int fd UNUSED, UINT32 length, const UINT8 *data) -{ - struct lsh_string *s; - - /* Data must not contain any NUL:s */ - assert(!memchr(data, '\0', length)); - - /* NUL-terminate the string. */ - s = ssh_format("%ls", length, data); - - /* FIXME: Should we use different log levels for werror, verbose and - * debug? */ - - syslog(LOG_NOTICE, "%s", lsh_get_cstring(s)); - lsh_string_free(s); - - return NULL; -} - -/* FIXME: Delete argument and use program_name. */ -void -set_error_syslog(const char *id) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - openlog(id, LOG_PID | LOG_CONS, LOG_DAEMON); - error_write = write_syslog; - error_fd = -1; -} -#endif /* HAVE_SYSLOG */ - -static const struct exception * -write_ignore(int fd UNUSED, - UINT32 length UNUSED, const UINT8 *data UNUSED) -{ return NULL; } - -void -set_error_stream(int fd) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - error_fd = fd; - - error_write = write_raw; -} - -void -set_error_nonblocking(int fd) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (error_fd == fd) - error_write = write_raw_with_poll; -} - -int -dup_error_stream(void) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return -1; - } - if (error_fd < 0) - /* We're not writing error messages on any file; there's no - * problem. */ - return 1; - else - { - int fd = dup(error_fd); - - /* This function is used to get stderr away from the stdio fd - * range. In the unlikely event that dup returns an fd <= - * STDERR_FILENO, we treat that as an error. */ - if (fd > STDERR_FILENO) - { - io_set_close_on_exec(fd); - error_fd = fd; - return 1; - } - - if (fd >= 0) - close(fd); - - return 0; - } -} - -void -set_error_ignore(void) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - context->_error_write = write_ignore; - context->_error_fd = -1; -} - -/*#define WERROR(c, l, d) (c->_error_write(c->_error_fd, (l), (d)))*/ -static void -WERROR(lshcontext *context, int l, const UINT8 *d) -{ - int oldConvertLFs = context->_convertLFs; - if (gLogStdIO || (!context->_tracing && !context->_verbosing && !context->_debugging)) - context->_convertLFs = true; - context->_error_write(context->_error_fd, l, d); - if (gLogStdIO || (!context->_tracing && !context->_verbosing && !context->_debugging)) - context->_convertLFs = oldConvertLFs; -} - -static void -werror_flush(void) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (context->_error_pos) - { - WERROR(context, context->_error_pos, context->_error_buffer); - context->_error_pos = 0; - } -} - -static void -werror_putc(UINT8 c) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (context->_error_pos == BUF_SIZE) - werror_flush(); - - context->_error_buffer[context->_error_pos++] = c; -} - -static void -werror_write(UINT32 length, const UINT8 *msg) -{ - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (context->_error_pos + length <= BUF_SIZE) - { - memcpy(context->_error_buffer + context->_error_pos, msg, length); - context->_error_pos += length; - } - else - { - werror_flush(); - WERROR(context, length, msg); - } -} - -static void -werror_cstring(char *s) { werror_write(strlen(s), (const unsigned char *)s); } - -static void -werror_bignum(mpz_t n, int base) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - char *s = alloca(mpz_sizeinbase(n, base) + 2); - mpz_get_str(s, 16, n); - - werror_cstring(s); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static void -werror_decimal(UINT32 n) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - unsigned length = format_size_in_decimal(n); - UINT8 *buffer = alloca(length); - - format_decimal(length, buffer, n); - - werror_write(length, buffer); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static unsigned format_size_in_hex(UINT32 n); - -static void -werror_hex_digit(unsigned digit) -{ - werror_putc("0123456789abcdef"[digit]); -} - -static void -werror_hex_putc(UINT8 c) -{ - werror_hex_digit(c / 16); - werror_hex_digit(c % 16); -} - -static void -werror_hex(UINT32 n) -{ - unsigned left = 8; - - while ( (left > 1) - && !(n & 0xf0000000UL)) - { - left --; - n <<= 4; - } - - while (left--) - { - werror_hex_digit((n >> 28) & 0xf); - n <<= 4; - } -} - -static void -werror_hexdump(UINT32 length, UINT8 *data) -{ - UINT32 i = 0; - - werror("(size %i = 0x%xi)\n", length, length); - - for (i = 0; i 16) - r = 16; - - for (j = 0; j 126) ) - c = '.'; - werror_putc(c); - } - - werror_cstring("\n"); - } -} - -static void -werror_paranoia_putc(UINT8 c) -{ - switch (c) - { - case '\\': - werror_cstring("\\\\"); - break; - case '\r': - /* Ignore */ - break; - default: - if (!isprint(c)) - { - werror_putc('\\'); - werror_hex_putc(c); - break; - } - /* Fall through */ - case '\n': - werror_putc(c); - break; - } -} - -void -werror_vformat(const char *f, va_list args) -{ - if (program_name) - { - werror_write(strlen(program_name), program_name); - werror_write(2, ": "); - } - - while (*f) - { - if (*f == '%') - { - int do_hex = 0; - int do_free = 0; - int do_paranoia = 0; - int do_utf8 = 0; - - while (*++f) - switch (*f) - { - case 'x': - do_hex = 1; - break; - case 'f': - do_free = 1; - break; - case 'p': - do_paranoia = 1; - break; - case 'u': - do_utf8 = 1; - break; - default: - goto end_options; - } - end_options: - switch(*f++) - { - case '%': - werror_putc(*f); - break; - case 'i': - (do_hex ? werror_hex : werror_decimal)(va_arg(args, UINT32)); - break; - case 'c': - (do_paranoia ? werror_paranoia_putc : werror_putc)(va_arg(args, int)); - break; - case 'n': - werror_bignum(va_arg(args, MP_INT *), do_hex ? 16 : 10); - break; - case 'a': - { - int atom = va_arg(args, int); - - assert(atom); - - werror_write(get_atom_length(atom), get_atom_name(atom)); - - break; - } - case 's': - { - UINT32 length = va_arg(args, UINT32); - UINT8 *s = va_arg(args, UINT8 *); - - struct lsh_string *u = NULL; - - if (do_utf8 && !local_is_utf8()) - { - u = low_utf8_to_local(length, s, 0); - if (!u) - { - werror_cstring(""); - break; - } - length = u->length; - s = u->data; - } - if (do_hex) - { - assert(!do_paranoia); - werror_hexdump(length, s); - } - else if (do_paranoia) - { - UINT32 i; - for (i=0; i"); - break; - } - do_free = 1; - } - if (do_hex) - { - assert(!do_paranoia); - werror_hexdump(s->length, s->data); - } - else if (do_paranoia) - { - UINT32 i; - for (i=0; ilength; i++) - werror_paranoia_putc(s->data[i]); - } - else - werror_write(s->length, s->data); - - if (do_free) - lsh_string_free(s); - - break; - } - case 't': - { - struct lsh_object *o = va_arg(args, struct lsh_object *); - const char *type; - - if (!o) - type = ""; - else if (o->isa) - type = o->isa->name; - else - type = ""; - - werror_write(strlen(type), type); - - break; - } - case 'z': - { - char *s = va_arg(args, char *); - - if (do_hex) - werror_hexdump(strlen(s), s); - - else if (do_paranoia) - while (*s) - werror_paranoia_putc(*s++); - else - werror_write(strlen(s), s); - - break; - } - default: - fatal("werror_vformat: bad format string!\n"); - break; - } - } - else - werror_putc(*f++); - } -} - -void -werror(const char *format, ...) -{ - va_list args; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - /* It is somewhat reasonable to use both -q and -v. In this case - * werror()-messages should be displayed. */ - if (context->_verbose_flag || !context->_quiet_flag) - { - if (gLogStdIO || (!context->_tracing && !context->_verbosing && !context->_debugging)) { - if (!gLogStdIO) { - werror_flush(); - set_error_stream(STDERR_FILENO); - } - } - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - if (gLogStdIO || (!context->_tracing && !context->_verbosing && !context->_debugging)) { - if (!gLogStdIO) { - set_error_syslog("lsh"); - } - } - } -} - -void -trace(const char *format, ...) -{ - va_list args; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (context->_trace_flag) - { - werror_flush(); - context->_tracing = true; - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - context->_tracing = false; - } -} - -void -debug(const char *format, ...) -{ - va_list args; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (context->_debug_flag) - { - werror_flush(); - context->_debugging = true; - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - context->_debugging = false; - } -} - -void -verbose(const char *format, ...) -{ - va_list args; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if ( !context ) { - return; - } - if (context->_verbose_flag) - { - werror_flush(); - context->_verbosing = true; - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - context->_verbosing = false; - } -} - -void -fatal(const char *format, ...) -{ - va_list args; - lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); - if (context) - { - werror_flush(); - set_error_stream(STDERR_FILENO); - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - set_error_syslog("lsh"); - } - abort(); -} - -static unsigned -format_size_in_hex(UINT32 n) -{ - int i; - int e; - - /* Table of 16^(2^n) */ - static const UINT32 powers[] = { 0x10UL, 0x100UL, 0x10000UL }; - -#define SIZE (sizeof(powers) / sizeof(powers[0])) - - /* Determine the smallest e such that n < 16^e */ - for (i = SIZE - 1 , e = 0; i >= 0; i--) - { - if (n >= powers[i]) - { - e += 1UL << i; - n /= powers[i]; - } - } - -#undef SIZE - - return e+1; -} - diff --git a/lsh/Makefile.am b/lsh/Makefile.am deleted file mode 100755 index 3f399ac..0000000 --- a/lsh/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ -## Automatically generated by make_am, Wed Aug 29 23:52:04 CEST 2001 -## Process this file with automake to produce Makefile.in - -SUBDIRS = src doc misc contrib - -AUTOMAKE_OPTIONS = foreign - -# We must run make the .dist_classes and various .dist_headers after -# recompiling, but before making a dist, as they uses dependency information to -# figure out which header files should be included in the dist. - -DOTDISTS = src/.dist_classes src/.dist_headers - -MAKEFILESAM = Makefile.am doc/Makefile.am src/Makefile.am \ - src/scm/Makefile.am - -# FIXME: Use the BASH variable to execute the script. The problem is -# that the script attempts to start itselt with "$0 args". -$(MAKEFILESAM): $(addsuffix .in,$(MAKEFILESAM)) - (cd $(srcdir) && BASH=$(BASH) \ - SELF="$(BASH) ./make_am" $(BASH) ./make_am) - -$(DOTDISTS): depend - (cd $(srcdir) && BASH=$(BASH) \ - SELF="$(BASH) ./make_am" $(BASH) ./make_am --rethink) - -.PHONY: dotdists -dotdists: $(DOTDISTS) - -.PHONY: bootstrap -bootstrap: - (cd src && $(MAKE) bootstrap) - -# FIXME: Have to figure out how to create dependency files recursively. -# dist-hook: $(DOTDISTS) - -MAINTAINERCLEANFILES += aclocal.m4 configure \ - config.status config.log config.cache \ - $(DOTDISTS) $(MAKEFILESAM) - -# Is this rule needed? -all-recursive check-recursive: config.h - - -EXTRA_DIST = ANNOUNCE AUTHORS FAQ README COPYING ChangeLog ChangeLog.1 NEWS FAQ \ - Makefile.am.in make_am distribution-key.gpg - - -include $(top_srcdir)/misc/ctags.mk diff --git a/lsh/Makefile.am.in b/lsh/Makefile.am.in deleted file mode 100755 index 94cdc60..0000000 Binary files a/lsh/Makefile.am.in and /dev/null differ diff --git a/lsh/Makefile.in b/lsh/Makefile.in deleted file mode 100755 index 88e9804..0000000 --- a/lsh/Makefile.in +++ /dev/null @@ -1,425 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -# ctags support. Automake only supports etags. We base our ctags support on -# automake's etags support. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = . - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -SUBDIRS = src doc misc contrib - -AUTOMAKE_OPTIONS = foreign - -# We must run make the .dist_classes and various .dist_headers after -# recompiling, but before making a dist, as they uses dependency information to -# figure out which header files should be included in the dist. - -DOTDISTS = src/.dist_classes src/.dist_headers - -MAKEFILESAM = Makefile.am doc/Makefile.am src/Makefile.am src/scm/Makefile.am - - -# FIXME: Have to figure out how to create dependency files recursively. -# dist-hook: $(DOTDISTS) - -MAINTAINERCLEANFILES = aclocal.m4 configure config.status config.log config.cache $(DOTDISTS) $(MAKEFILESAM) - - -EXTRA_DIST = ANNOUNCE AUTHORS FAQ README COPYING ChangeLog ChangeLog.1 NEWS FAQ Makefile.am.in make_am distribution-key.gpg - -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = -DIST_COMMON = README ./stamp-h.in AUTHORS COPYING ChangeLog Makefile.am \ -Makefile.in NEWS acconfig.h acinclude.m4 aclocal.m4 config.h.in \ -configure configure.in install-sh missing mkinstalldirs - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -all: all-redirect -.SUFFIXES: -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) $(top_srcdir)/misc/ctags.mk - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -$(ACLOCAL_M4): configure.in acinclude.m4 - cd $(srcdir) && $(ACLOCAL) - -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) - -config.h: stamp-h - @if test ! -f $@; then \ - rm -f stamp-h; \ - $(MAKE) stamp-h; \ - else :; fi -stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=config.h \ - $(SHELL) ./config.status - @echo timestamp > stamp-h 2> /dev/null -$(srcdir)/config.h.in: $(srcdir)/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/stamp-h.in; \ - $(MAKE) $(srcdir)/stamp-h.in; \ - else :; fi -$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f config.h - -maintainer-clean-hdr: - -# This directory's subdirectories are mostly independent; you can cd -# into them and run `make' without going through this Makefile. -# To change the values of `make' variables: instead of editing Makefiles, -# (1) if the variable is set in `config.status', edit `config.status' -# (which will cause the Makefiles to be regenerated when you run `make'); -# (2) otherwise, pass the desired values on the `make' command line. - -@SET_MAKE@ - -all-recursive install-data-recursive install-exec-recursive \ -installdirs-recursive install-recursive uninstall-recursive \ -check-recursive installcheck-recursive info-recursive dvi-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -mostlyclean-recursive clean-recursive distclean-recursive \ -maintainer-clean-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ - rev="$$subdir $$rev"; \ - test "$$subdir" = "." && dot_seen=yes; \ - done; \ - test "$$dot_seen" = "no" && rev=". $$rev"; \ - target=`echo $@ | sed s/-recursive//`; \ - for subdir in $$rev; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done && test -z "$$fail" -tags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ - done - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \ - fi; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -maintainer-clean-tags: - -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - -rm -rf $(distdir) - GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz - mkdir $(distdir)/=build - mkdir $(distdir)/=inst - dc_install_base=`cd $(distdir)/=inst && pwd`; \ - cd $(distdir)/=build \ - && ../configure --srcdir=.. --prefix=$$dc_install_base \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) dist - -rm -rf $(distdir) - @banner="$(distdir).tar.gz is ready for distribution"; \ - dashes=`echo "$$banner" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - echo "$$dashes" -dist: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -dist-all: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -distdir: $(DISTFILES) - -rm -rf $(distdir) - mkdir $(distdir) - -chmod 777 $(distdir) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - for subdir in $(SUBDIRS); do \ - if test "$$subdir" = .; then :; else \ - test -d $(distdir)/$$subdir \ - || mkdir $(distdir)/$$subdir \ - || exit 1; \ - chmod 777 $(distdir)/$$subdir; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \ - || exit 1; \ - fi; \ - done -info-am: -info: info-recursive -dvi-am: -dvi: dvi-recursive -check-am: all-am -check: check-recursive -installcheck-am: -installcheck: installcheck-recursive -all-recursive-am: config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -install-exec-am: -install-exec: install-exec-recursive - -install-data-am: -install-data: install-data-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-recursive -uninstall-am: -uninstall: uninstall-recursive -all-am: Makefile config.h -all-redirect: all-recursive-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: installdirs-recursive -installdirs-am: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: - -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) -mostlyclean-am: mostlyclean-hdr mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-recursive - -clean-am: clean-hdr clean-tags clean-generic mostlyclean-am - -clean: clean-recursive - -distclean-am: distclean-hdr distclean-tags distclean-generic clean-am - -distclean: distclean-recursive - -rm -f config.status - -maintainer-clean-am: maintainer-clean-hdr maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-recursive - -rm -f config.status - -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -install-data-recursive uninstall-data-recursive install-exec-recursive \ -uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \ -all-recursive check-recursive installcheck-recursive info-recursive \ -dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \ -maintainer-clean-recursive tags tags-recursive mostlyclean-tags \ -distclean-tags clean-tags maintainer-clean-tags distdir info-am info \ -dvi-am dvi check check-am installcheck-am installcheck all-recursive-am \ -install-exec-am install-exec install-data-am install-data install-am \ -install uninstall-am uninstall all-redirect all-am all installdirs-am \ -installdirs mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean - - -# FIXME: Use the BASH variable to execute the script. The problem is -# that the script attempts to start itselt with "$0 args". -$(MAKEFILESAM): $(addsuffix .in,$(MAKEFILESAM)) - (cd $(srcdir) && BASH=$(BASH) \ - SELF="$(BASH) ./make_am" $(BASH) ./make_am) - -$(DOTDISTS): depend - (cd $(srcdir) && BASH=$(BASH) \ - SELF="$(BASH) ./make_am" $(BASH) ./make_am --rethink) - -.PHONY: dotdists -dotdists: $(DOTDISTS) - -.PHONY: bootstrap -bootstrap: - (cd src && $(MAKE) bootstrap) - -# Is this rule needed? -all-recursive check-recursive: config.h - -.PHONY: ctags-recursive ctags - -ctags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - (cd $$subdir && $(MAKE) ctags); \ - done - -ctags: ctags-recursive $(HEADERS) $(SOURCES) $(CONFIG_HEADER) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - test -f $$subdir/tags && tags="$$tags $$here/$$subdir/tags"; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$(CONFIG_HEADER)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && ctags --langmap=c:.c.x -o $$here/tags $(CTAGS_ARGS) $$tags $(CONFIG_HEADER) $$unique $(LISP)) -# This treats .h.x files as C files rather than headers, but we can't -# distinguish them from .c.x files with ctags. - -# Override the standard distclean-tags target, as this doesn't support `tags' -distclean-tags: - -rm -f TAGS ID tags - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/NEWS b/lsh/NEWS deleted file mode 100755 index 023d6b7..0000000 --- a/lsh/NEWS +++ /dev/null @@ -1,655 +0,0 @@ -News for the 1.3.3 release: - - Server suport for subsystems, and a new experimental command - line option --subsystems for lshd. An sftp-server included in - the dist, but it's mostly untested. - - Better messages when the initial handshake fails. - - Support for AES (formely known only as rijndael). - - Simplified the internal command definition machinery. - - Fixed bug in lshg; it crashed if given a host name argument - with strange characters. - - Updates to SRP support, to get it closer to the latest draft. - - New client option -B, which is like -N but also puts the - process in the background. - -News for the 1.3.2 release: - - Suspend works better, and is bound to the escape sequence - RET ~ ^Z. - -News for the 1.3.1 release: - - Repackaged the low-level crypto functions as the "nettle" - library. Bugfixes for serpent. - -News for the 1.3.0 release: - - Bugfixes (same as in 1.2.2). - - constness fixes. - - Deleted the complex streamed sexp-parser. - - Verbose messages at KEXINIT and NEWKEYS. - - Tolerate empty atoms (like in "3des-cbs,,aes256-cbc,"). - - If compiled with --debug-alloc, all strings are counted and - leaks detected. Fixed some minor leaks. - - Changed conventions for packet handlers, all packets are freed - by connection_handle_packet, so individual packet handlers - shouldn't do that. - - Handle the TSTP signal. Backgrounding still doesn't work quite - right, though. - - Rewrote parts of the gaba.scm preprocessor. - -News for the 1.2.0 release: - - Added the lcp copying script to the distribution (although it - isn't installed automatically). No other changes. - -News for the 1.1.9 release: - - Some code cleanup. Removed a dozen files, four classes and - about 1k lines of code. Useful tools are make class-map and - ./configure --enable-gcov. - - To get gcov to work properly when running several processes in - parallell, you may also want to apply misc/libgcc2.c-patch to - gcc. The patch adds locking for the output *.da files. - -News for the 1.1.8 release: - - Updated the scsh support for scsh-0.5.2. Note that scsh is now - free software; the "non-commercial use" restrictions were - removed in the 0.5.2 release. - - Updated the channel close logic to be compatible with other - ssh implementations. - - Handle POLLERR; the previous version went into a busy loop if - poll set the POLLERR flag on any fd. - - --cvs-workaround=e is now on by default. New option - --no-cvs-workaround to disable it. - -News for the 1.1.7 release: - - More bug fixes, most of them related to the EOF handling. - - Added testcase for lshg -L, fixed the exposed bugs. - - Don't output the "Userauth successful" message unless in - verbose mode. - -News for the 1.1.6 release: - - Fixed a bug in the testsuite framework, and discovered and - fixed a few new and old bugs (mostly related to the EOF and - channel close logic). - - Improved handling of POLLHUP on Linux. - - Fixed bug in lshd password authentication, which sometimes - crashed lshd. - - Support for RSA keys, according to - draft-ietf-secsh-transport-09.txt. Wrote a test case for RSA - hostkeys, and fixed a bug in the ssh-rsa public key decoder. - - Added support for OpenSSH style RSA keys to ssh-conv. - - Changed unix_random.c to be more quiet. - - Changed tcpip forwarding code to call shutdown() when it - receives an SSH_MSG_CHANNEL_EOF. - - Updated the manual. - -News for the 1.1.5 release: - - Fixed bug in random generator seeding (spotted by jps). - - More argp fixes. - - Work on rsync, but still not used. - -News for the 1.1.4 release: - - Fixes for encrypted private keys (thanks to jps). - - Updated argp, and ripped out its dependencies on getopt. - -News for the 1.1.3 release: - - Support for encrypted private keys (not tested). - - The lshg gateway client works. - -News for the 1.1.2 release: - - New experimental option to lsh: --cvs-workaround. Using this - option causes lsh to fork off a few extra processes to handle - its stdio file descriptors, and avoid setting them in - nonblocking mode. One can also use for instance - --cvs-workaround=o to fork only for stdout; the optional - argument can be any combination of the characters 'i' (stdin), - 'o' (stdout) and 'e' (stderr). If this turns out to be useful, - the option will probably be renamed and perhaps made the - default. - - Implemented window change messages in the client. - - Added signal handlers to io_backend. - - Reorganized the code a little to make the lshg binary smaller. - - Some work on an "interactive" class, encapsulating the - oparations one may want to do on the user's tty, including - subscription for window change events. - -News for the 1.1.1 release: - - First try for the gateway mode. New option -G for lsh, and a - new program lshg for talking to the gateway. - - lshd forks of a new process and changes its uid for reading - user files. The only file read in this way, so far, is - ~/.lsh/srp-verifier. - - Improved randomness framework. - -News for the 1.1.0 release: - - First, note that the 1.1.x series should be considered - experimental. - - New program lsh-export-key (contributed by jps, and then - hacked some more by me). - - Some of the methods for public-key operations have been - improved and generalized. - -News for the 1.0.6 release - - Fixed bug in ssh-dss bug-compatibility. - - Experimental kerberos support. New lshd option - --kerberos-passwords. Compiles with heimdal, MIT kerberos not yet - tested. - - Improved handling of serialized userauth requests (not yet - used by kerberos password functions). - - Hacked serpent code to support variable size keys. - - Added rijndael test cases. No working serpent testcases yet. - -News for the 1.0.5 release - - Experimental support for RSA, using spki-style keys and - signatures. - - Some reorganization of signature algorithms, to support - spki-style signatures (including rsa) properly. - - Fix for key renegotiation bug reported by jps. - - New algorithms bulk encryption algorithms: serpent and - rijndael. Rijndael implementation and lsh glue code - contributed by Rafael R. Sevilla. Serpent implementation by - Ross Anderson, Eli Biham, and Lars Knudsen. - - New option -call to use any supported bulk encryption - algorithm; the default preference list is quite conservative. - - New option --hostkey-algorithm, to tune the hostkey algorithm - preference list. - - Renamed lsh_keygen and lsh_writekey to lsh-keygen and - lsh-writekey, respectively (actually happened in 1.0.4, but I - forgot to mention that). - -News for the 1.0.4 release - - Fixed yet another bug in the userauth logic. - - Some RSA support (so far, only lsh-keygen and lsh-writekey - support RSA). 408 hours left... - - Support for the transport spki format in sexp_parser.c. - -News for the 1.0.3 release - - Fixed bug in client userauth logic. - - Configure fix: put -L and -R flags in LDFLAGS, not LIBS. - - Portability fixes and some signed/unsigned cleanup. - -News for the 1.0.2 release - - Fixed bug in lsh_writekey, and improved the error message when - the outputfile already exists. - - Fixed bug in the poll emulation in jpoll.c (noticed by - Jean-Pierre Stierlin). - - Portability bugs reported by Jean-Pierre Stierlin, for - compiling on MacOS. - -News for the 1.0.1 release - - Various bug fixes. Spelling and grammar fixes in the manual, - contributed by Johan Myreen. - Hacked lsh user authentication to stop asking for a password - if the empty password is entered twice. - -News for the 0.9.15 release - - Portability fixes. Fixed 32-bit bug in the memory allocation - that appeared on alpha-linux. Fixes for HPUX compiler. Fixed - make distclean, which failed when cleaning in src/symmetric. - -News for the 0.9.14 release - - Added --stdin, --stdout and --stderr options to lsh. - - Implemented pretty-printing of s-expressions when using the - advanced syntax. - - Renamed sexp_conv to sexp-conv. - - Fixed bug preventing forwarded connections from being closed - properly. Reported by Daniel Prevett and Joseph Galbraith. - - New Getting Started chapter in the manual, and other - documentation updates. - -News for the 0.9.13 release - - New program lsh-decode-key and script ssh-conv, for converting - OpenSSH/ssh2 keys to sexp format. - - Updated SRP support to the draft doc/srp-spec.txt. - Made it possible to skip the userauth sub-protocol when using - SRP. The proxy program was probably broken in the process. - - Fixed lsh-authorize, to use the right options to sexp_conv. - - Let $HOME override the home directory in the passwd database, - when running as non-root. - -News for the 0.9.10 release - - Fixed bug that caused buffered output to be lost at channel - close. - - Experimental SRP support. - - New program srp-gen. - - Improved the hex dumps in debug output. - -News for the 0.9.9 release - - autoconf fixes. Add -R-flags when appropriate. Recognize - gmp-3.x. Added --with-lib-path option. - - Portability fixes. - -News for the 0.9.7 release - - Experimental IPv6 support. - - Experimental support for encrypted private keys (for now, only - in lsh_writekey). - - wtmp logging. - - Improved behaviour of --port and -z options. - -News for the 0.9.2 release - - Improved support for shadow passwords. - - Some preparations for gateway mode. - -News for the 0.9.1 release - - Support for remote commands directly on the lsh command line. - New options -S and -E. More features in the proxy. - -News for the 0.2.9 release - - Fixed bugs in the length checking of incoming packets. - -News for the 0.2.8 release - - Reworked i/o and the CHANNEL_OPEN mechanism. Seems to fix the - crash when requesting forwarding to a port that doesn't - answer. - - Also close ports for local and remote forwarding properly. - - Updated the proxy code. - -News for the 0.2.7 release - - Bug fixes for compialtion on Solaris. - -News for the 0.2.6 release - - Bugfixes for tcp forwarding functions. - - Some more tests for testsuite. To try them, you must first - setup lsh so that you can login with no password. Then type - "make check-more" in the testsuite subdirectory. - -News for the 0.2.5 release - - Bugfixes. - -News for the 0.2.3 release - - Added lshd options --password, --no-password, --publickey and - --no-publickey, for configuring the set of supported userauth - methods. - - Changes to the proxy program (Bazsi). - -News for the 0.2.2 release - - Bug fixes. Verbose messages on algorithm selection. - -News for the 000.2 release - - Bugfixes. New --pty-support and --no-pty-support options for - lshd. - -News for the lsh-0.1.20 release - - Bugfixes. New test script for lsh_writekey. - -News for the lsh-0.1.19 release - - Lots of bugfixes. Reading of ~/.lsh/known_hosts and - ~/.lsh/identity seems to work. - - New contrib sub-directory. - -News for the lsh-0.1.18 release - - lsh now reads ACL:s from the ~/.lsh/known_hosts file. - - First attempt at a m4-based testsuite. It depends on m4 being - able to handle the eight-bit quote characters » and «. If your - m4 doesn't do that, get the latest beta of GNU m4 or recompile - GNU m4-1.4 with CFLAGS=-funsigned-char. - -News for the lsh-0.1.17 release - - More support for host authentication and SPKI. - - First version that includes Bazsi's work on an ssh-proxy (i.e. - a program that implements the traditional Man-in-the-middle - attack on the ssh2 protocol). Could be useful for people - running firewalls, and also for those of us who want to point - out that it's a bad idea to use unauthenticated hostkeys. - -News for the lsh-0.1.16 release - - Some preparations for real host authentication. - -News for the lsh-0.1.15 release - - Support for publickey user authentication. - - A new script lsh-authorize. - -News for the lsh-0.1.14 release - - First try on daemonization support. - - Better tracing; try --trace to get some more information than - with -v, but without all the boring information generated by - --debug. - - Generally nicer options and help mesasges, thanks to argp. - - Better handling of i/o exceptions. lshd should no longer crash - when connections behave unexpectedly. - -News for the lsh-0.1.12 release - - Tried to fix bugs related to channel close. In the process, - improved the resource mechanism, and let each channel - have it's own list of resources. - - Fixed configure.in to handle systems with neither scsh or - guile installed. - - -News for the lsh-0.1.11 release - - Support for other scheme implementations in the build process, - in particular guile. - - -News for the lsh-0.1.10 release - - Fixed bug in sexp parser and lsh_writekey. - - Merged more of bazsis patches. - - -News for the lsh-0.1.9 release - - Lot's of bug fixes. This version actually seems to work. - - Bazsi's public key patches is in, although I haven't been able - to test them. - - The SEXP parser is rewritten to use the new exception - framework. The program that makes the most of of this right - now is lsh_writekey. Its core reads like - - (params - (private object io_write_file_info) - (public object io_write_file_info)) - - (lambda (backend) - (let ((key (read (stdin backend)))) - (prog1 (transport (open backend public) (private2public key)) - ; FIXME: Add encryption here - (canonical (open backend private) key)))))) - - The sexptest program has been renamed to sexp_conv. It reads - an sexp (for now, only canonical and transport syntax are - supported) on stdin, and prints it using advanced, transport - or canonical syntax. More features could be added. - - The --debug option now dumps both sent and received packets, - and it includes a human readable name of the packet type. - Packets of type SSH_MSG_USERAUTH_REQUEST are suppressed, - however, because they typically contains user passwords. - - There is one known bug: Running without pty allocation (lsh - -nt) doesn't work, at least not for me. - - -News for the lsh-0.1.8 release - - Reworked all the error handling to use exceptions. No new - features, but lots of new bugs. - -There are no official releases numbered 0.1.4 -- 0.1.7. However, -these version numbers are used for Bazsi's unofficial releases during -the summer. The unofficial releases feature public key user -authentication and better compatibility with Datafellow's ssh2 -products. - -News for the lsh-0.1.3 release - - Local forwarding (-L) works. -R is slightly broken. - -News for the lsh-0.1.2 release - - First user visible tcpforwarding (-L option). Not tested - yet... - - Fixed flow control. - - DSA signatures should conform better both to the draft andd to - the ssh-2.x implementations. - - Better handling of POLLHUP. - -News for the lsh-0.1 release - - Added compiler.scm to the dist. - - Changed the session key generation to comply with the latest - draft (pointed out by Joseph Galbraith). - - Added IDEA support (Bazsi). - - Fixes to pty handling and flow control (mostly Bazsi). - - Fixed the client side handling of userauth failures. - - By default, if we are running with a pty, use the same fd for - stdout and stderr. This workaround should make lsh more - friendly to bash and other programs that expect stderr to be a - tty. - -NEWS for the 1999-04-25 snapshot: - - Fixed a few bugs in pty and eof handling. Should now work - about as well as the 03-17 snapshot. Also removed most old - #if:ed out code. - -NEWS for the 1999-04-20 snapshot: - - Internal reorganization. Implemented the "control language". - And some bug fixes. See ChangeLog for all the details. - -NEWS for the 1999-03-17 snapshot - - CAST and TWFOFISH seem to work now. - - Includes a lambda->SK compiler. - - Bugfixes. - -NEWS for the 1999-03-08 snapshot - - No user visible changes. Added a instance variable to keep - track of the amount of buffered data in the write_buffer - objects (needed to fix the broken flow control). - - Added a generic doubly linked list, currently used by the - write_buffer and resource_list classes, but which will be - needed for more things (see the CONTROL item on the TODO - list). - -NEWS for the 1999-03-07 snapshot - - Improved CFMAKERAW. Ugly fix for the UNIX98-style pty:s - support. - - Twofish support (not quite working). - - Started on tcp forwarding (Bazsi). - - Some support for broken ssh2 signatures (Baszi). Needs some - more work. - - Various bugfixes. - -NEWS for the 1999-02-28 snapshot - - Portability fixes for Solaris. - -NEWS for the 1999-01-28 snapshot - - Some PTY support - - Integrated support for sshd1 fallback (not tested) - - Bug fixes. - -NEWS for the 1999-01-14 snapshot - - Fixed off-by-one bug in dss_keygen. - - Some portability fixes (sys/poll.h, crypt.h, unistd.h). - -NEWS for the 1999-01-08 snapshot: - - New program lsh_writekey. - -NEWS for the 1999-01-05 snapshot: - - Command line options to select which algorithms to use. - - Various bug fixes. The 3des and blowfish support seems do work - now. - -NEWS for the 1999-01-01 snapshot: - - ZLIB support. (Bazsi) - Long key support (needed for 3DES) (Bazsi). - Fixed configure test for shutdown(). - Various bug fixes (Ray). - -NEWS for the 1998-12-26 snapshot: - - New lsh_keygen program. - -NEWS for the 1998-12-21 snapshot: - -Moved most objects in crypto.c and abstract_crypto.c into separate -files. - -Added a workaround for Datafellows ssh2 client, which (contrary to the -specification) asks for protocol version 1.99. - -Use /dev/urandom, if available. - -Collect most object files into liblsh.a. - -Started on a key generation program. - -TASKLIST and NOTES files now included in the snapshot. - - -NEWS since the 1998-12-17 snapshot: - -Support for md5 (by Balázs Scheidler). - -Various bugfixes. - - -NEWS since the 1998-12-11 snapshot: - -A resource mechanism (resource.[ch]) used by the server to cleanup -properly when a connection dies unexpectedly. Can be used to kill -child processes, close files and ports, etc. - -Generic code for chaining ciphers (crypto_cbc()) and piping them -together (crypto_cascade()). - -Some untested support for blowfish and 3DES. A -c command line option -is needed. - -A few bugfixes. Thanks to J.H.M. Dassen (Ray) and Balázs Scheidler. diff --git a/lsh/README b/lsh/README deleted file mode 100755 index a8b9d52..0000000 --- a/lsh/README +++ /dev/null @@ -1,96 +0,0 @@ -LSH - a GNU implementation of the Secure Shell protocols. - - -LSH IS A WORK IN PROGRESS. IT WILL NOT PROVIDE ANY SECURITY ON SYSTEMS -THAT LACK /dev/random. THERE MAY BE OTHER SERIOUS BUGS THAT MAKE IT -TOTALLY INSECURE. - - -COPYRIGHT - -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. See the file COPYING for details. - - -INSTALLATION - -If you have downloaded a release, you should be able to compile it -with - - ./configure - make - -You need GNU make. Some shells have had bugs preventing them from -executing the configure script; if you experience problems, try -running - - bash configure - -If you want to hack lsh, you need some more tools: autoconf (at least -version 2.50), automake, bash, gcc, gperf (at least version 2.7) and a -scheme implementation. The currently supported schemes are guile and -scsh (at least version 0.5.2). All but scsh can be found at your local -GNU mirror site. scsh, Olin Shiver's Scheme Shell, can be downloaded -from . If you -use guile, you also need the slib library, which is usually -distributed separately. It's also available at the GNU mirrors. - -If you have checked out lsh from CVS, things are more complicated. You -must first generate Makefile.am files from the corresponding -Makefile.am.in files. Do this by running ./make_am in the top level -directory. Next, you need to run aclocal, autoconf, autoheader and -automake -a. This creates the configure script and a Makefile.in. Now -you can try ./configure ; make. If the compiler complains that it -can't find a file foo.h.x, try creating it with make foo.h.x, and -similarly for missing foo.c.x files. The misc/bootstrap.sh script -tries to do all this. - - -NEEDED LIBRARIES - -GMP (cersion 2.0.2 or better) can be found at ftp.gnu.org, or some of -its mirrors. - -ZLIB can be found at ftp://ftp.cdrom.com/pub/infozip/zlib/zlib.html or -http://www.cdrom.com/pub/infozip/zlib/. Latest version is zlib-1.1.3. - - -GETTING STARTED - -Some examples... - -Create a new DSS key pair, and save it in NEW_KEY and NEW_KEY.pub: - - ./lsh-keygen -l 8 | ./lsh-writekey -o NEW_KEY - -Start an lshd server on port 4711, using the key created above as the -server host key: - - ./lshd -p 4711 -h NEW_KEY - -Connect to an lshd server running on port 4711 on HOST, and attempt to -log in as USER: - - ./lsh -p 4711 -l USER HOST - - -MORE INFORMATION - -For more information on using LSH, read the LSH manual, doc/lsh.info -or doc/lsh.html. - -For an introduction to the inner workings of LSH, see the file -doc/HACKING. - -Several people have contributed to LSH, see the AUTHORS file for -details. - -If you are interested in lsh, you may want to subscribe to the -psst-list. Subscription address is psst-request@net.lut.ac.uk. - -Current snapshots of lsh can be found at -. - - -/Niels Möller diff --git a/lsh/acconfig.h b/lsh/acconfig.h deleted file mode 100755 index e69de29..0000000 diff --git a/lsh/acinclude.m4 b/lsh/acinclude.m4 deleted file mode 100755 index 296bc5e..0000000 Binary files a/lsh/acinclude.m4 and /dev/null differ diff --git a/lsh/aclocal.m4 b/lsh/aclocal.m4 deleted file mode 100755 index 9d027e6..0000000 --- a/lsh/aclocal.m4 +++ /dev/null @@ -1,558 +0,0 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4 - -dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without -dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A -dnl PARTICULAR PURPOSE. - -AH_TEMPLATE([socklen_t], [Length type used by getsockopt]) - -# Try to detect the type of the third arg to getsockname() et al -AC_DEFUN([AC_TYPE_SOCKLEN_T], -[AC_CACHE_CHECK([for socklen_t in sys/socket.h], ac_cv_type_socklen_t, -[AC_EGREP_HEADER(socklen_t, sys/socket.h, - [ac_cv_type_socklen_t=yes], [ac_cv_type_socklen_t=no])]) -if test $ac_cv_type_socklen_t = no; then - AC_MSG_CHECKING(for AIX) - AC_EGREP_CPP(yes, [ -#ifdef _AIX - yes -#endif -],[ -AC_MSG_RESULT(yes) -AC_DEFINE(socklen_t, size_t) -],[ -AC_MSG_RESULT(no) -AC_DEFINE(socklen_t, int) -]) -fi -]) - -# checks for gmp version 2 or later. -# AC_CHECK_LIBGMP(library, [, if-found [, if-not-found]]) -AC_DEFUN([AC_CHECK_LIBGMP], -[AC_CACHE_CHECK([for mpz_get_d in -l$1], ac_cv_lib_$1_mpz_get_d, -[ac_save_libs="$LIBS" -LIBS="-l$1 $LIBS" -AC_TRY_LINK(dnl -[#if HAVE_GMP_H -#include -#elif HAVE_GMP2_GMP_H -#include -#endif -], -[mpz_get_d(0);], -ac_cv_lib_$1_mpz_get_d=yes, -ac_cv_lib_$1_mpz_get_d=no) -LIBS="$ac_save_LIBS" -]) -if test x$ac_cv_lib_$1_mpz_get_d = xyes ; then -ifelse([$2], , -[AC_DEFINE(HAVE_LIBGMP) -LIBS="-l$1 $LIBS" -], [$2]) -ifelse([$3], , , -[else -$3 -])dnl -fi -]) - -# checks for gmp version 2 or later. -# AC_SEARCH_LIBGMP(libraries, [, if-found [, if-not-found]]) -AC_DEFUN([AC_SEARCH_LIBGMP], -[AC_CACHE_CHECK([for library containing mpz_get_d], ac_cv_search_mpz_get_d, -[ac_search_save_LIBS="$LIBS" -ac_cv_search_mpz_get_d="no" -for i in $1; do -LIBS="-l$i $ac_search_save_LIBS" -AC_TRY_LINK(dnl -[#if HAVE_GMP_H -#include -#elif HAVE_GMP2_GMP_H -#include -#endif -], -[mpz_get_d(0);], -[ac_cv_search_mpz_get_d=-l$i -break -]) -done -LIBS="$ac_search_save_LIBS" -]) -if test "x$ac_cv_search_mpz_get_d" != xno ; then - LIBS="$ac_cv_search_mpz_get_d $LIBS" -ifelse([$2], , -[AC_DEFINE(HAVE_LIBGMP) -], [$2]) -ifelse([$3], , , -[else -$3 -])dnl -fi -]) - -# LSH_PATH_ADD(path-id, directory) -AC_DEFUN([LSH_PATH_ADD], -[AC_MSG_CHECKING($2) -ac_exists=no -if test -d "$2/." ; then - ac_real_dir=`cd $2 && pwd` - if test -n "$ac_real_dir" ; then - ac_exists=yes - for old in $1_REAL_DIRS ; do - ac_found=no - if test x$ac_real_dir = x$old ; then - ac_found=yes; - break; - fi - done - if test $ac_found = yes ; then - AC_MSG_RESULT(already added) - else - AC_MSG_RESULT(added) - # LDFLAGS="$LDFLAGS -L $2" - $1_REAL_DIRS="$ac_real_dir [$]$1_REAL_DIRS" - $1_DIRS="$2 [$]$1_DIRS" - fi - fi -fi -if test $ac_exists = no ; then - AC_MSG_RESULT(not found) -fi -]) - -# LSH_RPATH_ADD(dir) -AC_DEFUN([LSH_RPATH_ADD], [LSH_PATH_ADD(RPATH_CANDIDATE, $1)]) - -# LSH_RPATH_INIT(candidates) -AC_DEFUN([LSH_RPATH_INIT], -[AC_MSG_CHECKING([for -R flag]) -RPATHFLAG='' -case `uname -sr` in - OSF1\ V4.*) - RPATHFLAG="-rpath " - ;; - IRIX\ 6.*) - RPATHFLAG="-rpath " - ;; - IRIX\ 5.*) - RPATHFLAG="-rpath " - ;; - SunOS\ 5.*) - if test "$TCC" = "yes"; then - # tcc doesn't know about -R - RPATHFLAG="-Wl,-R," - else - RPATHFLAG=-R - fi - ;; - Linux\ 2.*) - RPATHFLAG="-Wl,-rpath," - ;; - *) - : - ;; -esac - -if test x$RPATHFLAG = x ; then - AC_MSG_RESULT(none) -else - AC_MSG_RESULT([using $RPATHFLAG]) -fi - -RPATH_CANDIDATE_REAL_DIRS='' -RPATH_CANDIDATE_DIRS='' - -AC_MSG_RESULT([Searching for libraries]) - -for d in $1 ; do - LSH_RPATH_ADD($d) -done -]) - -# Try to execute a main program, and if it fails, try adding some -# -R flag. -# LSH_RPATH_FIX -AC_DEFUN([LSH_RPATH_FIX], -[if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then - ac_success=no - AC_TRY_RUN([int main(int argc, char **argv) { return 0; }], - ac_success=yes, ac_success=no, :) - - if test $ac_success = no ; then - AC_MSG_CHECKING([Running simple test program failed. Trying -R flags]) -dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS - ac_remaining_dirs='' - ac_rpath_save_LDFLAGS="$LDFLAGS" - for d in $RPATH_CANDIDATE_DIRS ; do - if test $ac_success = yes ; then - ac_remaining_dirs="$ac_remaining_dirs $d" - else - LDFLAGS="$RPATHFLAG$d $LDFLAGS" -dnl echo LDFLAGS = $LDFLAGS - AC_TRY_RUN([int main(int argc, char **argv) { return 0; }], - [ac_success=yes - ac_rpath_save_LDFLAGS="$LDFLAGS" - AC_MSG_RESULT([adding $RPATHFLAG$d]) - ], - [ac_remaining_dirs="$ac_remaining_dirs $d"], :) - LDFLAGS="$ac_rpath_save_LDFLAGS" - fi - done - RPATH_CANDIDATE_DIRS=$ac_remaining_dirs - fi - if test $ac_success = no ; then - AC_MSG_RESULT(failed) - fi -fi -]) - -# Like AC_CHECK_LIB, but uses $KRB_LIBS rather than $LIBS. -# AC_CHECK_KRB_LIB(LIBRARY, FUNCTION, [, ACTION-IF-FOUND [, -# ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]]) - -AC_DEFUN([AC_CHECK_KRB_LIB], -[AC_CHECK_LIB([$1], [$2], - ifelse([$3], , - [[ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - AC_DEFINE_UNQUOTED($ac_tr_lib) - KRB_LIBS="-l$1 $KRB_LIBS" - ]], [$3]), - ifelse([$4], , , [$4 -])dnl -, [$5 $KRB_LIBS]) -]) - -# AC_LIB_ARGP(ACTION-IF-OK, ACTION-IF-BAD) -AC_DEFUN([AC_LIB_ARGP], -[ ac_argp_save_LIBS="$LIBS" - ac_argp_save_LDFLAGS="$LDFLAGS" - ac_argp_ok=no - # First check if we can link with argp. - AC_SEARCH_LIBS(argp_parse, argp, - [ LSH_RPATH_FIX - AC_CACHE_CHECK([for working argp], - lsh_cv_lib_argp_works, - [ AC_TRY_RUN( -[#include -#include - -static const struct argp_option -options[] = -{ - { NULL, 0, NULL, 0, NULL, 0 } -}; - -struct child_state -{ - int n; -}; - -static error_t -child_parser(int key, char *arg, struct argp_state *state) -{ - struct child_state *input = (struct child_state *) state->input; - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_END: - if (!input->n) - input->n = 1; - break; - } - return 0; -} - -const struct argp child_argp = -{ - options, - child_parser, - NULL, NULL, NULL, NULL, NULL -}; - -struct main_state -{ - struct child_state child; - int m; -}; - -static error_t -main_parser(int key, char *arg, struct argp_state *state) -{ - struct main_state *input = (struct main_state *) state->input; - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &input->child; - break; - case ARGP_KEY_END: - if (!input->m) - input->m = input->child.n; - - break; - } - return 0; -} - -static const struct argp_child -main_children[] = -{ - { &child_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static const struct argp -main_argp = -{ options, main_parser, - NULL, - NULL, - main_children, - NULL, NULL -}; - -int main(int argc, char **argv) -{ - struct main_state input = { { 0 }, 0 }; - char *v[2] = { "foo", NULL }; - - argp_parse(&main_argp, 1, v, 0, NULL, &input); - - if ( (input.m == 1) && (input.child.n == 1) ) - return 0; - else - return 1; -} -], lsh_cv_lib_argp_works=yes, - lsh_cv_lib_argp_works=no, - lsh_cv_lib_argp_works=no)]) - - if test x$lsh_cv_lib_argp_works = xyes ; then - ac_argp_ok=yes - else - # Reset link flags - LIBS="$ac_argp_save_LIBS" - LDFLAGS="$ac_argp_save_LDFLAGS" - fi]) - - if test x$ac_argp_ok = xyes ; then - ifelse([$1],, true, [$1]) - else - ifelse([$2],, true, [$2]) - fi -]) - -# Do all the work for Automake. This macro actually does too much -- -# some checks are only needed if your package does certain things. -# But this isn't really a big deal. - -# serial 1 - -dnl Usage: -dnl AM_INIT_AUTOMAKE(package,version, [no-define]) - -AC_DEFUN(AM_INIT_AUTOMAKE, -[AC_REQUIRE([AC_PROG_INSTALL]) -PACKAGE=[$1] -AC_SUBST(PACKAGE) -VERSION=[$2] -AC_SUBST(VERSION) -dnl test to see if srcdir already configured -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) -fi -ifelse([$3],, -AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) -AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) -AC_REQUIRE([AM_SANITY_CHECK]) -AC_REQUIRE([AC_ARG_PROGRAM]) -dnl FIXME This is truly gross. -missing_dir=`cd $ac_aux_dir && pwd` -AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) -AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) -AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) -AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) -AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) -AC_REQUIRE([AC_PROG_MAKE_SET])]) - -# -# Check to make sure that the build environment is sane. -# - -AC_DEFUN(AM_SANITY_CHECK, -[AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "[$]*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "[$]*" != "X $srcdir/configure conftestfile" \ - && test "[$]*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi - - test "[$]2" = conftestfile - ) -then - # Ok. - : -else - AC_MSG_ERROR([newly created file is older than distributed files! -Check your system clock]) -fi -rm -f conftest* -AC_MSG_RESULT(yes)]) - -dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) -dnl The program must properly implement --version. -AC_DEFUN(AM_MISSING_PROG, -[AC_MSG_CHECKING(for working $2) -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if ($2 --version) < /dev/null > /dev/null 2>&1; then - $1=$2 - AC_MSG_RESULT(found) -else - $1="$3/missing $2" - AC_MSG_RESULT(missing) -fi -AC_SUBST($1)]) - -# Like AC_CONFIG_HEADER, but automatically create stamp file. - -AC_DEFUN(AM_CONFIG_HEADER, -[AC_PREREQ([2.12]) -AC_CONFIG_HEADER([$1]) -dnl When config.status generates a header, we must update the stamp-h file. -dnl This file resides in the same directory as the config header -dnl that is generated. We must strip everything past the first ":", -dnl and everything past the last "/". -AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl -ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>, -<>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>, -<>; do - case " <<$>>CONFIG_HEADERS " in - *" <<$>>am_file "*<<)>> - echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx - ;; - esac - am_indx=`expr "<<$>>am_indx" + 1` -done<<>>dnl>>) -changequote([,]))]) - - -# serial 1 - -# @defmac AC_PROG_CC_STDC -# @maindex PROG_CC_STDC -# @ovindex CC -# If the C compiler in not in ANSI C mode by default, try to add an option -# to output variable @code{CC} to make it so. This macro tries various -# options that select ANSI C on some system or another. It considers the -# compiler to be in ANSI C mode if it handles function prototypes correctly. -# -# If you use this macro, you should check after calling it whether the C -# compiler has been set to accept ANSI C; if not, the shell variable -# @code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source -# code in ANSI C, you can make an un-ANSIfied copy of it by using the -# program @code{ansi2knr}, which comes with Ghostscript. -# @end defmac - -AC_DEFUN(AM_PROG_CC_STDC, -[AC_REQUIRE([AC_PROG_CC]) -AC_BEFORE([$0], [AC_C_INLINE]) -AC_BEFORE([$0], [AC_C_CONST]) -dnl Force this before AC_PROG_CPP. Some cpp's, eg on HPUX, require -dnl a magic option to avoid problems with ANSI preprocessor commands -dnl like #elif. -dnl FIXME: can't do this because then AC_AIX won't work due to a -dnl circular dependency. -dnl AC_BEFORE([$0], [AC_PROG_CPP]) -AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C) -AC_CACHE_VAL(am_cv_prog_cc_stdc, -[am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - AC_TRY_COMPILE( -[#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -], [ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; -], -[am_cv_prog_cc_stdc="$ac_arg"; break]) -done -CC="$ac_save_CC" -]) -if test -z "$am_cv_prog_cc_stdc"; then - AC_MSG_RESULT([none needed]) -else - AC_MSG_RESULT($am_cv_prog_cc_stdc) -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac -]) - diff --git a/lsh/config.h.in b/lsh/config.h.in deleted file mode 100755 index 0f308d0..0000000 --- a/lsh/config.h.in +++ /dev/null @@ -1,322 +0,0 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ - -/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP - systems. This function is required for `alloca.c' support on those systems. - */ -#undef CRAY_STACKSEG_END - -/* Define if using `alloca.c'. */ -#undef C_ALLOCA - -/* Define to support non-standard packets of ssh2 */ -#undef DATAFELLOWS_WORKAROUNDS - -/* Define to enable sanity checking on memory allocation and casting */ -#undef DEBUG_ALLOC - -/* Define to enable tracing */ -#undef DEBUG_TRACE - -/* Define if the `getpgrp' function takes no argument. */ -#undef GETPGRP_VOID - -/* Define if AI_NUMERICHOST exists */ -#undef HAVE_AI_NUMERICHOST - -/* Define if you have `alloca', as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define if you have and it should be used (not on Ultrix). */ -#undef HAVE_ALLOCA_H - -/* Define if you have the header file. */ -#undef HAVE_ARGP_H - -/* Define if you have the `cfmakeraw' function. */ -#undef HAVE_CFMAKERAW - -/* Define if you have the header file. */ -#undef HAVE_CRYPT_H - -/* Define if you don't have `vprintf' but do have `_doprnt.' */ -#undef HAVE_DOPRNT - -/* Define if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define if you have the `gai_strerror' function. */ -#undef HAVE_GAI_STRERROR - -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE - -/* Define if the compiler understands __FUNCTION__ */ -#undef HAVE_GCC_FUNCTION - -/* Define if you have the `getaddrinfo' function. */ -#undef HAVE_GETADDRINFO - -/* Define if you have the `getnameinfo' function. */ -#undef HAVE_GETNAMEINFO - -/* Define if you have the `getrusage' function. */ -#undef HAVE_GETRUSAGE - -/* Define if you have the `getspnam' function. */ -#undef HAVE_GETSPNAM - -/* Define if you have the `gettimeofday' function. */ -#undef HAVE_GETTIMEOFDAY - -/* Define if you have the header file. */ -#undef HAVE_GMP2_GMP_H - -/* Define if you have the header file. */ -#undef HAVE_GMP_H - -/* Define if you have the `inet_aton' function. */ -#undef HAVE_INET_ATON - -/* Define if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define if you have the header file. */ -#undef HAVE_KRB5_H - -/* Define if you have the `crypt' library (-lcrypt). */ -#undef HAVE_LIBCRYPT - -/* Define if you have the `nsl' library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define if you have the `socket' library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define if you have the `util' library (-lutil). */ -#undef HAVE_LIBUTIL - -/* Define if you have the header file. */ -#undef HAVE_LIBUTIL_H - -/* Define if you have the `Xau' library (-lXau). */ -#undef HAVE_LIBXAU - -/* Define if you have the `xnet' library (-lxnet). */ -#undef HAVE_LIBXNET - -/* Define if you have the `z' library (-lz). */ -#undef HAVE_LIBZ - -/* Define if you have the `login' function. */ -#undef HAVE_LOGIN - -/* Define if you have the `logout' function. */ -#undef HAVE_LOGOUT - -/* Define if you have the `logwtmp' function. */ -#undef HAVE_LOGWTMP - -/* Define if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define if you have the `memxor' function. */ -#undef HAVE_MEMXOR - -/* Define if you have the `openpty' function. */ -#undef HAVE_OPENPTY - -/* Define if you have the `poll' function. */ -#undef HAVE_POLL - -/* Define if you have the header file. */ -#undef HAVE_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_PTY_H - -/* Define if you have the `select' function. */ -#undef HAVE_SELECT - -/* Define if you have the header file. */ -#undef HAVE_SHADOW_H - -/* Define if you have the `socket' function. */ -#undef HAVE_SOCKET - -/* Define if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define if you have the `strerror' function. */ -#undef HAVE_STRERROR - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STRING_H - -/* Define if you have the header file. */ -#undef HAVE_STROPTS_H - -/* Define if you have the `strsignal' function. */ -#undef HAVE_STRSIGNAL - -/* Define if you have the `strtol' function. */ -#undef HAVE_STRTOL - -/* Define if `ut_addr' is member of `struct utmp'. */ -#undef HAVE_STRUCT_UTMP_UT_ADDR - -/* Define if `ut_addr_v6' is member of `struct utmp'. */ -#undef HAVE_STRUCT_UTMP_UT_ADDR_V6 - -/* Define if `ut_host' is member of `struct utmp'. */ -#undef HAVE_STRUCT_UTMP_UT_HOST - -/* Define if `ut_name' is member of `struct utmp'. */ -#undef HAVE_STRUCT_UTMP_UT_NAME - -/* Define if `ut_user' is member of `struct utmp'. */ -#undef HAVE_STRUCT_UTMP_UT_USER - -/* Define if you have the `syslog' function. */ -#undef HAVE_SYSLOG - -/* Define if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_POLL_H - -/* Define if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define if a we have working UNIX98 pty handling */ -#undef HAVE_UNIX98_PTYS - -/* Define if you have the header file. */ -#undef HAVE_UTMPX_H - -/* Define if you have the header file. */ -#undef HAVE_UTMP_H - -/* Define if you have the `vprintf' function. */ -#undef HAVE_VPRINTF - -/* Define if you have the `vsnprintf' function. */ -#undef HAVE_VSNPRINTF - -/* Define if you have the header file. */ -#undef HAVE_X11_XAUTH_H - -/* Define if you have the header file. */ -#undef HAVE_ZLIB_H - -/* The name of this software distribution */ -#undef PACKAGE - -/* The installation prefix */ -#undef PREFIX - -/* Traditional BSD pty handling */ -#undef PTY_BSD_SCHEME - -/* Possible first characters in a /dev/ptyXX name */ -#undef PTY_BSD_SCHEME_FIRST_CHARS - -/* Possible second characters in a /dev/ptyXX name */ -#undef PTY_BSD_SCHEME_SECOND_CHARS - -/* sbin directory */ -#undef SBINDIR - -/* Define to indicate that shutdown seems to work properly */ -#undef SHUTDOWN_WORKS_WITH_UNIX_SOCKETS - -/* The size of a `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of a `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of a `short', as computed by sizeof. */ -#undef SIZEOF_SHORT - -/* Location of the SSH1 daemon */ -#undef SSHD1 - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ -#undef STACK_DIRECTION - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* The version of this software distribution */ -#undef VERSION - -/* Define to enable authentication agent forwarding */ -#undef WITH_AGENT_FORWARD - -/* Use gcov */ -#undef WITH_GCOV - -/* For Ipv6 support */ -#undef WITH_IPV6 - -/* For kerberos */ -#undef WITH_KERBEROS - -/* Define to enable pty support */ -#undef WITH_PTY_SUPPORT - -/* Define if SRP should be supported */ -#undef WITH_SRP - -/* Define to enable fallback to SSH1 */ -#undef WITH_SSH1_FALLBACK - -/* Define to enable tcp forwarding */ -#undef WITH_TCP_FORWARD - -/* For utmp support */ -#undef WITH_UTMP - -/* Define to enable x11 forwarding */ -#undef WITH_X11_FORWARD - -/* Define if zlib should be used */ -#undef WITH_ZLIB - -/* Define if your processor stores words with the most significant byte first - (like Motorola and SPARC, unlike Intel and VAX). */ -#undef WORDS_BIGENDIAN - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define to `int' if doesn't define. */ -#undef gid_t - -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ -#undef inline - -/* Define to `unsigned' if does not define. */ -#undef size_t - -/* Length type used by getsockopt */ -#undef socklen_t - -/* Define to `int' if doesn't define. */ -#undef uid_t diff --git a/lsh/configure b/lsh/configure deleted file mode 100755 index 72c2bb9..0000000 --- a/lsh/configure +++ /dev/null @@ -1,9958 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by Autoconf 2.50 for lsh 1.3.1. -# -# Report bugs to . -# -# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -# Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -exec 6>&1 - -# -# Initializations. -# -ac_default_prefix=/usr/local -cross_compiling=no -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - -# Avoid depending upon Character Ranges. -ac_cr_az='abcdefghijklmnopqrstuvwxyz' -ac_cr_AZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -ac_cr_09='0123456789' -ac_cr_alnum=$ac_cr_az$ac_cr_AZ$ac_cr_09 - -# Sed expression to map a string onto a valid sh and CPP variable names. -ac_tr_sh="sed y%*+%pp%;s%[^_$ac_cr_alnum]%_%g" -ac_tr_cpp="sed y%*$ac_cr_az%P$ac_cr_AZ%;s%[^_$ac_cr_alnum]%_%g" - -ac_unique_file="src/lsh_types.h" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#include -#include -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#else -# if HAVE_STRINGS_H -# include -# endif -#endif -#if HAVE_INTTYPES_H -# include -#endif -#if HAVE_UNISTD_H -# include -#endif" - -ac_subdirs_all="$ac_subdirs_all src/argp" -ac_subdirs_all="$ac_subdirs_all src/nettle" -ac_subdirs_all="$ac_subdirs_all src/sftp" - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Identity of this package. -PACKAGE_NAME='lsh' -PACKAGE_TARNAME='lsh' -PACKAGE_VERSION='1.3.1' -PACKAGE_STRING='lsh 1.3.1' -PACKAGE_BUGREPORT='bug-lsh@gnu.org' - -ac_prev= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_option in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - eval "enable_$ac_feature=no" ;; - - -enable-* | --enable-*) - ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "enable_$ac_feature='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package| sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "with_$ac_package='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/-/_/g'` - eval "with_$ac_package=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` - eval "$ac_envvar='$ac_optarg'" - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$ac_cr_alnum]" >/dev/null && - echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -# Be sure to have absolute paths. -for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ - localstatedir libdir includedir oldincludedir infodir mandir \ - exec_prefix prefix -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* ) ;; - NONE ) ;; - *) { echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: should be removed in autoconf 3.0. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo "$ac_prog" | sed 's%[\\/][^\\/][^\\/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "$as_me: error: cannot find sources in $ac_confdir or .." >&2 - { (exit 1); exit 1; }; } - else - { echo "$as_me: error: cannot find sources in $srcdir" >&2 - { (exit 1); exit 1; }; } - fi -fi -srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` -ac_env_build_alias_set=${build_alias+set} -ac_env_build_alias_value=$build_alias -ac_cv_env_build_alias_set=${build_alias+set} -ac_cv_env_build_alias_value=$build_alias -ac_env_host_alias_set=${host_alias+set} -ac_env_host_alias_value=$host_alias -ac_cv_env_host_alias_set=${host_alias+set} -ac_cv_env_host_alias_value=$host_alias -ac_env_target_alias_set=${target_alias+set} -ac_env_target_alias_value=$target_alias -ac_cv_env_target_alias_set=${target_alias+set} -ac_cv_env_target_alias_value=$target_alias -ac_env_CC_set=${CC+set} -ac_env_CC_value=$CC -ac_cv_env_CC_set=${CC+set} -ac_cv_env_CC_value=$CC -ac_env_CFLAGS_set=${CFLAGS+set} -ac_env_CFLAGS_value=$CFLAGS -ac_cv_env_CFLAGS_set=${CFLAGS+set} -ac_cv_env_CFLAGS_value=$CFLAGS -ac_env_LDFLAGS_set=${LDFLAGS+set} -ac_env_LDFLAGS_value=$LDFLAGS -ac_cv_env_LDFLAGS_set=${LDFLAGS+set} -ac_cv_env_LDFLAGS_value=$LDFLAGS -ac_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_env_CPPFLAGS_value=$CPPFLAGS -ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat < if you have libraries in a - nonstandard directory - CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have - headers in a nonstandard directory - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -Report bugs to . -EOF -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - ac_popdir=`pwd` - for ac_subdir in : $ac_subdirs_all; do test "x$ac_subdir" = x: && continue - cd $ac_subdir - # A "../" for each directory in /$ac_subdir. - ac_dots=`echo $ac_subdir | - sed 's,^\./,,;s,[^/]$,&/,;s,[^/]*/,../,g'` - - case $srcdir in - .) # No --srcdir option. We are building in place. - ac_sub_srcdir=$srcdir ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_sub_srcdir=$srcdir/$ac_subdir ;; - *) # Relative path. - ac_sub_srcdir=$ac_dots$srcdir/$ac_subdir ;; - esac - - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_sub_srcdir/configure.gnu; then - echo - $SHELL $ac_sub_srcdir/configure.gnu --help=recursive - elif test -f $ac_sub_srcdir/configure; then - echo - $SHELL $ac_sub_srcdir/configure --help=recursive - elif test -f $ac_sub_srcdir/configure.ac || - test -f $ac_sub_srcdir/configure.in; then - echo - $ac_configure --help - else - echo "$as_me: WARNING: no configuration information is in $ac_subdir" >&2 - fi - cd $ac_popdir - done -fi - -test -n "$ac_init_help" && exit 0 -if $ac_init_version; then - cat <<\EOF -lsh configure 1.3.1 -generated by GNU Autoconf 2.50 - -Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -EOF - exit 0 -fi -exec 5>config.log -cat >&5 </dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -hostinfo = `(hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -PATH = $PATH - -_ASUNAME -} >&5 - -cat >&5 <\?\"\']*) - ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` - ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" - ac_sep=" " ;; - *) ac_configure_args="$ac_configure_args$ac_sep$ac_arg" - ac_sep=" " ;; - esac - # Get rid of the leading space. -done - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - echo >&5 - echo "## ----------------- ##" >&5 - echo "## Cache variables. ##" >&5 - echo "## ----------------- ##" >&5 - echo >&5 - # The following way of writing the cache mishandles newlines in values, -{ - (set) 2>&1 | - case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in - *ac_space=\ *) - sed -n \ - "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" - ;; - *) - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} >&5 - sed "/^$/d" confdefs.h >conftest.log - if test -s conftest.log; then - echo >&5 - echo "## ------------ ##" >&5 - echo "## confdefs.h. ##" >&5 - echo "## ------------ ##" >&5 - echo >&5 - cat conftest.log >&5 - fi - (echo; echo) >&5 - test "$ac_signal" != 0 && - echo "$as_me: caught signal $ac_signal" >&5 - echo "$as_me: exit $exit_status" >&5 - rm -rf conftest* confdefs* core core.* *.core conf$$* $ac_clean_files && - exit $exit_status - ' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_status=$?; ac_signal='$ac_signal'; { (exit $ac_status); exit $ac_status; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo >confdefs.h - -# Let the site file select an alternate cache file if it wants to. -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - { echo "$as_me:887: loading site script $ac_site_file" >&5 -echo "$as_me: loading site script $ac_site_file" >&6;} - cat "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { echo "$as_me:898: loading cache $cache_file" >&5 -echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . $cache_file;; - *) . ./$cache_file;; - esac - fi -else - { echo "$as_me:906: creating cache $cache_file" >&5 -echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_suggest_removing_cache=false -for ac_var in `(set) 2>&1 | - sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val="\$ac_cv_env_${ac_var}_value" - eval ac_new_val="\$ac_env_${ac_var}_value" - case $ac_old_set,$ac_new_set in - set,) - { echo "$as_me:922: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,set) - { echo "$as_me:926: WARNING: \`$ac_var' was not set in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was not set in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - { echo "$as_me:932: WARNING: \`$ac_var' has changed since the previous run:" >&5 -echo "$as_me: WARNING: \`$ac_var' has changed since the previous run:" >&2;} - { echo "$as_me:934: WARNING: former value: $ac_old_val" >&5 -echo "$as_me: WARNING: former value: $ac_old_val" >&2;} - { echo "$as_me:936: WARNING: current value: $ac_new_val" >&5 -echo "$as_me: WARNING: current value: $ac_new_val" >&2;} - ac_suggest_removing_cache=: - fi;; - esac -done -if $ac_suggest_removing_cache; then - { echo "$as_me:943: WARNING: changes in the environment can compromise the build" >&5 -echo "$as_me: WARNING: changes in the environment can compromise the build" >&2;} - { echo "$as_me:945: WARNING: consider removing $cache_file and starting over" >&5 -echo "$as_me: WARNING: consider removing $cache_file and starting over" >&2;} -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac -echo "#! $SHELL" >conftest.sh -echo "exit 0" >>conftest.sh -chmod +x conftest.sh -if { (echo "$as_me:964: PATH=\".;.\"; conftest.sh") >&5 - (PATH=".;."; conftest.sh) 2>&5 - ac_status=$? - echo "$as_me:967: \$? = $ac_status" >&5 - (exit $ac_status); }; then - ac_path_separator=';' -else - ac_path_separator=: -fi -PATH_SEPARATOR="$ac_path_separator" -rm -f conftest.sh - -ac_aux_dir= -for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do - if test -f $ac_dir/install-sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f $ac_dir/install.sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f $ac_dir/shtool; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - { { echo "$as_me:993: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 -echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} - { (exit 1); exit 1; }; } -fi -ac_config_guess="$SHELL $ac_aux_dir/config.guess" -ac_config_sub="$SHELL $ac_aux_dir/config.sub" -ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# ./install, which can be erroneously created by make from ./install.sh. -echo "$as_me:1013: checking for a BSD compatible install" >&5 -echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6 -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_save_IFS=$IFS; IFS=$ac_path_separator - for ac_dir in $PATH; do - IFS=$ac_save_IFS - # Account for people who put trailing slashes in PATH elements. - case $ac_dir/ in - / | ./ | .// | /cC/* \ - | /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* \ - | /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - if $as_executable_p "$ac_dir/$ac_prog"; then - if test $ac_prog = install && - grep dspmsg "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - ac_cv_path_install="$ac_dir/$ac_prog -c" - break 2 - fi - fi - done - ;; - esac - done - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. We don't cache a - # path for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the path is relative. - INSTALL=$ac_install_sh - fi -fi -echo "$as_me:1062: result: $INSTALL" >&5 -echo "${ECHO_T}$INSTALL" >&6 - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -echo "$as_me:1073: checking whether build environment is sane" >&5 -echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6 -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "$*" != "X $srcdir/configure conftestfile" \ - && test "$*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - { { echo "$as_me:1096: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&5 -echo "$as_me: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&2;} - { (exit 1); exit 1; }; } - fi - - test "$2" = conftestfile - ) -then - # Ok. - : -else - { { echo "$as_me:1109: error: newly created file is older than distributed files! -Check your system clock" >&5 -echo "$as_me: error: newly created file is older than distributed files! -Check your system clock" >&2;} - { (exit 1); exit 1; }; } -fi -rm -f conftest* -echo "$as_me:1116: result: yes" >&5 -echo "${ECHO_T}yes" >&6 -if test "$program_transform_name" = s,x,x,; then - program_transform_name= -else - # Double any \ or $. echo might interpret backslashes. - cat <<\EOF >conftest.sed -s,\\,\\\\,g; s,\$,$$,g -EOF - program_transform_name=`echo $program_transform_name | sed -f conftest.sed` - rm -f conftest.sed -fi -test "$program_prefix" != NONE && - program_transform_name="s,^,${program_prefix},;$program_transform_name" -# Use a double $ so make ignores it. -test "$program_suffix" != NONE && - program_transform_name="s,\$\$,${program_suffix},;$program_transform_name" - -# sed with no file args requires a program. -test -z "$program_transform_name" && program_transform_name="s,x,x," - -echo "$as_me:1137: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1157: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1161: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -PACKAGE=lsh - -VERSION=1.3.4 - -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - { { echo "$as_me:1171: error: source directory already configured; run \"make distclean\" there first" >&5 -echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;} - { (exit 1); exit 1; }; } -fi - -cat >>confdefs.h <>confdefs.h <&5 -echo $ECHO_N "checking for working aclocal... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (aclocal --version) < /dev/null > /dev/null 2>&1; then - ACLOCAL=aclocal - echo "$as_me:1192: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - ACLOCAL="$missing_dir/missing aclocal" - echo "$as_me:1196: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1200: checking for working autoconf" >&5 -echo $ECHO_N "checking for working autoconf... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoconf --version) < /dev/null > /dev/null 2>&1; then - AUTOCONF=autoconf - echo "$as_me:1207: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOCONF="$missing_dir/missing autoconf" - echo "$as_me:1211: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1215: checking for working automake" >&5 -echo $ECHO_N "checking for working automake... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (automake --version) < /dev/null > /dev/null 2>&1; then - AUTOMAKE=automake - echo "$as_me:1222: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOMAKE="$missing_dir/missing automake" - echo "$as_me:1226: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1230: checking for working autoheader" >&5 -echo $ECHO_N "checking for working autoheader... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoheader --version) < /dev/null > /dev/null 2>&1; then - AUTOHEADER=autoheader - echo "$as_me:1237: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOHEADER="$missing_dir/missing autoheader" - echo "$as_me:1241: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1245: checking for working makeinfo" >&5 -echo $ECHO_N "checking for working makeinfo... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (makeinfo --version) < /dev/null > /dev/null 2>&1; then - MAKEINFO=makeinfo - echo "$as_me:1252: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - MAKEINFO="$missing_dir/missing makeinfo" - echo "$as_me:1256: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -ac_config_headers="$ac_config_headers config.h" - -ac_config_commands="$ac_config_commands default-1" - -# AC_CONFIG_HEADERS(config.h) - -# FIXME: Move this to the Makefile, as recommended by the autoconf manual. - -cat >>confdefs.h <>confdefs.h <&5 -echo "$as_me: WARNING: Converted $oldsrcdir to $srcdir, -If this does not work, please use an absolute path to the configure script. " >&2;} - ;; -esac - -# echo Replacing CPPFLAGS: $CPPFLAGS -# FIXME: Should be obsoleted by the nettle library -# We want to compile the crypto lib for use with lsh -# CPPFLAGS="$CPPFLAGS -I$srcdir -I$srcdir/src -I$srcdir/src/symmetric/include -DLSH" - -# src/rsync relies on lsh's definitions of WRITE_UINT32 etc. -CPPFLAGS="-I$srcdir/src -DLSH" - -# GNU libc defaults to supplying the ISO C library functions only. -# initgroups() and strsignal() are extensions; the _GNU_SOURCE define -# enables these extensions. -# Enable it on all systems; no problems have been reported with it so far. - -# We can't use AH_VERBATIM for this, as we want _GNU_SOURCE to be defined -# when running configure's test programs. -CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" - -# Check options -# Check whether --enable-debug_alloc or --disable-debug_alloc was given. -if test "${enable_debug_alloc+set}" = set; then - enableval="$enable_debug_alloc" - -else - enable_debug_alloc=no -fi; - -if test x$enable_debug_alloc = xyes ; then - cat >>confdefs.h <<\EOF -#define DEBUG_ALLOC 1 -EOF - -fi - -# Check whether --enable-debug_trace or --disable-debug_trace was given. -if test "${enable_debug_trace+set}" = set; then - enableval="$enable_debug_trace" - -else - enable_debug_trace=no -fi; - -if test x$enable_debug_trace = xyes ; then - cat >>confdefs.h <<\EOF -#define DEBUG_TRACE 1 -EOF - -fi - -# Check whether --enable-gcov or --disable-gcov was given. -if test "${enable_gcov+set}" = set; then - enableval="$enable_gcov" - -else - enable_gcov=no -fi; - -# Check whether --with-zlib or --without-zlib was given. -if test "${with_zlib+set}" = set; then - withval="$with_zlib" - -else - with_zlib=yes -fi; - -# Checking this variable is delayed until we have checked if zlib is -# actually available. - -# Check whether --enable-pty or --disable-pty was given. -if test "${enable_pty+set}" = set; then - enableval="$enable_pty" - -else - enable_pty=yes -fi; - -if test x$enable_pty = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_PTY_SUPPORT 1 -EOF - -fi - -# Check whether --with-sshd1 or --without-sshd1 was given. -if test "${with_sshd1+set}" = set; then - withval="$with_sshd1" - -else - with_sshd1=yes -fi; - -# Default sshd1 path -if test x$with_sshd1 = xyes ; then - with_sshd1=/usr/local/sbin/sshd1 -fi - -if test x$with_sshd1 != xno ; then - cat >>confdefs.h <<\EOF -#define WITH_SSH1_FALLBACK 1 -EOF - - cat >>confdefs.h <>confdefs.h <<\EOF -#define WITH_SRP 1 -EOF - - SRP_PROGRAM=srp-gen -fi - -# Check whether --enable-datafellows_workarounds or --disable-datafellows_workarounds was given. -if test "${enable_datafellows_workarounds+set}" = set; then - enableval="$enable_datafellows_workarounds" - -else - enable_datafellows_workarounds=yes -fi; - -if test x$enable_datafellows_workarounds = xyes ; then - cat >>confdefs.h <<\EOF -#define DATAFELLOWS_WORKAROUNDS 1 -EOF - -fi - -# Check whether --enable-tcp_forward or --disable-tcp_forward was given. -if test "${enable_tcp_forward+set}" = set; then - enableval="$enable_tcp_forward" - -else - enable_tcp_forward=yes -fi; - -if test x$enable_tcp_forward = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_TCP_FORWARD 1 -EOF - -fi - -# Check whether --enable-x11_forward or --disable-x11_forward was given. -if test "${enable_x11_forward+set}" = set; then - enableval="$enable_x11_forward" - -else - eanble_x11_forward=yes -fi; - -if test x$enable_x11_forward = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_X11_FORWARD 1 -EOF - -fi - -# Check whether --enable-agent_forward or --disable-agent_forward was given. -if test "${enable_agent_forward+set}" = set; then - enableval="$enable_agent_forward" - -else - with_agent_forward=yes -fi; - -if test x$disable_agent_forward = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_AGENT_FORWARD 1 -EOF - -fi - -# Check whether --with-scheme or --without-scheme was given. -if test "${with_scheme+set}" = set; then - withval="$with_scheme" - -else - with_scheme= -fi; - -# Check whether --with-system-argp or --without-system-argp was given. -if test "${with_system_argp+set}" = set; then - withval="$with_system_argp" - -else - with_system_argp=yes -fi; - -# IPv6 support -# Check whether --enable-ipv6 or --disable-ipv6 was given. -if test "${enable_ipv6+set}" = set; then - enableval="$enable_ipv6" - -else - enable_ipv6=yes -fi; - -# utmp/wtmp logging -# Check whether --enable-utmp or --disable-utmp was given. -if test "${enable_utmp+set}" = set; then - enableval="$enable_utmp" - -else - enable_utmp=yes -fi; - -if test x$enable_utmp = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_UTMP 1 -EOF - -fi - -# Check whether --with-include-path or --without-include-path was given. -if test "${with_include_path+set}" = set; then - withval="$with_include_path" - -else - with_include_path='' -fi; - -if test x$with_include_path != x ; then - CPPFLAGS="$CPPFLAGS -I `echo $with_include_path | sed 's/:/ -I /g'`" -fi - -# Check whether --with-lib-path or --without-lib-path was given. -if test "${with_lib_path+set}" = set; then - withval="$with_lib_path" - -else - with_lib_path='' -fi; - -if test x$with_lib_path != x ; then - LDFLAGS="-L `echo $with_lib_path | sed 's/:/ -L /g'`" -fi - -echo "$as_me:1546: checking for -R flag" >&5 -echo $ECHO_N "checking for -R flag... $ECHO_C" >&6 -RPATHFLAG='' -case `uname -sr` in - OSF1\ V4.*) - RPATHFLAG="-rpath " - ;; - IRIX\ 6.*) - RPATHFLAG="-rpath " - ;; - IRIX\ 5.*) - RPATHFLAG="-rpath " - ;; - SunOS\ 5.*) - if test "$TCC" = "yes"; then - # tcc doesn't know about -R - RPATHFLAG="-Wl,-R," - else - RPATHFLAG=-R - fi - ;; - Linux\ 2.*) - RPATHFLAG="-Wl,-rpath," - ;; - *) - : - ;; -esac - -if test x$RPATHFLAG = x ; then - echo "$as_me:1576: result: none" >&5 -echo "${ECHO_T}none" >&6 -else - echo "$as_me:1579: result: using $RPATHFLAG" >&5 -echo "${ECHO_T}using $RPATHFLAG" >&6 -fi - -RPATH_CANDIDATE_REAL_DIRS='' -RPATH_CANDIDATE_DIRS='' - -echo "$as_me:1586: result: Searching for libraries" >&5 -echo "${ECHO_T}Searching for libraries" >&6 - -for d in `echo $with_lib_path | sed 's/:/ /g'` \ - `echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed "s@^NONE@$ac_default_prefix/lib@g"` \ - /usr/local/lib /sw/local/lib /sw/lib \ - /usr/gnu/lib /opt/gnu/lib /sw/gnu/lib /usr/freeware/lib /usr/pkg/lib ; do - echo "$as_me:1593: checking $d" >&5 -echo $ECHO_N "checking $d... $ECHO_C" >&6 -ac_exists=no -if test -d "$d/." ; then - ac_real_dir=`cd $d && pwd` - if test -n "$ac_real_dir" ; then - ac_exists=yes - for old in RPATH_CANDIDATE_REAL_DIRS ; do - ac_found=no - if test x$ac_real_dir = x$old ; then - ac_found=yes; - break; - fi - done - if test $ac_found = yes ; then - echo "$as_me:1608: result: already added" >&5 -echo "${ECHO_T}already added" >&6 - else - echo "$as_me:1611: result: added" >&5 -echo "${ECHO_T}added" >&6 - # LDFLAGS="$LDFLAGS -L $d" - RPATH_CANDIDATE_REAL_DIRS="$ac_real_dir $RPATH_CANDIDATE_REAL_DIRS" - RPATH_CANDIDATE_DIRS="$d $RPATH_CANDIDATE_DIRS" - fi - fi -fi -if test $ac_exists = no ; then - echo "$as_me:1620: result: not found" >&5 -echo "${ECHO_T}not found" >&6 -fi - -done - -# Checks for programs. -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -echo "$as_me:1635: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}gcc" -echo "$as_me:1650: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1658: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1661: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo "$as_me:1670: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="gcc" -echo "$as_me:1685: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1693: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1696: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -echo "$as_me:1709: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}cc" -echo "$as_me:1724: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1732: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1735: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1744: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="cc" -echo "$as_me:1759: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1767: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1770: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1783: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue -fi -ac_cv_prog_CC="cc" -echo "$as_me:1803: found $ac_dir/$ac_word" >&5 -break -done - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - set dummy "$ac_dir/$ac_word" ${1+"$@"} - shift - ac_cv_prog_CC="$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1825: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1828: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:1839: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="$ac_tool_prefix$ac_prog" -echo "$as_me:1854: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1862: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1865: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:1878: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="$ac_prog" -echo "$as_me:1893: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1901: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1904: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CC" && break -done - - CC=$ac_ct_CC -fi - -fi - -test -z "$CC" && { { echo "$as_me:1916: error: no acceptable cc found in \$PATH" >&5 -echo "$as_me: error: no acceptable cc found in \$PATH" >&2;} - { (exit 1); exit 1; }; } - -cat >conftest.$ac_ext <<_ACEOF -#line 1921 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.exe" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compiler, and finding out an intuition -# of exeext. -echo "$as_me:1937: checking for C compiler default output" >&5 -echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6 -ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` -if { (eval echo "$as_me:1940: \"$ac_link_default\"") >&5 - (eval $ac_link_default) 2>&5 - ac_status=$? - echo "$as_me:1943: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `ls a.exe conftest.exe a.* conftest conftest.* 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - a.out ) # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1960: error: C compiler cannot create executables" >&5 -echo "$as_me: error: C compiler cannot create executables" >&2;} - { (exit 77); exit 77; }; } -fi - -ac_exeext=$ac_cv_exeext -echo "$as_me:1966: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6 - -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1971: checking whether the C compiler works" >&5 -echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (eval echo "$as_me:1977: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1980: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { echo "$as_me:1987: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&5 -echo "$as_me: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&2;} - { (exit 1); exit 1; }; } - fi - fi -fi -echo "$as_me:1995: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - -rm -f a.out a.exe conftest$ac_cv_exeext -ac_clean_files=$ac_clean_files_save -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:2002: checking whether we are cross compiling" >&5 -echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 -echo "$as_me:2004: result: $cross_compiling" >&5 -echo "${ECHO_T}$cross_compiling" >&6 - -echo "$as_me:2007: checking for executable suffix" >&5 -echo $ECHO_N "checking for executable suffix... $ECHO_C" >&6 -if { (eval echo "$as_me:2009: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2012: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in `(ls conftest.exe; ls conftest; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - { { echo "$as_me:2028: error: cannot compute EXEEXT: cannot compile and link" >&5 -echo "$as_me: error: cannot compute EXEEXT: cannot compile and link" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest$ac_cv_exeext -echo "$as_me:2034: result: $ac_cv_exeext" >&5 -echo "${ECHO_T}$ac_cv_exeext" >&6 - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -echo "$as_me:2040: checking for object suffix" >&5 -echo $ECHO_N "checking for object suffix... $ECHO_C" >&6 -if test "${ac_cv_objext+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2046 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (eval echo "$as_me:2058: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2061: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:2073: error: cannot compute OBJEXT: cannot compile" >&5 -echo "$as_me: error: cannot compute OBJEXT: cannot compile" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -echo "$as_me:2080: result: $ac_cv_objext" >&5 -echo "${ECHO_T}$ac_cv_objext" >&6 -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -echo "$as_me:2084: checking whether we are using the GNU C compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 -if test "${ac_cv_c_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2090 "configure" -#include "confdefs.h" - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2105: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2108: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2111: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2114: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_compiler_gnu=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:2126: result: $ac_cv_c_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 -GCC=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" -echo "$as_me:2132: checking whether $CC accepts -g" >&5 -echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2138 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2150: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2153: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2156: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2159: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_g=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_prog_cc_g=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2169: result: $ac_cv_prog_cc_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -# Some people use a C++ compiler to compile C. Since we use `exit', -# in C++ we need to declare it. In case someone uses the same compiler -# for both compiling C and C++ we need to have the C++ compiler decide -# the declaration of exit, since it's the most demanding environment. -cat >conftest.$ac_ext <<_ACEOF -#ifndef __cplusplus - choke me -#endif -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2196: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2199: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2202: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2205: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - for ac_declaration in \ - ''\ - '#include ' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -#line 2217 "configure" -#include "confdefs.h" -#include -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2230: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2233: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2236: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2239: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -continue -fi -rm -f conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -#line 2249 "configure" -#include "confdefs.h" -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2261: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2264: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2267: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2270: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -echo '#ifdef __cplusplus' >>confdefs.h -echo $ac_declaration >>confdefs.h -echo '#endif' >>confdefs.h - -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:2294: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:2314: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:2318: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -echo "$as_me:2326: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" -echo "$as_me:2341: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - echo "$as_me:2349: result: $RANLIB" >&5 -echo "${ECHO_T}$RANLIB" >&6 -else - echo "$as_me:2352: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -echo "$as_me:2361: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_RANLIB="ranlib" -echo "$as_me:2376: found $ac_dir/$ac_word" >&5 -break -done - - test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":" -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - echo "$as_me:2385: result: $ac_ct_RANLIB" >&5 -echo "${ECHO_T}$ac_ct_RANLIB" >&6 -else - echo "$as_me:2388: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - RANLIB=$ac_ct_RANLIB -else - RANLIB="$ac_cv_prog_RANLIB" -fi - -echo "$as_me:2397: checking for ${CC-cc} option to accept ANSI C" >&5 -echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6 -if test "${am_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - cat >conftest.$ac_ext <<_ACEOF -#line 2414 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; - -int -main () -{ - -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2456: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2459: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2462: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2465: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - am_cv_prog_cc_stdc="$ac_arg"; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -CC="$ac_save_CC" - -fi - -if test -z "$am_cv_prog_cc_stdc"; then - echo "$as_me:2479: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 -else - echo "$as_me:2482: result: $am_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$am_cv_prog_cc_stdc" >&6 -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac - -if test "x$am_cv_prog_cc_stdc" = xno ; then - { { echo "$as_me:2491: error: the C compiler doesn't handle ANSI-C" >&5 -echo "$as_me: error: the C compiler doesn't handle ANSI-C" >&2;} - { (exit 1); exit 1; }; } -fi - -# Use a particular scheme implementation? -if test x$with_scheme != x ; then - # Extract the first word of "$with_scheme", so it can be a program name with args. -set dummy $with_scheme; ac_word=$2 -echo "$as_me:2500: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_path_SCHEME_PROGRAM+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - case $SCHEME_PROGRAM in - [\\/]* | ?:[\\/]*) - ac_cv_path_SCHEME_PROGRAM="$SCHEME_PROGRAM" # Let the user override the test with a path. - ;; - *) - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - if $as_executable_p "$ac_dir/$ac_word"; then - ac_cv_path_SCHEME_PROGRAM="$ac_dir/$ac_word" - echo "$as_me:2517: found $ac_dir/$ac_word" >&5 - break -fi -done - - ;; -esac -fi -SCHEME_PROGRAM=$ac_cv_path_SCHEME_PROGRAM - -if test -n "$SCHEME_PROGRAM"; then - echo "$as_me:2528: result: $SCHEME_PROGRAM" >&5 -echo "${ECHO_T}$SCHEME_PROGRAM" >&6 -else - echo "$as_me:2531: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -else - for ac_prog in guile scsh -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:2540: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_path_SCHEME_PROGRAM+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - case $SCHEME_PROGRAM in - [\\/]* | ?:[\\/]*) - ac_cv_path_SCHEME_PROGRAM="$SCHEME_PROGRAM" # Let the user override the test with a path. - ;; - *) - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - if $as_executable_p "$ac_dir/$ac_word"; then - ac_cv_path_SCHEME_PROGRAM="$ac_dir/$ac_word" - echo "$as_me:2557: found $ac_dir/$ac_word" >&5 - break -fi -done - - ;; -esac -fi -SCHEME_PROGRAM=$ac_cv_path_SCHEME_PROGRAM - -if test -n "$SCHEME_PROGRAM"; then - echo "$as_me:2568: result: $SCHEME_PROGRAM" >&5 -echo "${ECHO_T}$SCHEME_PROGRAM" >&6 -else - echo "$as_me:2571: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$SCHEME_PROGRAM" && break -done - -fi - -if test x$SCHEME_PROGRAM = x ; then - { echo "$as_me:2581: WARNING: No scheme implementation found. -This is fine as long as you don't modify the source files." >&5 -echo "$as_me: WARNING: No scheme implementation found. -This is fine as long as you don't modify the source files." >&2;} - SCHEME_PROGRAM=false -fi - -SCHEME_NAME=`basename $SCHEME_PROGRAM` - -# Extract the first word of "bash", so it can be a program name with args. -set dummy bash; ac_word=$2 -echo "$as_me:2592: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_path_BASH+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - case $BASH in - [\\/]* | ?:[\\/]*) - ac_cv_path_BASH="$BASH" # Let the user override the test with a path. - ;; - *) - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - if $as_executable_p "$ac_dir/$ac_word"; then - ac_cv_path_BASH="$ac_dir/$ac_word" - echo "$as_me:2609: found $ac_dir/$ac_word" >&5 - break -fi -done - - ;; -esac -fi -BASH=$ac_cv_path_BASH - -if test -n "$BASH"; then - echo "$as_me:2620: result: $BASH" >&5 -echo "${ECHO_T}$BASH" >&6 -else - echo "$as_me:2623: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -# Extract the first word of "groff", so it can be a program name with args. -set dummy groff; ac_word=$2 -echo "$as_me:2629: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_path_GROFF+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - case $GROFF in - [\\/]* | ?:[\\/]*) - ac_cv_path_GROFF="$GROFF" # Let the user override the test with a path. - ;; - *) - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - if $as_executable_p "$ac_dir/$ac_word"; then - ac_cv_path_GROFF="$ac_dir/$ac_word" - echo "$as_me:2646: found $ac_dir/$ac_word" >&5 - break -fi -done - - ;; -esac -fi -GROFF=$ac_cv_path_GROFF - -if test -n "$GROFF"; then - echo "$as_me:2657: result: $GROFF" >&5 -echo "${ECHO_T}$GROFF" >&6 -else - echo "$as_me:2660: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -# Extract the first word of "m4", so it can be a program name with args. -set dummy m4; ac_word=$2 -echo "$as_me:2666: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_path_M4+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - case $M4 in - [\\/]* | ?:[\\/]*) - ac_cv_path_M4="$M4" # Let the user override the test with a path. - ;; - *) - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - if $as_executable_p "$ac_dir/$ac_word"; then - ac_cv_path_M4="$ac_dir/$ac_word" - echo "$as_me:2683: found $ac_dir/$ac_word" >&5 - break -fi -done - - test -z "$ac_cv_path_M4" && ac_cv_path_M4="m4" - ;; -esac -fi -M4=$ac_cv_path_M4 - -if test -n "$M4"; then - echo "$as_me:2695: result: $M4" >&5 -echo "${ECHO_T}$M4" >&6 -else - echo "$as_me:2698: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -echo "$as_me:2702: checking if m4 can handle eight-bit quote characters" >&5 -echo $ECHO_N "checking if m4 can handle eight-bit quote characters... $ECHO_C" >&6 -if test "${lsh_cv_prog_m4_quote_8bit+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test xfoo = x`echo 'change''quote(»,«)»foo«' | $M4`; then - lsh_cv_prog_m4_quote_8bit=yes - else - lsh_cv_prog_m4_quote_8bit=no - fi -fi -echo "$as_me:2713: result: $lsh_cv_prog_m4_quote_8bit" >&5 -echo "${ECHO_T}$lsh_cv_prog_m4_quote_8bit" >&6 - -if test x$lsh_cv_prog_m4_quote_8bit = xno; then - { echo "$as_me:2717: WARNING: To get the testsuite to work properly, you may need to -upgrade to a better version than GNU m4 1.4, or recompile -it with CFLAGS=-funsigned-char. -Latest version is available at " >&5 -echo "$as_me: WARNING: To get the testsuite to work properly, you may need to -upgrade to a better version than GNU m4 1.4, or recompile -it with CFLAGS=-funsigned-char. -Latest version is available at " >&2;} - M4="false --" -fi - -# Checks for header files. -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -echo "$as_me:2734: checking how to run the C preprocessor" >&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - # break 2 since there is a loop in there. - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2756 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2761: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2767: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2790 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2794: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2800: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break 2 -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:2837: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2847 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2852: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2858: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2881 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2885: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2891: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:2919: error: C preprocessor \"$CPP\" fails sanity check" >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:2930: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2936 "configure" -#include "confdefs.h" -#include -#include -#include -#include - -_ACEOF -if { (eval echo "$as_me:2944: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2950: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_header_stdc=no -fi -rm -f conftest.err conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2972 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2990 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 3011 "configure" -#include "confdefs.h" -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3037: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3040: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3042: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3045: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_stdc=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -fi -echo "$as_me:3058: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\EOF -#define STDC_HEADERS 1 -EOF - -fi - -# Some debian systems have both gmp and gmp2. -# This will probably not work right if both gmp.h and gmp2/gmp.h exists, -# and gmp.h is too old (i.e GMP-1.x). -gmp_header_found=no - -for ac_header in gmp.h gmp2/gmp.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:3076: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3082 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3086: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3092: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3111: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo "$as_me: error: Neither gmp.h nor gmp2/gmp.h found" >&2;} - { (exit 1); exit 1; }; } -fi - -for ac_header in fcntl.h strings.h sys/time.h unistd.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:3130: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3136 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3140: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3146: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3165: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3184 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3188: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3194: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3213: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3234 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3238: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3244: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3263: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3286 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3290: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3296: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3315: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3334 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3338: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3344: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3363: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3382 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3386: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3392: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3411: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3430 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3434: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3440: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3459: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3478 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3482: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3488: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3507: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3526 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3530: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3536: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3555: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3574 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3578: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3584: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3603: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3622 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3626: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3632: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3651: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for struct utmp.ut_host... $ECHO_C" >&6 -if test "${ac_cv_member_struct_utmp_ut_host+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3670 "configure" -#include "confdefs.h" -# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif - -int -main () -{ -struct utmp foo; -foo.ut_host; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3690: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3693: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3696: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3699: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_member_struct_utmp_ut_host=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_member_struct_utmp_ut_host=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3709: result: $ac_cv_member_struct_utmp_ut_host" >&5 -echo "${ECHO_T}$ac_cv_member_struct_utmp_ut_host" >&6 -if test $ac_cv_member_struct_utmp_ut_host = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for struct utmp.ut_name... $ECHO_C" >&6 -if test "${ac_cv_member_struct_utmp_ut_name+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3724 "configure" -#include "confdefs.h" -# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif - -int -main () -{ -struct utmp foo; -foo.ut_name; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3744: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3747: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3750: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3753: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_member_struct_utmp_ut_name=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_member_struct_utmp_ut_name=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3763: result: $ac_cv_member_struct_utmp_ut_name" >&5 -echo "${ECHO_T}$ac_cv_member_struct_utmp_ut_name" >&6 -if test $ac_cv_member_struct_utmp_ut_name = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for struct utmp.ut_user... $ECHO_C" >&6 -if test "${ac_cv_member_struct_utmp_ut_user+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3778 "configure" -#include "confdefs.h" -# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif - -int -main () -{ -struct utmp foo; -foo.ut_user; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3798: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3801: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3804: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3807: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_member_struct_utmp_ut_user=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_member_struct_utmp_ut_user=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3817: result: $ac_cv_member_struct_utmp_ut_user" >&5 -echo "${ECHO_T}$ac_cv_member_struct_utmp_ut_user" >&6 -if test $ac_cv_member_struct_utmp_ut_user = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for struct utmp.ut_addr... $ECHO_C" >&6 -if test "${ac_cv_member_struct_utmp_ut_addr+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3832 "configure" -#include "confdefs.h" -# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif - -int -main () -{ -struct utmp foo; -foo.ut_addr; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3852: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3855: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3858: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3861: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_member_struct_utmp_ut_addr=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_member_struct_utmp_ut_addr=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3871: result: $ac_cv_member_struct_utmp_ut_addr" >&5 -echo "${ECHO_T}$ac_cv_member_struct_utmp_ut_addr" >&6 -if test $ac_cv_member_struct_utmp_ut_addr = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for struct utmp.ut_addr_v6... $ECHO_C" >&6 -if test "${ac_cv_member_struct_utmp_ut_addr_v6+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3886 "configure" -#include "confdefs.h" -# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif - -int -main () -{ -struct utmp foo; -foo.ut_addr_v6; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3906: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3909: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3912: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3915: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_member_struct_utmp_ut_addr_v6=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_member_struct_utmp_ut_addr_v6=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3925: result: $ac_cv_member_struct_utmp_ut_addr_v6" >&5 -echo "${ECHO_T}$ac_cv_member_struct_utmp_ut_addr_v6" >&6 -if test $ac_cv_member_struct_utmp_ut_addr_v6 = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3946 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:3950: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:3956: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:3975: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3996 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:4000: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:4006: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:4025: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for socklen_t in sys/socket.h... $ECHO_C" >&6 -if test "${ac_cv_type_socklen_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 4051 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "socklen_t" >/dev/null 2>&1; then - ac_cv_type_socklen_t=yes -else - ac_cv_type_socklen_t=no -fi -rm -f conftest* - -fi -echo "$as_me:4065: result: $ac_cv_type_socklen_t" >&5 -echo "${ECHO_T}$ac_cv_type_socklen_t" >&6 -if test $ac_cv_type_socklen_t = no; then - echo "$as_me:4068: checking for AIX" >&5 -echo $ECHO_N "checking for AIX... $ECHO_C" >&6 - cat >conftest.$ac_ext <<_ACEOF -#line 4071 "configure" -#include "confdefs.h" - -#ifdef _AIX - yes -#endif - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "yes" >/dev/null 2>&1; then - -echo "$as_me:4082: result: yes" >&5 -echo "${ECHO_T}yes" >&6 -cat >>confdefs.h <<\EOF -#define socklen_t size_t -EOF - -else - -echo "$as_me:4090: result: no" >&5 -echo "${ECHO_T}no" >&6 -cat >>confdefs.h <<\EOF -#define socklen_t int -EOF - -fi -rm -f conftest* - -fi - -echo "$as_me:4101: checking for library containing mpz_get_d" >&5 -echo $ECHO_N "checking for library containing mpz_get_d... $ECHO_C" >&6 -if test "${ac_cv_search_mpz_get_d+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_search_save_LIBS="$LIBS" -ac_cv_search_mpz_get_d="no" -for i in gmp gmp2; do -LIBS="-l$i $ac_search_save_LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 4111 "configure" -#include "confdefs.h" -#if HAVE_GMP_H -#include -#elif HAVE_GMP2_GMP_H -#include -#endif - -int -main () -{ -mpz_get_d(0); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4128: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4131: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4134: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4137: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_search_mpz_get_d=-l$i -break - -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -done -LIBS="$ac_search_save_LIBS" - -fi -echo "$as_me:4151: result: $ac_cv_search_mpz_get_d" >&5 -echo "${ECHO_T}$ac_cv_search_mpz_get_d" >&6 -if test "x$ac_cv_search_mpz_get_d" != xno ; then - LIBS="$ac_cv_search_mpz_get_d $LIBS" -if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then - ac_success=no - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 4161 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:4166: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4169: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:4171: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4174: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_success=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - - if test $ac_success = no ; then - echo "$as_me:4187: checking Running simple test program failed. Trying -R flags" >&5 -echo $ECHO_N "checking Running simple test program failed. Trying -R flags... $ECHO_C" >&6 - ac_remaining_dirs='' - ac_rpath_save_LDFLAGS="$LDFLAGS" - for d in $RPATH_CANDIDATE_DIRS ; do - if test $ac_success = yes ; then - ac_remaining_dirs="$ac_remaining_dirs $d" - else - LDFLAGS="$RPATHFLAG$d $LDFLAGS" - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 4200 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:4205: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4208: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:4210: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4213: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes - ac_rpath_save_LDFLAGS="$LDFLAGS" - echo "$as_me:4217: result: adding $RPATHFLAG$d" >&5 -echo "${ECHO_T}adding $RPATHFLAG$d" >&6 - -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_remaining_dirs="$ac_remaining_dirs $d" -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - LDFLAGS="$ac_rpath_save_LDFLAGS" - fi - done - RPATH_CANDIDATE_DIRS=$ac_remaining_dirs - fi - if test $ac_success = no ; then - echo "$as_me:4234: result: failed" >&5 -echo "${ECHO_T}failed" >&6 - fi -fi - -else -{ { echo "$as_me:4240: error: GMP is missing. Get gmp-2.0.2 or better from ftp://ftp.gnu.org/pub/gnu/gmp" >&5 -echo "$as_me: error: GMP is missing. Get gmp-2.0.2 or better from ftp://ftp.gnu.org/pub/gnu/gmp" >&2;} - { (exit 1); exit 1; }; } -fi - -if test x$with_zlib = xyes; then - -echo "$as_me:4247: checking for inflate in -lz" >&5 -echo $ECHO_N "checking for inflate in -lz... $ECHO_C" >&6 -if test "${ac_cv_lib_z_inflate+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lz $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 4255 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char inflate (); -int -main () -{ -inflate (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4274: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4277: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4280: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4283: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_z_inflate=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_z_inflate=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:4294: result: $ac_cv_lib_z_inflate" >&5 -echo "${ECHO_T}$ac_cv_lib_z_inflate" >&6 -if test $ac_cv_lib_z_inflate = yes; then - cat >>confdefs.h <conftest.$ac_ext <<_ACEOF -#line 4316 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:4321: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4324: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:4326: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4329: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_success=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - - if test $ac_success = no ; then - echo "$as_me:4342: checking Running simple test program failed. Trying -R flags" >&5 -echo $ECHO_N "checking Running simple test program failed. Trying -R flags... $ECHO_C" >&6 - ac_remaining_dirs='' - ac_rpath_save_LDFLAGS="$LDFLAGS" - for d in $RPATH_CANDIDATE_DIRS ; do - if test $ac_success = yes ; then - ac_remaining_dirs="$ac_remaining_dirs $d" - else - LDFLAGS="$RPATHFLAG$d $LDFLAGS" - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 4355 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:4360: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4363: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:4365: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4368: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes - ac_rpath_save_LDFLAGS="$LDFLAGS" - echo "$as_me:4372: result: adding $RPATHFLAG$d" >&5 -echo "${ECHO_T}adding $RPATHFLAG$d" >&6 - -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_remaining_dirs="$ac_remaining_dirs $d" -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - LDFLAGS="$ac_rpath_save_LDFLAGS" - fi - done - RPATH_CANDIDATE_DIRS=$ac_remaining_dirs - fi - if test $ac_success = no ; then - echo "$as_me:4389: result: failed" >&5 -echo "${ECHO_T}failed" >&6 - fi -fi - -fi - -# X11 stuff. We only need libXau. -echo "$as_me:4397: checking for X" >&5 -echo $ECHO_N "checking for X... $ECHO_C" >&6 - -# Check whether --with-x or --without-x was given. -if test "${with_x+set}" = set; then - withval="$with_x" - -fi; -# $have_x is `yes', `no', `disabled', or empty when we do not yet know. -if test "x$with_x" = xno; then - # The user explicitly disabled X. - have_x=disabled -else - if test "x$x_includes" != xNONE && test "x$x_libraries" != xNONE; then - # Both variables are already set. - have_x=yes - else - if test "${ac_cv_have_x+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # One or both of the vars are not set, and there is no cached value. -ac_x_includes=no ac_x_libraries=no -rm -fr conftest.dir -if mkdir conftest.dir; then - cd conftest.dir - # Make sure to not put "make" in the Imakefile rules, since we grep it out. - cat >Imakefile <<'EOF' -acfindx: - @echo 'ac_im_incroot="${INCROOT}"; ac_im_usrlibdir="${USRLIBDIR}"; ac_im_libdir="${LIBDIR}"' -EOF - if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then - # GNU make sometimes prints "make[1]: Entering...", which would confuse us. - eval `${MAKE-make} acfindx 2>/dev/null | grep -v make` - # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR. - for ac_extension in a so sl; do - if test ! -f $ac_im_usrlibdir/libX11.$ac_extension && - test -f $ac_im_libdir/libX11.$ac_extension; then - ac_im_usrlibdir=$ac_im_libdir; break - fi - done - # Screen out bogus values from the imake configuration. They are - # bogus both because they are the default anyway, and because - # using them would break gcc on systems where it needs fixed includes. - case $ac_im_incroot in - /usr/include) ;; - *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;; - esac - case $ac_im_usrlibdir in - /usr/lib | /lib) ;; - *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;; - esac - fi - cd .. - rm -fr conftest.dir -fi - -# Standard set of common directories for X headers. -# Check X11 before X11Rn because it is often a symlink to the current release. -ac_x_header_dirs=' -/usr/X11/include -/usr/X11R6/include -/usr/X11R5/include -/usr/X11R4/include - -/usr/include/X11 -/usr/include/X11R6 -/usr/include/X11R5 -/usr/include/X11R4 - -/usr/local/X11/include -/usr/local/X11R6/include -/usr/local/X11R5/include -/usr/local/X11R4/include - -/usr/local/include/X11 -/usr/local/include/X11R6 -/usr/local/include/X11R5 -/usr/local/include/X11R4 - -/usr/X386/include -/usr/x386/include -/usr/XFree86/include/X11 - -/usr/include -/usr/local/include -/usr/unsupported/include -/usr/athena/include -/usr/local/x11r5/include -/usr/lpp/Xamples/include - -/usr/openwin/include -/usr/openwin/share/include' - -if test "$ac_x_includes" = no; then - # Guess where to find include files, by looking for Intrinsic.h. - # First, try using that file with no special directory specified. - cat >conftest.$ac_ext <<_ACEOF -#line 4494 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:4498: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:4504: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # We can compile using X headers with no special include directory. -ac_x_includes= -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - for ac_dir in $ac_x_header_dirs; do - if test -r "$ac_dir/X11/Intrinsic.h"; then - ac_x_includes=$ac_dir - break - fi -done -fi -rm -f conftest.err conftest.$ac_ext -fi # $ac_x_includes = no - -if test "$ac_x_libraries" = no; then - # Check for the libraries. - # See if we find them without any special options. - # Don't add to $LIBS permanently. - ac_save_LIBS=$LIBS - LIBS="-lXt $LIBS" - cat >conftest.$ac_ext <<_ACEOF -#line 4537 "configure" -#include "confdefs.h" -#include -int -main () -{ -XtMalloc (0) - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4549: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4552: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4555: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4558: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - LIBS=$ac_save_LIBS -# We can link X programs with no special library path. -ac_x_libraries= -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -LIBS=$ac_save_LIBS -for ac_dir in `echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g` -do - # Don't even attempt the hair of trying to link an X program! - for ac_extension in a so sl; do - if test -r $ac_dir/libXt.$ac_extension; then - ac_x_libraries=$ac_dir - break 2 - fi - done -done -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi # $ac_x_libraries = no - -if test "$ac_x_includes" = no || test "$ac_x_libraries" = no; then - # Didn't find X anywhere. Cache the known absence of X. - ac_cv_have_x="have_x=no" -else - # Record where we found X for the cache. - ac_cv_have_x="have_x=yes \ - ac_x_includes=$ac_x_includes ac_x_libraries=$ac_x_libraries" -fi -fi - - fi - eval "$ac_cv_have_x" -fi # $with_x != no - -if test "$have_x" != yes; then - echo "$as_me:4596: result: $have_x" >&5 -echo "${ECHO_T}$have_x" >&6 - no_x=yes -else - # If each of the values was on the command line, it overrides each guess. - test "x$x_includes" = xNONE && x_includes=$ac_x_includes - test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries - # Update the cache value to reflect the command line values. - ac_cv_have_x="have_x=yes \ - ac_x_includes=$x_includes ac_x_libraries=$x_libraries" - echo "$as_me:4606: result: libraries $x_libraries, headers $x_includes" >&5 -echo "${ECHO_T}libraries $x_libraries, headers $x_includes" >&6 -fi - -if test -z "$no_x" ; then - CPPFLAGS="$CPPFLAGS -I$x_includes" - LDFLAGS="$LDFLAGS -L$x_libraries" - echo "$as_me:4613: checking $x_libraries" >&5 -echo $ECHO_N "checking $x_libraries... $ECHO_C" >&6 -ac_exists=no -if test -d "$x_libraries/." ; then - ac_real_dir=`cd $x_libraries && pwd` - if test -n "$ac_real_dir" ; then - ac_exists=yes - for old in RPATH_CANDIDATE_REAL_DIRS ; do - ac_found=no - if test x$ac_real_dir = x$old ; then - ac_found=yes; - break; - fi - done - if test $ac_found = yes ; then - echo "$as_me:4628: result: already added" >&5 -echo "${ECHO_T}already added" >&6 - else - echo "$as_me:4631: result: added" >&5 -echo "${ECHO_T}added" >&6 - # LDFLAGS="$LDFLAGS -L $x_libraries" - RPATH_CANDIDATE_REAL_DIRS="$ac_real_dir $RPATH_CANDIDATE_REAL_DIRS" - RPATH_CANDIDATE_DIRS="$x_libraries $RPATH_CANDIDATE_DIRS" - fi - fi -fi -if test $ac_exists = no ; then - echo "$as_me:4640: result: not found" >&5 -echo "${ECHO_T}not found" >&6 -fi - -fi - -for ac_header in X11/Xauth.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:4649: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 4655 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:4659: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:4665: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:4684: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for XauGetAuthByAddr in -lXau... $ECHO_C" >&6 -if test "${ac_cv_lib_Xau_XauGetAuthByAddr+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lXau $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 4702 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char XauGetAuthByAddr (); -int -main () -{ -XauGetAuthByAddr (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4721: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4724: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4727: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4730: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_Xau_XauGetAuthByAddr=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_Xau_XauGetAuthByAddr=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:4741: result: $ac_cv_lib_Xau_XauGetAuthByAddr" >&5 -echo "${ECHO_T}$ac_cv_lib_Xau_XauGetAuthByAddr" >&6 -if test $ac_cv_lib_Xau_XauGetAuthByAddr = yes; then - cat >>confdefs.h <conftest.$ac_ext <<_ACEOF -#line 4758 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:4763: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4766: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:4768: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4771: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_success=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - - if test $ac_success = no ; then - echo "$as_me:4784: checking Running simple test program failed. Trying -R flags" >&5 -echo $ECHO_N "checking Running simple test program failed. Trying -R flags... $ECHO_C" >&6 - ac_remaining_dirs='' - ac_rpath_save_LDFLAGS="$LDFLAGS" - for d in $RPATH_CANDIDATE_DIRS ; do - if test $ac_success = yes ; then - ac_remaining_dirs="$ac_remaining_dirs $d" - else - LDFLAGS="$RPATHFLAG$d $LDFLAGS" - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 4797 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:4802: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4805: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:4807: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4810: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes - ac_rpath_save_LDFLAGS="$LDFLAGS" - echo "$as_me:4814: result: adding $RPATHFLAG$d" >&5 -echo "${ECHO_T}adding $RPATHFLAG$d" >&6 - -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_remaining_dirs="$ac_remaining_dirs $d" -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - LDFLAGS="$ac_rpath_save_LDFLAGS" - fi - done - RPATH_CANDIDATE_DIRS=$ac_remaining_dirs - fi - if test $ac_success = no ; then - echo "$as_me:4831: result: failed" >&5 -echo "${ECHO_T}failed" >&6 - fi -fi - -echo "$as_me:4836: checking for crypt in -lcrypt" >&5 -echo $ECHO_N "checking for crypt in -lcrypt... $ECHO_C" >&6 -if test "${ac_cv_lib_crypt_crypt+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lcrypt $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 4844 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char crypt (); -int -main () -{ -crypt (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4863: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4866: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4869: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4872: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_crypt_crypt=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_crypt_crypt=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:4883: result: $ac_cv_lib_crypt_crypt" >&5 -echo "${ECHO_T}$ac_cv_lib_crypt_crypt" >&6 -if test $ac_cv_lib_crypt_crypt = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for inet_addr in -lxnet... $ECHO_C" >&6 -if test "${ac_cv_lib_xnet_inet_addr+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lxnet $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 4902 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char inet_addr (); -int -main () -{ -inet_addr (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4921: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4924: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4927: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4930: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_xnet_inet_addr=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_xnet_inet_addr=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:4941: result: $ac_cv_lib_xnet_inet_addr" >&5 -echo "${ECHO_T}$ac_cv_lib_xnet_inet_addr" >&6 -if test $ac_cv_lib_xnet_inet_addr = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for gethostbyname in -lnsl... $ECHO_C" >&6 -if test "${ac_cv_lib_nsl_gethostbyname+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lnsl $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 4960 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char gethostbyname (); -int -main () -{ -gethostbyname (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:4979: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:4982: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:4985: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:4988: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_nsl_gethostbyname=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_nsl_gethostbyname=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:4999: result: $ac_cv_lib_nsl_gethostbyname" >&5 -echo "${ECHO_T}$ac_cv_lib_nsl_gethostbyname" >&6 -if test $ac_cv_lib_nsl_gethostbyname = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for setsockopt in -lsocket... $ECHO_C" >&6 -if test "${ac_cv_lib_socket_setsockopt+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lsocket $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5018 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char setsockopt (); -int -main () -{ -setsockopt (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5037: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5040: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5043: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5046: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_socket_setsockopt=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_socket_setsockopt=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5057: result: $ac_cv_lib_socket_setsockopt" >&5 -echo "${ECHO_T}$ac_cv_lib_socket_setsockopt" >&6 -if test $ac_cv_lib_socket_setsockopt = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for openpty in -lutil... $ECHO_C" >&6 -if test "${ac_cv_lib_util_openpty+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lutil $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5078 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char openpty (); -int -main () -{ -openpty (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5097: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5100: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5103: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5106: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_util_openpty=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_util_openpty=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5117: result: $ac_cv_lib_util_openpty" >&5 -echo "${ECHO_T}$ac_cv_lib_util_openpty" >&6 -if test $ac_cv_lib_util_openpty = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for library containing syslog... $ECHO_C" >&6 -if test "${ac_cv_search_syslog+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_func_search_save_LIBS=$LIBS -ac_cv_search_syslog=no -cat >conftest.$ac_ext <<_ACEOF -#line 5137 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char syslog (); -int -main () -{ -syslog (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5156: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5159: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5162: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5165: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_search_syslog="none required" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -if test "$ac_cv_search_syslog" = no; then - for ac_lib in bsd socket inet; do - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - cat >conftest.$ac_ext <<_ACEOF -#line 5177 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char syslog (); -int -main () -{ -syslog (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5196: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5199: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5202: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5205: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_search_syslog="-l$ac_lib" -break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext - done -fi -LIBS=$ac_func_search_save_LIBS -fi -echo "$as_me:5218: result: $ac_cv_search_syslog" >&5 -echo "${ECHO_T}$ac_cv_search_syslog" >&6 -if test "$ac_cv_search_syslog" != no; then - test "$ac_cv_search_syslog" = "none required" || LIBS="$ac_cv_search_syslog $LIBS" - cat >>confdefs.h <<\EOF -#define HAVE_SYSLOG 1 -EOF - -fi - -# Should we use zlib? -if test x$with_zlib = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_ZLIB 1 -EOF - -fi - -# The kerberos libraries are needed only to support the -# krb-check-passwd program, so we put them $KRB_LIBS, not in the -# ordinary $LIBS. - -if test x$enable_kerberos = xyes; then - echo "$as_me:5241: checking for strlcpy in -lroken" >&5 -echo $ECHO_N "checking for strlcpy in -lroken... $ECHO_C" >&6 -if test "${ac_cv_lib_roken_strlcpy+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lroken $KRB_LIBS $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5249 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char strlcpy (); -int -main () -{ -strlcpy (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5268: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5271: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5274: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5277: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_roken_strlcpy=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_roken_strlcpy=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5288: result: $ac_cv_lib_roken_strlcpy" >&5 -echo "${ECHO_T}$ac_cv_lib_roken_strlcpy" >&6 -if test $ac_cv_lib_roken_strlcpy = yes; then - ac_tr_lib=HAVE_LIB`echo roken | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >>confdefs.h <&5 -echo $ECHO_N "checking for dn_expand in -lresolv... $ECHO_C" >&6 -if test "${ac_cv_lib_resolv_dn_expand+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lresolv $KRB_LIBS $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5309 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char dn_expand (); -int -main () -{ -dn_expand (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5328: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5331: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5334: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5337: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_resolv_dn_expand=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_resolv_dn_expand=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5348: result: $ac_cv_lib_resolv_dn_expand" >&5 -echo "${ECHO_T}$ac_cv_lib_resolv_dn_expand" >&6 -if test $ac_cv_lib_resolv_dn_expand = yes; then - ac_tr_lib=HAVE_LIB`echo resolv | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >>confdefs.h <&5 -echo $ECHO_N "checking for des_cbc_encrypt in -ldes... $ECHO_C" >&6 -if test "${ac_cv_lib_des_des_cbc_encrypt+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-ldes $KRB_LIBS $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5369 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char des_cbc_encrypt (); -int -main () -{ -des_cbc_encrypt (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5388: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5391: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5394: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5397: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_des_des_cbc_encrypt=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_des_des_cbc_encrypt=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5408: result: $ac_cv_lib_des_des_cbc_encrypt" >&5 -echo "${ECHO_T}$ac_cv_lib_des_des_cbc_encrypt" >&6 -if test $ac_cv_lib_des_des_cbc_encrypt = yes; then - ac_tr_lib=HAVE_LIB`echo des | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >>confdefs.h <&5 -echo $ECHO_N "checking for der_get_octet_string in -lasn1... $ECHO_C" >&6 -if test "${ac_cv_lib_asn1_der_get_octet_string+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lasn1 $KRB_LIBS $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5429 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char der_get_octet_string (); -int -main () -{ -der_get_octet_string (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5448: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5451: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5454: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5457: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_asn1_der_get_octet_string=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_asn1_der_get_octet_string=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5468: result: $ac_cv_lib_asn1_der_get_octet_string" >&5 -echo "${ECHO_T}$ac_cv_lib_asn1_der_get_octet_string" >&6 -if test $ac_cv_lib_asn1_der_get_octet_string = yes; then - ac_tr_lib=HAVE_LIB`echo asn1 | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >>confdefs.h <&5 -echo $ECHO_N "checking for krb5_cc_gen_new in -lkrb5... $ECHO_C" >&6 -if test "${ac_cv_lib_krb5_krb5_cc_gen_new+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lkrb5 $KRB_LIBS $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line 5489 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char krb5_cc_gen_new (); -int -main () -{ -krb5_cc_gen_new (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:5508: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:5511: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:5514: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5517: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_krb5_krb5_cc_gen_new=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_krb5_krb5_cc_gen_new=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:5528: result: $ac_cv_lib_krb5_krb5_cc_gen_new" >&5 -echo "${ECHO_T}$ac_cv_lib_krb5_krb5_cc_gen_new" >&6 -if test $ac_cv_lib_krb5_krb5_cc_gen_new = yes; then - ac_tr_lib=HAVE_LIB`echo krb5 | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >>confdefs.h <>confdefs.h <<\EOF -#define WITH_KERBEROS 1 -EOF - - KRB_PROGRAM=lsh-krb-checkpw -fi - -if test "x$enable_gcov" = "xyes"; then - CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs" - cat >>confdefs.h <<\EOF -#define WITH_GCOV 1 -EOF - -fi - -# Checks for typedefs, structures, and compiler characteristics. -echo "$as_me:5563: checking for $CC option to accept ANSI C" >&5 -echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_prog_cc_stdc=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -#line 5571 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (eval echo "$as_me:5620: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:5623: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:5626: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5629: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_stdc=$ac_arg -break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext -done -rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC - -fi - -case "x$ac_cv_prog_cc_stdc" in - x|xno) - echo "$as_me:5646: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 ;; - *) - echo "$as_me:5649: result: $ac_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 - CC="$CC $ac_cv_prog_cc_stdc" ;; -esac - -echo "$as_me:5654: checking for an ANSI C-conforming const" >&5 -echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6 -if test "${ac_cv_c_const+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 5660 "configure" -#include "confdefs.h" - -int -main () -{ -/* FIXME: Include the comments suggested by Paul. */ -#ifndef __cplusplus - /* Ultrix mips cc rejects this. */ - typedef int charset[2]; - const charset x; - /* SunOS 4.1.1 cc rejects this. */ - char const *const *ccp; - char **p; - /* NEC SVR4.0.2 mips cc rejects this. */ - struct point {int x, y;}; - static struct point const zero = {0,0}; - /* AIX XL C 1.02.0.0 rejects this. - It does not let you subtract one const X* pointer from another in - an arm of an if-expression whose if-part is not a constant - expression */ - const char *g = "string"; - ccp = &g + (g ? g-g : 0); - /* HPUX 7.0 cc rejects these. */ - ++ccp; - p = (char**) ccp; - ccp = (char const *const *) p; - { /* SCO 3.2v4 cc rejects this. */ - char *t; - char const *s = 0 ? (char *) 0 : (char const *) 0; - - *t++ = 0; - } - { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ - int x[] = {25, 17}; - const int *foo = &x[0]; - ++foo; - } - { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ - typedef const int *iptr; - iptr p = 0; - ++p; - } - { /* AIX XL C 1.02.0.0 rejects this saying - "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; }; - struct s *b; b->j = 5; - } - { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ - const int foo = 10; - } -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:5718: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:5721: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:5724: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5727: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_const=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_const=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:5737: result: $ac_cv_c_const" >&5 -echo "${ECHO_T}$ac_cv_c_const" >&6 -if test $ac_cv_c_const = no; then - -cat >>confdefs.h <<\EOF -#define const -EOF - -fi - -echo "$as_me:5747: checking for inline" >&5 -echo $ECHO_N "checking for inline... $ECHO_C" >&6 -if test "${ac_cv_c_inline+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_inline=no -for ac_kw in inline __inline__ __inline; do - cat >conftest.$ac_ext <<_ACEOF -#line 5755 "configure" -#include "confdefs.h" -#ifndef __cplusplus -static $ac_kw int static_foo () {return 0; } -$ac_kw int foo () {return 0; } -#endif - -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:5764: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:5767: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:5770: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5773: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_inline=$ac_kw; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done - -fi -echo "$as_me:5784: result: $ac_cv_c_inline" >&5 -echo "${ECHO_T}$ac_cv_c_inline" >&6 -case $ac_cv_c_inline in - inline | yes) ;; - no) -cat >>confdefs.h <<\EOF -#define inline -EOF - ;; - *) cat >>confdefs.h <&5 -echo $ECHO_N "checking for uid_t in sys/types.h... $ECHO_C" >&6 -if test "${ac_cv_type_uid_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 5805 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "uid_t" >/dev/null 2>&1; then - ac_cv_type_uid_t=yes -else - ac_cv_type_uid_t=no -fi -rm -f conftest* - -fi -echo "$as_me:5819: result: $ac_cv_type_uid_t" >&5 -echo "${ECHO_T}$ac_cv_type_uid_t" >&6 -if test $ac_cv_type_uid_t = no; then - -cat >>confdefs.h <<\EOF -#define uid_t int -EOF - -cat >>confdefs.h <<\EOF -#define gid_t int -EOF - -fi - -for ac_header in stdlib.h string.h memory.h strings.h inttypes.h unistd.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:5836: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 5842 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:5846: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:5852: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:5871: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for size_t... $ECHO_C" >&6 -if test "${ac_cv_type_size_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 5887 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((size_t *) 0) - return 0; -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:5902: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:5905: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:5908: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5911: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_size_t=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_size_t=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:5921: result: $ac_cv_type_size_t" >&5 -echo "${ECHO_T}$ac_cv_type_size_t" >&6 -if test $ac_cv_type_size_t = yes; then - : -else - -cat >>confdefs.h <&5 -echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6 -if test "${ac_cv_header_time+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 5939 "configure" -#include "confdefs.h" -#include -#include -#include - -int -main () -{ -struct tm *tp; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:5954: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:5957: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:5960: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:5963: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_time=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_time=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:5973: result: $ac_cv_header_time" >&5 -echo "${ECHO_T}$ac_cv_header_time" >&6 -if test $ac_cv_header_time = yes; then - -cat >>confdefs.h <<\EOF -#define TIME_WITH_SYS_TIME 1 -EOF - -fi - -# Needed by the supplied memcmp.c -echo "$as_me:5984: checking whether byte ordering is bigendian" >&5 -echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6 -if test "${ac_cv_c_bigendian+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_bigendian=unknown -# See if sys/param.h defines the BYTE_ORDER macro. -cat >conftest.$ac_ext <<_ACEOF -#line 5992 "configure" -#include "confdefs.h" -#include -#include - -int -main () -{ -#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN - bogus endian macros -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6009: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6012: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6015: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6018: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - # It does; now see whether it defined to BIG_ENDIAN or not. -cat >conftest.$ac_ext <<_ACEOF -#line 6022 "configure" -#include "confdefs.h" -#include -#include - -int -main () -{ -#if BYTE_ORDER != BIG_ENDIAN - not big endian -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6039: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6042: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6045: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6048: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_bigendian=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -if test $ac_cv_c_bigendian = unknown; then -if test "$cross_compiling" = yes; then - { { echo "$as_me:6064: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 6069 "configure" -#include "confdefs.h" -int -main () -{ - /* Are we little or big endian? From Harbison&Steele. */ - union - { - long l; - char c[sizeof (long)]; - } u; - u.l = 1; - exit (u.c[sizeof (long) - 1] == 1); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:6085: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:6088: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:6090: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6093: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=no -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_bigendian=yes -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -fi -echo "$as_me:6106: result: $ac_cv_c_bigendian" >&5 -echo "${ECHO_T}$ac_cv_c_bigendian" >&6 -if test $ac_cv_c_bigendian = yes; then - -cat >>confdefs.h <<\EOF -#define WORDS_BIGENDIAN 1 -EOF - -fi - -echo "$as_me:6116: checking for short" >&5 -echo $ECHO_N "checking for short... $ECHO_C" >&6 -if test "${ac_cv_type_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6122 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((short *) 0) - return 0; -if (sizeof (short)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6137: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6140: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6143: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6146: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_short=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_short=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:6156: result: $ac_cv_type_short" >&5 -echo "${ECHO_T}$ac_cv_type_short" >&6 - -echo "$as_me:6159: checking size of short" >&5 -echo $ECHO_N "checking size of short... $ECHO_C" >&6 -if test "${ac_cv_sizeof_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_short" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 6168 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6180: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6183: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6186: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6189: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 6194 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6206: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6209: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6212: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6215: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 6231 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6243: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6246: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6249: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6252: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 6268 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6280: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6283: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6286: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6289: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_short=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:6302: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 6307 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (short))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:6323: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:6326: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:6328: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6331: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_short=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_short=0 -fi -fi -echo "$as_me:6347: result: $ac_cv_sizeof_short" >&5 -echo "${ECHO_T}$ac_cv_sizeof_short" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for int... $ECHO_C" >&6 -if test "${ac_cv_type_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6359 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((int *) 0) - return 0; -if (sizeof (int)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6374: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6377: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6380: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6383: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_int=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_int=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:6393: result: $ac_cv_type_int" >&5 -echo "${ECHO_T}$ac_cv_type_int" >&6 - -echo "$as_me:6396: checking size of int" >&5 -echo $ECHO_N "checking size of int... $ECHO_C" >&6 -if test "${ac_cv_sizeof_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_int" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 6405 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6417: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6420: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6423: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6426: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 6431 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6443: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6446: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6449: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6452: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 6468 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6480: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6483: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6486: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6489: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 6505 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6517: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6520: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6523: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6526: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_int=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:6539: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 6544 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (int))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:6560: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:6563: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:6565: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6568: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_int=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_int=0 -fi -fi -echo "$as_me:6584: result: $ac_cv_sizeof_int" >&5 -echo "${ECHO_T}$ac_cv_sizeof_int" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for long... $ECHO_C" >&6 -if test "${ac_cv_type_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6596 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((long *) 0) - return 0; -if (sizeof (long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6611: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6614: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6617: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6620: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_long=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:6630: result: $ac_cv_type_long" >&5 -echo "${ECHO_T}$ac_cv_type_long" >&6 - -echo "$as_me:6633: checking size of long" >&5 -echo $ECHO_N "checking size of long... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 6642 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6654: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6657: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6660: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6663: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 6668 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6680: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6683: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6686: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6689: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 6705 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6717: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6720: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6723: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6726: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 6742 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:6754: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:6757: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:6760: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6763: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_long=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:6776: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 6781 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (long))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:6797: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:6800: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:6802: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6805: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long=0 -fi -fi -echo "$as_me:6821: result: $ac_cv_sizeof_long" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for working alloca.h... $ECHO_C" >&6 -if test "${ac_cv_working_alloca_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6839 "configure" -#include "confdefs.h" -#include -int -main () -{ -char *p = (char *) alloca (2 * sizeof (int)); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:6851: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:6854: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:6857: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6860: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_working_alloca_h=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_working_alloca_h=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:6870: result: $ac_cv_working_alloca_h" >&5 -echo "${ECHO_T}$ac_cv_working_alloca_h" >&6 -if test $ac_cv_working_alloca_h = yes; then - -cat >>confdefs.h <<\EOF -#define HAVE_ALLOCA_H 1 -EOF - -fi - -echo "$as_me:6880: checking for alloca" >&5 -echo $ECHO_N "checking for alloca... $ECHO_C" >&6 -if test "${ac_cv_func_alloca_works+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6886 "configure" -#include "confdefs.h" -#ifdef __GNUC__ -# define alloca __builtin_alloca -#else -# ifdef _MSC_VER -# include -# define alloca _alloca -# else -# if HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -# endif -# endif -# endif -# endif -#endif - -int -main () -{ -char *p = (char *) alloca (1); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:6918: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:6921: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:6924: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:6927: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_alloca_works=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_func_alloca_works=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:6937: result: $ac_cv_func_alloca_works" >&5 -echo "${ECHO_T}$ac_cv_func_alloca_works" >&6 - -if test $ac_cv_func_alloca_works = yes; then - -cat >>confdefs.h <<\EOF -#define HAVE_ALLOCA 1 -EOF - -else - # The SVR3 libPW and SVR4 libucb both contain incompatible functions -# that cause trouble. Some versions do not even contain alloca or -# contain a buggy version. If you still want to use their alloca, -# use ar to extract alloca.o from them instead of compiling alloca.c. - -ALLOCA=alloca.$ac_objext - -cat >>confdefs.h <<\EOF -#define C_ALLOCA 1 -EOF - -echo "$as_me:6958: checking whether \`alloca.c' needs Cray hooks" >&5 -echo $ECHO_N "checking whether \`alloca.c' needs Cray hooks... $ECHO_C" >&6 -if test "${ac_cv_os_cray+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6964 "configure" -#include "confdefs.h" -#if defined(CRAY) && ! defined(CRAY2) -webecray -#else -wenotbecray -#endif - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "webecray" >/dev/null 2>&1; then - ac_cv_os_cray=yes -else - ac_cv_os_cray=no -fi -rm -f conftest* - -fi -echo "$as_me:6982: result: $ac_cv_os_cray" >&5 -echo "${ECHO_T}$ac_cv_os_cray" >&6 -if test $ac_cv_os_cray = yes; then - for ac_func in _getb67 GETB67 getb67; do - ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:6987: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 6993 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7024: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7027: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7030: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7033: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7043: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking stack direction for C alloca... $ECHO_C" >&6 -if test "${ac_cv_c_stack_direction+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_c_stack_direction=0 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7066 "configure" -#include "confdefs.h" -int -find_stack_direction () -{ - static char *addr = 0; - auto char dummy; - if (addr == 0) - { - addr = &dummy; - return find_stack_direction (); - } - else - return (&dummy > addr) ? 1 : -1; -} - -int -main () -{ - exit (find_stack_direction () < 0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:7089: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7092: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:7094: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7097: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_stack_direction=1 -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_stack_direction=-1 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:7109: result: $ac_cv_c_stack_direction" >&5 -echo "${ECHO_T}$ac_cv_c_stack_direction" >&6 - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for working memcmp... $ECHO_C" >&6 -if test "${ac_cv_func_memcmp_working+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_func_memcmp_working=no -else - cat >conftest.$ac_ext <<_ACEOF -#line 7127 "configure" -#include "confdefs.h" - -int -main () -{ - - /* Some versions of memcmp are not 8-bit clean. */ - char c0 = 0x40, c1 = 0x80, c2 = 0x81; - if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0) - exit (1); - - /* The Next x86 OpenStep bug shows up only when comparing 16 bytes - or more and with at least one buffer not starting on a 4-byte boundary. - William Lewis provided this test program. */ - { - char foo[21]; - char bar[21]; - int i; - for (i = 0; i < 4; i++) - { - char *a = foo + i; - char *b = bar + i; - strcpy (a, "--------01111111"); - strcpy (b, "--------10000000"); - if (memcmp (a, b, 16) >= 0) - exit (1); - } - exit (0); - } - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:7163: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7166: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:7168: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7171: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_memcmp_working=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_func_memcmp_working=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:7183: result: $ac_cv_func_memcmp_working" >&5 -echo "${ECHO_T}$ac_cv_func_memcmp_working" >&6 -test $ac_cv_func_memcmp_working = no && LIBOBJS="$LIBOBJS memcmp.$ac_objext" - -for ac_func in vprintf -do -ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:7190: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7196 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7227: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7230: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7233: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7236: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7246: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for _doprnt... $ECHO_C" >&6 -if test "${ac_cv_func__doprnt+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7259 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char _doprnt (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char _doprnt (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub__doprnt) || defined (__stub____doprnt) -choke me -#else -f = _doprnt; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7290: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7293: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7296: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7299: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func__doprnt=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_func__doprnt=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7309: result: $ac_cv_func__doprnt" >&5 -echo "${ECHO_T}$ac_cv_func__doprnt" >&6 -if test $ac_cv_func__doprnt = yes; then - -cat >>confdefs.h <<\EOF -#define HAVE_DOPRNT 1 -EOF - -fi - -fi -done - -for ac_func in select socket strerror strsignal strtol -do -ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:7325: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7331 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7362: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7365: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7368: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7371: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7381: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7400 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7431: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7434: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7437: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7440: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7450: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7469 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7500: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7503: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7506: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7509: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7519: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7538 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7569: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7572: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7575: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7578: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7588: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7607 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7638: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7641: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7644: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7647: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7657: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7676 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7707: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7710: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7713: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7716: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7726: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7745 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7776: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7779: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7782: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7785: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7795: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7814 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:7845: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7848: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:7851: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7854: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:7864: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking whether getpgrp takes no argument... $ECHO_C" >&6 -if test "${ac_cv_func_getpgrp_void+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:7880: error: cannot check getpgrp if cross compiling" >&5 -echo "$as_me: error: cannot check getpgrp if cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 7885 "configure" -#include "confdefs.h" - -/* - * If this system has a BSD-style getpgrp(), - * which takes a pid argument, exit unsuccessfully. - * - * Snarfed from Chet Ramey's bash pgrp.c test program - */ -#include -#include - -int pid; -int pg1, pg2, pg3, pg4; -int ng, np, s, child; - -int -main () -{ - pid = getpid (); - pg1 = getpgrp (0); - pg2 = getpgrp (); - pg3 = getpgrp (pid); - pg4 = getpgrp (1); - - /* If all of these values are the same, it's pretty sure that we're - on a system that ignores getpgrp's first argument. */ - if (pg2 == pg4 && pg1 == pg3 && pg2 == pg3) - exit (0); - - child = fork (); - if (child < 0) - exit(1); - else if (child == 0) - { - np = getpid (); - /* If this is Sys V, this will not work; pgrp will be set to np - because setpgrp just changes a pgrp to be the same as the - pid. */ - setpgrp (np, pg1); - ng = getpgrp (0); /* Same result for Sys V and BSD */ - if (ng == pg1) - exit (1); - else - exit (0); - } - else - { - wait (&s); - exit (s>>8); - } -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:7939: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:7942: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:7944: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:7947: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_getpgrp_void=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_func_getpgrp_void=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - -fi -echo "$as_me:7960: result: $ac_cv_func_getpgrp_void" >&5 -echo "${ECHO_T}$ac_cv_func_getpgrp_void" >&6 -if test $ac_cv_func_getpgrp_void = yes; then - -cat >>confdefs.h <<\EOF -#define GETPGRP_VOID 1 -EOF - -fi - -for ac_func in syslog -do -ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:7973: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 7979 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:8010: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8013: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:8016: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8019: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:8029: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 8048 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:8079: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8082: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:8085: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8088: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:8098: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking if netdb.h defines AI_NUMERICHOST... $ECHO_C" >&6 -if test "${lsh_cv_sys_ai_numerichost+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 8117 "configure" -#include "confdefs.h" -#include - #ifdef AI_NUMERICHOST - yes - #endif - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "yes" >/dev/null 2>&1; then - lsh_cv_sys_ai_numerichost=yes -else - lsh_cv_sys_ai_numerichost=no -fi -rm -f conftest* - -fi -echo "$as_me:8134: result: $lsh_cv_sys_ai_numerichost" >&5 -echo "${ECHO_T}$lsh_cv_sys_ai_numerichost" >&6 - -if test x$lsh_cv_sys_ai_numerichost = xyes ; then - cat >>confdefs.h <<\EOF -#define HAVE_AI_NUMERICHOST 1 -EOF - -fi - -for ac_func in poll -do -ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:8147: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 8153 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:8184: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8187: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:8190: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8193: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:8203: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for library containing argp_parse... $ECHO_C" >&6 -if test "${ac_cv_search_argp_parse+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_func_search_save_LIBS=$LIBS -ac_cv_search_argp_parse=no -cat >conftest.$ac_ext <<_ACEOF -#line 8229 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char argp_parse (); -int -main () -{ -argp_parse (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:8248: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8251: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:8254: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8257: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_search_argp_parse="none required" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -if test "$ac_cv_search_argp_parse" = no; then - for ac_lib in argp; do - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - cat >conftest.$ac_ext <<_ACEOF -#line 8269 "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char argp_parse (); -int -main () -{ -argp_parse (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:8288: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8291: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:8294: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8297: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_search_argp_parse="-l$ac_lib" -break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext - done -fi -LIBS=$ac_func_search_save_LIBS -fi -echo "$as_me:8310: result: $ac_cv_search_argp_parse" >&5 -echo "${ECHO_T}$ac_cv_search_argp_parse" >&6 -if test "$ac_cv_search_argp_parse" != no; then - test "$ac_cv_search_argp_parse" = "none required" || LIBS="$ac_cv_search_argp_parse $LIBS" - if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then - ac_success=no - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 8320 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:8325: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8328: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:8330: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8333: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_success=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - - if test $ac_success = no ; then - echo "$as_me:8346: checking Running simple test program failed. Trying -R flags" >&5 -echo $ECHO_N "checking Running simple test program failed. Trying -R flags... $ECHO_C" >&6 - ac_remaining_dirs='' - ac_rpath_save_LDFLAGS="$LDFLAGS" - for d in $RPATH_CANDIDATE_DIRS ; do - if test $ac_success = yes ; then - ac_remaining_dirs="$ac_remaining_dirs $d" - else - LDFLAGS="$RPATHFLAG$d $LDFLAGS" - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 8359 "configure" -#include "confdefs.h" -int main(int argc, char **argv) { return 0; } -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:8364: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8367: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:8369: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8372: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_success=yes - ac_rpath_save_LDFLAGS="$LDFLAGS" - echo "$as_me:8376: result: adding $RPATHFLAG$d" >&5 -echo "${ECHO_T}adding $RPATHFLAG$d" >&6 - -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_remaining_dirs="$ac_remaining_dirs $d" -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi - LDFLAGS="$ac_rpath_save_LDFLAGS" - fi - done - RPATH_CANDIDATE_DIRS=$ac_remaining_dirs - fi - if test $ac_success = no ; then - echo "$as_me:8393: result: failed" >&5 -echo "${ECHO_T}failed" >&6 - fi -fi - - echo "$as_me:8398: checking for working argp" >&5 -echo $ECHO_N "checking for working argp... $ECHO_C" >&6 -if test "${lsh_cv_lib_argp_works+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - lsh_cv_lib_argp_works=no -else - cat >conftest.$ac_ext <<_ACEOF -#line 8407 "configure" -#include "confdefs.h" -#include -#include - -static const struct argp_option -options[] = -{ - { NULL, 0, NULL, 0, NULL, 0 } -}; - -struct child_state -{ - int n; -}; - -static error_t -child_parser(int key, char *arg, struct argp_state *state) -{ - struct child_state *input = (struct child_state *) state->input; - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_END: - if (!input->n) - input->n = 1; - break; - } - return 0; -} - -const struct argp child_argp = -{ - options, - child_parser, - NULL, NULL, NULL, NULL, NULL -}; - -struct main_state -{ - struct child_state child; - int m; -}; - -static error_t -main_parser(int key, char *arg, struct argp_state *state) -{ - struct main_state *input = (struct main_state *) state->input; - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &input->child; - break; - case ARGP_KEY_END: - if (!input->m) - input->m = input->child.n; - - break; - } - return 0; -} - -static const struct argp_child -main_children[] = -{ - { &child_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static const struct argp -main_argp = -{ options, main_parser, - NULL, - NULL, - main_children, - NULL, NULL -}; - -int main(int argc, char **argv) -{ - struct main_state input = { { 0 }, 0 }; - char *v[2] = { "foo", NULL }; - - argp_parse(&main_argp, 1, v, 0, NULL, &input); - - if ( (input.m == 1) && (input.child.n == 1) ) - return 0; - else - return 1; -} - -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:8505: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8508: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:8510: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8513: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_lib_argp_works=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_lib_argp_works=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:8525: result: $lsh_cv_lib_argp_works" >&5 -echo "${ECHO_T}$lsh_cv_lib_argp_works" >&6 - - if test x$lsh_cv_lib_argp_works = xyes ; then - ac_argp_ok=yes - else - # Reset link flags - LIBS="$ac_argp_save_LIBS" - LDFLAGS="$ac_argp_save_LDFLAGS" - fi -fi - - if test x$ac_argp_ok = xyes ; then - true - else - with_system_argp=no - fi - -fi - -# We don't use LIBOBJS for this, as the LIBOBJS are added to -# liblsh.a, and we can't add an archive to an archive. -LIBARGP="" -if test x$with_system_argp = xno ; then - # FIXME: Perhaps it's better to use an absolute path? - LIBARGP="argp/libargp.a" -fi - -# Check for broken shutdown -echo "$as_me:8554: checking for working shutdown on AF_UNIX sockets" >&5 -echo $ECHO_N "checking for working shutdown on AF_UNIX sockets... $ECHO_C" >&6 -if test "${lsh_cv_func_shutdown_works_on_unix_sockets+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - -if test "$cross_compiling" = yes; then - lsh_cv_func_shutdown_works_on_unix_sockets=yes -else - cat >conftest.$ac_ext <<_ACEOF -#line 8564 "configure" -#include "confdefs.h" - -#include - -#include - -#include -#include - -#include - -#ifdef HAVE_UNISTD_H -#include -#endif - -/* Creates a one-way socket connection. Returns 1 on success, 0 on - * failure. fds[0] is for reading, fds[1] for writing (like for the - * pipe() system call). */ -static int make_pipe(int *fds) -{ - -#ifndef SHUT_RD -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 -#endif - - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) - { - fprintf(stderr, "socketpair() failed: %s\n", strerror(errno)); - return 0; - } - fprintf(stderr, "Created socket pair. Using fd:s %d <-- %d\n", fds[0], fds[1]); - - if(shutdown(fds[0], SHUT_WR) < 0) - { - fprintf(stderr, "shutdown(%d, SHUT_WR) failed: %s\n", - fds[0], strerror(errno)); - return 0; - } - if (shutdown(fds[1], SHUT_RD) < 0) - { - fprintf(stderr, "shutdown(%d, SHUT_RD) failed: %s\n", - fds[1], strerror(errno)); - return 0; - } - - return 1; -} - -int main(int argc, char **argv) -{ - int fds[2]; - - if (!make_pipe(fds)) - exit(1); - - if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) - { - fprintf(stderr, "signal failed.\n"); - exit(1); - } - - if ( (write(fds[1], "foo", 3) < 0) - && (errno == EPIPE)) - exit(1); - - exit(0); -} - -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:8637: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8640: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:8642: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8645: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_func_shutdown_works_on_unix_sockets=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_func_shutdown_works_on_unix_sockets=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:8657: result: $lsh_cv_func_shutdown_works_on_unix_sockets" >&5 -echo "${ECHO_T}$lsh_cv_func_shutdown_works_on_unix_sockets" >&6 - -if test x$lsh_cv_func_shutdown_works_on_unix_sockets = xyes ; then - cat >>confdefs.h <<\EOF -#define SHUTDOWN_WORKS_WITH_UNIX_SOCKETS 1 -EOF - -fi - -echo "$as_me:8667: checking for working UNIX98 ptys" >&5 -echo $ECHO_N "checking for working UNIX98 ptys... $ECHO_C" >&6 -if test "${lsh_cv_sys_unix98_ptys+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - # Pessimistic default for cross compilation. - lsh_cv_sys_unix98_ptys=no -else - cat >conftest.$ac_ext <<_ACEOF -#line 8677 "configure" -#include "confdefs.h" - - /* Try to obtain a working UNIX98-style pty master and slave */ - /* Based on example code from the GNU C library documentation */ - #include /* EXIT_FAILURE, EXIT_SUCCESS, ptsname */ - #include /* close(2) */ - - #include /* open(2) */ - #include /* - " - */ - #ifdef HAVE_FCNTL_H - # include /* - " - */ - #endif - #ifdef HAVE_STROPTS_H - # include /* isastream() */ - #endif - - int main(int argc, char* argv) { - int master, slave; - char *name; - - master = open("/dev/ptmx", O_RDWR); /* PTY master multiplex */ - if (master < 0) { - exit(EXIT_FAILURE); - } - - if (grantpt(master) < 0 || unlockpt(master) < 0) - goto close_master; - name = ptsname(master); - if (name == NULL) - goto close_master; - - slave = open(name, O_RDWR); - if (slave == -1) - goto close_master; - - #ifdef HAVE_STROPTS_H - if (isastream(slave)) - { - if (ioctl(slave, I_PUSH, "ptem") < 0 - || ioctl(slave, I_PUSH, "ldterm") < 0) - goto close_slave; - } - #endif - - exit(0); - - close_slave: - close (slave); - - close_master: - close (master); - exit(1); - } - -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:8734: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8737: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:8739: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8742: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_sys_unix98_ptys=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_sys_unix98_ptys=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:8754: result: $lsh_cv_sys_unix98_ptys" >&5 -echo "${ECHO_T}$lsh_cv_sys_unix98_ptys" >&6 - -if test x$lsh_cv_sys_unix98_ptys = xyes; then - cat >>confdefs.h <<\EOF -#define HAVE_UNIX98_PTYS 1 -EOF - -fi - -# Check for gcc's __attribute__ construction -echo "$as_me:8765: checking for __attribute__" >&5 -echo $ECHO_N "checking for __attribute__... $ECHO_C" >&6 -if test "${lsh_cv_c_attribute+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 8771 "configure" -#include "confdefs.h" - -#include - -int -main () -{ - -static void foo(void) __attribute__ ((noreturn)); - -static void __attribute__ ((noreturn)) -foo(void) -{ - exit(1); -} - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:8793: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:8796: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:8799: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8802: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_c_attribute=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_c_attribute=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:8812: result: $lsh_cv_c_attribute" >&5 -echo "${ECHO_T}$lsh_cv_c_attribute" >&6 - -if test "x$lsh_cv_c_attribute" = "xyes"; then - cat >>confdefs.h <<\EOF -#define HAVE_GCC_ATTRIBUTE 1 -EOF - -fi - -# Check for gcc's __FUNCTION__ variable -echo "$as_me:8823: checking for __FUNCTION__" >&5 -echo $ECHO_N "checking for __FUNCTION__... $ECHO_C" >&6 -if test "${lsh_cv_c_FUNCTION+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 8829 "configure" -#include "confdefs.h" - -int -main () -{ - void foo(void) { char c = __FUNCTION__[0]; } - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:8841: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:8844: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:8847: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8850: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_c_FUNCTION=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_c_FUNCTION=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:8860: result: $lsh_cv_c_FUNCTION" >&5 -echo "${ECHO_T}$lsh_cv_c_FUNCTION" >&6 - -if test "x$lsh_cv_c_FUNCTION" = "xyes"; then - cat >>confdefs.h <<\EOF -#define HAVE_GCC_FUNCTION 1 -EOF - -fi - -echo "$as_me:8870: checking for BSD pty names" >&5 -echo $ECHO_N "checking for BSD pty names... $ECHO_C" >&6 - -# FIXME: What is most portable, tr -d '\n' or tr -d '\012' ? -cat >>confdefs.h <>confdefs.h <>confdefs.h <<\EOF -#define PTY_BSD_SCHEME 1 -EOF - -echo "$as_me:8888: result: done" >&5 -echo "${ECHO_T}done" >&6 - -# IPv6 support - -if test x$enable_ipv6 = xyes ; then - echo "$as_me:8894: checking if IPv6 is supported" >&5 -echo $ECHO_N "checking if IPv6 is supported... $ECHO_C" >&6 -if test "${lsh_cv_sys_ipv6+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - lsh_cv_sys_ipv6=no -else - cat >conftest.$ac_ext <<_ACEOF -#line 8903 "configure" -#include "confdefs.h" -/* AF_INET6 avalable check */ - #include - #include - int main(int argc, char **argv) - { - if (socket(AF_INET6, SOCK_STREAM, 0) < 0) - exit(1); - else - exit(0); - } - -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:8918: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:8921: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:8923: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:8926: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_sys_ipv6=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_sys_ipv6=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:8938: result: $lsh_cv_sys_ipv6" >&5 -echo "${ECHO_T}$lsh_cv_sys_ipv6" >&6 - - if test x$lsh_cv_sys_ipv6 != xyes ; then - enable_ipv6=no - elif test x$ac_cv_func_getaddrinfo != xyes ; then - { echo "$as_me:8944: WARNING: getaddrinfo not found. Disabling IPv6 support" >&5 -echo "$as_me: WARNING: getaddrinfo not found. Disabling IPv6 support" >&2;} - enable_ipv6=no - elif test x$ac_cv_func_gai_strerror != xyes ; then - { echo "$as_me:8948: WARNING: gai_strerror not found. Disabling IPv6 support" >&5 -echo "$as_me: WARNING: gai_strerror not found. Disabling IPv6 support" >&2;} - enable_ipv6=no - elif test x$lsh_cv_sys_ai_numerichost != xyes ; then - { echo "$as_me:8952: WARNING: AI_NUMERICHOST not defined. Disabling IPv6 support" >&5 -echo "$as_me: WARNING: AI_NUMERICHOST not defined. Disabling IPv6 support" >&2;} - enable_ipv6=no - fi -fi - -if test x$enable_ipv6 = xyes ; then - cat >>confdefs.h <<\EOF -#define WITH_IPV6 1 -EOF - -fi - -subdirs="$subdirs src/argp" - -subdirs="$subdirs src/nettle" - -subdirs="$subdirs src/sftp" - -# Set these flags *last*, or else the test programs won't compile -if test x$GCC = xyes ; then - CFLAGS="$CFLAGS -ggdb3 -Wall -W \ - -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \ - -Waggregate-return \ - -Wpointer-arith -Wbad-function-cast -Wnested-externs" - -# Don't enable -Wcast-align as it results in tons of warnings in the -# DES code. And when using stdio. - -fi - -ac_config_files="$ac_config_files Makefile doc/Makefile misc/Makefile src/Makefile src/scm/Makefile src/testsuite/Makefile src/rsync/Makefile src/nettle/Makefile contrib/Makefile contrib/lsh.spec" - -cat >confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overriden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -{ - (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} | - sed ' - t clear - : clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - : end' >>confcache -if cmp -s $cache_file confcache; then :; else - if test -w $cache_file; then - test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" - cat confcache >$cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/; -s/:*\${srcdir}:*/:/; -s/:*@srcdir@:*/:/; -s/^\([^=]*=[ ]*\):*/\1/; -s/:*$//; -s/^[^=]*=[ ]*$//; -}' -fi - -DEFS=-DHAVE_CONFIG_H - -: ${CONFIG_STATUS=./config.status} -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ echo "$as_me:9064: creating $CONFIG_STATUS" >&5 -echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF -#! $SHELL -# Generated automatically by configure. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -SHELL=\${CONFIG_SHELL-$SHELL} -ac_cs_invocation="\$0 \$@" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -exec 6>&1 - -_ACEOF - -# Files that config.status was made for. -if test -n "$ac_config_files"; then - echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_headers"; then - echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_links"; then - echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_commands"; then - echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS -fi - -cat >>$CONFIG_STATUS <<\EOF - -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTIONS] [FILE]... - - -h, --help print this help, then exit - -V, --version print version number, then exit - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to ." -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -# If no file are specified by the user, then we need to provide default -# value. By we need to know if files were specified by the user. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "x$1" : 'x\([^=]*\)='` - ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` - shift - set dummy "$ac_option" "$ac_optarg" ${1+"$@"} - shift - ;; - -*);; - *) # This is not an option, so the user has probably given explicit - # arguments. - ac_need_defaults=false;; - esac - - case $1 in - # Handling of the options. -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF - --version | --vers* | -V ) - echo "$ac_cs_version"; exit 0 ;; - --he | --h) - # Conflict between --help and --header - { { echo "$as_me:9240: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - echo "$ac_cs_usage"; exit 0 ;; - --debug | --d* | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - shift - CONFIG_FILES="$CONFIG_FILES $1" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - shift - CONFIG_HEADERS="$CONFIG_HEADERS $1" - ac_need_defaults=false;; - - # Handling of arguments. - 'Makefile' ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; - 'doc/Makefile' ) CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; - 'misc/Makefile' ) CONFIG_FILES="$CONFIG_FILES misc/Makefile" ;; - 'src/Makefile' ) CONFIG_FILES="$CONFIG_FILES src/Makefile" ;; - 'src/scm/Makefile' ) CONFIG_FILES="$CONFIG_FILES src/scm/Makefile" ;; - 'src/testsuite/Makefile' ) CONFIG_FILES="$CONFIG_FILES src/testsuite/Makefile" ;; - 'src/rsync/Makefile' ) CONFIG_FILES="$CONFIG_FILES src/rsync/Makefile" ;; - 'src/nettle/Makefile' ) CONFIG_FILES="$CONFIG_FILES src/nettle/Makefile" ;; - 'contrib/Makefile' ) CONFIG_FILES="$CONFIG_FILES contrib/Makefile" ;; - 'contrib/lsh.spec' ) CONFIG_FILES="$CONFIG_FILES contrib/lsh.spec" ;; - 'default-1' ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; - 'config.h' ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - - # This is an error. - -*) { { echo "$as_me:9273: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; } ;; - *) { { echo "$as_me:9278: error: invalid argument: $1" >&5 -echo "$as_me: error: invalid argument: $1" >&2;} - { (exit 1); exit 1; }; };; - esac - shift -done - -exec 5>>config.log -cat >&5 << _ACEOF - -## ----------------------- ## -## Running config.status. ## -## ----------------------- ## - -This file was extended by $as_me (lsh 1.3.1) 2.50, executed with - > $ac_cs_invocation -on `(hostname || uname -n) 2>/dev/null | sed 1q` - -_ACEOF -EOF - -cat >>$CONFIG_STATUS <<\EOF -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Create a temporary directory, and hook for its removal unless debugging. -$debug || -{ - trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 - trap '{ (exit $?); exit $?; }' 1 2 13 15 -} - -# Create a (secure) tmp directory for tmp files. -: ${TMPDIR=/tmp} -{ - tmp=`(umask 077 && mktemp -d -q "$TMPDIR/csXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=$TMPDIR/cs$$-$RANDOM - (umask 077 && mkdir $tmp) -} || -{ - echo "$me: cannot create a temporary directory in $TMPDIR" >&2 - { (exit 1); exit 1; } -} - -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <\$tmp/subs.sed <<\\CEOF -s,@SHELL@,$SHELL,;t t -s,@exec_prefix@,$exec_prefix,;t t -s,@prefix@,$prefix,;t t -s,@program_transform_name@,$program_transform_name,;t t -s,@bindir@,$bindir,;t t -s,@sbindir@,$sbindir,;t t -s,@libexecdir@,$libexecdir,;t t -s,@datadir@,$datadir,;t t -s,@sysconfdir@,$sysconfdir,;t t -s,@sharedstatedir@,$sharedstatedir,;t t -s,@localstatedir@,$localstatedir,;t t -s,@libdir@,$libdir,;t t -s,@includedir@,$includedir,;t t -s,@oldincludedir@,$oldincludedir,;t t -s,@infodir@,$infodir,;t t -s,@mandir@,$mandir,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t -s,@ECHO_C@,$ECHO_C,;t t -s,@ECHO_N@,$ECHO_N,;t t -s,@ECHO_T@,$ECHO_T,;t t -s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t -s,@DEFS@,$DEFS,;t t -s,@LIBS@,$LIBS,;t t -s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t -s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t -s,@INSTALL_DATA@,$INSTALL_DATA,;t t -s,@PACKAGE@,$PACKAGE,;t t -s,@VERSION@,$VERSION,;t t -s,@ACLOCAL@,$ACLOCAL,;t t -s,@AUTOCONF@,$AUTOCONF,;t t -s,@AUTOMAKE@,$AUTOMAKE,;t t -s,@AUTOHEADER@,$AUTOHEADER,;t t -s,@MAKEINFO@,$MAKEINFO,;t t -s,@SET_MAKE@,$SET_MAKE,;t t -s,@SRP_PROGRAM@,$SRP_PROGRAM,;t t -s,@CC@,$CC,;t t -s,@CFLAGS@,$CFLAGS,;t t -s,@LDFLAGS@,$LDFLAGS,;t t -s,@CPPFLAGS@,$CPPFLAGS,;t t -s,@ac_ct_CC@,$ac_ct_CC,;t t -s,@EXEEXT@,$EXEEXT,;t t -s,@OBJEXT@,$OBJEXT,;t t -s,@RANLIB@,$RANLIB,;t t -s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t -s,@SCHEME_PROGRAM@,$SCHEME_PROGRAM,;t t -s,@SCHEME_NAME@,$SCHEME_NAME,;t t -s,@BASH@,$BASH,;t t -s,@GROFF@,$GROFF,;t t -s,@M4@,$M4,;t t -s,@CPP@,$CPP,;t t -s,@KRB_LIBS@,$KRB_LIBS,;t t -s,@KRB_PROGRAM@,$KRB_PROGRAM,;t t -s,@ALLOCA@,$ALLOCA,;t t -s,@LIBOBJS@,$LIBOBJS,;t t -s,@LIBARGP@,$LIBARGP,;t t -s,@subdirs@,$subdirs,;t t -CEOF - -EOF - - cat >>$CONFIG_STATUS <<\EOF - # Split the substitutions into bite-sized pieces for seds with - # small command number limits, like on Digital OSF/1 and HP-UX. - ac_max_sed_lines=48 - ac_sed_frag=1 # Number of current file. - ac_beg=1 # First line for current file. - ac_end=$ac_max_sed_lines # Line after last line for current file. - ac_more_lines=: - ac_sed_cmds= - while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - else - sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - fi - if test ! -s $tmp/subs.frag; then - ac_more_lines=false - else - # The purpose of the label and of the branching condition is to - # speed up the sed processing (if there are no `@' at all, there - # is no need to browse any of the substitutions). - # These are the two extra sed commands mentioned above. - (echo ':t - /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" - else - ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" - fi - ac_sed_frag=`expr $ac_sed_frag + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_lines` - fi - done - if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat - fi -fi # test -n "$CONFIG_FILES" - -EOF -cat >>$CONFIG_STATUS <<\EOF -for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - ac_dir_suffix="/`echo $ac_dir|sed 's,^\./,,'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo "$ac_dir_suffix" | sed 's,/[^/]*,../,g'` - else - ac_dir_suffix= ac_dots= - fi - - case $srcdir in - .) ac_srcdir=. - if test -z "$ac_dots"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_dots | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_dots$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_dots$srcdir ;; - esac - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_dots$INSTALL ;; - esac - - if test x"$ac_file" != x-; then - { echo "$as_me:9527: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - configure_input="Generated automatically from `echo $ac_file_in | - sed 's,.*/,,'` by configure." - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:9545: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:9558: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s,@configure_input@,$configure_input,;t t -s,@srcdir@,$ac_srcdir,;t t -s,@top_srcdir@,$ac_top_srcdir,;t t -s,@INSTALL@,$ac_INSTALL,;t t -" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out - rm -f $tmp/stdin - if test x"$ac_file" != x-; then - mv $tmp/out $ac_file - else - cat $tmp/out - rm -f $tmp/out - fi - -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_HEADER section. -# - -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' -ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t' - -for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - test x"$ac_file" != x- && { echo "$as_me:9619: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:9630: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:9643: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } - # Remove the trailing spaces. - sed 's/[ ]*$//' $ac_file_inputs >$tmp/in - -EOF - -# Transform confdefs.h into two sed scripts, `conftest.defines' and -# `conftest.undefs', that substitutes the proper values into -# config.h.in to produce config.h. The first handles `#define' -# templates, and the second `#undef' templates. -# And first: Protect against being on the right side of a sed subst in -# config.status. Protect against being in an unquoted here document -# in config.status. -rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. -# Putting comments in sed scripts is not portable. -# -# `end' is used to avoid that the second main sed command (meant for -# 0-ary CPP macros) applies to n-ary macro definitions. -# See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\EOF -s/[\\&,]/\\&/g -s,[\\$`],\\&,g -t clear -: clear -s,^[ ]*#[ ]*define[ ][ ]*\(\([^ (][^ (]*\)([^)]*)\)[ ]*\(.*\)$,${ac_dA}\2${ac_dB}\1${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end -EOF -# If some macros were called several times there might be several times -# the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. -uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs -rm -f confdef2sed.sed - -# This sed command replaces #undef with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\EOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -EOF - -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if egrep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.defines >/dev/null -do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/defines.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail - rm -f conftest.defines - mv conftest.tail conftest.defines -done -rm -f conftest.defines -echo ' fi # egrep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/undefs.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs - -cat >>$CONFIG_STATUS <<\EOF - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - if test x"$ac_file" = x-; then - echo "/* Generated automatically by configure. */" >$tmp/config.h - else - echo "/* $ac_file. Generated automatically by configure. */" >$tmp/config.h - fi - cat $tmp/in >>$tmp/config.h - rm -f $tmp/in - if test x"$ac_file" != x-; then - if cmp -s $ac_file $tmp/config.h 2>/dev/null; then - { echo "$as_me:9760: $ac_file is unchanged" >&5 -echo "$as_me: $ac_file is unchanged" >&6;} - else - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - fi - rm -f $ac_file - mv $tmp/config.h $ac_file - fi - else - cat $tmp/config.h - rm -f $tmp/config.h - fi -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_COMMANDS section. -# -for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue - ac_dest=`echo "$ac_file" | sed 's,:.*,,'` - ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'` - - case $ac_dest in - default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;; - esac -done -EOF - -cat >>$CONFIG_STATUS <<\EOF - -{ (exit 0); exit 0; } -EOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - exec 5>/dev/null - $SHELL $CONFIG_STATUS || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi - -# -# CONFIG_SUBDIRS section. -# -if test "$no_recursion" != yes; then - - # Remove --cache-file and --srcdir arguments so they do not pile up. - ac_sub_configure_args= - ac_prev= - for ac_arg in $ac_configure_args; do - if test -n "$ac_prev"; then - ac_prev= - continue - fi - case $ac_arg in - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \ - | --c=*) - ;; - --config-cache | -C) - ;; - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - ;; - *) ac_sub_configure_args="$ac_sub_configure_args $ac_arg" ;; - esac - done - - for ac_subdir in : $subdirs; do test "x$ac_subdir" = x: && continue - - # Do not complain, so a configure script can configure whichever - # parts of a large source tree are present. - test -d $srcdir/$ac_subdir || continue - - { echo "$as_me:9878: configuring in $ac_subdir" >&5 -echo "$as_me: configuring in $ac_subdir" >&6;} - case $srcdir in - .) ;; - *) { case "./$ac_subdir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="./$ac_subdir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - if test -d ./$ac_subdir; then :; - else - { { echo "$as_me:9900: error: cannot create \`pwd\`/$ac_subdir" >&5 -echo "$as_me: error: cannot create \`pwd\`/$ac_subdir" >&2;} - { (exit 1); exit 1; }; } - fi - ;; - esac - - ac_popdir=`pwd` - cd $ac_subdir - - # A "../" for each directory in /$ac_subdir. - ac_dots=`echo $ac_subdir | - sed 's,^\./,,;s,[^/]$,&/,;s,[^/]*/,../,g'` - - case $srcdir in - .) # No --srcdir option. We are building in place. - ac_sub_srcdir=$srcdir ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_sub_srcdir=$srcdir/$ac_subdir ;; - *) # Relative path. - ac_sub_srcdir=$ac_dots$srcdir/$ac_subdir ;; - esac - - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_sub_srcdir/configure.gnu; then - ac_sub_configure="$SHELL '$ac_sub_srcdir/configure.gnu'" - elif test -f $ac_sub_srcdir/configure; then - ac_sub_configure="$SHELL '$ac_sub_srcdir/configure'" - elif test -f $ac_sub_srcdir/configure.in; then - ac_sub_configure=$ac_configure - else - { echo "$as_me:9931: WARNING: no configuration information is in $ac_subdir" >&5 -echo "$as_me: WARNING: no configuration information is in $ac_subdir" >&2;} - ac_sub_configure= - fi - - # The recursion is here. - if test -n "$ac_sub_configure"; then - # Make the cache file name correct relative to the subdirectory. - case $cache_file in - [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;; - *) # Relative path. - ac_sub_cache_file=$ac_dots$cache_file ;; - esac - - { echo "$as_me:9945: running $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_sub_srcdir" >&5 -echo "$as_me: running $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_sub_srcdir" >&6;} - # The eval makes quoting arguments work. - eval $ac_sub_configure $ac_sub_configure_args \ - --cache-file=$ac_sub_cache_file --srcdir=$ac_sub_srcdir || - { { echo "$as_me:9950: error: $ac_sub_configure failed for $ac_subdir" >&5 -echo "$as_me: error: $ac_sub_configure failed for $ac_subdir" >&2;} - { (exit 1); exit 1; }; } - fi - - cd $ac_popdir - done -fi - diff --git a/lsh/configure.in b/lsh/configure.in deleted file mode 100755 index 4fd8985..0000000 --- a/lsh/configure.in +++ /dev/null @@ -1,714 +0,0 @@ -dnl -*- mode: shell-script; sh-indentation: 2; -*- -dnl $Id$ - -dnl Process this file with autoconf to produce a configure script. -AC_INIT([lsh], [1.3.1], [bug-lsh@gnu.org]) - -AC_PREREQ(2.50) - -AC_CONFIG_SRCDIR([src/lsh_types.h]) - -AM_INIT_AUTOMAKE(lsh, 1.3.4) - -AM_CONFIG_HEADER(config.h) -# AC_CONFIG_HEADERS(config.h) - -AH_TEMPLATE([PACKAGE], [The name of this software distribution]) -AH_TEMPLATE([VERSION], [The version of this software distribution]) - -# FIXME: Move this to the Makefile, as recommended by the autoconf manual. - -AH_TEMPLATE([PREFIX], [The installation prefix]) -AC_DEFINE_UNQUOTED(PREFIX, "`echo $prefix | sed "s@^NONE@$ac_default_prefix@"`") - -AH_TEMPLATE([SBINDIR], [sbin directory]) -# NOTE: The definition below is broken. -AC_DEFINE_UNQUOTED(SBINDIR, "`echo $sbindir | sed "s@^NONE@$prefix/sbin@" | sed "s@^NONE@$ac_default_prefix@"`") - -# We want an absolute path to the source-dir. -case "$srcdir" in - /*) - ;; - *) - oldsrcdir="$srcdir" - srcdir="`cd \"$srcdir\";pwd`" - AC_MSG_WARN([ Converted $oldsrcdir to $srcdir, -If this does not work, please use an absolute path to the configure script. ]) - ;; -esac - -# echo Replacing CPPFLAGS: $CPPFLAGS -# FIXME: Should be obsoleted by the nettle library -# We want to compile the crypto lib for use with lsh -# CPPFLAGS="$CPPFLAGS -I$srcdir -I$srcdir/src -I$srcdir/src/symmetric/include -DLSH" - -# src/rsync relies on lsh's definitions of WRITE_UINT32 etc. -CPPFLAGS="-I$srcdir/src -DLSH" - -# GNU libc defaults to supplying the ISO C library functions only. -# initgroups() and strsignal() are extensions; the _GNU_SOURCE define -# enables these extensions. -# Enable it on all systems; no problems have been reported with it so far. - -# We can't use AH_VERBATIM for this, as we want _GNU_SOURCE to be defined -# when running configure's test programs. -CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" - -# Check options -AC_ARG_ENABLE(debug_alloc, - AC_HELP_STRING([--enable-debug-alloc], [Enable memory allocation sanity checks]),, - [enable_debug_alloc=no]) - -AH_TEMPLATE([DEBUG_ALLOC], - [Define to enable sanity checking on memory allocation and casting]) -if test x$enable_debug_alloc = xyes ; then - AC_DEFINE(DEBUG_ALLOC) -fi - -AC_ARG_ENABLE(debug_trace, - AC_HELP_STRING([--enable-debug-trace], [Enable tracing support]),, - [enable_debug_trace=no]) - -AH_TEMPLATE([DEBUG_TRACE], [Define to enable tracing]) -if test x$enable_debug_trace = xyes ; then - AC_DEFINE(DEBUG_TRACE) -fi - -AC_ARG_ENABLE(gcov, - AC_HELP_STRING([--enable-gcov], [Instrument for gcov (requires a modern gcc)]),, - [enable_gcov=no]) - -AC_ARG_WITH(zlib, - AC_HELP_STRING([--without-zlib], [Don't use zlib compression]),, - [with_zlib=yes]) - -# Checking this variable is delayed until we have checked if zlib is -# actually available. - -AC_ARG_ENABLE(pty, - AC_HELP_STRING([--without-pty], [Disable pty support]),, - [enable_pty=yes]) - -AH_TEMPLATE([WITH_PTY_SUPPORT], [Define to enable pty support]) -if test x$enable_pty = xyes ; then - AC_DEFINE(WITH_PTY_SUPPORT) -fi - -AC_ARG_WITH(sshd1, - AC_HELP_STRING([[--with-sshd1[=PROGRAM]]], [support fallback to SSH1 daemon]),, - [with_sshd1=yes]) - -# Default sshd1 path -if test x$with_sshd1 = xyes ; then - with_sshd1=/usr/local/sbin/sshd1 -fi - -AH_TEMPLATE([SSHD1], [Location of the SSH1 daemon]) -AH_TEMPLATE([WITH_SSH1_FALLBACK], [Define to enable fallback to SSH1]) -if test x$with_sshd1 != xno ; then - AC_DEFINE(WITH_SSH1_FALLBACK) - AC_DEFINE_UNQUOTED(SSHD1,"$with_sshd1") -fi - -AC_ARG_ENABLE(srp, - AC_HELP_STRING([--disable-srp], [Disable the (experimental) support for SRP]),, - [enable_srp=yes]) - -AC_ARG_ENABLE(kerberos, - AC_HELP_STRING([--disable-kerberos], [Don't support kerberos]),, - [enable_kerberos=yes]) - -AH_TEMPLATE([WITH_SRP], [Define if SRP should be supported]) -if test x$enable_srp = xyes ; then - AC_DEFINE(WITH_SRP) - SRP_PROGRAM=srp-gen -fi - -AC_SUBST(SRP_PROGRAM) - -AC_ARG_ENABLE(datafellows_workarounds, - AC_HELP_STRING([--disable-datafellows-workarounds], - [Disable bug-compatibility with SSH Inc's clients and servers]),, - [enable_datafellows_workarounds=yes]) - -AH_TEMPLATE([DATAFELLOWS_WORKAROUNDS], - [Define to support non-standard packets of ssh2]) -if test x$enable_datafellows_workarounds = xyes ; then - AC_DEFINE(DATAFELLOWS_WORKAROUNDS) -fi - -AC_ARG_ENABLE(tcp_forward, - AC_HELP_STRING([--disable-tcp-forward], [Disable tcp forwarding]),, - [enable_tcp_forward=yes]) - -AH_TEMPLATE([WITH_TCP_FORWARD], [Define to enable tcp forwarding]) -if test x$enable_tcp_forward = xyes ; then - AC_DEFINE(WITH_TCP_FORWARD) -fi - -AC_ARG_ENABLE(x11_forward, - AC_HELP_STRING([--disable-x11-forward], [Disable x11 forwarding (proxy only)]),, - [eanble_x11_forward=yes]) - -AH_TEMPLATE([WITH_X11_FORWARD], [Define to enable x11 forwarding]) -if test x$enable_x11_forward = xyes ; then - AC_DEFINE(WITH_X11_FORWARD) -fi - -AC_ARG_ENABLE(agent_forward, - AC_HELP_STRING([--disable-agent-forward], [Disable auth-agent forwarding (proxy only)]),, - [with_agent_forward=yes]) - -AH_TEMPLATE([WITH_AGENT_FORWARD], - [Define to enable authentication agent forwarding]) -if test x$disable_agent_forward = xyes ; then - AC_DEFINE(WITH_AGENT_FORWARD) -fi - -AC_ARG_WITH(scheme, - AC_HELP_STRING([[--with-scheme[=PROGRAM]]], [Use a particular scheme implementation]),, - [with_scheme=]) - -AC_ARG_WITH(system-argp, - AC_HELP_STRING([--without-system-argp], [Don't use the system's argp]),, - [with_system_argp=yes]) - -# IPv6 support -AC_ARG_ENABLE(ipv6, - AC_HELP_STRING([--disable-ipv6], [Disable IPv6 support]),, - [enable_ipv6=yes]) - -# utmp/wtmp logging -AC_ARG_ENABLE(utmp, - AC_HELP_STRING([--disable-utmp], [Disable utmp and wtmp support]),, - [enable_utmp=yes]) - -AH_TEMPLATE([WITH_UTMP], [For utmp support]) -if test x$enable_utmp = xyes ; then - AC_DEFINE(WITH_UTMP) -fi - -AC_ARG_WITH(include-path, - AC_HELP_STRING([--with-include-path], [A colon-separated list of directories to search for include files]),, - [with_include_path='']) - -if test x$with_include_path != x ; then - CPPFLAGS="$CPPFLAGS -I `echo $with_include_path | sed 's/:/ -I /g'`" -fi - -AC_ARG_WITH(lib-path, - AC_HELP_STRING([--with-lib-path], [A colon-separated list of directories to search for libraries]),, - [with_lib_path='']) - -if test x$with_lib_path != x ; then - LDFLAGS="-L `echo $with_lib_path | sed 's/:/ -L /g'`" -fi - -LSH_RPATH_INIT([`echo $with_lib_path | sed 's/:/ /g'` \ - `echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed "s@^NONE@$ac_default_prefix/lib@g"` \ - /usr/local/lib /sw/local/lib /sw/lib \ - /usr/gnu/lib /opt/gnu/lib /sw/gnu/lib /usr/freeware/lib /usr/pkg/lib]) - -dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS - -# Checks for programs. -AC_PROG_CC -AC_PROG_MAKE_SET -AC_PROG_RANLIB -AM_PROG_CC_STDC - -if test "x$am_cv_prog_cc_stdc" = xno ; then - AC_MSG_ERROR([the C compiler doesn't handle ANSI-C]) -fi - -# Use a particular scheme implementation? -if test x$with_scheme != x ; then - AC_PATH_PROG(SCHEME_PROGRAM, $with_scheme,, $PATH) -else - AC_PATH_PROGS(SCHEME_PROGRAM, guile scsh,, $PATH) -fi - -if test x$SCHEME_PROGRAM = x ; then - AC_MSG_WARN([No scheme implementation found. -This is fine as long as you don't modify the source files.]) - SCHEME_PROGRAM=false -fi - -SCHEME_NAME=`basename $SCHEME_PROGRAM` -AC_SUBST(SCHEME_NAME) - -AC_PATH_PROG(BASH, bash,, $PATH) -AC_PATH_PROG(GROFF, groff,, $PATH) -AC_PATH_PROG(M4, m4, m4) - -AC_CACHE_CHECK([if m4 can handle eight-bit quote characters], - lsh_cv_prog_m4_quote_8bit, - [ if test xfoo = x`echo 'change''quote(»,«)»foo«' | $M4`; then - lsh_cv_prog_m4_quote_8bit=yes - else - lsh_cv_prog_m4_quote_8bit=no - fi]) - -if test x$lsh_cv_prog_m4_quote_8bit = xno; then - AC_MSG_WARN( -[To get the testsuite to work properly, you may need to -upgrade to a better version than GNU m4 1.4, or recompile -it with CFLAGS=-funsigned-char. -Latest version is available at ]) - M4="false --" -fi - -# Checks for header files. -AC_HEADER_STDC - -# Some debian systems have both gmp and gmp2. -# This will probably not work right if both gmp.h and gmp2/gmp.h exists, -# and gmp.h is too old (i.e GMP-1.x). -gmp_header_found=no -AC_CHECK_HEADERS(gmp.h gmp2/gmp.h, [gmp_header_found=yes; break]) -if test "$gmp_header_found" = no; then - AC_MSG_ERROR([Neither gmp.h nor gmp2/gmp.h found]) -fi - -AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h) -AC_CHECK_HEADERS(shadow.h) - -if test x$with_zlib = xyes; then - AC_CHECK_HEADERS(zlib.h,, [with_zlib=no]) -fi -AC_CHECK_HEADERS(poll.h sys/poll.h) -AC_CHECK_HEADERS(libutil.h) -AC_CHECK_HEADERS(crypt.h) -AC_CHECK_HEADERS(pty.h) -AC_CHECK_HEADERS(stropts.h) -AC_CHECK_HEADERS(syslog.h) -AC_CHECK_HEADERS(argp.h) - -AC_CHECK_HEADERS(utmp.h, [have_utmp_h=yes], [have_utmp_h=no]) - -if test x$have_utmp_h = xyes; then - AC_CHECK_MEMBERS([struct utmp.ut_host, - struct utmp.ut_name, - struct utmp.ut_user, - struct utmp.ut_addr, - struct utmp.ut_addr_v6],,, -[# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif -]) -fi - -AC_CHECK_HEADERS(utmpx.h) - -if test x$enable_kerberos = xyes; then - AC_CHECK_HEADERS(krb5.h,, [enable_kerberos=no]) -fi - -# Some systems (in particular, Unixware) doesn't have socklen_t, but -# uses size_t. Falling back to int will cause some warnings. - -# AC_CHECK_TYPE doesn't work, probably because the type in -# question is not defined in sys/types.h. - -AC_TYPE_SOCKLEN_T - -AC_SEARCH_LIBGMP(gmp gmp2, - [LSH_RPATH_FIX], - [AC_MSG_ERROR([GMP is missing. Get gmp-2.0.2 or better from ftp://ftp.gnu.org/pub/gnu/gmp]) ]) - -if test x$with_zlib = xyes; then - AC_CHECK_LIB(z, inflate,, [with_zlib=no]) -fi - -if test x$with_zlib = xyes; then - LSH_RPATH_FIX -fi - -# X11 stuff. We only need libXau. -AC_PATH_X - -if test -z "$no_x" ; then - CPPFLAGS="$CPPFLAGS -I$x_includes" - LDFLAGS="$LDFLAGS -L$x_libraries" - LSH_RPATH_ADD($x_libraries) -fi - -AC_CHECK_HEADERS(X11/Xauth.h) -AC_CHECK_LIB(Xau, XauGetAuthByAddr) -LSH_RPATH_FIX - -AC_CHECK_LIB(crypt, crypt) -AC_CHECK_LIB(xnet, inet_addr) -AC_CHECK_LIB(nsl, gethostbyname) -AC_CHECK_LIB(socket, setsockopt) -# logwtmp is also in libutil -AC_CHECK_LIB(util, openpty) - -# This macro is new in autoconf-2.13 -AC_SEARCH_LIBS(syslog, bsd socket inet, [AC_DEFINE(HAVE_SYSLOG)]) - -AH_TEMPLATE([WITH_ZLIB], [Define if zlib should be used]) -# Should we use zlib? -if test x$with_zlib = xyes ; then - AC_DEFINE(WITH_ZLIB) -fi - -# The kerberos libraries are needed only to support the -# krb-check-passwd program, so we put them $KRB_LIBS, not in the -# ordinary $LIBS. - -if test x$enable_kerberos = xyes; then - AC_CHECK_KRB_LIB(roken, strlcpy) - AC_CHECK_KRB_LIB(resolv, dn_expand) - AC_CHECK_KRB_LIB(des, des_cbc_encrypt) - AC_CHECK_KRB_LIB(asn1, der_get_octet_string) - AC_CHECK_KRB_LIB(krb5, krb5_cc_gen_new,, [enable_kerberos=no]) -fi - -AH_TEMPLATE([WITH_KERBEROS], [For kerberos]) -if test x$enable_kerberos = xyes; then - AC_DEFINE(WITH_KERBEROS) - KRB_PROGRAM=lsh-krb-checkpw -fi - -AC_SUBST(KRB_LIBS) -AC_SUBST(KRB_PROGRAM) - -AH_TEMPLATE([WITH_GCOV], [Use gcov]) -if test "x$enable_gcov" = "xyes"; then - CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs" - AC_DEFINE(WITH_GCOV) -fi - -# Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE -AC_TYPE_UID_T -AC_TYPE_SIZE_T -AC_HEADER_TIME - -# Needed by the supplied memcmp.c -AC_C_BIGENDIAN - -AC_CHECK_SIZEOF(short, 2) -AC_CHECK_SIZEOF(int, 4) -AC_CHECK_SIZEOF(long, 4) - -# FIXME: We should check that a pid_t fits in an int - -# Checks for library functions. - -AC_FUNC_ALLOCA -AC_FUNC_MEMCMP -AC_FUNC_VPRINTF -AC_CHECK_FUNCS(select socket strerror strsignal strtol) -AC_CHECK_FUNCS(getrusage gettimeofday) -AC_CHECK_FUNCS(getspnam) -AC_CHECK_FUNCS(vsnprintf inet_aton) -AC_CHECK_FUNCS(openpty) -AC_CHECK_FUNCS(cfmakeraw) -AC_CHECK_FUNCS(logwtmp login logout) -AC_CHECK_FUNCS(getaddrinfo getnameinfo gai_strerror) -AC_FUNC_GETPGRP -AC_CHECK_FUNCS(syslog) -AC_REPLACE_FUNCS(memxor) - -# FIXME: Is there a better way in autoconf 2.50? -AC_CACHE_CHECK([if netdb.h defines AI_NUMERICHOST], - lsh_cv_sys_ai_numerichost, - [AC_EGREP_CPP(yes, - [#include - #ifdef AI_NUMERICHOST - yes - #endif - ], lsh_cv_sys_ai_numerichost=yes, - lsh_cv_sys_ai_numerichost=no)]) - -AH_TEMPLATE([HAVE_AI_NUMERICHOST], [Define if AI_NUMERICHOST exists]) -if test x$lsh_cv_sys_ai_numerichost = xyes ; then - AC_DEFINE(HAVE_AI_NUMERICHOST) -fi - -AC_CHECK_FUNCS(poll,,[LIBOBJS="jpoll.o $LIBOBJS"]) - -# Test if the libc includes a good enough argp. -if test x$with_system_argp = xyes ; then - AC_LIB_ARGP(,with_system_argp=no) -fi - -# We don't use LIBOBJS for this, as the LIBOBJS are added to -# liblsh.a, and we can't add an archive to an archive. -LIBARGP="" -if test x$with_system_argp = xno ; then - # FIXME: Perhaps it's better to use an absolute path? - LIBARGP="argp/libargp.a" -fi - -AC_SUBST(LIBARGP) - -# Check for broken shutdown -AC_CACHE_CHECK(for working shutdown on AF_UNIX sockets, - lsh_cv_func_shutdown_works_on_unix_sockets, -[ -AC_TRY_RUN([ -#include - -#include - -#include -#include - -#include - -#ifdef HAVE_UNISTD_H -#include -#endif - -/* Creates a one-way socket connection. Returns 1 on success, 0 on - * failure. fds[0] is for reading, fds[1] for writing (like for the - * pipe() system call). */ -static int make_pipe(int *fds) -{ - -#ifndef SHUT_RD -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 -#endif - - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) - { - fprintf(stderr, "socketpair() failed: %s\n", strerror(errno)); - return 0; - } - fprintf(stderr, "Created socket pair. Using fd:s %d <-- %d\n", fds[0], fds[1]); - - if(shutdown(fds[0], SHUT_WR) < 0) - { - fprintf(stderr, "shutdown(%d, SHUT_WR) failed: %s\n", - fds[0], strerror(errno)); - return 0; - } - if (shutdown(fds[1], SHUT_RD) < 0) - { - fprintf(stderr, "shutdown(%d, SHUT_RD) failed: %s\n", - fds[1], strerror(errno)); - return 0; - } - - return 1; -} - -int main(int argc, char **argv) -{ - int fds[2]; - - if (!make_pipe(fds)) - exit(1); - - if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) - { - fprintf(stderr, "signal failed.\n"); - exit(1); - } - - if ( (write(fds[1], "foo", 3) < 0) - && (errno == EPIPE)) - exit(1); - - exit(0); -} -], lsh_cv_func_shutdown_works_on_unix_sockets=yes, - lsh_cv_func_shutdown_works_on_unix_sockets=no, - lsh_cv_func_shutdown_works_on_unix_sockets=yes)]) - -AH_TEMPLATE([SHUTDOWN_WORKS_WITH_UNIX_SOCKETS], - [Define to indicate that shutdown seems to work properly]) -if test x$lsh_cv_func_shutdown_works_on_unix_sockets = xyes ; then - AC_DEFINE(SHUTDOWN_WORKS_WITH_UNIX_SOCKETS) -fi - -AC_CACHE_CHECK( - [for working UNIX98 ptys], - lsh_cv_sys_unix98_ptys, - AC_TRY_RUN([ - /* Try to obtain a working UNIX98-style pty master and slave */ - /* Based on example code from the GNU C library documentation */ - #include /* EXIT_FAILURE, EXIT_SUCCESS, ptsname */ - #include /* close(2) */ - - #include /* open(2) */ - #include /* - " - */ - #ifdef HAVE_FCNTL_H - # include /* - " - */ - #endif - #ifdef HAVE_STROPTS_H - # include /* isastream() */ - #endif - - int main(int argc, char* argv[]) { - int master, slave; - char *name; - - master = open("/dev/ptmx", O_RDWR); /* PTY master multiplex */ - if (master < 0) { - exit(EXIT_FAILURE); - } - - if (grantpt(master) < 0 || unlockpt(master) < 0) - goto close_master; - name = ptsname(master); - if (name == NULL) - goto close_master; - - slave = open(name, O_RDWR); - if (slave == -1) - goto close_master; - - #ifdef HAVE_STROPTS_H - if (isastream(slave)) - { - if (ioctl(slave, I_PUSH, "ptem") < 0 - || ioctl(slave, I_PUSH, "ldterm") < 0) - goto close_slave; - } - #endif - - exit(0); - - close_slave: - close (slave); - - close_master: - close (master); - exit(1); - } - ], - [lsh_cv_sys_unix98_ptys=yes], - [lsh_cv_sys_unix98_ptys=no], - # Pessimistic default for cross compilation. - [lsh_cv_sys_unix98_ptys=no])) - -AH_TEMPLATE([HAVE_UNIX98_PTYS], - [Define if a we have working UNIX98 pty handling]) -if test x$lsh_cv_sys_unix98_ptys = xyes; then - AC_DEFINE(HAVE_UNIX98_PTYS) -fi - -# Check for gcc's __attribute__ construction -AC_CACHE_CHECK(for __attribute__, - lsh_cv_c_attribute, -[ AC_TRY_COMPILE([ -#include -], -[ -static void foo(void) __attribute__ ((noreturn)); - -static void __attribute__ ((noreturn)) -foo(void) -{ - exit(1); -} -], -lsh_cv_c_attribute=yes, -lsh_cv_c_attribute=no)]) - -AH_TEMPLATE([HAVE_GCC_ATTRIBUTE], [Define if the compiler understands __attribute__]) -if test "x$lsh_cv_c_attribute" = "xyes"; then - AC_DEFINE(HAVE_GCC_ATTRIBUTE) -fi - -# Check for gcc's __FUNCTION__ variable -AC_CACHE_CHECK(for __FUNCTION__, - lsh_cv_c_FUNCTION, - [ AC_TRY_COMPILE(, - [ void foo(void) { char c = __FUNCTION__[0]; } ], - lsh_cv_c_FUNCTION=yes, - lsh_cv_c_FUNCTION=no)]) - -AH_TEMPLATE([HAVE_GCC_FUNCTION], - [Define if the compiler understands __FUNCTION__]) -if test "x$lsh_cv_c_FUNCTION" = "xyes"; then - AC_DEFINE(HAVE_GCC_FUNCTION) -fi - -AC_MSG_CHECKING(for BSD pty names) - -AH_TEMPLATE([PTY_BSD_SCHEME_FIRST_CHARS], - [Possible first characters in a /dev/ptyXX name]) -AH_TEMPLATE([PTY_BSD_SCHEME_SECOND_CHARS], - [Possible second characters in a /dev/ptyXX name]) - -# FIXME: What is most portable, tr -d '\n' or tr -d '\012' ? -AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_FIRST_CHARS, "`ls /dev/pty* | cut -c 9-9 | uniq | tr -d '\n'`") -AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_SECOND_CHARS, "`ls /dev/pty* | cut -c 10-10 | sort | uniq | tr -d '\n'`") - -# FIXME: How can we test if the bsd scheme is likely to work? -AH_TEMPLATE([PTY_BSD_SCHEME], [Traditional BSD pty handling]) -AC_DEFINE(PTY_BSD_SCHEME) -AC_MSG_RESULT([done]) - -# IPv6 support - -if test x$enable_ipv6 = xyes ; then - AC_CACHE_CHECK([if IPv6 is supported], - lsh_cv_sys_ipv6, - [AC_TRY_RUN([/* AF_INET6 avalable check */ - #include - #include - int main(int argc, char **argv) - { - if (socket(AF_INET6, SOCK_STREAM, 0) < 0) - exit(1); - else - exit(0); - } - ], lsh_cv_sys_ipv6=yes, - lsh_cv_sys_ipv6=no, - lsh_cv_sys_ipv6=no)]) - - if test x$lsh_cv_sys_ipv6 != xyes ; then - enable_ipv6=no - elif test x$ac_cv_func_getaddrinfo != xyes ; then - AC_MSG_WARN([getaddrinfo not found. Disabling IPv6 support]) - enable_ipv6=no - elif test x$ac_cv_func_gai_strerror != xyes ; then - AC_MSG_WARN([gai_strerror not found. Disabling IPv6 support]) - enable_ipv6=no - elif test x$lsh_cv_sys_ai_numerichost != xyes ; then - AC_MSG_WARN([AI_NUMERICHOST not defined. Disabling IPv6 support]) - enable_ipv6=no - fi -fi - -AH_TEMPLATE([WITH_IPV6], [For Ipv6 support]) -if test x$enable_ipv6 = xyes ; then - AC_DEFINE(WITH_IPV6) -fi - -AC_CONFIG_SUBDIRS(src/argp) -AC_CONFIG_SUBDIRS(src/nettle) -AC_CONFIG_SUBDIRS(src/sftp) - -# Set these flags *last*, or else the test programs won't compile -if test x$GCC = xyes ; then - CFLAGS="$CFLAGS -ggdb3 -Wall -W \ - -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \ - -Waggregate-return \ - -Wpointer-arith -Wbad-function-cast -Wnested-externs" - -# Don't enable -Wcast-align as it results in tons of warnings in the -# DES code. And when using stdio. - -fi - -AC_CONFIG_FILES([Makefile doc/Makefile misc/Makefile - src/Makefile src/scm/Makefile - src/testsuite/Makefile src/rsync/Makefile - src/nettle/Makefile - contrib/Makefile contrib/lsh.spec]) -AC_OUTPUT diff --git a/lsh/contrib/Makefile.am b/lsh/contrib/Makefile.am deleted file mode 100755 index b214798..0000000 Binary files a/lsh/contrib/Makefile.am and /dev/null differ diff --git a/lsh/contrib/Makefile.in b/lsh/contrib/Makefile.in deleted file mode 100755 index 8043a28..0000000 --- a/lsh/contrib/Makefile.in +++ /dev/null @@ -1,179 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# Process this file with automake to create Makefile.in - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = .. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -EXTRA_DIST = README lsh.spec.in lsh.spec lshd.rhlinux.init lshd.debian.init -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../config.h -CONFIG_CLEAN_FILES = -DIST_COMMON = README Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -all: all-redirect -.SUFFIXES: -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps contrib/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -tags: TAGS -TAGS: - - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = contrib - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: tags distdir info-am info dvi-am dvi check check-am \ -installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/contrib/README b/lsh/contrib/README deleted file mode 100755 index efd8e0b..0000000 Binary files a/lsh/contrib/README and /dev/null differ diff --git a/lsh/contrib/lsh.spec b/lsh/contrib/lsh.spec deleted file mode 100755 index ccdd72a..0000000 Binary files a/lsh/contrib/lsh.spec and /dev/null differ diff --git a/lsh/contrib/lsh.spec.in b/lsh/contrib/lsh.spec.in deleted file mode 100755 index e76b525..0000000 Binary files a/lsh/contrib/lsh.spec.in and /dev/null differ diff --git a/lsh/contrib/lshd.debian.init b/lsh/contrib/lshd.debian.init deleted file mode 100755 index c4d3879..0000000 Binary files a/lsh/contrib/lshd.debian.init and /dev/null differ diff --git a/lsh/contrib/lshd.rhlinux.init b/lsh/contrib/lshd.rhlinux.init deleted file mode 100755 index 86c740f..0000000 Binary files a/lsh/contrib/lshd.rhlinux.init and /dev/null differ diff --git a/lsh/distribution-key.gpg b/lsh/distribution-key.gpg deleted file mode 100755 index 88266df..0000000 Binary files a/lsh/distribution-key.gpg and /dev/null differ diff --git a/lsh/doc/DSA.5 b/lsh/doc/DSA.5 deleted file mode 100755 index c436a40..0000000 Binary files a/lsh/doc/DSA.5 and /dev/null differ diff --git a/lsh/doc/HACKING b/lsh/doc/HACKING deleted file mode 100755 index f4ca548..0000000 Binary files a/lsh/doc/HACKING and /dev/null differ diff --git a/lsh/doc/Makefile.am b/lsh/doc/Makefile.am deleted file mode 100755 index d3d1385..0000000 --- a/lsh/doc/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -## Automatically generated by make_am, Wed Aug 29 23:52:14 CEST 2001 -## Process this file with automake to produce Makefile.in - - -Makefile.am: Makefile.am.in - (cd $(top_srcdir); ./make_am) - -# FIXME: Make this less GNU-make specific - -man_MANS=DSA.5 SHA.5 SPKI.5 secsh.5 \ - lsh.1 lsh_keygen.1 lsh_writekey.1 lshd.8 - -# MANPAGES = $(wildcard *.[1-9]) -info_TEXINFOS = lsh.texinfo - -EXTRA_DIST = HACKING NOTES PORTS TASKLIST \ - configuration.txt gateway-mode.txt \ - Makefile.am.in $(man_MANS) lsh.html \ - srp-spec.nroff srp-spec.txt fixff.sh fixff.pl - -# DVIS = $(addsuffix .dvi, $(man_MANS)) -# PSS = $(addsuffix .ps, $(man_MANS)) - -# all: dvi ps - -# dvi: $(DVIS) -# -# ps: $(PSS) - -all-local: srp-spec.txt lsh.html - -%.dvi: % - $(GROFF) -Tdvi -mandoc $< > $@ - -%.ps: % - $(GROFF) -Tps -mandoc $< > $@ - - -%.txt : %.nroff - $(GROFF) -ms -Tlatin1 $< | perl $(srcdir)/fixff.pl >$@T - test -s $@T && mv -f $@T $@ - -%.html : %.texinfo - (cd $(srcdir) \ - && $(MAKEINFO) --html --no-split --output $@T $(/dev/null 2>&1; then \ - list='$(INFO_DEPS)'; \ - for file in $$list; do \ - echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file";\ - install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file || :;\ - done; \ - else : ; fi - -uninstall-info: - $(PRE_UNINSTALL) - @if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \ - ii=yes; \ - else ii=; fi; \ - list='$(INFO_DEPS)'; \ - for file in $$list; do \ - test -z "$ii" \ - || install-info --info-dir=$(DESTDIR)$(infodir) --remove $$file; \ - done - @$(NORMAL_UNINSTALL) - list='$(INFO_DEPS)'; \ - for file in $$list; do \ - (cd $(DESTDIR)$(infodir) && rm -f $$file $$file-[0-9] $$file-[0-9][0-9]); \ - done - -dist-info: $(INFO_DEPS) - list='$(INFO_DEPS)'; \ - for base in $$list; do \ - d=$(srcdir); \ - for file in `cd $$d && eval echo $$base*`; do \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file; \ - done; \ - done - -mostlyclean-aminfo: - -rm -f lsh.aux lsh.cp lsh.cps lsh.dvi lsh.fn lsh.fns lsh.ky lsh.kys \ - lsh.ps lsh.log lsh.pg lsh.toc lsh.tp lsh.tps lsh.vr lsh.vrs \ - lsh.op lsh.tr lsh.cv lsh.cn - -clean-aminfo: - -distclean-aminfo: - -maintainer-clean-aminfo: - cd $(srcdir) && for i in $(INFO_DEPS); do \ - rm -f $$i; \ - if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then \ - rm -f $$i-[0-9]*; \ - fi; \ - done - -install-man1: - $(mkinstalldirs) $(DESTDIR)$(man1dir) - @list='$(man1_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.1*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ - else file=$$i; fi; \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst"; \ - $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst; \ - done - -uninstall-man1: - @list='$(man1_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.1*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " rm -f $(DESTDIR)$(man1dir)/$$inst"; \ - rm -f $(DESTDIR)$(man1dir)/$$inst; \ - done - -install-man5: - $(mkinstalldirs) $(DESTDIR)$(man5dir) - @list='$(man5_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.5*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ - else file=$$i; fi; \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man5dir)/$$inst"; \ - $(INSTALL_DATA) $$file $(DESTDIR)$(man5dir)/$$inst; \ - done - -uninstall-man5: - @list='$(man5_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.5*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " rm -f $(DESTDIR)$(man5dir)/$$inst"; \ - rm -f $(DESTDIR)$(man5dir)/$$inst; \ - done - -install-man8: - $(mkinstalldirs) $(DESTDIR)$(man8dir) - @list='$(man8_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.8*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ - else file=$$i; fi; \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man8dir)/$$inst"; \ - $(INSTALL_DATA) $$file $(DESTDIR)$(man8dir)/$$inst; \ - done - -uninstall-man8: - @list='$(man8_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.8*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " rm -f $(DESTDIR)$(man8dir)/$$inst"; \ - rm -f $(DESTDIR)$(man8dir)/$$inst; \ - done -install-man: $(MANS) - @$(NORMAL_INSTALL) - $(MAKE) $(AM_MAKEFLAGS) install-man1 install-man5 install-man8 -uninstall-man: - @$(NORMAL_UNINSTALL) - $(MAKE) $(AM_MAKEFLAGS) uninstall-man1 uninstall-man5 uninstall-man8 -tags: TAGS -TAGS: - - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = doc - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - $(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-info -info-am: $(INFO_DEPS) -info: info-am -dvi-am: $(DVIS) -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: install-info-am install-man -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: uninstall-info uninstall-man -uninstall: uninstall-am -all-am: Makefile $(INFO_DEPS) $(MANS) all-local -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - $(mkinstalldirs) $(DESTDIR)$(infodir) $(DESTDIR)$(mandir)/man1 \ - $(DESTDIR)$(mandir)/man5 $(DESTDIR)$(mandir)/man8 - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-aminfo mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-aminfo clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-aminfo distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-aminfo maintainer-clean-generic \ - distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: install-info-am uninstall-info mostlyclean-aminfo \ -distclean-aminfo clean-aminfo maintainer-clean-aminfo install-man1 \ -uninstall-man1 install-man5 uninstall-man5 install-man8 uninstall-man8 \ -install-man uninstall-man tags distdir info-am info dvi-am dvi check \ -check-am installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-local all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -Makefile.am: Makefile.am.in - (cd $(top_srcdir); ./make_am) - -# DVIS = $(addsuffix .dvi, $(man_MANS)) -# PSS = $(addsuffix .ps, $(man_MANS)) - -# all: dvi ps - -# dvi: $(DVIS) -# -# ps: $(PSS) - -all-local: srp-spec.txt lsh.html - -%.dvi: % - $(GROFF) -Tdvi -mandoc $< > $@ - -%.ps: % - $(GROFF) -Tps -mandoc $< > $@ - -%.txt : %.nroff - $(GROFF) -ms -Tlatin1 $< | perl $(srcdir)/fixff.pl >$@T - test -s $@T && mv -f $@T $@ - -%.html : %.texinfo - (cd $(srcdir) \ - && $(MAKEINFO) --html --no-split --output $@T $( -lsh - - - - - - -


-Node:Top, -Next:, -Previous:(dir), -Up:(dir) -
- -

- -

This document describes lsh and related programs. The lsh suite -of programs is intended as a free replacement for the ssh suite of -programs. In turn, ssh was intended as a secure replacement for -the rsh and rlogin programs for remote login over the -Internet. - -

lsh is a component of the GNU system. - -

This manual explains how to use and hack lsh; it corresponds to -lsh version 1.3.4. - -

- -


-Node:Introduction, -Next:, -Previous:Top, -Up:Top -
- -

Introduction

- -

What is this thing called computer security anyway? Why would you want -to use a program like lsh? - -

This chapter explains the threats lsh tries to protect you from, -and some of the threats that remain. It also describes some of the -technologies used in lsh. - -

From time to time in this manual, I will speak about the enemy. -This means anybody who is trying to eavesdrop or disturb your private -communication. This usage is technical, and it does not imply that the -enemy is somehow morally inferior to you: The enemy may be some awful -criminals trying to eavesdrop on you, or it may be the police trying to -eavesdrop on the same criminals. - -

The enemy can be a criminal, or a competitor, or your boss who's trying -to find out how much you tell collegues at competing firms. It may be -your own or somebody else's national security officials. Or your -ex-boyfriend who happens to be too curious. - -

So what can the enemy do to your communications and your privacy? -Remember that just because you're paranoid that doesn't mean that nobody -is trying to get you... - -

- -


-Node:Threats, -Next:, -Previous:Introduction, -Up:Introduction -
- -

Threats

- -

When logging in to some other machine via the Internet, either in the -same building or a few continents away, there are several things that -may be under enemy attack. - -

-
Local attacks -
The enemy controls your local environment. He or she may be looking over -your shoulder. Your local machine might be cracked. Or there may be some -device planted inside your keyboard transmitting everything you type to -the attacker. About the same problems occur if the attacker has taken -control over your target machine, i.e. the remote machine you have -logged in to. - -
Denial-of-service attacks -
The enemy has cut your network cable, effectively stopping your -communication. Even without doing physical damage, the enemy may be able -to flood and overload computers or network equipment. Or disrupt network -traffic by sending fake packets to hangup your TCP/IP -connections. - -
Passive eavesdropping -
The enemy may be able to listen to your communication somewhere along -its path. With the global Internet, it's difficult to predict who might -be able to listen. Internet traffic between buildings just a few hundred -meters apart have been observed temporarily being routed through half a -dozen countries, perhaps a few thousand kilometers. - -

And even without routing anomalies, it is possible that the enemy has -been able to take control of some nearby machine, and can listen in from -there. Of course, passive eavesdropping is most dangerous if you -transmit cleartext passwords. This is the main reason not to use vanilla -telnet to login to remote systems. Use a telnet with support for -SSL or Kerberos, or use a program like lsh or -ssh. - -

A passive eavesdropper is assumed not to do anything nasty with your -packets beyond listening to them. - -

Name resolution attacks -
The translation from symbolic DNS names to numeric -ip-addresses may be controlled by the attacker. In this case, you may -think that you are connecting to a friendly machine, when in fact you -are connecting somewhere else. - -
Fake packets -
It is fairly easy to fake the source address of an IP-packet, -although it is more difficult to get hold on the replies to the faked -packets. But even without any replies, this can cause serious -problems. - -
Man-in-the-middle attack -
In this attack, the enemy sits between you and the target. When -communicating with you, he pretends to be the target. When communicating -with the target, he pretends to be you. He also passes all information -on more or less unmodified, so that he is invisible to you and the -target. To mount this attack, the enemy either needs physical access to -some network equipment on the path between you and the target, or he has -been able to fool you to connect to him rather than to the target, for -example by manipulating the DNS-system. - -
- -

lsh makes no attempt to protect you from local attacks. You have -to trust the endpoint machines. It seems really difficult to uphold any -security if the local machine is compromised. This is important to keep -in mind in the "visitor"-scenario, where you visit a friend or perhaps an -Internet café and want to connect to some of the machines at home or at -work. If the enemy has been able to compromize your friend's or the -café's equipment, you may well be in trouble. - -

Protection from denial-of-service attacks is also a very difficult -problem, and lsh makes no attempt to protect you from that. - -

Instead, the aim of lsh, and most serious tools for cryptographic -protection of communications across the net, is to isolate the -vulnerabilities to the communication endpoints. If you know that the -endpoints are safe, the enemy should not be able to compromize your -privacy or communications. Except for denial-of-service attacks (which -at least can't be performed without you noticing it). - -

First of all, lsh provides protection against passive -eavesdropping. In addition, if you take the appropriate steps to make -sure that hostkeys are properly authenticated, lsh also protects -against man-in-the-middle attacks and in particular against attacks on -the name resolution. In short, you need only trust the security at the -end points: Even if the enemy controls all other network equipment, name -resolution and routing infrastructure, etc, he can't do anything beyond -the denial-of-service attack. - -

And at last, remember that there is no such thing as absolute security. -You have to estimate the value of that which you are protecting, and -adjust the security measures so that your enemies will not find it worth -the effort to break them. - -


-Node:Features, -Next:, -Previous:Threats, -Up:Introduction -
- -

Features

- -

lsh does not only provide more secure replacements for -telnet, rsh and rlogin, it also provides -some other features to make it convenient to communicate securely. This -section is expected to grow with time, as more features from the -wish-list are added to lsh. One goal for lsh is to make it -reasonable easy to extend it, without messing with the core security -functionality. - -

lsh can be configured to allow login based on a personal key-pair -consisting of a private and a public key, so that you can execute remote -commands without typing your password every time. You can also use -Thomas Wu's Secure Remote Password Protocol (SRP). Kerberos support is -on the wish list but not yet supported (see Kerberos). - -

The public-key authentication methods should also be extended to support -Simple Public Key Infrastructure (SPKI) certificates, including some -mechanism to delegate restricted logins. - -

Forwarding of arbitrary TCP/IP connections is provided. This -is useful for tunneling otherwise insecure protocols, like telnet and -pop, through an encrypted lsh connection. - -

Convenient tunneling of X was one of the most impressive -features of the original ssh programs. The current version of -lsh implements X-forwarding, although the -lshd server doesn't provide that service yet. - -

Whan X forwarding is in effect, the remote process is started -in an environment where the DISPLAY variable in the environment -points to a fake X server, connection to which are forwarded -to the X server in your local environment. lsh also -creates a new "fake" MIT-MAGIC-COOKIE-1 for controlling access -control. Your real X authentication data is never sent to the -remote machine. - -

Other kinds of tunneling that may turn out to be useful include -authentication (i.e. ssh-agent), general forwarding of -UDP, and why not also general IP-tunneling. - -


-Node:Related techniques, -Previous:Features, -Up:Introduction -
- -

Related programs and techniques

- -

This sections describes some other programs and techniques related to -lsh. The ssh family of programs use mostly the same kind of -security as lsh. Kerberos and IPSEC operate quite -differently, in particular when it comes to protection against -man-in-the-middle attacks. - -

- -


-Node:ssh1, -Next:, -Previous:Related techniques, -Up:Related techniques -
- -

ssh-1.x

- -

The first of the Secure shell programs was Tatu Ylönen's ssh. -The latest of the version 1 series is ssh-1.27 which speaks -version 1.5 of the protocol. The "free" version of ssh-1.27 -does not allow commercial use without additional licensing, which makes -ssh-1.27 non-free software according to Debian's Free Software -Guidelines and the Open Source Definition. - -

The version 1 protocol has some minor weaknesses, in particular, all -support for using stream ciphers was disabled by default a few versions -back, for security reasons. - -

There also exists free implementations of ssh-1, for both Unix -and Windows. ossh and later OpenSSH are derived from earlier -version av Tatu Ylönen's ssh, and are free software. - -


-Node:ssh2, -Next:, -Previous:ssh1, -Up:Related techniques -
- -

ssh-2.x

- -

ssh2 implements the next generation of the Secure Shell -protocol, the development of which is supervised by the IETF -secsh Working Group. lsh implements the required subset of -this protocol. It is intended to be compatible with the ssh2 -series of programs distributed by F-Secure Corporation. - -

However, the existing versions of ssh2 gets some details of the -protocol wrong (probably because it predates the protocol -specification), so there is some amount of bug-compatibility required. - -

Interoperability between independently developed implementations is one -necessary condition for the ssh-2 protocol to become a Proposed -Standard. - -

The license for F-Secure's ssh2 programs is similar to that -for recent versions of ssh1, but with a narrower definition of -"non-commercial use". - -

Besides lsh there are few free implementations of the -ssh-2 protocols. Since May 2000 it is supported also by -OpenSSH. - -


-Node:Kerberos, -Next:, -Previous:ssh2, -Up:Related techniques -
- -

Kerberos

- -

Kerberos is a key distribution system originally developed in the late -1980:s as a part of Project Athena at MIT. Recent development -have been done at The Royal Institute of Technology, Stockholm -(KTH). - -

Kerberos uses a central trusted ticket-granting server, and requires -less trust on the local machines in the system. It does not use -public-key technology. - -

Usually, Kerberos support is compiled into applications such as telnet, -ftp and X-clients. The ssh family of programs, on the other hand, tries -to do all needed magic, for instance to forward X securely, and then -provides general TCP/IP forwarding as a kitchen sink. - -

I believe Kerberos' and lsh's protection against passive eavesdropping -are mostly equivalent. The difference is in the set of machines and -assumptions you have to trust in order to be safe from a -man-in-the-middle attack. - -

I think the main advantage of lsh over Kerberos is that it is -easier to install and use for on ordinary mortal user. In order to set -up key exchange between two different Kerberos systems (or Kerberos -realms), the respective system operators need to exchange keys. In the -case of two random users at two random sites, setting up lsh or -some other program in the ssh family is likely easier than to get the -operators to spend time and attention. So lsh should be easier to -use in an anarchistic grass-roots environment. - -

Another perspective is to combine ssh features like X and -TCP/IP forwarding with authentication based on Kerberos. Such -an arrangement may provide the best of two worlds for those who happen -to have an account at a suitable ticket-granting server. - -


-Node:ipsec, -Previous:Kerberos, -Up:Related techniques -
- -

IPSEC

- -

IPSEC is a set of protocols for protecting general -IP traffic. It is developed by another IETF working -group, and is also a required part of IP version 6. - -

Again, the main difference between IPSEC and Kerberos and ssh -is the set of machines that have to be secure and the keys that have to -be exchanged in order to avoid man-in-the-middle attacks. - -

Current protocols and implementations of IPSEC only provide -authentication of machines; there's nothing analogous to the user -authentication in ssh or Kerberos. - -

On the other hand, IPSEC provides one distinct advantage over -application level encryption. Because IP and TCP -headers are authenticated, it provides protection against some -denial-of-service attacks. In particular, it makes attacks that cause -hangup of a TCP connection considerably more difficult. - -

So it makes sense to use both IPSEC and some application -level cryptographic protocol. - -

Also note that it is possible to use the Point-to-Point Protocol -(PPP) to tunnel arbitrary IP traffic accross an ssh -connection. This arrangement provides some of the functionality of -IPSEC, and is sometimes referred to as "a poor man's Virtual -Private Network". - -


-Node:Installation, -Next:, -Previous:Introduction, -Up:Top -
- -

Installation

- -

You install lsh with the usual ./configure && make && -make install. For a full listing of the options you can give to -configure, use ./configure --help. For example, use ---without-pty to disable pty-support. - -

The most commonly used option is --prefix, which tells -configure where lsh should be installed. Default prefix is -/usr/local. The lshd server is installed in -$prefix/sbin, all other programs and scripts are installed in -$prefix/bin. - -

The configure script tries to figure out if the linker needs any special -flags specifying where to find dynamically linked libraries at run time -(one case where this matters is if you have a dynamic libz.so installed -in a non -standard place). Usually, you can use - -

./configure --with-lib-path=/opt/lib:/other/place
-
- -

to specify extra library directories, and the configure script should do -the right thing. If it doesn't work, or you believe that you know your -system better than ./configure, just set LDFLAGS and/or -LD_LIBRARY_PATH to the right values instead. - -


-Node:Getting started, -Next:, -Previous:Installation, -Up:Top -
- -

Getting started

- -

This section tells you how to perform some common tasks using the -lsh suite of programs, without covering all options and -possibilities. - -

- -


-Node:lsh basics, -Next:, -Previous:Getting started, -Up:Getting started -
- -

lsh basics

- -

lsh is the program you use for connection to a remote machine. A -few examples are: - -

lsh sara.lysator.liu.se
-
- -

Connects to sara.lysator.liu.se and starts an interactive shell. -In this example, and in the rest of the examples in this section, lsh -will ask for your password, unless you have public-key user -authentication set up. - -

The first time you try to connect between two machines, lsh -typically complains about an "unknown host key". This is because it -has no reason to believe that it was the right machine that answered, -and not a machine controlled by the enemy (see Threats). The default -behaviour is to never ever accept a server that is not properly -authenticated. A machine is considered authentic if it follows the -protocol and has its public hostkey listed in ~/.lsh/known_hosts. - -

To make lsh less paranoid, use - -

lsh --sloppy-host-authentication sara.lysator.liu.se
-
- -

Then lsh will display a fingerprint of the host key of the -remote machine, and ask you if it is correct. If so, the machine is -considered authentic and its key is appended to the file -~/.lsh/captured_keys. You can copy keys you have verified to -~/.lsh/known_hosts. - -

You can even use - -

lsh --sloppy-host-authentication --capture-to ~/.lsh/known_hosts
-
- -

to get lsh to behave more like the traditional ssh program. - -

You can create fingerprints for the hostkeys you need regularly, and -keep with you (see sexp). - -

lsh -l omar sara.lysator.liu.se
-
- -

Connects, like above, but tries to log in as the user "omar". - -

lsh sara.lysator.liu.se tar cf - some/dir | (cd /target/dir && tar -xf -)
-
- -

Copies a directory from the remote machine, by executing one remote and -one local tar process and piping them together. - -

CVS_RSH=lsh cvs -d sara.lysator.liu.se:/lysator/cvsroot co lsh
-
- -

Checks out the lsh source code from the CVS -repository. - -


-Node:tcpip forwarding, -Next:, -Previous:lsh basics, -Up:Getting started -
- -

Port forwarding

- -

One useful feature of lsh and other ssh-like programs is the -ability to forward arbitrary connections inside the encrypted -connection. There are two flavors: "local" and "remote" forwarding. - -

An example of local forwarding is - -

lsh -L 4000:kom.lysator.liu.se:4894 sara.lysator.liu.se
-
- -

This makes lsh listen on port 4000 on the local machine. When -someone connects, lsh asks the server to open a connection from -the remote machine (i.e. sara) to port 4894 on another machine -(i.e. kom). The two connections are piped together using an -encrypted channel. - -

There are a few things that should be noted here: - -

    -
  • By default, lsh only listens on the loopback interface, so only -clients on the same machine can use the tunnel. To listen on all -interfaces, use the -g flag. - -
  • A connection through the tunnel consists of three parts: - -
      -
    1. From a client socket to the local port (4000 in this example) that -lsh listens on. - -
    2. The tunnel itself, from the local machine to the tunnel endpoint, -which is sara in this example. - -
    3. The connection from the tunnel endpoint to the ultimate target, in this -example from sara to kom. - -
    - -

    Only the middle part is protected by lsh: all data flowing -through the tunnel is sent across the first and last part in the -clear. So forwarding doesn't offer much protection unless the tunnel -endpoint and the ultimate target machine are close to eachother. They -should usually be either the same machine, or two machines connected by -a local network that is trusted. - -

  • Port forwarding is very useful for traversing firewalls. Of course, you -don't need to use lsh-style forwarding just to get out, there are other -tools like HTTPTunnel for that. But lsh helps you get out through -the firewall in a secure way. - -
  • Port forwarding is done in addition to anything else lsh is -doing. In the example above, a tunnel is set up, but lsh will -also start an interactive shell for you. Just as if the -L -option was not present. If this is not what you want, the -N or --B option is for you (see Invoking lsh) -
- -

Remote forwarding is similar, but asks the remote machine to -listen on a port. An example of remote forwarding is - -

lsh -g -R 8080:localhost:80 sara.lysator.liu.se
-
- -

This asks the remote machine to listen on port 8080 (note that you are -probably not authorized to listen on port 80). Whenever someone -connects, the connection is tunnelled to your local machine, and -directed to port 80 on the same machine. Note the use of -g; -the effect is to allow anybody in the world to use the tunnel to connect -to your local webserver. - -

The same considerations that apply to forwarded local ports apply also to -forwarded remote ports. - -

At last, you can use any number of -L and -R options -on the same command line. - -


-Node:lshd basics, -Next:, -Previous:tcpip forwarding, -Up:Getting started -
- -

lshd basics

- -

There are no global configuration files for lshd; all -configuration is done with command line options (see Invoking lshd). - -

To run lshd, you must first create a hostkey, usually stored in -/etc/lsh_host_key. To do this, run - -

lsh-keygen | lsh-writekey -o /etc/lsh_host_key
-
- -

This will also create a file /etc/lsh_host_key.pub, -containing the corresponding public key. - -

A typical command line for starting lshd in daemon mode is simply - -

lshd --daemonic
-
- -

You can find init script for lshd tailored for Debian's and -RedHat's GNU/Linux systems in the contrib directory. - -

It is also possible to let init start lshd, by adding it in -/etc/inittab. - -


-Node:public-key, -Next:, -Previous:lshd basics, -Up:Getting started -
- -

Using public-key user authentication

- -

Public-key user authentication is a way to authenticate for login, -without having to type any passwords. There are two steps: Creating a -key pair, and authorizing the public key to the systems where you want -to log in. - -

To create a keypair, run - -

lsh-keygen | lsh-writekey
-
- -

This can take some time, but in the end it creates two files -~/.lsh/identity and ~/.lsh/identity.pub. - -

If you want to use the key to login to some other machine, say -sara, you can do that by first copying the key, - -

lsh sara.lysator.liu.se '>my-key.pub' <~/.lsh/identity.pub
-
- -

then authorizing it by executing, on sara, - -

lsh-authorize my-key.pub
-
- -

For security reasons, you should keep the private key -~/.lsh/identity secret. Anybody who can read that file will be -able to login in your name to any machine where the corresponding public -key is registered as an authorized key. - -

Naturally, you should also make sure not to authorize any keys but your -own. For instance, it is inappropriate to use an insecure mechanism such -as unauthenticated email, ftp or http to transfer your -public key to the machines where you want to authorize it. - -

If you have accounts on several systems, you usually create a single -keypair on each of the systems, and on each system you authorize some or -all of your other public keys for login. - -

Note that lsh-writekey does not currently encrypt your -private key in any way. That means that you can lose it if a backup tape -gets into the wrong hands, and if you use NFS it will likely be sent in -the clear across your local network. To encrypt the key using a pass -phrase, give the -c 3des option to lsh-writekey. - -


-Node:srp, -Next:, -Previous:public-key, -Up:Getting started -
- -

Using SRP authentication

- -

The Secure Remote Password protocol is a fairly new protocol that -provides mutual authentication based on a password. To use it, you must -first choose a secret password. Next, you create a password -verifier that is derived from the password. The verifier is stored on -the target machine (i.e. the machine you want to log in to). - -

To create a verifier, you run the srp-gen program and type -your new password. You have to do it on either the target machine, -redirecting the output to ~/.lsh/srp-verifier, or you can generate it on -some other machine and copy it to the target. - -

The main advantage of using SRP is that you use the password -not only to get access to the remote machine, but you also use it to -authenticate the remote machine. I.e. you can use it to connect -securely, without having to know any hostkeys or fingerprints -beforehand! - -

For instance, you could connect using SRP to fetch the hostkey -fingerprint for the remote machine, as a kind of bootstrapping -procedure, and then use traditional authentication methods for further -connections. - -

For this to work, the verifier must be kept secret. If the -enemy gets your verifier, he can mount some attacks: - -

    -
  • He can mount a dictionary attack on your password, i.e. generate a large -list of likely password and check if any of them matches yours. - -
  • He can impersonate the server. That means that if you try to connect to -the remote machine using SRP, and the attacker can intercept -your connection (e.g. by attacking the name resolution or routing -system) he can successfully pretend to be the real server. -
- -

If you use SRP to get the hostkey or fingerprint for the -remote machine, as outlined above, the impersonation attack destroys -security, you could just as well connect the hostkey presented by the -remote server without verifying it at all. - -

If you use SRP exclusively, the situation seems somewhat -different. As far as I can see, an attacker knowing your verifier can -not mount a traditional man-in-the-middle-attack: He can play the -server's part when talking to you, but in order to play your part when -talking to the real server, he needs to know your password as well. - -

SRP support is disabled by default, but can be enabled by the ---srp-keyexchange option to lshd and lsh -(naturally, it won't be used unless enabled on both sides). At the time -of this writing, SRP is too new to be trusted by conservative -cryptographers (and remember that conservatism is a virtue when it comes -to security). - -

And even if SRP in itself is secure, the way lsh -integrates it into the ssh protocol has not had much peer review. -The bottom line of this disclaimer is that the SRP support in -lsh should be considered experimental. - -

As far as I know, using SRP as a host authentication mechanism -is not supported by any other ssh implementation. The protocol -lsh uses is described in the doc/srp-spec.txt. -Implementations that use SRP only as a user authentication -mechanism are not compatible with lsh. - -


-Node:sexp, -Next:, -Previous:srp, -Up:Getting started -
- -

Examining keys and other sexp files

- -

Keys and most other objects lsh needs to store on disk are -represented as so called S-expressions or sexps for short. -S-expressions have their roots in the Lisp world, and a variant of them -in used in the Simple Public Key Infrastructure (SPKI). -Currently, lsh's support for SPKI is quite limited, -but it uses SPKI's formats for keys and Access Control Lists -(ACL:s). - -

There are several flavours of the sexp syntax: - -

    -
  • The canonical syntax is somewhere between a text and a binary format, -and is extremely easy for programs to read and write. - -
  • The transport syntax, which is suitable when embedding sexps in text -files. It is essentially the canonical representation, encoded using -base64. - -
  • The advanced syntax, which is intended for humans to read and write, and -bears some resemblance to Lisp expressions. -
- -

To see what your ~/.lsh/known_hosts file really contains, try - -

sexp-conv -i advanced < ~/.lsh/known_hosts
-
- -

The sexp-conv program can also be used to computes -fingerprints. The fingerprint of a key (or any sexp, for that matter) is -simply the hash of its canonical representation. For example, - -

sexp-conv --raw-hash </etc/lsh_host_key.pub
-
- -


-Node:Converting keys, -Previous:sexp, -Up:Getting started -
- -

Converting keys from ssh2 and OpenSSH

- -

If you are already using ssh2 or OpenSSH, and have creating -one or more personal keypairs, you need to convert the public keys to -lsh's format before you can authorize them. Use the supplied -ssh-conv script, - -

ssh-conv <openssh-key.pub >new-key.pub
-
- -

You can then use the usual lsh-authorize on the converted -keys. ssh-conv supports both DSA and RSA keys. - -

There are currently no tools for converting private keys. - -


-Node:Invoking lsh, -Next:, -Previous:Getting started, -Up:Top -
- -

Invoking lsh

- -

- -

You use lsh to login to a remote machine. Basic usage is - -

lsh [-p port number] sara.lysator.liu.se - -

which attempts to connect, login, and start an interactive shell on the -remote machine. Default port number is whatever your system's -/etc/services lists for ssh. Usually, that is port 22. - -

There is a plethora of options to lsh, to let you configure where -and how to connect, how to authenticate, and what you want to do once -properly logged in to the remote host. Many options have both long and -short forms. This manual does not list all variants; for a full listing -of supported options, use lsh --help. - -

Note that for many of the options to lsh, the ordering of the -options on the command line is important. - -

- -


-Node:Algorithm options, -Next:, -Previous:Invoking lsh, -Up:Invoking lsh -
- -

Algorithm options

- -

Before a packet is sent, each packet can be compressed, encrypted -and authenticated, in that order. When the packet is received, it is -first decrypted, next it is checked that it is authenticated properly, -and finally it is decompressed. The algorithms used for this are -negotiated with the peer at the other end of the connection, as a part -of the initial handshake and key exchange. - -

Each party provides a list of supported algorithms, and the first -algorithm listed by the client, which is also found on the server's -list, is selected. Note that this implies that order in which algorithms -are listed on the server's list doesn't matter: if several algorithms -are present on both the server's and the client's lists, it's the -client's order that determines which algorithm is selected. - -

Algorithms of different types, e.g. data compression and message -authentication, are negotiated independently. Furthermore, algorithms -used for transmission from the client to the server are independent of -the algorithms used for transmission from the server to the client. -There are therefore no less than six different lists that could be -configured at each end. - -

The command line options for lsh and lshd don't let you specify -arbitrary lists. For instance, you can't specify different preferences -for sending and receiving. - -

There is a set of default algorithm preferences. When you use a command -line option to say that you want to use algorithm for one of the -algorithms, the default list is replaced with a list containing the -single element algorithm. For example, if you use -c -arcfour to say that you want to use arcfour as the encryption -algorithm, the connection will either end up using arcfour, or -algorithm negotiation will fail because the peer doesn't support -arcfour. - -

Option - Algorithm type Default -
-z Data compression - none, zlib - -The default preference list supports zlib compression, but -prefers not to use it. - -
-c Encryption - 3dec-cbc, blowfish-cbc, arcfour -arcfour - -The default encryption algorithm is triple-DES in CBC mode. This -seems to be the algorithm of choice among conservative cryptographers. -The default list includes only quite old and well studied algorithms. -There is a special algorithm name all to enable all supported -encryption algorithms (except none). - -
-m Message Authentication - hmac-sha1, hmac-md5 - -Both supported message authentication algorithms are of the -HMAC family. -
- -

As a special case, -z with no argument changes the compression -algorithm list to zlib, none, which means that you want to -use zlib if the other end supports it. This is different from --zzlib which causes the negotiation to fail if the other end -doesn't support zlib. A somewhat unobvious consequence of --z having an optional argument is that if you provide an -argument, it must follow directly after the option letter, no spaces -allowed. - -


-Node:Hostauth options, -Next:, -Previous:Algorithm options, -Up:Invoking lsh -
- -

Host authentication options

- -

As described earlier (see Threats), proper authentication of the -remote host is crucial to protect the connection against -man-in-the-middle attacks. By default, lsh verifies the server's -claimed host key against the Access Control Lists in -~/.lsh/known_hosts. If the remote host cannot be authenticated, -the connection is dropped. - -

The options that change this behaviour are - -

-
--host-db -
Specifies the location of the ACL file. - -
--sloppy-host-authentication -
Tell lsh not to drop the connection if the server's key can not -be authenticated. Instead, it displays the fingerprint of the key, and -asks if it is trusted. The received key is also appended to the file -~/.lsh/captured_keys. If run in quiet mode, lsh -q ---sloppy-host-authentication, lsh connects to any host, no -questions asked. - -
--strict-host-authentication -
Disable sloppy operation (this is the default behaviour). - -
--capture-to -
Use some other file than ~/.lsh/captured_keys. For example, - -
lsh --sloppy-host-authentication --capture-to ~/.lsh/known_hosts
-
- -

makes lsh behave more like the ssh program. - -

--srp-keyexchange -
Try using SRP for keyexchange and mutual authentication. - -
- -


-Node:Userauth options, -Next:, -Previous:Hostauth options, -Up:Invoking lsh -
- -

User authentication options

- -
- -
-l -
Provide a name to use when logging in. By default, the value of the -LOGNAME environment variable is used. - -
-i -
Try the keys from this file to log in. By default, lsh uses -~/.lsh/identity, if it exists. It ought to be possible to use -several -i options to use more than one file, but that is -currently not implemented. - -
--no-publickey -
Don't attempt to log in using public key authentication. - -
- -


-Node:Action options, -Next:, -Previous:Userauth options, -Up:Invoking lsh -
- -

Action options

- -

There are many things lsh can do once you are logged in. There -are two types of options that control this: actions and -action modifiers. For short options, actions use uppercase letters -and modifiers use lowercase. - -

For each modifier --foo there's also a negated form ---no-foo. Options can also be negated by preceding it with the -special option -n. This is mainly useful for negating short -options. For instance, use -nt to tell lsh not to -request a remote pseudo terminal. Each modifier and its negation can be -used several times on the command line. For each action, the latest -previous modifier of each pair apply. - -

First, the actions: - -

- -
-L -
Requests forwarding of a local port. This option takes mandatory -argument of the form -listen-port:target-host:target-port. This option tells -lsh to listen on listen-port on the local machine. When -someone conects to that port, lsh asks the remote server to open -a connection to target-port on target-host, and if it -succeeds, the two connections are joined together through an the -lsh connection. Both port numbers should be given in decimal. - -
-R -
Requests forwarding of a remote port. It takes one mandatory argument, -just like -L. But in this case lsh asks the -remote server to listen on listen-port. When someone -connects to the remote hosts, the server will inform the local -lsh. The local lsh then connects to target-port on -target-host. - -
-E -
This option takes one mandatory argument, which is a command line to be -executed on the remote machine. - -
-S -
Start an interactive shell on the remote machine. - -
-G -
Open a gateway on the local machine. A gateway is a local socket, -located under /tmp, that can be used for controlling and using the ssh -connection. It is protected using the ordinary file permissions. - -
-N -
This is a no-operation action. It inhibits the default action, which is -to start an interactive shell on the remote machine. It is useful if you -want to set up a few forwarded tunnels or a gateway, and nothing more. - -
-B -
Put the client into the background after key exchange and -user authentication. Implies -N -
- -

If there are trailing arguments after the name of the remote system, -this is equivalent to a -E option, with a command string -constructed by catenating all the remaining arguments, separated by -spaces. This implies that the arguments are usually expanded first by -the local shell, and then the resulting command string is interpreted -again by the remote system. - -

If there are no trailing arguments after the name of the remote system, -and the -N option is not given, the default action is to start -a shell on the remote machine. I.e. this is equivalent to the --S option. - -

There are a few supported modifiers: - -

- -
-t -
Request a pseudo terminal. lsh asks the remote system to allocate -a pseudo terminal. If it succeeds, the local terminal is set to raw -mode. The default behaviour is to request a pty if and only if the -local lsh process has a controlling terminal. This modifier -applies to actions that create remote processes, i.e. -E and --S, as well as the default actions. - -

Currently, this option is ignored if there is no local terminal. - -

-x -
Request X forwarding. Applies to the -E and -S and the default actions. - -
--stdin -
Redirect the stdin of a remote process from a given, local, file. -Default is to use lsh's stdin for the first process, and -/dev/null for the rest. This option applies to the -E -and -S options as well as to the default actions. The option -applies to only one process; as soon as it is used it is reset to the -default. - -
--stdout -
Redirect the stdout of a remote process to a given, local, file. Default -is to use lsh's stdout. Like --stdin, it is reset -after it is used. - -
--stderr -
Redirect the stdout of a remote process to a given, local, file. -Analogous to the --stdout option. - -
-g -
Remote peers, aka global forwarding. This option applies to the -forwarding actions, i.e. -L and -R. By default, only -connections to the loopback interface, ip 127.0.0.1, are forwared. This -implies that only processes on the same machine can use the forwarded -tunnel directly. If the -g modifier is in effect, the forwarding party -will listen on all network interfaces. - -
- -


-Node:Verbosity options, -Previous:Action options, -Up:Invoking lsh -
- -

Verbosity options

- -

These options determines what messages lsh writes on -its stderr. - -

- -
-q -
Quiet mode. Disables all messages and all questions, except password -prompts and fatal internal errors. - -
-v -
Verbose mode. Makes lsh a little more verbose. The intention is -to provide information that is useful for ordinary trouble shooting, -and makes sense also to those not familiar with lsh internals. - -
--trace -
Trace mode. Prints some internal information to aid tracking -lsh's flow of control. - -
--debug. -
Debug mode. Dumps a lot of information, including dumps of all -sent and received packets. It tries to avoid dumping highly sensitive data, -such as private keys and the contents of SSH_MSG_USERAUTH_REQUEST -messages, but you should still use it with care. - -
--log-file -
This option redirects all messages to a file. Takes one mandatory -argument: The name of that file. - -
- -

Note that all these options are orthogonal. If you use --trace, -you usually want to add -v as well; --trace does not -do that automatically. - -


-Node:Invoking lshd, -Next:, -Previous:Invoking lsh, -Up:Top -
- -

Invoking lshd

- -

- -

lshd is a server that accepts connections from clients -speaking the Secure Shell Protocol. It is usually started automatically -when the systems boots, and runs with root privileges. However, it is -also possible to start lshd manually, and with user -privileges. - -

There are currently no configuration files. Instead, command line options -are used to tell lshd what to do. Many options have --foo -and --no-foo variants. Options specifying the default behaviour -are not listed here. - -

Some of the options are the shared with lsh. In particular, see -Algorithm options and Verbosity options. - -

Options specific to the lshd server are: - -

- -
-p -
Port to listen to. The mandatory argument is a decimal port number or a -service name. Default is "ssh", usually port 22. - -
--interface -
Network interface to listen on. By default, lshd listens on all -interfaces. - -
-h -
Location of the server's private key file. By default, -/etc/lsh_host_key. - -
-i -
Variant of the s-expression syntax to use when reading the host key. -Default is to use transport format. Not a terribly useful option. - -
--ssh1-fallback -
This options enables fallback to ssh1. lshd doesn't -implement version 1 of the Secure Shell Protocol. But it can fork an -ssh1 server when an old client connects. Falling back to -ssh1 is inefficient, and requires some special features of the -server fallen back to. It should work with the sshd daemon -supplied with reasonably new versions of F-Secure's sshd1, -and with OpenSSH. - -

The optional argument provides the filename of the ssh1 daemon to use. -The default name is /usr/local/sbin/sshd1, unless something else -was configured at compile time. - -

--daemonic -
Enables daemonic mode. lshd forks into the background, -redirects its stdio file descriptors to /dev/null, changes its -working directory to /, and redirects any diagnostic or debugging -messages via syslog. - -

lshd should be able to deal with the environment it inherits -if it is started by init or inetd, but this is not -really tested. - -

--pid-file -
Creates a locked pid file, to make it easier to write start and stop -scripts for lshd. The mandatory argument provides the filename. -This option is enabled by default when operating in daemonic mode, and -the default filename is /var/run/lshd.pid. - -
--enable-core -
By default, lshd disables core dumps, to avoid leaking sensitive -information. This option changes that behaviour, and allows lshd -to dump core on fatal errors. - -
--no-password -
Disable the "password" user authentication mechanism. - -
--no-publickey -
Disable the "publickey" user authentication mechanism. - -
--root-login -
Enable root login. By default, root can not log in using lshd. - -
--kerberos-passwords -
Verify passwords against the kerberos database. This is implemented -using the lsh-krb-checkpw helper program. Note that this does -not use the Kerberos infrastructure in the Right Way. Experimental. - -
--password-helper -
Tells lshd to use a helper program for verifying passwords. -This is a generalization of --kerberos-passwords, and it could -be used for verifying passwords against any password database. See the -source files lsh-krb-checkpw.c and unix_user.c for -details. - -
--login-shell -
Use the specified program as the login shell for all users, overriding -the login shell in the passwd database. Mainly useful for testing. - -
--srp-keyexchange -
Enable SRP keyexchange and user authentication. - -
--no-pty-support -
Disable support for pseudo terminals. - -
--no-tcp-forward -
Disable support for tcp forwarding, in both directions. - -
- -


-Node:Terminology, -Next:, -Previous:Invoking lshd, -Up:Top -
- -

Terminology

- -


-Node:Concept Index, -Previous:Terminology, -Up:Top -
- -

Concept Index

- -
    -
- -

Table of Contents

- - - - - diff --git a/lsh/doc/lsh.info b/lsh/doc/lsh.info deleted file mode 100755 index e679f28..0000000 Binary files a/lsh/doc/lsh.info and /dev/null differ diff --git a/lsh/doc/lsh.texinfo b/lsh/doc/lsh.texinfo deleted file mode 100755 index 6ccaa88..0000000 Binary files a/lsh/doc/lsh.texinfo and /dev/null differ diff --git a/lsh/doc/lsh_keygen.1 b/lsh/doc/lsh_keygen.1 deleted file mode 100755 index 576eaf5..0000000 Binary files a/lsh/doc/lsh_keygen.1 and /dev/null differ diff --git a/lsh/doc/lsh_writekey.1 b/lsh/doc/lsh_writekey.1 deleted file mode 100755 index cb6fcf5..0000000 Binary files a/lsh/doc/lsh_writekey.1 and /dev/null differ diff --git a/lsh/doc/lshd.8 b/lsh/doc/lshd.8 deleted file mode 100755 index f88806a..0000000 Binary files a/lsh/doc/lshd.8 and /dev/null differ diff --git a/lsh/doc/secsh.5 b/lsh/doc/secsh.5 deleted file mode 100755 index 7e376f4..0000000 Binary files a/lsh/doc/secsh.5 and /dev/null differ diff --git a/lsh/doc/srp-spec.nroff b/lsh/doc/srp-spec.nroff deleted file mode 100755 index 9b274d5..0000000 Binary files a/lsh/doc/srp-spec.nroff and /dev/null differ diff --git a/lsh/doc/srp-spec.txt b/lsh/doc/srp-spec.txt deleted file mode 100755 index 76e8334..0000000 Binary files a/lsh/doc/srp-spec.txt and /dev/null differ diff --git a/lsh/doc/texinfo.tex b/lsh/doc/texinfo.tex deleted file mode 100755 index 63a548b..0000000 Binary files a/lsh/doc/texinfo.tex and /dev/null differ diff --git a/lsh/install-sh b/lsh/install-sh deleted file mode 100755 index 6bfa7aa..0000000 --- a/lsh/install-sh +++ /dev/null @@ -1,241 +0,0 @@ -#! /bin/sh -# -# $Id$ -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 - diff --git a/lsh/make_am b/lsh/make_am deleted file mode 100755 index 33668a3..0000000 Binary files a/lsh/make_am and /dev/null differ diff --git a/lsh/misc/Makefile.am b/lsh/misc/Makefile.am deleted file mode 100755 index c86e284..0000000 --- a/lsh/misc/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -## Automatically generated by make_am, Wed Aug 29 23:52:16 CEST 2001 -## Process this file with automake to produce Makefile.in - - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = ctags.mk libgcc2.c-patch bootstrap.sh make-dist - -all: - true - -include ctags.mk diff --git a/lsh/misc/Makefile.in b/lsh/misc/Makefile.in deleted file mode 100755 index 0879d10..0000000 --- a/lsh/misc/Makefile.in +++ /dev/null @@ -1,212 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -# ctags support. Automake only supports etags. We base our ctags support on -# automake's etags support. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = .. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = ctags.mk libgcc2.c-patch bootstrap.sh make-dist -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../config.h -CONFIG_CLEAN_FILES = -DIST_COMMON = Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -all: all-redirect -.SUFFIXES: -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) $(srcdir)/ctags.mk - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps misc/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -tags: TAGS -TAGS: - - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = misc - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: tags distdir info-am info dvi-am dvi check check-am \ -installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -all: - true - -.PHONY: ctags-recursive ctags - -ctags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - (cd $$subdir && $(MAKE) ctags); \ - done - -ctags: ctags-recursive $(HEADERS) $(SOURCES) $(CONFIG_HEADER) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - test -f $$subdir/tags && tags="$$tags $$here/$$subdir/tags"; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$(CONFIG_HEADER)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && ctags --langmap=c:.c.x -o $$here/tags $(CTAGS_ARGS) $$tags $(CONFIG_HEADER) $$unique $(LISP)) -# This treats .h.x files as C files rather than headers, but we can't -# distinguish them from .c.x files with ctags. - -# Override the standard distclean-tags target, as this doesn't support `tags' -distclean-tags: - -rm -f TAGS ID tags - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/misc/bootstrap.sh b/lsh/misc/bootstrap.sh deleted file mode 100644 index d8d27ce..0000000 --- a/lsh/misc/bootstrap.sh +++ /dev/null @@ -1,26 +0,0 @@ -#! /bin/sh - -# Build all automatically generated files that are not present in the -# CVS repository. - -# This script is for use in the source directory, before you run -# configure. To get started from a fresh CVS checkout, you also need -# to run configure and make bootstrap from your build directory. - -set -e -bash make_am -aclocal -autoheader -autoconf -(cd src/argp && aclocal) -(cd src/argp && autoconf) -(cd src/argp && autoheader) - -(cd src/nettle && ./.bootstrap) -(cd src/sftp && ./.bootstrap) - -automake -a Makefile src/Makefile - -(cd src/argp && automake -a) -(cd src/nettle && automake -a) -(cd src/sftp && automake -a) diff --git a/lsh/misc/ctags.mk b/lsh/misc/ctags.mk deleted file mode 100755 index d5e588b..0000000 Binary files a/lsh/misc/ctags.mk and /dev/null differ diff --git a/lsh/misc/libgcc2.c-patch b/lsh/misc/libgcc2.c-patch deleted file mode 100644 index 64246f6..0000000 --- a/lsh/misc/libgcc2.c-patch +++ /dev/null @@ -1,94 +0,0 @@ -This patch, relative to gcc-2.95.3, improves gcov support by properly -locking the output files that are written at process exit. - -/Niels Möller - ---- libgcc2.c.orig Fri Jun 11 05:11:43 1999 -+++ libgcc2.c Thu Mar 22 20:48:39 2001 -@@ -1459,6 +1459,10 @@ - #include "gcov-io.h" - #include - -+/* For O_RDWR and O_CREAT */ -+#include -+#include -+ - static struct bb *bb_head; - - /* Return the number of digits needed to print a value */ -@@ -1478,6 +1482,23 @@ - return ret; - } - -+/* Opens a file, locking it for exclusive access. Used for .da files -+ * below. -+ */ -+static FILE * -+lopen(const char *name) -+{ -+ int fd = open(name, O_RDWR | O_CREAT, 0666); -+ if (fd < 0) -+ return NULL; -+ -+ while ( (lockf(fd, F_LOCK, 0) < 0)) -+ if (errno != EINTR) -+ return NULL; -+ -+ return fdopen(fd, "r+b"); -+} -+ - void - __bb_exit_func (void) - { -@@ -1502,18 +1523,21 @@ - /* If the file exists, and the number of counts in it is the same, - then merge them in. */ - -- if ((da_file = fopen (ptr->filename, "r")) != 0) -+ long n_counts = 0; -+ -+ /* If the file exists, and the number of counts in it is the same, -+ then merge them in. */ -+ -+ -+ if ((da_file = lopen (ptr->filename)) == 0) - { -- long n_counts = 0; -- -- if (__read_long (&n_counts, da_file, 8) != 0) -- { -- fprintf (stderr, "arc profiling: Can't read output file %s.\n", -- ptr->filename); -- continue; -- } -+ fprintf (stderr, "arc profiling: Can't open output file %s.\n", -+ ptr->filename); -+ continue; -+ } - -- if (n_counts == ptr->ncounts) -+ if ( (__read_long (&n_counts, da_file, 8) == 0) -+ && (n_counts == ptr->ncounts) ) - { - int i; - -@@ -1531,16 +1555,9 @@ - } - } - -- if (fclose (da_file) == EOF) -- fprintf (stderr, "arc profiling: Error closing output file %s.\n", -- ptr->filename); -- } -- if ((da_file = fopen (ptr->filename, "w")) == 0) -- { -- fprintf (stderr, "arc profiling: Can't open output file %s.\n", -- ptr->filename); -- continue; -- } -+ /* Perhaps we should also truncate the file before -+ * writing? */ -+ rewind(da_file); - - /* ??? Should first write a header to the file. Preferably, a 4 byte - magic number, 4 bytes containing the time the program was diff --git a/lsh/misc/make-dist b/lsh/misc/make-dist deleted file mode 100644 index 52d838d..0000000 --- a/lsh/misc/make-dist +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/sh - -# strip_rsa () { -# mv src/.dist_classes src/.dist_classes-old \ -# && grep -v '^rsa.c.x$' < src/.dist_classes-old > src/.dist_classes -# } - -# make && (cd src/testsuite && make check-more) && \ -# ./make_am --rethink && ./make_am && make && make distcheck - -make && \ - ./make_am --rethink && ./make_am && make && make distcheck diff --git a/lsh/missing b/lsh/missing deleted file mode 100755 index 116e570..0000000 Binary files a/lsh/missing and /dev/null differ diff --git a/lsh/mkinstalldirs b/lsh/mkinstalldirs deleted file mode 100755 index 6b3b5fc..0000000 --- a/lsh/mkinstalldirs +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -# $Id$ - -errstatus=0 - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# mkinstalldirs ends here diff --git a/lsh/src/.dist_classes b/lsh/src/.dist_classes deleted file mode 100755 index d099459..0000000 Binary files a/lsh/src/.dist_classes and /dev/null differ diff --git a/lsh/src/.dist_headers b/lsh/src/.dist_headers deleted file mode 100755 index 897a45c..0000000 Binary files a/lsh/src/.dist_headers and /dev/null differ diff --git a/lsh/src/Makefile.am b/lsh/src/Makefile.am deleted file mode 100755 index dc450fe..0000000 --- a/lsh/src/Makefile.am +++ /dev/null @@ -1,178 +0,0 @@ -## Automatically generated by make_am, Wed Aug 29 23:52:06 CEST 2001 -## Process this file with automake to produce Makefile.in - -SUBDIRS = argp rsync nettle scm sftp . testsuite -cvs_headers = .dist_headers abstract_compress.h abstract_crypto.h abstract_io.h algorithms.h alist.h atoms.h bignum.h channel.h channel_commands.h channel_forward.h charset.h client.h client_keyexchange.h client_userauth.h command.h compress.h connection.h connection_commands.h crypto.h daemon.h debug.h digits.h disconnect.h dsa.h encrypt.h exception.h format.h gateway.h gateway_channel.h gateway_commands.h gc.h handshake.h interact.h io.h io_commands.h keyexchange.h list.h lookup_verifier.h lsh.h lsh_argp.h lsh_types.h memxor.h pad.h parse.h parse_macros.h proxy.h proxy_agentforward.h proxy_session.h proxy_tcpforward.h proxy_userauth.h proxy_x11forward.h publickey_crypto.h queue.h randomness.h read_data.h read_file.h read_line.h read_packet.h reaper.h resource.h rsa.h server.h server_authorization.h server_keyexchange.h server_pty.h server_session.h server_userauth.h sexp.h sexp_commands.h spki.h spki_commands.h srp.h ssh.h ssh1_fallback.h string_buffer.h suspend.h tcpforward.h tcpforward_commands.h translate_signal.h tty.h unpad.h userauth.h version.h werror.h write_buffer.h xalloc.h xauth.h -dist_x_files = .dist_classes abstract_compress.h.x abstract_crypto.c.x abstract_crypto.h.x abstract_io.h.x algorithms.h.x alist.c.x alist.h.x arcfour.c.x blowfish.c.x cascade.c.x cast.c.x cbc.c.x channel.c.x channel.h.x channel_commands.c.x channel_commands.h.x channel_forward.h.x client.c.x client.h.x client_escape.c.x client_keyexchange.c.x client_pty.c.x client_session.c.x client_userauth.c.x client_x11.c.x combinators.c.x command.c.x command.h.x compress.c.x connection.c.x connection.h.x connection_commands.h.x debug.c.x des.c.x dsa.c.x encrypt.c.x exception.c.x exception.h.x gateway_channel.c.x gateway_channel.h.x gateway_commands.c.x handshake.c.x handshake.h.x hmac.c.x interact.h.x io.c.x io.h.x io_commands.c.x io_commands.h.x keyexchange.c.x keyexchange.h.x list.h.x lookup_verifier.h.x lsh-decode-key.c.x lsh-export-key.c.x lsh-keygen.c.x lsh-writekey.c.x lsh.c.x lsh_proxy.c.x lshd.c.x lshg.c.x md5.c.x pad.c.x proxy.c.x proxy_session.c.x proxy_userauth.c.x proxy_userauth.h.x publickey_crypto.c.x publickey_crypto.h.x queue.h.x randomness.c.x randomness.h.x read_base64.c.x read_data.c.x read_file.c.x read_line.c.x read_line.h.x read_packet.c.x reaper.c.x reaper.h.x resource.c.x resource.h.x rijndael.c.x rsa.c.x rsa.h.x serpent.c.x server.c.x server_authorization.c.x server_keyexchange.c.x server_password.c.x server_pty.h.x server_publickey.c.x server_session.c.x server_userauth.c.x server_userauth.h.x sexp-conv.c.x sexp.c.x sexp.h.x sexp_commands.c.x sexp_commands.h.x sha.c.x spki.c.x spki.h.x spki_commands.c.x srp-gen.c.x srp.h.x ssh1_fallback.c.x ssh1_fallback.h.x tcpforward.c.x tcpforward.h.x tcpforward_commands.c.x twofish.c.x unix_interact.c.x unix_random.c.x unix_user.c.x unpad.c.x userauth.h.x write_buffer.h.x zlib.c.x - -AUTOMAKE_OPTIONS = foreign - -# To remake all Makefile.am-files, run -# -# ./make_am -# -# You should run ./make_am --rethink after recompiling, but before -# making a dist, as it uses dependency information to figure out which -# header files should be included in th dist. How to tell this to -# make? FIXME: These rules won't remake Makefile.am files in -# subdrectries. - -# FIXME: Use the BASH variable to execute the script. The problem is -# that the script attempts to start itself with "$0 args". - -Makefile.am: Makefile.am.in - (cd $(top_srcdir) && $(MAKE) src/Makefile.am) - -SCHEME = $(SCHEME_PROGRAM) -l $(srcdir)/scm/$(SCHEME_NAME)-compat.scm - -EXTRA_PROGRAMS = lsh-krb-checkpw srp-gen - -bin_PROGRAMS = lsh lshg lsh-keygen lsh-writekey lsh-decode-key lsh-export-key sexp-conv @SRP_PROGRAM@ @KRB_PROGRAM@ -sbin_PROGRAMS = lshd lsh_proxy -bin_SCRIPTS = lsh-authorize ssh-conv -noinst_PROGRAMS = prime_table digit_table pkcs5-test -noinst_SCRIPTS = lcp -noinst_LIBRARIES = liblsh.a -# noinst_HEADERS = $(dist_x_files) $(cvs_headers) - -# Don't use BUILT_SOURCES, as all these files are #included, and can't be -# compiled or dependency checked independently. - -generated_sources = atoms_defines.h atoms_gperf.c atoms_table.c \ - prime_table.h sexp_table.h digit_table.h packet_types.h - -POTENTIAL_X_FILES = $(addsuffix .x,$(wildcard $(srcdir)/*.[ch])) - -.PHONY: bootstrap - -bootstrap: $(generated_sources) - # Not all potential .x files can be generated - -$(MAKE) -k $(POTENTIAL_X_FILES) - @rm -f $(addsuffix T,$(POTENTIAL_X_FILES)) - -liblsh_a_SOURCES = abstract_io.c abstract_crypto.c abstract_compress.c \ - algorithms.c alist.c arcfour.c atoms.c \ - bignum.c blowfish.c \ - cascade.c cast.c cbc.c channel.c channel_commands.c channel_forward.c \ - charset.c \ - client.c client_escape.c client_keyexchange.c \ - client_pty.c client_session.c client_userauth.c client_x11.c \ - combinators.c command.c compress.c connection.c connection_commands.c \ - daemon.c \ - debug.c des.c digits.c disconnect.c dh_exchange.c \ - dsa.c dsa_keygen.c encrypt.c \ - exception.c \ - format.c gc.c \ - gateway.c gateway_channel.c gateway_commands.c \ - handshake.c \ - hmac.c idea.c interact.c io.c io_commands.c \ - keyexchange.c \ - list.c lookup_verifier.c md5.c \ - pad.c parse.c \ - pkcs5.c \ - proxy.c proxy_agentforward.c proxy_session.c \ - proxy_tcpforward.c proxy_userauth.c proxy_x11forward.c \ - publickey_crypto.c queue.c \ - randomness.c \ - read_base64.c read_data.c read_file.c read_line.c read_packet.c \ - reaper.c resource.c \ - rijndael.c rsa.c rsa_keygen.c serpent.c \ - server.c server_authorization.c server_keyexchange.c \ - server_password.c server_publickey.c \ - server_pty.c server_session.c server_userauth.c \ - sexp.c sexp_commands.c sexp_parser.c \ - sha.c spki.c spki_commands.c srp_exchange.c ssh1_fallback.c \ - string_buffer.c suspend.c \ - tcpforward.c tcpforward_commands.c \ - translate_signal.c tty.c twofish.c \ - unix_interact.c unix_random.c unix_user.c \ - unpad.c userauth.c \ - werror.c write_buffer.c xalloc.c xauth.c zlib.c - -liblsh_a_LIBADD = @LIBOBJS@ - -atoms_defines.h: atoms.in process_atoms - $(BASH) $(srcdir)/process_atoms header <$< >$@T - test -s $@T && mv -f $@T $@ - -# With the next version of gperf, add -F ", 0" -GPERF_FLAGS = -LANSI-C -t -c -C -l -k1,3,6,10,$$ -N gperf_atom -atoms_gperf.c: atoms.in process_atoms - $(BASH) $(srcdir)/process_atoms gperf <$< \ - | gperf $(GPERF_FLAGS) | sed 's/{""}/{"", 0}/g' >$@T - test -s $@T && mv -f $@T $@ - -atoms_table.c: atoms.in process_atoms - $(BASH) $(srcdir)/process_atoms table <$< >$@T - test -s $@T && mv -f $@T $@ - -PRIME_LIMIT = 1024 - -prime_table.h: prime_table - ./prime_table $(PRIME_LIMIT) >$@T - test -s $@T && mv -f $@T $@ - -prime_table_LDADD = - -sexp_table.h: sexp_chars.in $(srcdir)/scm/make-char-classes.scm - $(SCHEME) -e main -s $(srcdir)/scm/make-char-classes.scm <$< >$@T - test -s $@T && mv -f $@T $@ - -digit_table_LDADD = - -digit_table.h: digit_table - ./digit_table >$@T - test -s $@T && mv -f $@T $@ - -packet_types.h: ssh.h invert-defs - $(srcdir)/invert-defs $@T - test -s $@T && mv -f $@T $@ - -lsh_krb_checkpw_LDADD=@KRB_LIBS@ - -# typedescr.h: ssh.h $(top_srcdir)/misc/mk-reverse-table -# $(PERL) $(top_srcdir)/misc/mk-reverse-table ssh.h >$@T -# if test -s $@T ; then mv -f $@T $@ ; else touch $@ ; fi - -LDADD = liblsh.a nettle/libnettle.a @LIBARGP@ -lshg_LDADD = liblsh.a @LIBARGP@ - -class-map: $(srcdir)/make-class-map $(dist_x_files) - cat $(dist_x_files) | grep '^CLASS:' \ - | sort | awk -f $(srcdir)/make-class-map > $@ - -# Is this rule needed? -# all-recursive check-recursive: config.h - -EXTRA_DIST = lsh-authorize ssh-conv lcp \ - atoms.in process_atoms \ - invert-defs \ - $(generated_sources) \ - sexp_chars.in \ - jpoll.h jpoll.c \ - $(cvs_headers) $(dist_x_files) Makefile.am.in - -CLEANFILES = *.hT *.cT *.xT -MAINTAINERCLEANFILES += $(dist_x_files) - -# Class files -# SUFFIXES = .xh .xc - -.PHONY: depend -depend: - rm -f $(DEP_FILES) - make $(DEP_FILES) - -MAINTAINERCLEANFILES += $(DEP_FILES) - -# This is GNU make specific - -%.x: % $(srcdir)/scm/gaba.scm $(srcdir)/scm/compiler.scm - $(SCHEME) -e main -l $(srcdir)/scm/compiler.scm \ - -s $(srcdir)/scm/gaba.scm <$< >$@T - test -s $@T && mv -f $@T $@ - -ETAGS_ARGS = -r '/ (name[ \t]+\([a-zA-Z0-9_]+\)/\1/' \ - -r '/DEFINE[^(]*(\([a-zA-Z0-9_]+\)/\1/' - -include $(top_srcdir)/misc/ctags.mk diff --git a/lsh/src/Makefile.am.in b/lsh/src/Makefile.am.in deleted file mode 100755 index 9d4620d..0000000 Binary files a/lsh/src/Makefile.am.in and /dev/null differ diff --git a/lsh/src/Makefile.in b/lsh/src/Makefile.in deleted file mode 100755 index 9ad900d..0000000 --- a/lsh/src/Makefile.in +++ /dev/null @@ -1,1640 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -# ctags support. Automake only supports etags. We base our ctags support on -# automake's etags support. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = .. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -SUBDIRS = argp rsync nettle scm sftp . testsuite -cvs_headers = .dist_headers abstract_compress.h abstract_crypto.h abstract_io.h algorithms.h alist.h atoms.h bignum.h channel.h channel_commands.h channel_forward.h charset.h client.h client_keyexchange.h client_userauth.h command.h compress.h connection.h connection_commands.h crypto.h daemon.h debug.h digits.h disconnect.h dsa.h encrypt.h exception.h format.h gateway.h gateway_channel.h gateway_commands.h gc.h handshake.h interact.h io.h io_commands.h keyexchange.h list.h lookup_verifier.h lsh.h lsh_argp.h lsh_types.h memxor.h pad.h parse.h parse_macros.h proxy.h proxy_agentforward.h proxy_session.h proxy_tcpforward.h proxy_userauth.h proxy_x11forward.h publickey_crypto.h queue.h randomness.h read_data.h read_file.h read_line.h read_packet.h reaper.h resource.h rsa.h server.h server_authorization.h server_keyexchange.h server_pty.h server_session.h server_userauth.h sexp.h sexp_commands.h spki.h spki_commands.h srp.h ssh.h ssh1_fallback.h string_buffer.h suspend.h tcpforward.h tcpforward_commands.h translate_signal.h tty.h unpad.h userauth.h version.h werror.h write_buffer.h xalloc.h xauth.h -dist_x_files = .dist_classes abstract_compress.h.x abstract_crypto.c.x abstract_crypto.h.x abstract_io.h.x algorithms.h.x alist.c.x alist.h.x arcfour.c.x blowfish.c.x cascade.c.x cast.c.x cbc.c.x channel.c.x channel.h.x channel_commands.c.x channel_commands.h.x channel_forward.h.x client.c.x client.h.x client_escape.c.x client_keyexchange.c.x client_pty.c.x client_session.c.x client_userauth.c.x client_x11.c.x combinators.c.x command.c.x command.h.x compress.c.x connection.c.x connection.h.x connection_commands.h.x debug.c.x des.c.x dsa.c.x encrypt.c.x exception.c.x exception.h.x gateway_channel.c.x gateway_channel.h.x gateway_commands.c.x handshake.c.x handshake.h.x hmac.c.x interact.h.x io.c.x io.h.x io_commands.c.x io_commands.h.x keyexchange.c.x keyexchange.h.x list.h.x lookup_verifier.h.x lsh-decode-key.c.x lsh-export-key.c.x lsh-keygen.c.x lsh-writekey.c.x lsh.c.x lsh_proxy.c.x lshd.c.x lshg.c.x md5.c.x pad.c.x proxy.c.x proxy_session.c.x proxy_userauth.c.x proxy_userauth.h.x publickey_crypto.c.x publickey_crypto.h.x queue.h.x randomness.c.x randomness.h.x read_base64.c.x read_data.c.x read_file.c.x read_line.c.x read_line.h.x read_packet.c.x reaper.c.x reaper.h.x resource.c.x resource.h.x rijndael.c.x rsa.c.x rsa.h.x serpent.c.x server.c.x server_authorization.c.x server_keyexchange.c.x server_password.c.x server_pty.h.x server_publickey.c.x server_session.c.x server_userauth.c.x server_userauth.h.x sexp-conv.c.x sexp.c.x sexp.h.x sexp_commands.c.x sexp_commands.h.x sha.c.x spki.c.x spki.h.x spki_commands.c.x srp-gen.c.x srp.h.x ssh1_fallback.c.x ssh1_fallback.h.x tcpforward.c.x tcpforward.h.x tcpforward_commands.c.x twofish.c.x unix_interact.c.x unix_random.c.x unix_user.c.x unpad.c.x userauth.h.x write_buffer.h.x zlib.c.x - -AUTOMAKE_OPTIONS = foreign - -SCHEME = $(SCHEME_PROGRAM) -l $(srcdir)/scm/$(SCHEME_NAME)-compat.scm - -EXTRA_PROGRAMS = lsh-krb-checkpw srp-gen - -bin_PROGRAMS = lsh lshg lsh-keygen lsh-writekey lsh-decode-key lsh-export-key sexp-conv @SRP_PROGRAM@ @KRB_PROGRAM@ -sbin_PROGRAMS = lshd lsh_proxy -bin_SCRIPTS = lsh-authorize ssh-conv -noinst_PROGRAMS = prime_table digit_table pkcs5-test -noinst_SCRIPTS = lcp -noinst_LIBRARIES = liblsh.a -# noinst_HEADERS = $(dist_x_files) $(cvs_headers) - -# Don't use BUILT_SOURCES, as all these files are #included, and can't be -# compiled or dependency checked independently. - -generated_sources = atoms_defines.h atoms_gperf.c atoms_table.c prime_table.h sexp_table.h digit_table.h packet_types.h - - -POTENTIAL_X_FILES = $(addsuffix .x,$(wildcard $(srcdir)/*.[ch])) - -liblsh_a_SOURCES = abstract_io.c abstract_crypto.c abstract_compress.c algorithms.c alist.c arcfour.c atoms.c bignum.c blowfish.c cascade.c cast.c cbc.c channel.c channel_commands.c channel_forward.c charset.c client.c client_escape.c client_keyexchange.c client_pty.c client_session.c client_userauth.c client_x11.c combinators.c command.c compress.c connection.c connection_commands.c daemon.c debug.c des.c digits.c disconnect.c dh_exchange.c dsa.c dsa_keygen.c encrypt.c exception.c format.c gc.c gateway.c gateway_channel.c gateway_commands.c handshake.c hmac.c idea.c interact.c io.c io_commands.c keyexchange.c list.c lookup_verifier.c md5.c pad.c parse.c pkcs5.c proxy.c proxy_agentforward.c proxy_session.c proxy_tcpforward.c proxy_userauth.c proxy_x11forward.c publickey_crypto.c queue.c randomness.c read_base64.c read_data.c read_file.c read_line.c read_packet.c reaper.c resource.c rijndael.c rsa.c rsa_keygen.c serpent.c server.c server_authorization.c server_keyexchange.c server_password.c server_publickey.c server_pty.c server_session.c server_userauth.c sexp.c sexp_commands.c sexp_parser.c sha.c spki.c spki_commands.c srp_exchange.c ssh1_fallback.c string_buffer.c suspend.c tcpforward.c tcpforward_commands.c translate_signal.c tty.c twofish.c unix_interact.c unix_random.c unix_user.c unpad.c userauth.c werror.c write_buffer.c xalloc.c xauth.c zlib.c - - -liblsh_a_LIBADD = @LIBOBJS@ - -# With the next version of gperf, add -F ", 0" -GPERF_FLAGS = -LANSI-C -t -c -C -l -k1,3,6,10,$$ -N gperf_atom - -PRIME_LIMIT = 1024 - -prime_table_LDADD = - -digit_table_LDADD = - -lsh_krb_checkpw_LDADD = @KRB_LIBS@ - -# typedescr.h: ssh.h $(top_srcdir)/misc/mk-reverse-table -# $(PERL) $(top_srcdir)/misc/mk-reverse-table ssh.h >$@T -# if test -s $@T ; then mv -f $@T $@ ; else touch $@ ; fi - -LDADD = liblsh.a nettle/libnettle.a @LIBARGP@ -lshg_LDADD = liblsh.a @LIBARGP@ - -# Is this rule needed? -# all-recursive check-recursive: config.h - -EXTRA_DIST = lsh-authorize ssh-conv lcp atoms.in process_atoms invert-defs $(generated_sources) sexp_chars.in jpoll.h jpoll.c $(cvs_headers) $(dist_x_files) Makefile.am.in - - -CLEANFILES = *.hT *.cT *.xT - -MAINTAINERCLEANFILES = $(dist_x_files) $(DEP_FILES) - -ETAGS_ARGS = -r '/ (name[ \t]+\([a-zA-Z0-9_]+\)/\1/' -r '/DEFINE[^(]*(\([a-zA-Z0-9_]+\)/\1/' - -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../config.h -CONFIG_CLEAN_FILES = -LIBRARIES = $(noinst_LIBRARIES) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I.. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -liblsh_a_DEPENDENCIES = @LIBOBJS@ -liblsh_a_OBJECTS = abstract_io.o abstract_crypto.o abstract_compress.o \ -algorithms.o alist.o arcfour.o atoms.o bignum.o blowfish.o cascade.o \ -cast.o cbc.o channel.o channel_commands.o channel_forward.o charset.o \ -client.o client_escape.o client_keyexchange.o client_pty.o \ -client_session.o client_userauth.o client_x11.o combinators.o command.o \ -compress.o connection.o connection_commands.o daemon.o debug.o des.o \ -digits.o disconnect.o dh_exchange.o dsa.o dsa_keygen.o encrypt.o \ -exception.o format.o gc.o gateway.o gateway_channel.o \ -gateway_commands.o handshake.o hmac.o idea.o interact.o io.o \ -io_commands.o keyexchange.o list.o lookup_verifier.o md5.o pad.o \ -parse.o pkcs5.o proxy.o proxy_agentforward.o proxy_session.o \ -proxy_tcpforward.o proxy_userauth.o proxy_x11forward.o \ -publickey_crypto.o queue.o randomness.o read_base64.o read_data.o \ -read_file.o read_line.o read_packet.o reaper.o resource.o rijndael.o \ -rsa.o rsa_keygen.o serpent.o server.o server_authorization.o \ -server_keyexchange.o server_password.o server_publickey.o server_pty.o \ -server_session.o server_userauth.o sexp.o sexp_commands.o sexp_parser.o \ -sha.o spki.o spki_commands.o srp_exchange.o ssh1_fallback.o \ -string_buffer.o suspend.o tcpforward.o tcpforward_commands.o \ -translate_signal.o tty.o twofish.o unix_interact.o unix_random.o \ -unix_user.o unpad.o userauth.o werror.o write_buffer.o xalloc.o xauth.o \ -zlib.o -AR = ar -PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS) $(sbin_PROGRAMS) - -lsh_krb_checkpw_SOURCES = lsh-krb-checkpw.c -lsh_krb_checkpw_OBJECTS = lsh-krb-checkpw.o -lsh_krb_checkpw_DEPENDENCIES = -lsh_krb_checkpw_LDFLAGS = -srp_gen_SOURCES = srp-gen.c -srp_gen_OBJECTS = srp-gen.o -srp_gen_LDADD = $(LDADD) -srp_gen_DEPENDENCIES = liblsh.a nettle/libnettle.a -srp_gen_LDFLAGS = -lsh_SOURCES = lsh.c -lsh_OBJECTS = lsh.o -lsh_LDADD = $(LDADD) -lsh_DEPENDENCIES = liblsh.a nettle/libnettle.a -lsh_LDFLAGS = -lshg_SOURCES = lshg.c -lshg_OBJECTS = lshg.o -lshg_DEPENDENCIES = liblsh.a -lshg_LDFLAGS = -lsh_keygen_SOURCES = lsh-keygen.c -lsh_keygen_OBJECTS = lsh-keygen.o -lsh_keygen_LDADD = $(LDADD) -lsh_keygen_DEPENDENCIES = liblsh.a nettle/libnettle.a -lsh_keygen_LDFLAGS = -lsh_writekey_SOURCES = lsh-writekey.c -lsh_writekey_OBJECTS = lsh-writekey.o -lsh_writekey_LDADD = $(LDADD) -lsh_writekey_DEPENDENCIES = liblsh.a nettle/libnettle.a -lsh_writekey_LDFLAGS = -lsh_decode_key_SOURCES = lsh-decode-key.c -lsh_decode_key_OBJECTS = lsh-decode-key.o -lsh_decode_key_LDADD = $(LDADD) -lsh_decode_key_DEPENDENCIES = liblsh.a nettle/libnettle.a -lsh_decode_key_LDFLAGS = -lsh_export_key_SOURCES = lsh-export-key.c -lsh_export_key_OBJECTS = lsh-export-key.o -lsh_export_key_LDADD = $(LDADD) -lsh_export_key_DEPENDENCIES = liblsh.a nettle/libnettle.a -lsh_export_key_LDFLAGS = -sexp_conv_SOURCES = sexp-conv.c -sexp_conv_OBJECTS = sexp-conv.o -sexp_conv_LDADD = $(LDADD) -sexp_conv_DEPENDENCIES = liblsh.a nettle/libnettle.a -sexp_conv_LDFLAGS = -prime_table_SOURCES = prime_table.c -prime_table_OBJECTS = prime_table.o -prime_table_DEPENDENCIES = -prime_table_LDFLAGS = -digit_table_SOURCES = digit_table.c -digit_table_OBJECTS = digit_table.o -digit_table_DEPENDENCIES = -digit_table_LDFLAGS = -pkcs5_test_SOURCES = pkcs5-test.c -pkcs5_test_OBJECTS = pkcs5-test.o -pkcs5_test_LDADD = $(LDADD) -pkcs5_test_DEPENDENCIES = liblsh.a nettle/libnettle.a -pkcs5_test_LDFLAGS = -lshd_SOURCES = lshd.c -lshd_OBJECTS = lshd.o -lshd_LDADD = $(LDADD) -lshd_DEPENDENCIES = liblsh.a nettle/libnettle.a -lshd_LDFLAGS = -lsh_proxy_SOURCES = lsh_proxy.c -lsh_proxy_OBJECTS = lsh_proxy.o -lsh_proxy_LDADD = $(LDADD) -lsh_proxy_DEPENDENCIES = liblsh.a nettle/libnettle.a -lsh_proxy_LDFLAGS = -SCRIPTS = $(bin_SCRIPTS) $(noinst_SCRIPTS) - -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = Makefile.am Makefile.in jpoll.c memcmp.c memxor.c - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = $(liblsh_a_SOURCES) lsh-krb-checkpw.c srp-gen.c lsh.c lshg.c lsh-keygen.c lsh-writekey.c lsh-decode-key.c lsh-export-key.c sexp-conv.c prime_table.c digit_table.c pkcs5-test.c lshd.c lsh_proxy.c -OBJECTS = $(liblsh_a_OBJECTS) lsh-krb-checkpw.o srp-gen.o lsh.o lshg.o lsh-keygen.o lsh-writekey.o lsh-decode-key.o lsh-export-key.o sexp-conv.o prime_table.o digit_table.o pkcs5-test.o lshd.o lsh_proxy.o - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) $(top_srcdir)/misc/ctags.mk - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps src/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - - -mostlyclean-noinstLIBRARIES: - -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) - -distclean-noinstLIBRARIES: - -maintainer-clean-noinstLIBRARIES: - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -liblsh.a: $(liblsh_a_OBJECTS) $(liblsh_a_DEPENDENCIES) - -rm -f liblsh.a - $(AR) cru liblsh.a $(liblsh_a_OBJECTS) $(liblsh_a_LIBADD) - $(RANLIB) liblsh.a - -mostlyclean-binPROGRAMS: - -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) - -distclean-binPROGRAMS: - -maintainer-clean-binPROGRAMS: - -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ - $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - else :; fi; \ - done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - list='$(bin_PROGRAMS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - done - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -mostlyclean-sbinPROGRAMS: - -clean-sbinPROGRAMS: - -test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS) - -distclean-sbinPROGRAMS: - -maintainer-clean-sbinPROGRAMS: - -install-sbinPROGRAMS: $(sbin_PROGRAMS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(sbindir) - @list='$(sbin_PROGRAMS)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ - $(INSTALL_PROGRAM) $$p $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - else :; fi; \ - done - -uninstall-sbinPROGRAMS: - @$(NORMAL_UNINSTALL) - list='$(sbin_PROGRAMS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - done - -lsh-krb-checkpw: $(lsh_krb_checkpw_OBJECTS) $(lsh_krb_checkpw_DEPENDENCIES) - @rm -f lsh-krb-checkpw - $(LINK) $(lsh_krb_checkpw_LDFLAGS) $(lsh_krb_checkpw_OBJECTS) $(lsh_krb_checkpw_LDADD) $(LIBS) - -srp-gen: $(srp_gen_OBJECTS) $(srp_gen_DEPENDENCIES) - @rm -f srp-gen - $(LINK) $(srp_gen_LDFLAGS) $(srp_gen_OBJECTS) $(srp_gen_LDADD) $(LIBS) - -lsh: $(lsh_OBJECTS) $(lsh_DEPENDENCIES) - @rm -f lsh - $(LINK) $(lsh_LDFLAGS) $(lsh_OBJECTS) $(lsh_LDADD) $(LIBS) - -lshg: $(lshg_OBJECTS) $(lshg_DEPENDENCIES) - @rm -f lshg - $(LINK) $(lshg_LDFLAGS) $(lshg_OBJECTS) $(lshg_LDADD) $(LIBS) - -lsh-keygen: $(lsh_keygen_OBJECTS) $(lsh_keygen_DEPENDENCIES) - @rm -f lsh-keygen - $(LINK) $(lsh_keygen_LDFLAGS) $(lsh_keygen_OBJECTS) $(lsh_keygen_LDADD) $(LIBS) - -lsh-writekey: $(lsh_writekey_OBJECTS) $(lsh_writekey_DEPENDENCIES) - @rm -f lsh-writekey - $(LINK) $(lsh_writekey_LDFLAGS) $(lsh_writekey_OBJECTS) $(lsh_writekey_LDADD) $(LIBS) - -lsh-decode-key: $(lsh_decode_key_OBJECTS) $(lsh_decode_key_DEPENDENCIES) - @rm -f lsh-decode-key - $(LINK) $(lsh_decode_key_LDFLAGS) $(lsh_decode_key_OBJECTS) $(lsh_decode_key_LDADD) $(LIBS) - -lsh-export-key: $(lsh_export_key_OBJECTS) $(lsh_export_key_DEPENDENCIES) - @rm -f lsh-export-key - $(LINK) $(lsh_export_key_LDFLAGS) $(lsh_export_key_OBJECTS) $(lsh_export_key_LDADD) $(LIBS) - -sexp-conv: $(sexp_conv_OBJECTS) $(sexp_conv_DEPENDENCIES) - @rm -f sexp-conv - $(LINK) $(sexp_conv_LDFLAGS) $(sexp_conv_OBJECTS) $(sexp_conv_LDADD) $(LIBS) - -prime_table: $(prime_table_OBJECTS) $(prime_table_DEPENDENCIES) - @rm -f prime_table - $(LINK) $(prime_table_LDFLAGS) $(prime_table_OBJECTS) $(prime_table_LDADD) $(LIBS) - -digit_table: $(digit_table_OBJECTS) $(digit_table_DEPENDENCIES) - @rm -f digit_table - $(LINK) $(digit_table_LDFLAGS) $(digit_table_OBJECTS) $(digit_table_LDADD) $(LIBS) - -pkcs5-test: $(pkcs5_test_OBJECTS) $(pkcs5_test_DEPENDENCIES) - @rm -f pkcs5-test - $(LINK) $(pkcs5_test_LDFLAGS) $(pkcs5_test_OBJECTS) $(pkcs5_test_LDADD) $(LIBS) - -lshd: $(lshd_OBJECTS) $(lshd_DEPENDENCIES) - @rm -f lshd - $(LINK) $(lshd_LDFLAGS) $(lshd_OBJECTS) $(lshd_LDADD) $(LIBS) - -lsh_proxy: $(lsh_proxy_OBJECTS) $(lsh_proxy_DEPENDENCIES) - @rm -f lsh_proxy - $(LINK) $(lsh_proxy_LDFLAGS) $(lsh_proxy_OBJECTS) $(lsh_proxy_LDADD) $(LIBS) - -install-binSCRIPTS: $(bin_SCRIPTS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) - @list='$(bin_SCRIPTS)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_SCRIPT) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`"; \ - $(INSTALL_SCRIPT) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ - else if test -f $(srcdir)/$$p; then \ - echo " $(INSTALL_SCRIPT) $(srcdir)/$$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`"; \ - $(INSTALL_SCRIPT) $(srcdir)/$$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ - else :; fi; fi; \ - done - -uninstall-binSCRIPTS: - @$(NORMAL_UNINSTALL) - list='$(bin_SCRIPTS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ - done - -# This directory's subdirectories are mostly independent; you can cd -# into them and run `make' without going through this Makefile. -# To change the values of `make' variables: instead of editing Makefiles, -# (1) if the variable is set in `config.status', edit `config.status' -# (which will cause the Makefiles to be regenerated when you run `make'); -# (2) otherwise, pass the desired values on the `make' command line. - -@SET_MAKE@ - -all-recursive install-data-recursive install-exec-recursive \ -installdirs-recursive install-recursive uninstall-recursive \ -check-recursive installcheck-recursive info-recursive dvi-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -mostlyclean-recursive clean-recursive distclean-recursive \ -maintainer-clean-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ - rev="$$subdir $$rev"; \ - test "$$subdir" = "." && dot_seen=yes; \ - done; \ - test "$$dot_seen" = "no" && rev=". $$rev"; \ - target=`echo $@ | sed s/-recursive//`; \ - for subdir in $$rev; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done && test -z "$$fail" -tags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ - done - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \ - fi; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -maintainer-clean-tags: - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = src - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - for subdir in $(SUBDIRS); do \ - if test "$$subdir" = .; then :; else \ - test -d $(distdir)/$$subdir \ - || mkdir $(distdir)/$$subdir \ - || exit 1; \ - chmod 777 $(distdir)/$$subdir; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \ - || exit 1; \ - fi; \ - done -abstract_compress.o: abstract_compress.c abstract_compress.h lsh.h \ - lsh_types.h ../config.h abstract_compress.h.x -abstract_crypto.o: abstract_crypto.c abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x crypto.h \ - format.h atoms.h atoms_defines.h bignum.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h abstract_crypto.c.x -abstract_io.o: abstract_io.c abstract_io.h exception.h lsh.h lsh_types.h \ - ../config.h exception.h.x abstract_io.h.x -algorithms.o: algorithms.c algorithms.h abstract_compress.h lsh.h \ - lsh_types.h ../config.h abstract_compress.h.x alist.h alist.h.x \ - lsh_argp.h argp/argp.h randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x exception.h exception.h.x \ - randomness.h.x algorithms.h.x atoms.h atoms_defines.h \ - compress.h abstract_io.h abstract_io.h.x connection.h queue.h \ - queue.h.x resource.h resource.h.x connection.h.x crypto.h dsa.h \ - bignum.h publickey_crypto.h parse.h publickey_crypto.h.x rsa.h \ - rsa.h.x xalloc.h gc.h -alist.o: alist.c alist.h lsh.h lsh_types.h ../config.h alist.h.x atoms.h \ - atoms_defines.h list.h list.h.x werror.h bignum.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h alist.c.x -arcfour.o: arcfour.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h nettle/arcfour.h \ - arcfour.c.x -atoms.o: atoms.c atoms.h lsh_types.h ../config.h atoms_defines.h \ - atoms_gperf.c atoms_table.c -bignum.o: bignum.c bignum.h lsh.h lsh_types.h ../config.h randomness.h \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - exception.h exception.h.x randomness.h.x werror.h lsh_argp.h \ - argp/argp.h prime_table.h -blowfish.o: blowfish.c crypto.h abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x werror.h \ - bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h nettle/blowfish.h \ - blowfish.c.x -cascade.o: cascade.c abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h cascade.c.x -cast.o: cast.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h nettle/cast128.h cast.c.x -cbc.o: cbc.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h cbc.c.x nettle/memxor.h -channel.o: channel.c channel.h alist.h lsh.h lsh_types.h ../config.h \ - alist.h.x command.h exception.h exception.h.x list.h list.h.x \ - command.h.x connection.h abstract_io.h abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h \ - abstract_crypto.h.x randomness.h.x connection.h.x parse.h \ - atoms.h atoms_defines.h bignum.h server_pty.h server_pty.h.x \ - write_buffer.h write_buffer.h.x channel.h.x format.h io.h \ - io.h.x read_data.h ssh.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h channel.c.x -channel_commands.o: channel_commands.c channel_commands.h channel.h \ - alist.h lsh.h lsh_types.h ../config.h alist.h.x command.h \ - exception.h exception.h.x list.h list.h.x command.h.x \ - connection.h abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x ssh.h \ - werror.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - channel_commands.c.x -channel_forward.o: channel_forward.c channel_forward.h channel.h alist.h \ - lsh.h lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_forward.h.x io.h io.h.x \ - ssh.h werror.h lsh_argp.h argp/argp.h xalloc.h gc.h -charset.o: charset.c charset.h lsh_types.h ../config.h format.h atoms.h \ - atoms_defines.h bignum.h lsh.h parse.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h -client.o: client.c client.h channel_commands.h channel.h alist.h lsh.h \ - lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x format.h interact.h \ - interact.h.x pad.h ssh.h suspend.h tcpforward_commands.h \ - tcpforward.h xalloc.h gc.h tcpforward.h.x translate_signal.h \ - werror.h lsh_argp.h argp/argp.h client.c.x -client_escape.o: client_escape.c client.h channel_commands.h channel.h \ - alist.h lsh.h lsh_types.h ../config.h alist.h.x command.h \ - exception.h exception.h.x list.h list.h.x command.h.x \ - connection.h abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x format.h werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h client_escape.c.x -client_keyexchange.o: client_keyexchange.c client_keyexchange.h \ - interact.h lsh.h lsh_types.h ../config.h interact.h.x \ - keyexchange.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x abstract_compress.h abstract_compress.h.x \ - alist.h alist.h.x bignum.h connection.h abstract_io.h \ - exception.h exception.h.x abstract_io.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h randomness.h.x \ - connection.h.x keyexchange.h.x publickey_crypto.h parse.h \ - atoms.h atoms_defines.h publickey_crypto.h.x command.h \ - command.h.x debug.h dsa.h format.h lookup_verifier.h \ - lookup_verifier.h.x srp.h srp.h.x ssh.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h client_keyexchange.c.x -client_pty.o: client_pty.c client.h channel_commands.h channel.h alist.h \ - lsh.h lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x format.h interact.h \ - interact.h.x tty.h werror.h lsh_argp.h argp/argp.h xalloc.h \ - gc.h client_pty.c.x -client_session.o: client_session.c client.h channel_commands.h channel.h \ - alist.h lsh.h lsh_types.h ../config.h alist.h.x command.h \ - exception.h exception.h.x list.h list.h.x command.h.x \ - connection.h abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x read_data.h ssh.h \ - werror.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - client_session.c.x -client_userauth.o: client_userauth.c client_userauth.h alist.h lsh.h \ - lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x interact.h interact.h.x parse.h \ - atoms.h atoms_defines.h bignum.h userauth.h userauth.h.x \ - charset.h format.h publickey_crypto.h publickey_crypto.h.x \ - ssh.h werror.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - client_userauth.c.x -client_x11.o: client_x11.c client.h channel_commands.h channel.h alist.h \ - lsh.h lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x channel_forward.h \ - channel_forward.h.x format.h ssh.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h xauth.h client_x11.c.x -combinators.o: combinators.c command.h lsh.h lsh_types.h ../config.h \ - exception.h exception.h.x list.h list.h.x command.h.x werror.h \ - bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h combinators.c.x -command.o: command.c command.h lsh.h lsh_types.h ../config.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x io.h write_buffer.h \ - write_buffer.h.x io.h.x werror.h bignum.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h command.c.x -compress.o: compress.c compress.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x connection.h queue.h \ - queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - randomness.h.x connection.h.x ssh.h xalloc.h gc.h compress.c.x -connection.o: connection.c connection.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x randomness.h.x connection.h.x \ - compress.h debug.h disconnect.h encrypt.h format.h atoms.h \ - atoms_defines.h bignum.h io.h command.h command.h.x \ - write_buffer.h write_buffer.h.x io.h.x keyexchange.h alist.h \ - alist.h.x keyexchange.h.x pad.h ssh.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h connection.c.x packet_types.h -connection_commands.o: connection_commands.c connection_commands.h \ - command.h lsh.h lsh_types.h ../config.h exception.h \ - exception.h.x list.h list.h.x command.h.x \ - connection_commands.h.x connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x ssh.h werror.h bignum.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h -daemon.o: daemon.c daemon.h lsh.h lsh_types.h ../config.h format.h \ - atoms.h atoms_defines.h bignum.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h -debug.o: debug.c debug.h abstract_io.h exception.h lsh.h lsh_types.h \ - ../config.h exception.h.x abstract_io.h.x connection.h \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x randomness.h.x connection.h.x \ - format.h atoms.h atoms_defines.h bignum.h parse.h ssh.h \ - xalloc.h gc.h werror.h lsh_argp.h argp/argp.h debug.c.x -des.o: des.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h nettle/des.h des.c.x -dh_exchange.o: dh_exchange.c publickey_crypto.h abstract_crypto.h list.h \ - lsh.h lsh_types.h ../config.h list.h.x abstract_crypto.h.x \ - parse.h atoms.h atoms_defines.h bignum.h publickey_crypto.h.x \ - connection.h abstract_io.h exception.h exception.h.x \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - randomness.h.x connection.h.x crypto.h format.h ssh.h werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h -digit_table.o: digit_table.c sexp_table.h lsh_types.h ../config.h -digits.o: digits.c digits.h lsh_types.h ../config.h digit_table.h \ - werror.h bignum.h lsh.h lsh_argp.h argp/argp.h xalloc.h gc.h -disconnect.o: disconnect.c disconnect.h lsh_types.h ../config.h \ - connection.h abstract_io.h exception.h lsh.h exception.h.x \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - randomness.h.x connection.h.x format.h atoms.h atoms_defines.h \ - bignum.h parse.h ssh.h werror.h lsh_argp.h argp/argp.h xalloc.h \ - gc.h -dsa.o: dsa.c dsa.h bignum.h lsh.h lsh_types.h ../config.h \ - publickey_crypto.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x crypto.h format.h sexp.h command.h \ - exception.h exception.h.x command.h.x lsh_argp.h argp/argp.h \ - sexp_table.h sexp.h.x spki.h alist.h alist.h.x spki.h.x ssh.h \ - werror.h xalloc.h gc.h nettle/sha1.h dsa.c.x -dsa_keygen.o: dsa_keygen.c dsa.h bignum.h lsh.h lsh_types.h ../config.h \ - publickey_crypto.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x randomness.h exception.h exception.h.x \ - randomness.h.x sexp.h command.h command.h.x lsh_argp.h \ - argp/argp.h sexp_table.h sexp.h.x werror.h nettle/sha1.h \ - nettle/memxor.h -encrypt.o: encrypt.c encrypt.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - connection.h abstract_compress.h abstract_compress.h.x queue.h \ - queue.h.x resource.h resource.h.x randomness.h randomness.h.x \ - connection.h.x format.h atoms.h atoms_defines.h bignum.h \ - xalloc.h gc.h encrypt.c.x -exception.o: exception.c exception.h lsh.h lsh_types.h ../config.h \ - exception.h.x io.h abstract_io.h abstract_io.h.x command.h \ - list.h list.h.x command.h.x resource.h resource.h.x \ - write_buffer.h queue.h queue.h.x write_buffer.h.x io.h.x ssh.h \ - werror.h bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - exception.c.x -format.o: format.c format.h atoms.h lsh_types.h ../config.h \ - atoms_defines.h bignum.h lsh.h list.h list.h.x werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h -gateway.o: gateway.c gateway.h lsh.h lsh_types.h ../config.h format.h \ - atoms.h atoms_defines.h bignum.h io.h abstract_io.h exception.h \ - exception.h.x abstract_io.h.x command.h list.h list.h.x \ - command.h.x resource.h resource.h.x write_buffer.h queue.h \ - queue.h.x write_buffer.h.x io.h.x -gateway_channel.o: gateway_channel.c gateway_channel.h channel.h alist.h \ - lsh.h lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x gateway_channel.h.x \ - channel_commands.h channel_commands.h.x format.h ssh.h werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h gateway_channel.c.x -gateway_commands.o: gateway_commands.c gateway_commands.h command.h \ - lsh.h lsh_types.h ../config.h exception.h exception.h.x list.h \ - list.h.x command.h.x channel.h alist.h alist.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x connection_commands.h \ - connection_commands.h.x debug.h format.h gateway_channel.h \ - gateway_channel.h.x io_commands.h io.h io.h.x io_commands.h.x \ - read_packet.h ssh.h unpad.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h gateway_commands.c.x -gc.o: gc.c gc.h lsh.h lsh_types.h ../config.h werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h -handshake.o: handshake.c handshake.h alist.h lsh.h lsh_types.h \ - ../config.h alist.h.x command.h exception.h exception.h.x \ - list.h list.h.x command.h.x ssh1_fallback.h ssh1_fallback.h.x \ - handshake.h.x compress.h abstract_io.h abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x connection.h queue.h \ - queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x debug.h format.h atoms.h atoms_defines.h \ - bignum.h io.h write_buffer.h write_buffer.h.x io.h.x \ - keyexchange.h keyexchange.h.x read_line.h read_line.h.x \ - read_packet.h ssh.h unpad.h version.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h handshake.c.x -hmac.o: hmac.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x xalloc.h gc.h hmac.c.x \ - nettle/memxor.h -idea.o: idea.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h -interact.o: interact.c interact.h lsh.h lsh_types.h ../config.h \ - interact.h.x io.h abstract_io.h exception.h exception.h.x \ - abstract_io.h.x command.h list.h list.h.x command.h.x \ - resource.h resource.h.x write_buffer.h queue.h queue.h.x \ - write_buffer.h.x io.h.x werror.h bignum.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h -io.o: io.c io.h abstract_io.h exception.h lsh.h lsh_types.h ../config.h \ - exception.h.x abstract_io.h.x command.h list.h list.h.x \ - command.h.x resource.h resource.h.x write_buffer.h queue.h \ - queue.h.x write_buffer.h.x io.h.x format.h atoms.h \ - atoms_defines.h bignum.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h io.c.x -io_commands.o: io_commands.c io_commands.h command.h lsh.h lsh_types.h \ - ../config.h exception.h exception.h.x list.h list.h.x \ - command.h.x connection.h abstract_io.h abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h \ - abstract_crypto.h.x randomness.h.x connection.h.x io.h \ - write_buffer.h write_buffer.h.x io.h.x io_commands.h.x werror.h \ - bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h io_commands.c.x -keyexchange.o: keyexchange.c keyexchange.h abstract_crypto.h list.h \ - lsh.h lsh_types.h ../config.h list.h.x abstract_crypto.h.x \ - abstract_compress.h abstract_compress.h.x alist.h alist.h.x \ - bignum.h connection.h abstract_io.h exception.h exception.h.x \ - abstract_io.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h randomness.h.x connection.h.x keyexchange.h.x \ - algorithms.h lsh_argp.h argp/argp.h algorithms.h.x command.h \ - command.h.x debug.h disconnect.h format.h atoms.h \ - atoms_defines.h parse.h publickey_crypto.h publickey_crypto.h.x \ - ssh.h werror.h xalloc.h gc.h keyexchange.c.x -list.o: list.c list.h lsh.h lsh_types.h ../config.h list.h.x xalloc.h \ - gc.h -lookup_verifier.o: lookup_verifier.c lookup_verifier.h lsh.h lsh_types.h \ - ../config.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x lookup_verifier.h.x -lsh-decode-key.o: lsh-decode-key.c dsa.h bignum.h lsh.h lsh_types.h \ - ../config.h publickey_crypto.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x io.h abstract_io.h exception.h \ - exception.h.x abstract_io.h.x command.h command.h.x resource.h \ - resource.h.x write_buffer.h queue.h queue.h.x write_buffer.h.x \ - io.h.x lsh_argp.h argp/argp.h read_file.h rsa.h rsa.h.x \ - sexp_commands.h sexp.h sexp_table.h sexp.h.x sexp_commands.h.x \ - spki.h alist.h alist.h.x spki.h.x version.h werror.h xalloc.h \ - gc.h lsh-decode-key.c.x -lsh-export-key.o: lsh-export-key.c algorithms.h abstract_compress.h \ - lsh.h lsh_types.h ../config.h abstract_compress.h.x alist.h \ - alist.h.x lsh_argp.h argp/argp.h randomness.h abstract_crypto.h \ - list.h list.h.x abstract_crypto.h.x exception.h exception.h.x \ - randomness.h.x algorithms.h.x atoms.h atoms_defines.h crypto.h \ - format.h bignum.h io.h abstract_io.h abstract_io.h.x command.h \ - command.h.x resource.h resource.h.x write_buffer.h queue.h \ - queue.h.x write_buffer.h.x io.h.x sexp_commands.h sexp.h \ - parse.h sexp_table.h sexp.h.x sexp_commands.h.x spki.h dsa.h \ - publickey_crypto.h publickey_crypto.h.x spki.h.x version.h \ - werror.h xalloc.h gc.h lsh-export-key.c.x -lsh-keygen.o: lsh-keygen.c crypto.h abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x dsa.h \ - bignum.h publickey_crypto.h parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x format.h io.h abstract_io.h exception.h \ - exception.h.x abstract_io.h.x command.h command.h.x resource.h \ - resource.h.x write_buffer.h queue.h queue.h.x write_buffer.h.x \ - io.h.x randomness.h randomness.h.x rsa.h rsa.h.x sexp.h \ - lsh_argp.h argp/argp.h sexp_table.h sexp.h.x version.h werror.h \ - xalloc.h gc.h lsh-keygen.c.x -lsh-writekey.o: lsh-writekey.c algorithms.h abstract_compress.h lsh.h \ - lsh_types.h ../config.h abstract_compress.h.x alist.h alist.h.x \ - lsh_argp.h argp/argp.h randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x exception.h exception.h.x \ - randomness.h.x algorithms.h.x crypto.h dsa.h bignum.h \ - publickey_crypto.h parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x format.h io_commands.h command.h \ - command.h.x connection.h abstract_io.h abstract_io.h.x queue.h \ - queue.h.x resource.h resource.h.x connection.h.x io.h \ - write_buffer.h write_buffer.h.x io.h.x io_commands.h.x \ - interact.h interact.h.x rsa.h rsa.h.x sexp_commands.h sexp.h \ - sexp_table.h sexp.h.x sexp_commands.h.x spki_commands.h spki.h \ - spki.h.x version.h werror.h xalloc.h gc.h lsh-writekey.c.x -lsh.o: lsh.c algorithms.h abstract_compress.h lsh.h lsh_types.h \ - ../config.h abstract_compress.h.x alist.h alist.h.x lsh_argp.h \ - argp/argp.h randomness.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x exception.h exception.h.x randomness.h.x \ - algorithms.h.x atoms.h atoms_defines.h channel.h command.h \ - command.h.x connection.h abstract_io.h abstract_io.h.x queue.h \ - queue.h.x resource.h resource.h.x connection.h.x parse.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x charset.h client.h \ - channel_commands.h channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x client_keyexchange.h \ - interact.h interact.h.x publickey_crypto.h publickey_crypto.h.x \ - client_userauth.h userauth.h userauth.h.x compress.h \ - connection_commands.h connection_commands.h.x crypto.h dsa.h \ - format.h io_commands.h io_commands.h.x gateway.h \ - gateway_commands.h handshake.h ssh1_fallback.h \ - ssh1_fallback.h.x handshake.h.x lookup_verifier.h \ - lookup_verifier.h.x rsa.h rsa.h.x sexp.h sexp_table.h sexp.h.x \ - spki_commands.h spki.h spki.h.x srp.h srp.h.x ssh.h \ - tcpforward_commands.h tcpforward.h xalloc.h gc.h tcpforward.h.x \ - version.h werror.h lsh.c.x -lsh_proxy.o: lsh_proxy.c algorithms.h abstract_compress.h lsh.h \ - lsh_types.h ../config.h abstract_compress.h.x alist.h alist.h.x \ - lsh_argp.h argp/argp.h randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x exception.h exception.h.x \ - randomness.h.x algorithms.h.x atoms.h atoms_defines.h channel.h \ - command.h command.h.x connection.h abstract_io.h \ - abstract_io.h.x queue.h queue.h.x resource.h resource.h.x \ - connection.h.x parse.h bignum.h server_pty.h server_pty.h.x \ - write_buffer.h write_buffer.h.x channel.h.x channel_commands.h \ - channel_commands.h.x charset.h client_keyexchange.h interact.h \ - interact.h.x keyexchange.h keyexchange.h.x publickey_crypto.h \ - publickey_crypto.h.x compress.h connection_commands.h \ - connection_commands.h.x crypto.h daemon.h dsa.h format.h \ - gateway_channel.h gateway_channel.h.x handshake.h \ - ssh1_fallback.h ssh1_fallback.h.x handshake.h.x io.h io.h.x \ - io_commands.h io_commands.h.x lookup_verifier.h \ - lookup_verifier.h.x proxy.h proxy_agentforward.h \ - proxy_session.h proxy_tcpforward.h proxy_userauth.h xalloc.h \ - gc.h userauth.h userauth.h.x proxy_userauth.h.x \ - proxy_x11forward.h reaper.h reaper.h.x server.h \ - server_authorization.h server_keyexchange.h server_userauth.h \ - server_userauth.h.x server_session.h sexp.h sexp_table.h \ - sexp.h.x sexp_commands.h sexp_commands.h.x spki.h spki.h.x \ - spki_commands.h ssh.h version.h werror.h lsh_proxy.c.x -lshd.o: lshd.c algorithms.h abstract_compress.h lsh.h lsh_types.h \ - ../config.h abstract_compress.h.x alist.h alist.h.x lsh_argp.h \ - argp/argp.h randomness.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x exception.h exception.h.x randomness.h.x \ - algorithms.h.x atoms.h atoms_defines.h channel.h command.h \ - command.h.x connection.h abstract_io.h abstract_io.h.x queue.h \ - queue.h.x resource.h resource.h.x connection.h.x parse.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h \ - channel_commands.h.x charset.h compress.h connection_commands.h \ - connection_commands.h.x crypto.h daemon.h dsa.h \ - publickey_crypto.h publickey_crypto.h.x format.h handshake.h \ - ssh1_fallback.h ssh1_fallback.h.x handshake.h.x io.h io.h.x \ - io_commands.h io_commands.h.x lookup_verifier.h \ - lookup_verifier.h.x reaper.h reaper.h.x server.h \ - server_authorization.h server_keyexchange.h keyexchange.h \ - keyexchange.h.x server_userauth.h userauth.h userauth.h.x \ - server_userauth.h.x server_session.h sexp.h sexp_table.h \ - sexp.h.x sexp_commands.h sexp_commands.h.x spki_commands.h \ - interact.h interact.h.x spki.h spki.h.x srp.h srp.h.x ssh.h \ - tcpforward.h xalloc.h gc.h tcpforward.h.x tcpforward_commands.h \ - version.h werror.h lshd.c.x -lshg.o: lshg.c charset.h lsh_types.h ../config.h client.h \ - channel_commands.h channel.h alist.h lsh.h alist.h.x command.h \ - exception.h exception.h.x list.h list.h.x command.h.x \ - connection.h abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h.x io.h io.h.x \ - keyexchange.h keyexchange.h.x client.h.x debug.h format.h \ - gateway.h gateway_commands.h interact.h interact.h.x \ - io_commands.h io_commands.h.x ssh.h version.h werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h lshg.c.x -md5.o: md5.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x xalloc.h gc.h \ - nettle/md5.h md5.c.x -memxor.o: memxor.c memxor.h lsh_types.h ../config.h -pad.o: pad.c pad.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x abstract_io.h \ - exception.h exception.h.x abstract_io.h.x connection.h \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h randomness.h.x \ - connection.h.x format.h atoms.h atoms_defines.h bignum.h \ - xalloc.h gc.h pad.c.x -parse.o: parse.c parse.h atoms.h lsh_types.h ../config.h atoms_defines.h \ - bignum.h lsh.h format.h list.h list.h.x werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h parse_macros.h -pkcs5-test.o: pkcs5-test.c crypto.h abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x -pkcs5.o: pkcs5.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x memxor.h xalloc.h gc.h -prime_table.o: prime_table.c -proxy.o: proxy.c proxy.h alist.h lsh.h lsh_types.h ../config.h alist.h.x \ - command.h exception.h exception.h.x list.h list.h.x command.h.x \ - channel_commands.h channel.h connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x parse.h atoms.h atoms_defines.h bignum.h \ - server_pty.h server_pty.h.x write_buffer.h write_buffer.h.x \ - channel.h.x channel_commands.h.x format.h gateway_channel.h \ - gateway_channel.h.x io_commands.h io.h io.h.x io_commands.h.x \ - proxy_session.h proxy_userauth.h xalloc.h gc.h userauth.h \ - userauth.h.x proxy_userauth.h.x ssh.h werror.h lsh_argp.h \ - argp/argp.h proxy.c.x -proxy_agentforward.o: proxy_agentforward.c proxy_agentforward.h \ - channel_commands.h channel.h alist.h lsh.h lsh_types.h \ - ../config.h alist.h.x command.h exception.h exception.h.x \ - list.h list.h.x command.h.x connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x parse.h atoms.h atoms_defines.h bignum.h \ - server_pty.h server_pty.h.x write_buffer.h write_buffer.h.x \ - channel.h.x channel_commands.h.x format.h gateway_channel.h \ - gateway_channel.h.x ssh.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h -proxy_session.o: proxy_session.c proxy_session.h alist.h lsh.h \ - lsh_types.h ../config.h alist.h.x channel.h command.h \ - exception.h exception.h.x list.h list.h.x command.h.x \ - connection.h abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x channel_commands.h \ - channel_commands.h.x format.h gateway_channel.h \ - gateway_channel.h.x ssh.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h proxy_session.c.x -proxy_tcpforward.o: proxy_tcpforward.c proxy_tcpforward.h \ - gateway_channel.h channel.h alist.h lsh.h lsh_types.h \ - ../config.h alist.h.x command.h exception.h exception.h.x \ - list.h list.h.x command.h.x connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x parse.h atoms.h atoms_defines.h bignum.h \ - server_pty.h server_pty.h.x write_buffer.h write_buffer.h.x \ - channel.h.x gateway_channel.h.x xalloc.h gc.h ssh.h werror.h \ - lsh_argp.h argp/argp.h channel_commands.h channel_commands.h.x \ - format.h -proxy_userauth.o: proxy_userauth.c proxy_userauth.h xalloc.h gc.h lsh.h \ - lsh_types.h ../config.h alist.h alist.h.x list.h list.h.x \ - userauth.h command.h exception.h exception.h.x command.h.x \ - resource.h resource.h.x userauth.h.x proxy_userauth.h.x \ - client_userauth.h connection.h abstract_io.h abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x interact.h interact.h.x parse.h \ - atoms.h atoms_defines.h bignum.h format.h proxy.h \ - server_userauth.h io.h write_buffer.h write_buffer.h.x io.h.x \ - server_userauth.h.x ssh.h werror.h lsh_argp.h argp/argp.h \ - proxy_userauth.c.x -proxy_x11forward.o: proxy_x11forward.c proxy_x11forward.h \ - gateway_channel.h channel.h alist.h lsh.h lsh_types.h \ - ../config.h alist.h.x command.h exception.h exception.h.x \ - list.h list.h.x command.h.x connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x parse.h atoms.h atoms_defines.h bignum.h \ - server_pty.h server_pty.h.x write_buffer.h write_buffer.h.x \ - channel.h.x gateway_channel.h.x xalloc.h gc.h ssh.h werror.h \ - lsh_argp.h argp/argp.h channel_commands.h channel_commands.h.x \ - format.h -publickey_crypto.o: publickey_crypto.c publickey_crypto.h \ - abstract_crypto.h list.h lsh.h lsh_types.h ../config.h list.h.x \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h bignum.h \ - publickey_crypto.h.x connection.h abstract_io.h exception.h \ - exception.h.x abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h randomness.h.x connection.h.x crypto.h format.h \ - ssh.h werror.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - publickey_crypto.c.x -queue.o: queue.c queue.h lsh.h lsh_types.h ../config.h queue.h.x list.h \ - list.h.x werror.h bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h -randomness.o: randomness.c randomness.h abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x \ - exception.h exception.h.x randomness.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h crypto.h xalloc.h gc.h nettle/arcfour.h \ - randomness.c.x -read_base64.o: read_base64.c read_file.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x digits.h \ - werror.h bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - read_base64.c.x -read_data.o: read_data.c read_data.h channel.h alist.h lsh.h lsh_types.h \ - ../config.h alist.h.x command.h exception.h exception.h.x \ - list.h list.h.x command.h.x connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x parse.h atoms.h atoms_defines.h bignum.h \ - server_pty.h server_pty.h.x write_buffer.h write_buffer.h.x \ - channel.h.x io.h io.h.x werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h read_data.c.x -read_file.o: read_file.c read_file.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x werror.h \ - bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h read_file.c.x -read_line.o: read_line.c read_line.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x \ - read_line.h.x werror.h bignum.h lsh_argp.h argp/argp.h xalloc.h \ - gc.h read_line.c.x -read_packet.o: read_packet.c read_packet.h abstract_io.h exception.h \ - lsh.h lsh_types.h ../config.h exception.h.x abstract_io.h.x \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - connection.h abstract_compress.h abstract_compress.h.x queue.h \ - queue.h.x resource.h resource.h.x randomness.h randomness.h.x \ - connection.h.x crypto.h format.h atoms.h atoms_defines.h \ - bignum.h io.h command.h command.h.x write_buffer.h \ - write_buffer.h.x io.h.x ssh.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h read_packet.c.x -reaper.o: reaper.c reaper.h io.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x command.h \ - list.h list.h.x command.h.x resource.h resource.h.x \ - write_buffer.h queue.h queue.h.x write_buffer.h.x io.h.x \ - reaper.h.x alist.h alist.h.x werror.h bignum.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h reaper.c.x -resource.o: resource.c resource.h lsh.h lsh_types.h ../config.h \ - resource.h.x gc.h werror.h bignum.h lsh_argp.h argp/argp.h \ - xalloc.h resource.c.x -rijndael.o: rijndael.c crypto.h abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x werror.h \ - bignum.h lsh_argp.h argp/argp.h xalloc.h gc.h nettle/aes.h \ - rijndael.c.x -rsa.o: rsa.c rsa.h bignum.h lsh.h lsh_types.h ../config.h \ - publickey_crypto.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x rsa.h.x crypto.h format.h sexp.h command.h \ - exception.h exception.h.x command.h.x lsh_argp.h argp/argp.h \ - sexp_table.h sexp.h.x werror.h xalloc.h gc.h rsa.c.x -rsa_keygen.o: rsa_keygen.c rsa.h bignum.h lsh.h lsh_types.h ../config.h \ - publickey_crypto.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x rsa.h.x sexp.h command.h exception.h \ - exception.h.x command.h.x lsh_argp.h argp/argp.h sexp_table.h \ - sexp.h.x werror.h -serpent.o: serpent.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h nettle/serpent.h \ - serpent.c.x -server.o: server.c server.h command.h lsh.h lsh_types.h ../config.h \ - exception.h exception.h.x list.h list.h.x command.h.x alist.h \ - alist.h.x abstract_io.h abstract_io.h.x channel.h connection.h \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h \ - abstract_crypto.h.x randomness.h.x connection.h.x parse.h \ - atoms.h atoms_defines.h bignum.h server_pty.h server_pty.h.x \ - write_buffer.h write_buffer.h.x channel.h.x compress.h debug.h \ - disconnect.h format.h keyexchange.h keyexchange.h.x read_line.h \ - read_line.h.x read_packet.h reaper.h io.h io.h.x reaper.h.x \ - ssh.h unpad.h werror.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - server.c.x -server_authorization.o: server_authorization.c server_authorization.h \ - lookup_verifier.h lsh.h lsh_types.h ../config.h \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - lookup_verifier.h.x publickey_crypto.h parse.h atoms.h \ - atoms_defines.h bignum.h publickey_crypto.h.x dsa.h format.h \ - rsa.h rsa.h.x server_userauth.h alist.h alist.h.x command.h \ - exception.h exception.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h randomness.h.x connection.h.x io.h write_buffer.h \ - write_buffer.h.x io.h.x userauth.h userauth.h.x \ - server_userauth.h.x sexp.h lsh_argp.h argp/argp.h sexp_table.h \ - sexp.h.x spki.h spki.h.x xalloc.h gc.h server_authorization.c.x -server_keyexchange.o: server_keyexchange.c server_keyexchange.h \ - keyexchange.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x abstract_compress.h \ - abstract_compress.h.x alist.h alist.h.x bignum.h connection.h \ - abstract_io.h exception.h exception.h.x abstract_io.h.x queue.h \ - queue.h.x resource.h resource.h.x randomness.h randomness.h.x \ - connection.h.x keyexchange.h.x publickey_crypto.h parse.h \ - atoms.h atoms_defines.h publickey_crypto.h.x server_userauth.h \ - command.h command.h.x io.h write_buffer.h write_buffer.h.x \ - io.h.x userauth.h userauth.h.x server_userauth.h.x debug.h \ - dsa.h format.h sexp_commands.h sexp.h lsh_argp.h argp/argp.h \ - sexp_table.h sexp.h.x sexp_commands.h.x srp.h srp.h.x ssh.h \ - werror.h xalloc.h gc.h server_keyexchange.c.x -server_password.o: server_password.c charset.h lsh_types.h ../config.h \ - format.h atoms.h atoms_defines.h bignum.h lsh.h parse.h ssh.h \ - server_userauth.h alist.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x io.h write_buffer.h \ - write_buffer.h.x io.h.x userauth.h userauth.h.x \ - server_userauth.h.x werror.h lsh_argp.h argp/argp.h xalloc.h \ - gc.h server_password.c.x -server_pty.o: server_pty.c server_pty.h lsh.h lsh_types.h ../config.h \ - resource.h resource.h.x server_pty.h.x channel.h alist.h \ - alist.h.x command.h exception.h exception.h.x list.h list.h.x \ - command.h.x connection.h abstract_io.h abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h write_buffer.h write_buffer.h.x channel.h.x format.h \ - ssh.h werror.h lsh_argp.h argp/argp.h xalloc.h gc.h -server_publickey.o: server_publickey.c charset.h lsh_types.h ../config.h \ - connection.h abstract_io.h exception.h lsh.h exception.h.x \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h list.h list.h.x abstract_crypto.h.x \ - randomness.h.x connection.h.x dsa.h bignum.h publickey_crypto.h \ - parse.h atoms.h atoms_defines.h publickey_crypto.h.x format.h \ - lookup_verifier.h lookup_verifier.h.x server_userauth.h alist.h \ - alist.h.x command.h command.h.x io.h write_buffer.h \ - write_buffer.h.x io.h.x userauth.h userauth.h.x \ - server_userauth.h.x ssh.h werror.h lsh_argp.h argp/argp.h \ - xalloc.h gc.h server_publickey.c.x -server_session.o: server_session.c server_session.h channel.h alist.h \ - lsh.h lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x io.h io.h.x server_userauth.h \ - userauth.h userauth.h.x server_userauth.h.x channel_commands.h \ - channel_commands.h.x format.h read_data.h reaper.h reaper.h.x \ - ssh.h tcpforward.h xalloc.h gc.h tcpforward.h.x \ - translate_signal.h tty.h werror.h lsh_argp.h argp/argp.h \ - server_session.c.x -server_userauth.o: server_userauth.c server_userauth.h alist.h lsh.h \ - lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x io.h write_buffer.h \ - write_buffer.h.x io.h.x parse.h atoms.h atoms_defines.h \ - bignum.h userauth.h userauth.h.x server_userauth.h.x charset.h \ - format.h ssh.h werror.h lsh_argp.h argp/argp.h xalloc.h gc.h \ - server_userauth.c.x -sexp-conv.o: sexp-conv.c algorithms.h abstract_compress.h lsh.h \ - lsh_types.h ../config.h abstract_compress.h.x alist.h alist.h.x \ - lsh_argp.h argp/argp.h randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x exception.h exception.h.x \ - randomness.h.x algorithms.h.x atoms.h atoms_defines.h crypto.h \ - io.h abstract_io.h abstract_io.h.x command.h command.h.x \ - resource.h resource.h.x write_buffer.h queue.h queue.h.x \ - write_buffer.h.x io.h.x sexp_commands.h sexp.h bignum.h parse.h \ - sexp_table.h sexp.h.x sexp_commands.h.x spki_commands.h \ - interact.h interact.h.x spki.h dsa.h publickey_crypto.h \ - publickey_crypto.h.x spki.h.x version.h werror.h xalloc.h gc.h \ - sexp-conv.c.x -sexp.o: sexp.c sexp.h bignum.h lsh.h lsh_types.h ../config.h command.h \ - exception.h exception.h.x list.h list.h.x command.h.x \ - lsh_argp.h argp/argp.h parse.h atoms.h atoms_defines.h \ - sexp_table.h sexp.h.x format.h queue.h queue.h.x werror.h \ - xalloc.h gc.h sexp.c.x -sexp_commands.o: sexp_commands.c sexp_commands.h abstract_crypto.h \ - list.h lsh.h lsh_types.h ../config.h list.h.x \ - abstract_crypto.h.x abstract_io.h exception.h exception.h.x \ - abstract_io.h.x command.h command.h.x sexp.h bignum.h \ - lsh_argp.h argp/argp.h parse.h atoms.h atoms_defines.h \ - sexp_table.h sexp.h.x sexp_commands.h.x format.h io.h \ - resource.h resource.h.x write_buffer.h queue.h queue.h.x \ - write_buffer.h.x io.h.x read_file.h werror.h xalloc.h gc.h \ - sexp_commands.c.x -sexp_parser.o: sexp_parser.c sexp.h bignum.h lsh.h lsh_types.h \ - ../config.h command.h exception.h exception.h.x list.h list.h.x \ - command.h.x lsh_argp.h argp/argp.h parse.h atoms.h \ - atoms_defines.h sexp_table.h sexp.h.x digits.h format.h \ - parse_macros.h queue.h queue.h.x werror.h xalloc.h gc.h -sha.o: sha.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x xalloc.h gc.h \ - nettle/sha1.h sha.c.x -spki.o: spki.c spki.h alist.h lsh.h lsh_types.h ../config.h alist.h.x \ - dsa.h bignum.h publickey_crypto.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x exception.h exception.h.x spki.h.x \ - crypto.h format.h io.h abstract_io.h abstract_io.h.x command.h \ - command.h.x resource.h resource.h.x write_buffer.h queue.h \ - queue.h.x write_buffer.h.x io.h.x sexp.h lsh_argp.h argp/argp.h \ - sexp_table.h sexp.h.x werror.h xalloc.h gc.h spki.c.x -spki_commands.o: spki_commands.c spki_commands.h command.h lsh.h \ - lsh_types.h ../config.h exception.h exception.h.x list.h \ - list.h.x command.h.x interact.h interact.h.x spki.h alist.h \ - alist.h.x dsa.h bignum.h publickey_crypto.h abstract_crypto.h \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h \ - publickey_crypto.h.x spki.h.x crypto.h format.h queue.h \ - queue.h.x randomness.h randomness.h.x sexp_commands.h \ - abstract_io.h abstract_io.h.x sexp.h lsh_argp.h argp/argp.h \ - sexp_table.h sexp.h.x sexp_commands.h.x werror.h xalloc.h gc.h \ - spki_commands.c.x -srp-gen.o: srp-gen.c srp.h publickey_crypto.h abstract_crypto.h list.h \ - lsh.h lsh_types.h ../config.h list.h.x abstract_crypto.h.x \ - parse.h atoms.h atoms_defines.h bignum.h publickey_crypto.h.x \ - srp.h.x crypto.h format.h interact.h interact.h.x io.h \ - abstract_io.h exception.h exception.h.x abstract_io.h.x \ - command.h command.h.x resource.h resource.h.x write_buffer.h \ - queue.h queue.h.x write_buffer.h.x io.h.x randomness.h \ - randomness.h.x sexp.h lsh_argp.h argp/argp.h sexp_table.h \ - sexp.h.x version.h werror.h xalloc.h gc.h srp-gen.c.x -srp_exchange.o: srp_exchange.c srp.h publickey_crypto.h \ - abstract_crypto.h list.h lsh.h lsh_types.h ../config.h list.h.x \ - abstract_crypto.h.x parse.h atoms.h atoms_defines.h bignum.h \ - publickey_crypto.h.x srp.h.x crypto.h format.h sexp.h command.h \ - exception.h exception.h.x command.h.x lsh_argp.h argp/argp.h \ - sexp_table.h sexp.h.x ssh.h werror.h xalloc.h gc.h -ssh1_fallback.o: ssh1_fallback.c ssh1_fallback.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x ssh1_fallback.h.x io.h \ - abstract_io.h abstract_io.h.x command.h list.h list.h.x \ - command.h.x resource.h resource.h.x write_buffer.h queue.h \ - queue.h.x write_buffer.h.x io.h.x ssh.h werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h ssh1_fallback.c.x -string_buffer.o: string_buffer.c string_buffer.h lsh.h lsh_types.h \ - ../config.h xalloc.h gc.h -suspend.o: suspend.c suspend.h io.h abstract_io.h exception.h lsh.h \ - lsh_types.h ../config.h exception.h.x abstract_io.h.x command.h \ - list.h list.h.x command.h.x resource.h resource.h.x \ - write_buffer.h queue.h queue.h.x write_buffer.h.x io.h.x tty.h \ - werror.h bignum.h lsh_argp.h argp/argp.h -tcpforward.o: tcpforward.c tcpforward.h channel.h alist.h lsh.h \ - lsh_types.h ../config.h alist.h.x command.h exception.h \ - exception.h.x list.h list.h.x command.h.x connection.h \ - abstract_io.h abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x queue.h queue.h.x resource.h resource.h.x \ - randomness.h abstract_crypto.h abstract_crypto.h.x \ - randomness.h.x connection.h.x parse.h atoms.h atoms_defines.h \ - bignum.h server_pty.h server_pty.h.x write_buffer.h \ - write_buffer.h.x channel.h.x io.h io.h.x xalloc.h gc.h \ - tcpforward.h.x channel_commands.h channel_commands.h.x \ - channel_forward.h channel_forward.h.x format.h io_commands.h \ - io_commands.h.x ssh.h werror.h lsh_argp.h argp/argp.h \ - tcpforward.c.x -tcpforward_commands.o: tcpforward_commands.c tcpforward_commands.h \ - tcpforward.h channel.h alist.h lsh.h lsh_types.h ../config.h \ - alist.h.x command.h exception.h exception.h.x list.h list.h.x \ - command.h.x connection.h abstract_io.h abstract_io.h.x \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h \ - abstract_crypto.h.x randomness.h.x connection.h.x parse.h \ - atoms.h atoms_defines.h bignum.h server_pty.h server_pty.h.x \ - write_buffer.h write_buffer.h.x channel.h.x io.h io.h.x \ - xalloc.h gc.h tcpforward.h.x channel_commands.h \ - channel_commands.h.x channel_forward.h channel_forward.h.x \ - connection_commands.h connection_commands.h.x format.h \ - io_commands.h io_commands.h.x ssh.h werror.h lsh_argp.h \ - argp/argp.h tcpforward_commands.c.x -translate_signal.o: translate_signal.c translate_signal.h atoms.h \ - lsh_types.h ../config.h atoms_defines.h -tty.o: tty.c tty.h lsh_types.h ../config.h format.h atoms.h \ - atoms_defines.h bignum.h lsh.h parse.h ssh.h werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h -twofish.o: twofish.c crypto.h abstract_crypto.h list.h lsh.h lsh_types.h \ - ../config.h list.h.x abstract_crypto.h.x werror.h bignum.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h nettle/twofish.h \ - twofish.c.x -unix_interact.o: unix_interact.c interact.h lsh.h lsh_types.h \ - ../config.h interact.h.x format.h atoms.h atoms_defines.h \ - bignum.h io.h abstract_io.h exception.h exception.h.x \ - abstract_io.h.x command.h list.h list.h.x command.h.x \ - resource.h resource.h.x write_buffer.h queue.h queue.h.x \ - write_buffer.h.x io.h.x suspend.h tty.h werror.h lsh_argp.h \ - argp/argp.h xalloc.h gc.h unix_interact.c.x -unix_random.o: unix_random.c randomness.h abstract_crypto.h list.h lsh.h \ - lsh_types.h ../config.h list.h.x abstract_crypto.h.x \ - exception.h exception.h.x randomness.h.x crypto.h reaper.h io.h \ - abstract_io.h abstract_io.h.x command.h command.h.x resource.h \ - resource.h.x write_buffer.h queue.h queue.h.x write_buffer.h.x \ - io.h.x reaper.h.x xalloc.h gc.h werror.h bignum.h lsh_argp.h \ - argp/argp.h unix_random.c.x -unix_user.o: unix_user.c server_userauth.h alist.h lsh.h lsh_types.h \ - ../config.h alist.h.x command.h exception.h exception.h.x \ - list.h list.h.x command.h.x connection.h abstract_io.h \ - abstract_io.h.x abstract_compress.h abstract_compress.h.x \ - queue.h queue.h.x resource.h resource.h.x randomness.h \ - abstract_crypto.h abstract_crypto.h.x randomness.h.x \ - connection.h.x io.h write_buffer.h write_buffer.h.x io.h.x \ - parse.h atoms.h atoms_defines.h bignum.h userauth.h \ - userauth.h.x server_userauth.h.x format.h reaper.h reaper.h.x \ - werror.h lsh_argp.h argp/argp.h xalloc.h gc.h unix_user.c.x -unpad.o: unpad.c unpad.h abstract_io.h exception.h lsh.h lsh_types.h \ - ../config.h exception.h.x abstract_io.h.x connection.h \ - abstract_compress.h abstract_compress.h.x queue.h queue.h.x \ - resource.h resource.h.x randomness.h abstract_crypto.h list.h \ - list.h.x abstract_crypto.h.x randomness.h.x connection.h.x \ - format.h atoms.h atoms_defines.h bignum.h ssh.h xalloc.h gc.h \ - unpad.c.x -userauth.o: userauth.c userauth.h command.h lsh.h lsh_types.h \ - ../config.h exception.h exception.h.x list.h list.h.x \ - command.h.x resource.h resource.h.x userauth.h.x format.h \ - atoms.h atoms_defines.h bignum.h ssh.h xalloc.h gc.h -werror.o: werror.c werror.h bignum.h lsh.h lsh_types.h ../config.h \ - lsh_argp.h argp/argp.h charset.h format.h atoms.h \ - atoms_defines.h gc.h io.h abstract_io.h exception.h \ - exception.h.x abstract_io.h.x command.h list.h list.h.x \ - command.h.x resource.h resource.h.x write_buffer.h queue.h \ - queue.h.x write_buffer.h.x io.h.x parse.h xalloc.h -write_buffer.o: write_buffer.c write_buffer.h abstract_io.h exception.h \ - lsh.h lsh_types.h ../config.h exception.h.x abstract_io.h.x \ - queue.h queue.h.x write_buffer.h.x xalloc.h gc.h werror.h \ - bignum.h lsh_argp.h argp/argp.h -xalloc.o: xalloc.c xalloc.h gc.h lsh.h lsh_types.h ../config.h list.h \ - list.h.x werror.h bignum.h lsh_argp.h argp/argp.h -xauth.o: xauth.c xauth.h lsh.h lsh_types.h ../config.h format.h atoms.h \ - atoms_defines.h bignum.h werror.h lsh_argp.h argp/argp.h -zlib.o: zlib.c compress.h abstract_io.h exception.h lsh.h lsh_types.h \ - ../config.h exception.h.x abstract_io.h.x abstract_compress.h \ - abstract_compress.h.x connection.h queue.h queue.h.x resource.h \ - resource.h.x randomness.h abstract_crypto.h list.h list.h.x \ - abstract_crypto.h.x randomness.h.x connection.h.x format.h \ - atoms.h atoms_defines.h bignum.h ssh.h string_buffer.h werror.h \ - lsh_argp.h argp/argp.h xalloc.h gc.h zlib.c.x - -info-am: -info: info-recursive -dvi-am: -dvi: dvi-recursive -check-am: all-am -check: check-recursive -installcheck-am: -installcheck: installcheck-recursive -install-exec-am: install-binPROGRAMS install-sbinPROGRAMS \ - install-binSCRIPTS -install-exec: install-exec-recursive - -install-data-am: -install-data: install-data-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-recursive -uninstall-am: uninstall-binPROGRAMS uninstall-sbinPROGRAMS \ - uninstall-binSCRIPTS -uninstall: uninstall-recursive -all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(SCRIPTS) -all-redirect: all-recursive -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: installdirs-recursive -installdirs-am: - $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(sbindir) \ - $(DESTDIR)$(bindir) - - -mostlyclean-generic: - -clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: - -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) -mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \ - mostlyclean-binPROGRAMS mostlyclean-noinstPROGRAMS \ - mostlyclean-sbinPROGRAMS mostlyclean-tags \ - mostlyclean-generic - -mostlyclean: mostlyclean-recursive - -clean-am: clean-noinstLIBRARIES clean-compile clean-binPROGRAMS \ - clean-noinstPROGRAMS clean-sbinPROGRAMS clean-tags \ - clean-generic mostlyclean-am - -clean: clean-recursive - -distclean-am: distclean-noinstLIBRARIES distclean-compile \ - distclean-binPROGRAMS distclean-noinstPROGRAMS \ - distclean-sbinPROGRAMS distclean-tags distclean-generic \ - clean-am - -distclean: distclean-recursive - -maintainer-clean-am: maintainer-clean-noinstLIBRARIES \ - maintainer-clean-compile maintainer-clean-binPROGRAMS \ - maintainer-clean-noinstPROGRAMS \ - maintainer-clean-sbinPROGRAMS maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-recursive - -.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ -clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile mostlyclean-binPROGRAMS distclean-binPROGRAMS \ -clean-binPROGRAMS maintainer-clean-binPROGRAMS uninstall-binPROGRAMS \ -install-binPROGRAMS mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \ -clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \ -mostlyclean-sbinPROGRAMS distclean-sbinPROGRAMS clean-sbinPROGRAMS \ -maintainer-clean-sbinPROGRAMS uninstall-sbinPROGRAMS \ -install-sbinPROGRAMS uninstall-binSCRIPTS install-binSCRIPTS \ -install-data-recursive uninstall-data-recursive install-exec-recursive \ -uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \ -all-recursive check-recursive installcheck-recursive info-recursive \ -dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \ -maintainer-clean-recursive tags tags-recursive mostlyclean-tags \ -distclean-tags clean-tags maintainer-clean-tags distdir info-am info \ -dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ -install-exec install-data-am install-data install-am install \ -uninstall-am uninstall all-redirect all-am all installdirs-am \ -installdirs mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean - - -# To remake all Makefile.am-files, run -# -# ./make_am -# -# You should run ./make_am --rethink after recompiling, but before -# making a dist, as it uses dependency information to figure out which -# header files should be included in th dist. How to tell this to -# make? FIXME: These rules won't remake Makefile.am files in -# subdrectries. - -# FIXME: Use the BASH variable to execute the script. The problem is -# that the script attempts to start itself with "$0 args". - -Makefile.am: Makefile.am.in - (cd $(top_srcdir) && $(MAKE) src/Makefile.am) - -.PHONY: bootstrap - -bootstrap: $(generated_sources) - # Not all potential .x files can be generated - -$(MAKE) -k $(POTENTIAL_X_FILES) - @rm -f $(addsuffix T,$(POTENTIAL_X_FILES)) - -atoms_defines.h: atoms.in process_atoms - $(BASH) $(srcdir)/process_atoms header <$< >$@T - test -s $@T && mv -f $@T $@ -atoms_gperf.c: atoms.in process_atoms - $(BASH) $(srcdir)/process_atoms gperf <$< \ - | gperf $(GPERF_FLAGS) | sed 's/{""}/{"", 0}/g' >$@T - test -s $@T && mv -f $@T $@ - -atoms_table.c: atoms.in process_atoms - $(BASH) $(srcdir)/process_atoms table <$< >$@T - test -s $@T && mv -f $@T $@ - -prime_table.h: prime_table - ./prime_table $(PRIME_LIMIT) >$@T - test -s $@T && mv -f $@T $@ - -sexp_table.h: sexp_chars.in $(srcdir)/scm/make-char-classes.scm - $(SCHEME) -e main -s $(srcdir)/scm/make-char-classes.scm <$< >$@T - test -s $@T && mv -f $@T $@ - -digit_table.h: digit_table - ./digit_table >$@T - test -s $@T && mv -f $@T $@ - -packet_types.h: ssh.h invert-defs - $(srcdir)/invert-defs $@T - test -s $@T && mv -f $@T $@ - -class-map: $(srcdir)/make-class-map $(dist_x_files) - cat $(dist_x_files) | grep '^CLASS:' \ - | sort | awk -f $(srcdir)/make-class-map > $@ - -# Class files -# SUFFIXES = .xh .xc - -.PHONY: depend -depend: - rm -f $(DEP_FILES) - make $(DEP_FILES) - -# This is GNU make specific - -%.x: % $(srcdir)/scm/gaba.scm $(srcdir)/scm/compiler.scm - $(SCHEME) -e main -l $(srcdir)/scm/compiler.scm \ - -s $(srcdir)/scm/gaba.scm <$< >$@T - test -s $@T && mv -f $@T $@ - -.PHONY: ctags-recursive ctags - -ctags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - (cd $$subdir && $(MAKE) ctags); \ - done - -ctags: ctags-recursive $(HEADERS) $(SOURCES) $(CONFIG_HEADER) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - test -f $$subdir/tags && tags="$$tags $$here/$$subdir/tags"; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$(CONFIG_HEADER)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && ctags --langmap=c:.c.x -o $$here/tags $(CTAGS_ARGS) $$tags $(CONFIG_HEADER) $$unique $(LISP)) -# This treats .h.x files as C files rather than headers, but we can't -# distinguish them from .c.x files with ctags. - -# Override the standard distclean-tags target, as this doesn't support `tags' -distclean-tags: - -rm -f TAGS ID tags - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/abstract_compress.c b/lsh/src/abstract_compress.c deleted file mode 100755 index 8253cbf..0000000 --- a/lsh/src/abstract_compress.c +++ /dev/null @@ -1,31 +0,0 @@ -/* abstract_compress.c - * - * interface to compression algorithms... - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "abstract_compress.h" - -#define GABA_DEFINE -#include "abstract_compress.h.x" -#undef GABA_DEFINE diff --git a/lsh/src/abstract_compress.h b/lsh/src/abstract_compress.h deleted file mode 100755 index 306f19d..0000000 --- a/lsh/src/abstract_compress.h +++ /dev/null @@ -1,63 +0,0 @@ -/* abstract_compress.h - * - * interface to compression algorithms... - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ABSTRACT_COMPRESS_H_INCLUDED -#define LSH_ABSTRACT_COMPRESS_H_INCLUDED - -#include "lsh.h" - -#define GABA_DECLARE -#include "abstract_compress.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name compress_instance) - (vars - (codec method (string) - "struct lsh_string *data" "int free"))) -*/ - -#define CODEC(instance, packet, free) \ -((instance)->codec((instance), (packet), (free))) - -#define COMPRESS_DEFLATE 0 -#define COMPRESS_INFLATE 1 - -/* GABA: - (class - (name compress_algorithm) - (vars - (make_compress method (object compress_instance) - "int mode"))) -*/ - -#define MAKE_CODEC(algo, mode) \ -((algo)->make_compress((algo), (mode))) - -#define MAKE_DEFLATE(algo) MAKE_CODEC((algo), COMPRESS_DEFLATE) -#define MAKE_INFLATE(algo) MAKE_CODEC((algo), COMPRESS_INFLATE) - -#endif diff --git a/lsh/src/abstract_compress.h.x b/lsh/src/abstract_compress.h.x deleted file mode 100755 index 38410be..0000000 Binary files a/lsh/src/abstract_compress.h.x and /dev/null differ diff --git a/lsh/src/abstract_crypto.c b/lsh/src/abstract_crypto.c deleted file mode 100755 index c0c4a2b..0000000 --- a/lsh/src/abstract_crypto.c +++ /dev/null @@ -1,244 +0,0 @@ -/* abstract_crypto.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "abstract_crypto.h" - -#include "crypto.h" -#include "format.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#define GABA_DEFINE -#include "abstract_crypto.h.x" -#undef GABA_DEFINE - -#include "abstract_crypto.c.x" - -/* Combining block cryptos */ - -/* Inverts the encryption mode (needed for the EDE-operation of - * triple DES). */ -/* GABA: - (class - (name crypto_inverted) - (super crypto_algorithm) - (vars - (inner object crypto_algorithm))) -*/ - -static struct crypto_instance * -do_make_inverted(struct crypto_algorithm *s, - int mode, const UINT8 *key, const UINT8 *iv) -{ - CAST(crypto_inverted, self, s); - - return MAKE_CRYPT(self->inner, ( (mode == CRYPTO_ENCRYPT) - ? CRYPTO_DECRYPT - : CRYPTO_ENCRYPT), - key, iv); -} - -struct crypto_algorithm *crypto_invert(struct crypto_algorithm *inner) -{ - NEW(crypto_inverted, algorithm); - - algorithm->super.block_size = inner->block_size; - algorithm->super.key_size = inner->key_size; - algorithm->super.iv_size = inner->iv_size; - - algorithm->inner = inner; - algorithm->super.make_crypt = do_make_inverted; - - return &algorithm->super; -} - -struct lsh_string * -hash_string(struct hash_algorithm *a, - struct lsh_string *in, - int free) -{ - struct hash_instance *hash = MAKE_HASH(a); - struct lsh_string *out = lsh_string_alloc(hash->hash_size); - - HASH_UPDATE(hash, in->length, in->data); - HASH_DIGEST(hash, out->data); - - KILL(hash); - if (free) - lsh_string_free(in); - - return out; -} - -struct lsh_string * -mac_string(struct mac_algorithm *a, - struct lsh_string *key, - int kfree, - struct lsh_string *in, - int ifree) -{ - struct mac_instance *mac = MAKE_MAC(a, key->length, key->data); - struct lsh_string *out = lsh_string_alloc(mac->mac_size); - - HASH_UPDATE(mac, in->length, in->data); - HASH_DIGEST(mac, out->data); - - KILL(mac); - - if (kfree) - lsh_string_free(key); - if (ifree) - lsh_string_free(in); - - return out; -} - -struct lsh_string * -crypt_string(struct crypto_instance *c, - const struct lsh_string *in, - int free) -{ - struct lsh_string *out; - - if (free) - { - /* Do the encryption in place. The type cast is permissible - * because we're conceptually freeing the string and reusing the - * storage. */ - out = (struct lsh_string *) in; - } - else - /* Allocate fresh storage. */ - out = lsh_string_alloc(in->length); - - CRYPT(c, in->length, in->data, out->data); - - return out; -} - -/* FIXME: Missing testcases. This is only used for encrypted private - * keys */ -struct lsh_string * -crypt_string_pad(struct crypto_instance *c, - const struct lsh_string *in, - int free) -{ - struct lsh_string *s; - UINT8 *p; - UINT32 pad = c->block_size - (in->length % c->block_size); - - assert(pad); - - s = ssh_format(free ? "%lfS%lr" : "%lS%lr", in, pad, &p); - /* Use RFC 1423 and "generalized RFC 1423" as described in - * PKCS#5 version 2. */ - memset(p, pad, pad); - - return crypt_string(c, s, 1); -} - -struct lsh_string * -crypt_string_unpad(struct crypto_instance *c, - const struct lsh_string *in, - int free) -{ - struct lsh_string *out; - UINT32 pad; - - assert(in->length); - - out = crypt_string(c, in, free); - pad = out->data[out->length - 1]; - - if ( (pad > 0) && (pad <= c->block_size) ) - { - out->length -= pad; - return out; - } - else - { - lsh_string_free(out); - return NULL; - } -} - - -/* FIXME: These functions don't really belong here. */ - -UINT32 gcd(UINT32 x, UINT32 y) -{ - UINT32 res = 1; - - if (!x) - return y; - if (!y) - return x; - - while (! (x%2) && !(y%2) ) - { - x /= 2; y /= 2; res *= 2; - } - - if (!(x % 2)) - { - /* x is even. Swap */ - UINT32 tmp = x; - x = y; - y = tmp; - } - - for (;;) - { - /* During this loop, x is always odd */ - assert(x % 2); - - if (!y) - return x * res; - - while (!(y % 2)) - y /= 2; - - - if (x < y) - y -= x; - else - { /* x >= y */ - UINT32 d = x-y; - x = y; - y = d; - } - } -} - -UINT32 lcm(UINT32 x, UINT32 y) -{ - UINT32 g = gcd(x, y); - - assert(!(x % g) && ! (y % g)); - - return x * (y / g); -} - diff --git a/lsh/src/abstract_crypto.c.x b/lsh/src/abstract_crypto.c.x deleted file mode 100755 index 9bbf151..0000000 Binary files a/lsh/src/abstract_crypto.c.x and /dev/null differ diff --git a/lsh/src/abstract_crypto.h b/lsh/src/abstract_crypto.h deleted file mode 100755 index 7ce4544..0000000 --- a/lsh/src/abstract_crypto.h +++ /dev/null @@ -1,244 +0,0 @@ -/* abstract_crypto.h - * - * Interface to block cryptos and hash functions - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ABSTRACT_CRYPTO_H_INCLUDED -#define LSH_ABSTRACT_CRYPTO_H_INCLUDED - -#include "list.h" - -/* Use the same instance struct for both hash functions and macs. This - * is a little ugly. */ -#define mac_instance_class hash_instance_class -#define mac_instance hash_instance -#define mac_size hash_size - -#define GABA_DECLARE -#include "abstract_crypto.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name crypto_instance) - (vars - (block_size . UINT32) - ; Length must be a multiple of the block size. - ; NOTE: src == dst is allowed, but no other overlaps. - (crypt method void - "UINT32 length" "const UINT8 *src" "UINT8 *dst"))) -*/ - -#define CRYPT(instance, length, src, dst) \ -((instance)->crypt((instance), (length), (src), (dst))) - -#define CRYPTO_ENCRYPT 0 -#define CRYPTO_DECRYPT 1 - -/* GABA: - (class - (name crypto_algorithm) - (vars - (block_size . UINT32) - (key_size . UINT32) - (iv_size . UINT32) - (make_crypt method (object crypto_instance) - "int mode" "const UINT8 *key" "const UINT8 *iv"))) -*/ - -#define MAKE_CRYPT(crypto, mode, key, iv) \ -((crypto)->make_crypt((crypto), (mode), (key), (iv))) - -#define MAKE_ENCRYPT(crypto, key, iv) \ - MAKE_CRYPT((crypto), CRYPTO_ENCRYPT, (key), (iv)) - -#define MAKE_DECRYPT(crypto, key, iv) \ - MAKE_CRYPT((crypto), CRYPTO_DECRYPT, (key), (iv)) - -/* FIXME: Hashes could use non-virtual methods. */ - -/* GABA: - (class - (name hash_instance) - (vars - (hash_size . UINT32) - (update method void - "UINT32 length" "const UINT8 *data") - (digest method void "UINT8 *result") - - ;; FIXME: Perhaps add an argument which - ;; is a hash instance to copy to. - (copy method (object hash_instance)))) -*/ - -#define HASH_UPDATE(instance, length, data) \ -((instance)->update((instance), (length), (data))) - -#define HASH_DIGEST(instance, result) \ -((instance)->digest((instance), (result))) - -#define HASH_COPY(instance) ((instance)->copy((instance))) - -/* GABA: - (class - (name hash_algorithm) - (vars - (block_size . UINT32) - (hash_size . UINT32) - (make_hash method (object hash_instance)))) -*/ - -#define MAKE_HASH(h) ((h)->make_hash((h))) - -/* GABA: - (class - (name mac_algorithm) - (vars - (hash_size . UINT32) - ; Recommended key size - (key_size . UINT32) - (make_mac method (object mac_instance) - "UINT32 length" "const UINT8 *key"))) -*/ - -#define MAKE_MAC(m, l, key) ((m)->make_mac((m), (l), (key))) - - -/* GABA: - (class - (name verifier) - (vars - (verify method int - "int algorithm" - "UINT32 length" "const UINT8 *data" - "UINT32 signature_length" "const UINT8 *signature_data") - - (verify_spki method int - "UINT32 length" "const UINT8 *data" - "struct sexp *e") - - (public_key method (string)) - - ; Returns ( * ), i.e. the same - ; structure that is expected by spki_make_verifier(). - (public_spki_key method (object sexp)))) -*/ - -#define VERIFY(verifier, algorithm, length, data, slength, sdata) \ -((verifier)->verify((verifier), (algorithm), (length), (data), (slength), (sdata))) - -#define VERIFY_SPKI(verifier, length, data, e) \ -((verifier)->verify_spki((verifier), (length), (data), (e))) - -#define PUBLIC_KEY(signer) ((signer)->public_key((signer))) -#define PUBLIC_SPKI_KEY(signer) ((signer)->public_spki_key((signer))) - - -/* GABA: - (class - (name signer) - (vars - ; Returns a non-spki signature - (sign method (string) - "int algorithm" "UINT32 length" "const UINT8 *data") - ; Returns a sexp - (sign_spki method (object sexp) - "UINT32 length" "const UINT8 *data") - - (get_verifier method (object verifier)))) -*/ - -#define SIGN(signer, algorithm, length, data) \ -((signer)->sign((signer), (algorithm), (length), (data))) -#define SIGN_SPKI(signer, length, data) ((signer)->sign_spki((signer), (length), (data))) -#define SIGNER_GET_VERIFIER(signer) ((signer)->get_verifier((signer))) - - -/* GABA: - (class - (name signature_algorithm) - (vars - ; Iterators should point past the algorithm tag - (make_signer method (object signer) - "struct sexp_iterator *i") - - (make_verifier method (object verifier) - "struct sexp_iterator *i"))) -*/ - -#define MAKE_SIGNER(a, i) \ -((a)->make_signer((a), (i))) - -#define MAKE_VERIFIER(a, i) \ -((a)->make_verifier((a), (i))) - - -/* Combining block cryptos */ - -/* Example: To create a tripple DES cbc encryptor: - * - * struct crypto_algorithm des3_cbc - * = make_cbc(crypto_cascade(3, des_algorithm, - * crypto_invert(des_algorithm) - * des_algorithm, -1)); - */ - -struct crypto_algorithm *crypto_cbc(struct crypto_algorithm *inner); -struct crypto_algorithm *crypto_invert(struct crypto_algorithm *inner); -struct crypto_algorithm *crypto_cascadel(struct object_list *cascade); -struct crypto_algorithm *crypto_cascade(unsigned n, ...); - -/* Utility functions */ -UINT32 gcd(UINT32 x, UINT32 y); -UINT32 lcm(UINT32 x, UINT32 y); - -/* Simple hashing */ -struct lsh_string * -hash_string(struct hash_algorithm *a, - struct lsh_string *in, - int free); - -/* Used only by the testsuite */ -struct lsh_string * -mac_string(struct mac_algorithm *a, - struct lsh_string *key, - int kfree, - struct lsh_string *in, - int ifree); - -struct lsh_string * -crypt_string(struct crypto_instance *c, - const struct lsh_string *in, - int free); - -struct lsh_string * -crypt_string_pad(struct crypto_instance *c, - const struct lsh_string *in, - int free); - -struct lsh_string * -crypt_string_unpad(struct crypto_instance *c, - const struct lsh_string *in, - int free); - -#endif /* LSH_ABSTRACT_CRYPTO_H_INCLUDED */ diff --git a/lsh/src/abstract_crypto.h.x b/lsh/src/abstract_crypto.h.x deleted file mode 100755 index 794f600..0000000 Binary files a/lsh/src/abstract_crypto.h.x and /dev/null differ diff --git a/lsh/src/abstract_io.c b/lsh/src/abstract_io.c deleted file mode 100755 index af0101f..0000000 --- a/lsh/src/abstract_io.c +++ /dev/null @@ -1,30 +0,0 @@ -/* abstract_io.c - * - * This is the layer separating protocol processing from actual io. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "abstract_io.h" - -#define GABA_DEFINE -#include "abstract_io.h.x" -#undef GABA_DEFINE diff --git a/lsh/src/abstract_io.h b/lsh/src/abstract_io.h deleted file mode 100755 index 29e5c4b..0000000 --- a/lsh/src/abstract_io.h +++ /dev/null @@ -1,74 +0,0 @@ -/* abstract_io.h - * - * This is the layer separating protocol processing from actual io. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ABSTRACT_IO_H_INCLUDED -#define LSH_ABSTRACT_IO_H_INCLUDED - -#include "exception.h" - -#define GABA_DECLARE -#include "abstract_io.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name abstract_write) - (vars - (write method void "struct lsh_string *packet"))) -*/ - -#define A_WRITE(f, packet) ((f)->write((f), (packet) )) - -/* A handler that passes packets on to another handler */ -/* GABA: - (class - (name abstract_write_pipe) - (super abstract_write) - (vars - (next object abstract_write))) -*/ - - -/* GABA: - (class - (name read_handler) - (vars - (handler indirect-method - - ; The method returns the amount of data processed. - ; On errors, it can set self to NULL, but only for - ; debugging purposes; it's the responibility of the the - ; exception handler to close the corresponding fd and - ; make sure that handler is not called again. ' - - ; Available is 0 iff we have got EOF. - UINT32 "UINT32 available" "UINT8 *data"))) - "struct exception_handler *e"))) -*/ - -/* May store a new handler into *h. */ -#define READ_HANDLER(h, l, d) ((h)->handler(&(h), (l), (d))) - -#endif /*LSH_ABSTRACT_IO_H_INCLUDED */ diff --git a/lsh/src/abstract_io.h.x b/lsh/src/abstract_io.h.x deleted file mode 100755 index 0b5ef14..0000000 Binary files a/lsh/src/abstract_io.h.x and /dev/null differ diff --git a/lsh/src/algorithms.c b/lsh/src/algorithms.c deleted file mode 100755 index 60366bc..0000000 --- a/lsh/src/algorithms.c +++ /dev/null @@ -1,599 +0,0 @@ -/* algorithms.c - * - * Translate algorithm identifiers (or names) to algorithm objects. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "algorithms.h" - -#include "atoms.h" -#include "compress.h" -#include "crypto.h" -#include "dsa.h" -#include "rsa.h" -#include "xalloc.h" - -#include "lsh_argp.h" - -#include -#include -#include - -#if MACOS -extern int strcasecmp(const char * str1, const char * str2); -#endif - -#define GABA_DEFINE -#include "algorithms.h.x" -#undef GABA_DEFINE - -struct alist * -all_symmetric_algorithms() -{ - struct crypto_algorithm *aes = crypto_cbc(&rijndael256_algorithm); - return make_alist(10 -#if WITH_ZLIB - +1 -#endif - , - ATOM_ARCFOUR, &crypto_arcfour_algorithm, - ATOM_BLOWFISH_CBC, crypto_cbc(&blowfish_algorithm), - ATOM_TWOFISH_CBC, crypto_cbc(&twofish256_algorithm), - ATOM_AES256_CBC, aes, - ATOM_RIJNDAEL_CBC_LOCAL, aes, - ATOM_SERPENT_CBC_LOCAL, crypto_cbc(&serpent256_algorithm), - ATOM_3DES_CBC, crypto_cbc(make_des3()), - ATOM_CAST128_CBC, crypto_cbc(&cast128_algorithm), -#if WITH_IDEA - ATOM_IDEA_CBC, crypto_cbc(&idea_algorithm), -#endif - ATOM_HMAC_SHA1, make_hmac_algorithm(&sha1_algorithm), - ATOM_HMAC_MD5, make_hmac_algorithm(&md5_algorithm), -#if WITH_ZLIB - ATOM_ZLIB, make_zlib(), -#endif - -1); -} - -/* This is used for spki operations, and should therefore use spki names. */ -struct alist * -all_signature_algorithms(struct randomness *r) -{ - return make_alist(3, - ATOM_DSA, make_dsa_algorithm(r), - ATOM_RSA_PKCS1_SHA1, &rsa_sha1_algorithm.super, - ATOM_RSA_PKCS1_MD5, &rsa_md5_algorithm.super, - -1); -} - -/* Forward declaration */ -struct int_list * -filter_algorithms_l(struct alist *algorithms, unsigned n, ...); - -/* Includes only reasonably old algorithms and well studied - * algorithms. */ -static struct int_list * -default_crypto_algorithms(struct alist *algorithms) -{ - return filter_algorithms_l(algorithms, 3, - ATOM_3DES_CBC, - ATOM_BLOWFISH_CBC, - ATOM_ARCFOUR, -1); -} - -/* Includes all supported algorithms, except none. In effect, the - * peer is trusted in choosing an adequate algorithm. */ -static struct int_list * -all_crypto_algorithms(struct alist *algorithms) -{ - return filter_algorithms_l(algorithms, 9, - ATOM_3DES_CBC, - ATOM_TWOFISH_CBC, - ATOM_CAST128_CBC, - ATOM_SERPENT_CBC_LOCAL, - ATOM_AES256_CBC, - ATOM_RIJNDAEL_CBC_LOCAL, - ATOM_IDEA_CBC, - ATOM_BLOWFISH_CBC, - ATOM_ARCFOUR, -1); -} - -static struct int_list * -default_mac_algorithms(struct alist *algorithms) -{ - return filter_algorithms_l(algorithms, 2, ATOM_HMAC_SHA1, ATOM_HMAC_MD5, -1); -} - -static struct int_list * -default_compression_algorithms(struct alist *algorithms) -{ - return filter_algorithms_l(algorithms, 2, ATOM_NONE, ATOM_ZLIB, -1); -} - -static struct int_list * -prefer_compression_algorithms(struct alist *algorithms) -{ - return filter_algorithms_l(algorithms, 2, ATOM_ZLIB, ATOM_NONE, -1); -} - - -/* This is not really efficient, but it doesn't matter. */ -static int strcasecmp_list(const char *name, ...) -{ - va_list args; - char *s; - int res = 0; - - va_start(args, name); - while ( (s = va_arg(args, char *)) ) - { - if (!strcasecmp(name, s)) - { - res = 1; - break; - } - } - va_end(args); - - return res; -} - -int -lookup_crypto(struct alist *algorithms, const char *name, struct crypto_algorithm **ap) -{ - int atom; - - if (!strcasecmp(name, "none")) - { - if (ap) - *ap = NULL; - - return ATOM_NONE; - } - else if (strcasecmp_list(name, "arcfour", NULL)) - atom = ATOM_ARCFOUR; - else if (strcasecmp_list(name, "twofish-cbc", "twofish", NULL)) - atom = ATOM_TWOFISH_CBC; - else if (strcasecmp_list(name, "blowfish-cbc", "blowfish", NULL)) - atom = ATOM_BLOWFISH_CBC; - else if (strcasecmp_list(name, "3des-cbc", "3des", NULL)) - atom = ATOM_3DES_CBC; - else if (strcasecmp_list(name, "aes256-cbc", "aes-cbc", "aes", NULL)) - atom = ATOM_AES256_CBC; - else if (strcasecmp_list(name, "rijndael-cbc@lysator.liu.se", - "rijndael-cbc", "rijndael", NULL)) - atom = ATOM_RIJNDAEL_CBC_LOCAL; - else if (strcasecmp_list(name, "serpent-cbc@lysator.liu.se", - "serpent-cbc", "serpent", NULL)) - atom = ATOM_SERPENT_CBC_LOCAL; - else if (strcasecmp_list(name, "idea-cbc", "idea", NULL)) - atom = ATOM_IDEA_CBC; - else if (strcasecmp_list(name, "cast128-cbc", "cast", - "cast-cbc", "cast128", NULL)) - atom = ATOM_CAST128_CBC; - else - return 0; - - /* Is this crypto supported? */ - { - CAST_SUBTYPE(crypto_algorithm, a, ALIST_GET(algorithms, atom)); - if (a) - { - if (ap) - *ap = a; - - return atom; - } - else - return 0; - } -} - -int -lookup_mac(struct alist *algorithms, const char *name, struct mac_algorithm **ap) -{ - int atom; - - if (!strcasecmp(name, "none")) - { - if (ap) - *ap = NULL; - - return ATOM_NONE; - } - if (strcasecmp_list(name, "hmac-sha1", "sha", "hmac-sha", "sha1", NULL)) - atom = ATOM_HMAC_SHA1; - else if (strcasecmp_list(name, "hmac-md5", "md5", NULL)) - atom = ATOM_HMAC_MD5; - else - return 0; - - /* Is this mac supported? */ - { - CAST_SUBTYPE(mac_algorithm, a, ALIST_GET(algorithms, atom)); - if (a) - { - if (ap) - *ap = a; - - return atom; - } - else - return 0; - } -} - -int -lookup_compression(struct alist *algorithms, const char *name, struct compress_algorithm **ap) -{ - int atom; - - if (!strcasecmp(name, "none")) - { - if (ap) - *ap = NULL; - - return ATOM_NONE; - } - if (strcasecmp_list(name, "zlib", "z", NULL)) - atom = ATOM_ZLIB; - else - return 0; - - /* Is this compression algorithm supported? */ - { - CAST_SUBTYPE(compress_algorithm, a, ALIST_GET(algorithms, atom)); - if (a) - { - if (ap) - *ap = a; - - return atom; - } - else - return 0; - } -} - -int -lookup_hostkey_algorithm(const char *name) -{ - if (!strcasecmp(name, "none")) - return ATOM_NONE; - else if (strcasecmp_list(name, "ssh-dss", "dsa", "dss", NULL)) - return ATOM_SSH_DSS; - else if (strcasecmp_list(name, "spki-sign-rsa", "spki-rsa", NULL)) - return ATOM_SPKI_SIGN_RSA; - else if (strcasecmp_list(name, "spki-sign-dss", "spki-dss", - "spki-sign-dsa", "spki-dsa", NULL)) - return ATOM_SPKI_SIGN_DSS; - else - return 0; -} - -/* This function is used by sexp-conv */ -int -lookup_hash(struct alist *algorithms, const char *name, - struct hash_algorithm **ap, int none_is_valid) -{ - int atom; - - if (none_is_valid && !strcasecmp(name, "none")) - { - if (ap) - *ap = NULL; - - return ATOM_NONE; - } - if (strcasecmp_list(name, "md5", NULL)) - atom = ATOM_MD5; - else if (strcasecmp_list(name, "sha1", NULL)) - atom = ATOM_SHA1; - else - return 0; - - /* Is this hash algorithm supported? */ - { - CAST_SUBTYPE(hash_algorithm, a, ALIST_GET(algorithms, atom)); - if (a) - { - if (ap) - *ap = a; - - return atom; - } - else - return 0; - } -} - -/* FIXME: Perhaps this function belongs in list.c or alist.c? */ - -/* Return an int list containing the elements of CANDIDATES - * that have associated values in ALGORITHMS. - * Returns a non-empty list or NULL. */ - -struct int_list * -filter_algorithms(struct alist *algorithms, - const struct int_list *candidates) -{ - struct int_list *l; - unsigned i, j; - unsigned supported; - - for (i = 0, supported = 0; i < LIST_LENGTH(candidates); i++) - { - int atom = LIST(candidates)[i]; - if (ALIST_GET(algorithms, atom) - || (atom == ATOM_NONE)) - supported++; - } - - if (!supported) - return NULL; - - l = alloc_int_list(supported); - - for (i = j = 0; i < LIST_LENGTH(candidates); i++) - { - int atom = LIST(candidates)[i]; - if (ALIST_GET(algorithms, atom) - || (atom == ATOM_NONE)) - { - assert(j < supported); - LIST(l)[j++] = atom; - } - } - assert(j == supported); - - return l; -} - - -struct int_list * -filter_algorithms_l(struct alist *algorithms, unsigned n, ...) -{ - va_list args; - struct int_list *l; - struct int_list *candidates; - - va_start(args, n); - candidates = make_int_listv(n, args); - va_end(args); - - l = filter_algorithms(algorithms, candidates); - - assert(LIST_LENGTH(l)); - - KILL(candidates); - return l; -} - - -static void -list_algorithms(const struct argp_state *state, - char *prefix, - struct int_list *algorithms, - int none) -{ - unsigned i; - int separate; - - fprintf(state->out_stream, "%s", prefix); - - for (i = 0, separate = 0; iout_stream, ", "); - - fprintf(state->out_stream, "%s", - /* NOTE: This is the only place where we use that - * atom names are NUL-terminated. */ - get_atom_name(LIST(algorithms)[i])); - separate = 1; - } - - if (none) - { - if (separate) - fprintf(state->out_stream, ", "); - fprintf(state->out_stream, "none"); - } -} - -void -list_crypto_algorithms(const struct argp_state *state, - struct alist *algorithms) -{ - list_algorithms(state, - "Supported crypto algorithms: ", - all_crypto_algorithms(algorithms), - 1); -} - -void -list_mac_algorithms(const struct argp_state *state, - struct alist *algorithms) -{ - list_algorithms(state, - "Supported MAC algorithms: ", - default_mac_algorithms(algorithms), - 1); -} - -void -list_compression_algorithms(const struct argp_state *state, - struct alist *algorithms) -{ - list_algorithms(state, - "Supported compression algorithms: ", - default_compression_algorithms(algorithms), - 0); -} - -void -list_hostkey_algorithms(const struct argp_state *state) -{ - fprintf(state->out_stream, "%s", "Supported hostkey algorithms: ssh-dss, spki, none"); -} - - -#define OPT_LIST_ALGORITHMS 0x100 -#define OPT_HOSTKEY_ALGORITHMS 0x101 - -static const struct argp_option -algorithms_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { NULL, 0, NULL, 0, "Algorithm selection:", 0}, - { "crypto", 'c', "Algorithm", 0, "", 0 }, - { "compression", 'z', "Algorithm", - OPTION_ARG_OPTIONAL, "Default is zlib.", 0 }, - { "mac", 'm', "Algorithm", 0, "", 0 }, - { "hostkey-algorithm", OPT_HOSTKEY_ALGORITHMS, "Algorithm", 0, "", 0 }, - { "list-algorithms", OPT_LIST_ALGORITHMS, NULL, 0, - "List supported algorithms.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -void -init_algorithms_options(struct algorithms_options *self, - struct alist *algorithms) -{ - self->algorithms = algorithms; - - self->crypto_algorithms = NULL; - self->mac_algorithms = NULL; - self->compression_algorithms = NULL; - self->hostkey_algorithms = NULL; -} - -struct algorithms_options * -make_algorithms_options(struct alist *algorithms) -{ - NEW(algorithms_options, self); - init_algorithms_options(self, algorithms); - - return self; -} - -static error_t -algorithms_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST_SUBTYPE(algorithms_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_END: - if (!self->crypto_algorithms) - self->crypto_algorithms = default_crypto_algorithms(self->algorithms); - if (!self->mac_algorithms) - self->mac_algorithms = default_mac_algorithms(self->algorithms); - if (!self->compression_algorithms) - self->compression_algorithms = default_compression_algorithms(self->algorithms); - if (!self->hostkey_algorithms) - self->hostkey_algorithms = make_int_list(4, ATOM_SSH_RSA, ATOM_SSH_DSS, - ATOM_SPKI_SIGN_RSA, ATOM_SPKI_SIGN_DSS, -1); - break; - case 'c': - { - int crypto = lookup_crypto(self->algorithms, arg, NULL); - - if (crypto) - self->crypto_algorithms = make_int_list(1, crypto, -1); - else if (strcasecmp_list(arg, "all", "any", NULL)) - self->crypto_algorithms = all_crypto_algorithms(self->algorithms); - - else - { - list_crypto_algorithms(state, self->algorithms); - argp_error(state, "Unknown crypto algorithm '%s'.", arg); - } - break; - } - case 'm': - { - int mac = lookup_mac(self->algorithms, arg, NULL); - if (mac) - self->mac_algorithms = make_int_list(1, mac, -1); - else - { - list_mac_algorithms(state, self->algorithms); - argp_error(state, "Unknown message authentication algorithm '%s'.", arg); - } - break; - } - case 'z': - { - if (!arg) - self->compression_algorithms = prefer_compression_algorithms(self->algorithms); - else - { - int compression = lookup_compression(self->algorithms, arg, NULL); - if (compression) { - // fix attempt for unsupported zlib in OpenSSH 3.4/3.5, add 'none' - if ( compression == ATOM_ZLIB ) - self->compression_algorithms = make_int_list(2, compression, ATOM_NONE, -1); - else - self->compression_algorithms = make_int_list(1, compression, -1); - } else - { - list_compression_algorithms(state, self->algorithms); - argp_error(state, "Unknown compression algorithm '%s'.", arg); - } - } - break; - } - case OPT_HOSTKEY_ALGORITHMS: - { - int algorithm = lookup_hostkey_algorithm(arg); - if (algorithm) - self->hostkey_algorithms = make_int_list(1, algorithm, -1); - else - { - list_hostkey_algorithms(state); - argp_error(state, "Unknown hostkey algorithm '%s'.", arg); - } - break; - - } - - case OPT_LIST_ALGORITHMS: - list_crypto_algorithms(state, self->algorithms); - list_compression_algorithms(state, self->algorithms); - list_mac_algorithms(state, self->algorithms); - list_hostkey_algorithms(state); - - if (! (state->flags & ARGP_NO_EXIT)) - exit (0); - } - return 0; -} - -const struct argp algorithms_argp = -{ - algorithms_options, - algorithms_argp_parser, - NULL, NULL, NULL, NULL, NULL -}; diff --git a/lsh/src/algorithms.h b/lsh/src/algorithms.h deleted file mode 100755 index 4d8de9e..0000000 --- a/lsh/src/algorithms.h +++ /dev/null @@ -1,77 +0,0 @@ -/* algorithms.h - * - * Translate algorithm identifiers (or names) to algorithm objects. - * - * $Id$ */ - -#ifndef LSH_ALGORITHMS_H_INCLUDED -#define LSH_ALGORITHMS_H_INCLUDED - -#include "abstract_compress.h" -#include "alist.h" -#include "lsh_argp.h" -#include "randomness.h" - -#define GABA_DECLARE -#include "algorithms.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name algorithms_options) - (vars - (algorithms object alist) - ; (pubkey_algorithms object alist) - - (crypto_algorithms object int_list) - (mac_algorithms object int_list) - (compression_algorithms object int_list) - (hostkey_algorithms object int_list))) -*/ - -struct alist *all_symmetric_algorithms(void); -struct alist *all_signature_algorithms(struct randomness *r); - -struct int_list * -filter_algorithms(struct alist *algorithms, - const struct int_list *candidates); - -int -lookup_crypto(struct alist *algorithms, const char *name, - struct crypto_algorithm **ap); -int -lookup_mac(struct alist *algorithms, const char *name, - struct mac_algorithm **ap); -int -lookup_compression(struct alist *algorithms, const char *name, - struct compress_algorithm **ap); - -int -lookup_hostkey_algorithm(const char *name); - -int lookup_hash(struct alist *algorithms, const char *name, - struct hash_algorithm **ap, - int none_is_valid); - -void -list_crypto_algorithms(const struct argp_state *state, - struct alist *algorithms); -void -list_mac_algorithms(const struct argp_state *state, - struct alist *algorithms); -void -list_compression_algorithms(const struct argp_state *state, - struct alist *algorithms); - -void -list_hostkey_algorithms(const struct argp_state *state); - -void init_algorithms_options(struct algorithms_options *self, - struct alist *algorithms); - -struct algorithms_options * -make_algorithms_options(struct alist *algorithms); - -extern const struct argp algorithms_argp; - -#endif /* LSH_ALGORITHMS_H_INCLUDED */ diff --git a/lsh/src/algorithms.h.x b/lsh/src/algorithms.h.x deleted file mode 100755 index 75e7ca3..0000000 Binary files a/lsh/src/algorithms.h.x and /dev/null differ diff --git a/lsh/src/alist.c b/lsh/src/alist.c deleted file mode 100755 index 59aad83..0000000 --- a/lsh/src/alist.c +++ /dev/null @@ -1,304 +0,0 @@ -/* alist.c - * - * Associations are implemented as linear tables. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - - -#include "alist.h" - -#include "atoms.h" -#include "list.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "alist.h.x" -#undef GABA_DEFINE - -struct alist * -alist_addv(struct alist *a, unsigned n, va_list args) -{ - unsigned i; - - for (i=0; i= 0); - assert(atom < NUMBER_OF_ATOMS); - - return self->table[atom]; -} - -static void -do_linear_set(struct alist *c, int atom, struct lsh_object *value) -{ - CAST(alist_linear, self, c); - - assert(atom >= 0); - assert(atom < NUMBER_OF_ATOMS); - - self->super.size += !self->table[atom] - !value; - - self->table[atom] = value; -} - -struct alist * -make_linear_alist(unsigned n, ...) -{ - int i; - va_list args; - - NEW(alist_linear, res); - - res->super.size = 0; - - for (i = 0; itable[i] = NULL; - - va_start(args, n); - - alist_addv(&res->super, n, args); - va_end(args); - - return &res->super; -} - -/* NOTE: A linked alist does not have any limit on the size of its keys. */ - -/* GABA: - (class - (name alist_linked) - (super alist) - (meta alist) - (vars - (head special "struct alist_node *" - do_mark_list do_free_list)) - (methods do_linked_get do_linked_set)) -*/ - -static void -do_mark_list(struct alist_node *n, - void (*mark)(struct lsh_object *o)) -{ - while(n) - { - mark(n->value); - n = n->next; - } -} - -static void -do_free_list(struct alist_node *n) -{ - while(n) - { - struct alist_node *old = n; - n = n->next; - lsh_space_free(old); - } -} - -static struct lsh_object * -do_linked_get(struct alist *c, int atom) -{ - CAST(alist_linked, self, c); - struct alist_node *p; - - assert(atom >= 0); - - for (p = self->head; p; p = p->next) - if (p->atom == atom) - return p->value; - - return NULL; -} - -static void -do_linked_set(struct alist *c, int atom, struct lsh_object *value) -{ - CAST(alist_linked, self, c); - - assert(atom >= 0); - - if (value) - { - struct alist_node *p; - - for (p = self->head; p; p = p->next) - if (p->atom == atom) - { - p->value = value; - return; - } - - NEW_SPACE(p); - p->next = self->head; - p->atom = atom; - p->value = value; - - self->head = p; - - self->super.size++; - } - else - { /* Remove atom */ - struct alist_node **p; - - for(p = &self->head; *p; ) - { - struct alist_node *o = *p; - if (o->atom == atom) - { - *p = o->next; - lsh_space_free(o); - - self->super.size--; - return; - } - p = &o->next; - } - /* Not found */ - } -} - -struct alist * -make_linked_alist(unsigned n, ...) -{ - va_list args; - - struct alist *res; - - NEW(alist_linked, self); - res = &self->super; - - res->size = 0; - - self->head = NULL; - - va_start(args, n); - - alist_addv(res, n, args); - va_end(args); - - return res; -} - -/* Copies selected elements from one alist to another. */ - -unsigned -alist_select(struct alist *dst, struct alist *src, - struct int_list *names) -{ - unsigned selected; - unsigned i; - for (i = 0, selected = 0; i < LIST_LENGTH(names); i++) - { - int atom = LIST(names)[i]; - struct lsh_object *o = ALIST_GET(src, atom); - if (o) - { - ALIST_SET(dst, atom, o); - selected ++; - } - } - return selected; -} - -unsigned -alist_select_l(struct alist *dst, struct alist *src, - unsigned n, ...) -{ - va_list args; - struct int_list *names; - unsigned selected; - - va_start(args, n); - names = make_int_listv(n, args); - va_end(args); - - selected = alist_select(dst, src, names); - - KILL(names); - - return selected; -} - diff --git a/lsh/src/alist.c.x b/lsh/src/alist.c.x deleted file mode 100755 index 08e92c6..0000000 Binary files a/lsh/src/alist.c.x and /dev/null differ diff --git a/lsh/src/alist.h b/lsh/src/alist.h deleted file mode 100755 index 407aac3..0000000 --- a/lsh/src/alist.h +++ /dev/null @@ -1,87 +0,0 @@ -/* alist.h - * - * Associate atoms with objects (or functions) . - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ALIST_H_INCLUDED -#define LSH_ALIST_H_INCLUDED - -#include "lsh.h" - -#include - -/* Forward declaration */ -struct alist; - -#define GABA_DECLARE -#include "alist.h.x" -#undef GABA_DECLARE - -/* Abstract interface allows for multiple implementations ("real" - * alists, linear tables, hash tables */ - -/* GABA: - (meta - (name alist) - (methods - "struct lsh_object * (*get)(struct alist *self, int atom)" - "void (*set)(struct alist *self, int atom, struct lsh_object *value)")) -*/ - -/* GABA: - (class - (name alist) - (meta alist) - (vars - (size . unsigned)) - ; Only subclasses has methods - (methods NULL NULL)) -*/ - -#define ALIST_CLASS(l) ((struct alist_meta *) ((l)->super.isa)) - -#define ALIST_GET(alist, atom) \ - (ALIST_CLASS(alist)->get((alist), (atom))) - -#define ALIST_SET(alist, atom, value) \ - (ALIST_CLASS(alist)->set((alist), (atom), (value))) - -struct alist *alist_addv(struct alist *a, unsigned n, va_list args); - -/* n is the number of pairs. The argument list should be terminated - * with -1, for sanity checks. */ - -struct alist *make_linear_alist(unsigned n, ...); -struct alist *make_linked_alist(unsigned n, ...); - -#define make_alist make_linear_alist - -unsigned -alist_select(struct alist *dst, struct alist *src, - struct int_list *names); - -unsigned -alist_select_l(struct alist *dst, struct alist *src, - unsigned n, ...); - -#endif /* LSH_ALIST_H_INCLUDED */ diff --git a/lsh/src/alist.h.x b/lsh/src/alist.h.x deleted file mode 100755 index c806a98..0000000 Binary files a/lsh/src/alist.h.x and /dev/null differ diff --git a/lsh/src/arcfour.c b/lsh/src/arcfour.c deleted file mode 100755 index 1754de9..0000000 --- a/lsh/src/arcfour.c +++ /dev/null @@ -1,69 +0,0 @@ -/* arcfour.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/arcfour.h" - -#include "arcfour.c.x" - -/* GABA: - (class - (name arcfour_instance) - (super crypto_instance) - (vars - (ctx . "struct arcfour_ctx"))) -*/ - -static void do_crypt_arcfour(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(arcfour_instance, self, s); - - if (length % 8) - fatal("Internal error\n"); - - arcfour_crypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_arcfour_instance(struct crypto_algorithm *ignored UNUSED, - int mode UNUSED, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(arcfour_instance, self); - - self->super.block_size = 8; - self->super.crypt = do_crypt_arcfour; - - arcfour_set_key(&self->ctx, 16, key); - - return &self->super; -} - -struct crypto_algorithm crypto_arcfour_algorithm = -{ STATIC_HEADER, - 8, 16, 0, make_arcfour_instance }; diff --git a/lsh/src/arcfour.c.x b/lsh/src/arcfour.c.x deleted file mode 100755 index 7b16c2b..0000000 Binary files a/lsh/src/arcfour.c.x and /dev/null differ diff --git a/lsh/src/argp/Makefile.am b/lsh/src/argp/Makefile.am deleted file mode 100755 index f5efe19..0000000 Binary files a/lsh/src/argp/Makefile.am and /dev/null differ diff --git a/lsh/src/argp/Makefile.in b/lsh/src/argp/Makefile.in deleted file mode 100755 index 8cc3d8a..0000000 --- a/lsh/src/argp/Makefile.in +++ /dev/null @@ -1,408 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# From glibc - -# Copyright (C) 1997 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Library General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. - -# The GNU C Library 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 -# Library General Public License for more details. - -# You should have received a copy of the GNU Library General Public -# License along with the GNU C Library; see the file COPYING.LIB. If -# not, write to the Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = . - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -LIBOBJS = @LIBOBJS@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -VERSION = @VERSION@ - -AUTOMAKE_OPTIONS = foreign - -noinst_LIBRARIES = libargp.a -noinst_PROGRAMS = argp-test -noinst_HEADERS = argp.h argp-fmtstream.h argp-namefrob.h # argp-comp.h - -EXTRA_DIST = mempcpy.c strchrnul.c strndup.c Versions - -# Leaves out argp-fs-xinl.c and argp-xinl.c -libargp_a_SOURCES = argp-ba.c argp-eexst.c argp-fmtstream.c argp-help.c argp-parse.c argp-pv.c argp-pvh.c argp-eexst.c - - -libargp_a_LIBADD = @LIBOBJS@ - -argp_test_LDADD = libargp.a -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs -CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = -LIBRARIES = $(noinst_LIBRARIES) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -libargp_a_DEPENDENCIES = @LIBOBJS@ -libargp_a_OBJECTS = argp-ba.o argp-eexst.o argp-fmtstream.o argp-help.o \ -argp-parse.o argp-pv.o argp-pvh.o argp-eexst.o -AR = ar -PROGRAMS = $(noinst_PROGRAMS) - -argp_test_SOURCES = argp-test.c -argp_test_OBJECTS = argp-test.o -argp_test_DEPENDENCIES = libargp.a -argp_test_LDFLAGS = -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -HEADERS = $(noinst_HEADERS) - -DIST_COMMON = ./stamp-h.in Makefile.am Makefile.in acconfig.h \ -acinclude.m4 aclocal.m4 config.h.in configure configure.in mempcpy.c \ -strchrnul.c strndup.c - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = $(libargp_a_SOURCES) argp-test.c -OBJECTS = $(libargp_a_OBJECTS) argp-test.o - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -$(ACLOCAL_M4): configure.in acinclude.m4 - cd $(srcdir) && $(ACLOCAL) - -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) - -config.h: stamp-h - @if test ! -f $@; then \ - rm -f stamp-h; \ - $(MAKE) stamp-h; \ - else :; fi -stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=config.h \ - $(SHELL) ./config.status - @echo timestamp > stamp-h 2> /dev/null -$(srcdir)/config.h.in: $(srcdir)/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/stamp-h.in; \ - $(MAKE) $(srcdir)/stamp-h.in; \ - else :; fi -$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f config.h - -maintainer-clean-hdr: - -mostlyclean-noinstLIBRARIES: - -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) - -distclean-noinstLIBRARIES: - -maintainer-clean-noinstLIBRARIES: - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -libargp.a: $(libargp_a_OBJECTS) $(libargp_a_DEPENDENCIES) - -rm -f libargp.a - $(AR) cru libargp.a $(libargp_a_OBJECTS) $(libargp_a_LIBADD) - $(RANLIB) libargp.a - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -argp-test: $(argp_test_OBJECTS) $(argp_test_DEPENDENCIES) - @rm -f argp-test - $(LINK) $(argp_test_LDFLAGS) $(argp_test_OBJECTS) $(argp_test_LDADD) $(LIBS) - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - -rm -rf $(distdir) - GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz - mkdir $(distdir)/=build - mkdir $(distdir)/=inst - dc_install_base=`cd $(distdir)/=inst && pwd`; \ - cd $(distdir)/=build \ - && ../configure --srcdir=.. --prefix=$$dc_install_base \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) dist - -rm -rf $(distdir) - @banner="$(distdir).tar.gz is ready for distribution"; \ - dashes=`echo "$$banner" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - echo "$$dashes" -dist: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -dist-all: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -distdir: $(DISTFILES) - -rm -rf $(distdir) - mkdir $(distdir) - -chmod 777 $(distdir) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -argp-ba.o: argp-ba.c -argp-eexst.o: argp-eexst.c config.h argp.h -argp-fmtstream.o: argp-fmtstream.c config.h argp-fmtstream.h \ - argp-namefrob.h -argp-help.o: argp-help.c config.h argp.h argp-fmtstream.h \ - argp-namefrob.h -argp-parse.o: argp-parse.c config.h argp.h argp-namefrob.h -argp-pv.o: argp-pv.c -argp-pvh.o: argp-pvh.c config.h argp.h -argp-test.o: argp-test.c config.h argp.h - -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -all-recursive-am: config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(HEADERS) config.h -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-hdr mostlyclean-noinstLIBRARIES \ - mostlyclean-compile mostlyclean-noinstPROGRAMS \ - mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-hdr clean-noinstLIBRARIES clean-compile \ - clean-noinstPROGRAMS clean-tags clean-generic \ - mostlyclean-am - -clean: clean-am - -distclean-am: distclean-hdr distclean-noinstLIBRARIES distclean-compile \ - distclean-noinstPROGRAMS distclean-tags \ - distclean-generic clean-am - -distclean: distclean-am - -rm -f config.status - -maintainer-clean-am: maintainer-clean-hdr \ - maintainer-clean-noinstLIBRARIES \ - maintainer-clean-compile \ - maintainer-clean-noinstPROGRAMS maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -rm -f config.status - -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ -clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile mostlyclean-noinstPROGRAMS \ -distclean-noinstPROGRAMS clean-noinstPROGRAMS \ -maintainer-clean-noinstPROGRAMS tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ -check-am installcheck-am installcheck all-recursive-am install-exec-am \ -install-exec install-data-am install-data install-am install \ -uninstall-am uninstall all-redirect all-am all installdirs \ -mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean - - -all: libargp.a - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/argp/Versions b/lsh/src/argp/Versions deleted file mode 100755 index df2fafd..0000000 Binary files a/lsh/src/argp/Versions and /dev/null differ diff --git a/lsh/src/argp/acconfig.h b/lsh/src/argp/acconfig.h deleted file mode 100755 index 48a6469..0000000 --- a/lsh/src/argp/acconfig.h +++ /dev/null @@ -1,3 +0,0 @@ -/* Global variables needed by argp */ -#undef HAVE_PROGRAM_INVOCATION_NAME -#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME diff --git a/lsh/src/argp/acinclude.m4 b/lsh/src/argp/acinclude.m4 deleted file mode 100755 index 952d9bf..0000000 Binary files a/lsh/src/argp/acinclude.m4 and /dev/null differ diff --git a/lsh/src/argp/aclocal.m4 b/lsh/src/argp/aclocal.m4 deleted file mode 100755 index ba2c4c2..0000000 --- a/lsh/src/argp/aclocal.m4 +++ /dev/null @@ -1,228 +0,0 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4 - -dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without -dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A -dnl PARTICULAR PURPOSE. - -dnl ARGP_CHECK_VAR(VAR, INCLUDES) -AC_DEFUN(ARGP_CHECK_VAR, -[ AC_CACHE_CHECK( - [for $1], - lsh_cv_var_$1, - AC_TRY_LINK([$2], [void *p = (void *) &$1;], - [lsh_cv_var_$1=yes], - [lsh_cv_var_$1=no])) - if eval "test \"`echo '$lsh_cv_var_'$1`\" = yes"; then - AC_DEFINE_UNQUOTED(HAVE_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`) - fi -]) - -# Do all the work for Automake. This macro actually does too much -- -# some checks are only needed if your package does certain things. -# But this isn't really a big deal. - -# serial 1 - -dnl Usage: -dnl AM_INIT_AUTOMAKE(package,version, [no-define]) - -AC_DEFUN(AM_INIT_AUTOMAKE, -[AC_REQUIRE([AC_PROG_INSTALL]) -PACKAGE=[$1] -AC_SUBST(PACKAGE) -VERSION=[$2] -AC_SUBST(VERSION) -dnl test to see if srcdir already configured -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) -fi -ifelse([$3],, -AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) -AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) -AC_REQUIRE([AM_SANITY_CHECK]) -AC_REQUIRE([AC_ARG_PROGRAM]) -dnl FIXME This is truly gross. -missing_dir=`cd $ac_aux_dir && pwd` -AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) -AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) -AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) -AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) -AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) -AC_REQUIRE([AC_PROG_MAKE_SET])]) - -# -# Check to make sure that the build environment is sane. -# - -AC_DEFUN(AM_SANITY_CHECK, -[AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "[$]*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "[$]*" != "X $srcdir/configure conftestfile" \ - && test "[$]*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi - - test "[$]2" = conftestfile - ) -then - # Ok. - : -else - AC_MSG_ERROR([newly created file is older than distributed files! -Check your system clock]) -fi -rm -f conftest* -AC_MSG_RESULT(yes)]) - -dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) -dnl The program must properly implement --version. -AC_DEFUN(AM_MISSING_PROG, -[AC_MSG_CHECKING(for working $2) -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if ($2 --version) < /dev/null > /dev/null 2>&1; then - $1=$2 - AC_MSG_RESULT(found) -else - $1="$3/missing $2" - AC_MSG_RESULT(missing) -fi -AC_SUBST($1)]) - -# Like AC_CONFIG_HEADER, but automatically create stamp file. - -AC_DEFUN(AM_CONFIG_HEADER, -[AC_PREREQ([2.12]) -AC_CONFIG_HEADER([$1]) -dnl When config.status generates a header, we must update the stamp-h file. -dnl This file resides in the same directory as the config header -dnl that is generated. We must strip everything past the first ":", -dnl and everything past the last "/". -AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl -ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>, -<>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>, -<>; do - case " <<$>>CONFIG_HEADERS " in - *" <<$>>am_file "*<<)>> - echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx - ;; - esac - am_indx=`expr "<<$>>am_indx" + 1` -done<<>>dnl>>) -changequote([,]))]) - - -# serial 1 - -# @defmac AC_PROG_CC_STDC -# @maindex PROG_CC_STDC -# @ovindex CC -# If the C compiler in not in ANSI C mode by default, try to add an option -# to output variable @code{CC} to make it so. This macro tries various -# options that select ANSI C on some system or another. It considers the -# compiler to be in ANSI C mode if it handles function prototypes correctly. -# -# If you use this macro, you should check after calling it whether the C -# compiler has been set to accept ANSI C; if not, the shell variable -# @code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source -# code in ANSI C, you can make an un-ANSIfied copy of it by using the -# program @code{ansi2knr}, which comes with Ghostscript. -# @end defmac - -AC_DEFUN(AM_PROG_CC_STDC, -[AC_REQUIRE([AC_PROG_CC]) -AC_BEFORE([$0], [AC_C_INLINE]) -AC_BEFORE([$0], [AC_C_CONST]) -dnl Force this before AC_PROG_CPP. Some cpp's, eg on HPUX, require -dnl a magic option to avoid problems with ANSI preprocessor commands -dnl like #elif. -dnl FIXME: can't do this because then AC_AIX won't work due to a -dnl circular dependency. -dnl AC_BEFORE([$0], [AC_PROG_CPP]) -AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C) -AC_CACHE_VAL(am_cv_prog_cc_stdc, -[am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - AC_TRY_COMPILE( -[#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -], [ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; -], -[am_cv_prog_cc_stdc="$ac_arg"; break]) -done -CC="$ac_save_CC" -]) -if test -z "$am_cv_prog_cc_stdc"; then - AC_MSG_RESULT([none needed]) -else - AC_MSG_RESULT($am_cv_prog_cc_stdc) -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac -]) - diff --git a/lsh/src/argp/argp-ba.c b/lsh/src/argp/argp-ba.c deleted file mode 100755 index 5657c27..0000000 --- a/lsh/src/argp/argp-ba.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Default definition for ARGP_PROGRAM_BUG_ADDRESS. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* If set by the user program, it should point to string that is the - bug-reporting address for the program. It will be printed by argp_help if - the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help - messages), embedded in a sentence that says something like `Report bugs to - ADDR.'. */ -const char *argp_program_bug_address; diff --git a/lsh/src/argp/argp-eexst.c b/lsh/src/argp/argp-eexst.c deleted file mode 100755 index 9040058..0000000 --- a/lsh/src/argp/argp-eexst.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Default definition for ARGP_ERR_EXIT_STATUS - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "argp.h" - -/* The exit status that argp will use when exiting due to a parsing error. - If not defined or set by the user program, this defaults to EX_USAGE from - . */ -error_t argp_err_exit_status = EX_USAGE; diff --git a/lsh/src/argp/argp-fmtstream.c b/lsh/src/argp/argp-fmtstream.c deleted file mode 100755 index 53f595b..0000000 --- a/lsh/src/argp/argp-fmtstream.c +++ /dev/null @@ -1,479 +0,0 @@ -/* Word-wrapping and line-truncating streams - Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* This package emulates glibc `line_wrap_stream' semantics for systems that - don't have that. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "argp-fmtstream.h" -#include "argp-namefrob.h" - -#ifndef ARGP_FMTSTREAM_USE_LINEWRAP - -#ifndef isblank -#define isblank(ch) ((ch)==' ' || (ch)=='\t') -#endif - -#if defined _LIBC && defined USE_IN_LIBIO -# include -# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a) -#endif - -#define INIT_BUF_SIZE 200 -#define PRINTF_SIZE_GUESS 150 - -/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines - written on it with LMARGIN spaces and limits them to RMARGIN columns - total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by - replacing the whitespace before them with a newline and WMARGIN spaces. - Otherwise, chars beyond RMARGIN are simply dropped until a newline. - Returns NULL if there was an error. */ -argp_fmtstream_t -__argp_make_fmtstream (FILE *stream, - size_t lmargin, size_t rmargin, ssize_t wmargin) -{ - argp_fmtstream_t fs = malloc (sizeof (struct argp_fmtstream)); - if (fs) - { - fs->stream = stream; - - fs->lmargin = lmargin; - fs->rmargin = rmargin; - fs->wmargin = wmargin; - fs->point_col = 0; - fs->point_offs = 0; - - fs->buf = malloc (INIT_BUF_SIZE); - if (! fs->buf) - { - free (fs); - fs = 0; - } - else - { - fs->p = fs->buf; - fs->end = fs->buf + INIT_BUF_SIZE; - } - } - - return fs; -} -#ifdef weak_alias -weak_alias (__argp_make_fmtstream, argp_make_fmtstream) -#endif - -/* Flush FS to its stream, and free it (but don't close the stream). */ -void -__argp_fmtstream_free (argp_fmtstream_t fs) -{ - __argp_fmtstream_update (fs); - if (fs->p > fs->buf) - fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); - free (fs->buf); - free (fs); -} -#ifdef weak_alias -weak_alias (__argp_fmtstream_free, argp_fmtstream_free) -#endif - -/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the - end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ -void -__argp_fmtstream_update (argp_fmtstream_t fs) -{ - char *buf, *nl; - size_t len; - - /* Scan the buffer for newlines. */ - buf = fs->buf + fs->point_offs; - while (buf < fs->p) - { - size_t r; - - if (fs->point_col == 0 && fs->lmargin != 0) - { - /* We are starting a new line. Print spaces to the left margin. */ - const size_t pad = fs->lmargin; - if (fs->p + pad < fs->end) - { - /* We can fit in them in the buffer by moving the - buffer text up and filling in the beginning. */ - memmove (buf + pad, buf, fs->p - buf); - fs->p += pad; /* Compensate for bigger buffer. */ - memset (buf, ' ', pad); /* Fill in the spaces. */ - buf += pad; /* Don't bother searching them. */ - } - else - { - /* No buffer space for spaces. Must flush. */ - size_t i; - for (i = 0; i < pad; i++) - putc_unlocked (' ', fs->stream); - } - fs->point_col = pad; - } - - len = fs->p - buf; - nl = memchr (buf, '\n', len); - - if (fs->point_col < 0) - fs->point_col = 0; - - if (!nl) - { - /* The buffer ends in a partial line. */ - - if (fs->point_col + len < fs->rmargin) - { - /* The remaining buffer text is a partial line and fits - within the maximum line width. Advance point for the - characters to be written and stop scanning. */ - fs->point_col += len; - break; - } - else - /* Set the end-of-line pointer for the code below to - the end of the buffer. */ - nl = fs->p; - } - else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) - { - /* The buffer contains a full line that fits within the maximum - line width. Reset point and scan the next line. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - - /* This line is too long. */ - r = fs->rmargin - 1; - - if (fs->wmargin < 0) - { - /* Truncate the line by overwriting the excess with the - newline and anything after it in the buffer. */ - if (nl < fs->p) - { - memmove (buf + (r - fs->point_col), nl, fs->p - nl); - fs->p -= buf + (r - fs->point_col) - nl; - /* Reset point for the next line and start scanning it. */ - fs->point_col = 0; - buf += r + 1; /* Skip full line plus \n. */ - } - else - { - /* The buffer ends with a partial line that is beyond the - maximum line width. Advance point for the characters - written, and discard those past the max from the buffer. */ - fs->point_col += len; - fs->p -= fs->point_col - r; - break; - } - } - else - { - /* Do word wrap. Go to the column just past the maximum line - width and scan back for the beginning of the word there. - Then insert a line break. */ - - char *p, *nextline; - int i; - - p = buf + (r + 1 - fs->point_col); - while (p >= buf && !isblank (*p)) - --p; - nextline = p + 1; /* This will begin the next line. */ - - if (nextline > buf) - { - /* Swallow separating blanks. */ - if (p >= buf) - do - --p; - while (p >= buf && isblank (*p)); - nl = p + 1; /* The newline will replace the first blank. */ - } - else - { - /* A single word that is greater than the maximum line width. - Oh well. Put it on an overlong line by itself. */ - p = buf + (r + 1 - fs->point_col); - /* Find the end of the long word. */ - do - ++p; - while (p < nl && !isblank (*p)); - if (p == nl) - { - /* It already ends a line. No fussing required. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - /* We will move the newline to replace the first blank. */ - nl = p; - /* Swallow separating blanks. */ - do - ++p; - while (isblank (*p)); - /* The next line will start here. */ - nextline = p; - } - - /* Note: There are a bunch of tests below for - NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall - at the end of the buffer, and NEXTLINE is in fact empty (and so - we need not be careful to maintain its contents). */ - - if (nextline == buf + len + 1 - ? fs->end - nl < fs->wmargin + 1 - : nextline - (nl + 1) < fs->wmargin) - { - /* The margin needs more blanks than we removed. */ - if (fs->end - fs->p > fs->wmargin + 1) - /* Make some space for them. */ - { - size_t mv = fs->p - nextline; - memmove (nl + 1 + fs->wmargin, nextline, mv); - nextline = nl + 1 + fs->wmargin; - len = nextline + mv - buf; - *nl++ = '\n'; - } - else - /* Output the first line so we can use the space. */ - { - if (nl > fs->buf) - fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); - putc_unlocked ('\n', fs->stream); - len += buf - fs->buf; - nl = buf = fs->buf; - } - } - else - /* We can fit the newline and blanks in before - the next word. */ - *nl++ = '\n'; - - if (nextline - nl >= fs->wmargin - || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) - /* Add blanks up to the wrap margin column. */ - for (i = 0; i < fs->wmargin; ++i) - *nl++ = ' '; - else - for (i = 0; i < fs->wmargin; ++i) - putc_unlocked (' ', fs->stream); - - /* Copy the tail of the original buffer into the current buffer - position. */ - if (nl < nextline) - memmove (nl, nextline, buf + len - nextline); - len -= nextline - buf; - - /* Continue the scan on the remaining lines in the buffer. */ - buf = nl; - - /* Restore bufp to include all the remaining text. */ - fs->p = nl + len; - - /* Reset the counter of what has been output this line. If wmargin - is 0, we want to avoid the lmargin getting added, so we set - point_col to a magic value of -1 in that case. */ - fs->point_col = fs->wmargin ? fs->wmargin : -1; - } - } - - /* Remember that we've scanned as far as the end of the buffer. */ - fs->point_offs = fs->p - fs->buf; -} - -/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by - growing the buffer, or by flushing it. True is returned iff we succeed. */ -int -__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) -{ - if ((size_t) (fs->end - fs->p) < amount) - { - ssize_t wrote; - - /* Flush FS's buffer. */ - __argp_fmtstream_update (fs); - - wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); - if (wrote == fs->p - fs->buf) - { - fs->p = fs->buf; - fs->point_offs = 0; - } - else - { - fs->p -= wrote; - fs->point_offs -= wrote; - memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf); - return 0; - } - - if ((size_t) (fs->end - fs->buf) < amount) - /* Gotta grow the buffer. */ - { - size_t new_size = fs->end - fs->buf + amount; - char *new_buf = realloc (fs->buf, new_size); - - if (! new_buf) - { - __set_errno (ENOMEM); - return 0; - } - - fs->buf = new_buf; - fs->end = new_buf + new_size; - fs->p = fs->buf; - } - } - - return 1; -} - -ssize_t -__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...) -{ - size_t out; - size_t avail; - size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */ - - do - { - va_list args; - - if (! __argp_fmtstream_ensure (fs, size_guess)) - return -1; - - va_start (args, fmt); - avail = fs->end - fs->p; - out = __vsnprintf (fs->p, avail, fmt, args); - va_end (args); - if (out >= avail) - size_guess = out + 1; - } - while (out >= avail); - - fs->p += out; - - return out; -} -#ifdef weak_alias -weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf) -#endif - -#if __MC68K__ - -/* Duplicate the inline definitions in argp-fmtstream.h, for compilers - * that don't do inlining. */ -size_t -__argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len) -{ - if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) - { - memcpy (__fs->p, __str, __len); - __fs->p += __len; - return __len; - } - else - return 0; -} - -int -__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str) -{ - size_t __len = strlen (__str); - if (__len) - { - size_t __wrote = __argp_fmtstream_write (__fs, __str, __len); - return __wrote == __len ? 0 : -1; - } - else - return 0; -} - -int -__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch) -{ - if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1)) - return *__fs->p++ = __ch; - else - return EOF; -} - -/* Set __FS's left margin to __LMARGIN and return the old value. */ -size_t -__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->lmargin; - __fs->lmargin = __lmargin; - return __old; -} - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -size_t -__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->rmargin; - __fs->rmargin = __rmargin; - return __old; -} - -/* Set FS's wrap margin to __WMARGIN and return the old value. */ -size_t -__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->wmargin; - __fs->wmargin = __wmargin; - return __old; -} - -/* Return the column number of the current output point in __FS. */ -size_t -__argp_fmtstream_point (argp_fmtstream_t __fs) -{ - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - return __fs->point_col >= 0 ? __fs->point_col : 0; -} - -#endif /* __MC68K__ */ - -#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */ diff --git a/lsh/src/argp/argp-fmtstream.h b/lsh/src/argp/argp-fmtstream.h deleted file mode 100755 index ac44645..0000000 --- a/lsh/src/argp/argp-fmtstream.h +++ /dev/null @@ -1,322 +0,0 @@ -/* Word-wrapping and line-truncating streams. - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* This package emulates glibc `line_wrap_stream' semantics for systems that - don't have that. If the system does have it, it is just a wrapper for - that. This header file is only used internally while compiling argp, and - shouldn't be installed. */ - -#ifndef _ARGP_FMTSTREAM_H -#define _ARGP_FMTSTREAM_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#if !_LIBC -# if ! (defined (HAVE_FLOCKFILE) && defined(HAVE_PUTC_UNLOCKED) \ - && defined (HAVE_FPUTS_UNLOCKED) && defined (HAVE_FWRITE_UNLOCKED) ) - -/* Don't use stdio locking */ - -# define flockfile(f) -# define funlockfile(f) -# define putc_unlocked(c, f) putc((c), (f)) -# define fputs_unlocked(s, f) fputs((s), (f)) -# define fwrite_unlocked(b, s, n, f) fwrite((b), (s), (n), (f)) -# endif /* No thread safe i/o */ -#endif /* !_LIBC */ - -#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \ - || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)) -/* line_wrap_stream is available, so use that. */ -#define ARGP_FMTSTREAM_USE_LINEWRAP -#endif - -#ifdef ARGP_FMTSTREAM_USE_LINEWRAP -/* Just be a simple wrapper for line_wrap_stream; the semantics are - *slightly* different, as line_wrap_stream doesn't actually make a new - object, it just modifies the given stream (reversibly) to do - line-wrapping. Since we control who uses this code, it doesn't matter. */ - -#include - -typedef FILE *argp_fmtstream_t; - -#define argp_make_fmtstream line_wrap_stream -#define __argp_make_fmtstream line_wrap_stream -#define argp_fmtstream_free line_unwrap_stream -#define __argp_fmtstream_free line_unwrap_stream - -#define __argp_fmtstream_putc(fs,ch) putc(ch,fs) -#define argp_fmtstream_putc(fs,ch) putc(ch,fs) -#define __argp_fmtstream_puts(fs,str) fputs(str,fs) -#define argp_fmtstream_puts(fs,str) fputs(str,fs) -#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) -#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) -#define __argp_fmtstream_printf fprintf -#define argp_fmtstream_printf fprintf - -#define __argp_fmtstream_lmargin line_wrap_lmargin -#define argp_fmtstream_lmargin line_wrap_lmargin -#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin -#define argp_fmtstream_set_lmargin line_wrap_set_lmargin -#define __argp_fmtstream_rmargin line_wrap_rmargin -#define argp_fmtstream_rmargin line_wrap_rmargin -#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin -#define argp_fmtstream_set_rmargin line_wrap_set_rmargin -#define __argp_fmtstream_wmargin line_wrap_wmargin -#define argp_fmtstream_wmargin line_wrap_wmargin -#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin -#define argp_fmtstream_set_wmargin line_wrap_set_wmargin -#define __argp_fmtstream_point line_wrap_point -#define argp_fmtstream_point line_wrap_point - -#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */ -/* Guess we have to define our own version. */ - -#ifndef __const -#define __const const -#endif - -/* FIXME: We could use a configure test to check for __attribute__, - * just like lsh does. */ -#ifndef PRINTF_STYLE -# if __GNUC__ >= 2 -# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) -# else -# define PRINTF_STYLE(f, a) -# endif -#endif - - -struct argp_fmtstream -{ - FILE *stream; /* The stream we're outputting to. */ - - size_t lmargin, rmargin; /* Left and right margins. */ - ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ - - /* Point in buffer to which we've processed for wrapping, but not output. */ - size_t point_offs; - /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ - ssize_t point_col; - - char *buf; /* Output buffer. */ - char *p; /* Current end of text in BUF. */ - char *end; /* Absolute end of BUF. */ -}; - -typedef struct argp_fmtstream *argp_fmtstream_t; - -/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines - written on it with LMARGIN spaces and limits them to RMARGIN columns - total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by - replacing the whitespace before them with a newline and WMARGIN spaces. - Otherwise, chars beyond RMARGIN are simply dropped until a newline. - Returns NULL if there was an error. */ -extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); -extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); - -/* Flush __FS to its stream, and free it (but don't close the stream). */ -extern void __argp_fmtstream_free (argp_fmtstream_t __fs); -extern void argp_fmtstream_free (argp_fmtstream_t __fs); - -extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, - __const char *__fmt, ...) - PRINTF_STYLE(2,3); -extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, - __const char *__fmt, ...) - PRINTF_STYLE(2,3); - -extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); -extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); - -extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str); -extern int argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str); - -extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len); -extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len); - -/* Access macros for various bits of state. */ -#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin) -#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin) -#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin) -#define __argp_fmtstream_lmargin argp_fmtstream_lmargin -#define __argp_fmtstream_rmargin argp_fmtstream_rmargin -#define __argp_fmtstream_wmargin argp_fmtstream_wmargin - -/* Set __FS's left margin to LMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); -extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); -extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); - -/* Set __FS's wrap margin to __WMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); -extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); - -/* Return the column number of the current output point in __FS. */ -extern size_t argp_fmtstream_point (argp_fmtstream_t __fs); -extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs); - -/* Internal routines. */ -extern void _argp_fmtstream_update (argp_fmtstream_t __fs); -extern void __argp_fmtstream_update (argp_fmtstream_t __fs); -extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); -extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); - -#ifdef __OPTIMIZE__ -/* Inline versions of above routines. */ - -#if !_LIBC -#define __argp_fmtstream_putc argp_fmtstream_putc -#define __argp_fmtstream_puts argp_fmtstream_puts -#define __argp_fmtstream_write argp_fmtstream_write -#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin -#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin -#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin -#define __argp_fmtstream_point argp_fmtstream_point -#define __argp_fmtstream_update _argp_fmtstream_update -#define __argp_fmtstream_ensure _argp_fmtstream_ensure -#endif - -#ifndef ARGP_FS_EI -#define ARGP_FS_EI extern inline -#endif - -ARGP_FS_EI size_t -__argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len) -{ - if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) - { - memcpy (__fs->p, __str, __len); - __fs->p += __len; - return __len; - } - else - return 0; -} - -ARGP_FS_EI int -__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str) -{ - size_t __len = strlen (__str); - if (__len) - { - size_t __wrote = __argp_fmtstream_write (__fs, __str, __len); - return __wrote == __len ? 0 : -1; - } - else - return 0; -} - -ARGP_FS_EI int -__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch) -{ - if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1)) - return *__fs->p++ = __ch; - else - return EOF; -} - -/* Set __FS's left margin to __LMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->lmargin; - __fs->lmargin = __lmargin; - return __old; -} - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->rmargin; - __fs->rmargin = __rmargin; - return __old; -} - -/* Set FS's wrap margin to __WMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->wmargin; - __fs->wmargin = __wmargin; - return __old; -} - -/* Return the column number of the current output point in __FS. */ -ARGP_FS_EI size_t -__argp_fmtstream_point (argp_fmtstream_t __fs) -{ - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - return __fs->point_col >= 0 ? __fs->point_col : 0; -} - -#if !_LIBC -#undef __argp_fmtstream_putc -#undef __argp_fmtstream_puts -#undef __argp_fmtstream_write -#undef __argp_fmtstream_set_lmargin -#undef __argp_fmtstream_set_rmargin -#undef __argp_fmtstream_set_wmargin -#undef __argp_fmtstream_point -#undef __argp_fmtstream_update -#undef __argp_fmtstream_ensure -#endif - -#endif /* __OPTIMIZE__ */ - -#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */ - -#endif /* argp-fmtstream.h */ diff --git a/lsh/src/argp/argp-help.c b/lsh/src/argp/argp-help.c deleted file mode 100755 index eeb3102..0000000 --- a/lsh/src/argp/argp-help.c +++ /dev/null @@ -1,1890 +0,0 @@ -/* Hierarchial argument parsing help output - Copyright (C) 1995,1996,1997,1998,1999,2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifndef alloca -# ifdef __GNUC__ -# define alloca __builtin_alloca -# define HAVE_ALLOCA 1 -# else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca -char *alloca (); -# endif -# endif -# endif -# endif -#endif - -#include -#include -#include -#include -#include -#ifndef MACOS -#include -#endif -#include - - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. */ -# if defined HAVE_LIBINTL_H || defined _LIBC -# include -# ifdef _LIBC -# undef dgettext -# define dgettext(domain, msgid) __dcgettext (domain, msgid, LC_MESSAGES) -# endif -# else -# define dgettext(domain, msgid) (msgid) -# endif -#endif - -#include "argp.h" -#include "argp-fmtstream.h" -#include "argp-namefrob.h" - - -/* FIXME: We could use a configure test to check for __attribute__, - * just like lsh does. */ -#ifndef UNUSED -# if __GNUC__ >= 2 -# define UNUSED __attribute__ ((__unused__)) -# else -# define UNUSED -# endif -#endif - -#ifndef _LIBC -# ifndef __strchrnul -# define __strchrnul strchrnul -# endif -# ifndef __mempcpy -# define __mempcpy mempcpy -# endif -/* We need to use a different name, as __strndup is likely a macro. */ -# define STRNDUP strndup -# ifndef __flockfile -# define __flockfile flockfile -# endif -# ifndef __funlockfile -# define __funlockfile funlockfile -# endif -# if HAVE_STRERROR -# define STRERROR strerror -# else -# define STRERROR(x) (sys_errlist[x]) -# endif -#else /* _LIBC */ -# define STRNDUP __strndup -# define STRERROR strerror -#endif - -#if !_LIBC -# if !HAVE_STRNDUP -char *strndup (const char *s, size_t size); -# endif /* !HAVE_STRNDUP */ - -# if !HAVE_MEMPCPY -void *mempcpy (void *to, const void *from, size_t size); -# endif /* !HAVE_MEMPCPY */ - -# if !HAVE_STRCHRNUL -char *strchrnul(const char *s, int c); -# endif /* !HAVE_STRCHRNUL */ - -#endif /* !_LIBC */ - - -/* User-selectable (using an environment variable) formatting parameters. - - These may be specified in an environment variable called `ARGP_HELP_FMT', - with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2 - Where VALn must be a positive integer. The list of variables is in the - UPARAM_NAMES vector, below. */ - -/* Default parameters. */ -#define DUP_ARGS 0 /* True if option argument can be duplicated. */ -#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */ -#define SHORT_OPT_COL 2 /* column in which short options start */ -#define LONG_OPT_COL 6 /* column in which long options start */ -#define DOC_OPT_COL 2 /* column in which doc options start */ -#define OPT_DOC_COL 29 /* column in which option text starts */ -#define HEADER_COL 1 /* column in which group headers are printed */ -#define USAGE_INDENT 12 /* indentation of wrapped usage lines */ -#define RMARGIN 79 /* right margin used for wrapping */ - -/* User-selectable (using an environment variable) formatting parameters. - They must all be of type `int' for the parsing code to work. */ -struct uparams -{ - /* If true, arguments for an option are shown with both short and long - options, even when a given option has both, e.g. `-x ARG, --longx=ARG'. - If false, then if an option has both, the argument is only shown with - the long one, e.g., `-x, --longx=ARG', and a message indicating that - this really means both is printed below the options. */ - int dup_args; - - /* This is true if when DUP_ARGS is false, and some duplicate arguments have - been suppressed, an explanatory message should be printed. */ - int dup_args_note; - - /* Various output columns. */ - int short_opt_col; - int long_opt_col; - int doc_opt_col; - int opt_doc_col; - int header_col; - int usage_indent; - int rmargin; - - int valid; /* True when the values in here are valid. */ -}; - -/* This is a global variable, as user options are only ever read once. */ -static struct uparams uparams = { - DUP_ARGS, DUP_ARGS_NOTE, - SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL, - USAGE_INDENT, RMARGIN, - 0 -}; - -/* A particular uparam, and what the user name is. */ -struct uparam_name -{ - const char *name; /* User name. */ - int is_bool; /* Whether it's `boolean'. */ - size_t uparams_offs; /* Location of the (int) field in UPARAMS. */ -}; - -/* The name-field mappings we know about. */ -static const struct uparam_name uparam_names[] = -{ - { "dup-args", 1, offsetof (struct uparams, dup_args) }, - { "dup-args-note", 1, offsetof (struct uparams, dup_args_note) }, - { "short-opt-col", 0, offsetof (struct uparams, short_opt_col) }, - { "long-opt-col", 0, offsetof (struct uparams, long_opt_col) }, - { "doc-opt-col", 0, offsetof (struct uparams, doc_opt_col) }, - { "opt-doc-col", 0, offsetof (struct uparams, opt_doc_col) }, - { "header-col", 0, offsetof (struct uparams, header_col) }, - { "usage-indent", 0, offsetof (struct uparams, usage_indent) }, - { "rmargin", 0, offsetof (struct uparams, rmargin) }, - { 0 } -}; - -/* Read user options from the environment, and fill in UPARAMS appropiately. */ -static void -fill_in_uparams (const struct argp_state *state) -{ - /* FIXME: Can we get away without an explicit cast? */ - const unsigned char *var = (unsigned char *) getenv ("ARGP_HELP_FMT"); - -#define SKIPWS(p) do { while (isspace (*p)) p++; } while (0); - - if (var) - /* Parse var. */ - while (*var) - { - SKIPWS (var); - - if (isalpha (*var)) - { - size_t var_len; - const struct uparam_name *un; - int unspec = 0, val = 0; - const unsigned char *arg = var; - - while (isalnum (*arg) || *arg == '-' || *arg == '_') - arg++; - var_len = arg - var; - - SKIPWS (arg); - - if (*arg == '\0' || *arg == ',') - unspec = 1; - else if (*arg == '=') - { - arg++; - SKIPWS (arg); - } - - if (unspec) - { - if (var[0] == 'n' && var[1] == 'o' && var[2] == '-') - { - val = 0; - var += 3; - var_len -= 3; - } - else - val = 1; - } - else if (isdigit (*arg)) - { - val = atoi (arg); - while (isdigit (*arg)) - arg++; - SKIPWS (arg); - } - - for (un = uparam_names; un->name; un++) - if (strlen (un->name) == var_len - && strncmp (var, un->name, var_len) == 0) - { - if (unspec && !un->is_bool) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, "\ -%.*s: ARGP_HELP_FMT parameter requires a value"), - (int) var_len, var); - else - *(int *)((char *)&uparams + un->uparams_offs) = val; - break; - } - if (! un->name) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, "\ -%.*s: Unknown ARGP_HELP_FMT parameter"), - (int) var_len, var); - - var = arg; - if (*var == ',') - var++; - } - else if (*var) - { - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "Garbage in ARGP_HELP_FMT: %s"), var); - break; - } - } -} - -/* Returns true if OPT hasn't been marked invisible. Visibility only affects - whether OPT is displayed or used in sorting, not option shadowing. */ -#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN)) - -/* Returns true if OPT is an alias for an earlier option. */ -#define oalias(opt) ((opt)->flags & OPTION_ALIAS) - -/* Returns true if OPT is an documentation-only entry. */ -#define odoc(opt) ((opt)->flags & OPTION_DOC) - -/* Returns true if OPT is the end-of-list marker for a list of options. */ -#define oend(opt) __option_is_end (opt) - -/* Returns true if OPT has a short option. */ -#define oshort(opt) __option_is_short (opt) - -/* - The help format for a particular option is like: - - -xARG, -yARG, --long1=ARG, --long2=ARG Documentation... - - Where ARG will be omitted if there's no argument, for this option, or - will be surrounded by "[" and "]" appropiately if the argument is - optional. The documentation string is word-wrapped appropiately, and if - the list of options is long enough, it will be started on a separate line. - If there are no short options for a given option, the first long option is - indented slighly in a way that's supposed to make most long options appear - to be in a separate column. - - For example, the following output (from ps): - - -p PID, --pid=PID List the process PID - --pgrp=PGRP List processes in the process group PGRP - -P, -x, --no-parent Include processes without parents - -Q, --all-fields Don't elide unusable fields (normally if there's - some reason ps can't print a field for any - process, it's removed from the output entirely) - -r, --reverse, --gratuitously-long-reverse-option - Reverse the order of any sort - --session[=SID] Add the processes from the session SID (which - defaults to the sid of the current process) - - Here are some more options: - -f ZOT, --foonly=ZOT Glork a foonly - -z, --zaza Snit a zar - - -?, --help Give this help list - --usage Give a short usage message - -V, --version Print program version - - The struct argp_option array for the above could look like: - - { - {"pid", 'p', "PID", 0, "List the process PID"}, - {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"}, - {"no-parent", 'P', 0, 0, "Include processes without parents"}, - {0, 'x', 0, OPTION_ALIAS}, - {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" - " if there's some reason ps can't" - " print a field for any process, it's" - " removed from the output entirely)" }, - {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, - {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, - {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL, - "Add the processes from the session" - " SID (which defaults to the sid of" - " the current process)" }, - - {0,0,0,0, "Here are some more options:"}, - {"foonly", 'f', "ZOT", 0, "Glork a foonly"}, - {"zaza", 'z', 0, 0, "Snit a zar"}, - - {0} - } - - Note that the last three options are automatically supplied by argp_parse, - unless you tell it not to with ARGP_NO_HELP. - -*/ - -/* Returns true if CH occurs between BEG and END. */ -static int -find_char (char ch, char *beg, char *end) -{ - while (beg < end) - if (*beg == ch) - return 1; - else - beg++; - return 0; -} - -struct hol_cluster; /* fwd decl */ - -struct hol_entry -{ - /* First option. */ - const struct argp_option *opt; - /* Number of options (including aliases). */ - unsigned num; - - /* A pointers into the HOL's short_options field, to the first short option - letter for this entry. The order of the characters following this point - corresponds to the order of options pointed to by OPT, and there are at - most NUM. A short option recorded in a option following OPT is only - valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's - probably been shadowed by some other entry). */ - char *short_options; - - /* Entries are sorted by their group first, in the order: - 1, 2, ..., n, 0, -m, ..., -2, -1 - and then alphabetically within each group. The default is 0. */ - int group; - - /* The cluster of options this entry belongs to, or 0 if none. */ - struct hol_cluster *cluster; - - /* The argp from which this option came. */ - const struct argp *argp; -}; - -/* A cluster of entries to reflect the argp tree structure. */ -struct hol_cluster -{ - /* A descriptive header printed before options in this cluster. */ - const char *header; - - /* Used to order clusters within the same group with the same parent, - according to the order in which they occurred in the parent argp's child - list. */ - int index; - - /* How to sort this cluster with respect to options and other clusters at the - same depth (clusters always follow options in the same group). */ - int group; - - /* The cluster to which this cluster belongs, or 0 if it's at the base - level. */ - struct hol_cluster *parent; - - /* The argp from which this cluster is (eventually) derived. */ - const struct argp *argp; - - /* The distance this cluster is from the root. */ - int depth; - - /* Clusters in a given hol are kept in a linked list, to make freeing them - possible. */ - struct hol_cluster *next; -}; - -/* A list of options for help. */ -struct hol -{ - /* An array of hol_entry's. */ - struct hol_entry *entries; - /* The number of entries in this hol. If this field is zero, the others - are undefined. */ - unsigned num_entries; - - /* A string containing all short options in this HOL. Each entry contains - pointers into this string, so the order can't be messed with blindly. */ - char *short_options; - - /* Clusters of entries in this hol. */ - struct hol_cluster *clusters; -}; - -/* Create a struct hol from the options in ARGP. CLUSTER is the - hol_cluster in which these entries occur, or 0, if at the root. */ -static struct hol * -make_hol (const struct argp *argp, struct hol_cluster *cluster) -{ - char *so; - const struct argp_option *o; - const struct argp_option *opts = argp->options; - struct hol_entry *entry; - unsigned num_short_options = 0; - struct hol *hol = malloc (sizeof (struct hol)); - - assert (hol); - - hol->num_entries = 0; - hol->clusters = 0; - - if (opts) - { - int cur_group = 0; - - /* The first option must not be an alias. */ - assert (! oalias (opts)); - - /* Calculate the space needed. */ - for (o = opts; ! oend (o); o++) - { - if (! oalias (o)) - hol->num_entries++; - if (oshort (o)) - num_short_options++; /* This is an upper bound. */ - } - - hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries); - hol->short_options = malloc (num_short_options + 1); - - assert (hol->entries && hol->short_options); - - /* Fill in the entries. */ - so = hol->short_options; - for (o = opts, entry = hol->entries; ! oend (o); entry++) - { - entry->opt = o; - entry->num = 0; - entry->short_options = so; - entry->group = cur_group = - o->group - ? o->group - : ((!o->name && !o->key) - ? cur_group + 1 - : cur_group); - entry->cluster = cluster; - entry->argp = argp; - - do - { - entry->num++; - if (oshort (o) && ! find_char (o->key, hol->short_options, so)) - /* O has a valid short option which hasn't already been used.*/ - *so++ = o->key; - o++; - } - while (! oend (o) && oalias (o)); - } - *so = '\0'; /* null terminated so we can find the length */ - } - - return hol; -} - -/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the - associated argp child list entry), INDEX, and PARENT, and return a pointer - to it. ARGP is the argp that this cluster results from. */ -static struct hol_cluster * -hol_add_cluster (struct hol *hol, int group, const char *header, int index, - struct hol_cluster *parent, const struct argp *argp) -{ - struct hol_cluster *cl = malloc (sizeof (struct hol_cluster)); - if (cl) - { - cl->group = group; - cl->header = header; - - cl->index = index; - cl->parent = parent; - cl->argp = argp; - cl->depth = parent ? parent->depth + 1 : 0; - - cl->next = hol->clusters; - hol->clusters = cl; - } - return cl; -} - -/* Free HOL and any resources it uses. */ -static void -hol_free (struct hol *hol) -{ - struct hol_cluster *cl = hol->clusters; - - while (cl) - { - struct hol_cluster *next = cl->next; - free (cl); - cl = next; - } - - if (hol->num_entries > 0) - { - free (hol->entries); - free (hol->short_options); - } - - free (hol); -} - -static inline int -hol_entry_short_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) -{ - unsigned nopts; - int val = 0; - const struct argp_option *opt, *real = entry->opt; - char *so = entry->short_options; - - for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) - if (oshort (opt) && *so == opt->key) - { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - so++; - } - - return val; -} - -static inline int -hol_entry_long_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) -{ - unsigned nopts; - int val = 0; - const struct argp_option *opt, *real = entry->opt; - - for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) - if (opt->name) - { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - } - - return val; -} - -/* Iterator that returns true for the first short option. */ -static inline int -until_short (const struct argp_option *opt, const struct argp_option *real UNUSED, - const char *domain UNUSED, void *cookie UNUSED) -{ - return oshort (opt) ? opt->key : 0; -} - -/* Returns the first valid short option in ENTRY, or 0 if there is none. */ -static char -hol_entry_first_short (const struct hol_entry *entry) -{ - return hol_entry_short_iterate (entry, until_short, - entry->argp->argp_domain, 0); -} - -/* Returns the first valid long option in ENTRY, or 0 if there is none. */ -static const char * -hol_entry_first_long (const struct hol_entry *entry) -{ - const struct argp_option *opt; - unsigned num; - for (opt = entry->opt, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - return opt->name; - return 0; -} - -/* Returns the entry in HOL with the long option name NAME, or 0 if there is - none. */ -static struct hol_entry * -hol_find_entry (struct hol *hol, const char *name) -{ - struct hol_entry *entry = hol->entries; - unsigned num_entries = hol->num_entries; - - while (num_entries-- > 0) - { - const struct argp_option *opt = entry->opt; - unsigned num_opts = entry->num; - - while (num_opts-- > 0) - if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0) - return entry; - else - opt++; - - entry++; - } - - return 0; -} - -/* If an entry with the long option NAME occurs in HOL, set it's special - sort position to GROUP. */ -static void -hol_set_group (struct hol *hol, const char *name, int group) -{ - struct hol_entry *entry = hol_find_entry (hol, name); - if (entry) - entry->group = group; -} - -/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1. - EQ is what to return if GROUP1 and GROUP2 are the same. */ -static int -group_cmp (int group1, int group2, int eq) -{ - if (group1 == group2) - return eq; - else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0)) - return group1 - group2; - else - return group2 - group1; -} - -/* Compare clusters CL1 & CL2 by the order that they should appear in - output. */ -static int -hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2) -{ - /* If one cluster is deeper than the other, use its ancestor at the same - level, so that finding the common ancestor is straightforward. */ - while (cl1->depth < cl2->depth) - cl1 = cl1->parent; - while (cl2->depth < cl1->depth) - cl2 = cl2->parent; - - /* Now reduce both clusters to their ancestors at the point where both have - a common parent; these can be directly compared. */ - while (cl1->parent != cl2->parent) - cl1 = cl1->parent, cl2 = cl2->parent; - - return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index); -} - -/* Return the ancestor of CL that's just below the root (i.e., has a parent - of 0). */ -static struct hol_cluster * -hol_cluster_base (struct hol_cluster *cl) -{ - while (cl->parent) - cl = cl->parent; - return cl; -} - -/* Return true if CL1 is a child of CL2. */ -static int -hol_cluster_is_child (const struct hol_cluster *cl1, - const struct hol_cluster *cl2) -{ - while (cl1 && cl1 != cl2) - cl1 = cl1->parent; - return cl1 == cl2; -} - -/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail - that should be used for comparisons, and returns true iff it should be - treated as a non-option. */ - -/* FIXME: Can we use unsigned char * for the argument? */ -static int -canon_doc_option (const char **name) -{ - int non_opt; - /* Skip initial whitespace. */ - while (isspace ( (unsigned char) **name)) - (*name)++; - /* Decide whether this looks like an option (leading `-') or not. */ - non_opt = (**name != '-'); - /* Skip until part of name used for sorting. */ - while (**name && !isalnum ( (unsigned char) **name)) - (*name)++; - return non_opt; -} - -/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help - listing. */ -static int -hol_entry_cmp (const struct hol_entry *entry1, - const struct hol_entry *entry2) -{ - /* The group numbers by which the entries should be ordered; if either is - in a cluster, then this is just the group within the cluster. */ - int group1 = entry1->group, group2 = entry2->group; - - if (entry1->cluster != entry2->cluster) - { - /* The entries are not within the same cluster, so we can't compare them - directly, we have to use the appropiate clustering level too. */ - if (! entry1->cluster) - /* ENTRY1 is at the `base level', not in a cluster, so we have to - compare it's group number with that of the base cluster in which - ENTRY2 resides. Note that if they're in the same group, the - clustered option always comes laster. */ - return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1); - else if (! entry2->cluster) - /* Likewise, but ENTRY2's not in a cluster. */ - return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1); - else - /* Both entries are in clusters, we can just compare the clusters. */ - return hol_cluster_cmp (entry1->cluster, entry2->cluster); - } - else if (group1 == group2) - /* The entries are both in the same cluster and group, so compare them - alphabetically. */ - { - int short1 = hol_entry_first_short (entry1); - int short2 = hol_entry_first_short (entry2); - int doc1 = odoc (entry1->opt); - int doc2 = odoc (entry2->opt); - /* FIXME: Can we use unsigned char * instead? */ - const char *long1 = hol_entry_first_long (entry1); - const char *long2 = hol_entry_first_long (entry2); - - if (doc1) - doc1 = canon_doc_option (&long1); - if (doc2) - doc2 = canon_doc_option (&long2); - - if (doc1 != doc2) - /* `documentation' options always follow normal options (or - documentation options that *look* like normal options). */ - return doc1 - doc2; - else if (!short1 && !short2 && long1 && long2) - /* Only long options. */ - return __strcasecmp (long1, long2); - else - /* Compare short/short, long/short, short/long, using the first - character of long options. Entries without *any* valid - options (such as options with OPTION_HIDDEN set) will be put - first, but as they're not displayed, it doesn't matter where - they are. */ - { - unsigned char first1 = short1 ? short1 : long1 ? *long1 : 0; - unsigned char first2 = short2 ? short2 : long2 ? *long2 : 0; -#ifdef _tolower - int lower_cmp = _tolower (first1) - _tolower (first2); -#else - int lower_cmp = tolower (first1) - tolower (first2); -#endif - /* Compare ignoring case, except when the options are both the - same letter, in which case lower-case always comes first. */ - /* NOTE: The subtraction below does the right thing - even with eight-bit chars: first1 and first2 are - converted to int *before* the subtraction. */ - return lower_cmp ? lower_cmp : first2 - first1; - } - } - else - /* Within the same cluster, but not the same group, so just compare - groups. */ - return group_cmp (group1, group2, 0); -} - -/* Version of hol_entry_cmp with correct signature for qsort. */ -static int -hol_entry_qcmp (const void *entry1_v, const void *entry2_v) -{ - return hol_entry_cmp (entry1_v, entry2_v); -} - -/* Sort HOL by group and alphabetically by option name (with short options - taking precedence over long). Since the sorting is for display purposes - only, the shadowing of options isn't effected. */ -static void -hol_sort (struct hol *hol) -{ - if (hol->num_entries > 0) - qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry), - hol_entry_qcmp); -} - -/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow - any in MORE with the same name. */ -static void -hol_append (struct hol *hol, struct hol *more) -{ - struct hol_cluster **cl_end = &hol->clusters; - - /* Steal MORE's cluster list, and add it to the end of HOL's. */ - while (*cl_end) - cl_end = &(*cl_end)->next; - *cl_end = more->clusters; - more->clusters = 0; - - /* Merge entries. */ - if (more->num_entries > 0) - { - if (hol->num_entries == 0) - { - hol->num_entries = more->num_entries; - hol->entries = more->entries; - hol->short_options = more->short_options; - more->num_entries = 0; /* Mark MORE's fields as invalid. */ - } - else - /* Append the entries in MORE to those in HOL, taking care to only add - non-shadowed SHORT_OPTIONS values. */ - { - unsigned left; - char *so, *more_so; - struct hol_entry *e; - unsigned num_entries = hol->num_entries + more->num_entries; - struct hol_entry *entries = - malloc (num_entries * sizeof (struct hol_entry)); - unsigned hol_so_len = strlen (hol->short_options); - char *short_options = - malloc (hol_so_len + strlen (more->short_options) + 1); - - __mempcpy (__mempcpy (entries, hol->entries, - hol->num_entries * sizeof (struct hol_entry)), - more->entries, - more->num_entries * sizeof (struct hol_entry)); - - __mempcpy (short_options, hol->short_options, hol_so_len); - - /* Fix up the short options pointers from HOL. */ - for (e = entries, left = hol->num_entries; left > 0; e++, left--) - e->short_options += (short_options - hol->short_options); - - /* Now add the short options from MORE, fixing up its entries - too. */ - so = short_options + hol_so_len; - more_so = more->short_options; - for (left = more->num_entries; left > 0; e++, left--) - { - int opts_left; - const struct argp_option *opt; - - e->short_options = so; - - for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--) - { - int ch = *more_so; - if (oshort (opt) && ch == opt->key) - /* The next short option in MORE_SO, CH, is from OPT. */ - { - if (! find_char (ch, short_options, - short_options + hol_so_len)) - /* The short option CH isn't shadowed by HOL's options, - so add it to the sum. */ - *so++ = ch; - more_so++; - } - } - } - - *so = '\0'; - - free (hol->entries); - free (hol->short_options); - - hol->entries = entries; - hol->num_entries = num_entries; - hol->short_options = short_options; - } - } - - hol_free (more); -} - -/* Inserts enough spaces to make sure STREAM is at column COL. */ -static void -indent_to (argp_fmtstream_t stream, unsigned col) -{ - int needed = col - __argp_fmtstream_point (stream); - while (needed-- > 0) - __argp_fmtstream_putc (stream, ' '); -} - -/* Output to STREAM either a space, or a newline if there isn't room for at - least ENSURE characters before the right margin. */ -static void -space (argp_fmtstream_t stream, size_t ensure) -{ - if (__argp_fmtstream_point (stream) + ensure - >= __argp_fmtstream_rmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - else - __argp_fmtstream_putc (stream, ' '); -} - -/* If the option REAL has an argument, we print it in using the printf - format REQ_FMT or OPT_FMT depending on whether it's a required or - optional argument. */ -static void -arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt, - const char *domain UNUSED, argp_fmtstream_t stream) -{ - if (real->arg) - { - if (real->flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, opt_fmt, - dgettext (domain, real->arg)); - else - __argp_fmtstream_printf (stream, req_fmt, - dgettext (domain, real->arg)); - } -} - -/* Helper functions for hol_entry_help. */ - -/* State used during the execution of hol_help. */ -struct hol_help_state -{ - /* PREV_ENTRY should contain the previous entry printed, or 0. */ - struct hol_entry *prev_entry; - - /* If an entry is in a different group from the previous one, and SEP_GROUPS - is true, then a blank line will be printed before any output. */ - int sep_groups; - - /* True if a duplicate option argument was suppressed (only ever set if - UPARAMS.dup_args is false). */ - int suppressed_dup_arg; -}; - -/* Some state used while printing a help entry (used to communicate with - helper functions). See the doc for hol_entry_help for more info, as most - of the fields are copied from its arguments. */ -struct pentry_state -{ - const struct hol_entry *entry; - argp_fmtstream_t stream; - struct hol_help_state *hhstate; - - /* True if nothing's been printed so far. */ - int first; - - /* If non-zero, the state that was used to print this help. */ - const struct argp_state *state; -}; - -/* If a user doc filter should be applied to DOC, do so. */ -static const char * -filter_doc (const char *doc, int key, const struct argp *argp, - const struct argp_state *state) -{ - if (argp->help_filter) - /* We must apply a user filter to this output. */ - { - void *input = __argp_input (argp, state); - return (*argp->help_filter) (key, doc, input); - } - else - /* No filter. */ - return doc; -} - -/* Prints STR as a header line, with the margin lines set appropiately, and - notes the fact that groups should be separated with a blank line. ARGP is - the argp that should dictate any user doc filtering to take place. Note - that the previous wrap margin isn't restored, but the left margin is reset - to 0. */ -static void -print_header (const char *str, const struct argp *argp, - struct pentry_state *pest) -{ - const char *tstr = dgettext (argp->argp_domain, str); - const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); - - if (fstr) - { - if (*fstr) - { - if (pest->hhstate->prev_entry) - /* Precede with a blank line. */ - __argp_fmtstream_putc (pest->stream, '\n'); - indent_to (pest->stream, uparams.header_col); - __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col); - __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col); - __argp_fmtstream_puts (pest->stream, fstr); - __argp_fmtstream_set_lmargin (pest->stream, 0); - __argp_fmtstream_putc (pest->stream, '\n'); - } - - pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */ - } - - if (fstr != tstr) - free ((char *) fstr); -} - -/* Inserts a comma if this isn't the first item on the line, and then makes - sure we're at least to column COL. If this *is* the first item on a line, - prints any pending whitespace/headers that should precede this line. Also - clears FIRST. */ -static void -comma (unsigned col, struct pentry_state *pest) -{ - if (pest->first) - { - const struct hol_entry *pe = pest->hhstate->prev_entry; - const struct hol_cluster *cl = pest->entry->cluster; - - if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group) - __argp_fmtstream_putc (pest->stream, '\n'); - - if (cl && cl->header && *cl->header - && (!pe - || (pe->cluster != cl - && !hol_cluster_is_child (pe->cluster, cl)))) - /* If we're changing clusters, then this must be the start of the - ENTRY's cluster unless that is an ancestor of the previous one - (in which case we had just popped into a sub-cluster for a bit). - If so, then print the cluster's header line. */ - { - int old_wm = __argp_fmtstream_wmargin (pest->stream); - print_header (cl->header, cl->argp, pest); - __argp_fmtstream_set_wmargin (pest->stream, old_wm); - } - - pest->first = 0; - } - else - __argp_fmtstream_puts (pest->stream, ", "); - - indent_to (pest->stream, col); -} - -/* Print help for ENTRY to STREAM. */ -static void -hol_entry_help (struct hol_entry *entry, const struct argp_state *state, - argp_fmtstream_t stream, struct hol_help_state *hhstate) -{ - unsigned num; - const struct argp_option *real = entry->opt, *opt; - char *so = entry->short_options; - int have_long_opt = 0; /* We have any long options. */ - /* Saved margins. */ - int old_lm = __argp_fmtstream_set_lmargin (stream, 0); - int old_wm = __argp_fmtstream_wmargin (stream); - /* PEST is a state block holding some of our variables that we'd like to - share with helper functions. */ -#ifdef __GNUC__ - struct pentry_state pest = { entry, stream, hhstate, 1, state }; -#else /* !__GNUC__ */ - /* Decent initializers are a GNU extension */ - struct pentry_state pest; - pest.entry = entry; - pest.stream = stream; - pest.hhstate = hhstate; - pest.first = 1; - pest.state = state; -#endif /* !__GNUC__ */ - - if (! odoc (real)) - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - have_long_opt = 1; - break; - } - - /* First emit short options. */ - __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */ - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (oshort (opt) && opt->key == *so) - /* OPT has a valid (non shadowed) short option. */ - { - if (ovisible (opt)) - { - comma (uparams.short_opt_col, &pest); - __argp_fmtstream_putc (stream, '-'); - __argp_fmtstream_putc (stream, *so); - if (!have_long_opt || uparams.dup_args) - arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - so++; - } - - /* Now, long options. */ - if (odoc (real)) - /* A `documentation' option. */ - { - __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col); - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - comma (uparams.doc_opt_col, &pest); - /* Calling gettext here isn't quite right, since sorting will - have been done on the original; but documentation options - should be pretty rare anyway... */ - __argp_fmtstream_puts (stream, - dgettext (state->root_argp->argp_domain, - opt->name)); - } - } - else - /* A real long option. */ - { - int first_long_opt = 1; - - __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col); - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - comma (uparams.long_opt_col, &pest); - __argp_fmtstream_printf (stream, "--%s", opt->name); - if (first_long_opt || uparams.dup_args) - arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, - stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - } - - /* Next, documentation strings. */ - __argp_fmtstream_set_lmargin (stream, 0); - - if (pest.first) - { - /* Didn't print any switches, what's up? */ - if (!oshort (real) && !real->name) - /* This is a group header, print it nicely. */ - print_header (real->doc, entry->argp, &pest); - else - /* Just a totally shadowed option or null header; print nothing. */ - goto cleanup; /* Just return, after cleaning up. */ - } - else - { - const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain, - real->doc) : 0; - const char *fstr = filter_doc (tstr, real->key, entry->argp, state); - if (fstr && *fstr) - { - unsigned int col = __argp_fmtstream_point (stream); - - __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col); - __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col); - - if (col > (unsigned int) (uparams.opt_doc_col + 3)) - __argp_fmtstream_putc (stream, '\n'); - else if (col >= (unsigned int) uparams.opt_doc_col) - __argp_fmtstream_puts (stream, " "); - else - indent_to (stream, uparams.opt_doc_col); - - __argp_fmtstream_puts (stream, fstr); - } - if (fstr && fstr != tstr) - free ((char *) fstr); - - /* Reset the left margin. */ - __argp_fmtstream_set_lmargin (stream, 0); - __argp_fmtstream_putc (stream, '\n'); - } - - hhstate->prev_entry = entry; - -cleanup: - __argp_fmtstream_set_lmargin (stream, old_lm); - __argp_fmtstream_set_wmargin (stream, old_wm); -} - -/* Output a long help message about the options in HOL to STREAM. */ -static void -hol_help (struct hol *hol, const struct argp_state *state, - argp_fmtstream_t stream) -{ - unsigned num; - struct hol_entry *entry; - struct hol_help_state hhstate = { 0, 0, 0 }; - - for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--) - hol_entry_help (entry, state, stream, &hhstate); - - if (hhstate.suppressed_dup_arg && uparams.dup_args_note) - { - const char *tstr = dgettext (state->root_argp->argp_domain, "\ -Mandatory or optional arguments to long options are also mandatory or \ -optional for any corresponding short options."); - const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE, - state ? state->root_argp : 0, state); - if (fstr && *fstr) - { - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, fstr); - __argp_fmtstream_putc (stream, '\n'); - } - if (fstr && fstr != tstr) - free ((char *) fstr); - } -} - -/* Helper functions for hol_usage. */ - -/* If OPT is a short option without an arg, append its key to the string - pointer pointer to by COOKIE, and advance the pointer. */ -static int -add_argless_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain UNUSED, void *cookie) -{ - char **snao_end = cookie; - if (!(opt->arg || real->arg) - && !((opt->flags | real->flags) & OPTION_NO_USAGE)) - *(*snao_end)++ = opt->key; - return 0; -} - -/* If OPT is a short option with an arg, output a usage entry for it to the - stream pointed at by COOKIE. */ -static int -usage_argful_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain UNUSED, void *cookie) -{ - argp_fmtstream_t stream = cookie; - const char *arg = opt->arg; - int flags = opt->flags | real->flags; - - if (! arg) - arg = real->arg; - - if (arg && !(flags & OPTION_NO_USAGE)) - { - arg = dgettext (domain, arg); - - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); - else - { - /* Manually do line wrapping so that it (probably) won't - get wrapped at the embedded space. */ - space (stream, 6 + strlen (arg)); - __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg); - } - } - - return 0; -} - -/* Output a usage entry for the long option opt to the stream pointed at by - COOKIE. */ -static int -usage_long_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain UNUSED, void *cookie) -{ - argp_fmtstream_t stream = cookie; - const char *arg = opt->arg; - int flags = opt->flags | real->flags; - - if (! arg) - arg = real->arg; - - if (! (flags & OPTION_NO_USAGE)) - { - if (arg) - { - arg = dgettext (domain, arg); - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); - else - __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg); - } - else - __argp_fmtstream_printf (stream, " [--%s]", opt->name); - } - - return 0; -} - -/* Print a short usage description for the arguments in HOL to STREAM. */ -static void -hol_usage (struct hol *hol, argp_fmtstream_t stream) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - if (hol->num_entries > 0) - { - unsigned nentries; - struct hol_entry *entry; - char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1); - char *snao_end = short_no_arg_opts; - - /* First we put a list of short options without arguments. */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, add_argless_short_opt, - entry->argp->argp_domain, &snao_end); - if (snao_end > short_no_arg_opts) - { - *snao_end++ = 0; - __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); - } - - /* Now a list of short options *with* arguments. */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, usage_argful_short_opt, - entry->argp->argp_domain, stream); - - /* Finally, a list of long options (whew!). */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_long_iterate (entry, usage_long_opt, - entry->argp->argp_domain, stream); - } -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -/* Make a HOL containing all levels of options in ARGP. CLUSTER is the - cluster in which ARGP's entries should be clustered, or 0. */ -static struct hol * -argp_hol (const struct argp *argp, struct hol_cluster *cluster) -{ - const struct argp_child *child = argp->children; - struct hol *hol = make_hol (argp, cluster); - if (child) - while (child->argp) - { - struct hol_cluster *child_cluster = - ((child->group || child->header) - /* Put CHILD->argp within its own cluster. */ - ? hol_add_cluster (hol, child->group, child->header, - child - argp->children, cluster, argp) - /* Just merge it into the parent's cluster. */ - : cluster); - hol_append (hol, argp_hol (child->argp, child_cluster)) ; - child++; - } - return hol; -} - -/* Calculate how many different levels with alternative args strings exist in - ARGP. */ -static size_t -argp_args_levels (const struct argp *argp) -{ - size_t levels = 0; - const struct argp_child *child = argp->children; - - if (argp->args_doc && strchr (argp->args_doc, '\n')) - levels++; - - if (child) - while (child->argp) - levels += argp_args_levels ((child++)->argp); - - return levels; -} - -/* Print all the non-option args documented in ARGP to STREAM. Any output is - preceded by a space. LEVELS is a pointer to a byte vector the length - returned by argp_args_levels; it should be initialized to zero, and - updated by this routine for the next call if ADVANCE is true. True is - returned as long as there are more patterns to output. */ -static int -argp_args_usage (const struct argp *argp, const struct argp_state *state, - char **levels, int advance, argp_fmtstream_t stream) -{ - char *our_level = *levels; - int multiple = 0; - const struct argp_child *child = argp->children; - const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0; - const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state); - - if (fdoc) - { - const char *cp = fdoc; - nl = __strchrnul (cp, '\n'); - if (*nl != '\0') - /* This is a `multi-level' args doc; advance to the correct position - as determined by our state in LEVELS, and update LEVELS. */ - { - int i; - multiple = 1; - for (i = 0; i < *our_level; i++) - cp = nl + 1, nl = __strchrnul (cp, '\n'); - (*levels)++; - } - - /* Manually do line wrapping so that it (probably) won't get wrapped at - any embedded spaces. */ - space (stream, 1 + nl - cp); - - __argp_fmtstream_write (stream, cp, nl - cp); - } - if (fdoc && fdoc != tdoc) - free ((char *)fdoc); /* Free user's modified doc string. */ - - if (child) - while (child->argp) - advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream); - - if (advance && multiple) - { - /* Need to increment our level. */ - if (*nl) - /* There's more we can do here. */ - { - (*our_level)++; - advance = 0; /* Our parent shouldn't advance also. */ - } - else if (*our_level > 0) - /* We had multiple levels, but used them up; reset to zero. */ - *our_level = 0; - } - - return !advance; -} - -/* Print the documentation for ARGP to STREAM; if POST is false, then - everything preceeding a `\v' character in the documentation strings (or - the whole string, for those with none) is printed, otherwise, everything - following the `\v' character (nothing for strings without). Each separate - bit of documentation is separated a blank line, and if PRE_BLANK is true, - then the first is as well. If FIRST_ONLY is true, only the first - occurrence is output. Returns true if anything was output. */ -static int -argp_doc (const struct argp *argp, const struct argp_state *state, - int post, int pre_blank, int first_only, - argp_fmtstream_t stream) -{ - const char *text; - const char *inp_text; - void *input = 0; - int anything = 0; - size_t inp_text_limit = 0; - const char *doc = dgettext (argp->argp_domain, argp->doc); - const struct argp_child *child = argp->children; - - if (doc) - { - char *vt = strchr (doc, '\v'); - inp_text = post ? (vt ? vt + 1 : 0) : doc; - inp_text_limit = (!post && vt) ? (vt - doc) : 0; - } - else - inp_text = 0; - - if (argp->help_filter) - /* We have to filter the doc strings. */ - { - if (inp_text_limit) - /* Copy INP_TEXT so that it's nul-terminated. */ - inp_text = STRNDUP (inp_text, inp_text_limit); - input = __argp_input (argp, state); - text = - (*argp->help_filter) (post - ? ARGP_KEY_HELP_POST_DOC - : ARGP_KEY_HELP_PRE_DOC, - inp_text, input); - } - else - text = (const char *) inp_text; - - if (text) - { - if (pre_blank) - __argp_fmtstream_putc (stream, '\n'); - - if (text == inp_text && inp_text_limit) - __argp_fmtstream_write (stream, inp_text, inp_text_limit); - else - __argp_fmtstream_puts (stream, text); - - if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - - anything = 1; - } - - if (text && text != inp_text) - free ((char *) text); /* Free TEXT returned from the help filter. */ - if (inp_text && inp_text_limit && argp->help_filter) - free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */ - - if (post && argp->help_filter) - /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */ - { - text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input); - if (text) - { - if (anything || pre_blank) - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, text); - free ((char *) text); - if (__argp_fmtstream_point (stream) - > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - anything = 1; - } - } - - if (child) - while (child->argp && !(first_only && anything)) - anything |= - argp_doc ((child++)->argp, state, - post, anything || pre_blank, first_only, - stream); - - return anything; -} - -/* Output a usage message for ARGP to STREAM. If called from - argp_state_help, STATE is the relevent parsing state. FLAGS are from the - set ARGP_HELP_*. NAME is what to use wherever a `program name' is - needed. */ - -static void -_help (const struct argp *argp, const struct argp_state *state, FILE *stream, - unsigned flags, const char *name) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - int anything = 0; /* Whether we've output anything. */ - struct hol *hol = 0; - argp_fmtstream_t fs; - - if (! stream) - return; - - __flockfile (stream); - - if (! uparams.valid) - fill_in_uparams (state); - - fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0); - if (! fs) - { - __funlockfile (stream); - return; - } - - if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG)) - { - hol = argp_hol (argp, 0); - - /* If present, these options always come last. */ - hol_set_group (hol, "help", -1); - hol_set_group (hol, "version", -1); - - hol_sort (hol); - } - - if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE)) - /* Print a short `Usage:' message. */ - { - int first_pattern = 1, more_patterns; - size_t num_pattern_levels = argp_args_levels (argp); - char *pattern_levels = alloca (num_pattern_levels); - - memset (pattern_levels, 0, num_pattern_levels); - - do - { - int old_lm; - int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); - char *levels = pattern_levels; - - if (first_pattern) - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, "Usage:"), - name); - else - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, " or: "), - name); - - /* We set the lmargin as well as the wmargin, because hol_usage - manually wraps options with newline to avoid annoying breaks. */ - old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent); - - if (flags & ARGP_HELP_SHORT_USAGE) - /* Just show where the options go. */ - { - if (hol->num_entries > 0) - __argp_fmtstream_puts (fs, dgettext (argp->argp_domain, - " [OPTION...]")); - } - else - /* Actually print the options. */ - { - hol_usage (hol, fs); - flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */ - } - - more_patterns = argp_args_usage (argp, state, &levels, 1, fs); - - __argp_fmtstream_set_wmargin (fs, old_wm); - __argp_fmtstream_set_lmargin (fs, old_lm); - - __argp_fmtstream_putc (fs, '\n'); - anything = 1; - - first_pattern = 0; - } - while (more_patterns); - } - - if (flags & ARGP_HELP_PRE_DOC) - anything |= argp_doc (argp, state, 0, 0, 1, fs); - - if (flags & ARGP_HELP_SEE) - { - __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\ -Try `%s --help' or `%s --usage' for more information.\n"), - name, name); - anything = 1; - } - - if (flags & ARGP_HELP_LONG) - /* Print a long, detailed help message. */ - { - /* Print info about all the options. */ - if (hol->num_entries > 0) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - hol_help (hol, state, fs); - anything = 1; - } - } - - if (flags & ARGP_HELP_POST_DOC) - /* Print any documentation strings at the end. */ - anything |= argp_doc (argp, state, 1, anything, 0, fs); - - if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, - "Report bugs to %s.\n"), - argp_program_bug_address); - anything = 1; - } - - __funlockfile (stream); - - if (hol) - hol_free (hol); - - __argp_fmtstream_free (fs); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -/* Output a usage message for ARGP to STREAM. FLAGS are from the set - ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */ -void __argp_help (const struct argp *argp, FILE *stream, - unsigned flags, char *name) -{ - _help (argp, 0, stream, flags, name); -} -#ifdef weak_alias -weak_alias (__argp_help, argp_help) -#endif - -char *__argp_basename(char *name) -{ - char *short_name = strrchr(name, '/'); - return short_name ? short_name + 1 : name; -} - -char * -__argp_short_program_name(const struct argp_state *state) -{ - if (state) - return state->name; -#if HAVE_PROGRAM_INVOCATION_SHORT_NAME - return program_invocation_short_name; -#elif HAVE_PROGRAM_INVOCATION_NAME - return __argp_basename(program_invocation_name); -#else /* !HAVE_PROGRAM_INVOCATION_NAME */ - /* FIXME: What now? Miles suggests that it is better to use NULL, - but currently the value is passed on directly to fputs_unlocked, - so that requires more changes. */ -# if __GNUC__ -# warning No reasonable value to return - return ""; -# endif /* __GNUC__ */ -#endif /* !HAVE_PROGRAM_INVOCATION_NAME */ -} - -/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are - from the set ARGP_HELP_*. */ -void -__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags) -{ - if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream) - { - if (state && (state->flags & ARGP_LONG_ONLY)) - flags |= ARGP_HELP_LONG_ONLY; - - _help (state ? state->root_argp : 0, state, stream, flags, - __argp_short_program_name(state)); - - if (!state || ! (state->flags & ARGP_NO_EXIT)) - { - if (flags & ARGP_HELP_EXIT_ERR) - exit (argp_err_exit_status); - if (flags & ARGP_HELP_EXIT_OK) - exit (0); - } - } -} -#ifdef weak_alias -weak_alias (__argp_state_help, argp_state_help) -#endif - -/* If appropriate, print the printf string FMT and following args, preceded - by the program name and `:', to stderr, and followed by a `Try ... --help' - message, then exit (1). */ -void -__argp_error (const struct argp_state *state, const char *fmt, ...) -{ - if (!state || !(state->flags & ARGP_NO_ERRS)) - { - FILE *stream = state ? state->err_stream : stderr; - - if (stream) - { - va_list ap; - - __flockfile (stream); - - fputs_unlocked (__argp_short_program_name(state), - stream); - putc_unlocked (':', stream); - putc_unlocked (' ', stream); - - va_start (ap, fmt); - vfprintf (stream, fmt, ap); - va_end (ap); - - putc_unlocked ('\n', stream); - - __argp_state_help (state, stream, ARGP_HELP_STD_ERR); - - __funlockfile (stream); - } - } -} -#ifdef weak_alias -weak_alias (__argp_error, argp_error) -#endif - -/* Similar to the standard gnu error-reporting function error(), but will - respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print - to STATE->err_stream. This is useful for argument parsing code that is - shared between program startup (when exiting is desired) and runtime - option parsing (when typically an error code is returned instead). The - difference between this function and argp_error is that the latter is for - *parsing errors*, and the former is for other problems that occur during - parsing but don't reflect a (syntactic) problem with the input. */ -void -__argp_failure (const struct argp_state *state, int status, int errnum, - const char *fmt, ...) -{ - if (!state || !(state->flags & ARGP_NO_ERRS)) - { - FILE *stream = state ? state->err_stream : stderr; - - if (stream) - { - __flockfile (stream); - - fputs_unlocked (__argp_short_program_name(state), - stream); - - if (fmt) - { - va_list ap; - - putc_unlocked (':', stream); - putc_unlocked (' ', stream); - - va_start (ap, fmt); - vfprintf (stream, fmt, ap); - va_end (ap); - } - - if (errnum) - { - putc_unlocked (':', stream); - putc_unlocked (' ', stream); - fputs (STRERROR (errnum), stream); - } - - putc_unlocked ('\n', stream); - - __funlockfile (stream); - - if (status && (!state || !(state->flags & ARGP_NO_EXIT))) - exit (status); - } - } -} -#ifdef weak_alias -weak_alias (__argp_failure, argp_failure) -#endif diff --git a/lsh/src/argp/argp-namefrob.h b/lsh/src/argp/argp-namefrob.h deleted file mode 100755 index 0ce1148..0000000 --- a/lsh/src/argp/argp-namefrob.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Name frobnication for compiling argp outside of glibc - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#if !_LIBC -/* This code is written for inclusion in gnu-libc, and uses names in the - namespace reserved for libc. If we're not compiling in libc, define those - names to be the normal ones instead. */ - -/* argp-parse functions */ -#undef __argp_parse -#define __argp_parse argp_parse -#undef __option_is_end -#define __option_is_end _option_is_end -#undef __option_is_short -#define __option_is_short _option_is_short -#undef __argp_input -#define __argp_input _argp_input - -/* argp-help functions */ -#undef __argp_help -#define __argp_help argp_help -#undef __argp_error -#define __argp_error argp_error -#undef __argp_failure -#define __argp_failure argp_failure -#undef __argp_state_help -#define __argp_state_help argp_state_help -#undef __argp_usage -#define __argp_usage argp_usage -#undef __argp_basename -#define __argp_basename _argp_basename -#undef __argp_short_program_name -#define __argp_short_program_name _argp_short_program_name - -/* argp-fmtstream functions */ -#undef __argp_make_fmtstream -#define __argp_make_fmtstream argp_make_fmtstream -#undef __argp_fmtstream_free -#define __argp_fmtstream_free argp_fmtstream_free -#undef __argp_fmtstream_putc -#define __argp_fmtstream_putc argp_fmtstream_putc -#undef __argp_fmtstream_puts -#define __argp_fmtstream_puts argp_fmtstream_puts -#undef __argp_fmtstream_write -#define __argp_fmtstream_write argp_fmtstream_write -#undef __argp_fmtstream_printf -#define __argp_fmtstream_printf argp_fmtstream_printf -#undef __argp_fmtstream_set_lmargin -#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin -#undef __argp_fmtstream_set_rmargin -#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin -#undef __argp_fmtstream_set_wmargin -#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin -#undef __argp_fmtstream_point -#define __argp_fmtstream_point argp_fmtstream_point -#undef __argp_fmtstream_update -#define __argp_fmtstream_update _argp_fmtstream_update -#undef __argp_fmtstream_ensure -#define __argp_fmtstream_ensure _argp_fmtstream_ensure -#undef __argp_fmtstream_lmargin -#define __argp_fmtstream_lmargin argp_fmtstream_lmargin -#undef __argp_fmtstream_rmargin -#define __argp_fmtstream_rmargin argp_fmtstream_rmargin -#undef __argp_fmtstream_wmargin -#define __argp_fmtstream_wmargin argp_fmtstream_wmargin - -/* normal libc functions we call */ -#undef __sleep -#define __sleep sleep -#undef __strcasecmp -#define __strcasecmp strcasecmp -#undef __vsnprintf -#define __vsnprintf vsnprintf - -#endif /* !_LIBC */ - -#ifndef __set_errno -#define __set_errno(e) (errno = (e)) -#endif diff --git a/lsh/src/argp/argp-parse.c b/lsh/src/argp/argp-parse.c deleted file mode 100755 index 2238186..0000000 --- a/lsh/src/argp/argp-parse.c +++ /dev/null @@ -1,1307 +0,0 @@ -/* Hierarchial argument parsing - Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#if MACOS -#define isascii(x) ((((unsigned char)(x)) & 0x80) == 0) -#endif - -#ifndef UNUSED -# if __GNUC__ >= 2 -# define UNUSED __attribute__ ((__unused__)) -# else -# define UNUSED -# endif -#endif - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. - When compiling libc, the _ macro is predefined. */ -# if defined HAVE_LIBINTL_H || defined _LIBC -# include -# ifdef _LIBC -# undef dgettext -# define dgettext(domain, msgid) __dcgettext (domain, msgid, LC_MESSAGES) -# endif -# else -# define dgettext(domain, msgid) (msgid) -# define gettext(msgid) (msgid) -# endif -#endif -#ifndef N_ -# define N_(msgid) (msgid) -#endif - -#if _LIBC - 0 -#include -#else -#ifdef HAVE_CTHREADS_H -#include -#endif -#endif /* _LIBC */ - -#include "argp.h" -#include "argp-namefrob.h" - - -/* The meta-argument used to prevent any further arguments being interpreted - as options. */ -#define QUOTE "--" - -/* EZ alias for ARGP_ERR_UNKNOWN. */ -#define EBADKEY ARGP_ERR_UNKNOWN - - -/* Default options. */ - -/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep - for one second intervals, decrementing _ARGP_HANG until it's zero. Thus - you can force the program to continue by attaching a debugger and setting - it to 0 yourself. */ -volatile int _argp_hang; - -#define OPT_PROGNAME -2 -#define OPT_USAGE -3 -#define OPT_HANG -4 - -static const struct argp_option argp_default_options[] = -{ - {"help", '?', 0, 0, N_("Give this help list"), -1}, - {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message")}, - {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, N_("Set the program name")}, -#ifndef MACOS - {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN, - N_("Hang for SECS seconds (default 3600)")}, -#endif - {0, 0} -}; - -static error_t -argp_default_parser (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case '?': - __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP); - break; - case OPT_USAGE: - __argp_state_help (state, state->out_stream, - ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); - break; - - case OPT_PROGNAME: /* Set the program name. */ -#if HAVE_PROGRAM_INVOCATION_NAME - program_invocation_name = arg; -#endif - /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka - __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined - to be that, so we have to be a bit careful here.] */ - - /* Update what we use for messages. */ - - state->name = __argp_basename(arg); - -#if HAVE_PROGRAM_INVOCATION_SHORT_NAME - program_invocation_short_name = state->name; -#endif - - if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS)) - == ARGP_PARSE_ARGV0) - /* Update what getopt uses too. */ - state->argv[0] = arg; - - break; - -#ifndef MACOS - case OPT_HANG: - _argp_hang = atoi (arg ? arg : "3600"); - fprintf(state->err_stream, "%s: pid = %ld\n", - state->name, (long) getpid()); - while (_argp_hang-- > 0) - __sleep (1); - break; -#endif - - default: - return EBADKEY; - } - return 0; -} - -static const struct argp argp_default_argp = - {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"}; - - -static const struct argp_option argp_version_options[] = -{ - {"version", 'V', 0, 0, N_("Print program version"), -1}, - {0, 0} -}; - -static error_t -argp_version_parser (int key, char *arg UNUSED, struct argp_state *state) -{ - switch (key) - { - case 'V': - if (argp_program_version_hook) - (*argp_program_version_hook) (state->out_stream, state); - else if (argp_program_version) - fprintf (state->out_stream, "%s\n", argp_program_version); - else - __argp_error (state, dgettext (state->root_argp->argp_domain, - "(PROGRAM ERROR) No version known!?")); - if (! (state->flags & ARGP_NO_EXIT)) - exit (0); - break; - default: - return EBADKEY; - } - return 0; -} - -static const struct argp argp_version_argp = - {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"}; - - - -/* The state of a `group' during parsing. Each group corresponds to a - particular argp structure from the tree of such descending from the top - level argp passed to argp_parse. */ -struct group -{ - /* This group's parsing function. */ - argp_parser_t parser; - - /* Which argp this group is from. */ - const struct argp *argp; - - /* The number of non-option args sucessfully handled by this parser. */ - unsigned args_processed; - - /* This group's parser's parent's group. */ - struct group *parent; - unsigned parent_index; /* And the our position in the parent. */ - - /* These fields are swapped into and out of the state structure when - calling this group's parser. */ - void *input, **child_inputs; - void *hook; -}; - -/* Call GROUP's parser with KEY and ARG, swapping any group-specific info - from STATE before calling, and back into state afterwards. If GROUP has - no parser, EBADKEY is returned. */ -static error_t -group_parse (struct group *group, struct argp_state *state, int key, char *arg) -{ - if (group->parser) - { - error_t err; - state->hook = group->hook; - state->input = group->input; - state->child_inputs = group->child_inputs; - state->arg_num = group->args_processed; - err = (*group->parser)(key, arg, state); - group->hook = state->hook; - return err; - } - else - return EBADKEY; -} - -struct parser -{ - const struct argp *argp; - - const char *posixly_correct; - - /* True if there are only no-option arguments left, which are just - passed verbatim with ARGP_KEY_ARG. This is set if we encounter a - quote, or the end of the proper options, but may be cleared again - if the user moves the next argument pointer backwards. */ - int args_only; - - /* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, the default is - REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is - defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; stop option - processing when the first non-option is seen. This is what Unix - does. This mode of operation is selected by either setting the - environment variable POSIXLY_CORRECT, or using `+' as the first - character of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we - scan, so that eventually all the non-options are at the end. This - allows options to be given in any order, even with programs that - were not written to expect this. - - RETURN_IN_ORDER is an option available to programs that were - written to expect options and other ARGV-elements in any order - and that care about the ordering of the two. We describe each - non-option ARGV-element as if it were the argument of an option - with character code 1. Using `-' as the first character of the - list of option characters selects this mode of operation. - - */ - enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; - - /* A segment of non-option arguments that have been skipped for - later processing, after all options. `first_nonopt' is the index - in ARGV of the first of them; `last_nonopt' is the index after - the last of them. - - If quoted or args_only is non-zero, this segment should be empty. */ - - /* FIXME: I'd prefer to use unsigned, but it's more consistent to - use the same type as for state.next. */ - int first_nonopt; - int last_nonopt; - - /* String of all recognized short options. Needed for ARGP_LONG_ONLY. */ - /* FIXME: Perhaps change to a pointer to a suitable bitmap instead? */ - char *short_opts; - - /* For parsing combined short options. */ - char *nextchar; - - /* States of the various parsing groups. */ - struct group *groups; - /* The end of the GROUPS array. */ - struct group *egroup; - /* An vector containing storage for the CHILD_INPUTS field in all groups. */ - void **child_inputs; - - /* State block supplied to parsing routines. */ - struct argp_state state; - - /* Memory used by this parser. */ - void *storage; -}; - -/* Search for a group defining a short option. */ -static const struct argp_option * -find_short_option(struct parser *parser, int key, struct group **p) -{ - struct group *group; - - assert(key >= 0); - assert(isascii(key)); - - for (group = parser->groups; group < parser->egroup; group++) - { - const struct argp_option *opts; - - for (opts = group->argp->options; !__option_is_end(opts); opts++) - if (opts->key == key) - { - *p = group; - return opts; - } - } - return NULL; -} - -enum match_result { MATCH_EXACT, MATCH_PARTIAL, MATCH_NO }; - -/* If defined, allow complete.el-like abbreviations of long options. */ -#ifndef ARGP_COMPLETE -#define ARGP_COMPLETE 0 -#endif - -/* Matches an encountern long-option argument ARG against an option NAME. - * ARG is terminated by NUL or '='. */ -static enum match_result -match_option(const char *arg, const char *name) -{ - unsigned i, j; - for (i = j = 0;; i++, j++) - { - switch(arg[i]) - { - case '\0': - case '=': - return name[j] ? MATCH_PARTIAL : MATCH_EXACT; -#if ARGP_COMPLETE - case '-': - while (name[j] != '-') - if (!name[j++]) - return MATCH_NO; - break; -#endif - default: - if (arg[i] != name[j]) - return MATCH_NO; - } - } -} - -static const struct argp_option * -find_long_option(struct parser *parser, - const char *arg, - struct group **p) -{ - struct group *group; - - /* Partial match found so far. */ - struct group *matched_group = NULL; - const struct argp_option *matched_option = NULL; - - /* Number of partial matches. */ - int num_partial = 0; - - for (group = parser->groups; group < parser->egroup; group++) - { - const struct argp_option *opts; - - for (opts = group->argp->options; !__option_is_end(opts); opts++) - { - if (!opts->name) - continue; - switch (match_option(arg, opts->name)) - { - case MATCH_NO: - break; - case MATCH_PARTIAL: - num_partial++; - - matched_group = group; - matched_option = opts; - - break; - case MATCH_EXACT: - /* Exact match. */ - *p = group; - return opts; - } - } - } - if (num_partial == 1) - { - *p = matched_group; - return matched_option; - } - - return NULL; -} - - -/* The next usable entries in the various parser tables being filled in by - convert_options. */ -struct parser_convert_state -{ - struct parser *parser; - char *short_end; - void **child_inputs_end; -}; - -/* Initialize GROUP from ARGP. If CVT->SHORT_END is non-NULL, short - options are recorded in the short options string. Returns the next - unused group entry. CVT holds state used during the conversion. */ -static struct group * -convert_options (const struct argp *argp, - struct group *parent, unsigned parent_index, - struct group *group, struct parser_convert_state *cvt) -{ - const struct argp_option *opt = argp->options; - const struct argp_child *children = argp->children; - - if (opt || argp->parser) - { - /* This parser needs a group. */ - if (cvt->short_end) - { - /* Record any short options. */ - for ( ; !__option_is_end (opt); opt++) - if (__option_is_short(opt)) - *cvt->short_end++ = opt->key; - } - - group->parser = argp->parser; - group->argp = argp; - group->args_processed = 0; - group->parent = parent; - group->parent_index = parent_index; - group->input = 0; - group->hook = 0; - group->child_inputs = 0; - - if (children) - /* Assign GROUP's CHILD_INPUTS field some space from - CVT->child_inputs_end.*/ - { - unsigned num_children = 0; - while (children[num_children].argp) - num_children++; - group->child_inputs = cvt->child_inputs_end; - cvt->child_inputs_end += num_children; - } - parent = group++; - } - else - parent = 0; - - if (children) - { - unsigned index = 0; - while (children->argp) - group = - convert_options (children++->argp, parent, index++, group, cvt); - } - - return group; -} -/* Allocate and initialize the group structures, so that they are - ordered as if by traversing the corresponding argp parser tree in - pre-order. Also build the list of short options, if that is needed. */ -static void -parser_convert (struct parser *parser, const struct argp *argp) -{ - struct parser_convert_state cvt; - - cvt.parser = parser; - cvt.short_end = parser->short_opts; - cvt.child_inputs_end = parser->child_inputs; - - parser->argp = argp; - - if (argp) - parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt); - else - parser->egroup = parser->groups; /* No parsers at all! */ - - if (parser->short_opts) - *cvt.short_end ='\0'; -} - -/* Lengths of various parser fields which we will allocated. */ -struct parser_sizes -{ - /* Needed only ARGP_LONG_ONLY */ - size_t short_len; /* Number of short options. */ - - size_t num_groups; /* Group structures we allocate. */ - size_t num_child_inputs; /* Child input slots. */ -}; - -/* For ARGP, increments the NUM_GROUPS field in SZS by the total - number of argp structures descended from it, and the SHORT_LEN by - the total number of short options. */ -static void -calc_sizes (const struct argp *argp, struct parser_sizes *szs) -{ - const struct argp_child *child = argp->children; - const struct argp_option *opt = argp->options; - - if (opt || argp->parser) - { - /* This parser needs a group. */ - szs->num_groups++; - if (opt) - { - while (__option_is_short (opt++)) - szs->short_len++; - } - } - - if (child) - while (child->argp) - { - calc_sizes ((child++)->argp, szs); - szs->num_child_inputs++; - } -} - -/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */ -static error_t -parser_init (struct parser *parser, const struct argp *argp, - int argc, char **argv, int flags, void *input) -{ - error_t err = 0; - struct group *group; - struct parser_sizes szs; - - parser->posixly_correct = getenv ("POSIXLY_CORRECT"); - - if (flags & ARGP_IN_ORDER) - parser->ordering = RETURN_IN_ORDER; - else if (flags & ARGP_NO_ARGS) - parser->ordering = REQUIRE_ORDER; - else if (parser->posixly_correct) - parser->ordering = REQUIRE_ORDER; - else - parser->ordering = PERMUTE; - - szs.short_len = 0; - szs.num_groups = 0; - szs.num_child_inputs = 0; - - if (argp) - calc_sizes (argp, &szs); - - if (!(flags & ARGP_LONG_ONLY)) - /* We have no use for the short option array. */ - szs.short_len = 0; - - /* Lengths of the various bits of storage used by PARSER. */ -#define GLEN (szs.num_groups + 1) * sizeof (struct group) -#define CLEN (szs.num_child_inputs * sizeof (void *)) -#define SLEN (szs.short_len + 1) -#define STORAGE(offset) ((void *) (((char *) parser->storage) + (offset))) - - parser->storage = malloc (GLEN + CLEN + SLEN); - if (! parser->storage) - return ENOMEM; - - parser->groups = parser->storage; - - parser->child_inputs = STORAGE(GLEN); - memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *)); - - if (flags & ARGP_LONG_ONLY) - parser->short_opts = STORAGE(GLEN + CLEN); - else - parser->short_opts = NULL; - - parser_convert (parser, argp); - - memset (&parser->state, 0, sizeof (struct argp_state)); - - parser->state.root_argp = parser->argp; - parser->state.argc = argc; - parser->state.argv = argv; - parser->state.flags = flags; - parser->state.err_stream = stderr; - parser->state.out_stream = stdout; - parser->state.pstate = parser; - - parser->args_only = 0; - parser->nextchar = NULL; - parser->first_nonopt = parser->last_nonopt = 0; - - /* Call each parser for the first time, giving it a chance to propagate - values to child parsers. */ - if (parser->groups < parser->egroup) - parser->groups->input = input; - for (group = parser->groups; - group < parser->egroup && (!err || err == EBADKEY); - group++) - { - if (group->parent) - /* If a child parser, get the initial input value from the parent. */ - group->input = group->parent->child_inputs[group->parent_index]; - - if (!group->parser - && group->argp->children && group->argp->children->argp) - /* For the special case where no parsing function is supplied for an - argp, propagate its input to its first child, if any (this just - makes very simple wrapper argps more convenient). */ - group->child_inputs[0] = group->input; - - err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0); - } - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - if (err) - return err; - - if (argv[0] && !(parser->state.flags & ARGP_PARSE_ARGV0)) - /* There's an argv[0]; use it for messages. */ - { - parser->state.name = __argp_basename(argv[0]); - - /* Don't parse it as an argument. */ - parser->state.next = 1; - } - else - parser->state.name = __argp_short_program_name(NULL); - - return 0; -} - -/* Free any storage consumed by PARSER (but not PARSER itself). */ -static error_t -parser_finalize (struct parser *parser, - error_t err, int arg_ebadkey, int *end_index) -{ - struct group *group; - - if (err == EBADKEY && arg_ebadkey) - /* Suppress errors generated by unparsed arguments. */ - err = 0; - - if (! err) - { - if (parser->state.next == parser->state.argc) - /* We successfully parsed all arguments! Call all the parsers again, - just a few more times... */ - { - for (group = parser->groups; - group < parser->egroup && (!err || err==EBADKEY); - group++) - if (group->args_processed == 0) - err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0); - for (group = parser->egroup - 1; - group >= parser->groups && (!err || err==EBADKEY); - group--) - err = group_parse (group, &parser->state, ARGP_KEY_END, 0); - - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - /* Tell the user that all arguments are parsed. */ - if (end_index) - *end_index = parser->state.next; - } - else if (end_index) - /* Return any remaining arguments to the user. */ - *end_index = parser->state.next; - else - /* No way to return the remaining arguments, they must be bogus. */ - { - if (!(parser->state.flags & ARGP_NO_ERRS) - && parser->state.err_stream) - fprintf (parser->state.err_stream, - dgettext (parser->argp->argp_domain, - "%s: Too many arguments\n"), - parser->state.name); - err = EBADKEY; - } - } - - /* Okay, we're all done, with either an error or success; call the parsers - to indicate which one. */ - - if (err) - { - /* Maybe print an error message. */ - if (err == EBADKEY) - /* An appropriate message describing what the error was should have - been printed earlier. */ - __argp_state_help (&parser->state, parser->state.err_stream, - ARGP_HELP_STD_ERR); - - /* Since we didn't exit, give each parser an error indication. */ - for (group = parser->groups; group < parser->egroup; group++) - group_parse (group, &parser->state, ARGP_KEY_ERROR, 0); - } - else - /* Notify parsers of success, and propagate back values from parsers. */ - { - /* We pass over the groups in reverse order so that child groups are - given a chance to do there processing before passing back a value to - the parent. */ - for (group = parser->egroup - 1 - ; group >= parser->groups && (!err || err == EBADKEY) - ; group--) - err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0); - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - } - - /* Call parsers once more, to do any final cleanup. Errors are ignored. */ - for (group = parser->egroup - 1; group >= parser->groups; group--) - group_parse (group, &parser->state, ARGP_KEY_FINI, 0); - - if (err == EBADKEY) - err = EINVAL; - - free (parser->storage); - - return err; -} - -/* Call the user parsers to parse the non-option argument VAL, at the - current position, returning any error. The state NEXT pointer - should point to the argument; this function will adjust it - correctly to reflect however many args actually end up being - consumed. */ -static error_t -parser_parse_arg (struct parser *parser, char *val) -{ - /* Save the starting value of NEXT */ - int index = parser->state.next; - error_t err = EBADKEY; - struct group *group; - int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */ - - /* Try to parse the argument in each parser. */ - for (group = parser->groups - ; group < parser->egroup && err == EBADKEY - ; group++) - { - parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */ - key = ARGP_KEY_ARG; - err = group_parse (group, &parser->state, key, val); - - if (err == EBADKEY) - /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */ - { - parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */ - key = ARGP_KEY_ARGS; - err = group_parse (group, &parser->state, key, 0); - } - } - - if (! err) - { - if (key == ARGP_KEY_ARGS) - /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't - changed by the user, *all* arguments should be considered - consumed. */ - parser->state.next = parser->state.argc; - - if (parser->state.next > index) - /* Remember that we successfully processed a non-option - argument -- but only if the user hasn't gotten tricky and set - the clock back. */ - (--group)->args_processed += (parser->state.next - index); - else - /* The user wants to reparse some args, so try looking for options again. */ - parser->args_only = 0; - } - - return err; -} - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,next), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -static void -exchange (struct parser *parser) -{ - int bottom = parser->first_nonopt; - int middle = parser->last_nonopt; - int top = parser->state.next; - char **argv = parser->state.argv; - - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - parser->first_nonopt += (parser->state.next - parser->last_nonopt); - parser->last_nonopt = parser->state.next; -} - - - -enum arg_type { ARG_ARG, ARG_SHORT_OPTION, - ARG_LONG_OPTION, ARG_LONG_ONLY_OPTION, - ARG_QUOTE }; - -static enum arg_type -classify_arg(struct parser *parser, char *arg, char **opt) -{ - if (arg[0] == '-') - /* Looks like an option... */ - switch (arg[1]) - { - case '\0': - /* "-" is not an option. */ - return ARG_ARG; - case '-': - /* Long option, or quote. */ - if (!arg[2]) - return ARG_QUOTE; - - /* A long option. */ - if (opt) - *opt = arg + 2; - return ARG_LONG_OPTION; - - default: - /* Short option. But if ARGP_LONG_ONLY, it can also be a long option. */ - - if (opt) - *opt = arg + 1; - - if (parser->state.flags & ARGP_LONG_ONLY) - { - /* Rules from getopt.c: - - If long_only and the ARGV-element has the form "-f", - where f is a valid short option, don't consider it an - abbreviated form of a long option that starts with f. - Otherwise there would be no way to give the -f short - option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an - abbreviation of the long option, just like "--fu", and - not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - assert(parser->short_opts); - - if (arg[2] || !strchr(parser->short_opts, arg[1])) - return ARG_LONG_ONLY_OPTION; - } - - return ARG_SHORT_OPTION; - } - - else - return ARG_ARG; -} - -/* Parse the next argument in PARSER (as indicated by PARSER->state.next). - Any error from the parsers is returned, and *ARGP_EBADKEY indicates - whether a value of EBADKEY is due to an unrecognized argument (which is - generally not fatal). */ -static error_t -parser_parse_next (struct parser *parser, int *arg_ebadkey) -{ - if (parser->state.quoted && parser->state.next < parser->state.quoted) - /* The next argument pointer has been moved to before the quoted - region, so pretend we never saw the quoting `--', and start - looking for options again. If the `--' is still there we'll just - process it one more time. */ - parser->state.quoted = parser->args_only = 0; - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if NEXT has been - moved back by the user (who may also have changed the arguments). */ - if (parser->last_nonopt > parser->state.next) - parser->last_nonopt = parser->state.next; - if (parser->first_nonopt > parser->state.next) - parser->first_nonopt = parser->state.next; - - if (parser->nextchar) - /* Deal with short options. */ - { - struct group *group; - char c; - const struct argp_option *option; - char *value = NULL;; - - assert(!parser->args_only); - - c = *parser->nextchar++; - - option = find_short_option(parser, c, &group); - if (!option) - { - if (parser->posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: illegal option -- %c\n"), - parser->state.name, c); - else - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: invalid option -- %c\n"), - parser->state.name, c); - - *arg_ebadkey = 0; - return EBADKEY; - } - - if (!*parser->nextchar) - parser->nextchar = NULL; - - if (option->arg) - { - value = parser->nextchar; - parser->nextchar = NULL; - - if (!value - && !(option->flags & OPTION_ARG_OPTIONAL)) - /* We need an mandatory argument. */ - { - if (parser->state.next == parser->state.argc) - /* Missing argument */ - { - /* 1003.2 specifies the format of this message. */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: option requires an argument -- %c\n"), - parser->state.name, c); - - *arg_ebadkey = 0; - return EBADKEY; - } - value = parser->state.argv[parser->state.next++]; - } - } - return group_parse(group, &parser->state, - option->key, value); - } - else - /* Advance to the next ARGV-element. */ - { - if (parser->args_only) - { - *arg_ebadkey = 1; - if (parser->state.next >= parser->state.argc) - /* We're done. */ - return EBADKEY; - else - return parser_parse_arg(parser, - parser->state.argv[parser->state.next]); - } - - if (parser->state.next >= parser->state.argc) - /* Almost done. If there are non-options that we skipped - previously, we should process them now. */ - { - *arg_ebadkey = 1; - if (parser->first_nonopt != parser->last_nonopt) - { - /* Start processing the arguments we skipped previously. */ - parser->state.next = parser->first_nonopt; - - parser->first_nonopt = parser->last_nonopt = 0; - - parser->args_only = 1; - return 0; - } - else - /* Indicate that we're really done. */ - return EBADKEY; - } - else - /* Look for options. */ - { - char *arg = parser->state.argv[parser->state.next]; - - char *optstart; - enum arg_type token = classify_arg(parser, arg, &optstart); - - switch (token) - { - case ARG_ARG: - switch (parser->ordering) - { - case PERMUTE: - if (parser->first_nonopt == parser->last_nonopt) - /* Skipped sequence is empty; start a new one. */ - parser->first_nonopt = parser->last_nonopt = parser->state.next; - - else if (parser->last_nonopt != parser->state.next) - /* We have a non-empty skipped sequence, and - we're not at the end-point, so move it. */ - exchange(parser); - - assert(parser->last_nonopt == parser->state.next); - - /* Skip this argument for now. */ - parser->state.next++; - parser->last_nonopt = parser->state.next; - - return 0; - - case REQUIRE_ORDER: - /* Implicit quote before the first argument. */ - parser->args_only = 1; - return 0; - - case RETURN_IN_ORDER: - *arg_ebadkey = 1; - return parser_parse_arg(parser, arg); - - default: - abort(); - } - case ARG_QUOTE: - /* Skip it, then exchange with any previous non-options. */ - parser->state.next++; - assert (parser->last_nonopt != parser->state.next); - - if (parser->first_nonopt != parser->last_nonopt) - { - exchange(parser); - - /* Start processing the skipped and the quoted - arguments. */ - - parser->state.quoted = parser->state.next = parser->first_nonopt; - - /* Also empty the skipped-list, to avoid confusion - if the user resets the next pointer. */ - parser->first_nonopt = parser->last_nonopt = 0; - } - else - parser->state.quoted = parser->state.next; - - parser->args_only = 1; - return 0; - - case ARG_LONG_ONLY_OPTION: - case ARG_LONG_OPTION: - { - struct group *group; - const struct argp_option *option; - char *value; - - parser->state.next++; - option = find_long_option(parser, optstart, &group); - - if (!option) - { - /* NOTE: This includes any "=something" in the output. */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: unrecognized option `%s'\n"), - parser->state.name, arg); - *arg_ebadkey = 0; - return EBADKEY; - } - - value = strchr(optstart, '='); - if (value) - value++; - - if (value && !option->arg) - /* Unexpected argument. */ - { - if (token == ARG_LONG_OPTION) - /* --option */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: option `--%s' doesn't allow an argument\n"), - parser->state.name, option->name); - else - /* +option or -option */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: option `%c%s' doesn't allow an argument\n"), - parser->state.name, arg[0], option->name); - - *arg_ebadkey = 0; - return EBADKEY; - } - - if (option->arg && !value - && !(option->flags & OPTION_ARG_OPTIONAL)) - /* We need an mandatory argument. */ - { - if (parser->state.next == parser->state.argc) - /* Missing argument */ - { - if (token == ARG_LONG_OPTION) - /* --option */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: option `--%s' requires an argument\n"), - parser->state.name, option->name); - else - /* +option or -option */ - fprintf (parser->state.err_stream, - dgettext(parser->state.root_argp->argp_domain, - "%s: option `%c%s' requires an argument\n"), - parser->state.name, arg[0], option->name); - - *arg_ebadkey = 0; - return EBADKEY; - } - - value = parser->state.argv[parser->state.next++]; - } - *arg_ebadkey = 0; - return group_parse(group, &parser->state, - option->key, value); - } - case ARG_SHORT_OPTION: - parser->state.next++; - parser->nextchar = optstart; - return 0; - - default: - abort(); - } - } - } -} - -/* Parse the options strings in ARGC & ARGV according to the argp in ARGP. - FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the - index in ARGV of the first unparsed option is returned in it. If an - unknown option is present, EINVAL is returned; if some parser routine - returned a non-zero value, it is returned; otherwise 0 is returned. */ -error_t -__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, - int *end_index, void *input) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - error_t err; - struct parser parser; - - /* If true, then err == EBADKEY is a result of a non-option argument failing - to be parsed (which in some cases isn't actually an error). */ - int arg_ebadkey = 0; - - if (! (flags & ARGP_NO_HELP)) - /* Add our own options. */ - { - struct argp_child *child = alloca (4 * sizeof (struct argp_child)); - struct argp *top_argp = alloca (sizeof (struct argp)); - - /* TOP_ARGP has no options, it just serves to group the user & default - argps. */ - memset (top_argp, 0, sizeof (*top_argp)); - top_argp->children = child; - - memset (child, 0, 4 * sizeof (struct argp_child)); - - if (argp) - (child++)->argp = argp; - (child++)->argp = &argp_default_argp; - if (argp_program_version || argp_program_version_hook) - (child++)->argp = &argp_version_argp; - child->argp = 0; - - argp = top_argp; - } - - /* Construct a parser for these arguments. */ - err = parser_init (&parser, argp, argc, argv, flags, input); - - if (! err) - /* Parse! */ - { - while (! err) - err = parser_parse_next (&parser, &arg_ebadkey); - err = parser_finalize (&parser, err, arg_ebadkey, end_index); - } - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return err; -} -#ifdef weak_alias -weak_alias (__argp_parse, argp_parse) -#endif - -/* Return the input field for ARGP in the parser corresponding to STATE; used - by the help routines. */ -void * -__argp_input (const struct argp *argp, const struct argp_state *state) -{ - if (state) - { - struct group *group; - struct parser *parser = state->pstate; - - for (group = parser->groups; group < parser->egroup; group++) - if (group->argp == argp) - return group->input; - } - - return 0; -} -#ifdef weak_alias -weak_alias (__argp_input, _argp_input) -#endif - -/* Defined here, in case a user is not inlining the definitions in - * argp.h */ -void -__argp_usage (__const struct argp_state *__state) __THROW -{ - __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE); -} - -int -__option_is_short (__const struct argp_option *__opt) __THROW -{ - if (__opt->flags & OPTION_DOC) - return 0; - else - { - int __key = __opt->key; - /* FIXME: whether or not a particular key implies a short option - * ought not to be locale dependent. */ - return __key > 0 && isprint (__key); - } -} - -int -__option_is_end (__const struct argp_option *__opt) __THROW -{ - return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; -} diff --git a/lsh/src/argp/argp-pv.c b/lsh/src/argp/argp-pv.c deleted file mode 100755 index 5061074..0000000 --- a/lsh/src/argp/argp-pv.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Default definition for ARGP_PROGRAM_VERSION. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* If set by the user program to a non-zero value, then a default option - --version is added (unless the ARGP_NO_HELP flag is used), which will - print this this string followed by a newline and exit (unless the - ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ -const char *argp_program_version; diff --git a/lsh/src/argp/argp-pvh.c b/lsh/src/argp/argp-pvh.c deleted file mode 100755 index 2d0bd39..0000000 --- a/lsh/src/argp/argp-pvh.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Default definition for ARGP_PROGRAM_VERSION_HOOK. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "argp.h" - -/* If set by the user program to a non-zero value, then a default option - --version is added (unless the ARGP_NO_HELP flag is used), which calls - this function with a stream to print the version to and a pointer to the - current parsing state, and then exits (unless the ARGP_NO_EXIT flag is - used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ -void (*argp_program_version_hook) (FILE *stream, struct argp_state *state); diff --git a/lsh/src/argp/argp-test.c b/lsh/src/argp/argp-test.c deleted file mode 100755 index 8165902..0000000 --- a/lsh/src/argp/argp-test.c +++ /dev/null @@ -1,259 +0,0 @@ -/* Test program for argp argument parser - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "argp.h" - -#ifndef UNUSED -# if __GNUC__ >= 2 -# define UNUSED __attribute__ ((__unused__)) -# else -# define UNUSED -# endif -#endif - -#if !HAVE_ASPRINTF -#include - -static int -asprintf (char **result, const char *format, ...) -{ - size_t size; - char *p; - - for (size = 200, p = NULL;; size *= 2) - { - va_list args; - int written; - - p = realloc(p, size + 1); - if (!p) - { - fprintf(stderr, "Virtual memory exhausted.\n"); - abort(); - } - - p[size] = '\0'; - - va_start(args, format); - written = vsnprintf(p, size, format, args); - va_end(args); - - if (written >= 0) - { - *result = p; - return written; - } - } -} -#endif /* !HAVE_ASPRINTF */ - -const char *argp_program_version = "argp-test 1.0"; - -struct argp_option sub_options[] = -{ - {"subopt1", 's', 0, 0, "Nested option 1"}, - {"subopt2", 'S', 0, 0, "Nested option 2"}, - - { 0, 0, 0, 0, "Some more nested options:", 10}, - {"subopt3", 'p', 0, 0, "Nested option 3"}, - - {"subopt4", 'q', 0, 0, "Nested option 4", 1}, - - {0} -}; - -static const char sub_args_doc[] = "STRING...\n-"; -static const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser."; - -static error_t -sub_parse_opt (int key, char *arg, struct argp_state *state UNUSED) -{ - switch (key) - { - case ARGP_KEY_NO_ARGS: - printf ("NO SUB ARGS\n"); - break; - case ARGP_KEY_ARG: - printf ("SUB ARG: %s\n", arg); - break; - - case 's' : case 'S': case 'p': case 'q': - printf ("SUB KEY %c\n", key); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static char * -sub_help_filter (int key, const char *text, void *input UNUSED) -{ - if (key == ARGP_KEY_HELP_EXTRA) - return strdup ("This is some extra text from the sub parser (note that it \ -is preceded by a blank line)."); - else - return (char *)text; -} - -static struct argp sub_argp = { - sub_options, sub_parse_opt, sub_args_doc, sub_doc, 0, sub_help_filter -}; - -/* Structure used to communicate with the parsing functions. */ -struct params -{ - unsigned foonly; /* Value parsed for foonly. */ - unsigned foonly_default; /* Default value for it. */ -}; - -#define OPT_PGRP 1 -#define OPT_SESS 2 - -struct argp_option options[] = -{ - {"pid", 'p', "PID", 0, "List the process PID"}, - {"pgrp", OPT_PGRP,"PGRP",0, "List processes in the process group PGRP"}, - {"no-parent", 'P', 0, 0, "Include processes without parents"}, - {0, 'x', 0, OPTION_ALIAS}, - {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" - " if there's some reason ps can't" - " print a field for any process, it's" - " removed from the output entirely)" }, - {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, - {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, - {"session", OPT_SESS,"SID", OPTION_ARG_OPTIONAL, - "Add the processes from the session" - " SID (which defaults to the sid of" - " the current process)" }, - - {0,0,0,0, "Here are some more options:"}, - {"foonly", 'f', "ZOT", OPTION_ARG_OPTIONAL, "Glork a foonly"}, - {"zaza", 'z', 0, 0, "Snit a zar"}, - - {0} -}; - -static const char args_doc[] = "STRING"; -static const char doc[] = "Test program for argp." - "\vThis doc string comes after the options." - "\nHey! Some manual formatting!" - "\nThe current time is: %s"; - -static void -popt (int key, char *arg) -{ - char buf[10]; - if (isprint (key)) - sprintf (buf, "%c", key); - else - sprintf (buf, "%d", key); - if (arg) - printf ("KEY %s: %s\n", buf, arg); - else - printf ("KEY %s\n", buf); -} - -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - struct params *params = state->input; - - switch (key) - { - case ARGP_KEY_NO_ARGS: - printf ("NO ARGS\n"); - break; - - case ARGP_KEY_ARG: - if (state->arg_num > 0) - return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser. */ - printf ("ARG: %s\n", arg); - break; - - case 'f': - if (arg) - params->foonly = atoi (arg); - else - params->foonly = params->foonly_default; - popt (key, arg); - break; - - case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q': - case 'r': case OPT_SESS: case 'z': - popt (key, arg); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static char * -help_filter (int key, const char *text, void *input) -{ - char *new_text; - struct params *params = input; - - if (key == ARGP_KEY_HELP_POST_DOC && text) - { - time_t now = time (0); - asprintf (&new_text, text, ctime (&now)); - } - else if (key == 'f') - /* Show the default for the --foonly option. */ - asprintf (&new_text, "%s (ZOT defaults to %x)", - text, params->foonly_default); - else - new_text = (char *)text; - - return new_text; -} - -static struct argp_child argp_children[] = { { &sub_argp }, { 0 } }; -static struct argp argp = { - options, parse_opt, args_doc, doc, argp_children, help_filter -}; - -int -main (int argc, char **argv) -{ - struct params params; - params.foonly = 0; - params.foonly_default = random (); - argp_parse (&argp, argc, argv, 0, 0, ¶ms); - printf ("After parsing: foonly = %x\n", params.foonly); - return 0; -} diff --git a/lsh/src/argp/argp.h b/lsh/src/argp/argp.h deleted file mode 100755 index 156de6b..0000000 --- a/lsh/src/argp/argp.h +++ /dev/null @@ -1,592 +0,0 @@ -/* Hierarchial argument parsing. - Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _ARGP_H -#define _ARGP_H - -#include -#include - -#define __need_error_t -#include - -#ifndef __THROW -# define __THROW -#endif - -#ifndef __const -# define __const const -#endif - -#ifndef __error_t_defined -typedef int error_t; -# define __error_t_defined -#endif - -/* FIXME: We could use a configure test to check for __attribute__, - * just like lsh does. */ -#ifndef PRINTF_STYLE -# if __GNUC__ >= 2 -# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) -# else -# define PRINTF_STYLE(f, a) -# endif -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -/* A description of a particular option. A pointer to an array of - these is passed in the OPTIONS field of an argp structure. Each option - entry can correspond to one long option and/or one short option; more - names for the same option can be added by following an entry in an option - array with options having the OPTION_ALIAS flag set. */ -struct argp_option -{ - /* The long option name. For more than one name for the same option, you - can use following options with the OPTION_ALIAS flag set. */ - __const char *name; - - /* What key is returned for this option. If > 0 and printable, then it's - also accepted as a short option. */ - int key; - - /* If non-NULL, this is the name of the argument associated with this - option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */ - __const char *arg; - - /* OPTION_ flags. */ - int flags; - - /* The doc string for this option. If both NAME and KEY are 0, This string - will be printed outdented from the normal option column, making it - useful as a group header (it will be the first thing printed in its - group); in this usage, it's conventional to end the string with a `:'. */ - __const char *doc; - - /* The group this option is in. In a long help message, options are sorted - alphabetically within each group, and the groups presented in the order - 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with - if this field 0 will inherit the group number of the previous entry, or - zero if it's the first one, unless its a group header (NAME and KEY both - 0), in which case, the previous entry + 1 is the default. Automagic - options such as --help are put into group -1. */ - int group; -}; - -/* The argument associated with this option is optional. */ -#define OPTION_ARG_OPTIONAL 0x1 - -/* This option isn't displayed in any help messages. */ -#define OPTION_HIDDEN 0x2 - -/* This option is an alias for the closest previous non-alias option. This - means that it will be displayed in the same help entry, and will inherit - fields other than NAME and KEY from the aliased option. */ -#define OPTION_ALIAS 0x4 - -/* This option isn't actually an option (and so should be ignored by the - actual option parser), but rather an arbitrary piece of documentation that - should be displayed in much the same manner as the options. If this flag - is set, then the option NAME field is displayed unmodified (e.g., no `--' - prefix is added) at the left-margin (where a *short* option would normally - be displayed), and the documentation string in the normal place. For - purposes of sorting, any leading whitespace and puncuation is ignored, - except that if the first non-whitespace character is not `-', this entry - is displayed after all options (and OPTION_DOC entries with a leading `-') - in the same group. */ -#define OPTION_DOC 0x8 - -/* This option shouldn't be included in `long' usage messages (but is still - included in help messages). This is mainly intended for options that are - completely documented in an argp's ARGS_DOC field, in which case including - the option in the generic usage list would be redundant. For instance, - if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to - distinguish these two cases, -x should probably be marked - OPTION_NO_USAGE. */ -#define OPTION_NO_USAGE 0x10 - -struct argp; /* fwd declare this type */ -struct argp_state; /* " */ -struct argp_child; /* " */ - -/* The type of a pointer to an argp parsing function. */ -typedef error_t (*argp_parser_t) (int key, char *arg, - struct argp_state *state); - -/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such - returns will simply be ignored. For user keys, this error will be turned - into EINVAL (if the call to argp_parse is such that errors are propagated - back to the user instead of exiting); returning EINVAL itself would result - in an immediate stop to parsing in *all* cases. */ -#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ - -/* Special values for the KEY argument to an argument parsing function. - ARGP_ERR_UNKNOWN should be returned if they aren't understood. - - The sequence of keys to a parsing function is either (where each - uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key): - - INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all - or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed - or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized - - The third case is where every parser returned ARGP_KEY_UNKNOWN for an - argument, in which case parsing stops at that argument (returning the - unparsed arguments to the caller of argp_parse if requested, or stopping - with an error message if not). - - If an error occurs (either detected by argp, or because the parsing - function returned an error value), then the parser is called with - ARGP_KEY_ERROR, and no further calls are made. */ - -/* This is not an option at all, but rather a command line argument. If a - parser receiving this key returns success, the fact is recorded, and the - ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the - argument, a parser function decrements the NEXT field of the state it's - passed, the option won't be considered processed; this is to allow you to - actually modify the argument (perhaps into an option), and have it - processed again. */ -#define ARGP_KEY_ARG 0 -/* There are remaining arguments not parsed by any parser, which may be found - starting at (STATE->argv + STATE->next). If success is returned, but - STATE->next left untouched, it's assumed that all arguments were consume, - otherwise, the parser should adjust STATE->next to reflect any arguments - consumed. */ -#define ARGP_KEY_ARGS 0x1000006 -/* There are no more command line arguments at all. */ -#define ARGP_KEY_END 0x1000001 -/* Because it's common to want to do some special processing if there aren't - any non-option args, user parsers are called with this key if they didn't - successfully process any non-option arguments. Called just before - ARGP_KEY_END (where more general validity checks on previously parsed - arguments can take place). */ -#define ARGP_KEY_NO_ARGS 0x1000002 -/* Passed in before any parsing is done. Afterwards, the values of each - element of the CHILD_INPUT field, if any, in the state structure is - copied to each child's state to be the initial value of the INPUT field. */ -#define ARGP_KEY_INIT 0x1000003 -/* Use after all other keys, including SUCCESS & END. */ -#define ARGP_KEY_FINI 0x1000007 -/* Passed in when parsing has successfully been completed (even if there are - still arguments remaining). */ -#define ARGP_KEY_SUCCESS 0x1000004 -/* Passed in if an error occurs. */ -#define ARGP_KEY_ERROR 0x1000005 - -/* An argp structure contains a set of options declarations, a function to - deal with parsing one, documentation string, a possible vector of child - argp's, and perhaps a function to filter help output. When actually - parsing options, getopt is called with the union of all the argp - structures chained together through their CHILD pointers, with conflicts - being resolved in favor of the first occurrence in the chain. */ -struct argp -{ - /* An array of argp_option structures, terminated by an entry with both - NAME and KEY having a value of 0. */ - __const struct argp_option *options; - - /* What to do with an option from this structure. KEY is the key - associated with the option, and ARG is any associated argument (NULL if - none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be - returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then - parsing is stopped immediately, and that value is returned from - argp_parse(). For special (non-user-supplied) values of KEY, see the - ARGP_KEY_ definitions below. */ - argp_parser_t parser; - - /* A string describing what other arguments are wanted by this program. It - is only used by argp_usage to print the `Usage:' message. If it - contains newlines, the strings separated by them are considered - alternative usage patterns, and printed on separate lines (lines after - the first are prefix by ` or: ' instead of `Usage:'). */ - __const char *args_doc; - - /* If non-NULL, a string containing extra text to be printed before and - after the options in a long help message (separated by a vertical tab - `\v' character). */ - __const char *doc; - - /* A vector of argp_children structures, terminated by a member with a 0 - argp field, pointing to child argps should be parsed with this one. Any - conflicts are resolved in favor of this argp, or early argps in the - CHILDREN list. This field is useful if you use libraries that supply - their own argp structure, which you want to use in conjunction with your - own. */ - __const struct argp_child *children; - - /* If non-zero, this should be a function to filter the output of help - messages. KEY is either a key from an option, in which case TEXT is - that option's help text, or a special key from the ARGP_KEY_HELP_ - defines, below, describing which other help text TEXT is. The function - should return either TEXT, if it should be used as-is, a replacement - string, which should be malloced, and will be freed by argp, or NULL, - meaning `print nothing'. The value for TEXT is *after* any translation - has been done, so if any of the replacement text also needs translation, - that should be done by the filter function. INPUT is either the input - supplied to argp_parse, or NULL, if argp_help was called directly. */ - char *(*help_filter) (int __key, __const char *__text, void *__input); - - /* If non-zero the strings used in the argp library are translated using - the domain described by this string. Otherwise the currently installed - default domain is used. */ - const char *argp_domain; -}; - -/* Possible KEY arguments to a help filter function. */ -#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */ -#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ -#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ -#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; - TEXT is NULL for this key. */ -/* Explanatory note emitted when duplicate option arguments have been - suppressed. */ -#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005 -#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ - -/* When an argp has a non-zero CHILDREN field, it should point to a vector of - argp_child structures, each of which describes a subsidiary argp. */ -struct argp_child -{ - /* The child parser. */ - __const struct argp *argp; - - /* Flags for this child. */ - int flags; - - /* If non-zero, an optional header to be printed in help output before the - child options. As a side-effect, a non-zero value forces the child - options to be grouped together; to achieve this effect without actually - printing a header string, use a value of "". */ - __const char *header; - - /* Where to group the child options relative to the other (`consolidated') - options in the parent argp; the values are the same as the GROUP field - in argp_option structs, but all child-groupings follow parent options at - a particular group level. If both this field and HEADER are zero, then - they aren't grouped at all, but rather merged with the parent options - (merging the child's grouping levels with the parents). */ - int group; -}; - -/* Parsing state. This is provided to parsing functions called by argp, - which may examine and, as noted, modify fields. */ -struct argp_state -{ - /* The top level ARGP being parsed. */ - __const struct argp *root_argp; - - /* The argument vector being parsed. May be modified. */ - int argc; - char **argv; - - /* The index in ARGV of the next arg that to be parsed. May be modified. */ - int next; - - /* The flags supplied to argp_parse. May be modified. */ - unsigned flags; - - /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the - number of the current arg, starting at zero, and incremented after each - such call returns. At all other times, this is the number of such - arguments that have been processed. */ - unsigned arg_num; - - /* If non-zero, the index in ARGV of the first argument following a special - `--' argument (which prevents anything following being interpreted as an - option). Only set once argument parsing has proceeded past this point. */ - int quoted; - - /* An arbitrary pointer passed in from the user. */ - void *input; - /* Values to pass to child parsers. This vector will be the same length as - the number of children for the current parser. */ - void **child_inputs; - - /* For the parser's use. Initialized to 0. */ - void *hook; - - /* The name used when printing messages. This is initialized to ARGV[0], - or PROGRAM_INVOCATION_NAME if that is unavailable. */ - char *name; - - /* Streams used when argp prints something. */ - FILE *err_stream; /* For errors; initialized to stderr. */ - FILE *out_stream; /* For information; initialized to stdout. */ - - void *pstate; /* Private, for use by argp. */ -}; - -/* Flags for argp_parse (note that the defaults are those that are - convenient for program command line parsing): */ - -/* Don't ignore the first element of ARGV. Normally (and always unless - ARGP_NO_ERRS is set) the first element of the argument vector is - skipped for option parsing purposes, as it corresponds to the program name - in a command line. */ -#define ARGP_PARSE_ARGV0 0x01 - -/* Don't print error messages for unknown options to stderr; unless this flag - is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program - name in the error messages. This flag implies ARGP_NO_EXIT (on the - assumption that silent exiting upon errors is bad behaviour). */ -#define ARGP_NO_ERRS 0x02 - -/* Don't parse any non-option args. Normally non-option args are parsed by - calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg - as the value. Since it's impossible to know which parse function wants to - handle it, each one is called in turn, until one returns 0 or an error - other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the - argp_parse returns prematurely (but with a return value of 0). If all - args have been parsed without error, all parsing functions are called one - last time with a key of ARGP_KEY_END. This flag needn't normally be set, - as the normal behavior is to stop parsing as soon as some argument can't - be handled. */ -#define ARGP_NO_ARGS 0x04 - -/* Parse options and arguments in the same order they occur on the command - line -- normally they're rearranged so that all options come first. */ -#define ARGP_IN_ORDER 0x08 - -/* Don't provide the standard long option --help, which causes usage and - option help information to be output to stdout, and exit (0) called. */ -#define ARGP_NO_HELP 0x10 - -/* Don't exit on errors (they may still result in error messages). */ -#define ARGP_NO_EXIT 0x20 - -/* Use the gnu getopt `long-only' rules for parsing arguments. */ -#define ARGP_LONG_ONLY 0x40 - -/* Turns off any message-printing/exiting options. */ -#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP) - -/* Parse the options strings in ARGC & ARGV according to the options in ARGP. - FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the - index in ARGV of the first unparsed option is returned in it. If an - unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser - routine returned a non-zero value, it is returned; otherwise 0 is - returned. This function may also call exit unless the ARGP_NO_HELP flag - is set. INPUT is a pointer to a value to be passed in to the parser. */ -extern error_t argp_parse (__const struct argp *__restrict __argp, - int __argc, char **__restrict __argv, - unsigned __flags, int *__restrict __arg_index, - void *__restrict __input) __THROW; -extern error_t __argp_parse (__const struct argp *__restrict __argp, - int __argc, char **__restrict __argv, - unsigned __flags, int *__restrict __arg_index, - void *__restrict __input) __THROW; - -/* Global variables. */ - -/* If defined or set by the user program to a non-zero value, then a default - option --version is added (unless the ARGP_NO_HELP flag is used), which - will print this string followed by a newline and exit (unless the - ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ -extern __const char *argp_program_version; - -/* If defined or set by the user program to a non-zero value, then a default - option --version is added (unless the ARGP_NO_HELP flag is used), which - calls this function with a stream to print the version to and a pointer to - the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is - used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ -extern void (*argp_program_version_hook) (FILE *__restrict __stream, - struct argp_state *__restrict - __state); - -/* If defined or set by the user program, it should point to string that is - the bug-reporting address for the program. It will be printed by - argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various - standard help messages), embedded in a sentence that says something like - `Report bugs to ADDR.'. */ -extern __const char *argp_program_bug_address; - -/* The exit status that argp will use when exiting due to a parsing error. - If not defined or set by the user program, this defaults to EX_USAGE from - . */ -extern error_t argp_err_exit_status; - -/* Flags for argp_help. */ -#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ -#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ -#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */ -#define ARGP_HELP_LONG 0x08 /* a long help message. */ -#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ -#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ -#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) -#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ -#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to - reflect ARGP_LONG_ONLY mode. */ - -/* These ARGP_HELP flags are only understood by argp_state_help. */ -#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ -#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ - -/* The standard thing to do after a program command line parsing error, if an - error message has already been printed. */ -#define ARGP_HELP_STD_ERR \ - (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) -/* The standard thing to do after a program command line parsing error, if no - more specific error message has been printed. */ -#define ARGP_HELP_STD_USAGE \ - (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) -/* The standard thing to do in response to a --help option. */ -#define ARGP_HELP_STD_HELP \ - (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \ - | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR) - -/* Output a usage message for ARGP to STREAM. FLAGS are from the set - ARGP_HELP_*. */ -extern void argp_help (__const struct argp *__restrict __argp, - FILE *__restrict __stream, - unsigned __flags, char *__restrict __name) __THROW; -extern void __argp_help (__const struct argp *__restrict __argp, - FILE *__restrict __stream, unsigned __flags, - char *__name) __THROW; - -/* The following routines are intended to be called from within an argp - parsing routine (thus taking an argp_state structure as the first - argument). They may or may not print an error message and exit, depending - on the flags in STATE -- in any case, the caller should be prepared for - them *not* to exit, and should return an appropiate error after calling - them. [argp_usage & argp_error should probably be called argp_state_..., - but they're used often enough that they should be short] */ - -/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are - from the set ARGP_HELP_*. */ -extern void argp_state_help (__const struct argp_state *__restrict __state, - FILE *__restrict __stream, - unsigned int __flags) __THROW; -extern void __argp_state_help (__const struct argp_state *__restrict __state, - FILE *__restrict __stream, - unsigned int __flags) __THROW; - -/* Possibly output the standard usage message for ARGP to stderr and exit. */ -extern void argp_usage (__const struct argp_state *__state) __THROW; -extern void __argp_usage (__const struct argp_state *__state) __THROW; - -/* If appropriate, print the printf string FMT and following args, preceded - by the program name and `:', to stderr, and followed by a `Try ... --help' - message, then exit (1). */ -extern void argp_error (__const struct argp_state *__restrict __state, - __const char *__restrict __fmt, ...) __THROW - PRINTF_STYLE(2,3); -extern void __argp_error (__const struct argp_state *__restrict __state, - __const char *__restrict __fmt, ...) __THROW - PRINTF_STYLE(2,3); - -/* Similar to the standard gnu error-reporting function error(), but will - respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print - to STATE->err_stream. This is useful for argument parsing code that is - shared between program startup (when exiting is desired) and runtime - option parsing (when typically an error code is returned instead). The - difference between this function and argp_error is that the latter is for - *parsing errors*, and the former is for other problems that occur during - parsing but don't reflect a (syntactic) problem with the input. */ -extern void argp_failure (__const struct argp_state *__restrict __state, - int __status, int __errnum, - __const char *__restrict __fmt, ...) __THROW - PRINTF_STYLE(4,5); -extern void __argp_failure (__const struct argp_state *__restrict __state, - int __status, int __errnum, - __const char *__restrict __fmt, ...) __THROW - PRINTF_STYLE(4,5); - -/* Returns true if the option OPT is a valid short option. */ -extern int _option_is_short (__const struct argp_option *__opt) __THROW; -extern int __option_is_short (__const struct argp_option *__opt) __THROW; - -/* Returns true if the option OPT is in fact the last (unused) entry in an - options array. */ -extern int _option_is_end (__const struct argp_option *__opt) __THROW; -extern int __option_is_end (__const struct argp_option *__opt) __THROW; - -/* Return the input field for ARGP in the parser corresponding to STATE; used - by the help routines. */ -extern void *_argp_input (__const struct argp *__restrict __argp, - __const struct argp_state *__restrict __state) - __THROW; -extern void *__argp_input (__const struct argp *__restrict __argp, - __const struct argp_state *__restrict __state) - __THROW; - -/* Used for extracting the program name from argv[0] */ -extern char *_argp_basename(char *name) __THROW; -extern char *__argp_basename(char *name) __THROW; - -/* Getting the program name given an argp state */ -extern char * -_argp_short_program_name(const struct argp_state *state) __THROW; -extern char * -__argp_short_program_name(const struct argp_state *state) __THROW; - - -#ifdef __USE_EXTERN_INLINES - -# if !_LIBC -# define __argp_usage argp_usage -# define __argp_state_help argp_state_help -# define __option_is_short _option_is_short -# define __option_is_end _option_is_end -# endif - -# ifndef ARGP_EI -# define ARGP_EI extern __inline__ -# endif - -ARGP_EI void -__argp_usage (__const struct argp_state *__state) __THROW -{ - __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE); -} - -ARGP_EI int -__option_is_short (__const struct argp_option *__opt) __THROW -{ - if (__opt->flags & OPTION_DOC) - return 0; - else - { - int __key = __opt->key; - return __key > 0 && isprint (__key); - } -} - -ARGP_EI int -__option_is_end (__const struct argp_option *__opt) __THROW -{ - return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; -} - -# if !_LIBC -# undef __argp_usage -# undef __argp_state_help -# undef __option_is_short -# undef __option_is_end -# endif -#endif /* Use extern inlines. */ - -#ifdef __cplusplus -} -#endif - -#endif /* argp.h */ diff --git a/lsh/src/argp/config.h.in b/lsh/src/argp/config.h.in deleted file mode 100755 index a46db74..0000000 --- a/lsh/src/argp/config.h.in +++ /dev/null @@ -1,105 +0,0 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ -/* Global variables needed by argp */ -#undef HAVE_PROGRAM_INVOCATION_NAME -#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME - -/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP - systems. This function is required for `alloca.c' support on those systems. - */ -#undef CRAY_STACKSEG_END - -/* Define if using `alloca.c'. */ -#undef C_ALLOCA - -/* Define if you have `alloca', as a function or macro. */ -#undef HAVE_ALLOCA - -/* Define if you have and it should be used (not on Ultrix). */ -#undef HAVE_ALLOCA_H - -/* Define if you have the `asprintf' function. */ -#undef HAVE_ASPRINTF - -/* Define if you don't have `vprintf' but do have `_doprnt.' */ -#undef HAVE_DOPRNT - -/* Define if you have the `flockfile' function. */ -#undef HAVE_FLOCKFILE - -/* Define if you have the `fputs_unlocked' function. */ -#undef HAVE_FPUTS_UNLOCKED - -/* Define if you have the `fwrite_unlocked' function. */ -#undef HAVE_FWRITE_UNLOCKED - -/* Define if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define if you have the header file. */ -#undef HAVE_LIMITS_H - -/* Define if you have the header file. */ -#undef HAVE_MALLOC_H - -/* Define if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define if you have the `mempcpy' function. */ -#undef HAVE_MEMPCPY - -/* Define if you have the `putc_unlocked' function. */ -#undef HAVE_PUTC_UNLOCKED - -/* Define if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define if you have the `strchrnul' function. */ -#undef HAVE_STRCHRNUL - -/* Define if you have the `strdup' function. */ -#undef HAVE_STRDUP - -/* Define if you have the `strerror' function. */ -#undef HAVE_STRERROR - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STRING_H - -/* Define if you have the `strndup' function. */ -#undef HAVE_STRNDUP - -/* Define if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define if you have the `vprintf' function. */ -#undef HAVE_VPRINTF - -/* Name of package */ -#undef PACKAGE - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ -#undef STACK_DIRECTION - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Version number of package */ -#undef VERSION - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ -#undef inline - -/* Define to `unsigned' if does not define. */ -#undef size_t diff --git a/lsh/src/argp/configure b/lsh/src/argp/configure deleted file mode 100755 index b2e9b40..0000000 --- a/lsh/src/argp/configure +++ /dev/null @@ -1,4525 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by Autoconf 2.50. -# -# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -# Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -exec 6>&1 - -# -# Initializations. -# -ac_default_prefix=/usr/local -cross_compiling=no -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - -# Avoid depending upon Character Ranges. -ac_cr_az='abcdefghijklmnopqrstuvwxyz' -ac_cr_AZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -ac_cr_09='0123456789' -ac_cr_alnum=$ac_cr_az$ac_cr_AZ$ac_cr_09 - -# Sed expression to map a string onto a valid sh and CPP variable names. -ac_tr_sh="sed y%*+%pp%;s%[^_$ac_cr_alnum]%_%g" -ac_tr_cpp="sed y%*$ac_cr_az%P$ac_cr_AZ%;s%[^_$ac_cr_alnum]%_%g" - -ac_unique_file="argp-ba.c" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#include -#include -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#else -# if HAVE_STRINGS_H -# include -# endif -#endif -#if HAVE_INTTYPES_H -# include -#endif -#if HAVE_UNISTD_H -# include -#endif" - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Identity of this package. -PACKAGE_NAME= -PACKAGE_TARNAME= -PACKAGE_VERSION= -PACKAGE_STRING= -PACKAGE_BUGREPORT= - -ac_prev= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_option in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - eval "enable_$ac_feature=no" ;; - - -enable-* | --enable-*) - ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "enable_$ac_feature='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package| sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "with_$ac_package='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/-/_/g'` - eval "with_$ac_package=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` - eval "$ac_envvar='$ac_optarg'" - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$ac_cr_alnum]" >/dev/null && - echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -# Be sure to have absolute paths. -for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ - localstatedir libdir includedir oldincludedir infodir mandir \ - exec_prefix prefix -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* ) ;; - NONE ) ;; - *) { echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: should be removed in autoconf 3.0. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo "$ac_prog" | sed 's%[\\/][^\\/][^\\/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "$as_me: error: cannot find sources in $ac_confdir or .." >&2 - { (exit 1); exit 1; }; } - else - { echo "$as_me: error: cannot find sources in $srcdir" >&2 - { (exit 1); exit 1; }; } - fi -fi -srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` -ac_env_build_alias_set=${build_alias+set} -ac_env_build_alias_value=$build_alias -ac_cv_env_build_alias_set=${build_alias+set} -ac_cv_env_build_alias_value=$build_alias -ac_env_host_alias_set=${host_alias+set} -ac_env_host_alias_value=$host_alias -ac_cv_env_host_alias_set=${host_alias+set} -ac_cv_env_host_alias_value=$host_alias -ac_env_target_alias_set=${target_alias+set} -ac_env_target_alias_value=$target_alias -ac_cv_env_target_alias_set=${target_alias+set} -ac_cv_env_target_alias_value=$target_alias -ac_env_CC_set=${CC+set} -ac_env_CC_value=$CC -ac_cv_env_CC_set=${CC+set} -ac_cv_env_CC_value=$CC -ac_env_CFLAGS_set=${CFLAGS+set} -ac_env_CFLAGS_value=$CFLAGS -ac_cv_env_CFLAGS_set=${CFLAGS+set} -ac_cv_env_CFLAGS_value=$CFLAGS -ac_env_LDFLAGS_set=${LDFLAGS+set} -ac_env_LDFLAGS_value=$LDFLAGS -ac_cv_env_LDFLAGS_set=${LDFLAGS+set} -ac_cv_env_LDFLAGS_value=$LDFLAGS -ac_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_env_CPPFLAGS_value=$CPPFLAGS -ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat < if you have libraries in a - nonstandard directory - CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have - headers in a nonstandard directory - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -EOF -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - ac_popdir=`pwd` - for ac_subdir in : $ac_subdirs_all; do test "x$ac_subdir" = x: && continue - cd $ac_subdir - # A "../" for each directory in /$ac_subdir. - ac_dots=`echo $ac_subdir | - sed 's,^\./,,;s,[^/]$,&/,;s,[^/]*/,../,g'` - - case $srcdir in - .) # No --srcdir option. We are building in place. - ac_sub_srcdir=$srcdir ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_sub_srcdir=$srcdir/$ac_subdir ;; - *) # Relative path. - ac_sub_srcdir=$ac_dots$srcdir/$ac_subdir ;; - esac - - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_sub_srcdir/configure.gnu; then - echo - $SHELL $ac_sub_srcdir/configure.gnu --help=recursive - elif test -f $ac_sub_srcdir/configure; then - echo - $SHELL $ac_sub_srcdir/configure --help=recursive - elif test -f $ac_sub_srcdir/configure.ac || - test -f $ac_sub_srcdir/configure.in; then - echo - $ac_configure --help - else - echo "$as_me: WARNING: no configuration information is in $ac_subdir" >&2 - fi - cd $ac_popdir - done -fi - -test -n "$ac_init_help" && exit 0 -if $ac_init_version; then - cat <<\EOF - -Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -EOF - exit 0 -fi -exec 5>config.log -cat >&5 </dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -hostinfo = `(hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -PATH = $PATH - -_ASUNAME -} >&5 - -cat >&5 <\?\"\']*) - ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` - ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" - ac_sep=" " ;; - *) ac_configure_args="$ac_configure_args$ac_sep$ac_arg" - ac_sep=" " ;; - esac - # Get rid of the leading space. -done - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - echo >&5 - echo "## ----------------- ##" >&5 - echo "## Cache variables. ##" >&5 - echo "## ----------------- ##" >&5 - echo >&5 - # The following way of writing the cache mishandles newlines in values, -{ - (set) 2>&1 | - case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in - *ac_space=\ *) - sed -n \ - "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" - ;; - *) - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} >&5 - sed "/^$/d" confdefs.h >conftest.log - if test -s conftest.log; then - echo >&5 - echo "## ------------ ##" >&5 - echo "## confdefs.h. ##" >&5 - echo "## ------------ ##" >&5 - echo >&5 - cat conftest.log >&5 - fi - (echo; echo) >&5 - test "$ac_signal" != 0 && - echo "$as_me: caught signal $ac_signal" >&5 - echo "$as_me: exit $exit_status" >&5 - rm -rf conftest* confdefs* core core.* *.core conf$$* $ac_clean_files && - exit $exit_status - ' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_status=$?; ac_signal='$ac_signal'; { (exit $ac_status); exit $ac_status; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo >confdefs.h - -# Let the site file select an alternate cache file if it wants to. -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - { echo "$as_me:841: loading site script $ac_site_file" >&5 -echo "$as_me: loading site script $ac_site_file" >&6;} - cat "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { echo "$as_me:852: loading cache $cache_file" >&5 -echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . $cache_file;; - *) . ./$cache_file;; - esac - fi -else - { echo "$as_me:860: creating cache $cache_file" >&5 -echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_suggest_removing_cache=false -for ac_var in `(set) 2>&1 | - sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val="\$ac_cv_env_${ac_var}_value" - eval ac_new_val="\$ac_env_${ac_var}_value" - case $ac_old_set,$ac_new_set in - set,) - { echo "$as_me:876: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,set) - { echo "$as_me:880: WARNING: \`$ac_var' was not set in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was not set in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - { echo "$as_me:886: WARNING: \`$ac_var' has changed since the previous run:" >&5 -echo "$as_me: WARNING: \`$ac_var' has changed since the previous run:" >&2;} - { echo "$as_me:888: WARNING: former value: $ac_old_val" >&5 -echo "$as_me: WARNING: former value: $ac_old_val" >&2;} - { echo "$as_me:890: WARNING: current value: $ac_new_val" >&5 -echo "$as_me: WARNING: current value: $ac_new_val" >&2;} - ac_suggest_removing_cache=: - fi;; - esac -done -if $ac_suggest_removing_cache; then - { echo "$as_me:897: WARNING: changes in the environment can compromise the build" >&5 -echo "$as_me: WARNING: changes in the environment can compromise the build" >&2;} - { echo "$as_me:899: WARNING: consider removing $cache_file and starting over" >&5 -echo "$as_me: WARNING: consider removing $cache_file and starting over" >&2;} -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac -echo "#! $SHELL" >conftest.sh -echo "exit 0" >>conftest.sh -chmod +x conftest.sh -if { (echo "$as_me:918: PATH=\".;.\"; conftest.sh") >&5 - (PATH=".;."; conftest.sh) 2>&5 - ac_status=$? - echo "$as_me:921: \$? = $ac_status" >&5 - (exit $ac_status); }; then - ac_path_separator=';' -else - ac_path_separator=: -fi -PATH_SEPARATOR="$ac_path_separator" -rm -f conftest.sh - -ac_aux_dir= -for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do - if test -f $ac_dir/install-sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f $ac_dir/install.sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f $ac_dir/shtool; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - { { echo "$as_me:947: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 -echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} - { (exit 1); exit 1; }; } -fi -ac_config_guess="$SHELL $ac_aux_dir/config.guess" -ac_config_sub="$SHELL $ac_aux_dir/config.sub" -ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# ./install, which can be erroneously created by make from ./install.sh. -echo "$as_me:967: checking for a BSD compatible install" >&5 -echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6 -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_save_IFS=$IFS; IFS=$ac_path_separator - for ac_dir in $PATH; do - IFS=$ac_save_IFS - # Account for people who put trailing slashes in PATH elements. - case $ac_dir/ in - / | ./ | .// | /cC/* \ - | /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* \ - | /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - if $as_executable_p "$ac_dir/$ac_prog"; then - if test $ac_prog = install && - grep dspmsg "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - ac_cv_path_install="$ac_dir/$ac_prog -c" - break 2 - fi - fi - done - ;; - esac - done - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. We don't cache a - # path for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the path is relative. - INSTALL=$ac_install_sh - fi -fi -echo "$as_me:1016: result: $INSTALL" >&5 -echo "${ECHO_T}$INSTALL" >&6 - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -echo "$as_me:1027: checking whether build environment is sane" >&5 -echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6 -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "$*" != "X $srcdir/configure conftestfile" \ - && test "$*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - { { echo "$as_me:1050: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&5 -echo "$as_me: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&2;} - { (exit 1); exit 1; }; } - fi - - test "$2" = conftestfile - ) -then - # Ok. - : -else - { { echo "$as_me:1063: error: newly created file is older than distributed files! -Check your system clock" >&5 -echo "$as_me: error: newly created file is older than distributed files! -Check your system clock" >&2;} - { (exit 1); exit 1; }; } -fi -rm -f conftest* -echo "$as_me:1070: result: yes" >&5 -echo "${ECHO_T}yes" >&6 -if test "$program_transform_name" = s,x,x,; then - program_transform_name= -else - # Double any \ or $. echo might interpret backslashes. - cat <<\EOF >conftest.sed -s,\\,\\\\,g; s,\$,$$,g -EOF - program_transform_name=`echo $program_transform_name | sed -f conftest.sed` - rm -f conftest.sed -fi -test "$program_prefix" != NONE && - program_transform_name="s,^,${program_prefix},;$program_transform_name" -# Use a double $ so make ignores it. -test "$program_suffix" != NONE && - program_transform_name="s,\$\$,${program_suffix},;$program_transform_name" - -# sed with no file args requires a program. -test -z "$program_transform_name" && program_transform_name="s,x,x," - -echo "$as_me:1091: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1111: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1115: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -PACKAGE=argp - -VERSION=standalone-1.1 - -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - { { echo "$as_me:1125: error: source directory already configured; run \"make distclean\" there first" >&5 -echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;} - { (exit 1); exit 1; }; } -fi - -cat >>confdefs.h <>confdefs.h <&5 -echo $ECHO_N "checking for working aclocal... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (aclocal --version) < /dev/null > /dev/null 2>&1; then - ACLOCAL=aclocal - echo "$as_me:1146: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - ACLOCAL="$missing_dir/missing aclocal" - echo "$as_me:1150: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1154: checking for working autoconf" >&5 -echo $ECHO_N "checking for working autoconf... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoconf --version) < /dev/null > /dev/null 2>&1; then - AUTOCONF=autoconf - echo "$as_me:1161: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOCONF="$missing_dir/missing autoconf" - echo "$as_me:1165: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1169: checking for working automake" >&5 -echo $ECHO_N "checking for working automake... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (automake --version) < /dev/null > /dev/null 2>&1; then - AUTOMAKE=automake - echo "$as_me:1176: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOMAKE="$missing_dir/missing automake" - echo "$as_me:1180: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1184: checking for working autoheader" >&5 -echo $ECHO_N "checking for working autoheader... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoheader --version) < /dev/null > /dev/null 2>&1; then - AUTOHEADER=autoheader - echo "$as_me:1191: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOHEADER="$missing_dir/missing autoheader" - echo "$as_me:1195: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1199: checking for working makeinfo" >&5 -echo $ECHO_N "checking for working makeinfo... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (makeinfo --version) < /dev/null > /dev/null 2>&1; then - MAKEINFO=makeinfo - echo "$as_me:1206: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - MAKEINFO="$missing_dir/missing makeinfo" - echo "$as_me:1210: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -ac_config_headers="$ac_config_headers config.h" - -ac_config_commands="$ac_config_commands default-1" - -# GNU libc defaults to supplying the ISO C library functions only. The -# _GNU_SOURCE define enables these extensions, in particular we want -# errno.h to declare program_invocation_name. Enable it on all -# systems; no problems have been reported with it so far. - -CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -echo "$as_me:1233: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}gcc" -echo "$as_me:1248: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1256: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1259: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo "$as_me:1268: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="gcc" -echo "$as_me:1283: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1291: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1294: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -echo "$as_me:1307: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}cc" -echo "$as_me:1322: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1330: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1333: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1342: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="cc" -echo "$as_me:1357: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1365: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1368: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1381: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue -fi -ac_cv_prog_CC="cc" -echo "$as_me:1401: found $ac_dir/$ac_word" >&5 -break -done - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - set dummy "$ac_dir/$ac_word" ${1+"$@"} - shift - ac_cv_prog_CC="$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1423: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1426: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:1437: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="$ac_tool_prefix$ac_prog" -echo "$as_me:1452: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1460: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1463: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:1476: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="$ac_prog" -echo "$as_me:1491: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1499: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1502: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CC" && break -done - - CC=$ac_ct_CC -fi - -fi - -test -z "$CC" && { { echo "$as_me:1514: error: no acceptable cc found in \$PATH" >&5 -echo "$as_me: error: no acceptable cc found in \$PATH" >&2;} - { (exit 1); exit 1; }; } - -cat >conftest.$ac_ext <<_ACEOF -#line 1519 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.exe" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compiler, and finding out an intuition -# of exeext. -echo "$as_me:1535: checking for C compiler default output" >&5 -echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6 -ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` -if { (eval echo "$as_me:1538: \"$ac_link_default\"") >&5 - (eval $ac_link_default) 2>&5 - ac_status=$? - echo "$as_me:1541: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `ls a.exe conftest.exe a.* conftest conftest.* 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - a.out ) # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1558: error: C compiler cannot create executables" >&5 -echo "$as_me: error: C compiler cannot create executables" >&2;} - { (exit 77); exit 77; }; } -fi - -ac_exeext=$ac_cv_exeext -echo "$as_me:1564: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6 - -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1569: checking whether the C compiler works" >&5 -echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (eval echo "$as_me:1575: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1578: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { echo "$as_me:1585: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&5 -echo "$as_me: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&2;} - { (exit 1); exit 1; }; } - fi - fi -fi -echo "$as_me:1593: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - -rm -f a.out a.exe conftest$ac_cv_exeext -ac_clean_files=$ac_clean_files_save -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1600: checking whether we are cross compiling" >&5 -echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 -echo "$as_me:1602: result: $cross_compiling" >&5 -echo "${ECHO_T}$cross_compiling" >&6 - -echo "$as_me:1605: checking for executable suffix" >&5 -echo $ECHO_N "checking for executable suffix... $ECHO_C" >&6 -if { (eval echo "$as_me:1607: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:1610: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in `(ls conftest.exe; ls conftest; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - { { echo "$as_me:1626: error: cannot compute EXEEXT: cannot compile and link" >&5 -echo "$as_me: error: cannot compute EXEEXT: cannot compile and link" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest$ac_cv_exeext -echo "$as_me:1632: result: $ac_cv_exeext" >&5 -echo "${ECHO_T}$ac_cv_exeext" >&6 - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -echo "$as_me:1638: checking for object suffix" >&5 -echo $ECHO_N "checking for object suffix... $ECHO_C" >&6 -if test "${ac_cv_objext+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1644 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (eval echo "$as_me:1656: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1659: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1671: error: cannot compute OBJEXT: cannot compile" >&5 -echo "$as_me: error: cannot compute OBJEXT: cannot compile" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -echo "$as_me:1678: result: $ac_cv_objext" >&5 -echo "${ECHO_T}$ac_cv_objext" >&6 -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -echo "$as_me:1682: checking whether we are using the GNU C compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 -if test "${ac_cv_c_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1688 "configure" -#include "confdefs.h" - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1703: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1706: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1709: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1712: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_compiler_gnu=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:1724: result: $ac_cv_c_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 -GCC=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" -echo "$as_me:1730: checking whether $CC accepts -g" >&5 -echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1736 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1748: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1751: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1754: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1757: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_g=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_prog_cc_g=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:1767: result: $ac_cv_prog_cc_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -# Some people use a C++ compiler to compile C. Since we use `exit', -# in C++ we need to declare it. In case someone uses the same compiler -# for both compiling C and C++ we need to have the C++ compiler decide -# the declaration of exit, since it's the most demanding environment. -cat >conftest.$ac_ext <<_ACEOF -#ifndef __cplusplus - choke me -#endif -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1794: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1797: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1800: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1803: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - for ac_declaration in \ - ''\ - '#include ' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -#line 1815 "configure" -#include "confdefs.h" -#include -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1828: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1831: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1834: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1837: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -continue -fi -rm -f conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -#line 1847 "configure" -#include "confdefs.h" -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1859: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1862: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1865: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1868: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -echo '#ifdef __cplusplus' >>confdefs.h -echo $ac_declaration >>confdefs.h -echo '#endif' >>confdefs.h - -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:1892: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1912: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1916: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -echo "$as_me:1924: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" -echo "$as_me:1939: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - echo "$as_me:1947: result: $RANLIB" >&5 -echo "${ECHO_T}$RANLIB" >&6 -else - echo "$as_me:1950: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -echo "$as_me:1959: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_RANLIB="ranlib" -echo "$as_me:1974: found $ac_dir/$ac_word" >&5 -break -done - - test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":" -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - echo "$as_me:1983: result: $ac_ct_RANLIB" >&5 -echo "${ECHO_T}$ac_ct_RANLIB" >&6 -else - echo "$as_me:1986: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - RANLIB=$ac_ct_RANLIB -else - RANLIB="$ac_cv_prog_RANLIB" -fi - -echo "$as_me:1995: checking for ${CC-cc} option to accept ANSI C" >&5 -echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6 -if test "${am_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - cat >conftest.$ac_ext <<_ACEOF -#line 2012 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; - -int -main () -{ - -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2054: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2057: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2060: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2063: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - am_cv_prog_cc_stdc="$ac_arg"; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -CC="$ac_save_CC" - -fi - -if test -z "$am_cv_prog_cc_stdc"; then - echo "$as_me:2077: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 -else - echo "$as_me:2080: result: $am_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$am_cv_prog_cc_stdc" >&6 -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac - -if test "x$am_cv_prog_cc_stdc" = xno ; then - { { echo "$as_me:2089: error: the C compiler doesn't handle ANSI-C" >&5 -echo "$as_me: error: the C compiler doesn't handle ANSI-C" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -echo "$as_me:2099: checking how to run the C preprocessor" >&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - # break 2 since there is a loop in there. - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2121 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2126: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2132: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2155 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2159: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2165: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break 2 -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:2202: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2212 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2217: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2223: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2246 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2250: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2256: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:2284: error: C preprocessor \"$CPP\" fails sanity check" >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:2295: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2301 "configure" -#include "confdefs.h" -#include -#include -#include -#include - -_ACEOF -if { (eval echo "$as_me:2309: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2315: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_header_stdc=no -fi -rm -f conftest.err conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2337 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2355 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 2376 "configure" -#include "confdefs.h" -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:2402: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2405: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:2407: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2410: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_stdc=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -fi -echo "$as_me:2423: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\EOF -#define STDC_HEADERS 1 -EOF - -fi - -for ac_header in limits.h malloc.h unistd.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:2436: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2442 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:2446: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2452: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:2471: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_prog_cc_stdc=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -#line 2489 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (eval echo "$as_me:2538: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2541: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2544: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2547: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_stdc=$ac_arg -break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext -done -rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC - -fi - -case "x$ac_cv_prog_cc_stdc" in - x|xno) - echo "$as_me:2564: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 ;; - *) - echo "$as_me:2567: result: $ac_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 - CC="$CC $ac_cv_prog_cc_stdc" ;; -esac - -echo "$as_me:2572: checking for an ANSI C-conforming const" >&5 -echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6 -if test "${ac_cv_c_const+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2578 "configure" -#include "confdefs.h" - -int -main () -{ -/* FIXME: Include the comments suggested by Paul. */ -#ifndef __cplusplus - /* Ultrix mips cc rejects this. */ - typedef int charset[2]; - const charset x; - /* SunOS 4.1.1 cc rejects this. */ - char const *const *ccp; - char **p; - /* NEC SVR4.0.2 mips cc rejects this. */ - struct point {int x, y;}; - static struct point const zero = {0,0}; - /* AIX XL C 1.02.0.0 rejects this. - It does not let you subtract one const X* pointer from another in - an arm of an if-expression whose if-part is not a constant - expression */ - const char *g = "string"; - ccp = &g + (g ? g-g : 0); - /* HPUX 7.0 cc rejects these. */ - ++ccp; - p = (char**) ccp; - ccp = (char const *const *) p; - { /* SCO 3.2v4 cc rejects this. */ - char *t; - char const *s = 0 ? (char *) 0 : (char const *) 0; - - *t++ = 0; - } - { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ - int x[] = {25, 17}; - const int *foo = &x[0]; - ++foo; - } - { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ - typedef const int *iptr; - iptr p = 0; - ++p; - } - { /* AIX XL C 1.02.0.0 rejects this saying - "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; }; - struct s *b; b->j = 5; - } - { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ - const int foo = 10; - } -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2636: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2639: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2642: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2645: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_const=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_const=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2655: result: $ac_cv_c_const" >&5 -echo "${ECHO_T}$ac_cv_c_const" >&6 -if test $ac_cv_c_const = no; then - -cat >>confdefs.h <<\EOF -#define const -EOF - -fi - -echo "$as_me:2665: checking for inline" >&5 -echo $ECHO_N "checking for inline... $ECHO_C" >&6 -if test "${ac_cv_c_inline+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_inline=no -for ac_kw in inline __inline__ __inline; do - cat >conftest.$ac_ext <<_ACEOF -#line 2673 "configure" -#include "confdefs.h" -#ifndef __cplusplus -static $ac_kw int static_foo () {return 0; } -$ac_kw int foo () {return 0; } -#endif - -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2682: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2685: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2688: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2691: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_inline=$ac_kw; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done - -fi -echo "$as_me:2702: result: $ac_cv_c_inline" >&5 -echo "${ECHO_T}$ac_cv_c_inline" >&6 -case $ac_cv_c_inline in - inline | yes) ;; - no) -cat >>confdefs.h <<\EOF -#define inline -EOF - ;; - *) cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2726 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:2730: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2736: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:2755: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for size_t... $ECHO_C" >&6 -if test "${ac_cv_type_size_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2771 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((size_t *) 0) - return 0; -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2786: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2789: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2792: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2795: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_size_t=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_size_t=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2805: result: $ac_cv_type_size_t" >&5 -echo "${ECHO_T}$ac_cv_type_size_t" >&6 -if test $ac_cv_type_size_t = yes; then - : -else - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for working alloca.h... $ECHO_C" >&6 -if test "${ac_cv_working_alloca_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2825 "configure" -#include "confdefs.h" -#include -int -main () -{ -char *p = (char *) alloca (2 * sizeof (int)); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:2837: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2840: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:2843: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2846: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_working_alloca_h=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_working_alloca_h=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:2856: result: $ac_cv_working_alloca_h" >&5 -echo "${ECHO_T}$ac_cv_working_alloca_h" >&6 -if test $ac_cv_working_alloca_h = yes; then - -cat >>confdefs.h <<\EOF -#define HAVE_ALLOCA_H 1 -EOF - -fi - -echo "$as_me:2866: checking for alloca" >&5 -echo $ECHO_N "checking for alloca... $ECHO_C" >&6 -if test "${ac_cv_func_alloca_works+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2872 "configure" -#include "confdefs.h" -#ifdef __GNUC__ -# define alloca __builtin_alloca -#else -# ifdef _MSC_VER -# include -# define alloca _alloca -# else -# if HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -# endif -# endif -# endif -# endif -#endif - -int -main () -{ -char *p = (char *) alloca (1); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:2904: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2907: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:2910: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2913: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_alloca_works=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_func_alloca_works=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:2923: result: $ac_cv_func_alloca_works" >&5 -echo "${ECHO_T}$ac_cv_func_alloca_works" >&6 - -if test $ac_cv_func_alloca_works = yes; then - -cat >>confdefs.h <<\EOF -#define HAVE_ALLOCA 1 -EOF - -else - # The SVR3 libPW and SVR4 libucb both contain incompatible functions -# that cause trouble. Some versions do not even contain alloca or -# contain a buggy version. If you still want to use their alloca, -# use ar to extract alloca.o from them instead of compiling alloca.c. - -ALLOCA=alloca.$ac_objext - -cat >>confdefs.h <<\EOF -#define C_ALLOCA 1 -EOF - -echo "$as_me:2944: checking whether \`alloca.c' needs Cray hooks" >&5 -echo $ECHO_N "checking whether \`alloca.c' needs Cray hooks... $ECHO_C" >&6 -if test "${ac_cv_os_cray+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2950 "configure" -#include "confdefs.h" -#if defined(CRAY) && ! defined(CRAY2) -webecray -#else -wenotbecray -#endif - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "webecray" >/dev/null 2>&1; then - ac_cv_os_cray=yes -else - ac_cv_os_cray=no -fi -rm -f conftest* - -fi -echo "$as_me:2968: result: $ac_cv_os_cray" >&5 -echo "${ECHO_T}$ac_cv_os_cray" >&6 -if test $ac_cv_os_cray = yes; then - for ac_func in _getb67 GETB67 getb67; do - ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:2973: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2979 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3010: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3013: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3016: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3019: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3029: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - -cat >>confdefs.h <&5 -echo $ECHO_N "checking stack direction for C alloca... $ECHO_C" >&6 -if test "${ac_cv_c_stack_direction+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_c_stack_direction=0 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3052 "configure" -#include "confdefs.h" -int -find_stack_direction () -{ - static char *addr = 0; - auto char dummy; - if (addr == 0) - { - addr = &dummy; - return find_stack_direction (); - } - else - return (&dummy > addr) ? 1 : -1; -} - -int -main () -{ - exit (find_stack_direction () < 0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3075: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3078: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3080: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3083: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_stack_direction=1 -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_stack_direction=-1 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -echo "$as_me:3095: result: $ac_cv_c_stack_direction" >&5 -echo "${ECHO_T}$ac_cv_c_stack_direction" >&6 - -cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3113 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3144: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3147: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3150: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3153: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3163: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for _doprnt... $ECHO_C" >&6 -if test "${ac_cv_func__doprnt+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3176 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char _doprnt (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char _doprnt (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub__doprnt) || defined (__stub____doprnt) -choke me -#else -f = _doprnt; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3207: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3210: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3213: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3216: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func__doprnt=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_func__doprnt=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3226: result: $ac_cv_func__doprnt" >&5 -echo "${ECHO_T}$ac_cv_func__doprnt" >&6 -if test $ac_cv_func__doprnt = yes; then - -cat >>confdefs.h <<\EOF -#define HAVE_DOPRNT 1 -EOF - -fi - -fi -done - -for ac_func in strerror -do -ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:3242: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3248 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3279: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3282: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3285: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3288: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3298: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3317 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3348: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3351: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3354: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3357: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3367: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3388 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3419: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3422: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3425: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3428: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3438: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3457 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3488: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3491: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3494: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3497: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3507: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3526 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3557: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3560: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3563: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3566: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3576: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for program_invocation_name... $ECHO_C" >&6 -if test "${lsh_cv_var_program_invocation_name+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3592 "configure" -#include "confdefs.h" -#include -int -main () -{ -void *p = (void *) &program_invocation_name; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3604: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3607: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3610: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3613: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_var_program_invocation_name=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_var_program_invocation_name=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3623: result: $lsh_cv_var_program_invocation_name" >&5 -echo "${ECHO_T}$lsh_cv_var_program_invocation_name" >&6 - if eval "test \"`echo '$lsh_cv_var_'program_invocation_name`\" = yes"; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for program_invocation_short_name... $ECHO_C" >&6 -if test "${lsh_cv_var_program_invocation_short_name+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3638 "configure" -#include "confdefs.h" -#include -int -main () -{ -void *p = (void *) &program_invocation_short_name; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3650: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3653: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3656: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3659: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_var_program_invocation_short_name=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_var_program_invocation_short_name=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3669: result: $lsh_cv_var_program_invocation_short_name" >&5 -echo "${ECHO_T}$lsh_cv_var_program_invocation_short_name" >&6 - if eval "test \"`echo '$lsh_cv_var_'program_invocation_short_name`\" = yes"; then - cat >>confdefs.h <confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overriden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -{ - (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} | - sed ' - t clear - : clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - : end' >>confcache -if cmp -s $cache_file confcache; then :; else - if test -w $cache_file; then - test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" - cat confcache >$cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/; -s/:*\${srcdir}:*/:/; -s/:*@srcdir@:*/:/; -s/^\([^=]*=[ ]*\):*/\1/; -s/:*$//; -s/^[^=]*=[ ]*$//; -}' -fi - -DEFS=-DHAVE_CONFIG_H - -: ${CONFIG_STATUS=./config.status} -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ echo "$as_me:3768: creating $CONFIG_STATUS" >&5 -echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF -#! $SHELL -# Generated automatically by configure. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -SHELL=\${CONFIG_SHELL-$SHELL} -ac_cs_invocation="\$0 \$@" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -exec 6>&1 - -_ACEOF - -# Files that config.status was made for. -if test -n "$ac_config_files"; then - echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_headers"; then - echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_links"; then - echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_commands"; then - echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS -fi - -cat >>$CONFIG_STATUS <<\EOF - -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTIONS] [FILE]... - - -h, --help print this help, then exit - -V, --version print version number, then exit - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to ." -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -# If no file are specified by the user, then we need to provide default -# value. By we need to know if files were specified by the user. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "x$1" : 'x\([^=]*\)='` - ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` - shift - set dummy "$ac_option" "$ac_optarg" ${1+"$@"} - shift - ;; - -*);; - *) # This is not an option, so the user has probably given explicit - # arguments. - ac_need_defaults=false;; - esac - - case $1 in - # Handling of the options. -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF - --version | --vers* | -V ) - echo "$ac_cs_version"; exit 0 ;; - --he | --h) - # Conflict between --help and --header - { { echo "$as_me:3944: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - echo "$ac_cs_usage"; exit 0 ;; - --debug | --d* | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - shift - CONFIG_FILES="$CONFIG_FILES $1" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - shift - CONFIG_HEADERS="$CONFIG_HEADERS $1" - ac_need_defaults=false;; - - # Handling of arguments. - 'Makefile' ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; - 'default-1' ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; - 'config.h' ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - - # This is an error. - -*) { { echo "$as_me:3968: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; } ;; - *) { { echo "$as_me:3973: error: invalid argument: $1" >&5 -echo "$as_me: error: invalid argument: $1" >&2;} - { (exit 1); exit 1; }; };; - esac - shift -done - -exec 5>>config.log -cat >&5 << _ACEOF - -## ----------------------- ## -## Running config.status. ## -## ----------------------- ## - -This file was extended by $as_me 2.50, executed with - > $ac_cs_invocation -on `(hostname || uname -n) 2>/dev/null | sed 1q` - -_ACEOF -EOF - -cat >>$CONFIG_STATUS <<\EOF -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Create a temporary directory, and hook for its removal unless debugging. -$debug || -{ - trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 - trap '{ (exit $?); exit $?; }' 1 2 13 15 -} - -# Create a (secure) tmp directory for tmp files. -: ${TMPDIR=/tmp} -{ - tmp=`(umask 077 && mktemp -d -q "$TMPDIR/csXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=$TMPDIR/cs$$-$RANDOM - (umask 077 && mkdir $tmp) -} || -{ - echo "$me: cannot create a temporary directory in $TMPDIR" >&2 - { (exit 1); exit 1; } -} - -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <\$tmp/subs.sed <<\\CEOF -s,@SHELL@,$SHELL,;t t -s,@exec_prefix@,$exec_prefix,;t t -s,@prefix@,$prefix,;t t -s,@program_transform_name@,$program_transform_name,;t t -s,@bindir@,$bindir,;t t -s,@sbindir@,$sbindir,;t t -s,@libexecdir@,$libexecdir,;t t -s,@datadir@,$datadir,;t t -s,@sysconfdir@,$sysconfdir,;t t -s,@sharedstatedir@,$sharedstatedir,;t t -s,@localstatedir@,$localstatedir,;t t -s,@libdir@,$libdir,;t t -s,@includedir@,$includedir,;t t -s,@oldincludedir@,$oldincludedir,;t t -s,@infodir@,$infodir,;t t -s,@mandir@,$mandir,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t -s,@ECHO_C@,$ECHO_C,;t t -s,@ECHO_N@,$ECHO_N,;t t -s,@ECHO_T@,$ECHO_T,;t t -s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t -s,@DEFS@,$DEFS,;t t -s,@LIBS@,$LIBS,;t t -s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t -s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t -s,@INSTALL_DATA@,$INSTALL_DATA,;t t -s,@PACKAGE@,$PACKAGE,;t t -s,@VERSION@,$VERSION,;t t -s,@ACLOCAL@,$ACLOCAL,;t t -s,@AUTOCONF@,$AUTOCONF,;t t -s,@AUTOMAKE@,$AUTOMAKE,;t t -s,@AUTOHEADER@,$AUTOHEADER,;t t -s,@MAKEINFO@,$MAKEINFO,;t t -s,@SET_MAKE@,$SET_MAKE,;t t -s,@CC@,$CC,;t t -s,@CFLAGS@,$CFLAGS,;t t -s,@LDFLAGS@,$LDFLAGS,;t t -s,@CPPFLAGS@,$CPPFLAGS,;t t -s,@ac_ct_CC@,$ac_ct_CC,;t t -s,@EXEEXT@,$EXEEXT,;t t -s,@OBJEXT@,$OBJEXT,;t t -s,@RANLIB@,$RANLIB,;t t -s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t -s,@CPP@,$CPP,;t t -s,@ALLOCA@,$ALLOCA,;t t -s,@LIBOBJS@,$LIBOBJS,;t t -CEOF - -EOF - - cat >>$CONFIG_STATUS <<\EOF - # Split the substitutions into bite-sized pieces for seds with - # small command number limits, like on Digital OSF/1 and HP-UX. - ac_max_sed_lines=48 - ac_sed_frag=1 # Number of current file. - ac_beg=1 # First line for current file. - ac_end=$ac_max_sed_lines # Line after last line for current file. - ac_more_lines=: - ac_sed_cmds= - while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - else - sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - fi - if test ! -s $tmp/subs.frag; then - ac_more_lines=false - else - # The purpose of the label and of the branching condition is to - # speed up the sed processing (if there are no `@' at all, there - # is no need to browse any of the substitutions). - # These are the two extra sed commands mentioned above. - (echo ':t - /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" - else - ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" - fi - ac_sed_frag=`expr $ac_sed_frag + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_lines` - fi - done - if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat - fi -fi # test -n "$CONFIG_FILES" - -EOF -cat >>$CONFIG_STATUS <<\EOF -for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - ac_dir_suffix="/`echo $ac_dir|sed 's,^\./,,'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo "$ac_dir_suffix" | sed 's,/[^/]*,../,g'` - else - ac_dir_suffix= ac_dots= - fi - - case $srcdir in - .) ac_srcdir=. - if test -z "$ac_dots"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_dots | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_dots$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_dots$srcdir ;; - esac - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_dots$INSTALL ;; - esac - - if test x"$ac_file" != x-; then - { echo "$as_me:4212: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - configure_input="Generated automatically from `echo $ac_file_in | - sed 's,.*/,,'` by configure." - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:4230: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:4243: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s,@configure_input@,$configure_input,;t t -s,@srcdir@,$ac_srcdir,;t t -s,@top_srcdir@,$ac_top_srcdir,;t t -s,@INSTALL@,$ac_INSTALL,;t t -" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out - rm -f $tmp/stdin - if test x"$ac_file" != x-; then - mv $tmp/out $ac_file - else - cat $tmp/out - rm -f $tmp/out - fi - -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_HEADER section. -# - -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' -ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t' - -for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - test x"$ac_file" != x- && { echo "$as_me:4304: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:4315: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:4328: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } - # Remove the trailing spaces. - sed 's/[ ]*$//' $ac_file_inputs >$tmp/in - -EOF - -# Transform confdefs.h into two sed scripts, `conftest.defines' and -# `conftest.undefs', that substitutes the proper values into -# config.h.in to produce config.h. The first handles `#define' -# templates, and the second `#undef' templates. -# And first: Protect against being on the right side of a sed subst in -# config.status. Protect against being in an unquoted here document -# in config.status. -rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. -# Putting comments in sed scripts is not portable. -# -# `end' is used to avoid that the second main sed command (meant for -# 0-ary CPP macros) applies to n-ary macro definitions. -# See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\EOF -s/[\\&,]/\\&/g -s,[\\$`],\\&,g -t clear -: clear -s,^[ ]*#[ ]*define[ ][ ]*\(\([^ (][^ (]*\)([^)]*)\)[ ]*\(.*\)$,${ac_dA}\2${ac_dB}\1${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end -EOF -# If some macros were called several times there might be several times -# the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. -uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs -rm -f confdef2sed.sed - -# This sed command replaces #undef with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\EOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -EOF - -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if egrep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.defines >/dev/null -do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/defines.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail - rm -f conftest.defines - mv conftest.tail conftest.defines -done -rm -f conftest.defines -echo ' fi # egrep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/undefs.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs - -cat >>$CONFIG_STATUS <<\EOF - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - if test x"$ac_file" = x-; then - echo "/* Generated automatically by configure. */" >$tmp/config.h - else - echo "/* $ac_file. Generated automatically by configure. */" >$tmp/config.h - fi - cat $tmp/in >>$tmp/config.h - rm -f $tmp/in - if test x"$ac_file" != x-; then - if cmp -s $ac_file $tmp/config.h 2>/dev/null; then - { echo "$as_me:4445: $ac_file is unchanged" >&5 -echo "$as_me: $ac_file is unchanged" >&6;} - else - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - fi - rm -f $ac_file - mv $tmp/config.h $ac_file - fi - else - cat $tmp/config.h - rm -f $tmp/config.h - fi -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_COMMANDS section. -# -for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue - ac_dest=`echo "$ac_file" | sed 's,:.*,,'` - ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'` - - case $ac_dest in - default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;; - esac -done -EOF - -cat >>$CONFIG_STATUS <<\EOF - -{ (exit 0); exit 0; } -EOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - exec 5>/dev/null - $SHELL $CONFIG_STATUS || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi - diff --git a/lsh/src/argp/configure.in b/lsh/src/argp/configure.in deleted file mode 100755 index 0da46c2..0000000 Binary files a/lsh/src/argp/configure.in and /dev/null differ diff --git a/lsh/src/argp/mempcpy.c b/lsh/src/argp/mempcpy.c deleted file mode 100755 index 6fa228b..0000000 --- a/lsh/src/argp/mempcpy.c +++ /dev/null @@ -1,18 +0,0 @@ -/* strndup.c - * - */ - -/* Written by Niels Möller - * - * This file is hereby placed in the public domain. - */ - -#include - -void * -mempcpy (void *to, const void *from, size_t size) -{ - memcpy(to, from, size); - return (char *) to + size; -} - diff --git a/lsh/src/argp/stamp-h.in b/lsh/src/argp/stamp-h.in deleted file mode 100755 index 9176ac3..0000000 Binary files a/lsh/src/argp/stamp-h.in and /dev/null differ diff --git a/lsh/src/argp/strchrnul.c b/lsh/src/argp/strchrnul.c deleted file mode 100755 index af1b4bb..0000000 --- a/lsh/src/argp/strchrnul.c +++ /dev/null @@ -1,21 +0,0 @@ -/* strchrnul.c - * - */ - -/* Written by Niels Möller - * - * This file is hereby placed in the public domain. - */ - -/* FIXME: What is this function supposed to do? My guess is that it is - * like strchr, but returns a pointer to the NUL character, not a NULL - * pointer, if the character isn't found. */ - -char *strchrnul(const char *s, int c) -{ - const char *p = s; - while (*p && (*p != c)) - p++; - - return (char *) p; -} diff --git a/lsh/src/argp/strndup.c b/lsh/src/argp/strndup.c deleted file mode 100755 index f01065a..0000000 --- a/lsh/src/argp/strndup.c +++ /dev/null @@ -1,31 +0,0 @@ -/* strndup.c - * - */ - -/* Written by Niels Möller - * - * This file is hereby placed in the public domain. - */ - -#include -#include - -char * -strndup (const char *s, size_t size) -{ - char *r; - char *end = memchr(s, 0, size); - - if (end) - /* Length + 1 */ - size = end - s + 1; - - r = malloc(size); - - if (size) - { - memcpy(r, s, size-1); - r[size-1] = '\0'; - } - return r; -} diff --git a/lsh/src/atoms.c b/lsh/src/atoms.c deleted file mode 100755 index 5c190d7..0000000 --- a/lsh/src/atoms.c +++ /dev/null @@ -1,60 +0,0 @@ -/* atoms.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "atoms.h" - -#include - -struct atom_rassoc -{ - const UINT8 *name; - UINT32 length; -}; - -const struct atom_assoc * -gperf_atom (const char *str, unsigned int len); - -#include "atoms_gperf.c" - -struct atom_rassoc atom_table[] = -#include "atoms_table.c" -; - -UINT32 get_atom_length(int atom) -{ return atom_table[atom].length; } - -const UINT8 *get_atom_name(int atom) -{ return atom_table[atom].name; } - -int -lookup_atom(UINT32 length, const UINT8 *name) -{ - /* NOTE: The automatically generated code uses const char *, and - * some compilers signal a fatal error on char * / unsigned char * - * mismatch. */ - const struct atom_assoc *pair = gperf_atom( (const char *) name, length); - - return pair ? pair->id : 0; -} diff --git a/lsh/src/atoms.h b/lsh/src/atoms.h deleted file mode 100755 index d1eccf8..0000000 --- a/lsh/src/atoms.h +++ /dev/null @@ -1,39 +0,0 @@ -/* atoms.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ATOMS_H_INCLUDED -#define LSH_ATOMS_H_INCLUDED - -#include "lsh_types.h" -#include "atoms_defines.h" - -/* Atoms are represented as plain (small) ints. Zero is used for all - * atoms we don't know about. */ - -UINT32 get_atom_length(int atom); -const UINT8 *get_atom_name(int atom); -int lookup_atom(UINT32 length, const UINT8 *name); - -#endif /* LSH_ATOMS_H_INCLUDED */ diff --git a/lsh/src/atoms.in b/lsh/src/atoms.in deleted file mode 100755 index 981b61d..0000000 Binary files a/lsh/src/atoms.in and /dev/null differ diff --git a/lsh/src/atoms_defines.h b/lsh/src/atoms_defines.h deleted file mode 100755 index 20b6d55..0000000 --- a/lsh/src/atoms_defines.h +++ /dev/null @@ -1,120 +0,0 @@ -/* Automatically generated by process_atoms, - * Sat Mar 17 21:48:51 CET 2001 - * Do not edit! */ - -#define ATOM_NONE 1 -#define ATOM_ZLIB 2 -#define ATOM_3DES_CBC 3 -#define ATOM_BLOWFISH_CBC 4 -#define ATOM_TWOFISH256_CBC 5 -#define ATOM_TWOFISH_CBC 6 -#define ATOM_TWOFISH192_CBC 7 -#define ATOM_TWOFISH128_CBC 8 -#define ATOM_AES256_CBC 9 -#define ATOM_AES192_CBC 10 -#define ATOM_AES128_CBC 11 -#define ATOM_SERPENT256_CBC 12 -#define ATOM_SERPENT192_CBC 13 -#define ATOM_SERPENT128_CBC 14 -#define ATOM_RIJNDAEL_CBC_LOCAL 15 -#define ATOM_SERPENT_CBC_LOCAL 16 -#define ATOM_ARCFOUR 17 -#define ATOM_IDEA_CBC 18 -#define ATOM_CAST128_CBC 19 -#define ATOM_HMAC_SHA1 20 -#define ATOM_HMAC_SHA1_96 21 -#define ATOM_HMAC_MD5 22 -#define ATOM_HMAC_MD5_96 23 -#define ATOM_DIFFIE_HELLMAN_GROUP1_SHA1 24 -#define ATOM_SSH_DSS 25 -#define ATOM_SSH_RSA 26 -#define ATOM_X509V3_SIGN_RSA 27 -#define ATOM_X509V3_SIGN_DSS 28 -#define ATOM_SPKI_SIGN_RSA 29 -#define ATOM_SPKI_SIGN_DSS 30 -#define ATOM_PGP_SIGN_RSA 31 -#define ATOM_PGP_SIGN_DSS 32 -#define ATOM_SSH_DSS_KLUDGE_LOCAL 33 -#define ATOM_SSH_USERAUTH 34 -#define ATOM_SSH_CONNECTION 35 -#define ATOM_PUBLICKEY 36 -#define ATOM_PASSWORD 37 -#define ATOM_HOSTBASED 38 -#define ATOM_SESSION 39 -#define ATOM_PTY_REQ 40 -#define ATOM_X11_REQ 41 -#define ATOM_X11 42 -#define ATOM_AUTH_AGENT_REQ 43 -#define ATOM_AUTH_AGENT 44 -#define ATOM_AUTH_SSH1_AGENT_REQ 45 -#define ATOM_AUTH_SSH1_AGENT 46 -#define ATOM_ENV 47 -#define ATOM_SHELL 48 -#define ATOM_EXEC 49 -#define ATOM_SUBSYSTEM 50 -#define ATOM_WINDOW_CHANGE 51 -#define ATOM_XON_XOFF 52 -#define ATOM_SIGNAL 53 -#define ATOM_EXIT_STATUS 54 -#define ATOM_EXIT_SIGNAL 55 -#define ATOM_TCPIP_FORWARD 56 -#define ATOM_CANCEL_TCPIP_FORWARD 57 -#define ATOM_FORWARDED_TCPIP 58 -#define ATOM_DIRECT_TCPIP 59 -#define ATOM_ABRT 60 -#define ATOM_ALRM 61 -#define ATOM_FPE 62 -#define ATOM_HUP 63 -#define ATOM_ILL 64 -#define ATOM_INT 65 -#define ATOM_KILL 66 -#define ATOM_PIPE 67 -#define ATOM_QUIT 68 -#define ATOM_SEGV 69 -#define ATOM_TERM 70 -#define ATOM_USR1 71 -#define ATOM_USR2 72 -#define ATOM_SIGNAL_UNKNOWN_LOCAL 73 -#define ATOM_PRIVATE_KEY 74 -#define ATOM_PUBLIC_KEY 75 -#define ATOM_DSA 76 -#define ATOM_P 77 -#define ATOM_Q 78 -#define ATOM_G 79 -#define ATOM_Y 80 -#define ATOM_X 81 -#define ATOM_R 82 -#define ATOM_S 83 -#define ATOM_RSA_PKCS1_SHA1 84 -#define ATOM_RSA_PKCS1_MD5 85 -#define ATOM_N 86 -#define ATOM_E 87 -#define ATOM_D 88 -#define ATOM_A 89 -#define ATOM_B 90 -#define ATOM_C 91 -#define ATOM_HASH 92 -#define ATOM_MD5 93 -#define ATOM_SHA1 94 -#define ATOM_PASSWORD_ENCRYPTED 95 -#define ATOM_XPKCS5V2 96 -#define ATOM_ITERATIONS 97 -#define ATOM_SALT 98 -#define ATOM_DATA 99 -#define ATOM_IV 100 -#define ATOM_SEQUENCE 101 -#define ATOM_CERTIFICATE 102 -#define ATOM_SIGNATURE 103 -#define ATOM_NAME 104 -#define ATOM_ACL 105 -#define ATOM_VERSION 106 -#define ATOM_ENTRY 107 -#define ATOM_PROPAGATE 108 -#define ATOM_TAG 109 -#define ATOM_PREFIX 110 -#define ATOM_SET 111 -#define ATOM_STAR 112 -#define ATOM_SRP_RING1_SHA1_LOCAL 113 -#define ATOM_SRP_VERIFIER 114 -#define ATOM_SSH_RING1 115 -#define NUMBER_OF_ATOMS 116 diff --git a/lsh/src/atoms_gperf.c b/lsh/src/atoms_gperf.c deleted file mode 100755 index 56fcde3..0000000 --- a/lsh/src/atoms_gperf.c +++ /dev/null @@ -1,350 +0,0 @@ -/* ANSI-C code produced by gperf version 2.7 */ -/* Command-line: gperf -LANSI-C -t -c -C -l -k1,3,6,10,$ -N gperf_atom */ -/* Automatically generated by process_atoms, - * Tue Jun 26 23:51:53 CEST 2001 - * Do not edit! */ - -struct atom_assoc { const char *name; int id; }; - -#define TOTAL_KEYWORDS 115 -#define MIN_WORD_LENGTH 1 -#define MAX_WORD_LENGTH 29 -#define MIN_HASH_VALUE 1 -#define MAX_HASH_VALUE 488 -/* maximum key range = 488, duplicates = 0 */ - -#ifdef __GNUC__ -__inline -#endif -static unsigned int -hash (register const char *str, register unsigned int len) -{ - static const unsigned short asso_values[] = - { - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 5, 489, 489, 0, 489, 489, 0, 30, - 45, 20, 489, 10, 50, 489, 20, 0, 489, 489, - 489, 489, 489, 489, 489, 12, 489, 489, 489, 35, - 5, 55, 40, 35, 489, 50, 5, 10, 489, 489, - 0, 15, 0, 0, 0, 60, 0, 489, 5, 489, - 489, 489, 489, 489, 489, 489, 489, 40, 85, 108, - 90, 125, 50, 60, 0, 65, 0, 125, 5, 35, - 65, 10, 75, 25, 45, 0, 0, 25, 0, 10, - 80, 105, 35, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489, 489, 489, 489, 489, - 489, 489, 489, 489, 489, 489 - }; - register int hval = len; - - switch (hval) - { - default: - case 10: - hval += asso_values[(unsigned char)str[9]]; - case 9: - case 8: - case 7: - case 6: - hval += asso_values[(unsigned char)str[5]]; - case 5: - case 4: - case 3: - hval += asso_values[(unsigned char)str[2]]; - case 2: - case 1: - hval += asso_values[(unsigned char)str[0]]; - break; - } - return hval + asso_values[(unsigned char)str[len - 1]]; -} - -#ifdef __GNUC__ -__inline -#endif -const struct atom_assoc * -gperf_atom (register const char *str, register unsigned int len) -{ - static const unsigned char lengthtable[] = - { - 0, 1, 0, 3, 4, 0, 0, 7, 0, 4, 0, 1, 0, 0, - 4, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 3, 4, 0, 0, - 0, 3, 0, 0, 0, 7, 3, 0, 0, 1, 0, 3, 4, 15, - 0, 0, 3, 4, 0, 0, 0, 0, 4, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 4, 0, 6, 0, 3, 9, 0, 1, 7, 0, - 19, 0, 0, 0, 0, 0, 10, 1, 0, 8, 4, 0, 0, 0, - 0, 0, 0, 0, 12, 0, 9, 0, 0, 0, 0, 4, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 14, 0, 1, 0, 3, 0, 0, - 0, 7, 3, 9, 0, 1, 0, 0, 4, 5, 11, 0, 13, 9, - 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 14, 0, - 0, 0, 0, 0, 0, 29, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 3, 0, 15, 0, 14, 13, 0, 0, 1, - 14, 8, 0, 0, 0, 0, 13, 4, 0, 0, 0, 8, 9, 0, - 0, 14, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 8, 11, 15, 0, 1, 0, 0, 0, 0, 0, 8, - 0, 7, 11, 0, 0, 4, 15, 0, 0, 13, 0, 5, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 1, - 14, 0, 14, 0, 0, 0, 0, 4, 0, 0, 0, 13, 0, 0, - 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 9, - 0, 0, 14, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, - 29, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 10, 12, 0, 0, 0, 10, 12, 18, 0, 0, 0, - 12, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 7, 0, 11, 0, 0, 0, 0, 29, 27, 26, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 4, 20, - 0, 0, 6, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 11, 9, 0, 0, 0, 0, 0, 12, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 - }; - static const struct atom_assoc wordlist[] = - { - {"", 0}, - {"s", ATOM_S}, - {"", 0}, - {"set", ATOM_SET}, - {"hash", ATOM_HASH}, - {"", 0}, {"", 0}, - {"ssh-dss", ATOM_SSH_DSS}, - {"", 0}, - {"salt", ATOM_SALT}, - {"", 0}, - {"*", ATOM_STAR}, - {"", 0}, {"", 0}, - {"TERM", ATOM_TERM}, - {"", 0}, - {"ABRT", ATOM_ABRT}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"ALRM", ATOM_ALRM}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, - {"ssh-userauth", ATOM_SSH_USERAUTH}, - {"INT", ATOM_INT}, - {"PIPE", ATOM_PIPE}, - {"", 0}, {"", 0}, {"", 0}, - {"HUP", ATOM_HUP}, - {"", 0}, {"", 0}, {"", 0}, - {"ssh-rsa", ATOM_SSH_RSA}, - {"ILL", ATOM_ILL}, - {"", 0}, {"", 0}, - {"q", ATOM_Q}, - {"", 0}, - {"acl", ATOM_ACL}, - {"QUIT", ATOM_QUIT}, - {"auth-ssh1-agent", ATOM_AUTH_SSH1_AGENT}, - {"", 0}, {"", 0}, - {"md5", ATOM_MD5}, - {"SEGV", ATOM_SEGV}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"KILL", ATOM_KILL}, - {"", 0}, {"", 0}, - {"iv", ATOM_IV}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"sha1", ATOM_SHA1}, - {"", 0}, - {"signal", ATOM_SIGNAL}, - {"", 0}, - {"FPE", ATOM_FPE}, - {"hmac-sha1", ATOM_HMAC_SHA1}, - {"", 0}, - {"a", ATOM_A}, - {"session", ATOM_SESSION}, - {"", 0}, - {"auth-ssh1-agent-req", ATOM_AUTH_SSH1_AGENT_REQ}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"auth-agent", ATOM_AUTH_AGENT}, - {"r", ATOM_R}, - {"", 0}, - {"hmac-md5", ATOM_HMAC_MD5}, - {"USR1", ATOM_USR1}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"hmac-sha1-96", ATOM_HMAC_SHA1_96}, - {"", 0}, - {"ssh-ring1", ATOM_SSH_RING1}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"USR2", ATOM_USR2}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"auth-agent-req", ATOM_AUTH_AGENT_REQ}, - {"", 0}, - {"g", ATOM_G}, - {"", 0}, - {"tag", ATOM_TAG}, - {"", 0}, {"", 0}, {"", 0}, - {"version", ATOM_VERSION}, - {"env", ATOM_ENV}, - {"subsystem", ATOM_SUBSYSTEM}, - {"", 0}, - {"n", ATOM_N}, - {"", 0}, {"", 0}, - {"data", ATOM_DATA}, - {"shell", ATOM_SHELL}, - {"hmac-md5-96", ATOM_HMAC_MD5_96}, - {"", 0}, - {"spki-sign-dss", ATOM_SPKI_SIGN_DSS}, - {"hostbased", ATOM_HOSTBASED}, - {"", 0}, {"", 0}, {"", 0}, - {"x11", ATOM_X11}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"p", ATOM_P}, - {"twofish128-cbc", ATOM_TWOFISH128_CBC}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"ssh-dss-kludge@lysator.liu.se", ATOM_SSH_DSS_KLUDGE_LOCAL}, - {"", 0}, - {"x", ATOM_X}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"b", ATOM_B}, - {"", 0}, - {"dsa", ATOM_DSA}, - {"", 0}, - {"x509v3-sign-dss", ATOM_X509V3_SIGN_DSS}, - {"", 0}, - {"twofish192-cbc", ATOM_TWOFISH192_CBC}, - {"spki-sign-rsa", ATOM_SPKI_SIGN_RSA}, - {"", 0}, {"", 0}, - {"d", ATOM_D}, - {"twofish256-cbc", ATOM_TWOFISH256_CBC}, - {"password", ATOM_PASSWORD}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"tcpip-forward", ATOM_TCPIP_FORWARD}, - {"zlib", ATOM_ZLIB}, - {"", 0}, {"", 0}, {"", 0}, - {"Xpkcs5v2", ATOM_XPKCS5V2}, - {"signature", ATOM_SIGNATURE}, - {"", 0}, {"", 0}, - {"ssh-connection", ATOM_SSH_CONNECTION}, - {"", 0}, {"", 0}, - {"iterations", ATOM_ITERATIONS}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, - {"y", ATOM_Y}, - {"", 0}, - {"xon-xoff", ATOM_XON_XOFF}, - {"twofish-cbc", ATOM_TWOFISH_CBC}, - {"x509v3-sign-rsa", ATOM_X509V3_SIGN_RSA}, - {"", 0}, - {"c", ATOM_C}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"sequence", ATOM_SEQUENCE}, - {"", 0}, - {"arcfour", ATOM_ARCFOUR}, - {"exit-status", ATOM_EXIT_STATUS}, - {"", 0}, {"", 0}, - {"name", ATOM_NAME}, - {"forwarded-tcpip", ATOM_FORWARDED_TCPIP}, - {"", 0}, {"", 0}, - {"rsa-pkcs1-md5", ATOM_RSA_PKCS1_MD5}, - {"", 0}, - {"entry", ATOM_ENTRY}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, - {"exit-signal", ATOM_EXIT_SIGNAL}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"e", ATOM_E}, - {"serpent128-cbc", ATOM_SERPENT128_CBC}, - {"", 0}, - {"rsa-pkcs1-sha1", ATOM_RSA_PKCS1_SHA1}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"none", ATOM_NONE}, - {"", 0}, {"", 0}, {"", 0}, - {"window-change", ATOM_WINDOW_CHANGE}, - {"", 0}, {"", 0}, {"", 0}, - {"x11-req", ATOM_X11_REQ}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"serpent192-cbc", ATOM_SERPENT192_CBC}, - {"", 0}, - {"propagate", ATOM_PROPAGATE}, - {"", 0}, {"", 0}, - {"serpent256-cbc", ATOM_SERPENT256_CBC}, - {"", 0}, {"", 0}, {"", 0}, - {"aes128-cbc", ATOM_AES128_CBC}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"srp-ring1-sha1@lysator.liu.se", ATOM_SRP_RING1_SHA1_LOCAL}, - {"", 0}, {"", 0}, - {"direct-tcpip", ATOM_DIRECT_TCPIP}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"aes192-cbc", ATOM_AES192_CBC}, - {"pgp-sign-rsa", ATOM_PGP_SIGN_RSA}, - {"", 0}, {"", 0}, {"", 0}, - {"aes256-cbc", ATOM_AES256_CBC}, - {"pgp-sign-dss", ATOM_PGP_SIGN_DSS}, - {"password-encrypted", ATOM_PASSWORD_ENCRYPTED}, - {"", 0}, {"", 0}, {"", 0}, - {"srp-verifier", ATOM_SRP_VERIFIER}, - {"", 0}, {"", 0}, {"", 0}, - {"diffie-hellman-group1-sha1", ATOM_DIFFIE_HELLMAN_GROUP1_SHA1}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, - {"pty-req", ATOM_PTY_REQ}, - {"", 0}, - {"certificate", ATOM_CERTIFICATE}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"signal-unknown@lysator.liu.se", ATOM_SIGNAL_UNKNOWN_LOCAL}, - {"rijndael-cbc@lysator.liu.se", ATOM_RIJNDAEL_CBC_LOCAL}, - {"serpent-cbc@lysator.liu.se", ATOM_SERPENT_CBC_LOCAL}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, - {"cast128-cbc", ATOM_CAST128_CBC}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"exec", ATOM_EXEC}, - {"cancel-tcpip-forward", ATOM_CANCEL_TCPIP_FORWARD}, - {"", 0}, {"", 0}, - {"prefix", ATOM_PREFIX}, - {"", 0}, {"", 0}, - {"3des-cbc", ATOM_3DES_CBC}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, - {"private-key", ATOM_PRIVATE_KEY}, - {"publickey", ATOM_PUBLICKEY}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"blowfish-cbc", ATOM_BLOWFISH_CBC}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"idea-cbc", ATOM_IDEA_CBC}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, {"", 0}, - {"", 0}, - {"public-key", ATOM_PUBLIC_KEY} - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - if (len == lengthtable[key]) - { - register const char *s = wordlist[key].name; - - if (*str == *s && !strncmp (str + 1, s + 1, len - 1)) - return &wordlist[key]; - } - } - return 0; -} diff --git a/lsh/src/atoms_table.c b/lsh/src/atoms_table.c deleted file mode 100755 index d802178..0000000 --- a/lsh/src/atoms_table.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Automatically generated by process_atoms, - * Sat Mar 17 21:50:34 CET 2001 - * Do not edit! */ - -{ { "UNKNOWN", 7 }, - { "none", 4 }, - { "zlib", 4 }, - { "3des-cbc", 8 }, - { "blowfish-cbc", 12 }, - { "twofish256-cbc", 14 }, - { "twofish-cbc", 11 }, - { "twofish192-cbc", 14 }, - { "twofish128-cbc", 14 }, - { "aes256-cbc", 10 }, - { "aes192-cbc", 10 }, - { "aes128-cbc", 10 }, - { "serpent256-cbc", 14 }, - { "serpent192-cbc", 14 }, - { "serpent128-cbc", 14 }, - { "rijndael-cbc@lysator.liu.se", 27 }, - { "serpent-cbc@lysator.liu.se", 26 }, - { "arcfour", 7 }, - { "idea-cbc", 8 }, - { "cast128-cbc", 11 }, - { "hmac-sha1", 9 }, - { "hmac-sha1-96", 12 }, - { "hmac-md5", 8 }, - { "hmac-md5-96", 11 }, - { "diffie-hellman-group1-sha1", 26 }, - { "ssh-dss", 7 }, - { "ssh-rsa", 7 }, - { "x509v3-sign-rsa", 15 }, - { "x509v3-sign-dss", 15 }, - { "spki-sign-rsa", 13 }, - { "spki-sign-dss", 13 }, - { "pgp-sign-rsa", 12 }, - { "pgp-sign-dss", 12 }, - { "ssh-dss-kludge@lysator.liu.se", 29 }, - { "ssh-userauth", 12 }, - { "ssh-connection", 14 }, - { "publickey", 9 }, - { "password", 8 }, - { "hostbased", 9 }, - { "session", 7 }, - { "pty-req", 7 }, - { "x11-req", 7 }, - { "x11", 3 }, - { "auth-agent-req", 14 }, - { "auth-agent", 10 }, - { "auth-ssh1-agent-req", 19 }, - { "auth-ssh1-agent", 15 }, - { "env", 3 }, - { "shell", 5 }, - { "exec", 4 }, - { "subsystem", 9 }, - { "window-change", 13 }, - { "xon-xoff", 8 }, - { "signal", 6 }, - { "exit-status", 11 }, - { "exit-signal", 11 }, - { "tcpip-forward", 13 }, - { "cancel-tcpip-forward", 20 }, - { "forwarded-tcpip", 15 }, - { "direct-tcpip", 12 }, - { "ABRT", 4 }, - { "ALRM", 4 }, - { "FPE", 3 }, - { "HUP", 3 }, - { "ILL", 3 }, - { "INT", 3 }, - { "KILL", 4 }, - { "PIPE", 4 }, - { "QUIT", 4 }, - { "SEGV", 4 }, - { "TERM", 4 }, - { "USR1", 4 }, - { "USR2", 4 }, - { "signal-unknown@lysator.liu.se", 29 }, - { "private-key", 11 }, - { "public-key", 10 }, - { "dsa", 3 }, - { "p", 1 }, - { "q", 1 }, - { "g", 1 }, - { "y", 1 }, - { "x", 1 }, - { "r", 1 }, - { "s", 1 }, - { "rsa-pkcs1-sha1", 14 }, - { "rsa-pkcs1-md5", 13 }, - { "n", 1 }, - { "e", 1 }, - { "d", 1 }, - { "a", 1 }, - { "b", 1 }, - { "c", 1 }, - { "hash", 4 }, - { "md5", 3 }, - { "sha1", 4 }, - { "password-encrypted", 18 }, - { "Xpkcs5v2", 8 }, - { "iterations", 10 }, - { "salt", 4 }, - { "data", 4 }, - { "iv", 2 }, - { "sequence", 8 }, - { "certificate", 11 }, - { "signature", 9 }, - { "name", 4 }, - { "acl", 3 }, - { "version", 7 }, - { "entry", 5 }, - { "propagate", 9 }, - { "tag", 3 }, - { "prefix", 6 }, - { "set", 3 }, - { "*", 1 }, - { "srp-ring1-sha1@lysator.liu.se", 29 }, - { "srp-verifier", 12 }, - { "ssh-ring1", 9 } } diff --git a/lsh/src/bignum.c b/lsh/src/bignum.c deleted file mode 100755 index 4d6d27a..0000000 --- a/lsh/src/bignum.c +++ /dev/null @@ -1,407 +0,0 @@ -/* bignum.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "bignum.h" -#include "randomness.h" -#include "werror.h" - -#include -#include -#include - -#include "prime_table.h" - -static void -limbs_to_octets(const mpz_t n, UINT32 length, - UINT8 pad, UINT8 *data) -{ - UINT8 *dst = data + length - 1; - - mp_limb_t *l = n->_mp_d; /* Starts at the least significant limb */ - int left; - - for (left = n->_mp_size; - (length > 0) && (left > 0); - left--) - { - size_t i; - mp_limb_t word = *l++; - for(i = 0; i>= 8; - length--; - if (!length) - break; - } - } - while (length > 0) - { - *dst-- = pad; - length--; - } -} - -/* Formatting of signed numbers */ -void -bignum_parse_s(mpz_t n, UINT32 length, const UINT8 *data) -{ - int negative = length && (*data & 0x80); - size_t i; - mpz_t digit; - - mpz_init(digit); - mpz_set_ui(n, 0); - for (i = 0; i < length; i++) - { - mpz_set_ui(digit, data[i]); - mpz_mul_2exp(digit, digit, (length - i - 1) * 8); - mpz_ior(n, n, digit); - } - if (negative) - { - mpz_set_ui(digit, 1); - mpz_mul_2exp(digit, digit, length*8); - mpz_sub(n, n, digit); - } - mpz_clear(digit); -} - -static int -mpz_size_of_complement(const mpz_t n) -{ - int bits; - - /* One's complement(x) = - x - 1 */ - mpz_t complement; - mpz_init(complement); - mpz_com(complement, n); - - /* Note that bits == 1 if complement == 0, i.e n = -1 */ - bits = mpz_sizeinbase(complement, 2); - - mpz_clear(complement); - - return bits; -} - -/* This function should handle both positive and negative numbers */ -UINT32 bignum_format_s_length(const mpz_t n) -{ - switch(mpz_sgn(n)) - { - case 0: - return 0; - case 1: - return mpz_sizeinbase(n, 2)/8 + 1; - case -1: - return mpz_size_of_complement(n)/8 + 1; - default: - fatal("Internal error"); - } -} - -UINT32 -bignum_format_s(const mpz_t n, UINT8 *data) -{ - switch(mpz_sgn(n)) - { - case 0: - return 0; - case 1: - { - size_t length = mpz_sizeinbase(n, 2)/8 + 1; - - limbs_to_octets(n, length, 0, data); - return length; - } - case -1: - { - mpz_t complement; - size_t length; - int i; - - mpz_init(complement); - mpz_com(complement, n); - - /* Note that mpz_sizeinbase(0) == 0.*/ - length = mpz_sizeinbase(complement, 2)/8 + 1; - - for (i = 0; i_mp_size; i++) - complement->_mp_d[i] = ~complement->_mp_d[i]; - - limbs_to_octets(complement, length, 0xff, data); - - mpz_clear(complement); - return length; - } - default: - fatal("Internal error"); - } -} - -/* Formatting of unsigned numbers */ -void -bignum_parse_u(mpz_t n, UINT32 length, const UINT8 *data) -{ - size_t i; - mpz_t digit; - - mpz_init(digit); - mpz_set_ui(n, 0); - for (i = 0; i < length; i++) - { - mpz_set_ui(digit, data[i]); - mpz_mul_2exp(digit, digit, (length - i - 1) * 8); - mpz_ior(n, n, digit); - } - mpz_clear(digit); -} - -UINT32 -bignum_format_u_length(const mpz_t n) -{ - switch(mpz_sgn(n)) - { - case 0: - return 0; - case 1: - return (mpz_sizeinbase(n, 2) + 7) / 8; - default: - fatal("Internal error: Negative number to bignum_format_u_length\n"); - } -} - -void -bignum_write(mpz_t n, unsigned length, UINT8 *data) -{ - limbs_to_octets(n, length, 0, data); -} - -UINT32 -bignum_format_u(const mpz_t n, UINT8 *data) -{ - switch(mpz_sgn(n)) - { - case 0: - return 0; - case 1: - { - size_t length = (mpz_sizeinbase(n, 2) + 7) / 8; - - limbs_to_octets(n, length, 0, data); - return length; - } - default: - fatal("Internal error: Negative number to bignum_format_u\n"); - } -} - -/* Returns a random number, 0 <= x < 2^bits. */ -void -bignum_random_size(mpz_t x, struct randomness *random, unsigned bits) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - unsigned length = (bits + 7) / 8; - UINT8 *data = alloca(length); - - RANDOM(random, length, data); - - bignum_parse_u(x, length, data); - - if (bits % 8) - mpz_fdiv_r_2exp(x, x, bits); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -/* Returns a random number, 0 <= x < n. */ -void -bignum_random(mpz_t x, struct randomness *random, mpz_t n) -{ - /* FIXME: This leaves some bias, which may be bad for DSA. A better - * way might to generate a random number of mpz_sizeinbase(n, 2) - * bits, and loop until one smaller than n is found. */ - - /* From Daniel Bleichenbacher (via coderpunks): - * - * There is still a theoretical attack possible with 8 extra bits. - * But, the attack would need about 2^66 signatures 2^66 memory and - * 2^66 time (if I remember that correctly). Compare that to DSA, - * where the attack requires 2^22 signatures 2^40 memory and 2^64 - * time. And of course, the numbers above are not a real threat for - * PGP. Using 16 extra bits (i.e. generating a 176 bit random number - * and reducing it modulo q) will defeat even this theoretical - * attack. - * - * More generally log_2(q)/8 extra bits are enoug to defeat my - * attack. NIST also plans to update the standard. - */ - - /* Add a few bits extra, to decrease the bias from the final modulo - * operation. */ - bignum_random_size(x, random, mpz_sizeinbase(n, 2) + 10); - - mpz_fdiv_r(x, x, n); -} - -/* Returns a small factor of n, or 0 if none is found.*/ -unsigned long -bignum_small_factor(mpz_t n, int limit) -{ - int i; - unsigned long stop; - - if (limit > NUMBER_OF_PRIMES) - limit = NUMBER_OF_PRIMES; - - stop = mpz_get_ui(n); - if (mpz_cmp_ui(n, stop) != 0) - stop = ULONG_MAX; - - for (i = 0; - (i < limit) - /* These squares could be tabulated as well, but I don't - * think it's worth the effort to get rid of this extra - * multiplication. */ - && (SQR(primes[i]) <= stop); - i++) - if (mpz_fdiv_ui(n, primes[i]) == 0) - return primes[i]; - return 0; -} - -void -bignum_next_prime(mpz_t p, mpz_t n, int count, int prime_limit) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - mpz_t tmp; - unsigned long *moduli = NULL; - unsigned long difference; - - /* First handle tiny numbers */ - if (mpz_cmp_ui(n, 2) <= 0) - { - mpz_set_ui(p, 2); - return; - } - mpz_set(p, n); - mpz_setbit(p, 0); - - if (mpz_cmp_ui(p, 8) < 0) - return; - - mpz_init(tmp); - - if (prime_limit > (NUMBER_OF_PRIMES -1)) - prime_limit = NUMBER_OF_PRIMES - 1; - - if (prime_limit && (mpz_cmp_ui(p, primes[prime_limit]) <= 0) ) - /* Don't use table for small numbers */ - prime_limit = 0; - - if (prime_limit) - { - /* Compute residues modulo small odd primes */ - int i; - - moduli = alloca(prime_limit * sizeof(*moduli)); - for (i = 0; i < prime_limit; i++) - moduli[i] = mpz_fdiv_ui(p, primes[i + 1]); - } - - for (difference = 0; ; difference += 2) - { -#if MACOS - extern void ssh2_sched(); - ssh2_sched(); -#endif - if (difference >= ULONG_MAX - 10) - { /* Should not happen, at least not very often... */ - mpz_add_ui(p, p, difference); - difference = 0; - } - - /* First check residues */ - if (prime_limit) - { - int composite = 0; - int i; - - for (i = 0; i < prime_limit; i++) - { - if (moduli[i] == 0) - composite = 1; - moduli[i] = (moduli[i] + 2) % primes[i + 1]; - } - if (composite) - continue; - } - - mpz_add_ui(p, p, difference); - difference = 0; - - /* Fermat test, with respect to 2 */ - mpz_set_ui(tmp, 2); - mpz_powm(tmp, tmp, p, p); - if (mpz_cmp_ui(tmp, 2) != 0) - continue; - - /* Miller-Rabin test */ - if (mpz_probab_prime_p(p, count)) - break; - } - mpz_clear(tmp); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -void -bignum_random_prime(mpz_t x, struct randomness *random, unsigned bits) -{ - assert(bits); - - do - { -#if MACOS - extern void ssh2_sched(); - ssh2_sched(); -#endif - bignum_random_size(x, random, bits); - mpz_setbit(x, bits - 1); - - /* Miller-rabin count of 25, and use primes in the table. */ - bignum_next_prime(x, x, 25, 5000); - } - while (mpz_sizeinbase(x, 2) > bits); - - assert(mpz_sizeinbase(x, 2) == bits); -} diff --git a/lsh/src/bignum.h b/lsh/src/bignum.h deleted file mode 100755 index 3f9a263..0000000 --- a/lsh/src/bignum.h +++ /dev/null @@ -1,64 +0,0 @@ -/* bignum.h - * - * Interface and conversion functions for GMP. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_BIGNUM_H_INCLUDED -#define LSH_BIGNUM_H_INCLUDED - -#include "lsh.h" - -/* Needed for the declaration of mpz_out_str */ -#include - -#if HAVE_GMP2_GMP_H -#include -#else -#if HAVE_GMP_H -#include -#else -#error No gmp.h! -#endif -#endif - -void bignum_parse_s(mpz_t n, UINT32 length, const UINT8 *data); -void bignum_parse_u(mpz_t n, UINT32 length, const UINT8 *data); - -UINT32 bignum_format_s(const mpz_t n, UINT8 *data); -UINT32 bignum_format_s_length(const mpz_t n); - -UINT32 bignum_format_u(const mpz_t n, UINT8 *data); -UINT32 bignum_format_u_length(const mpz_t n); - -void bignum_write(mpz_t n, unsigned length, UINT8 *data); - -/* Generates a random number in the interval 0 <= x < n */ -void bignum_random(mpz_t x, struct randomness *random, mpz_t n); -void bignum_random_size(mpz_t x, struct randomness *random, unsigned bits); -void -bignum_random_prime(mpz_t x, struct randomness *random, unsigned bits); - -unsigned long bignum_small_factor(mpz_t n, int limit); -void bignum_next_prime(mpz_t p, mpz_t n, int count, int prime_limit); - -#endif /* LSH_BIGNUM_H_INCLUDED */ diff --git a/lsh/src/blowfish.c b/lsh/src/blowfish.c deleted file mode 100755 index a640b3e..0000000 --- a/lsh/src/blowfish.c +++ /dev/null @@ -1,101 +0,0 @@ -/* blowfish.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/blowfish.h" - -#include - -#include "blowfish.c.x" - -/* Blowfish */ -/* GABA: - (class - (name blowfish_instance) - (super crypto_instance) - (vars - (ctx . "struct blowfish_ctx"))) -*/ - -static void -do_blowfish_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(blowfish_instance, self, s); - - blowfish_encrypt(&self->ctx, length, dst, src); -} - -static void -do_blowfish_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(blowfish_instance, self, s); - - blowfish_decrypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_blowfish_instance(struct crypto_algorithm *algorithm, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(blowfish_instance, self); - - self->super.block_size = BLOWFISH_BLOCK_SIZE; - self->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_blowfish_encrypt - : do_blowfish_decrypt); - - if (blowfish_set_key(&self->ctx, algorithm->key_size, key)) - return &self->super; - else - { - werror("Detected a weak blowfish key!\n"); - KILL(self); - return NULL; - } -} - -struct crypto_algorithm * -make_blowfish_algorithm(UINT32 key_size) -{ - NEW(crypto_algorithm, algorithm); - - assert(key_size <= BLOWFISH_MAX_KEY_SIZE); - assert(key_size >= BLOWFISH_MIN_KEY_SIZE); - - algorithm->block_size = BLOWFISH_BLOCK_SIZE; - algorithm->key_size = key_size; - algorithm->iv_size = 0; - algorithm->make_crypt = make_blowfish_instance; - - return algorithm; -} - -struct crypto_algorithm blowfish_algorithm = -{ STATIC_HEADER, BLOWFISH_BLOCK_SIZE, BLOWFISH_KEY_SIZE, - 0, make_blowfish_instance}; diff --git a/lsh/src/blowfish.c.x b/lsh/src/blowfish.c.x deleted file mode 100755 index 2c25fcc..0000000 Binary files a/lsh/src/blowfish.c.x and /dev/null differ diff --git a/lsh/src/cascade.c b/lsh/src/cascade.c deleted file mode 100755 index 8741747..0000000 --- a/lsh/src/cascade.c +++ /dev/null @@ -1,144 +0,0 @@ -/* cascade.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "abstract_crypto.h" - -#include "list.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "cascade.c.x" - -/* GABA: - (class - (name crypto_cascade_algorithm) - (super crypto_algorithm) - (vars - (cascade object object_list))) -*/ - -/* GABA: - (class - (name crypto_cascade_instance) - (super crypto_instance) - (vars - (cascade object object_list))) -*/ - -static void do_cascade_crypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(crypto_cascade_instance, self, s); - unsigned i; - - if (length % self->super.block_size) - fatal("Internal error!\n"); - - assert(LIST_LENGTH(self->cascade)); - - { - CAST_SUBTYPE(crypto_instance, o, LIST(self->cascade)[0]); - CRYPT(o, length, src, dst); - } - for (i = 1; icascade); i++) - { - CAST_SUBTYPE(crypto_instance, o, LIST(self->cascade)[i]); - CRYPT(o, length, dst, dst); - } -} - -static struct crypto_instance * -do_make_cascade(struct crypto_algorithm *s, - int mode, const UINT8 *key, const UINT8 *iv) -{ - CAST(crypto_cascade_algorithm, algorithm, s); - NEW(crypto_cascade_instance, instance); - unsigned i; - unsigned l = LIST_LENGTH(algorithm->cascade); - - instance->super.block_size = algorithm->super.block_size; - instance->cascade = alloc_object_list(l); - - for (i = 0; icascade)[i]); - struct crypto_instance *o = MAKE_CRYPT(a, mode, key, iv); - - if (!o) - { - KILL(instance); - return NULL; - } - - LIST(instance->cascade)[j] = (struct lsh_object *) o; - key += a->key_size; - iv += a->iv_size; - } - - instance->super.crypt = do_cascade_crypt; - - return &instance->super; -} - -struct crypto_algorithm *crypto_cascadel(struct object_list *cascade) -{ - NEW(crypto_cascade_algorithm, self); - unsigned i; - - self->cascade = cascade; - - self->super.key_size = self->super.iv_size = 0; - self->super.block_size = 1; - - for (i = 0; icascade); i++) - { - CAST_SUBTYPE(crypto_algorithm, a, LIST(self->cascade)[i]); - self->super.key_size += a->key_size; - self->super.iv_size += a->iv_size; - self->super.block_size = lcm(self->super.block_size, a->block_size); - } - - self->super.make_crypt = do_make_cascade; - - return &self->super; -} - -struct crypto_algorithm *crypto_cascade(unsigned n, ...) -{ - va_list args; - struct object_list *l; - - va_start(args, n); - l = make_object_listv(n, args); - va_end(args); - - return crypto_cascadel(l); -} diff --git a/lsh/src/cascade.c.x b/lsh/src/cascade.c.x deleted file mode 100755 index 8b656b7..0000000 Binary files a/lsh/src/cascade.c.x and /dev/null differ diff --git a/lsh/src/cast.c b/lsh/src/cast.c deleted file mode 100755 index 2ed814f..0000000 --- a/lsh/src/cast.c +++ /dev/null @@ -1,97 +0,0 @@ -/* cast.c - wrapper arround the CAST128 implementation - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * Copyright (C) 1999 J.H.M. Dassen (Ray) - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/cast128.h" - -#include - -#include "cast.c.x" - -struct crypto_algorithm *make_cast_algorithm(UINT32 key_size); - -/* Cast */ -/* GABA: - (class - (name cast_instance) - (super crypto_instance) - (vars - (ctx . "struct cast128_ctx"))) -*/ - - -static void -do_cast_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(cast_instance, self, s); - - cast128_encrypt(&self->ctx, length, dst, src); -} - -static void -do_cast_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(cast_instance, self, s); - - cast128_decrypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_cast_instance(struct crypto_algorithm *algorithm, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(cast_instance, self); - - self->super.block_size = CAST128_BLOCK_SIZE; - self->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_cast_encrypt - : do_cast_decrypt); - - cast128_set_key(&self->ctx, algorithm->key_size, key); - return &self->super; -} - -struct crypto_algorithm *make_cast_algorithm(UINT32 key_size) -{ - NEW(crypto_algorithm, algorithm); - - assert(key_size <= CAST128_MAX_KEY_SIZE); - assert(key_size >= CAST128_MIN_KEY_SIZE); - - algorithm->block_size = CAST128_BLOCK_SIZE; - algorithm->key_size = key_size; - algorithm->iv_size = 0; - algorithm->make_crypt = make_cast_instance; - - return algorithm; -} - -struct crypto_algorithm cast128_algorithm = -{ STATIC_HEADER, CAST128_BLOCK_SIZE, CAST128_MAX_KEY_SIZE, 0, make_cast_instance}; diff --git a/lsh/src/cast.c.x b/lsh/src/cast.c.x deleted file mode 100755 index 75dded5..0000000 Binary files a/lsh/src/cast.c.x and /dev/null differ diff --git a/lsh/src/cbc.c b/lsh/src/cbc.c deleted file mode 100755 index b08f00a..0000000 --- a/lsh/src/cbc.c +++ /dev/null @@ -1,147 +0,0 @@ -/* cbc.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include "cbc.c.x" - -#if !HAVE_MEMXOR -#include "nettle/memxor.h" -#endif - -/* GABA: - (class - (name cbc_algorithm) - (super crypto_algorithm) - (vars - (inner object crypto_algorithm))) -*/ - -/* GABA: - (class - (name cbc_instance) - (super crypto_instance) - (vars - (inner object crypto_instance) - (iv space UINT8))) -*/ - -static void do_cbc_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(cbc_instance, self, s); - - FOR_BLOCKS(length, src, dst, self->super.block_size) - { - memxor(self->iv, src, self->super.block_size); - - CRYPT(self->inner, self->super.block_size, self->iv, dst); - - memcpy(self->iv, dst, self->super.block_size); - } -} - -static void do_cbc_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(cbc_instance, self, s); - - if (length % self->super.block_size) - fatal("Internal error\n"); - - if (!length) - return; - - if (src == dst) - { - /* Keep a copy of the ciphertext. */ - UINT8 *tmp = alloca(length); - memcpy(tmp, src, length); - src = tmp; - } - - /* Decrypt in ECB mode */ - CRYPT(self->inner, length, src, dst); - - /* XOR the cryptotext, shifted one block */ - memxor(dst, - self->iv, self->super.block_size); - memxor(dst + self->super.block_size, - src, length - self->super.block_size); - memcpy(self->iv, - src + length - self->super.block_size, self->super.block_size); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static struct crypto_instance * -do_make_cbc_instance(struct crypto_algorithm *s, - int mode, const UINT8 *key, const UINT8 *iv) -{ - CAST(cbc_algorithm, algorithm, s); - NEW(cbc_instance, instance); - - instance->super.block_size = algorithm->super.block_size; - - /* NOTE: We use a prefix of the iv, and pass the tail on to the - * inner block crypto. This allows nested chaining, although the - * semantics may be a little obscure.. */ - instance->inner = MAKE_CRYPT(algorithm->inner, mode, key, - iv + algorithm->super.block_size); - if (!instance->inner) - { - /* Weak key */ - KILL(instance); - return NULL; - } - instance->iv = lsh_space_alloc(algorithm->super.block_size); - memcpy(instance->iv, iv, algorithm->super.block_size); - - instance->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_cbc_encrypt - : do_cbc_decrypt); - return &instance->super; -} - -struct crypto_algorithm *crypto_cbc(struct crypto_algorithm *inner) -{ - NEW(cbc_algorithm, algorithm); - algorithm->super.block_size = inner->block_size; - algorithm->super.key_size = inner->key_size; - algorithm->super.iv_size = inner->iv_size + inner->block_size; - - algorithm->inner = inner; - algorithm->super.make_crypt = do_make_cbc_instance; - - return &algorithm->super; -} diff --git a/lsh/src/cbc.c.x b/lsh/src/cbc.c.x deleted file mode 100755 index 4872550..0000000 Binary files a/lsh/src/cbc.c.x and /dev/null differ diff --git a/lsh/src/channel.c b/lsh/src/channel.c deleted file mode 100755 index a955c71..0000000 --- a/lsh/src/channel.c +++ /dev/null @@ -1,2124 +0,0 @@ -/* channel.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "channel.h" - -#include "format.h" -#include "io.h" -#include "read_data.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#define GABA_DEFINE -#include "channel.h.x" -#undef GABA_DEFINE - -#include "channel.c.x" - -struct exception * -make_channel_open_exception(UINT32 error_code, const char *msg) -{ - NEW(channel_open_exception, self); - -#define MAX_ERROR 4 - static const char *msgs[MAX_ERROR + 1] = { - "", - "Administratively prohibited", - "Connect failed", - "Unknown channel type", - "Resource shortage" - }; - - assert(error_code > 0); - assert(error_code <= MAX_ERROR); -#undef MAX_ERROR - - self->super.type = EXC_CHANNEL_OPEN; - self->super.msg = msg ? msg : msgs[error_code]; - self->error_code = error_code; - - return &self->super; -} - - -struct lsh_string * -format_global_failure(void) -{ - return ssh_format("%c", SSH_MSG_REQUEST_FAILURE); -} - -struct lsh_string * -format_global_success(void) -{ - return ssh_format("%c", SSH_MSG_REQUEST_SUCCESS); -} - -struct lsh_string * -format_open_confirmation(struct ssh_channel *channel, - UINT32 channel_number, - const char *format, ...) -{ - va_list args; - UINT32 l1, l2; - struct lsh_string *packet; - -#define CONFIRM_FORMAT "%c%i%i%i%i" -#define CONFIRM_ARGS \ - SSH_MSG_CHANNEL_OPEN_CONFIRMATION, channel->channel_number, \ - channel_number, channel->rec_window_size, channel->rec_max_packet - - debug("format_open_confirmation: rec_window_size = %i,\n" - " rec_max_packet = %i,\n", - channel->rec_window_size, - channel->rec_max_packet); - l1 = ssh_format_length(CONFIRM_FORMAT, CONFIRM_ARGS); - - va_start(args, format); - l2 = ssh_vformat_length(format, args); - va_end(args); - - packet = lsh_string_alloc(l1 + l2); - - ssh_format_write(CONFIRM_FORMAT, l1, packet->data, CONFIRM_ARGS); - - va_start(args, format); - ssh_vformat_write(format, l2, packet->data+l1, args); - va_end(args); - - return packet; -#undef CONFIRM_FORMAT -#undef CONFIRM_ARGS -} - -struct lsh_string * -format_open_failure(UINT32 channel, UINT32 reason, - const char *msg, const char *language) -{ - return ssh_format("%c%i%i%z%z", SSH_MSG_CHANNEL_OPEN_FAILURE, - channel, reason, msg, language); -} - -struct lsh_string * -format_channel_success(UINT32 channel) -{ - return ssh_format("%c%i", SSH_MSG_CHANNEL_SUCCESS, channel); -} - -struct lsh_string * -format_channel_failure(UINT32 channel) -{ - return ssh_format("%c%i", SSH_MSG_CHANNEL_FAILURE, channel); -} - -struct lsh_string * -prepare_window_adjust(struct ssh_channel *channel, - UINT32 add) -{ - channel->rec_window_size += add; - - return ssh_format("%c%i%i", - SSH_MSG_CHANNEL_WINDOW_ADJUST, - channel->channel_number, add); -} - -/* GABA: - (class - (name exc_finish_channel_handler) - (super exception_handler) - (vars - (connection object ssh_connection) - ; Non-zero if the channel has already been deallocated. - (dead . int) - ; Local channel number - (channel_number . UINT32))) -*/ - -static void -do_exc_finish_channel_handler(struct exception_handler *s, - const struct exception *e) -{ - CAST(exc_finish_channel_handler, self, s); - - switch (e->type) - { - case EXC_FINISH_PENDING: - if (self->dead) - werror("channel.c: EXC_FINISH_PENDING on dead channel.\n"); - - self->connection->table->pending_close = 1; - - /* NOTE: We don't need to raise a EXC_FINISH_READ here. Only - * code in a live channel is supposed to raise - * EXC_FINISH_PENDING. The typical caller is a channel's - * CHANNEL_CLOSE callback that is called below. */ - break; - - case EXC_FINISH_CHANNEL: - /* NOTE: This type of exception must be handled only once. - * However, there is at least one case where it is difficult to - * ensure that the exception is raised only once. - * - * For instance, in do_channel_close, the CHANNEL_EOF callback - * can decide to call close_channel, which might raise this - * exception. When control gets back to do_channel_close, and - * CHANNEL_SENT_CLOSE is true, it raises the exception again. - * - * To get this right, we set a flag when the channel is - * deallocated. */ - if (self->dead) - debug("EXC_FINISH_CHANNEL on dead channel.\n"); - else - { - struct ssh_channel *channel - = self->connection->table->channels[self->channel_number]; - - assert(channel); - assert(channel->resources->super.alive); - - if (channel->close) - CHANNEL_CLOSE(channel); - - KILL_RESOURCE_LIST(channel->resources); - - dealloc_channel(self->connection->table, self->channel_number); - self->dead = 1; - - if (self->connection->table->pending_close && - !self->connection->table->channel_count) - { - /* FIXME: Send a SSH_DISCONNECT_BY_APPLICATION message? */ - EXCEPTION_RAISE(self->connection->e, &finish_read_exception); - } - } - break; - default: - EXCEPTION_RAISE(self->super.parent, e); - } -} - -static struct exception_handler * -make_exc_finish_channel_handler(struct ssh_connection *connection, - UINT32 channel_number, - struct exception_handler *e, - const char *context) -{ - NEW(exc_finish_channel_handler, self); - self->super.parent = e; - self->super.raise = do_exc_finish_channel_handler; - self->super.context = context; - - self->connection = connection; - self->channel_number = channel_number; - self->dead = 0; - - return &self->super; -} - - -/* Channel objects */ - -#define INITIAL_CHANNELS 32 -/* Arbitrary limit */ -#define MAX_CHANNELS (1L<<17) - -struct channel_table * -make_channel_table(void) -{ - NEW(channel_table, table); - - table->channels = lsh_space_alloc(sizeof(struct ssh_channel *) - * INITIAL_CHANNELS); - table->in_use = lsh_space_alloc(INITIAL_CHANNELS); - - table->allocated_channels = INITIAL_CHANNELS; - table->used_channels = 0; - table->next_channel = 0; - table->channel_count = 0; - - table->max_channels = MAX_CHANNELS; - - table->pending_close = 0; - - table->global_requests = make_alist(0, -1); - table->channel_types = make_alist(0, -1); - table->open_fallback = NULL; - - object_queue_init(&table->local_ports); - object_queue_init(&table->remote_ports); - table->x11_display = NULL; - - object_queue_init(&table->active_global_requests); - object_queue_init(&table->pending_global_requests); - - return table; -} - -/* Returns -1 if allocation fails */ -/* NOTE: This function returns locally chosen channel numbers, which - * are always small integers. So there's no problem fitting them in - * a signed int. */ -int -alloc_channel(struct channel_table *table) -{ - UINT32 i; - - for(i = table->next_channel; i < table->used_channels; i++) - { - if (table->in_use[i] == CHANNEL_FREE) - { - assert(!table->channels[i]); - table->in_use[i] = CHANNEL_RESERVED; - table->next_channel = i+1; - - goto success; - } - } - if (i == table->max_channels) - return -1; - - if (i == table->allocated_channels) - { - UINT32 new_size = table->allocated_channels * 2; - struct ssh_channel **new_channels; - UINT8 *new_in_use; - - new_channels = lsh_space_alloc(sizeof(struct ssh_channel *) - * new_size); - memcpy(new_channels, table->channels, - sizeof(struct ssh_channel *) * table->used_channels); - lsh_space_free(table->channels); - table->channels = new_channels; - - /* FIXME: Use realloc(). */ - new_in_use = lsh_space_alloc(new_size); - memcpy(new_in_use, table->in_use, table->used_channels); - lsh_space_free(table->in_use); - table->in_use = new_in_use; - - table->allocated_channels = new_size; - } - - table->next_channel = table->used_channels = i+1; - - table->in_use[i] = CHANNEL_RESERVED; - table->channels[i] = NULL; - - success: - table->channel_count++; - verbose("Allocated local channel number %i\n", i); - - return i; -} - -void -dealloc_channel(struct channel_table *table, int i) -{ - assert(i >= 0); - assert( (unsigned) i < table->used_channels); - assert(table->channel_count); - - verbose("Deallocating local channel %i\n", i); - table->channels[i] = NULL; - table->in_use[i] = CHANNEL_FREE; - - table->channel_count--; - - if ( (unsigned) i < table->next_channel) - table->next_channel = i; -} - -void -use_channel(struct ssh_connection *connection, - UINT32 local_channel_number) -{ - struct channel_table *table = connection->table; - struct ssh_channel *channel = table->channels[local_channel_number]; - - assert(channel); - assert(table->in_use[local_channel_number] == CHANNEL_RESERVED); - - table->in_use[local_channel_number] = CHANNEL_IN_USE; - verbose("Taking channel %i in use, (local %i).\n", - channel->channel_number, local_channel_number); -} - -/* FIXME: Delete connection argument */ -void -register_channel(UINT32 local_channel_number, - struct ssh_channel *channel, - int take_into_use) -{ - struct channel_table *table = channel->connection->table; - - assert(table->in_use[local_channel_number] == CHANNEL_RESERVED); - assert(!table->channels[local_channel_number]); - - verbose("Registering local channel %i.\n", - local_channel_number); - - /* NOTE: Is this the right place to install this exception handler? */ - channel->e = - make_exc_finish_channel_handler(channel->connection, - local_channel_number, - (channel->e ? channel->e - : channel->connection->e), - HANDLER_CONTEXT); - - table->channels[local_channel_number] = channel; - - if (take_into_use) - use_channel(channel->connection, local_channel_number); - - REMEMBER_RESOURCE(channel->connection->resources, - &channel->resources->super); -} - -struct ssh_channel * -lookup_channel(struct channel_table *table, UINT32 i) -{ - return ( (i < table->used_channels) - && (table->in_use[i] == CHANNEL_IN_USE)) - ? table->channels[i] : NULL; -} - -struct ssh_channel * -lookup_channel_reserved(struct channel_table *table, UINT32 i) -{ - return ( (i < table->used_channels) - && (table->in_use[i] == CHANNEL_RESERVED)) - ? table->channels[i] : NULL; -} - - -/* FIXME: It seems suboptimal to send a window adjust message for - * *every* write that we do. A better scheme might be as follows: - * - * Delay window adjust messages, keeping track of both the locally - * maintained window size, which is updated after each write, and the - * size that has been reported to the remote end. When the difference - * between these two values gets large enough (say, larger than one - * half or one third of the maximum window size), we send a - * window_adjust message to sync them. */ -static void -adjust_rec_window(struct flow_controlled *f, UINT32 written) -{ - CAST_SUBTYPE(ssh_channel, channel, f); - - /* NOTE: The channel object (referenced as a flow-control callback) - * may live longer than the actual channel. */ - if (! (channel->flags & (CHANNEL_RECEIVED_EOF | CHANNEL_RECEIVED_CLOSE - | CHANNEL_SENT_CLOSE))) - C_WRITE(channel->connection, - prepare_window_adjust(channel, written)); -} - -void -channel_start_receive(struct ssh_channel *channel, - UINT32 initial_window_size) -{ - if (channel->rec_window_size < initial_window_size) - C_WRITE(channel->connection, - prepare_window_adjust - (channel, initial_window_size - channel->rec_window_size)); -} - -/* Channel related messages */ - -/* GABA: - (class - (name request_status) - (vars - ; -1 for still active requests, - ; 0 for failure, - ; 1 for success - (status . int))) -*/ - -static struct request_status * -make_request_status(void) -{ - NEW(request_status, self); - self->status = -1; - - return self; -} - -/* GABA: - (class - (name global_request_continuation) - (super command_continuation) - (vars - (connection object ssh_connection) - (active object request_status))) -*/ - -static void -send_global_request_responses(struct ssh_connection *connection, - struct object_queue *q) -{ - for (;;) - { - CAST(request_status, n, object_queue_peek_head(q)); - if (!n || (n->status < 0)) - break; - - object_queue_remove_head(q); - - C_WRITE(connection, - (n->status - ? format_global_success() - : format_global_failure())); - } -} - -static void -do_global_request_response(struct command_continuation *s, - struct lsh_object *x UNUSED) -{ - CAST(global_request_continuation, self, s); - struct object_queue *q = &self->connection->table->active_global_requests; - - assert(self->active->status == -1); - assert(!object_queue_is_empty(q)); - - self->active->status = 1; - - send_global_request_responses(self->connection, q); -} - -static struct command_continuation * -make_global_request_response(struct ssh_connection *connection, - struct request_status *active) -{ - NEW(global_request_continuation, self); - - self->super.c = do_global_request_response; - self->connection = connection; - self->active = active; - - return &self->super; -} - - -/* GABA: - (class - (name global_request_exception_handler) - (super exception_handler) - (vars - (connection object ssh_connection) - (active object request_status))) -*/ - -/* NOTE: We handle *only* EXC_GLOBAL_REQUEST */ -static void -do_exc_global_request_handler(struct exception_handler *c, - const struct exception *e) -{ - CAST(global_request_exception_handler, self, c); - if (e->type == EXC_GLOBAL_REQUEST) - { - struct object_queue *q = &self->connection->table->active_global_requests; - - assert(self->active->status == -1); - assert(!object_queue_is_empty(q)); - - self->active->status = 0; - - send_global_request_responses(self->connection, q); - } - else - EXCEPTION_RAISE(c->parent, e); -} - -static struct exception_handler * -make_global_request_exception_handler(struct ssh_connection *connection, - struct request_status *active, - struct exception_handler *h, - const char *context) -{ - NEW(global_request_exception_handler, self); - - self->super.raise = do_exc_global_request_handler; - self->super.context = context; - self->super.parent = h; - self->active = active; - self->connection = connection; - return &self->super; -} - -DEFINE_PACKET_HANDLER(static, global_request_handler, connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - int name; - int want_reply; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_GLOBAL_REQUEST) - && parse_atom(&buffer, &name) - && parse_boolean(&buffer, &want_reply)) - { - struct global_request *req = NULL; - struct command_continuation *c = &discard_continuation; - struct exception_handler *e = connection->e; - - if (name && connection->table->global_requests) - { - CAST_SUBTYPE(global_request, r, - ALIST_GET(connection->table->global_requests, - name)); - req = r; - } - if (!req) - { - C_WRITE(connection, format_global_failure()); - return; - } - else - { - if (want_reply) - { - struct request_status *a = make_request_status(); - - object_queue_add_tail(&connection->table->active_global_requests, - &a->super); - - c = make_global_request_response(connection, a); - e = make_global_request_exception_handler(connection, a, e, HANDLER_CONTEXT); - } - else - { - /* We should ignore failures. */ - static struct report_exception_info global_req_ignore = - STATIC_REPORT_EXCEPTION_INFO(EXC_ALL, EXC_GLOBAL_REQUEST, - "Ignored:"); - - e = make_report_exception_handler(&global_req_ignore, - e, HANDLER_CONTEXT); - } - GLOBAL_REQUEST(req, connection, name, want_reply, &buffer, c, e); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_GLOBAL_REQUEST message."); -} - -DEFINE_PACKET_HANDLER(static, global_success_handler, - connection, packet) -{ - if (packet->length != 1) - { - PROTOCOL_ERROR(connection->e, "Invalid GLOBAL_REQUEST_SUCCESS message."); - return; - } - - assert(packet->data[0] == SSH_MSG_REQUEST_SUCCESS); - - if (object_queue_is_empty(&connection->table->pending_global_requests)) - { - werror("do_global_request_success: Unexpected message, ignoring.\n"); - return; - } - { - CAST_SUBTYPE(command_context, ctx, - object_queue_remove_head(&connection->table->pending_global_requests)); - COMMAND_RETURN(ctx->c, connection); - } -} - -struct exception global_request_exception = -STATIC_EXCEPTION(EXC_GLOBAL_REQUEST, "Global request failed"); - -DEFINE_PACKET_HANDLER(static, global_failure_handler, - connection, packet) -{ - if (packet->length != 1) - { - PROTOCOL_ERROR(connection->e, "Invalid GLOBAL_REQUEST_FAILURE message."); - return; - } - - assert(packet->data[0] == SSH_MSG_REQUEST_FAILURE); - - if (object_queue_is_empty(&connection->table->pending_global_requests)) - { - werror("do_global_request_failure: Unexpected message, ignoring.\n"); - } - else - { - CAST_SUBTYPE(command_context, ctx, - object_queue_remove_head(&connection->table->pending_global_requests)); - EXCEPTION_RAISE(ctx->e, &global_request_exception); - } -} - -/* FIXME: Don't store the channel here, instead have it passed as the - * argument of the continuation. This might also allow some - * unification with the handling of global_requests. */ - -/* GABA: - (class - (name channel_request_continuation) - (super command_continuation) - (vars - ;; FIXME: Delete connection argument - (connection object ssh_connection) - (channel object ssh_channel) - (active object request_status))) -*/ - -/* FIXME: Delete connection argument */ -static void -send_channel_request_responses(struct ssh_connection *connection, - struct ssh_channel *channel, - struct object_queue *q) -{ - for (;;) - { - CAST(request_status, n, object_queue_peek_head(q)); - if (!n || (n->status < 0)) - break; - - object_queue_remove_head(q); - - C_WRITE(connection, - (n->status - ? format_channel_success(channel->channel_number) - : format_channel_failure(channel->channel_number))); - } -} - -static void -do_channel_request_response(struct command_continuation *s, - struct lsh_object *x UNUSED) -{ - CAST(channel_request_continuation, self, s); - struct object_queue *q = &self->channel->active_requests; - - assert(self->active->status == -1); - assert(!object_queue_is_empty(q)); - - self->active->status = 1; - - send_channel_request_responses(self->connection, self->channel, q); -} - -/* FIXME: Delete connection argument */ -static struct command_continuation * -make_channel_request_response(struct ssh_connection *connection, - struct ssh_channel *channel, - struct request_status *active) -{ - NEW(channel_request_continuation, self); - - self->super.c = do_channel_request_response; - self->connection = connection; - self->channel = channel; - self->active = active; - - return &self->super; -} - -/* GABA: - (class - (name channel_request_exception_handler) - (super exception_handler) - (vars - ;; FIXME: Delete connection argument - (connection object ssh_connection) - (channel object ssh_channel) - (active object request_status))) -*/ - -/* NOTE: We handle *only* EXC_CHANNEL_REQUEST */ -static void -do_exc_channel_request_handler(struct exception_handler *c, - const struct exception *e) -{ - CAST(channel_request_exception_handler, self, c); - if (e->type == EXC_CHANNEL_REQUEST) - { - struct object_queue *q = &self->channel->active_requests; - - assert(self->active->status == -1); - assert(!object_queue_is_empty(q)); - - self->active->status = 0; - - send_channel_request_responses(self->connection, self->channel, q); - } - else - EXCEPTION_RAISE(c->parent, e); -} - -/* FIXME: Delete connection argument */ -static struct exception_handler * -make_channel_request_exception_handler(struct ssh_connection *connection, - struct ssh_channel *channel, - struct request_status *active, - struct exception_handler *h, - const char *context) -{ - NEW(channel_request_exception_handler, self); - - self->super.raise = do_exc_channel_request_handler; - self->super.parent = h; - self->super.context = context; - self->connection = connection; - self->channel = channel; - self->active = active; - - return &self->super; -} - -static int -parse_channel_request(struct simple_buffer *buffer, - UINT32 *channel_number, - struct channel_request_info *info) -{ - unsigned msg_number; - - if (parse_uint8(buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_REQUEST) - && parse_uint32(buffer, channel_number) - && parse_string(buffer, - &info->type_length, &info->type_data) - && parse_boolean(buffer, &info->want_reply)) - { - info->type = lookup_atom(info->type_length, info->type_data); - return 1; - } - else - return 0; -} - -DEFINE_PACKET_HANDLER(static, channel_request_handler, - connection, packet) -{ - struct simple_buffer buffer; - struct channel_request_info info; - UINT32 channel_number; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_channel_request(&buffer, &channel_number, &info)) - { - struct ssh_channel *channel = lookup_channel(connection->table, - channel_number); - - /* NOTE: We can't free packet yet, because it is not yet fully - * parsed. There may be some more arguments, which are parsed by - * the CHANNEL_REQUEST method below. */ - - if (channel) - { - struct channel_request *req = NULL; - struct command_continuation *c = &discard_continuation; - struct exception_handler *e = channel->e; - - if (info.type && channel->request_types) - { - CAST_SUBTYPE(channel_request, r, - ALIST_GET(channel->request_types, info.type)); - req = r; - } - if (!req) - req = channel->request_fallback; - - if (req) - { - if (info.want_reply) - { - struct request_status *a = make_request_status(); - - object_queue_add_tail(&channel->active_requests, - &a->super); - - c = make_channel_request_response(connection, channel, a); - e = make_channel_request_exception_handler(connection, channel, a, e, HANDLER_CONTEXT); - } - else - { - /* We should ignore failures. */ - static struct report_exception_info channel_req_ignore = - STATIC_REPORT_EXCEPTION_INFO(EXC_ALL, EXC_CHANNEL_REQUEST, - "Ignored:"); - - e = make_report_exception_handler(&channel_req_ignore, - e, HANDLER_CONTEXT); - } - - CHANNEL_REQUEST(req, channel, &info, &buffer, c, e); - } - else - { - if (info.want_reply) - C_WRITE(connection, - format_channel_failure(channel->channel_number)); - } - } - else - { - werror("SSH_MSG_CHANNEL_REQUEST on nonexistant channel %i: %xS\n", - channel_number, packet); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_CHANNEL_REQUEST message."); -} - - -/* GABA: - (class - (name channel_open_continuation) - (super command_continuation) - (vars - (connection object ssh_connection) - (local_channel_number . UINT32) - (remote_channel_number . UINT32) - (send_window_size . UINT32) - (send_max_packet . UINT32))) -*/ - -static void -do_channel_open_continue(struct command_continuation *c, - struct lsh_object *value) -{ - CAST(channel_open_continuation, self, c); - CAST_SUBTYPE(ssh_channel, channel, value); - - assert(channel); - - /* FIXME: This copying could just as well be done by the - * CHANNEL_OPEN handler? Then we can remove the corresponding fields - * from the closure as well. */ - channel->send_window_size = self->send_window_size; - channel->send_max_packet = self->send_max_packet; - channel->channel_number = self->remote_channel_number; - - channel->connection = self->connection; - - register_channel(self->local_channel_number, - channel, - 1); - - /* FIXME: Doesn't support sending extra arguments with the - * confirmation message. */ - - C_WRITE(self->connection, - format_open_confirmation(channel, self->local_channel_number, "")); -} - -static struct command_continuation * -make_channel_open_continuation(struct ssh_connection *connection, - UINT32 local_channel_number, - UINT32 remote_channel_number, - UINT32 send_window_size, - UINT32 send_max_packet) -{ - NEW(channel_open_continuation, self); - - self->super.c = do_channel_open_continue; - self->connection = connection; - self->local_channel_number = local_channel_number; - self->remote_channel_number = remote_channel_number; - self->send_window_size = send_window_size; - self->send_max_packet = send_max_packet; - - return &self->super; -} - -/* GABA: - (class - (name exc_channel_open_handler) - (super exception_handler) - (vars - (connection object ssh_connection) - (local_channel_number . UINT32) - (remote_channel_number . UINT32))) -*/ - -static void -do_exc_channel_open_handler(struct exception_handler *s, - const struct exception *e) -{ - CAST(exc_channel_open_handler, self, s); - - switch (e->type) - { - case EXC_CHANNEL_OPEN: - { - CAST_SUBTYPE(channel_open_exception, exc, e); - struct channel_table *table = self->connection->table; - - assert(table->in_use[self->local_channel_number]); - assert(!table->channels[self->local_channel_number]); - - dealloc_channel(table, self->local_channel_number); - - C_WRITE(self->connection, - format_open_failure(self->remote_channel_number, - exc->error_code, e->msg, "")); - break; - } - default: - EXCEPTION_RAISE(self->super.parent, e); - } -} - -static struct exception_handler * -make_exc_channel_open_handler(struct ssh_connection *connection, - UINT32 local_channel_number, - UINT32 remote_channel_number, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_channel_open_handler, self); - self->super.parent = parent; - self->super.raise = do_exc_channel_open_handler; - self->super.context = context; - - self->connection = connection; - self->local_channel_number = local_channel_number; - self->remote_channel_number = remote_channel_number; - - return &self->super; -} - -static int -parse_channel_open(struct simple_buffer *buffer, - struct channel_open_info *info) -{ - unsigned msg_number; - - if (parse_uint8(buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_OPEN) - && parse_string(buffer, &info->type_length, &info->type_data) - && parse_uint32(buffer, &info->remote_channel_number) - && parse_uint32(buffer, &info->send_window_size) - && parse_uint32(buffer, &info->send_max_packet)) - { - info->type = lookup_atom(info->type_length, info->type_data); - - /* We don't support larger packets than the default, - * SSH_MAX_PACKET. The fuzz factor is because the - * channel's max sizes refer to the data string inside the - * packet, while the SSH_PACKET limit refers to the complete - * packet including some overhead (9 octets for - * SSH_MSG_CHANNEL_DATA and 13 octets for - * SSH_MSG_CHANNEL_EXTENDED_DATA). */ - if (info->send_max_packet > (SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ)) - { - werror("do_channel_open: The remote end asked for really large packets.\n"); - info->send_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ; - } - - return 1; - } - else - return 0; -} - - -DEFINE_PACKET_HANDLER(static, channel_open_handler, - connection, packet) -{ - struct simple_buffer buffer; - struct channel_open_info info; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_channel_open(&buffer, &info)) - { - struct channel_open *open = NULL; - - /* NOTE: We can't free the packet yet, as the buffer is passed - * to the CHANNEL_OPEN method later. */ - - if (connection->table->pending_close) - { - /* We are waiting for channels to close. Don't open any new ones. */ - - C_WRITE(connection, - format_open_failure(info.remote_channel_number, - SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, - "Waiting for channels to close.", "")); - } - else - { - if (info.type) - { - CAST_SUBTYPE(channel_open, o, - ALIST_GET(connection->table->channel_types, - info.type)); - open = o; - } - - if (!open) - open = connection->table->open_fallback; - - if (!open) - { - C_WRITE(connection, - format_open_failure(info.remote_channel_number, - SSH_OPEN_UNKNOWN_CHANNEL_TYPE, - "Unknown channel type", "")); - } - else - { - int local_number = alloc_channel(connection->table); - - if (local_number < 0) - C_WRITE(connection, - format_open_failure(info.remote_channel_number, - SSH_OPEN_RESOURCE_SHORTAGE, - "Channel limit exceeded.", "")); - - CHANNEL_OPEN(open, connection, - &info, - &buffer, - make_channel_open_continuation(connection, - local_number, - info.remote_channel_number, - info.send_window_size, - info.send_max_packet), - make_exc_channel_open_handler(connection, - local_number, - info.remote_channel_number, - connection->e, - HANDLER_CONTEXT)); - - } - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_CHANNEL_OPEN message."); -} - -DEFINE_PACKET_HANDLER(static, window_adjust_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - UINT32 size; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_WINDOW_ADJUST) - && parse_uint32(&buffer, &channel_number) - && parse_uint32(&buffer, &size) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = lookup_channel(connection->table, - channel_number); - - if (channel - && !(channel->flags & CHANNEL_RECEIVED_CLOSE)) - { - if (! (channel->flags & (CHANNEL_SENT_CLOSE | CHANNEL_SENT_EOF))) - { - channel->send_window_size += size; - if (channel->send_window_size && channel->send_adjust) - { - assert(channel->send_window_size); - CHANNEL_SEND_ADJUST(channel, size); - } - } - } - else - { - werror("SSH_MSG_CHANNEL_WINDOW_ADJUST on nonexistant or closed " - "channel %i\n", channel_number); - PROTOCOL_ERROR(connection->e, "Unexpected CHANNEL_WINDOW_ADJUST"); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_WINDOW_ADJUST message."); -} - -DEFINE_PACKET_HANDLER(static, channel_data_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - struct lsh_string *data; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_DATA) - && parse_uint32(&buffer, &channel_number) - && ( (data = parse_string_copy(&buffer)) ) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = lookup_channel(connection->table, - channel_number); - - if (channel && channel->receive - && !(channel->flags & (CHANNEL_RECEIVED_EOF - | CHANNEL_RECEIVED_CLOSE))) - { - if (channel->flags & CHANNEL_SENT_CLOSE) - { - lsh_string_free(data); - werror("Ignoring data on channel which is closing\n"); - return; - } - else - { - if (data->length > channel->rec_max_packet) - { - werror("Channel data larger than rec_max_packet. Extra data ignored.\n"); - data->length = channel->rec_max_packet; - } - - if (data->length > channel->rec_window_size) - { - /* Truncate data to fit window */ - werror("Channel data overflow. Extra data ignored.\n"); - debug(" (data->length=%i, rec_window_size=%i).\n", - data->length, channel->rec_window_size); - - data->length = channel->rec_window_size; - } - - if (!data->length) - { - /* Ignore data packet */ - lsh_string_free(data); - return; - } - channel->rec_window_size -= data->length; - - CHANNEL_RECEIVE(channel, CHANNEL_DATA, data); - } - } - else - { - werror("Data on closed or non-existant channel %i\n", - channel_number); - lsh_string_free(data); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_DATA message."); -} - -DEFINE_PACKET_HANDLER(static, channel_extended_data_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - UINT32 type; - struct lsh_string *data; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_EXTENDED_DATA) - && parse_uint32(&buffer, &channel_number) - && parse_uint32(&buffer, &type) - && ( (data = parse_string_copy(&buffer)) ) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = lookup_channel(connection->table, - channel_number); - - if (channel && channel->receive - && !(channel->flags & (CHANNEL_RECEIVED_EOF - | CHANNEL_RECEIVED_CLOSE))) - { - if (channel->flags & CHANNEL_SENT_CLOSE) - { - lsh_string_free(data); - werror("Ignoring extended data on channel which is closing\n"); - return; - } - else - { - if (data->length > channel->rec_max_packet) - { - werror("Channel data larger than rec_max_packet. Extra data ignored.\n"); - data->length = channel->rec_max_packet; - } - - if (data->length > channel->rec_window_size) - { - /* Truncate data to fit window */ - werror("Channel extended data overflow. " - "Extra data ignored.\n"); - debug(" (data->length=%i, rec_window_size=%i).\n", - data->length, channel->rec_window_size); - data->length = channel->rec_window_size; - } - - if (!data->length) - { - /* Ignore data packet */ - lsh_string_free(data); - return; - } - - channel->rec_window_size -= data->length; - - switch(type) - { - case SSH_EXTENDED_DATA_STDERR: - CHANNEL_RECEIVE(channel, CHANNEL_STDERR_DATA, data); - break; - default: - werror("Unknown type %i of extended data.\n", - type); - lsh_string_free(data); - } - } - } - else - { - werror("Extended data on closed or non-existant channel %i\n", - channel_number); - lsh_string_free(data); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_EXTENDED_DATA message."); -} - -DEFINE_PACKET_HANDLER(static, channel_eof_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_EOF) - && parse_uint32(&buffer, &channel_number) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = lookup_channel(connection->table, - channel_number); - - if (channel) - { - if (channel->flags & (CHANNEL_RECEIVED_EOF | CHANNEL_RECEIVED_CLOSE)) - { - werror("Receiving EOF on channel on closed channel.\n"); - PROTOCOL_ERROR(connection->e, - "Received EOF on channel on closed channel."); - } - else - { - verbose("Receiving EOF on channel %i (local %i)\n", - channel->channel_number, channel_number); - - channel->flags |= CHANNEL_RECEIVED_EOF; - - if (channel->eof) - { - CHANNEL_EOF(channel); - - /* Should we close the channel now? */ - if ( (channel->flags & CHANNEL_SENT_EOF) - && (channel->flags & CHANNEL_CLOSE_AT_EOF)) - channel_close(channel); - } - else - { - /* By default, close the channel. */ - debug("No CHANNEL_EOF handler. Closing.\n"); - channel_close(channel); - } - - } - } - else - { - werror("EOF on non-existant channel %i\n", - channel_number); - PROTOCOL_ERROR(connection->e, "EOF on non-existant channel"); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_EOF message"); -} - -DEFINE_PACKET_HANDLER(static, channel_close_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_CLOSE) - && parse_uint32(&buffer, &channel_number) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = lookup_channel(connection->table, - channel_number); - - if (channel) - { - verbose("Receiving CLOSE on channel %i (local %i)\n", - channel->channel_number, channel_number); - - if (channel->flags & CHANNEL_RECEIVED_CLOSE) - { - werror("Receiving multiple CLOSE on channel.\n"); - PROTOCOL_ERROR(connection->e, "Receiving multiple CLOSE on channel."); - } - else - { - channel->flags |= CHANNEL_RECEIVED_CLOSE; - - if (! (channel->flags & (CHANNEL_RECEIVED_EOF | CHANNEL_NO_WAIT_FOR_EOF - | CHANNEL_SENT_CLOSE))) - { - werror("Unexpected channel CLOSE.\n"); - } - - if (channel->flags & CHANNEL_SENT_CLOSE) - { - static const struct exception finish_exception - = STATIC_EXCEPTION(EXC_FINISH_CHANNEL, "Received CLOSE message."); - - EXCEPTION_RAISE(channel->e, - &finish_exception); - } - else - channel_close(channel); - } - } - else - { - werror("CLOSE on non-existant channel %i\n", - channel_number); - PROTOCOL_ERROR(connection->e, "CLOSE on non-existant channel"); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_CLOSE message"); -} - -DEFINE_PACKET_HANDLER(static, channel_open_confirm_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 local_channel_number; - UINT32 remote_channel_number; - UINT32 window_size; - UINT32 max_packet; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_OPEN_CONFIRMATION) - && parse_uint32(&buffer, &local_channel_number) - && parse_uint32(&buffer, &remote_channel_number) - && parse_uint32(&buffer, &window_size) - && parse_uint32(&buffer, &max_packet) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = - lookup_channel_reserved(connection->table, - local_channel_number); - - if (channel) - { - struct command_continuation *c = channel->open_continuation; - assert(c); - - channel->open_continuation = NULL; - - channel->channel_number = remote_channel_number; - channel->send_window_size = window_size; - channel->send_max_packet = max_packet; - - /* FIXME: Initialize channel->write here? */ - use_channel(connection, local_channel_number); - - COMMAND_RETURN(c, channel); - } - else - { - werror("Unexpected SSH_MSG_CHANNEL_OPEN_CONFIRMATION on channel %i\n", - local_channel_number); - PROTOCOL_ERROR(connection->e, "Unexpected CHANNEL_OPEN_CONFIRMATION."); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN_CONFIRMATION message."); -} - -DEFINE_PACKET_HANDLER(static, channel_open_failure_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - UINT32 reason; - - const UINT8 *msg; - UINT32 length; - - const UINT8 *language; - UINT32 language_length; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_OPEN_FAILURE) - && parse_uint32(&buffer, &channel_number) - && parse_uint32(&buffer, &reason) - && parse_string(&buffer, &length, &msg) - && parse_string(&buffer, &language_length, &language) - && parse_eod(&buffer)) - { - struct ssh_channel *channel = - lookup_channel_reserved(connection->table, - channel_number); - - if (channel) - { - static const struct exception finish_exception - = STATIC_EXCEPTION(EXC_FINISH_CHANNEL, "CHANNEL_OPEN failed."); - - assert(channel->open_continuation); - - /* FIXME: It would be nice to pass the message on. */ - EXCEPTION_RAISE(channel->e, - make_channel_open_exception(reason, "Refused by peer")); - EXCEPTION_RAISE(channel->e, &finish_exception); - } - else - werror("Unexpected SSH_MSG_CHANNEL_OPEN_FAILURE on channel %i\n", - channel_number); - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN_FAILURE message."); -} - -DEFINE_PACKET_HANDLER(static, channel_success_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - struct ssh_channel *channel; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_SUCCESS) - && parse_uint32(&buffer, &channel_number) - && parse_eod(&buffer) - && (channel = lookup_channel(connection->table, channel_number))) - { - if (object_queue_is_empty(&channel->pending_requests)) - { - werror("do_channel_success: Unexpected message. Ignoring.\n"); - } - else - { - CAST_SUBTYPE(command_context, ctx, - object_queue_remove_head(&channel->pending_requests)); - - COMMAND_RETURN(ctx->c, channel); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_SUCCESS message"); -} - -DEFINE_PACKET_HANDLER(static, channel_failure_handler, - connection, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 channel_number; - struct ssh_channel *channel; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_CHANNEL_FAILURE) - && parse_uint32(&buffer, &channel_number) - && parse_eod(&buffer) - && (channel = lookup_channel(connection->table, channel_number))) - { - if (object_queue_is_empty(&channel->pending_requests)) - { - werror("do_channel_failure: No handler. Ignoring.\n"); - } - else - { - static const struct exception channel_request_exception = - STATIC_EXCEPTION(EXC_CHANNEL_REQUEST, "Channel request failed"); - - CAST_SUBTYPE(command_context, ctx, - object_queue_remove_head(&channel->pending_requests)); - - EXCEPTION_RAISE(ctx->e, &channel_request_exception); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_FAILURE message."); -} - - -void init_connection_service(struct ssh_connection *connection) -{ - struct channel_table *table = make_channel_table(); - - debug("channel.c: do_connection_service\n"); - - connection->table = table; - - connection->dispatch[SSH_MSG_GLOBAL_REQUEST] - = &global_request_handler; - connection->dispatch[SSH_MSG_CHANNEL_OPEN] - = &channel_open_handler; - connection->dispatch[SSH_MSG_CHANNEL_REQUEST] - = &channel_request_handler; - - connection->dispatch[SSH_MSG_CHANNEL_WINDOW_ADJUST] - = &window_adjust_handler; - connection->dispatch[SSH_MSG_CHANNEL_DATA] - = &channel_data_handler; - connection->dispatch[SSH_MSG_CHANNEL_EXTENDED_DATA] - = &channel_extended_data_handler; - - connection->dispatch[SSH_MSG_CHANNEL_EOF] - = &channel_eof_handler; - connection->dispatch[SSH_MSG_CHANNEL_CLOSE] - = &channel_close_handler; - - connection->dispatch[SSH_MSG_CHANNEL_OPEN_CONFIRMATION] - = &channel_open_confirm_handler; - connection->dispatch[SSH_MSG_CHANNEL_OPEN_FAILURE] - = &channel_open_failure_handler; - - connection->dispatch[SSH_MSG_CHANNEL_SUCCESS] - = &channel_success_handler; - connection->dispatch[SSH_MSG_CHANNEL_FAILURE] - = &channel_failure_handler; - - connection->dispatch[SSH_MSG_REQUEST_SUCCESS] - = &global_success_handler; - connection->dispatch[SSH_MSG_REQUEST_FAILURE] - = &global_failure_handler; -} - -DEFINE_COMMAND(connection_service_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(ssh_connection, connection, a); - - init_connection_service(connection); - - COMMAND_RETURN(c, connection); -} - -struct lsh_string * -format_channel_close(struct ssh_channel *channel) -{ - return ssh_format("%c%i", - SSH_MSG_CHANNEL_CLOSE, - channel->channel_number); -} - -void -channel_close(struct ssh_channel *channel) -{ - static const struct exception finish_exception = - STATIC_EXCEPTION(EXC_FINISH_CHANNEL, "Closing channel"); - - if (! (channel->flags & CHANNEL_SENT_CLOSE)) - { - verbose("Sending CLOSE on channel %i\n", channel->channel_number); - - channel->flags |= CHANNEL_SENT_CLOSE; - - C_WRITE(channel->connection, format_channel_close(channel) ); - - if (channel->flags & CHANNEL_RECEIVED_CLOSE) - EXCEPTION_RAISE(channel->e, &finish_exception); - } -} - -struct lsh_string * -format_channel_eof(struct ssh_channel *channel) -{ - return ssh_format("%c%i", - SSH_MSG_CHANNEL_EOF, - channel->channel_number); -} - -void -channel_eof(struct ssh_channel *channel) -{ - if (! (channel->flags & - (CHANNEL_SENT_EOF | CHANNEL_SENT_CLOSE | CHANNEL_RECEIVED_CLOSE))) - { - verbose("Sending EOF on channel %i\n", channel->channel_number); - - channel->flags |= CHANNEL_SENT_EOF; - C_WRITE(channel->connection, format_channel_eof(channel) ); - - if ( (channel->flags & CHANNEL_CLOSE_AT_EOF) - && (channel->flags & (CHANNEL_RECEIVED_EOF | CHANNEL_NO_WAIT_FOR_EOF)) ) - { - /* Initiate close */ - channel_close(channel); - } - } -} - -void -init_channel(struct ssh_channel *channel) -{ - /* channel->super.handler = do_read_channel; */ -#if 0 - channel->write = NULL; -#endif - channel->connection = NULL; - - channel->super.report = adjust_rec_window; - - channel->flags = CHANNEL_CLOSE_AT_EOF; - channel->sources = 0; - - channel->request_types = NULL; - channel->request_fallback = NULL; - - channel->receive = NULL; - channel->send_adjust = NULL; - - channel->close = NULL; - channel->eof = NULL; - - channel->open_continuation = NULL; - - channel->resources = empty_resource_list(); - - object_queue_init(&channel->pending_requests); - object_queue_init(&channel->active_requests); -} - -struct lsh_string * -channel_transmit_data(struct ssh_channel *channel, - struct lsh_string *data) -{ - assert(data->length <= channel->send_window_size); - assert(data->length <= channel->send_max_packet); - channel->send_window_size -= data->length; - - return ssh_format("%c%i%fS", - SSH_MSG_CHANNEL_DATA, - channel->channel_number, - data); -} - -struct lsh_string * -channel_transmit_extended(struct ssh_channel *channel, - UINT32 type, - struct lsh_string *data) -{ - assert(data->length <= channel->send_window_size); - assert(data->length <= channel->send_max_packet); - channel->send_window_size -= data->length; - - return ssh_format("%c%i%i%fS", - SSH_MSG_CHANNEL_EXTENDED_DATA, - channel->channel_number, - type, - data); -} - -/* Writing data to a channel */ - -/* NOTE: Flow control when sending data on a channel works as follows: - * When the i/o backend wants to read from one of the channel's - * sources, it first calls do_read_data_query (in read_data.c), - * which looks at the current value of send_window_size to determine - * how much data can be sent right now. The backend reads at most that - * amount of data, and then calls do_channel_write or - * do_channel_write_extended. These objects are responsible for - * subtracting the actual amount of data from the send_window_size. - * - * It is crucial that no other i/o is done between the call to - * do_read_data_query and do_channel_write, otherwise we would have a - * race condition. - * - * At EOF, decrementing the sources count is not done here; it's done - * by the appropriate i/o close callback. These objects does checks if - * sources == 1, to determine if any eof message should be sent. */ - -/* GABA: - (class - (name channel_write) - (super abstract_write) - (vars - (channel object ssh_channel))) -*/ - -/* GABA: - (class - (name channel_write_extended) - (super channel_write) - (vars - (type . UINT32))) -*/ - -static void -do_channel_write(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(channel_write, closure, w); - - if (!packet) - { - /* EOF */ - assert(closure->channel->sources); - if (closure->channel->sources == 1) - channel_eof(closure->channel); - } - else - C_WRITE(closure->channel->connection, - channel_transmit_data(closure->channel, packet) ); -} - -static void -do_channel_write_extended(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(channel_write_extended, closure, w); - - if (!packet) - { - /* EOF */ - assert(closure->super.channel->sources); - if (closure->super.channel->sources == 1) - channel_eof(closure->super.channel); - } - else - C_WRITE(closure->super.channel->connection, - channel_transmit_extended(closure->super.channel, - closure->type, - packet)); -} - -struct abstract_write * -make_channel_write(struct ssh_channel *channel) -{ - NEW(channel_write, closure); - - closure->super.write = do_channel_write; - closure->channel = channel; - - return &closure->super; -} - -struct abstract_write * -make_channel_write_extended(struct ssh_channel *channel, - UINT32 type) -{ - NEW(channel_write_extended, closure); - - closure->super.super.write = do_channel_write_extended; - closure->super.channel = channel; - closure->type = type; - - return &closure->super.super; -} - -struct io_callback * -make_channel_read_data(struct ssh_channel *channel) -{ - /* byte SSH_MSG_CHANNEL_DATA - * uint32 recipient channel - * string data - * - * gives 9 bytes of overhead, including the length field. */ - - return make_read_data(channel, make_channel_write(channel)); -} - -struct io_callback * -make_channel_read_stderr(struct ssh_channel *channel) -{ - /* byte SSH_MSG_CHANNEL_EXTENDED_DATA - * uint32 recipient_channel - * uint32 data_type_code - * string data - * - * gives 13 bytes of overhead, including the length field for the string. */ - - return make_read_data(channel, - make_channel_write_extended(channel, - SSH_EXTENDED_DATA_STDERR)); -} - -/* GABA: - (class - (name channel_close_callback) - (super lsh_callback) - (vars - (channel object ssh_channel))) */ - - -/* NOTE: This callback is almost redundant. The EOF cases in - * do_channel_write and do_channel_write_extended should take care of - * sending SSH_MSG_CHANNEL_EOF when appropriate. But we still need - * this callback, in order to reliably decrement the sources count in - * all cases, including i/o errors. */ - -/* Close callback for files we are reading from. */ - -static void -channel_read_close_callback(struct lsh_callback *c) -{ - CAST(channel_close_callback, closure, c); - - trace("channel_read_close_callback: File closed.\n"); - - assert(closure->channel->sources); - - if (!--closure->channel->sources) - { - /* Send eof, unless already done. */ - channel_eof(closure->channel); - } -} - -struct lsh_callback * -make_channel_read_close_callback(struct ssh_channel *channel) -{ - NEW(channel_close_callback, closure); - - closure->super.f = channel_read_close_callback; - closure->channel = channel; - - return &closure->super; -} - -/* Exception handler that closes the channel on I/O errors. - * Primarily used for write fd:s that the channel is fed into. - * - * FIXME: Ideally, I'd like to pass something like broken pipe to the - * other end, on write errors, but I don't see how to do that. - * - * NOTE: This isn't used by tcpforward channels. But that is not a big - * problem, because there is only one fd involved. Any error (on - * either read or write) will close that fd, and then the - * channel_read_close_callback will close the channel. */ - -/* GABA: - (class - (name channel_io_exception_handler) - (super exception_handler) - (vars - (channel object ssh_channel) - (prefix . "const char *"))) -*/ - -static void -do_channel_io_exception_handler(struct exception_handler *s, - const struct exception *x) -{ - CAST(channel_io_exception_handler, self, s); - if (x->type & EXC_IO) - { - werror("channel.c: I/O error on write, %z\n", x->msg); -#if 0 - send_debug_message(self->channel->write, - ssh_format("%z I/O error: %z\n", - self->prefix, x->msg), - 1); -#endif - channel_close(self->channel); - } - else - EXCEPTION_RAISE(s->parent, x); -} - -struct exception_handler * -make_channel_io_exception_handler(struct ssh_channel *channel, - const char *prefix, - struct exception_handler *parent, - const char *context) -{ - NEW(channel_io_exception_handler, self); - self->super.raise = do_channel_io_exception_handler; - self->super.parent = parent; - self->super.context = context; - - self->channel = channel; - self->prefix = prefix; - - return &self->super; -} - -/* Used by do_gateway_channel_open */ -struct lsh_string * -format_channel_open_s(struct lsh_string *type, - UINT32 local_channel_number, - struct ssh_channel *channel, - struct lsh_string *args) -{ - return ssh_format("%c%S%i%i%i%lS", SSH_MSG_CHANNEL_OPEN, - type, local_channel_number, - channel->rec_window_size, channel->rec_max_packet, - args); -} - -struct lsh_string * -format_channel_open(int type, UINT32 local_channel_number, - struct ssh_channel *channel, - const char *format, ...) -{ - va_list args; - UINT32 l1, l2; - struct lsh_string *packet; - -#define OPEN_FORMAT "%c%a%i%i%i" -#define OPEN_ARGS SSH_MSG_CHANNEL_OPEN, type, local_channel_number, \ - channel->rec_window_size, channel->rec_max_packet - - debug("format_channel_open: rec_window_size = %i,\n" - " rec_max_packet = %i,\n", - channel->rec_window_size, - channel->rec_max_packet); - - l1 = ssh_format_length(OPEN_FORMAT, OPEN_ARGS); - - va_start(args, format); - l2 = ssh_vformat_length(format, args); - va_end(args); - - packet = lsh_string_alloc(l1 + l2); - - ssh_format_write(OPEN_FORMAT, l1, packet->data, OPEN_ARGS); - - va_start(args, format); - ssh_vformat_write(format, l2, packet->data+l1, args); - va_end(args); - - return packet; -#undef OPEN_FORMAT -#undef OPEN_ARGS -} - -struct lsh_string * -format_channel_request_i(struct channel_request_info *info, - struct ssh_channel *channel, - UINT32 args_length, const UINT8 *args_data) -{ - return ssh_format("%c%i%s%c%ls", SSH_MSG_CHANNEL_REQUEST, - channel->channel_number, - info->type_length, info->type_data, - info->want_reply, - args_length, args_data); -} - -struct lsh_string * -format_channel_request(int type, struct ssh_channel *channel, - int want_reply, const char *format, - ...) -{ - va_list args; - UINT32 l1, l2; - struct lsh_string *packet; - -#define REQUEST_FORMAT "%c%i%a%c" -#define REQUEST_ARGS SSH_MSG_CHANNEL_REQUEST, channel->channel_number, \ - type, want_reply - - l1 = ssh_format_length(REQUEST_FORMAT, REQUEST_ARGS); - - va_start(args, format); - l2 = ssh_vformat_length(format, args); - va_end(args); - - packet = lsh_string_alloc(l1 + l2); - - ssh_format_write(REQUEST_FORMAT, l1, packet->data, REQUEST_ARGS); - - va_start(args, format); - ssh_vformat_write(format, l2, packet->data+l1, args); - va_end(args); - - return packet; -#undef REQUEST_FORMAT -#undef REQUEST_ARGS -} - -struct lsh_string * -format_global_request(int type, int want_reply, - const char *format, ...) -{ - va_list args; - UINT32 l1, l2; - struct lsh_string *packet; - -#define REQUEST_FORMAT "%c%a%c" -#define REQUEST_ARGS SSH_MSG_GLOBAL_REQUEST, type, want_reply - - l1 = ssh_format_length(REQUEST_FORMAT, REQUEST_ARGS); - - va_start(args, format); - l2 = ssh_vformat_length(format, args); - va_end(args); - - packet = lsh_string_alloc(l1 + l2); - - ssh_format_write(REQUEST_FORMAT, l1, packet->data, REQUEST_ARGS); - - va_start(args, format); - ssh_vformat_write(format, l2, packet->data+l1, args); - va_end(args); - - return packet; -#undef REQUEST_FORMAT -#undef REQUEST_ARGS -} diff --git a/lsh/src/channel.c.x b/lsh/src/channel.c.x deleted file mode 100755 index f3a6acd..0000000 Binary files a/lsh/src/channel.c.x and /dev/null differ diff --git a/lsh/src/channel.h b/lsh/src/channel.h deleted file mode 100755 index 465da9e..0000000 --- a/lsh/src/channel.h +++ /dev/null @@ -1,417 +0,0 @@ -/* channel.h - * - * Information about ssh channels. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CHANNEL_H_INCLUDED -#define LSH_CHANNEL_H_INCLUDED - -#include "alist.h" -#include "command.h" -#include "connection.h" -#include "parse.h" -#include "server_pty.h" -#include "write_buffer.h" - -struct channel_open_info -{ - UINT32 type_length; - - /* NOTE: This is a pointer into the packet, so if it is needed later - * it must be copied. */ - const UINT8 *type_data; - - int type; - - UINT32 remote_channel_number; - UINT32 send_window_size; - UINT32 send_max_packet; -}; - -struct channel_request_info -{ - UINT32 type_length; - const UINT8 *type_data; - - int type; - - int want_reply; -}; - -#define GABA_DECLARE -#include "channel.h.x" -#undef GABA_DECLARE - -/* Channels are indexed by local channel number in some array. This - * index is not stored in the channel struct. When sending messages on - * the channel, it is identified by the *remote* sides index number, - * and this number must be stored. */ - -#define CHANNEL_DATA 0 -#define CHANNEL_STDERR_DATA 1 - -#define CHANNEL_SENT_CLOSE 1 -#define CHANNEL_RECEIVED_CLOSE 2 -#define CHANNEL_SENT_EOF 4 -#define CHANNEL_RECEIVED_EOF 8 - -/* Normally, this flag is set, and we initiate channel close as soon - * as we have both sent and received SSH_MSG_CHANNEL_EOF. Clearing - * this flag keeps the channel open. */ - -#define CHANNEL_CLOSE_AT_EOF 0x10 - -/* This flags means that we don't expect any more data from the other - * end, and that we don't want to wait for an SSH_MSG_CHANNEL_EOF - * before closing the channel. */ - -#define CHANNEL_NO_WAIT_FOR_EOF 0x20 - -/* GABA: - (class - (name ssh_channel) - (super flow_controlled) - (vars - ; Remote channel number - (channel_number . UINT32) - - ; Where to pass errors. This is used for two different - ; purposes: If opening the channel fails, EXC_CHANNEL_OPEN is - ; raised. Once the channel is open, this handler is used for - ; EXC_FINISH_CHANNEL and EXC_FINISH_PENDING. If the channel was - ; opened on the peer's request, the connection's exception - ; handler is a parent of the channel's. But that is not true in - ; general. - (e object exception_handler) - - ; Resources associated with the channel. This object is also - ; put onto the connections resource list. - (resources object resource_list) - - ; NOTE: The channels maximum packet sizes refer to the packet - ; payload, i.e. the DATA string in SSH_CHANNEL_DATA and - ; SSH_MSG_CHANNEL_EXTENDED_DATA. - - (rec_window_size . UINT32) - (rec_max_packet . UINT32) - - (send_window_size . UINT32) - (send_max_packet . UINT32) - - (connection object ssh_connection) - - (request_types object alist) - - ; If non-NULL, invoked for unknown channel requests. - (request_fallback object channel_request) - - (flags . int) - - ; Number of files connected to this channel. For instance, - ; stdout and stderr can be multiplexed on the same channel. We - ; should not close the channel until we have got an EOF on both - ; sources. - (sources . int) - - ; Type is CHANNEL_DATA or CHANNEL_STDERR_DATA - (receive method void "int type" "struct lsh_string *data") - - ; Called when we are allowed to send more data on the channel. - ; Implies that the send_window_size is non-zero. - (send_adjust method void "UINT32 increment") - - ; Called when the channel is closed. - ; Used by client_session and gateway_channel. - (close method void) - - ; Called when eof is received on the channel (or when it is - ; closed, whatever happens first). - (eof method void) - - ; Reply from SSH_MSG_CHANNEL_OPEN_REQUEST - (open_continuation object command_continuation) - - ; Queue of channel requests that we expect replies on - (pending_requests struct object_queue) - - ; Channel requests that we have received, and should reply to - ; in the right order - (active_requests struct object_queue))) - -*/ - -#define CHANNEL_RECEIVE(s, t, d) \ -((s)->receive((s), (t), (d))) - -#define CHANNEL_SEND_ADJUST(s, i) ((s)->send_adjust((s), (i))) - -#define CHANNEL_CLOSE(s) \ -((s)->close((s))) - -#define CHANNEL_EOF(s) \ -((s)->eof((s))) - -#define CHANNEL_OPEN_CONFIRM(s) \ -((s)->open_confirm((s))) - -#define CHANNEL_OPEN_FAILURE(s) \ -((s)->open_failure((s))) - -/* Values used in the in_use array. */ -#define CHANNEL_FREE 0 -#define CHANNEL_RESERVED 1 -#define CHANNEL_IN_USE 2 - -/* GABA: - (class - (name channel_table) - (vars - ; Channels are indexed by local number - (channels space (object ssh_channel) used_channels) - - ; Global requests that we support - (global_requests object alist) - ; Channel types that we can open - (channel_types object alist) - - ; FIXME: Add fallbacks, to be used for unknown requests - ; and channel types. - ; (global_fallback object ...) - (open_fallback object channel_open) - - ; Allocation of local channel numbers is managed using the same - ; method as is traditionally used for allocation of unix file - ; descriptors. - - ; Channel numbers can be reserved before there is any actual channel - ; assigned to them. So the channels table is not enough for keeping track of which - ; numbers are in use. - (in_use space UINT8) - - ; Allocated size of the arrays. - (allocated_channels . UINT32) - - ; Number of entries in the arrays that are in use and - ; initialized. - (used_channels . UINT32) - - ; The smallest channel number that is likely to be free - (next_channel . UINT32) - - ; Number of currently allocated channel numbers. - (channel_count . UINT32) - - (max_channels . UINT32) ; Max number of channels allowed - - ; Forwarded TCP ports - (local_ports struct object_queue) - (remote_ports struct object_queue) - - ; Used if we're currently forwarding X11 - ; To support several screens at the same time, - ; this should be replaced with a list, analogous to - ; the remote_ports list above. - (x11_display object client_x11_display) - - ; Global requests that we have received, and should reply to - ; in the right order - (active_global_requests struct object_queue) - - ; Queue of global requests that we expect replies on. - (pending_global_requests struct object_queue) - - ; If non-zero, close connection after all active channels have - ; died, and don't allow any new channels to be opened. - (pending_close . int))) -*/ - -/* SSH_MSG_GLOBAL_REQUEST */ - -/* GABA: - (class - (name global_request) - (vars - (handler method void "struct ssh_connection *connection" - "UINT32 type" - ; want-reply is needed only by - ; do_gateway_global_request. - "int want_reply" - "struct simple_buffer *args" - "struct command_continuation *c" - "struct exception_handler *e"))) -*/ - -#define GLOBAL_REQUEST(r, c, t, w, a, n, e) \ -((r)->handler((r), (c), (t), (w), (a), (n), (e))) - -/* SSH_MSG_CHANNEL_OPEN */ - -/* Raised if opening of a channel fails. Used both on the client and - * the server side.*/ -/* GABA: - (class - (name channel_open_exception) - (super exception) - (vars - (error_code . UINT32))) -*/ - -struct exception * -make_channel_open_exception(UINT32 error_code, const char *msg); - - -/* GABA: - (class - (name channel_open) - (vars - (handler method void - "struct ssh_connection *connection" - "struct channel_open_info *info" - "struct simple_buffer *data" - "struct command_continuation *c" - "struct exception_handler *e"))) -*/ - -#define CHANNEL_OPEN(o, c, i, d, r, e) \ -((o)->handler((o), (c), (i), (d), (r), (e))) - -/* SSH_MSG_CHANNEL_REQUEST */ - -/* GABA: - (class - (name channel_request) - (vars - (handler method void - "struct ssh_channel *channel" - "struct channel_request_info *info" - "struct simple_buffer *args" - "struct command_continuation *c" - "struct exception_handler *e"))) -*/ - -#define CHANNEL_REQUEST(s, c, i, a, n, e) \ -((s)->handler((s), (c), (i), (a), (n), (e))) - - -void init_channel(struct ssh_channel *channel); - -struct channel_table *make_channel_table(void); -int alloc_channel(struct channel_table *table); -void dealloc_channel(struct channel_table *table, int i); - -void -use_channel(struct ssh_connection *connection, - UINT32 local_channel_number); - -void -register_channel(UINT32 local_channel_number, - struct ssh_channel *channel, - int take_into_use); - -struct ssh_channel * -lookup_channel(struct channel_table *table, UINT32 i); -struct ssh_channel * -lookup_channel_reserved(struct channel_table *table, UINT32 i); - -struct abstract_write *make_channel_write(struct ssh_channel *channel); -struct abstract_write *make_channel_write_extended(struct ssh_channel *channel, - UINT32 type); - -struct io_callback *make_channel_read_data(struct ssh_channel *channel); -struct io_callback *make_channel_read_stderr(struct ssh_channel *channel); - -struct lsh_string *format_global_failure(void); -struct lsh_string *format_global_success(void); - -struct lsh_string *format_open_failure(UINT32 channel, UINT32 reason, - const char *msg, const char *language); -struct lsh_string *format_open_confirmation(struct ssh_channel *channel, - UINT32 channel_number, - const char *format, ...); - -struct lsh_string *format_channel_success(UINT32 channel); -struct lsh_string *format_channel_failure(UINT32 channel); - -struct lsh_string *prepare_window_adjust(struct ssh_channel *channel, - UINT32 add); - -void -channel_start_receive(struct ssh_channel *channel, - UINT32 initial_window_size); - -struct lsh_string * -format_channel_open_s(struct lsh_string *type, - UINT32 local_channel_number, - struct ssh_channel *channel, - struct lsh_string *args); - -struct lsh_string * -format_channel_open(int type, UINT32 local_channel_number, - struct ssh_channel *channel, - const char *format, ...); - -struct lsh_string * -format_channel_request_i(struct channel_request_info *info, - struct ssh_channel *channel, - UINT32 args_length, const UINT8 *args_data); - -struct lsh_string * -format_channel_request(int type, - struct ssh_channel *channel, - int want_reply, - const char *format, ...); - -struct lsh_string * -format_global_request(int type, int want_reply, - const char *format, ...); - -struct lsh_string *format_channel_close(struct ssh_channel *channel); -struct lsh_string *format_channel_eof(struct ssh_channel *channel); - -void channel_close(struct ssh_channel *channel); -void channel_eof(struct ssh_channel *channel); - -struct lsh_callback * -make_channel_read_close_callback(struct ssh_channel *channel); - -struct exception_handler * -make_channel_io_exception_handler(struct ssh_channel *channel, - const char *prefix, - struct exception_handler *parent, - const char *context); - -struct lsh_string *channel_transmit_data(struct ssh_channel *channel, - struct lsh_string *data); - -struct lsh_string *channel_transmit_extended(struct ssh_channel *channel, - UINT32 type, - struct lsh_string *data); - -void init_connection_service(struct ssh_connection *connection); - -extern struct command connection_service_command; -#define INIT_CONNECTION_SERVICE (&connection_service_command.super) - - -#endif /* LSH_CHANNEL_H_INCLUDED */ diff --git a/lsh/src/channel.h.x b/lsh/src/channel.h.x deleted file mode 100755 index 4028bcd..0000000 Binary files a/lsh/src/channel.h.x and /dev/null differ diff --git a/lsh/src/channel_commands.c b/lsh/src/channel_commands.c deleted file mode 100755 index 764d9ef..0000000 --- a/lsh/src/channel_commands.c +++ /dev/null @@ -1,252 +0,0 @@ -/* channel_commands.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "channel_commands.h" - -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#define GABA_DEFINE -#include "channel_commands.h.x" -#undef GABA_DEFINE - -#include "channel_commands.c.x" - -#include - -void -do_channel_open_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(channel_open_command, self, s); - CAST(ssh_connection, connection, x); - struct lsh_string *request; - struct ssh_channel *channel; - - int index = alloc_channel(connection->table); - - if (index < 0) - { - /* We have run out of channel numbers. */ - werror("do_channel_open_command: alloc_channel failed\n"); - EXCEPTION_RAISE(e, - make_channel_open_exception( - SSH_OPEN_RESOURCE_SHORTAGE, - "Allocating a local channel number failed.")); - } - - channel = NEW_CHANNEL(self, connection, index, &request); - - if (!channel) - { - werror("do_channel_open_command: NEW_CHANNEL failed\n"); - dealloc_channel(connection->table, index); - } - else - { - /* FIXME: Set up channel->write here? If we do that, perhaps we - * need not pass the connection to NEW_CHANNEL. */ - channel->open_continuation = c; - channel->e = e; - register_channel(index, channel, 0); - - C_WRITE(connection, request); - } -} - -void -do_channel_request_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(channel_request_command, self, s); - CAST_SUBTYPE(ssh_channel, channel, x); - - struct lsh_string *request - = FORMAT_CHANNEL_REQUEST(self, channel, &c); - - if (CONTINUATION_USED_P(c)) - object_queue_add_tail(&channel->pending_requests, - &make_command_context(c, e)->super); - - C_WRITE(channel->connection, request); -} - -void -do_channel_global_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(global_request_command, self, s); - CAST_SUBTYPE(ssh_connection, connection, x); - - struct lsh_string *request - = FORMAT_GLOBAL_REQUEST(self, connection, &c); - - if (CONTINUATION_USED_P(c)) - object_queue_add_tail(&connection->table->pending_global_requests, - &make_command_context(c, e)->super); - - C_WRITE(connection, request); -} - -void -do_install_global_request_handler(struct command_2 *s, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(install_info, self, s); - CAST(ssh_connection, connection, a1); - CAST_SUBTYPE(global_request, handler, a2); - - assert(handler); - - trace("Installing global request handler for '%a'\n", self->name); - - ALIST_SET(connection->table->global_requests, - self->name, - &handler->super); - - COMMAND_RETURN(c, connection); -} - -void -do_install_channel_open_handler(struct command_2 *s, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(install_info, self, s); - CAST(ssh_connection, connection, a1); - CAST_SUBTYPE(channel_open, handler, a2); - - assert(handler); - - trace("Installing channel open handler for '%a'\n", self->name); - - ALIST_SET(connection->table->channel_types, - self->name, - &handler->super); - - COMMAND_RETURN(c, connection); -} - - -/* Special cases, when the handler is known early */ - -/* Takes a connection as argument, and installs a fix handler */ -/* GABA: - (class - (name install_global_request_handler) - (super command) - (vars - (name . int) - (handler object global_request))) -*/ - -static void -do_install_fix_global_request_handler(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(install_global_request_handler, self, s); - CAST(ssh_connection, connection, x); - - trace("Installing fix global request handler for '%a'\n", self->name); - - ALIST_SET(connection->table->global_requests, - self->name, - &self->handler->super); - - COMMAND_RETURN(c, x); -} - -struct command * -make_install_fix_global_request_handler(UINT32 name, - struct global_request *handler) -{ - NEW(install_global_request_handler, self); - - assert(handler); - - self->super.call = do_install_fix_global_request_handler; - self->name = name; - self->handler = handler; - - return &self->super; -} - -/* Takes a connection as argument, and installs a fix handler */ -/* GABA: - (class - (name install_channel_open_handler) - (super command) - (vars - (name . int) - (handler object channel_open))) -*/ - -static void -do_install_fix_channel_open_handler(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(install_channel_open_handler, self, s); - CAST(ssh_connection, connection, x); - - trace("Installing fix channel open handler for type '%a'\n", self->name); - - ALIST_SET(connection->table - ->channel_types, - self->name, - &self->handler->super); - - COMMAND_RETURN(c, connection); -} - -struct command * -make_install_fix_channel_open_handler(UINT32 name, - struct channel_open *handler) -{ - NEW(install_channel_open_handler, self); - - assert(handler); - - self->super.call = do_install_fix_channel_open_handler; - self->name = name; - self->handler = handler; - - return &self->super; -} - diff --git a/lsh/src/channel_commands.c.x b/lsh/src/channel_commands.c.x deleted file mode 100755 index 9c4d305..0000000 Binary files a/lsh/src/channel_commands.c.x and /dev/null differ diff --git a/lsh/src/channel_commands.h b/lsh/src/channel_commands.h deleted file mode 100755 index a58c4c3..0000000 --- a/lsh/src/channel_commands.h +++ /dev/null @@ -1,142 +0,0 @@ -/* channel_commands.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CHANNEL_COMMANDS_H_INCLUDED -#define LSH_CHANNEL_COMMANDS_H_INCLUDED - -#include "channel.h" - -#define GABA_DECLARE -#include "channel_commands.h.x" -#undef GABA_DECLARE - -/* Command to open a new channel. Takes a connection as argument - * returns a new channel. Raises an EXC_CHANNEL_OPEN exception on - * error. */ - -/* GABA: - (class - (name channel_open_command) - (super command) - (vars - ; This method should return a partially filled in channel, - ; and create a channel open request by calling - ; prepare_channel_open. - (new_channel method "struct ssh_channel *" - "struct ssh_connection *connection" - "UINT32 local_channel_number" - "struct lsh_string **request"))) -*/ - -#define NEW_CHANNEL(s, c, n, r) ((s)->new_channel((s), (c), (n), (r))) - -void do_channel_open_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e); - -/* Takes a channel as argument, and returns the same channel. Raises - * an exception on error. FIXME: Which exception??? */ -/* GABA: - (class - (name channel_request_command) - (super command) - (vars - ; This method should return a formatted request. The - ; want_reply field in the request should be non_zero iff *c is - ; non-NULL on return. - (format_request method "struct lsh_string *" - "struct ssh_channel *channel" - "struct command_continuation **c"))) -*/ - -#define FORMAT_CHANNEL_REQUEST(r, c, w) \ -((r)->format_request((r), (c), (w))) - -void do_channel_request_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e); - -/* GABA: - (class - (name global_request_command) - (super command) - (vars - (format_request method "struct lsh_string *" - "struct ssh_connection *connection" - "struct command_continuation **c"))) -*/ - -#define FORMAT_GLOBAL_REQUEST(r, conn, c) \ -((r)->format_request((r), (conn), (c))) - - -void do_channel_global_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e); - -struct command * -make_install_global_request_handler(UINT32 name, - struct global_request *handler); - -/* Takes a connection and a handler as arguments, and installs the - * handler. */ -/* GABA: - (class - (name install_info) - (super command_2) - (vars - (name . int))) -*/ - -void -do_install_global_request_handler(struct command_2 *s, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e); -void -do_install_channel_open_handler(struct command_2 *s, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e); - -#define STATIC_INSTALL_GLOBAL_HANDLER(atom) \ -{ { { STATIC_HEADER, do_command_2 }, do_install_global_request_handler }, atom } - -#define STATIC_INSTALL_OPEN_HANDLER(atom) \ -{ { { STATIC_HEADER, do_command_2 }, do_install_channel_open_handler }, atom } - -struct command * -make_install_fix_global_request_handler(UINT32 name, - struct global_request *handler); - -struct command * -make_install_fix_channel_open_handler(UINT32 name, - struct channel_open *handler); - -#endif /* LSH_CHANNEL_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/channel_commands.h.x b/lsh/src/channel_commands.h.x deleted file mode 100755 index aeec6f0..0000000 Binary files a/lsh/src/channel_commands.h.x and /dev/null differ diff --git a/lsh/src/channel_forward.c b/lsh/src/channel_forward.c deleted file mode 100644 index d085100..0000000 --- a/lsh/src/channel_forward.c +++ /dev/null @@ -1,137 +0,0 @@ -/* channel_forward.h - * - * General channel type for forwarding data to an fd - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 2001 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "channel_forward.h" - -#include "io.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#define GABA_DEFINE -#include "channel_forward.h.x" -#undef GABA_DEFINE - -/* NOTE: Adds the socket to the channel's resource list */ -void -init_channel_forward(struct channel_forward *self, - struct lsh_fd *socket, UINT32 initial_window) -{ - assert(socket); - - init_channel(&self->super); - - /* The rest of the callbacks are not set up until tcpip_start_io. */ - - /* NOTE: We don't need a close handler, as the channel's resource - * list is taken care of automatically. */ - - self->super.rec_window_size = initial_window; - - /* FIXME: Make maximum packet size configurable. */ - self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ; - - self->socket = socket; - - REMEMBER_RESOURCE(self->super.resources, &socket->super); -} - -struct channel_forward * -make_channel_forward(struct lsh_fd *socket, UINT32 initial_window) -{ - NEW(channel_forward, self); - init_channel_forward(self, socket, initial_window); - - return self; -} - -static void -do_channel_forward_receive(struct ssh_channel *c, - int type, struct lsh_string *data) -{ - CAST(channel_forward, closure, c); - - switch (type) - { - case CHANNEL_DATA: - A_WRITE(&closure->socket->write_buffer->super, data); - break; - case CHANNEL_STDERR_DATA: - werror("Ignoring unexpected stderr data.\n"); - lsh_string_free(data); - break; - default: - fatal("Internal error. do_channel_forward_receive"); - } -} - -static void -do_channel_forward_send_adjust(struct ssh_channel *s, - UINT32 i UNUSED) -{ - CAST(channel_forward, self, s); - - self->socket->want_read = 1; -} - -static void -do_channel_forward_eof(struct ssh_channel *s) -{ - CAST(channel_forward, self, s); - - if (shutdown (self->socket->fd, SHUT_WR) < 0) - werror("do_channel_forward_eof, shutdown failed, (errno = %i): %z\n", - errno, STRERROR(errno)); -} - - -/* NOTE: Because this function is called by - * do_open_forwarded_tcpip_continuation, the same restrictions apply. - * I.e we can not assume that the channel is completely initialized - * (channel_open_continuation has not yet done its work), and we can't - * send any packets. */ -void -channel_forward_start_io(struct channel_forward *channel) -{ - channel->super.receive = do_channel_forward_receive; - channel->super.send_adjust = do_channel_forward_send_adjust; - channel->super.eof = do_channel_forward_eof; - - /* Install callbacks on the local socket. - * NOTE: We don't install any channel_io_exception_handler. */ - io_read_write(channel->socket, - make_channel_read_data(&channel->super), - /* FIXME: Make this configurable */ - SSH_MAX_PACKET * 10, /* self->block_size, */ - make_channel_read_close_callback(&channel->super)); - - /* Flow control */ - channel->socket->write_buffer->report = &channel->super.super; -} - diff --git a/lsh/src/channel_forward.h b/lsh/src/channel_forward.h deleted file mode 100644 index da56170..0000000 --- a/lsh/src/channel_forward.h +++ /dev/null @@ -1,55 +0,0 @@ -/* channel_forward.h - * - * General channel type for forwarding data to an fd - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 2001 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CHANNEL_FORWARD_H_INCLUDED -#define LSH_CHANNEL_FORWARD_H_INCLUDED - -#include "channel.h" - -#define GABA_DECLARE -#include "channel_forward.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name channel_forward) - (super ssh_channel) - (vars - (socket object lsh_fd))) -*/ - -void -init_channel_forward(struct channel_forward *self, - struct lsh_fd *socket, UINT32 initial_window); - -struct channel_forward * -make_channel_forward(struct lsh_fd *socket, UINT32 initial_window); - -void -channel_forward_start_io(struct channel_forward *channel_forward); - - -#endif /* LSH_CHANNEL_FORWARD_H_INCLUDED */ - diff --git a/lsh/src/channel_forward.h.x b/lsh/src/channel_forward.h.x deleted file mode 100644 index 40533af..0000000 --- a/lsh/src/channel_forward.h.x +++ /dev/null @@ -1,31 +0,0 @@ -/* -CLASS:channel_forward:ssh_channel -*/ -#ifndef GABA_DEFINE -struct channel_forward -{ - struct ssh_channel super; - struct lsh_fd *socket; -}; -extern struct lsh_class channel_forward_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_channel_forward_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct channel_forward *i = (struct channel_forward *) o; - mark((struct lsh_object *) i->socket); -} -struct lsh_class channel_forward_class = -{ - STATIC_HEADER, - &(ssh_channel_class), - "channel_forward", - sizeof(struct channel_forward), - do_channel_forward_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - diff --git a/lsh/src/charset.c b/lsh/src/charset.c deleted file mode 100755 index 0c7431e..0000000 --- a/lsh/src/charset.c +++ /dev/null @@ -1,226 +0,0 @@ -/* charset.c - * - * Translate local characterset to and from utf8. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "charset.h" - -#include "format.h" /* For lsh_string_dup() */ -#include "parse.h" -#include "werror.h" -#include "xalloc.h" - -#include - -static int local_charset; - -void set_local_charset(int charset) -{ - local_charset = charset; -} - -UINT32 local_to_ucs4(int c) -{ - switch (local_charset) - { - case CHARSET_USASCII: - case CHARSET_LATIN1: - return (UINT32) c; - default: - fatal("Internal error"); - }; -} - -/* NOTE: This function does not filter any control characters */ -int ucs4_to_local(UINT32 c) -{ - switch (local_charset) - { - case CHARSET_USASCII: - return (c < 0x80) ? (int) c : -1; - case CHARSET_LATIN1: - return (c < 0x100) ? (int) c : -1; - default: - fatal("Internal error"); - }; -} - -struct lsh_string * -local_to_utf8(struct lsh_string *s, int free) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - switch (local_charset) - { - case CHARSET_UTF8: - case CHARSET_USASCII: - return s; - default: - { - UINT32 *chars = alloca(s->length * sizeof(UINT32)); - unsigned char *lengths = alloca(s->length); - - UINT32 total = 0; - { - UINT32 i; - - /* First convert to ucs-4, and compute the length of the corresponding - * utf-8 string. */ - for (i = 0; ilength; i++) - { - UINT32 c = local_to_ucs4(s->data[i]); - unsigned char l = 1; - - if (c >= (1UL<<7)) - { - l++; - if (c >= (1UL<<11)) - { - l++; - if (c >= (1UL<<16)) - { - l++; - if (c >= (1UL<<21)) - { - l++; - if (c >= (1UL<<25)) - { - l++; - if (c >= (1UL<<31)) - fatal("Internal error!\n"); - }}}}} - chars[i] = c; - lengths[i] = l; - total += l; - } - } - { - struct lsh_string *res = lsh_string_alloc(total); - UINT32 i, j; - - for(i = j = 0; ilength; i++) - { - static const UINT8 prefix[] - = {0, 0xC0, 0xE0, 0xF0, 0xF8, 0XFC }; - - UINT32 c = chars[i]; - unsigned char l = lengths[i] - 1; - int k; - - for (k = l; k; k--) - { - res->data[j+k] = 0x80 | (c & 0x3f); - c >>= 6; - } - assert( !(prefix[l] & c) ); - res->data[j] = prefix[l] | c; - - j += lengths[i]; - } - assert(j == total); - - if (free) - lsh_string_free(s); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return res; - } - } - } -} - -int local_is_utf8(void) { return (local_charset == CHARSET_UTF8); } - -struct lsh_string *low_utf8_to_local(UINT32 length, UINT8 *s, int strict) -{ - UINT32 i; - struct lsh_string *res; - struct simple_buffer buffer; - - assert(!local_is_utf8()); - - /* The string can't grow when converted to local charset */ - res = lsh_string_alloc(length); - - simple_buffer_init(&buffer, length, s); - - for (i = 0; 1; i++) - { - UINT32 ucs4; - - switch(parse_utf8(&buffer, &ucs4)) - { - case -1: - assert(i<=res->length); - - res->length = i; - - return res; - - case 1: - { - int local = ucs4_to_local(ucs4); - - if (local >= 0) - { - res->data[i] = local; - break; - } - else if (!strict) - { - /* Replace unkonwn characters. */ - res->data[i] = '?'; - break; - } - /* Fall through */ - } - case 0: /* Error */ - lsh_string_free(res); - - return NULL; - - default: - - fatal("Internal error!\n"); - } - } -} - -struct lsh_string *utf8_to_local(struct lsh_string *s, int strict, int free) -{ - struct lsh_string *res; - - if (local_is_utf8()) - return free ? s : lsh_string_dup(s); - - res = low_utf8_to_local(s->length, s->data, strict); - - if (free) - lsh_string_free(s); - - return res; -} diff --git a/lsh/src/charset.h b/lsh/src/charset.h deleted file mode 100755 index 69afb9a..0000000 --- a/lsh/src/charset.h +++ /dev/null @@ -1,53 +0,0 @@ -/* charset.h - * - * Translate local characterset to and from utf8. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CHARSET_H_INCLUDED -#define LSH_CHARSET_H_INCLUDED - -#include "lsh_types.h" - -/* FIXME: Use charsets real objects, instead of using fixed constants */ - -#define CHARSET_UTF8 0 -#define CHARSET_LATIN1 1 -#define CHARSET_USASCII 2 - -void set_local_charset(int charset); - -UINT32 local_to_ucs4(int c); -int ucs4_to_local(UINT32 c); - -struct lsh_string *local_to_utf8(struct lsh_string *s, int free); - -/* Returns NULL if the UTF-8 encoding is invalid. If STRICT, it - * returns NULL also if the UTF-8 is valid but not representable in - * the local charset. If not STRICT, non-representably charecters are - * replaced with '?'. */ -struct lsh_string *utf8_to_local(struct lsh_string *s, int strict, int free); -struct lsh_string *low_utf8_to_local(UINT32 length, UINT8 *s, int strict); -int local_is_utf8(void); - -#endif /* LSH_CHARSET_H_INCLUDED */ diff --git a/lsh/src/client.c b/lsh/src/client.c deleted file mode 100755 index 6f4f838..0000000 --- a/lsh/src/client.c +++ /dev/null @@ -1,1262 +0,0 @@ -/* client.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000 Niels Möller - * - * 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 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 should 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 - */ - -#if MACOS -#include "lsh_context.h" -#endif - -#include "client.h" - -#include "abstract_io.h" -#include "channel.h" -#include "channel_commands.h" -#include "connection.h" -#include "format.h" -#include "interact.h" -#include "io.h" -#include "pad.h" -#include "parse.h" -#include "ssh.h" -#include "suspend.h" -#include "tcpforward_commands.h" -#include "translate_signal.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include -#include -#include - -#if MACOS -extern int strcasecmp(const char * str1, const char * str2); -#endif - -#include "lsh_argp.h" - -#define GABA_DEFINE -#include "client.h.x" -#undef GABA_DEFINE - -#include "client.c.x" - -#define DEFAULT_ESCAPE_CHAR '~' - -static struct lsh_string * -format_service_request(int name) -{ - return ssh_format("%c%a", SSH_MSG_SERVICE_REQUEST, name); -} - -/* Start a service that the server has accepted (for instance - * ssh-userauth). */ -/* GABA: - (class - (name accept_service_handler) - (super packet_handler) - (vars - (service . int) - (c object command_continuation) - - ;; FIXME: Do we really need the exception handler here? - (e object exception_handler))) -*/ - -static void -do_accept_service(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(accept_service_handler, closure, c); - - struct simple_buffer buffer; - unsigned msg_number; - int name; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_SERVICE_ACCEPT) - && ( -#if DATAFELLOWS_WORKAROUNDS - (connection->peer_flags & PEER_SERVICE_ACCEPT_KLUDGE) -#else - 0 -#endif - || (parse_atom(&buffer, &name) - && (name == closure->service))) - && parse_eod(&buffer)) - { - connection->dispatch[SSH_MSG_SERVICE_ACCEPT] = &connection_fail_handler; - - COMMAND_RETURN(closure->c, connection); - } - else - PROTOCOL_ERROR(closure->e, "Invalid SSH_MSG_SERVICE_ACCEPT message"); -} - -struct packet_handler * -make_accept_service_handler(UINT32 service, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(accept_service_handler, closure); - - closure->super.handler = do_accept_service; - closure->service = service; - closure->c = c; - closure->e = e; - - return &closure->super; -} - -void -do_request_service(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(request_service, self, s); - CAST(ssh_connection, connection, x); - - connection->dispatch[SSH_MSG_SERVICE_ACCEPT] - = make_accept_service_handler(self->service, c, e); - - C_WRITE(connection, - format_service_request(self->service)); -} - -struct command * -make_request_service(int service) -{ - NEW(request_service, closure); - - closure->super.call = do_request_service; - closure->service = service; - - return &closure->super; -} - - -/* GABA: - (class - (name exit_handler) - (super channel_request) - (vars - (exit_status . "int *"))) -*/ - -static void -do_exit_status(struct channel_request *c, - struct ssh_channel *channel, - struct channel_request_info *info, - struct simple_buffer *args, - struct command_continuation *s, - struct exception_handler *e) -{ - CAST(exit_handler, closure, c); - UINT32 status; - - if (!info->want_reply - && parse_uint32(args, &status) - && parse_eod(args)) - { - verbose("client.c: Receiving exit-status %i on channel %i\n", - status, channel->channel_number); - - *closure->exit_status = status; - - ALIST_SET(channel->request_types, ATOM_EXIT_STATUS, NULL); - ALIST_SET(channel->request_types, ATOM_EXIT_SIGNAL, NULL); - - COMMAND_RETURN(s, NULL); - } - else - /* Invalid request */ - PROTOCOL_ERROR(e, "Invalid exit-status message"); -} - -static void -do_exit_signal(struct channel_request *c, - struct ssh_channel *channel, - struct channel_request_info *info, - struct simple_buffer *args, - struct command_continuation *s, - struct exception_handler *e) -{ - CAST(exit_handler, closure, c); - - UINT32 signal; - int core; - - const UINT8 *msg; - UINT32 length; - - const UINT8 *language; - UINT32 language_length; - - if (!info->want_reply - && parse_atom(args, &signal) - && parse_boolean(args, &core) - && parse_string(args, &length, &msg) - && parse_string(args, &language_length, &language) - && parse_eod(args)) - { - /* FIXME: What exit status should be returned when the remote - * process dies violently? */ - - *closure->exit_status = 7; - - werror("Remote process was killed by signal: %ups %z\n", - length, msg, - core ? "(core dumped remotely)\n": ""); - - ALIST_SET(channel->request_types, ATOM_EXIT_STATUS, NULL); - ALIST_SET(channel->request_types, ATOM_EXIT_SIGNAL, NULL); - - COMMAND_RETURN(s, NULL); - } - else - /* Invalid request */ - PROTOCOL_ERROR(e, "Invalid exit-signal message"); -} - -struct channel_request * -make_handle_exit_status(int *exit_status) -{ - NEW(exit_handler, self); - - self->super.handler = do_exit_status; - - self->exit_status = exit_status; - - return &self->super; -} - -struct channel_request * -make_handle_exit_signal(int *exit_status) -{ - NEW(exit_handler, self); - - self->super.handler = do_exit_signal; - - self->exit_status = exit_status; - - return &self->super; -} - -/* GABA: - (class - (name session_open_command) - (super channel_open_command) - (vars - ; This command can only be executed once, - ; so we can allocate the session object in advance. - (session object ssh_channel))) -*/ - -static struct ssh_channel * -new_session(struct channel_open_command *s, - struct ssh_connection *connection, - UINT32 local_channel_number, - struct lsh_string **request) -{ - CAST(session_open_command, self, s); - struct ssh_channel *res; - - self->session->connection = connection; - - *request = format_channel_open(ATOM_SESSION, - local_channel_number, - self->session, ""); - - res = self->session; - - /* Make sure this command can not be invoked again */ - self->session = NULL; - - return res; -} - -struct command * -make_open_session_command(struct ssh_channel *session) -{ - NEW(session_open_command, self); - self->super.super.call = do_channel_open_command; - self->super.new_channel = new_session; - self->session = session; - - return &self->super.super; -} - - -static struct lsh_string * -do_format_shell_request(struct channel_request_command *s UNUSED, - struct ssh_channel *channel, - struct command_continuation **c) -{ - return format_channel_request(ATOM_SHELL, channel, !!*c, ""); -} - -struct channel_request_command request_shell = -{ { STATIC_HEADER, do_channel_request_command }, do_format_shell_request }; - - -/* GABA: - (class - (name exec_request) - (super channel_request_command) - (vars - (command string))) -*/ - -static struct lsh_string * -do_format_exec_request(struct channel_request_command *s, - struct ssh_channel *channel, - struct command_continuation **c) -{ - CAST(exec_request, self, s); - - verbose("lsh: Requesting remote exec.\n"); - - return format_channel_request(ATOM_EXEC, channel, - !!*c, "%S", self->command); -} - -struct command * -make_exec_request(struct lsh_string *command) -{ - NEW(exec_request, req); - - req->super.format_request = do_format_exec_request; - req->super.super.call = do_channel_request_command; - req->command = command; - - return &req->super.super; -} - - -/* Handling of options and operations shared by the plain lsh client - and lshg. */ - -/* Forward declaration */ - -static struct ssh_channel * -make_client_session(struct client_options *options); - -/* Block size for stdout and stderr buffers */ -#define BLOCK_SIZE 32768 - -/* Window size for the session channel - * - * NOTE: Large windows seem to trig a bug in sshd2. */ -#define WINDOW_SIZE 10000 - -#define ARG_NOT 0x400 - -#define OPT_STDIN 0x210 -#define OPT_STDOUT 0x211 -#define OPT_STDERR 0x212 - -#define OPT_FORK_STDIO 0x213 - -void -init_client_options(struct client_options *self, - struct io_backend *backend, - struct randomness_with_poll *random, - struct exception_handler *handler, - int *exit_code) -{ - self->backend = backend; - self->random = random; - - self->tty = make_unix_interact(backend); - self->escape = -1; - - self->handler = handler; - - self->exit_code = exit_code; - - self->not = 0; - self->port = "ssh"; - self->remote = NULL; - - self->local_user = self->user = getenv("LOGNAME"); - - self->with_remote_peers = 0; - self->with_pty = -1; - self->with_x11 = 0; - - self->stdin_file = NULL; - self->stdout_file = NULL; - self->stderr_file = NULL; - - self->stdin_fork = 0; - self->stdout_fork = 0; -#ifndef MACOS - self->stderr_fork = 1; -#else - self->stderr_fork = 0; -#endif - self->used_stdin = 0; - self->used_pty = 0; - self->used_x11 = 0; - - self->start_shell = 1; - self->remote_forward = 0; - - object_queue_init(&self->actions); -} - -/* Host to connect to */ -DEFINE_COMMAND(client_options2remote) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(client_options, options, a); - trace("client.c: client_options2remote\n"); - - COMMAND_RETURN(c, options->remote); -} - -/* Host to connect to */ -DEFINE_COMMAND(client_options2actions) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(client_options, options, a); - - trace("client.c: client_options2actions, %i actions\n", - options->actions.length); - - COMMAND_RETURN(c, queue_to_list(&options->actions)); -} - -static const struct argp_option -client_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "port", 'p', "Port", 0, "Connect to this port.", 0 }, - { "user", 'l', "User name", 0, "Login as this user.", 0 }, - - { NULL, 0, NULL, 0, "Actions:", CLIENT_ARGP_ACTION_GROUP }, - { "forward-local-port", 'L', "local-port:target-host:target-port", 0, "", 0 }, -#if 0 - { "forward-remote-port", 'R', "remote-port:target-host:target-port", 0, "", 0 }, -#endif - { "nop", 'N', NULL, 0, "No operation (suppresses the default action, " - "which is to spawn a remote shell)", 0 }, -#if !MACOS - { "background", 'B', NULL, 0, "Put process into the background. Implies -N.", 0 }, -#endif - { "execute", 'E', "command", 0, "Execute a command on the remote machine", 0 }, - { "shell", 'S', "command", 0, "Spawn a remote shell", 0 }, - /* { "gateway", 'G', NULL, 0, "Setup a local gateway", 0 }, */ - { NULL, 0, NULL, 0, "Universal not:", 0 }, - { "no", 'n', NULL, 0, "Inverts the effect of the next modifier", 0 }, - - { NULL, 0, NULL, 0, "Modifiers that apply to port forwarding:", - CLIENT_ARGP_MODIFIER_GROUP - 10 }, - { "remote-peers", 'g', NULL, 0, "Allow remote access to forwarded ports", 0 }, - { "no-remote-peers", 'g' | ARG_NOT, NULL, 0, - "Disallow remote access to forwarded ports (default).", 0 }, - - { NULL, 0, NULL, 0, "Modifiers that apply to remote execution:", 0 }, - { "stdin", OPT_STDIN, "Filename", 0, "Redirect stdin", 0}, - { "no-stdin", OPT_STDIN | ARG_NOT, NULL, 0, "Redirect stdin from /dev/null", 0}, - { "stdout", OPT_STDOUT, "Filename", 0, "Redirect stdout", 0}, - { "no-stdout", OPT_STDOUT | ARG_NOT, NULL, 0, "Redirect stdout to /dev/null", 0}, - { "stderr", OPT_STDERR, "Filename", 0, "Redirect stderr", 0}, - { "no-stderr", OPT_STDERR | ARG_NOT, NULL, 0, "Redirect stderr to /dev/null", 0}, -#if !MACOS - { "cvs-workaround", OPT_FORK_STDIO, "i?o?e?", OPTION_ARG_OPTIONAL, - "Avoid setting one or more of the stdio file descriptors into " - "non-blocking mode. If no argument is provided, the workaround is " - "applied to all three file descriptors. By default, the workaround " - "is applied to stderr only.", 0 }, - { "no-cvs-workaround", OPT_FORK_STDIO | ARG_NOT, NULL, 0, - "Disable the cvs workaround.", 0 }, -#endif -#if WITH_PTY_SUPPORT - { "pty", 't', NULL, 0, "Request a remote pty (default).", 0 }, - { "no-pty", 't' | ARG_NOT, NULL, 0, "Don't request a remote pty.", 0 }, -#endif /* WITH_PTY_SUPPORT */ - { "escape-char", 'e', "Character", 0, "Escape char. `none' means disable. " - "Default is to use `~' if we have a tty, otherwise none.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - - -/* GABA: - (expr - (name make_start_session) - (params - (open_session object command) - (requests object object_list)) - (expr (lambda (connection) - ((progn requests) - ; Create a "session" channel - (open_session connection))))) -*/ - -/* Requests a shell or command, and connects the channel to our stdio. */ -/* GABA: - (expr - (name client_start_session) - (params - (request object command)) - (expr - (lambda (session) - (client_start_io (request session))))) -*/ - -static struct command * -make_client_start_session(struct command *request) -{ - CAST_SUBTYPE(command, r, client_start_session(request)); - return r; -} - -static void -client_maybe_pty(struct client_options *options, - struct object_queue *q) -{ -#if WITH_PTY_SUPPORT - if (options->with_pty && !options->used_pty) - { - options->used_pty = 1; - - if (options->tty && INTERACT_IS_TTY(options->tty)) - { - struct command *get_pty = make_pty_request(options->tty); - - if (get_pty) - object_queue_add_tail(q, - /* Ignore EXC_CHANNEL_REQUEST for the pty allocation call. */ - &make_catch_apply - (make_catch_handler_info(EXC_ALL, EXC_CHANNEL_REQUEST, - 0, NULL), - get_pty)->super); - else - werror("lsh: Can't use tty (probably getattr or atexit failed).\n"); - } - else - werror("lsh: No tty available.\n"); - } -#endif -} - -static void -client_maybe_x11(struct client_options *options, - struct object_queue *q) -{ - if (options->with_x11) - { - char *display = getenv("DISPLAY"); - struct command *request = NULL; - - assert(options->random); - if (display) - request = make_forward_x11(display, &options->random->super); - - if (request) - { - object_queue_add_tail(q, &request->super); - options->used_x11 = 1; - } - else - werror("Can't find any local X11 display to forward.\n"); - } -} - -/* Create an interactive session */ -static struct command * -client_shell_session(struct client_options *options) -{ - struct ssh_channel *session = make_client_session(options); - - if (session) - { - struct object_queue session_requests; - - object_queue_init(&session_requests); - - client_maybe_pty(options, &session_requests); - client_maybe_x11(options, &session_requests); - - object_queue_add_tail(&session_requests, - &make_client_start_session(&request_shell.super)->super); - - { - CAST_SUBTYPE(command, r, - make_start_session - (make_open_session_command(session), - queue_to_list_and_kill(&session_requests))); - return r; - } - } - else - return NULL; -} - -/* Create a session executing a command line */ -static struct command * -client_command_session(struct client_options *options, - struct lsh_string *command) -{ - struct ssh_channel *session = make_client_session(options); - - if (session) - { - struct object_queue session_requests; - - object_queue_init(&session_requests); - - /* NOTE: Doesn't ask for a pty. That's traditional behaviour, - * although perhaps not the Right Thing. */ - - client_maybe_pty(options, &session_requests); - client_maybe_x11(options, &session_requests); - - object_queue_add_tail(&session_requests, - &make_client_start_session(make_exec_request(command))->super); - { - CAST_SUBTYPE(command, r, - make_start_session - (make_open_session_command(session), - queue_to_list_and_kill(&session_requests))); - return r; - } - } - - return NULL; -} - -struct command * -client_add_action(struct client_options *options, - struct command *action) -{ - if (action) - object_queue_add_tail(&options->actions, &action->super); - - return action; -} - -/* NOTE: Some of the original quoting is lost here. */ -static struct lsh_string * -rebuild_command_line(unsigned argc, char **argv) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - unsigned length; - unsigned i; - unsigned pos; - struct lsh_string *r; - unsigned *alengths = alloca(sizeof(unsigned) * argc); - - assert (argc); - length = argc - 1; /* Number of separating spaces. */ - - for (i = 0; idata, argv[0], alengths[0]); - pos = alengths[0]; - for (i = 1; idata[pos++] = ' '; - memcpy(r->data + pos, argv[i], alengths[i]); - pos += alengths[i]; - } - - assert(pos == r->length); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return r; -} - -#if MACOS - -static int -fork_input(int in) -{ - return -1; -} - -static int -fork_output(int out) -{ - return -1; -} - -#else - -static int -fork_input(int in) -{ - /* pipe[0] for reading, pipe[1] for writing. */ - int pipe[2]; - - if (!lsh_make_pipe(pipe)) - return -1; - - switch (fork()) - { - case -1: - /* Error */ - return -1; - case 0: - close(pipe[0]); - if (lsh_copy_file(in, pipe[1])) - _exit(EXIT_SUCCESS); - else - _exit(EXIT_FAILURE); - default: - /* Parent */ - close(pipe[1]); - return pipe[0]; - } -} - -static int -fork_output(int out) -{ - /* pipe[0] for reading, pipe[1] for writing. */ - int pipe[2]; - - if (!lsh_make_pipe(pipe)) - return -1; - - switch (fork()) - { - case -1: - /* Error */ - return -1; - case 0: - close(pipe[1]); - if (lsh_copy_file(pipe[0], out)) - _exit(EXIT_SUCCESS); - else - _exit(EXIT_FAILURE); - default: - /* Parent */ - close(pipe[0]); - return pipe[1]; - } -} -#endif - -/* FIXME: Use const? */ - -#define DEFINE_CALLBACK(name) \ -static void do_##name(struct lsh_callback *self); \ -static struct lsh_callback \ -name = { STATIC_HEADER, do_##name }; \ -static void do_##name(struct lsh_callback *self UNUSED) - -/* A callback that exits the process immediately. */ -DEFINE_CALLBACK(exit_callback) -{ - exit(EXIT_SUCCESS); -} - -DEFINE_CALLBACK(verbose_callback) -{ - verbose_flag = !verbose_flag; - if (verbose_flag) - verbose("Enabling verbose messages\n"); -} - -DEFINE_CALLBACK(debug_callback) -{ - debug_flag = !debug_flag; - if (debug_flag) - debug("Enabling debug messages\n"); -} - -DEFINE_CALLBACK(quiet_callback) -{ - quiet_flag = !quiet_flag; - if (!quiet_flag) - werror("Enabling warning messages\n"); -} - -DEFINE_COMMAND(background_process) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ -#if MACOS - werror("background_process: fork unimplemented\n"); - COMMAND_RETURN(c, a); -#else - switch (fork()) - { - case 0: - /* Child */ - /* FIXME: Should we create a new process group, close our tty - * and stdio, etc? */ - COMMAND_RETURN(c, a); - break; - case -1: - /* Error */ - werror("background_process: fork failed (errno = %i): %z\n", - errno, STRERROR(errno)); - COMMAND_RETURN(c, a); - break; - default: - /* Parent */ - _exit(EXIT_SUCCESS); - } -#endif -} - -/* Create a session object. stdout and stderr are shared (although - * with independent lsh_fd objects). stdin can be used by only one - * session (until something "session-control"/"job-control" is added). - * */ -static struct ssh_channel * -make_client_session(struct client_options *options) -{ - int in; - int out; - int err; - int is_tty = 0; - - struct escape_info *escape = NULL; - - debug("lsh.c: Setting up stdin\n"); - - if (options->stdin_file) - in = open(options->stdin_file, O_RDONLY); - else - { - if (options->used_stdin) -#if MACOS - in = open("dev:null", O_RDONLY); -#else - in = open("/dev/null", O_RDONLY); -#endif - else - { - in = (options->stdin_fork ? fork_input : dup)(STDIN_FILENO); - is_tty = isatty(STDIN_FILENO); - - options->used_stdin = 1; - } - } - - if (in < 0) - { - werror("lsh: Can't dup/open stdin (errno = %i): %z!\n", - errno, strerror(errno)); - return NULL; - } - - /* Attach the escape char handler, if appropriate. */ - if (options->escape > 0) - { - verbose("Enabling explicit escape character `%pc'\n", - options->escape); - escape = make_escape_info(options->escape); - } - else if ( (options->escape < 0) && is_tty) - { - verbose("Enabling default escape character `%pc'\n", - DEFAULT_ESCAPE_CHAR); - escape = make_escape_info(DEFAULT_ESCAPE_CHAR); - } - - /* Bind ^Z to suspend. */ - if (escape) - { - /* Bind ^Z to suspend. */ - escape->dispatch[26] = &suspend_callback; - escape->dispatch['.'] = &exit_callback; - - /* Toggle the verbosity flags */ - escape->dispatch['d'] = &debug_callback; - escape->dispatch['v'] = &verbose_callback; - escape->dispatch['q'] = &quiet_callback; - } - - debug("lsh.c: Setting up stdout\n"); - - if (options->stdout_file) - out = open(options->stdout_file, O_WRONLY | O_CREAT, 0666); - else if (options->stdout_fork) - out = fork_output(STDOUT_FILENO); - else - out = dup(STDOUT_FILENO); - - if (out < 0) - { - werror("lsh: Can't dup/open stdout (errno = %i): %z!\n", - errno, strerror(errno)); - close(in); - return NULL; - } - - debug("lsh.c: Setting up stderr\n"); - - if (options->stderr_file) - err = open(options->stderr_file, O_WRONLY | O_CREAT, 0666); - else if (options->stderr_fork) - err = fork_output(STDERR_FILENO); - else - { - err = dup(STDERR_FILENO); -#if MACOS -// set_error_syslog("lsh"); - set_error_nonblocking(STDERR_FILENO); -#else - set_error_nonblocking(STDERR_FILENO); -#endif - } - - if (err < 0) - { - werror("lsh: Can't dup/open stderr!\n"); - close(in); - close(out); - return NULL; - } - - /* Clear options */ - options->stdin_file = options->stdout_file = options->stderr_file = NULL; - - return make_client_session_channel - (io_read(make_lsh_fd(options->backend, - in, "client stdin", options->handler), - NULL, NULL), - io_write(make_lsh_fd(options->backend, - out, "client stdout", options->handler), - BLOCK_SIZE, NULL), - io_write(make_lsh_fd(options->backend, - err, "client stderr", options->handler), - BLOCK_SIZE, NULL), - escape, - WINDOW_SIZE, - options->exit_code); -} - - -/* Parse the argument for -R and -L */ -int -client_parse_forward_arg(char *arg, - UINT32 *listen_port, - struct address_info **target) -{ - char *first; - char *second; - char *end; - long port; - - first = strchr(arg, ':'); - if (!first) - return 0; - - second = strchr(first + 1, ':'); - if (!second || (second == first + 1)) - return 0; - - if (strchr(second + 1, ':')) - return 0; - - port = strtol(arg, &end, 0); - if ( (end == arg) || (end != first) - || (port < 0) || (port > 0xffff) ) - return 0; - - *listen_port = port; - - port = strtol(second + 1, &end, 0); - if ( (end == second + 1) || (*end != '\0') - || (port < 0) || (port > 0xffff) ) - return 0; - - *target = make_address_info(ssh_format("%ls", second - first - 1, first + 1), port); - - return 1; -} - -#define CASE_ARG(opt, attr, none) \ - case opt: \ - if (options->not) \ - { \ - options->not = 0; \ - \ - case opt | ARG_NOT: \ - options->attr = none; \ - break; \ - } \ - \ - options->attr = arg; \ - break - -#define CASE_FLAG(opt, flag) \ - case opt: \ - if (options->not) \ - { \ - options->not = 0; \ - \ - case opt | ARG_NOT: \ - options->flag = 0; \ - break; \ - } \ - \ - options->flag = 1; \ - break - -static error_t -client_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST_SUBTYPE(client_options, options, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_NO_ARGS: - argp_usage(state); - break; - case ARGP_KEY_ARG: - if (!state->arg_num) - { - if (options->port) - options->remote = make_address_info_c(arg, options->port, 0); - else - options->remote = make_address_info_c(arg, "ssh", 22); - - if (!options->remote) - argp_error(state, "Invalid port or service '%s'.", options->port); - - break; - } - else - /* Let the next case parse it. */ - return ARGP_ERR_UNKNOWN; - - break; - case ARGP_KEY_ARGS: - client_add_action - (options, - client_command_session - (options, rebuild_command_line(state->argc - state->next, - state->argv + state->next))); - options->start_shell = 0; - break; - - case ARGP_KEY_END: - if (!options->user) - { - argp_error(state, "No user name given. Use the -l option, or set LOGNAME in the environment."); - break; - } - -#if WITH_TCP_FORWARD - if (options->remote_forward) - client_add_action(options, - make_install_fix_channel_open_handler - (ATOM_FORWARDED_TCPIP, &channel_open_forwarded_tcpip)); -#endif /* WITH_TCP_FORWARD */ - - /* Add shell action */ - if (options->start_shell) - client_add_action(options, client_shell_session(options)); - - if (options->used_x11) - client_add_action(options, - make_install_fix_channel_open_handler - (ATOM_X11, - make_channel_open_x11(options->backend))); - - /* Install suspend-handler */ - suspend_install_handler(); - break; - - case 'p': - options->port = arg; - break; - - case 'l': - options->user = arg; - break; - - case 'e': - if (arg[0] && !arg[1]) - /* A single char argument */ - options->escape = arg[0]; - else if (!strcasecmp(arg, "none")) - options->escape = 0; - else - argp_error(state, "Invalid escape char: `%s'. " - "You must use a single character or `none'.", arg); - break; - case 'E': - client_add_action(options, client_command_session(options, ssh_format("%lz", arg))); - break; - - case 'S': - client_add_action(options, client_shell_session(options)); - break; - - case 'L': - { - UINT32 listen_port; - struct address_info *target; - - if (!client_parse_forward_arg(arg, &listen_port, &target)) - argp_error(state, "Invalid forward specification '%s'.", arg); - - client_add_action(options, make_forward_local_port - (options->backend, - make_address_info((options->with_remote_peers - ? NULL - : ssh_format("%lz", "127.0.0.1")), - listen_port), - target)); - break; - } - -#if 0 - case 'R': - { - UINT32 listen_port; - struct address_info *target; - - if (!client_parse_forward_arg(arg, &listen_port, &target)) - argp_error(state, "Invalid forward specification '%s'.", arg); - - client_add_action(options, make_forward_remote_port - (options->backend, - make_address_info((options->with_remote_peers - ? ssh_format("%lz", "0.0.0.0") - : ssh_format("%lz", "127.0.0.1")), - listen_port), - target)); - options->remote_forward = 1; - break; - } -#endif - case 'N': - options->start_shell = 0; - break; - -#if !defined(MACOS) - case 'B': - options->start_shell = 0; - client_add_action(options, &background_process); - break; -#endif - - CASE_FLAG('g', with_remote_peers); - -#if WITH_PTY_SUPPORT - CASE_FLAG('t', with_pty); -#endif /* WITH_PTY_SUPPORT */ - -#if MACOS - CASE_ARG(OPT_STDIN, stdin_file, "dev:null"); - CASE_ARG(OPT_STDOUT, stdout_file, "dev:null"); - CASE_ARG(OPT_STDERR, stderr_file, "dev:null"); -#else - CASE_ARG(OPT_STDIN, stdin_file, "/dev/null"); - CASE_ARG(OPT_STDOUT, stdout_file, "/dev/null"); - CASE_ARG(OPT_STDERR, stderr_file, "/dev/null"); -#endif - -#if !defined(MACOS) - case OPT_FORK_STDIO: - if (options->not) - { - options->not = 0; - case OPT_FORK_STDIO | ARG_NOT: - options->stdin_fork = options->stdout_fork = options->stderr_fork = 0; - break; - } - else if (!arg) - options->stdin_fork = options->stdout_fork = options->stderr_fork = 1; - else - { - int i; - - options->stdin_fork = options->stdout_fork = options->stderr_fork = 0; - - for (i = 0; arg[i]; i++) - switch(arg[i]) - { - case 'i': case 'I': - options->stdin_fork = 1; - break; - case 'o': case 'O': - options->stdout_fork = 1; - break; - case 'e': case 'E': - options->stderr_fork = 1; - break; - default: - argp_error(state, "The argument to --cvs-workaround should " - "be one or more of the characters 'i' (stdin), " - "'o' (stdout) and 'e' (stderr)."); - goto loop_done; - } - loop_done: - ; - } - break; -#endif - - case 'n': - options->not = !options->not; - break; - } - return 0; -} - -const struct argp client_argp = -{ - client_options, - client_argp_parser, - NULL, NULL, NULL, NULL, NULL -}; diff --git a/lsh/src/client.c.x b/lsh/src/client.c.x deleted file mode 100755 index 7f7fe92..0000000 Binary files a/lsh/src/client.c.x and /dev/null differ diff --git a/lsh/src/client.h b/lsh/src/client.h deleted file mode 100755 index 95fb1f9..0000000 --- a/lsh/src/client.h +++ /dev/null @@ -1,193 +0,0 @@ -/* client.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000, 2001 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CLIENT_H_INCLUDED -#define LSH_CLIENT_H_INCLUDED - -#include "channel_commands.h" -#include "io.h" -#include "keyexchange.h" - -#define GABA_DECLARE -#include "client.h.x" -#undef GABA_DECLARE - -/* The argp option group for actions. */ -#define CLIENT_ARGP_ACTION_GROUP 100 -#define CLIENT_ARGP_MODIFIER_GROUP 200 - -struct packet_handler * -make_accept_service_handler(UINT32 service, - struct command_continuation *c, - struct exception_handler *e); - -/* GABA: - (class - (name request_service) - (super command) - (vars - (service . int))) -*/ - -void -do_request_service(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e); - -#define STATIC_REQUEST_SERVICE(service) \ -{ STATIC_COMMAND(do_request_service), service } - -struct command *make_request_service(int service); - -/* GABA: - (class - (name escape_info) - (vars - (escape . UINT8) - ; Handlers, indexed by character. - (dispatch array (object lsh_callback) "0x100"))) -*/ - -struct escape_info *make_escape_info(UINT8 escape); -struct abstract_write * -make_handle_escape(struct escape_info *info, struct abstract_write *next); - -struct channel_request *make_handle_exit_status(int *exit_code); -struct channel_request *make_handle_exit_signal(int *exit_code); - -struct command *make_open_session_command(struct ssh_channel *session); - - -extern struct channel_request_command request_shell; -#define REQUEST_SHELL (&request_shell.super.super) - -extern struct command client_io; -#define CLIENT_START_IO (&client_io.super) - -struct ssh_channel * -make_client_session_channel(struct lsh_fd *in, - struct lsh_fd *out, - struct lsh_fd *err, - struct escape_info *escape, - UINT32 initial_window, - int *exit_status); - -struct command * -make_exec_request(struct lsh_string *command); - -struct command * -make_pty_request(struct interact *tty); - - -struct channel_open * -make_channel_open_x11(struct io_backend *backend); - -struct command * -make_forward_x11(const char *display_string, - struct randomness *random); - -struct client_x11_display * -make_client_x11_display(const char *display, struct lsh_string *fake); - -/* GABA: - (class - (name client_options) - (vars - (backend object io_backend) - - ;; Used only by lsh, NULL for lshg. - (random object randomness_with_poll) - - (tty object interact) - - ; -1 means default. - (escape . int) - - ; For i/o exceptions - (handler object exception_handler) - - (exit_code . "int *") - - (not . int) - (port . "char *") - (remote object address_info) - - (local_user . "char *") - (user . "char *") - - (with_remote_peers . int) - - ; -1 means default behaviour - (with_pty . int) - - (with_x11 . int) - - ; Session modifiers - (stdin_file . "const char *") - (stdout_file . "const char *") - (stderr_file . "const char *") - - ; fork() extra processes for handling stdio file-descriptors, - ; to avoid setting them in non-blocking mode. - (stdin_fork . int) - (stdout_fork . int) - (stderr_fork . int) - - ; True if the process's stdin or pty (respectively) has been used. - (used_stdin . int) - (used_pty . int) - (used_x11 . int) - - (start_shell . int) - (remote_forward . int) - (actions struct object_queue))) -*/ - -void -init_client_options(struct client_options *options, - struct io_backend *backend, - struct randomness_with_poll *random, - struct exception_handler *handler, - int *exit_code); - -struct command * -client_add_action(struct client_options *options, - struct command *action); - -int -client_parse_forward_arg(char *arg, - UINT32 *listen_port, - struct address_info **target); - -extern struct command client_options2remote; -#define OPTIONS2REMOTE (&client_options2remote.super) - -extern struct command client_options2actions; -#define OPTIONS2ACTIONS (&client_options2actions.super) - -extern const struct argp client_argp; - -#endif /* LSH_CLIENT_H_INCLUDED */ diff --git a/lsh/src/client.h.x b/lsh/src/client.h.x deleted file mode 100755 index 0f9f2aa..0000000 Binary files a/lsh/src/client.h.x and /dev/null differ diff --git a/lsh/src/client_escape.c b/lsh/src/client_escape.c deleted file mode 100644 index f6619fa..0000000 --- a/lsh/src/client_escape.c +++ /dev/null @@ -1,236 +0,0 @@ -/* client_escape.h - * - * Escape char handling. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000, 2001 Niels Möller - * - * 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 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 should 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 - */ - -#include "client.h" - -#include "format.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -/* This must be defined before including the .x file. */ - -enum escape_state { GOT_NONE, GOT_NEWLINE, GOT_ESCAPE }; - -#include "client_escape.c.x" - -struct escape_info * -make_escape_info(UINT8 escape) -{ - NEW(escape_info, self); - unsigned i; - - self->escape = escape; - - for (i = 0; i<0x100; i++) - self->dispatch[i] = NULL; - - return self; -} - -/* GABA: - (class - (name escape_handler) - (super abstract_write_pipe) - (vars - (info object escape_info) - ; Number of characters of the prefix NL escape - ; that have been read. - (state . "enum escape_state"))) -*/ - -static inline int -newlinep(UINT8 c) -{ - return (c == '\n') || (c == '\r'); -} - -/* Search for NEWLINE ESCAPE, starting at pos. If successful, returns - * 1 and returns the index of the escape char. Otherwise, returns - * zero. */ -static UINT32 -scan_escape(struct lsh_string *packet, UINT32 pos, UINT8 escape) -{ - for ( ; (pos + 2) <= packet->length; pos++) - { - if (newlinep(packet->data[pos]) - && (packet->data[pos+1] == escape)) - return pos + 1; - } - return 0; -} - -/* Returns 1 for the quote action. */ -static int -escape_dispatch(struct escape_info *info, - UINT8 c) -{ - struct lsh_callback *f; - - if (c == info->escape) - return 1; - - f = info->dispatch[c]; - if (f) - LSH_CALLBACK(f); - else - werror(" `%pc' not defined.\n", c); - - return 0; -} - -static void -do_escape_handler(struct abstract_write *s, struct lsh_string *packet) -{ - CAST(escape_handler, self, s); - UINT32 pos; - UINT32 done; - -#if 0 - trace("do_escape_handler: state = %i, packet length = %i\n", - self->state, packet->length); -#endif - - if (!packet) - { - /* EOF. Pass it on */ - A_WRITE(self->super.next, packet); - return; - } - - assert(packet->length); - - /* done is the length of the prefix of the data that is already - * consumed in one way or the other, while pos is the next position - * where it makes sense to look for the escape sequence. */ - done = pos = 0; - - /* Look for an escape at the start of the packet. */ - switch (self->state) - { - case GOT_NEWLINE: - /* We already got newline. Is the next character the escape? */ - if (packet->data[0] == self->info->escape) - { - if (packet->length == 1) - { - self->state = GOT_ESCAPE; - lsh_string_free(packet); - return; - } - else - { - pos = 2; - if (escape_dispatch(self->info, packet->data[1])) - /* The quote action. Keep the escape. */ - done = 1; - else - done = 2; - } - } - break; - case GOT_ESCAPE: - pos = 1; - if (escape_dispatch(self->info, packet->data[0])) - /* The quote action. Keep the escape. */ - done = 0; - else - done = 1; - - break; - - case GOT_NONE: - /* No special processing needed. */ - break; - } - - while ( (pos = scan_escape(packet, pos, self->info->escape)) ) - { - /* We found another escape char! */ - - /* First, pass on the data before the escape. */ - assert(pos > done); - A_WRITE(self->super.next, - ssh_format("%ls", pos - done, packet->data + done)); - - /* Point to the action character. */ - pos++; - if (pos == packet->length) - { - /* Remember how far we got. */ - self->state = GOT_ESCAPE; - lsh_string_free(packet); - return; - } - if (escape_dispatch(self->info, packet->data[pos])) - /* Keep escape */ - done = pos; - else - done = pos + 1; - pos++; - } - - /* Handle any data after the final escape */ - if (done < packet->length) - { - /* Rember if the last character is a newline. */ - if (newlinep(packet->data[packet->length - 1])) - self->state = GOT_NEWLINE; - else - self->state = GOT_NONE; - - /* Send data on */ - if (done) - { - /* Partial packet */ - A_WRITE(self->super.next, - ssh_format("%ls", packet->length - done, - packet->data + done)); - lsh_string_free(packet); - } - else - A_WRITE(self->super.next, packet); - } - else - { - self->state = GOT_NONE; - lsh_string_free(packet); - } -} - -struct abstract_write * -make_handle_escape(struct escape_info *info, struct abstract_write *next) -{ - NEW(escape_handler, self); - - self->super.super.write = do_escape_handler; - self->super.next = next; - self->info = info; - self->state = GOT_NONE; - - return &self->super.super; -} diff --git a/lsh/src/client_escape.c.x b/lsh/src/client_escape.c.x deleted file mode 100644 index b9c979b..0000000 --- a/lsh/src/client_escape.c.x +++ /dev/null @@ -1,32 +0,0 @@ -/* -CLASS:escape_handler:abstract_write_pipe -*/ -#ifndef GABA_DEFINE -struct escape_handler -{ - struct abstract_write_pipe super; - struct escape_info *info; - enum escape_state state; -}; -extern struct lsh_class escape_handler_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_escape_handler_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct escape_handler *i = (struct escape_handler *) o; - mark((struct lsh_object *) i->info); -} -struct lsh_class escape_handler_class = -{ - STATIC_HEADER, - &(abstract_write_pipe_class), - "escape_handler", - sizeof(struct escape_handler), - do_escape_handler_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - diff --git a/lsh/src/client_keyexchange.c b/lsh/src/client_keyexchange.c deleted file mode 100755 index 803ff5f..0000000 --- a/lsh/src/client_keyexchange.c +++ /dev/null @@ -1,357 +0,0 @@ -/* client_keyexchange.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "client_keyexchange.h" - -#include "atoms.h" -#include "command.h" -#include "debug.h" -#include "dsa.h" -#include "format.h" -#include "lookup_verifier.h" - -#include "srp.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "client_keyexchange.c.x" - -/* GABA: - (class - (name dh_client_exchange) - (super keyexchange_algorithm) - (vars - (dh object dh_method))) -*/ - -/* Handler for the kex_dh_reply message */ -/* GABA: - (class - (name dh_client) - (super packet_handler) - (vars - (dh struct dh_instance) - (hostkey_algorithm . int) - (verifier object lookup_verifier) - (algorithms object object_list))) -*/ - -static void -do_handle_dh_reply(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(dh_client, closure, c); - struct lsh_string *server_key; - int algorithm; - struct lsh_string *signature; - struct verifier *v; - int res; - - trace("handle_dh_reply\n"); - - server_key = dh_process_server_msg(&closure->dh, &signature, packet); - - if (!server_key) - { - disconnect_kex_failed(connection, "Bad dh-reply\r\n"); - return; - } - - v = LOOKUP_VERIFIER(closure->verifier, closure->hostkey_algorithm, - NULL, server_key); - lsh_string_free(server_key); - - if (!v) - { - /* FIXME: Use a more appropriate error code? */ - disconnect_kex_failed(connection, "Bad server host key\r\n"); - lsh_string_free(signature); - return; - } - -#if DATAFELLOWS_WORKAROUNDS - if (closure->hostkey_algorithm == ATOM_SSH_DSS && - (connection->peer_flags & PEER_SSH_DSS_KLUDGE)) - { - algorithm = ATOM_SSH_DSS_KLUDGE_LOCAL; - } - else -#endif - algorithm = closure->hostkey_algorithm; - - res = VERIFY(v, algorithm, - closure->dh.exchange_hash->length, closure->dh.exchange_hash->data, - signature->length, signature->data); - lsh_string_free(signature); - - if (!res) - { - werror("Invalid server signature. Disconnecting.\n"); - /* FIXME: Use a more appropriate error code? */ - disconnect_kex_failed(connection, "Invalid server signature\r\n"); - return; - } - - /* Key exchange successful! */ - - connection->dispatch[SSH_MSG_KEXDH_REPLY] = &connection_fail_handler; - - keyexchange_finish(connection, closure->algorithms, - closure->dh.method->H, - closure->dh.exchange_hash, - closure->dh.K); - - /* For gc */ - closure->dh.K = NULL; - closure->dh.exchange_hash = NULL; -} - -static void -do_init_client_dh(struct keyexchange_algorithm *c, - struct ssh_connection *connection, - int hostkey_algorithm_atom, - struct lsh_object *extra, - struct object_list *algorithms) -{ - CAST(dh_client_exchange, closure, c); - CAST_SUBTYPE(lookup_verifier, verifier, extra); - - NEW(dh_client, dh); - - assert(verifier); - - /* Initialize */ - dh->super.handler = do_handle_dh_reply; - init_dh_instance(closure->dh, &dh->dh, connection); - - dh->verifier = verifier; - dh->hostkey_algorithm = hostkey_algorithm_atom; - - dh->algorithms = algorithms; - - /* Send client's message */ - C_WRITE(connection, dh_make_client_msg(&dh->dh)); - - /* Install handler */ - connection->dispatch[SSH_MSG_KEXDH_REPLY] = &dh->super; -} - - -struct keyexchange_algorithm * -make_dh_client(struct dh_method *dh) -{ - NEW(dh_client_exchange, self); - - self->super.init = do_init_client_dh; - self->dh = dh; - - return &self->super; -} - - -#if WITH_SRP -/* SRP key exchange */ - -/* GABA: - (class - (name srp_client_instance) - (vars - (dh struct dh_instance) - (tty object interact) - (name string) - (m2 string) - (algorithms object object_list))) -*/ - -/* GABA: - (class - (name srp_client_handler) - (super packet_handler) - (vars - (srp object srp_client_instance))) -*/ - -static void -do_srp_client_proof_handler(struct packet_handler *s, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(srp_client_handler, self, s); - - int res = srp_process_server_proof(self->srp->m2, - packet); - - connection->dispatch[SSH_MSG_KEXSRP_PROOF] = &connection_fail_handler; - - if (res) - { - connection->flags |= CONNECTION_SRP; - - keyexchange_finish(connection, self->srp->algorithms, - self->srp->dh.method->H, - self->srp->dh.exchange_hash, - self->srp->dh.K); - - /* For gc */ - self->srp->dh.K = NULL; - self->srp->dh.exchange_hash = NULL; - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_KEXSRP_PROOF message"); - - /* Try to purge information about the key exchange */ - KILL(self->srp); - KILL(self); -} - -static struct packet_handler * -make_srp_client_proof_handler(struct srp_client_instance *srp) -{ - NEW(srp_client_handler, self); - self->super.handler = do_srp_client_proof_handler; - self->srp = srp; - - return &self->super; -} - -#define MAX_PASSWD 100 - -static void -do_handle_srp_reply(struct packet_handler *s, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(srp_client_handler, self, s); - struct lsh_string *salt = srp_process_reply_msg(&self->srp->dh, packet); - struct lsh_string *passwd; - struct lsh_string *response; - - mpz_t x; - - connection->dispatch[SSH_MSG_KEXSRP_REPLY] = &connection_fail_handler; - - if (!salt) - { - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_KEXSRP_REPLY message"); - return; - } - - /* Ask for SRP password */ - passwd = INTERACT_READ_PASSWORD(self->srp->tty, MAX_PASSWD, - ssh_format("SRP password for %lS: ", - self->srp->name), 1); - if (!passwd) - { - lsh_string_free(salt); - disconnect_kex_failed(connection, "Bye"); - } - - mpz_init(x); - srp_hash_password(x, self->srp->dh.method->H, - salt, self->srp->name, - passwd); - - lsh_string_free(salt); - lsh_string_free(passwd); - - response = srp_make_client_proof(&self->srp->dh, &self->srp->m2, x); - mpz_clear(x); - - if (!response) - PROTOCOL_ERROR(connection->e, - "SRP failure: Invalid public value from server."); - - C_WRITE(connection, response); - - connection->dispatch[SSH_MSG_KEXSRP_PROOF] - = make_srp_client_proof_handler(self->srp); -} - -static struct packet_handler * -make_srp_reply_handler(struct srp_client_instance *srp) -{ - NEW(srp_client_handler, self); - self->super.handler = do_handle_srp_reply; - self->srp = srp; - - return &self->super; -} - -/* GABA: - (class - (name srp_client_exchange) - (super keyexchange_algorithm) - (vars - (dh object dh_method) - (tty object interact) - (name string))) -*/ - -static void -do_init_client_srp(struct keyexchange_algorithm *s, - struct ssh_connection *connection, - int hostkey_algorithm_atom UNUSED, - struct lsh_object *extra UNUSED, - struct object_list *algorithms) -{ - CAST(srp_client_exchange, self, s); - - NEW(srp_client_instance, srp); - - /* Initialize */ - init_dh_instance(self->dh, &srp->dh, connection); - - srp->tty = self->tty; - srp->algorithms = algorithms; - srp->name = self->name; - srp->m2 = NULL; - - /* Send client's message */ - C_WRITE(connection, srp_make_init_msg(&srp->dh, self->name)); - - /* Install handler */ - connection->dispatch[SSH_MSG_KEXSRP_REPLY] = make_srp_reply_handler(srp); -} - -struct keyexchange_algorithm * -make_srp_client(struct dh_method *dh, struct interact *tty, - struct lsh_string *name) -{ - NEW(srp_client_exchange, self); - - assert(dh->G->add); - assert(dh->G->subtract); - - self->super.init = do_init_client_srp; - self->dh = dh; - self->tty = tty; - self->name = name; - - return &self->super; -} - -#endif /* WITH_SRP */ diff --git a/lsh/src/client_keyexchange.c.x b/lsh/src/client_keyexchange.c.x deleted file mode 100755 index 3eb66b3..0000000 Binary files a/lsh/src/client_keyexchange.c.x and /dev/null differ diff --git a/lsh/src/client_keyexchange.h b/lsh/src/client_keyexchange.h deleted file mode 100755 index a80f79b..0000000 --- a/lsh/src/client_keyexchange.h +++ /dev/null @@ -1,40 +0,0 @@ -/* client_keyexchange.h - * - * Client specific key exchange handling - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CLIENT_KEYEXCHANGE_H_INCLUDED -#define LSH_CLIENT_KEYEXCHANGE_H_INCLUDED - -#include "interact.h" -#include "keyexchange.h" -#include "publickey_crypto.h" - -struct keyexchange_algorithm * -make_dh_client(struct dh_method *dh); - -struct keyexchange_algorithm * -make_srp_client(struct dh_method *dh, - struct interact *tty, struct lsh_string *name); - -#endif /* LSH_CLIENT_KEYEXCHANGE_H_INCLUDED */ diff --git a/lsh/src/client_pty.c b/lsh/src/client_pty.c deleted file mode 100755 index 833d527..0000000 --- a/lsh/src/client_pty.c +++ /dev/null @@ -1,222 +0,0 @@ -/* client_pty.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, Niels Möller, Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "client.h" - -#include "channel_commands.h" -#include "format.h" -#include "interact.h" -#include "tty.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "client_pty.c.x" - -/* GABA: - (class - (name pty_request) - (super channel_request_command) - (vars - (tty object interact) - (term string) - (attr object terminal_attributes) - (dims . "struct terminal_dimensions"))) -*/ - -/* GABA: - (class - (name client_tty_resource) - (super resource) - (vars - (tty object interact) - (attr object terminal_attributes))) -*/ - -static void -do_kill_client_tty_resource(struct resource *s) -{ - CAST(client_tty_resource, self, s); - self->super.alive = 0; - INTERACT_SET_ATTRIBUTES(self->tty, self->attr); -} - -static struct resource * -make_client_tty_resource(struct interact *tty, - struct terminal_attributes *attr) -{ - NEW(client_tty_resource, self); - init_resource(&self->super, do_kill_client_tty_resource); - - self->tty = tty; - self->attr = attr; - - return &self->super; -} - -/* GABA: - (class - (name client_winch_handler) - (super window_change_callback) - (vars - (channel object ssh_channel))) -*/ - -static struct lsh_string * -format_window_change(struct ssh_channel *channel, - struct terminal_dimensions *dims) -{ - return format_channel_request - (ATOM_WINDOW_CHANGE, channel, - 0, "%i%i%i%i", - dims->char_width, dims->char_height, - dims->pixel_width, dims->pixel_height); -} - -static void -do_client_winch_handler(struct window_change_callback *s, - struct interact *tty) -{ - CAST(client_winch_handler, self, s); - struct terminal_dimensions dims; - - if (!INTERACT_WINDOW_SIZE(tty, &dims)) - return; - - C_WRITE(self->channel->connection, - format_window_change(self->channel, &dims)); -} - -static struct window_change_callback * -make_client_winch_handler(struct ssh_channel *channel) -{ - NEW(client_winch_handler, self); - self->super.f = do_client_winch_handler; - self->channel = channel; - - return &self->super; -} - - -/* GABA: - (class - (name pty_request_continuation) - (super command_frame) - (vars - (req object pty_request))) -*/ - -/* FIXME: !!! failed requests show up as an exception. /Bazsi - * - * I think that is normal. It's up to the caller to do something reasonable - * about the exception. /nisse - */ -static void -do_pty_continuation(struct command_continuation *s, - struct lsh_object *x) -{ - CAST(pty_request_continuation, self, s); - CAST_SUBTYPE(ssh_channel, channel, x); - struct terminal_attributes *raw; - - assert(x); - verbose("pty request succeeded\n"); - - raw = TERM_MAKE_RAW(self->req->attr); - if (!INTERACT_SET_ATTRIBUTES(self->req->tty, raw)) - { - werror("do_pty_continuation: " - "Setting the attributes of the local terminal failed.\n"); - } - - REMEMBER_RESOURCE(channel->resources, - make_client_tty_resource(self->req->tty, - self->req->attr)); - - REMEMBER_RESOURCE(channel->resources, - INTERACT_WINDOW_SUBSCRIBE - (self->req->tty, - make_client_winch_handler(channel))); - - COMMAND_RETURN(self->super.up, x); -} - -static struct command_continuation * -make_pty_continuation(struct pty_request *req, - struct command_continuation *c) -{ - NEW(pty_request_continuation, self); - self->req = req; - self->super.up = c; - self->super.super.c = do_pty_continuation; - - return &self->super.super; -} - -static struct lsh_string * -do_format_pty_request(struct channel_request_command *s, - struct ssh_channel *channel, - struct command_continuation **c) -{ - CAST(pty_request, self, s); - - verbose("Requesting a remote pty.\n"); - - *c = make_pty_continuation(self, *c); - - return format_channel_request - (ATOM_PTY_REQ, channel, 1, - "%S%i%i%i%i%fS", - self->term, - self->dims.char_width, self->dims.char_height, - self->dims.pixel_width, self->dims.pixel_height, - TERM_ENCODE(self->attr)); -} - -struct command * -make_pty_request(struct interact *tty) -{ - NEW(pty_request, req); - char *term = getenv("TERM"); - - req->attr = INTERACT_GET_ATTRIBUTES(tty); - - if (!req->attr) - { - KILL(req); - return NULL; - } - - if (!INTERACT_WINDOW_SIZE(tty, &req->dims)) - req->dims.char_width = req->dims.char_height - = req->dims.pixel_width = req->dims.pixel_height = 0; - - req->super.super.call = do_channel_request_command; - req->super.format_request = do_format_pty_request; - - req->tty = tty; - req->term = term ? make_string(term) : ssh_format(""); - - return &req->super.super; -} diff --git a/lsh/src/client_pty.c.x b/lsh/src/client_pty.c.x deleted file mode 100755 index d5b4611..0000000 Binary files a/lsh/src/client_pty.c.x and /dev/null differ diff --git a/lsh/src/client_session.c b/lsh/src/client_session.c deleted file mode 100755 index 923d9fb..0000000 --- a/lsh/src/client_session.c +++ /dev/null @@ -1,228 +0,0 @@ -/* client_session.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "client.h" - -#include "channel_commands.h" -#include "client.h" -#include "io.h" -#include "read_data.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "client_session.c.x" - -/* Initiate and manage a session */ -/* GABA: - (class - (name client_session_channel) - (super ssh_channel) - (vars - ; To access stdio - (in object lsh_fd) - (out object lsh_fd) - (err object lsh_fd) - - ; Escape char handling - (escape object escape_info) - ; Where to save the exit code. - (exit_status . "int *"))) -*/ - -/* Callback used when the server sends us eof */ - -/* FIXME: Perhaps unify with server_session.c:do_eof */ -static void -do_client_session_eof(struct ssh_channel *c) -{ - CAST(client_session_channel, session, c); - - close_fd_nicely(session->out); - close_fd_nicely(session->err); -} - -static void -do_client_session_close(struct ssh_channel *c) -{ - static const struct exception finish_exception - = STATIC_EXCEPTION(EXC_FINISH_PENDING, "Session closed."); - - EXCEPTION_RAISE(c->e, &finish_exception); -} - - -/* Receive channel data */ -static void -do_receive(struct ssh_channel *c, - int type, struct lsh_string *data) -{ - CAST(client_session_channel, closure, c); - - switch(type) - { - case CHANNEL_DATA: - A_WRITE(&closure->out->write_buffer->super, data); - break; - case CHANNEL_STDERR_DATA: - A_WRITE(&closure->err->write_buffer->super, data); - break; - default: - fatal("Internal error!\n"); - } -} - -/* We may send more data */ -static void -do_send_adjust(struct ssh_channel *s, - UINT32 i UNUSED) -{ - CAST(client_session_channel, self, s); - - assert(self->in->read); - - self->in->want_read = 1; -} - -/* Escape char handling */ - -static struct io_callback * -client_read_stdin(struct client_session_channel *session) -{ - struct abstract_write *write = make_channel_write(&session->super); - - if (session->escape) - write = make_handle_escape(session->escape, write); - - return make_read_data(&session->super, write); -} - -/* We have a remote shell */ -static void -do_client_io(struct command *s UNUSED, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) - -{ - CAST(client_session_channel, session, x); - struct ssh_channel *channel = &session->super; - assert(x); - - /* Set up write fd:s. */ - - channel->receive = do_receive; - - /* FIXME: It seems a little kludgy to modify - * exception handlers here; it would be better to create the - * fd-objects at a point where the right exception handlers can be - * installed from the start. */ - session->out->e - = make_channel_io_exception_handler(channel, - "lsh: I/O error on stdout", - session->out->e, - HANDLER_CONTEXT); - - session->err->e - = make_channel_io_exception_handler(channel, - "lsh: I/O error on stderr", - session->err->e, - HANDLER_CONTEXT); - - /* Set up the fd we read from. */ - channel->send_adjust = do_send_adjust; - - /* Setup escape char handler, if appropriate. */ - session->in->read = client_read_stdin(session); - - /* FIXME: Perhaps there is some way to arrange that channel.c calls - * the CHANNEL_SEND_ADJUST method instead? */ - if (session->super.send_window_size) - session->in->want_read = 1; - - session->in->close_callback - = make_channel_read_close_callback(channel); - - /* Make sure stdio is closed properly if the channel or connection dies */ - REMEMBER_RESOURCE(channel->resources, &session->in->super); - REMEMBER_RESOURCE(channel->resources, &session->out->super); - REMEMBER_RESOURCE(channel->resources, &session->err->super); - - ALIST_SET(channel->request_types, ATOM_EXIT_STATUS, - &make_handle_exit_status(session->exit_status)->super); - ALIST_SET(channel->request_types, ATOM_EXIT_SIGNAL, - &make_handle_exit_signal(session->exit_status)->super); - - channel->eof = do_client_session_eof; - - COMMAND_RETURN(c, channel); -} - -struct command client_io = -{ STATIC_HEADER, do_client_io }; - - -struct ssh_channel * -make_client_session_channel(struct lsh_fd *in, - struct lsh_fd *out, - struct lsh_fd *err, - struct escape_info *escape, - UINT32 initial_window, - int *exit_status) -{ - NEW(client_session_channel, self); - - init_channel(&self->super); - - /* Makes sure the pending_close bit is set whenever this session - * dies, no matter when or how. */ - self->super.close = do_client_session_close; - - self->super.rec_window_size = initial_window; - - /* FIXME: Make maximum packet size configurable */ - self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ; - - self->super.request_types = make_alist(0, -1); - - /* self->expect_close = 0; */ - self->in = in; - self->out = out; - self->err = err; - self->escape = escape; - - REMEMBER_RESOURCE(self->super.resources, &in->super); - REMEMBER_RESOURCE(self->super.resources, &out->super); - REMEMBER_RESOURCE(self->super.resources, &err->super); - - /* Flow control */ - out->write_buffer->report = &self->super.super; - err->write_buffer->report = &self->super.super; - - self->exit_status = exit_status; - - return &self->super; -} diff --git a/lsh/src/client_session.c.x b/lsh/src/client_session.c.x deleted file mode 100755 index 2654129..0000000 Binary files a/lsh/src/client_session.c.x and /dev/null differ diff --git a/lsh/src/client_userauth.c b/lsh/src/client_userauth.c deleted file mode 100755 index f72ae4e..0000000 --- a/lsh/src/client_userauth.c +++ /dev/null @@ -1,980 +0,0 @@ -/* client_userauth.c - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "client_userauth.h" - -#include "charset.h" -#include "command.h" -#include "format.h" -#include "parse.h" -#include "publickey_crypto.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Forward declaration */ -struct client_userauth; - -#include "client_userauth.c.x" - -static struct lsh_string * -format_userauth_none(struct lsh_string *name, - int service) -{ - return ssh_format("%c%S%a%a", - SSH_MSG_USERAUTH_REQUEST, - name, - service, - ATOM_NONE); -} - -/* The last parameters says whether or not to free the password. */ -struct lsh_string * -format_userauth_password(struct lsh_string *name, - int service, - struct lsh_string *passwd, - int free) -{ - return ssh_format(free ? "%c%S%a%a%c%fS" : "%c%S%a%a%c%S", - SSH_MSG_USERAUTH_REQUEST, - name, - service, - ATOM_PASSWORD, - 0, - passwd); -} - -static struct lsh_string * -format_userauth_publickey_query(struct lsh_string *name, - UINT32 service, - UINT32 keytype, - struct lsh_string *public) -{ - return ssh_format("%c%S%a%a%c%a%S", - SSH_MSG_USERAUTH_REQUEST, - name, - service, - ATOM_PUBLICKEY, - 0, - keytype, - public); -} - -static struct lsh_string * -format_userauth_publickey(struct lsh_string *name, - UINT32 service, - UINT32 keytype, - struct lsh_string *public) -{ - return ssh_format("%c%S%a%a%c%a%S", - SSH_MSG_USERAUTH_REQUEST, - name, - service, - ATOM_PUBLICKEY, - 1, - keytype, - public); -} - -/* Called when we receive a USERAUTH_FAILURE message. It will - * typically either try again, or raise EXC_USERAUTH. */ - -/* GABA: - (class - (name client_userauth_failure) - (vars - ; again is true if the server says that - ; the current method is still useful. - (failure method void "int again"))) -*/ - -#define CLIENT_USERAUTH_FAILURE(f, c) ((f)->failure((f), (c))) - -/* Almost like a command, but returns a failure handler. */ -/* GABA: - (class - (name client_userauth_method) - (vars - (type . int) - (login method (object client_userauth_failure) - "struct client_userauth *u" - "struct ssh_connection *c" - "struct exception_handler *e"))) -*/ - -#define CLIENT_USERAUTH_LOGIN(m, u, c, e) \ - ((m)->login((m), (u), (c), (e))) - -/* Takes a connection as argument, and attempts to login. It does this - * by trying each METHOD in turn. As soon as one succeeds, the - * connection is returned. When a method fails (raising a EXC_USERAUTH - * exception), we try the next method. If all methods fail, we raise - * EXC_USERAUTH. */ - -/* GABA: - (class - (name client_userauth) - (super command) - (vars - ; The name should already be converted to utf8 - (username string) ; Remote user name to authenticate as. - (service_name . int) ; Service we want to access. - (methods object object_list) ; Authentication methods, in order. - )) -*/ - -/* GABA: - (class - (name client_userauth_state) - (vars - (userauth object client_userauth) - (connection object ssh_connection) - (failure object client_userauth_failure) - - ; Current method - (current . unsigned) - - ; The next method that the server has indicated is useful. - (next . unsigned))) -*/ - -static struct client_userauth_state * -make_client_userauth_state(struct client_userauth *userauth, - struct ssh_connection *connection) -{ - NEW(client_userauth_state, self); - - trace("client_userauth.c: make_client_userauth_state\n"); - self->connection = connection; - self->userauth = userauth; - self->failure = NULL; - self->current = 0; - self->next = 1; - - return self; -} - -/* GABA: - (class - (name userauth_packet_handler) - (super packet_handler) - (vars - (state object client_userauth_state))) -*/ - - -/* GABA: - (class - (name userauth_success_handler) - (super packet_handler) - (vars - (c object command_continuation))) -*/ - -static void -do_userauth_success(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(userauth_success_handler, self, c); - struct simple_buffer buffer; - - unsigned msg_number; - - trace("client_userauth.c: do_userauth_success\n"); - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_SUCCESS) - && parse_eod(&buffer)) - { - unsigned i; - - verbose("User authentication successful.\n"); - - for (i = SSH_FIRST_USERAUTH_GENERIC; i < SSH_FIRST_CONNECTION_GENERIC; i++) - connection->dispatch[i] = &connection_fail_handler; - - COMMAND_RETURN(self->c, connection); - } - else - PROTOCOL_ERROR(connection->e, "Invalid USERAUTH_SUCCESS message"); -} - -static struct packet_handler * -make_success_handler(struct command_continuation *c) -{ - NEW(userauth_success_handler, self); - - self->super.handler = do_userauth_success; - self->c = c; - - return &self->super; -} - - -/* GABA: - (class - (name failure_handler) - (super userauth_packet_handler) - (vars - (e object exception_handler))) -*/ - - -/* Arbitrary limit on list length */ -#define USERAUTH_MAX_METHODS 47 - -static int -userauth_method_is_useful(struct client_userauth *userauth, - struct int_list *advertised, - unsigned n) -{ - CAST_SUBTYPE(client_userauth_method, method, - LIST(userauth->methods)[n]); - - unsigned i; - -#if 0 - debug("userauth_method_is_useful, advertised:\n"); - for(i = 0; i < LIST_LENGTH(advertised); i++) - debug(" %a\n", LIST(advertised)[i]); - - debug(" method: type = %a, class = %t\n", method->type, method); -#endif - - for(i = 0; i < LIST_LENGTH(advertised); i++) - if (LIST(advertised)[i] == method->type) - return 1; - - return 0; -} - -static void -do_userauth_failure(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(userauth_packet_handler, self, c); - struct simple_buffer buffer; - - unsigned msg_number; - struct int_list *methods = NULL; - int partial_success; - - trace("client_userauth.c: do_userauth_failure\n"); - assert(self->state->current < self->state->next); - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_FAILURE) - && ( (methods = parse_atom_list(&buffer, USERAUTH_MAX_METHODS)) ) - && parse_boolean(&buffer, &partial_success) - && parse_eod(&buffer)) - { - if (partial_success) - /* Doesn't help us */ - werror("Received SSH_MSH_USERAUTH_FAILURE " - "indicating partial success.\n"); - - while ( (self->state->next < LIST_LENGTH(self->state->userauth->methods)) - && !userauth_method_is_useful(self->state->userauth, - methods, self->state->next)) - self->state->next++; - - CLIENT_USERAUTH_FAILURE(self->state->failure, - userauth_method_is_useful(self->state->userauth, - methods, self->state->current)); - } - else - PROTOCOL_ERROR(connection->e, "Invalid USERAUTH_FAILURE message."); - - KILL(methods); -} - -static struct packet_handler * -make_failure_handler(struct client_userauth_state *state) -{ - NEW(userauth_packet_handler, self); - - trace("client_userauth.c: make_failure_handler\n"); - - self->super.handler = do_userauth_failure; - self->state = state; - - return &self->super; -} - -static void -do_userauth_banner(struct packet_handler *self UNUSED, - struct ssh_connection *connection UNUSED, - struct lsh_string *packet) -{ - struct simple_buffer buffer; - - unsigned msg_number; - UINT32 length; - const UINT8 *msg; - - UINT32 language_length; - const UINT8 *language; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_BANNER) - && parse_string(&buffer, &length, &msg) - && parse_string(&buffer, &language_length, &language) - && parse_eod(&buffer)) - { - /* Ignore language tag */ - werror("%ups", length, msg); - } - else - PROTOCOL_ERROR(connection->e, "Invalid USERAUTH_SUCCESS message"); -} - -static struct packet_handler userauth_banner_handler = -{ STATIC_HEADER, do_userauth_banner }; - - -/* GABA: - (class - (name exc_client_userauth) - (super exception_handler) - (vars - (state object client_userauth_state))) -*/ - -/* Skip to the next useful userauth method, or reraise the exception - * if there are no more methods to try. */ - -static void -do_exc_client_userauth(struct exception_handler *s, - const struct exception *e) -{ - CAST(exc_client_userauth, self, s); - - trace("client_userauth.c: do_exc_client_userauth\n"); - assert(self->state->current < self->state->next); - - if ( (e->type == EXC_USERAUTH) - && (self->state->next < LIST_LENGTH(self->state->userauth->methods))) - { - self->state->current = self->state->next++; - { - CAST_SUBTYPE(client_userauth_method, method, - LIST(self->state->userauth->methods)[self->state->current]); - - self->state->failure - = CLIENT_USERAUTH_LOGIN(method, self->state->userauth, - self->state->connection, s); - } - } - else - EXCEPTION_RAISE(s->parent, e); -} - -static struct exception_handler * -make_exc_client_userauth(struct client_userauth_state *state, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_client_userauth, self); - - trace("client_userauth.c: make_exc_client_userauth\n"); - - self->super.parent = parent; - self->super.raise = do_exc_client_userauth; - self->super.context = context; - - self->state = state; - - return &self->super; -} - -/* GABA: - (class - (name exc_userauth_disconnect) - (super exception_handler) - (vars - (connection object ssh_connection))) -*/ - -/* Disconnects the connection if user authentication fails. */ -static void -do_exc_userauth_disconnect(struct exception_handler *s, - const struct exception *e) -{ - CAST(exc_userauth_disconnect, self, s); - - if (e->type == EXC_USERAUTH) - { - werror("User authentication failed.\n"); - EXCEPTION_RAISE(self->connection->e, - make_protocol_exception(SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, - NULL)); - } - - EXCEPTION_RAISE(s->parent, e); -} - -static struct exception_handler * -make_exc_userauth_disconnect(struct ssh_connection *connection, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_userauth_disconnect, self); - - trace("client_userauth.c: make_exc_userauth_disconnect\n"); - - self->super.parent = parent; - self->super.raise = do_exc_userauth_disconnect; - self->super.context = context; - - self->connection = connection; - return &self->super; -} - -static void -do_client_userauth(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(client_userauth, self, s); - CAST(ssh_connection, connection, x); - - struct client_userauth_state *state - = make_client_userauth_state(self, connection); - - trace("client_userauth.c: do_client_userauth\n"); - - connection->dispatch[SSH_MSG_USERAUTH_SUCCESS] - = make_success_handler(c); - connection->dispatch[SSH_MSG_USERAUTH_FAILURE] - = make_failure_handler(state); - connection->dispatch[SSH_MSG_USERAUTH_BANNER] - = &userauth_banner_handler; - - assert(LIST_LENGTH(self->methods)); - { - CAST_SUBTYPE(client_userauth_method, method, - LIST(self->methods)[0]); - state->failure - = CLIENT_USERAUTH_LOGIN(method, self, - connection, - make_exc_client_userauth - (state, - make_exc_userauth_disconnect - (connection, e, HANDLER_CONTEXT), - HANDLER_CONTEXT)); - } -} - - -struct command * -make_client_userauth(struct lsh_string *username, - int service_name, - struct object_list *methods) -{ - NEW(client_userauth, self); - - self->super.call = do_client_userauth; - self->username = local_to_utf8(username, 1); - self->service_name = service_name; - self->methods = methods; - - return &self->super; -} - - -/* None authentication */ -/* GABA: - (class - (name client_none_state) - (super client_userauth_failure) - (vars - (e object exception_handler))) -*/ - -static void -do_none_failure(struct client_userauth_failure *s, int again) -{ - CAST(client_none_state, self, s); - - static const struct exception need_auth = - STATIC_EXCEPTION(EXC_USERAUTH, "Need real authentication."); - - trace("client_userauth.c: do_none_failure\n"); - - if (again) - werror("Odd. Server says we should try the `none'authentication method again.\n"); - - EXCEPTION_RAISE(self->e, &need_auth); -} - -static struct client_userauth_failure * -make_client_none_state(struct exception_handler *e) -{ - NEW(client_none_state, self); - - trace("client_userauth.c: make_client_none_state\n"); - - self->super.failure = do_none_failure; - self->e = e; - - return &self->super; -} - -static struct client_userauth_failure * -do_none_login(struct client_userauth_method *s UNUSED, - struct client_userauth *userauth, - struct ssh_connection *connection, - struct exception_handler *e) -{ - trace("client_userauth.c: do_none_login\n"); - - C_WRITE(connection, - format_userauth_none(userauth->username, - userauth->service_name)); - - return make_client_none_state(e); -} - -static struct client_userauth_method -client_userauth_none = - { STATIC_HEADER, ATOM_NONE, do_none_login }; - -struct client_userauth_method * -make_client_none_auth(void) -{ - return &client_userauth_none; -} - - -/* Password authentication */ - -#define MAX_PASSWD 100 - -/* GABA: - (class - (name client_password_state) - (super client_userauth_failure) - (vars - (userauth object client_userauth) - (tty object interact) - ; Have we tried the empty password already? - (tried_empty_passwd . int) - (connection object ssh_connection) - (e object exception_handler))) -*/ - -static void -send_password(struct client_password_state *state) -{ - struct lsh_string *passwd - = INTERACT_READ_PASSWORD(state->tty, MAX_PASSWD, - ssh_format("Password for %lS: ", - state->userauth->username), 1); - - if (passwd) - { - /* Password empty? */ - if (!passwd->length) - { - /* NOTE: At least on some systems, the getpass function - * sets the tty to raw mode, disabling ^C, ^D and the like. - * - * To be a little friendlier, we stop asking if the users - * gives us the empty password twice. - */ - state->tried_empty_passwd++; - } - - C_WRITE(state->connection, - format_userauth_password(state->userauth->username, - state->userauth->service_name, - local_to_utf8(passwd, 1), - 1)); - } - else - { - /* If the user aborts the password dialogue (by pressing ^D at - * the terminal, or by closing a password popup window, - * whatever), read_password should return NULL, and we should - * skip to the next authentication method. */ - static const struct exception no_passwd = - STATIC_EXCEPTION(EXC_USERAUTH, "No password supplied."); - - EXCEPTION_RAISE(state->e, &no_passwd); - } -} - - -static void -do_password_failure(struct client_userauth_failure *s, int again) -{ - CAST(client_password_state, self, s); - - trace("client_userauth.c: do_password_failure\n"); - - if (again) - { - if (self->tried_empty_passwd >= 2) - { - static const struct exception no_passwd = - STATIC_EXCEPTION(EXC_USERAUTH, "No password supplied."); - - EXCEPTION_RAISE(self->e, &no_passwd); - } - else - send_password(self); - } - else - { - static const struct exception passwd_not_useful = - STATIC_EXCEPTION(EXC_USERAUTH, "password authentication not useful."); - - EXCEPTION_RAISE(self->e, &passwd_not_useful); - } -} - -static struct client_password_state * -make_client_password_state(struct client_userauth *userauth, - struct interact *tty, - struct ssh_connection *connection, - struct exception_handler *e) -{ - NEW(client_password_state, self); - - trace("client_userauth.c: make_client_password_state\n"); - - self->super.failure = do_password_failure; - self->userauth = userauth; - self->tty = tty; - self->tried_empty_passwd = 0; - self->connection = connection; - self->e = e; - - return self; -} - -/* GABA: - (class - (name client_password_method) - (super client_userauth_method) - (vars - (tty object interact))) -*/ - - -static struct client_userauth_failure * -do_password_login(struct client_userauth_method *s, - struct client_userauth *userauth, - struct ssh_connection *connection, - struct exception_handler *e) -{ - CAST(client_password_method, self, s); - - struct client_password_state *state - = make_client_password_state(userauth, self->tty, - connection, e); - - trace("client_userauth.c: do_password_login\n"); - - send_password(state); - - return &state->super; -} - -struct client_userauth_method * -make_client_password_auth(struct interact *tty) -{ - NEW(client_password_method, self); - - self->super.type = ATOM_PASSWORD; - self->super.login = do_password_login; - self->tty = tty; - - return &self->super; -} - - -/* Publickey authentication. */ - -/* We first send a set of publickey authentication requests for the - * available keys. This is analogous to unlocking a door by first - * examining the keys on one's keyring to see if any of them can be - * inserted into the lock. ' - * - * FIXME: At this stage it is preferable to use spki hashed public - * keys rather than the public keys themselves. - * - * Next we wait for SSH_MSH_USERAUTH_FAILURE or SSH_MSG_USERAUTH_PK_OK - * messages. If any of the keys is recognized, we compute a signature - * and send it to the server (analogous to inserting the key into the - * lock and trying to turn it around). */ - -/* GABA: - (class - (name client_publickey_method) - (super client_userauth_method) - (vars - (keys object object_list))) -*/ - -/* GABA: - (class - (name client_publickey_state) - (super client_userauth_failure) - (vars - (userauth object client_userauth) - (connection object ssh_connection) - (keys object object_list) - ; Number of keys for which we have received either - ; a USERAUTH_FAILURE or USERAUTH_PK_OK message. - (done . UINT32) - ; Number of keys for which we have computed and sent a signature, - ; and not yet received any failure. - (pending . UINT32) - (e object exception_handler))) -*/ - -static void -client_publickey_next(struct client_publickey_state *state) -{ - static const struct exception publickey_auth_failed = - STATIC_EXCEPTION(EXC_USERAUTH, "Public key userauth failed."); - - if (state->done < LIST_LENGTH(state->keys)) - { - /* We received a response on a query request. */ - - state->done++; - if (state->done < LIST_LENGTH(state->keys)) - /* We are still waiting for SSH_MSG_USERAUTH_FAILURE or - * SSH_MSG_USERAUTH_PK_OK */ - return; - - /* We have got a response on the final query request. */ - state->connection->dispatch[SSH_MSG_USERAUTH_PK_OK] - = &connection_fail_handler; - } - else - { - /* We received a response (actually, a failure) on a request - * that included a signature. */ - assert(state->pending); - state->pending--; - } - - if (!state->pending) - /* All failed. */ - EXCEPTION_RAISE(state->e, &publickey_auth_failed); -} - -static void -do_publickey_failure(struct client_userauth_failure *s, int again UNUSED) -{ - CAST(client_publickey_state, self, s); - - /* NOTE: We have several pending requests, so we have to get all the - * replies before skipping to the next method. That's why the again - * argument must be ignored. */ - client_publickey_next(self); -} - -static struct client_publickey_state * -make_client_publickey_state(struct client_userauth *userauth, - struct ssh_connection *connection, - struct object_list *keys, - struct exception_handler *e) -{ - NEW(client_publickey_state, self); - self->super.failure = do_publickey_failure; - self->userauth = userauth; - self->connection = connection; - self->keys = keys; - self->done = 0; - self->pending = 0; - self->e = e; - - return self; -} - -/* GABA: - (class - (name userauth_pk_ok_handler) - (super packet_handler) - (vars - (state object client_publickey_state))) */ - -static void -do_userauth_pk_ok(struct packet_handler *s, - struct ssh_connection *connection, - struct lsh_string *packet UNUSED) -{ - CAST(userauth_pk_ok_handler, self, s); - - struct simple_buffer buffer; - - unsigned msg_number; - int algorithm; - UINT32 keyblob_length; - const UINT8 *keyblob; -#if MACOS - int found = 0; -#endif - - simple_buffer_init(&buffer, packet->length, packet->data); - -#if MACOS - /* workaround for ssh 1.99-2.0.13 non conform reply */ - if ((connection->peer_flags & PEER_WRONG_PK_OK)) { - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_PK_OK) - && parse_uint32(&buffer, &keyblob_length) - && keyblob_length == buffer.capacity - buffer.pos) { - algorithm = ATOM_SSH_DSS; - keyblob = buffer.data + buffer.pos; - found = 1; - } - } else { - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_PK_OK) - && parse_atom(&buffer, &algorithm) - && parse_string(&buffer, &keyblob_length, &keyblob) - && parse_eod(&buffer)) { - found = 1; - } - } - if ( found ) -#else - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_PK_OK) - && parse_atom(&buffer, &algorithm) - && parse_string(&buffer, &keyblob_length, &keyblob) - && parse_eod(&buffer)) -#endif - { - CAST(keypair, key, LIST(self->state->keys)[self->state->done]); - verbose("SSH_MSG_USERAUTH_PK_OK received\n"); - - if ( (key->type == algorithm) - && lsh_string_eq_l(key->public, keyblob_length, keyblob) ) - { - struct lsh_string *request; - struct lsh_string *signed_data; - -#if DATAFELLOWS_WORKAROUNDS - if (connection->peer_flags & PEER_USERAUTH_REQUEST_KLUDGE) - request = format_userauth_publickey(self->state->userauth->username, - ATOM_SSH_USERAUTH, - key->type, - key->public); - else -#endif /* DATAFELLOWS_WORKAROUNDS */ - request = format_userauth_publickey(self->state->userauth->username, - self->state->userauth->service_name, - key->type, - key->public); - - signed_data = ssh_format("%S%lS", connection->session_id, request); - request = ssh_format("%flS%fS", - request, - SIGN(key->private, key->type, signed_data->length, signed_data->data)); - lsh_string_free(signed_data); - C_WRITE(connection, request); - self->state->pending++; - } - else - werror("client_userauth.c: Unexpected key in USERAUTH_PK_OK message.\n"); - - client_publickey_next(self->state); - } - else - PROTOCOL_ERROR(self->state->e, "Invalid USERAUTH_PK_OK message"); - } - -static struct packet_handler * -make_pk_ok_handler(struct client_publickey_state *state) -{ - NEW(userauth_pk_ok_handler, self); - - self->super.handler = do_userauth_pk_ok; - self->state = state; - - return &self->super; -} - -static struct client_userauth_failure * -do_publickey_login(struct client_userauth_method *s, - struct client_userauth *userauth, - struct ssh_connection *connection, - struct exception_handler *e) -{ - CAST(client_publickey_method, self, s); - - assert(LIST_LENGTH(self->keys)); - - - { - struct client_publickey_state *state = - make_client_publickey_state(userauth, - connection, - self->keys, - e); - unsigned i; - - for (i = 0; i < LIST_LENGTH(self->keys); i++) - { - CAST(keypair, key, LIST(self->keys)[i]); - - /* NOTE: The PEER_USERAUTH_REQUEST_KLUDGE only applies to the - * signed data. */ - C_WRITE(connection, - format_userauth_publickey_query(userauth->username, - userauth->service_name, - key->type, key->public)); - } - connection->dispatch[SSH_MSG_USERAUTH_PK_OK] = make_pk_ok_handler(state); - return &state->super; - } -} - -struct client_userauth_method * -make_client_publickey_auth(struct object_list *keys) -{ - NEW(client_publickey_method, self); - - self->super.type = ATOM_PUBLICKEY; - self->super.login = do_publickey_login; - self->keys = keys; - - return &self->super; -} diff --git a/lsh/src/client_userauth.c.x b/lsh/src/client_userauth.c.x deleted file mode 100755 index 140a23e..0000000 Binary files a/lsh/src/client_userauth.c.x and /dev/null differ diff --git a/lsh/src/client_userauth.h b/lsh/src/client_userauth.h deleted file mode 100755 index 87e8db0..0000000 --- a/lsh/src/client_userauth.h +++ /dev/null @@ -1,58 +0,0 @@ -/* client_userauth.h - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_CLIENT_USERAUTH_H_INCLUDED -#define LSH_CLIENT_USERAUTH_H_INCLUDED - -#include "alist.h" -#include "command.h" -#include "connection.h" -#include "interact.h" -#include "list.h" -#include "parse.h" -#include "userauth.h" - -/* Client functions */ -struct lsh_string * -format_userauth_password(struct lsh_string *name, - int service, - struct lsh_string *passwd, - int free); - - -/* Consumes the username */ -struct command *make_client_userauth(struct lsh_string *username, - int service_name, - struct object_list *methods); - -struct client_userauth_method * -make_client_password_auth(struct interact *tty); - -struct client_userauth_method * -make_client_publickey_auth(struct object_list *); - -struct client_userauth_method * -make_client_none_auth(void); - -#endif /* LSH_CLIENT_USERAUTH_H_INCLUDED */ - diff --git a/lsh/src/client_x11.c b/lsh/src/client_x11.c deleted file mode 100644 index dda391d..0000000 --- a/lsh/src/client_x11.c +++ /dev/null @@ -1,770 +0,0 @@ -/* client_x11.c - * - * Client side of X11 forwaarding. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 - */ - -#include "client.h" - -#include "channel_forward.h" -#include "format.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" -#include "xauth.h" - -#include "client_x11.c.x" - -#include -#include - -#include -#include - -#include -#include -#include - -/* First port number for X, according to RFC 1013 */ -#define X11_BASE_PORT 6000 - -#define X11_WINDOW_SIZE 10000 - -#define X11_COOKIE_LENGTH 16 - -/* ;; GABA: - (class - (name client_x11_auth_info) - (vars - ; Fake MIT-COOKIE-1 - (fake string) - - ; Real authentication info - (name string) - (auth string))) -*/ - -/* FIXME: Perhaps merge auth_info directly into this struct */ -/* GABA: - (class - (name client_x11_display) - (vars - (address_length . socklen_t) - (address space "struct sockaddr") - - ; Default screen - (screen . UINT16) - - ; Fake MIT-COOKIE-1 - (fake string) - - ; Real authentication info - (auth_name string) - (auth_data string))) -*/ - -/* GABA: - (class - (name channel_open_x11) - (super channel_open) - (vars - (backend object io_backend))) -*/ - -/* GABA: - (class - (name client_x11_channel) - (super channel_forward) - (vars - (display object client_x11_display) - (state . int) - (little_endian . int) - (name_length . unsigned) - (auth_length . unsigned) - (i . UINT32) - (buffer string))) -*/ - -/* This function is responsible for checking the fake cookie, and - * replacing it with the real one. - * - * It intercepts the first packet sent by the client, which has the - * following format: - * - * Type Possible or typical values - * - * uint8_t byte-order 'B' (big endian) or 'L' (little endian) - * uint8_t pad 0 - * uint16_t major-version Usually 11 - * uint16_t minor-version Usually 0. - * uint16_t name_length 18 - * uint16_t auth_length 16 - * uint16_t pad What's this? - * uint8_t [name_length] name "MIT-MAGIC-COOKIE-1" - * uint8_t [auth_length] auth Authentication data - * - * The last fields; name and auth, are padded to a multiple of four octets. - * - * The typical setup packet, with a 16-octet cookie, is 48 octets. - */ - -/* Observed data: - * - * $10 = {0x42, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x12, 0x0, 0x10, 0x0, 0xa4, 0x4d, - * 0x49, 0x54, 0x2d, 0x4d, 0x41, 0x47, 0x49, 0x43, 0x2d, 0x43, 0x4f, 0x4f, - * 0x4b, 0x49, 0x45, 0x2d, 0x31, 0xff, 0xf7, 0x8b, 0x1e, 0x2c, 0xa0, 0x98, - * 0x11, 0x27, 0x82, 0xa9, 0x0, 0x2d, 0xc4, 0x68, 0x7f, 0x66, 0x2b} - * - */ - -/* From Pike's X.pmod: - * - * /( Always uses network byteorder (big endian) - * string msg = sprintf("B\0%2c%2c%2c%2c\0\0%s%s", - * 11, 0, - * strlen(auth_data->name), strlen(auth_data->data), - * ._Xlib.pad(auth_data->name), ._Xlib.pad(auth_data->data)); - */ - -#define MIT_COOKIE_NAME "MIT-MAGIC-COOKIE-1" -#define MIT_COOKIE_NAME_LENGTH 18 -#define MIT_COOKIE_LENGTH 16 - -#define X11_SETUP_VERSION_LENGTH 6 -#define X11_SETUP_HEADER_LENGTH 12 - -/* The size of a connection setup message with a 16 octet - * MIT-MAGIC-COOKIE-1. Using such a low value leaks the information - * that we expect a 16-octet cookie, but I don't think that's areal - * problem. */ -#define X11_SETUP_MAX_LENGTH 48 - -enum { CLIENT_X11_START, - CLIENT_X11_GOT_LENGTHS, - CLIENT_X11_OK, - CLIENT_X11_DENIED -}; - -/* And the other, little-endian, byteorder */ -#define LE_READ_UINT16(p) \ -( (((uint32_t) (p)[1]) << 8) \ - | ((uint32_t) (p)[0])) - -#define LE_WRITE_UINT16(p, i) \ -do { \ - (p)[1] = ((i) >> 8) & 0xff; \ - (p)[0] = (i) & 0xff; \ -} while(0) - -/* FIXME: This function is a little ugly. It would get cleaner if we - * just replaced the channel's receive function pointer with NULL on - * failure and do_channel_forward_receive on success. */ -static void -do_client_channel_x11_receive(struct ssh_channel *s, - int type, struct lsh_string *data) -{ - CAST(client_x11_channel, self, s); - - if (type != CHANNEL_DATA) - { - werror("Ignoring unexpected stderr data.\n"); - lsh_string_free(data); - } - else switch (self->state) - { - case CLIENT_X11_OK: - A_WRITE(&self->super.socket->write_buffer->super, data); - break; - - fail: - channel_close(&self->super.super); - self->state = CLIENT_X11_DENIED; - - break; - - case CLIENT_X11_DENIED: - /* Any data on the channel should be stopped before we get - * here; the CHANNEL_SENT_CLOSE should be set. */ - fatal("Internal error!\n"); - - default: - { - /* Copy data to buffer */ - UINT32 left = self->buffer->length - self->i; - - /* The small initial window size should ensure that we don't get - * more data. */ - assert(data->length <= left); - - memcpy(self->buffer->data + self->i, data->data, - data->length); - self->i += data->length; - lsh_string_free(data); - - switch (self->state) - { - case CLIENT_X11_START: - /* We need byte-order, major, minor and name_length, - * which is 6 octets */ - - if (self->i < X11_SETUP_HEADER_LENGTH) - break; - - self->state = CLIENT_X11_GOT_LENGTHS; - - switch (self->buffer->data[0]) - { - case 'B': /* Big endian */ - case 'b': /* Big endian */ - self->little_endian = 0; - self->name_length = READ_UINT16(self->buffer->data + 6); - self->auth_length = READ_UINT16(self->buffer->data + 8); - break; - case 'L': /* Little endian */ - case 'l': /* Little endian */ - self->little_endian = 1; - self->name_length = LE_READ_UINT16(self->buffer->data + 6); - self->auth_length = LE_READ_UINT16(self->buffer->data + 8); - break; - default: - werror("client_x11.c: Bad endian indicator.\n"); - goto fail; - } - if ( (self->name_length > 20) - || (self->auth_length > 16) ) - { - werror("client_x11.c: Too long auth name or cookie\n"); - goto fail; - } - - /* Fall through */ - - case CLIENT_X11_GOT_LENGTHS: - { - const unsigned pad_length[4] = { 0, 3, 2, 1 }; - -#define PAD(l) (pad_length[ (l) % 4]) - - UINT32 auth_offset = X11_SETUP_HEADER_LENGTH - + self->name_length + PAD(self->name_length); - - UINT32 length = auth_offset + self->auth_length - + pad_length[self->auth_length % 4]; - - if (self->i < length) - break; - - debug("Received cookie of type `%ps': %xs\n", - self->name_length, self->buffer->data + X11_SETUP_HEADER_LENGTH, - self->auth_length, self->buffer->data + auth_offset); - - /* Ok, now we have the connection setup message. Check if it's ok. */ - if ( (self->name_length == MIT_COOKIE_NAME_LENGTH) - && !memcmp(self->buffer->data + X11_SETUP_HEADER_LENGTH, - MIT_COOKIE_NAME, MIT_COOKIE_NAME_LENGTH) - && lsh_string_eq_l(self->display->fake, - self->auth_length, - self->buffer->data + auth_offset)) - { - struct lsh_string *msg; - UINT8 lengths[4]; - static const UINT8 pad[3] = { 0, 0, 0 }; - - /* Cookies match! */ - verbose("client_x11: Allowing X11 connection; cookies match.\n"); - - if (self->little_endian) - { - LE_WRITE_UINT16(lengths, self->display->auth_name->length); - LE_WRITE_UINT16(lengths + 2, self->display->auth_data->length); - } - else - { - WRITE_UINT16(lengths, self->display->auth_name->length); - WRITE_UINT16(lengths + 2, self->display->auth_data->length); - } - - /* FIXME: Perhaps it would be easier to build the message by hand than - * using ssh_format? */ - /* Construct the real setup message. */ - msg = ssh_format("%ls%ls%c%c%ls%ls%ls%ls", - X11_SETUP_VERSION_LENGTH, self->buffer->data, - 4, lengths, - 0, 0, - self->display->auth_name->length, - self->display->auth_name->data, - PAD(self->display->auth_name->length), pad, - self->display->auth_data->length, - self->display->auth_data->data, - self->i - length, - self->buffer + self->i); - - lsh_string_free(self->buffer); - self->buffer = NULL; - - /* Bump window size */ - channel_start_receive(&self->super.super, X11_WINDOW_SIZE - msg->length); - - debug("client_x11.c: Sending real X11 setup message: %xS\n", - msg); - - /* Send real x11 connection setup message. */ - A_WRITE(&self->super.socket->write_buffer->super, msg); - - self->state = CLIENT_X11_OK; - } - else - { - werror("client_x11: X11 connection denied; bad cookie.\n"); - goto fail; - } - break; -#undef PAD - } - default: - fatal("Internal error. do_client_channel_x11_receive"); - break; - } - } - break; - } -} - -static struct client_x11_channel * -make_client_x11_channel(struct lsh_fd *fd, - struct client_x11_display *display) -{ - NEW(client_x11_channel, self); - - /* Use a limited window size for the setup */ - init_channel_forward(&self->super, fd, X11_SETUP_MAX_LENGTH); - self->display = display; - self->state = 0; - self->buffer = lsh_string_alloc(X11_SETUP_MAX_LENGTH); - - return self; -} - -/* GABA: - (class - (name channel_open_x11_continuation) - (super command_continuation) - (vars - (display object client_x11_display) - (up object command_continuation))) -*/ - -static void -do_channel_open_x11_continuation(struct command_continuation *s, - struct lsh_object *a) -{ - CAST(channel_open_x11_continuation, self, s); - CAST(lsh_fd, fd, a); - - struct client_x11_channel *channel = make_client_x11_channel(fd, self->display); - channel_forward_start_io(&channel->super); - channel->super.super.receive = do_client_channel_x11_receive; - - COMMAND_RETURN(self->up, channel); -} - -static struct command_continuation * -make_channel_open_x11_continuation(struct client_x11_display *display, - struct command_continuation *up) -{ - NEW(channel_open_x11_continuation, self); - self->super.c = do_channel_open_x11_continuation; - self->display = display; - self->up = up; - - return &self->super; -} - -/* Exception handler that promotes connect errors to CHANNEL_OPEN - * exceptions */ - -static void -do_exc_x11_connect_handler(struct exception_handler *s, - const struct exception *e) -{ - switch(e->type) - { - case EXC_IO_CONNECT: - EXCEPTION_RAISE(s->parent, - make_channel_open_exception(SSH_OPEN_CONNECT_FAILED, - e->msg)); - break; - default: - EXCEPTION_RAISE(s->parent, e); - } -} - -static struct exception_handler * -make_exc_x11_connect_handler(struct exception_handler *parent, - const char *context) -{ - return make_exception_handler(do_exc_x11_connect_handler, parent, context); -} - -static void -do_channel_open_x11(struct channel_open *s, - struct ssh_connection *connection, - struct channel_open_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(channel_open_x11, self, s); - - UINT32 originator_length; - const UINT8 *originator; - UINT32 originator_port; - - if (parse_string(args, &originator_length, &originator) - && parse_uint32(args, &originator_port) - && parse_eod(args)) - { - struct client_x11_display *display = connection->table->x11_display; - - verbose("x11 connection attempt, originator: %s:%i\n", - originator_length, originator, originator_port); - - - if (display) - { - struct lsh_fd *fd - = io_connect(self->backend, - display->address, - display->address_length, - make_channel_open_x11_continuation(display, - c), - make_exc_x11_connect_handler(e, HANDLER_CONTEXT)); - - if (fd) - REMEMBER_RESOURCE(connection->resources, &fd->super); - else - EXCEPTION_RAISE(e, - make_channel_open_exception(SSH_OPEN_CONNECT_FAILED, - STRERROR(errno))); - - /* FIXME: To handle single-connection feature, - * remove the display here. */ - } - else - EXCEPTION_RAISE(e, make_channel_open_exception - (SSH_OPEN_CONNECT_FAILED, - "No X11 forwarding has been requested.")); - } - else - { - werror("do_channel_open_x11: Invalid message!\n"); - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN x11 message."); - } -} - -struct channel_open * -make_channel_open_x11(struct io_backend *backend) -{ - NEW(channel_open_x11, self); - - self->super.handler = do_channel_open_x11; - self->backend = backend; - - return &self->super; -} - - -/* Format is host:display.screen, where display and screen are numbers */ -static int -parse_display(struct client_x11_display *self, const char *display) -{ - struct lsh_string *host; - - const char *num; - unsigned num_length; - unsigned display_num; - - /* Get host name */ - if (display[0] == ':') - { - /* Local transport */ - host = NULL; - display++; - } - else - { - const char *separator = strchr(display, ':'); - size_t length; - - if (!separator) - return 0; - - length = separator - display; - host = ssh_format("%ls", length, display); - - display = separator + 1; - } - - /* Get display number */ - { - char *end; - - num = display; - - display_num = strtol(display, &end, 0); - - num_length = end - num; - - if (!num_length) - { - lsh_string_free(host); - return 0; - } - - if (!*end) - /* Default screen number */ - self->screen = 0; - else if (*end != '.') - { - lsh_string_free(host); - return 0; - } - else - { - display = end + 1; - self->screen = strtol(display, &end, 0); - - if (*end) - { - lsh_string_free(host); - return 0; - } - } - } - - if (host) - { - /* NOTE: How do we support IPv6 displays? I have no idea how - * that would work with xauth. Actually, xauth ought to use DNS - * names rather than IP addresses. */ - struct address_info *a = make_address_info(host, X11_BASE_PORT + display_num); - - self->address = address_info2sockaddr(&self->address_length, a, NULL, 1); - - KILL(a); - - if (!self->address) - return 0; - } - else - { - /* Local transport */ - struct lsh_string *name = ssh_format("/tmp/.X11-unix/X%di", display_num); - struct sockaddr_un *sa; - - verbose("Using local X11 transport `%pS'\n", name); - - self->address_length = offsetof(struct sockaddr_un, sun_path) + name->length; - sa = lsh_space_alloc(self->address_length); - sa->sun_family = AF_UNIX; - memcpy(sa->sun_path, name->data, name->length); - - lsh_string_free(name); - self->address = (struct sockaddr *) sa; - } - - if (!xauth_lookup(self->address, - num_length, num, - &self->auth_name, - &self->auth_data)) - { - /* Fallback: Don't use xauth, and hope that the X server uses - * xhost to let us in anyway. */ - werror("Can't find any xauth information for X11 display.\n"); - - self->auth_name = ssh_format(""); - self->auth_data = ssh_format(""); - } - - return 1; -} - -struct client_x11_display * -make_client_x11_display(const char *display, struct lsh_string *fake) -{ - NEW(client_x11_display, self); - - self->fake = fake; - - if (!parse_display(self, display)) - { - werror("Can't parse X11 display: `%z'\n", display); - KILL(self); - return NULL; - } - - return self; -} - -/* GABA: - (class - (name client_x11_display_resource) - (super resource) - (vars - (connection object ssh_connection) - (display object client_x11_display))) -*/ - -static void -do_kill_x11_display(struct resource *s) -{ - CAST(client_x11_display_resource, self, s); - - if (self->super.alive) - { - self->super.alive = 0; - - if (self->connection->table->x11_display == self->display) - self->connection->table->x11_display = NULL; - else - werror("do_kill_x11_display: Display has been replaced.\n"); - } -} - -static struct resource * -make_client_x11_display_resource(struct ssh_connection *connection, - struct client_x11_display *display) -{ - NEW(client_x11_display_resource, self); - init_resource(&self->super, do_kill_x11_display); - - self->connection = connection; - self->display = display; - - return &self->super; -} - -/* GABA: - (class - (name request_x11_continuation) - (super command_continuation) - (vars - (connection object ssh_connection) - (display object client_x11_display) - (up object command_continuation))) -*/ - -static void -do_request_x11_continuation(struct command_continuation *s, - struct lsh_object *a) -{ - CAST(request_x11_continuation, self, s); - CAST_SUBTYPE(ssh_channel, channel, a); - - verbose("X11 request succeeded\n"); - - if (self->connection->table->x11_display) - werror("client_x11.c: Replacing old x11 forwarding.\n"); - - self->connection->table->x11_display = self->display; - - REMEMBER_RESOURCE(channel->resources, - make_client_x11_display_resource(self->connection, - self->display)); - - COMMAND_RETURN(self->up, a); -} - -static struct command_continuation * -make_request_x11_continuation(struct ssh_connection *connection, - struct client_x11_display *display, - struct command_continuation *up) -{ - NEW(request_x11_continuation, self); - self->super.c = do_request_x11_continuation; - - self->connection = connection; - self->display = display; - self->up = up; - - return &self->super; -} - -/* GABA: - (class - (name request_x11_forward_command) - (super channel_request_command) - (vars - (connection object ssh_connection) - (display object client_x11_display))) -*/ - -static struct lsh_string * -do_format_request_x11_forward(struct channel_request_command *s, - struct ssh_channel *channel, - struct command_continuation **c) -{ - CAST(request_x11_forward_command, self, s); - - verbose("Requesting X11 forwarding.\n"); - - *c = make_request_x11_continuation(channel->connection, - self->display, *c); - - /* NOTE: The cookie is hex encoded, appearantly so that it can be - * passed directly to the xauth command line. That's really ugly, - * but it's how the other ssh implementations do it. */ - - return format_channel_request(ATOM_X11_REQ, channel, 1, "%c%s%xS%i", - 0, /* Single connection not supported */ - MIT_COOKIE_NAME_LENGTH, MIT_COOKIE_NAME, - self->display->fake, - self->display->screen); -} - -/* Consumes fake */ -struct command * -make_forward_x11(const char *display_string, - struct randomness *random) -{ - struct lsh_string *fake = lsh_string_alloc(X11_COOKIE_LENGTH); - struct client_x11_display *display; - - RANDOM(random, fake->length, fake->data); - - debug("Generated X11 fake cookie %xS\n", fake); - - /* This deallocates fake if it fails. */ - display = make_client_x11_display(display_string, fake); - - if (display) - { - NEW(request_x11_forward_command, self); - self->super.super.call = do_channel_request_command; - self->super.format_request = do_format_request_x11_forward; - - self->display = display; - return &self->super.super; - } - else - return NULL; -} diff --git a/lsh/src/client_x11.c.x b/lsh/src/client_x11.c.x deleted file mode 100644 index c12a16f..0000000 --- a/lsh/src/client_x11.c.x +++ /dev/null @@ -1,250 +0,0 @@ -/* -CLASS:client_x11_display: -*/ -#ifndef GABA_DEFINE -struct client_x11_display -{ - struct lsh_object super; - socklen_t address_length; - struct sockaddr (*(address)); - UINT16 screen; - struct lsh_string *fake; - struct lsh_string *auth_name; - struct lsh_string *auth_data; -}; -extern struct lsh_class client_x11_display_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_client_x11_display_free(struct lsh_object *o) -{ - struct client_x11_display *i = (struct client_x11_display *) o; - if ( i->address ) - lsh_space_free(i->address); - if ( i->fake ) - lsh_string_free(i->fake); - if ( i->auth_name ) - lsh_string_free(i->auth_name); - if ( i->auth_data ) - lsh_string_free(i->auth_data); -} -struct lsh_class client_x11_display_class = -{ - STATIC_HEADER, - NULL, - "client_x11_display", - sizeof(struct client_x11_display), - NULL, - do_client_x11_display_free, -}; -#endif /* !GABA_DECLARE */ - -/* -CLASS:channel_open_x11:channel_open -*/ -#ifndef GABA_DEFINE -struct channel_open_x11 -{ - struct channel_open super; - struct io_backend *backend; -}; -extern struct lsh_class channel_open_x11_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_channel_open_x11_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct channel_open_x11 *i = (struct channel_open_x11 *) o; - mark((struct lsh_object *) i->backend); -} -struct lsh_class channel_open_x11_class = -{ - STATIC_HEADER, - &(channel_open_class), - "channel_open_x11", - sizeof(struct channel_open_x11), - do_channel_open_x11_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - -/* -CLASS:client_x11_channel:channel_forward -*/ -#ifndef GABA_DEFINE -struct client_x11_channel -{ - struct channel_forward super; - struct client_x11_display *display; - int state; - int little_endian; - unsigned name_length; - unsigned auth_length; - UINT32 i; - struct lsh_string *buffer; -}; -extern struct lsh_class client_x11_channel_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_client_x11_channel_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct client_x11_channel *i = (struct client_x11_channel *) o; - mark((struct lsh_object *) i->display); -} -static void -do_client_x11_channel_free(struct lsh_object *o) -{ - struct client_x11_channel *i = (struct client_x11_channel *) o; - lsh_string_free(i->buffer); -} -struct lsh_class client_x11_channel_class = -{ - STATIC_HEADER, - &(channel_forward_class), - "client_x11_channel", - sizeof(struct client_x11_channel), - do_client_x11_channel_mark, - do_client_x11_channel_free, -}; -#endif /* !GABA_DECLARE */ - -/* -CLASS:channel_open_x11_continuation:command_continuation -*/ -#ifndef GABA_DEFINE -struct channel_open_x11_continuation -{ - struct command_continuation super; - struct client_x11_display *display; - struct command_continuation *up; -}; -extern struct lsh_class channel_open_x11_continuation_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_channel_open_x11_continuation_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct channel_open_x11_continuation *i = (struct channel_open_x11_continuation *) o; - mark((struct lsh_object *) i->display); - mark((struct lsh_object *) i->up); -} -struct lsh_class channel_open_x11_continuation_class = -{ - STATIC_HEADER, - &(command_continuation_class), - "channel_open_x11_continuation", - sizeof(struct channel_open_x11_continuation), - do_channel_open_x11_continuation_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - -/* -CLASS:client_x11_display_resource:resource -*/ -#ifndef GABA_DEFINE -struct client_x11_display_resource -{ - struct resource super; - struct ssh_connection *connection; - struct client_x11_display *display; -}; -extern struct lsh_class client_x11_display_resource_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_client_x11_display_resource_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct client_x11_display_resource *i = (struct client_x11_display_resource *) o; - mark((struct lsh_object *) i->connection); - mark((struct lsh_object *) i->display); -} -struct lsh_class client_x11_display_resource_class = -{ - STATIC_HEADER, - &(resource_class), - "client_x11_display_resource", - sizeof(struct client_x11_display_resource), - do_client_x11_display_resource_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - -/* -CLASS:request_x11_continuation:command_continuation -*/ -#ifndef GABA_DEFINE -struct request_x11_continuation -{ - struct command_continuation super; - struct ssh_connection *connection; - struct client_x11_display *display; - struct command_continuation *up; -}; -extern struct lsh_class request_x11_continuation_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_request_x11_continuation_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct request_x11_continuation *i = (struct request_x11_continuation *) o; - mark((struct lsh_object *) i->connection); - mark((struct lsh_object *) i->display); - mark((struct lsh_object *) i->up); -} -struct lsh_class request_x11_continuation_class = -{ - STATIC_HEADER, - &(command_continuation_class), - "request_x11_continuation", - sizeof(struct request_x11_continuation), - do_request_x11_continuation_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - -/* -CLASS:request_x11_forward_command:channel_request_command -*/ -#ifndef GABA_DEFINE -struct request_x11_forward_command -{ - struct channel_request_command super; - struct ssh_connection *connection; - struct client_x11_display *display; -}; -extern struct lsh_class request_x11_forward_command_class; -#endif /* !GABA_DEFINE */ - -#ifndef GABA_DECLARE -static void -do_request_x11_forward_command_mark(struct lsh_object *o, - void (*mark)(struct lsh_object *o)) -{ - struct request_x11_forward_command *i = (struct request_x11_forward_command *) o; - mark((struct lsh_object *) i->connection); - mark((struct lsh_object *) i->display); -} -struct lsh_class request_x11_forward_command_class = -{ - STATIC_HEADER, - &(channel_request_command_class), - "request_x11_forward_command", - sizeof(struct request_x11_forward_command), - do_request_x11_forward_command_mark, - NULL, -}; -#endif /* !GABA_DECLARE */ - diff --git a/lsh/src/combinators.c b/lsh/src/combinators.c deleted file mode 100755 index 824373e..0000000 --- a/lsh/src/combinators.c +++ /dev/null @@ -1,253 +0,0 @@ -/* combinators.c - * - * Builtin combinator functions (S, K, ...) - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "command.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "combinators.c.x" - -/* Combinators */ - -/* Ix == x */ -DEFINE_COMMAND(command_I) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - COMMAND_RETURN(c, a); -} - - -/* ((K x) y) == x */ -DEFINE_COMMAND2(command_K) - (struct command_2 *s UNUSED, - struct lsh_object *x, - struct lsh_object *y UNUSED, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - COMMAND_RETURN(c, x); -} - - -/* ((S f) g) x == (f x)(g x) */ - -/* Receives the value of (f x) */ -/* GABA: - (class - (name command_S_continuation) - (super command_frame) - (vars - (g object command) - (x object lsh_object))) -*/ - -static void -do_command_S_continuation(struct command_continuation *c, - struct lsh_object *value) -{ - CAST(command_S_continuation, self, c); - CAST_SUBTYPE(command, op, value); - COMMAND_CALL(self->g, self->x, - make_apply(op, self->super.up, self->super.e), - self->super.e); -} - -static struct command_continuation * -make_command_S_continuation(struct command *g, - struct lsh_object *x, - struct command_continuation *up, - struct exception_handler *e) -{ - NEW(command_S_continuation, c); - c->g = g; - c->x = x; - c->super.up = up; - c->super.e = e; - c->super.super.c = do_command_S_continuation; - - return &c->super.super; -} - -DEFINE_COMMAND3(command_S) - (struct lsh_object *f, - struct lsh_object *g, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, cf, f); - CAST_SUBTYPE(command, cg, g); - - COMMAND_CALL(cf, x, - make_command_S_continuation(cg, x, c, e), - e); -} - -/* S' k f g x == k (f x) (g x) */ - -DEFINE_COMMAND4(command_Sp) - (struct lsh_object *k, - struct lsh_object *f, - struct lsh_object *g, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, ck, k); - CAST_SUBTYPE(command, cf, f); - CAST_SUBTYPE(command, cg, g); - - trace("command_Sp\n"); - - COMMAND_CALL(cf, x, - make_apply(ck, - make_command_S_continuation(cg, - x, c, e), - e), - e); -} - - -/* B f g x == f (g x) */ -DEFINE_COMMAND3(command_B) - (struct lsh_object *f, - struct lsh_object *g, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, cf, f); - CAST_SUBTYPE(command, cg, g); - - trace("command_B, f = %xi, cf = %xi, g = %xi, cg = %xi\n", - f, cf, g, cg); - - COMMAND_CALL(cg, x, - make_apply(cf, c, e), e); -} - - -/* B' k f g x == k (f (g x)) */ -DEFINE_COMMAND4(command_Bp) - (struct lsh_object *k, - struct lsh_object *f, - struct lsh_object *g, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, ck, k); - CAST_SUBTYPE(command, cf, f); - CAST_SUBTYPE(command, cg, g); - - trace("command_Bp\n"); - - COMMAND_CALL(cg, x, - make_apply(cf, - make_apply(ck, c, e), e), - e); -} - - -/* ((C f) y) x == (f x) y */ - -/* GABA: - (class - (name command_C_continuation) - (super command_frame) - (vars - (y object lsh_object))) -*/ - -static void -do_command_C_continuation(struct command_continuation *c, - struct lsh_object *value) -{ - CAST(command_C_continuation, self, c); - CAST_SUBTYPE(command, op, value); - - COMMAND_CALL(op, self->y, self->super.up, self->super.e); -} - -static struct command_continuation * -make_command_C_continuation(struct lsh_object *y, - struct command_continuation *up, - struct exception_handler *e) -{ - NEW(command_C_continuation, c); - c->y = y; - c->super.up = up; - c->super.e = e; - c->super.super.c = do_command_C_continuation; - - return &c->super.super; -} - -DEFINE_COMMAND3(command_C) - (struct lsh_object *f, - struct lsh_object *y, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, cf, f); - - trace("command_C\n"); - - COMMAND_CALL(cf, x, - make_command_C_continuation(y, c, e), - e); -} - - -/* C' k f y x == k (f x) y */ -DEFINE_COMMAND4(command_Cp) - (struct lsh_object *k, - struct lsh_object *f, - struct lsh_object *y, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, ck, k); - CAST_SUBTYPE(command, cf, f); - - trace("command_Cp\n"); - -#if 0 - werror("command_Cp: k: %t, f: %t, y: %t, x: %t\n", - k, f, y, x); -#endif - - COMMAND_CALL(cf, x, - make_apply(ck, - make_command_C_continuation(y, c, e), e), - e); -} diff --git a/lsh/src/combinators.c.x b/lsh/src/combinators.c.x deleted file mode 100755 index e1d0867..0000000 Binary files a/lsh/src/combinators.c.x and /dev/null differ diff --git a/lsh/src/command.c b/lsh/src/command.c deleted file mode 100755 index 12c4142..0000000 --- a/lsh/src/command.c +++ /dev/null @@ -1,708 +0,0 @@ -/* command.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "command.h" - -#include "connection.h" -#include "io.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "command.h.x" -#undef GABA_DEFINE - -#include "command.c.x" - -static void -do_discard_continuation(struct command_continuation *ignored UNUSED, - struct lsh_object *x UNUSED) -{} - -struct command_continuation discard_continuation = -{ STATIC_HEADER, do_discard_continuation}; - -struct command_context * -make_command_context(struct command_continuation *c, - struct exception_handler *e) -{ - NEW(command_context, self); - self->c = c; - self->e = e; - - return self; -} - -/* GABA: - (class - (name command_apply) - (super command_frame) - (vars - (f object command))) -*/ - -static void -do_command_apply(struct command_continuation *s, - struct lsh_object *value) -{ - CAST(command_apply, self, s); - COMMAND_CALL(self->f, value, - self->super.up, self->super.e); -} - -struct command_continuation * -make_apply(struct command *f, - struct command_continuation *c, struct exception_handler *e) -{ - NEW(command_apply, res); - assert(f); - assert(c); - assert(e); - - res->f = f; - res->super.up = c; - res->super.e = e; - res->super.super.c = do_command_apply; - - return &res->super.super; -} - -/* GABA: - (class - (name gaba_continuation) - (super command_continuation) - (vars - (value object lsh_object))) -*/ - -static void -do_gaba_continuation(struct command_continuation *c, - struct lsh_object *x) -{ - CAST(gaba_continuation, self, c); - - assert(!self->value); - self->value = x; -} - -struct lsh_object * -gaba_apply(struct lsh_object *f, - struct lsh_object *x) -{ - CAST_SUBTYPE(command, cf, f); - struct gaba_continuation c = - { { STATIC_HEADER, do_gaba_continuation }, NULL }; - - COMMAND_CALL(cf, x, &c.super, &default_exception_handler); - return c.value; -} - -/* A command taking 2 arguments */ -/* GABA: - (class - (name command_2_invoke) - (super command) - (vars - (f object command_2) - (a1 object lsh_object))) -*/ - -static void -do_command_2_invoke(struct command *s, struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(command_2_invoke, self, s); - COMMAND_2_INVOKE(self->f, self->a1, a2, c, e); -} - -struct command * -make_command_2_invoke(struct command_2 *f, - struct lsh_object *a1) -{ - NEW(command_2_invoke, self); - - self->super.call = do_command_2_invoke; - self->f = f; - self->a1 = a1; - - return &self->super; -} - -void -do_command_2(struct command *s, - struct lsh_object *a1, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command_2, self, s); - COMMAND_RETURN(c, make_command_2_invoke(self, a1)); -} - -/* A command taking 3 arguments */ -/* GABA: - (class - (name command_3_invoke_2) - (super command) - (vars - (f object command_3) - (a1 object lsh_object) - (a2 object lsh_object))) -*/ - -static void -do_command_3_invoke_2(struct command *s, - struct lsh_object *a3, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(command_3_invoke_2, self, s); - self->f->invoke(self->a1, self->a2, a3, c, e); -} - -struct command * -make_command_3_invoke_2(struct command_3 *f, - struct lsh_object *a1, - struct lsh_object *a2) -{ - NEW(command_3_invoke_2, self); - - self->super.call = do_command_3_invoke_2; - self->f = f; - self->a1 = a1; - self->a2 = a2; - - return &self->super; -} - -/* GABA: - (class - (name command_3_invoke) - (super command) - (vars - (f object command_3) - (a1 object lsh_object))) -*/ - -static void -do_command_3_invoke(struct command *s, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(command_3_invoke, self, s); - COMMAND_RETURN(c, make_command_3_invoke_2(self->f, self->a1, a2)); -} - -struct command * -make_command_3_invoke(struct command_3 *f, - struct lsh_object *a1) -{ - NEW(command_3_invoke, self); - - self->super.call = do_command_3_invoke; - self->f = f; - self->a1 = a1; - - return &self->super; -} - -void -do_command_3(struct command *s, - struct lsh_object *a1, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command_3, self, s); - COMMAND_RETURN(c, make_command_3_invoke(self, a1)); -} - - -/* A command taking 4 arguments */ -/* GABA: - (class - (name command_4_invoke_3) - (super command) - (vars - (f object command_4) - (a1 object lsh_object) - (a2 object lsh_object) - (a3 object lsh_object))) -*/ - -static void -do_command_4_invoke_3(struct command *s, - struct lsh_object *a4, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(command_4_invoke_3, self, s); - self->f->invoke(self->a1, self->a2, self->a3, a4, c, e); -} - -struct command * -make_command_4_invoke_3(struct command_4 *f, - struct lsh_object *a1, - struct lsh_object *a2, - struct lsh_object *a3) -{ - NEW(command_4_invoke_3, self); - - self->super.call = do_command_4_invoke_3; - self->f = f; - self->a1 = a1; - self->a2 = a2; - self->a3 = a3; - - return &self->super; -} - -/* GABA: - (class - (name command_4_invoke_2) - (super command) - (vars - (f object command_4) - (a1 object lsh_object) - (a2 object lsh_object))) -*/ - -static void -do_command_4_invoke_2(struct command *s, - struct lsh_object *a3, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(command_4_invoke_2, self, s); - COMMAND_RETURN(c, make_command_4_invoke_3(self->f, self->a1, self->a2, a3)); -} - -struct command * -make_command_4_invoke_2(struct command_4 *f, - struct lsh_object *a1, - struct lsh_object *a2) -{ - NEW(command_4_invoke_2, self); - - self->super.call = do_command_4_invoke_2; - self->f = f; - self->a1 = a1; - self->a2 = a2; - - return &self->super; -} - - -/* GABA: - (class - (name command_4_invoke) - (super command) - (vars - (f object command_4) - (a1 object lsh_object))) -*/ - -static void -do_command_4_invoke(struct command *s, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(command_4_invoke, self, s); - COMMAND_RETURN(c, make_command_4_invoke_2(self->f, self->a1, a2)); -} - -struct command * -make_command_4_invoke(struct command_4 *f, - struct lsh_object *a1) -{ - NEW(command_4_invoke, self); - - self->super.call = do_command_4_invoke; - self->f = f; - self->a1 = a1; - - return &self->super; -} - -void -do_command_4(struct command *s, - struct lsh_object *a1, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command_4, self, s); - COMMAND_RETURN(c, make_command_4_invoke(self, a1)); -} - - -/* Tracing */ - -#if DEBUG_TRACE - -/* GABA: - (class - (name trace_continuation) - (super command_continuation) - (vars - (name . "const char *") - (real object command_continuation))) -*/ - -static void -do_trace_continuation(struct command_continuation *s, - struct lsh_object *x) -{ - CAST(trace_continuation, self, s); - - trace("Leaving %z, value of type %t.\n", - self->name, x); - COMMAND_RETURN(self->real, x); -} - -static struct command_continuation * -make_trace_continuation(const char *name, - struct command_continuation *real) -{ - NEW(trace_continuation, self); - self->super.c = do_trace_continuation; - self->name = name; - self->real = real; - - return &self->super; -} - -/* GABA: - (class - (name trace_command) - (super command) - (vars - (name . "const char *") - (real object command))) -*/ - -static void -do_trace_command(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(trace_command, self, s); - - trace("Entering %z\n", self->name); -#if 1 - COMMAND_CALL(self->real, x, - make_trace_continuation(self->name, c), - e); -#else - COMMAND_CALL(self->real, x, c, e); -#endif -} - -struct command *make_trace(const char *name, struct command *real) -{ - NEW(trace_command, self); - self->super.call = do_trace_command; - self->name = name; - self->real = real; - - return &self->super; -} - -struct lsh_object *collect_trace(const char *name, struct lsh_object *c) -{ - CAST_SUBTYPE(command, real, c); - return &make_trace(name, real)->super; -} -#endif /* DEBUG_TRACE */ - -/* GABA: - (class - (name parallell_progn) - (super command) - (vars - (body object object_list))) -*/ - -static void -do_parallell_progn(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(parallell_progn, self, s); - unsigned i; - - for (i=0; i < LIST_LENGTH(self->body) - 1; i++) - { - CAST_SUBTYPE(command, command, LIST(self->body)[i]); - COMMAND_CALL(command, x, &discard_continuation, e); - } - { - CAST_SUBTYPE(command, command, LIST(self->body)[i]); - - COMMAND_CALL(command, x, c, e); - } -} - -struct command *make_parallell_progn(struct object_list *body) -{ - assert(LIST_LENGTH(body)); - { - NEW(parallell_progn, self); - self->body = body; - self->super.call = do_parallell_progn; - - return &self->super; - } -} - -DEFINE_COMMAND(progn_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(object_list, body, a); - - COMMAND_RETURN(c, (LIST_LENGTH(body) - ? make_parallell_progn(body) - : &command_I)); -} - -/* Catch command - * - * (catch handler body x) - * - * or - * - * ( (catch handler body) x) - * - * Invokes (body x), with an exception handler that passes exceptions - * of certain types to handler. */ - -/* GABA: - (class - (name catch_handler_info) - (vars - (mask . UINT32) - (value . UINT32) - (ignore_value . int) - ; NULL handler means ignore all caught exceptions. - (handler object command))) -*/ - -struct catch_handler_info * -make_catch_handler_info(UINT32 mask, UINT32 value, - int ignore_value, - struct command *handler) -{ - NEW(catch_handler_info, self); - self->mask = mask; - self->value = value; - self->ignore_value = ignore_value; - self->handler = handler; - - return self; -} - -/* GABA: - (class - (name catch_handler) - (super exception_handler) - (vars - (c object command_continuation) - (info object catch_handler_info))) -*/ - -static void -do_catch_handler(struct exception_handler *s, - const struct exception *e) -{ - CAST(catch_handler, self, s); - - if ((e->type & self->info->mask) == self->info->value) - { - if (self->info->handler) - COMMAND_CALL(self->info->handler, - e, self->c, self->super.parent); - else - trace("do_catch_handler: Ignoring exception: %z.\n", - e->msg); - } - else - EXCEPTION_RAISE(self->super.parent, e); -} - -static struct exception_handler * -make_catch_handler(struct catch_handler_info *info, - struct command_continuation *c, - struct exception_handler *e, - const char *context) -{ - NEW(catch_handler, self); - - self->super.raise = do_catch_handler; - self->super.parent = e; - self->super.context = context; - - self->c = c; - self->info = info; - - return &self->super; -} - -/* GABA: - (class - (name catch_apply) - (super command) - (vars - (info object catch_handler_info) - (body object command))) -*/ - -static void -do_catch_apply(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(catch_apply, self, s); - - COMMAND_CALL(self->body, a, (self->info->ignore_value - ? &discard_continuation - : c), - make_catch_handler(self->info, c, e, - HANDLER_CONTEXT)); -} - -struct command * -make_catch_apply(struct catch_handler_info *info, - struct command *body) -{ - NEW(catch_apply, self); - self->super.call = do_catch_apply; - self->info = info; - self->body = body; - - return &self->super; -} - - -/* GABA: - (class - (name catch_collect_body) - (super command) - (vars - (info object catch_handler_info))) -*/ - -static void -do_catch_collect_body(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(catch_collect_body, self, s); - CAST_SUBTYPE(command, body, a); - - COMMAND_RETURN(c, make_catch_apply(self->info, body)); -} - -static struct command * -make_catch_collect_body(struct catch_handler_info *info) -{ - NEW(catch_collect_body, self); - self->super.call = do_catch_collect_body; - self->info = info; - - return &self->super; -} - -void -do_catch_simple(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(catch_command, self, s); - CAST_SUBTYPE(command, f, a); - COMMAND_RETURN(c, - make_catch_collect_body - (make_catch_handler_info(self->mask, - self->value, self->ignore_value, f))); -} - - -/* Catch and report some exceptions. - * - * FIXME: This duplicates most of the catch command. */ - -/* GABA: - (class - (name catch_report_apply) - (super command) - (vars - (info object report_exception_info) - (body object command))) -*/ - -static void -do_catch_report_apply(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(catch_report_apply, self, s); - - COMMAND_CALL(self->body, a, c, - make_report_exception_handler(self->info, e, - HANDLER_CONTEXT)); -} - -struct command * -make_catch_report_apply(struct report_exception_info *info, - struct command *body) -{ - NEW(catch_report_apply, self); - self->super.call = do_catch_report_apply; - self->info = info; - self->body = body; - - return &self->super; -} - -void -do_catch_report_collect(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(catch_report_collect, self, s); - CAST_SUBTYPE(command, body, a); - - COMMAND_RETURN(c, - make_catch_report_apply(self->info, body)); -} diff --git a/lsh/src/command.c.x b/lsh/src/command.c.x deleted file mode 100755 index 4beb16b..0000000 Binary files a/lsh/src/command.c.x and /dev/null differ diff --git a/lsh/src/command.h b/lsh/src/command.h deleted file mode 100755 index 0448a2e..0000000 --- a/lsh/src/command.h +++ /dev/null @@ -1,424 +0,0 @@ -/* command.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_COMMAND_H_INCLUDED -#define LSH_COMMAND_H_INCLUDED - -#include "lsh.h" - -#include "exception.h" -#include "list.h" -/* #include "io.h" */ - -#include - -#define GABA_DECLARE -#include "command.h.x" -#undef GABA_DECLARE - -/* Continuation based command execution. A command can take one object - * as argument, and returns one object. */ - -/* GABA: - (class - (name command_continuation) - (vars - (c method void "struct lsh_object *result"))) -*/ - -#define COMMAND_RETURN(r, v) ((r)->c((r), (struct lsh_object *) (v))) - -/* GABA: - (class - (name command) - (vars - (call method void "struct lsh_object *arg" - "struct command_continuation *c" - "struct exception_handler *e"))) -*/ - -#define COMMAND_CALL(f, a, c, e) \ - ((void)&(f), ((f)->call((f), (struct lsh_object *) (a), (c), (e)))) - -/* NOTE: Except when inheriting command, use DEFINE_COMMAND instead. */ -#define STATIC_COMMAND(f) { STATIC_HEADER, f } - -#define DEFINE_COMMAND(cname) \ -static void \ -do_##cname(struct command *, \ - struct lsh_object *, \ - struct command_continuation *, \ - struct exception_handler *); \ - \ -struct command cname = \ -STATIC_COMMAND(do_##cname); \ - \ -static void \ -do_##cname - -/* A command taking 2 arguments */ -/* GABA: - (class - (name command_2) - (super command) - (vars - (invoke method void - "struct lsh_object *a1" - "struct lsh_object *a2" - "struct command_continuation *c" - "struct exception_handler *e")))) -*/ - -#define COMMAND_2_INVOKE(s, a1, a2, c, e) \ -((s)->invoke((s), (a1), (a2), (c), (e))) - -void -do_command_2(struct command *s, - struct lsh_object *a1, - struct command_continuation *c, - struct exception_handler *e); - -struct command * -make_command_2_invoke(struct command_2 *f, - struct lsh_object *a1); - -#define DEFINE_COMMAND2(cname) \ -static void \ -do_##cname(struct command_2 *, \ - struct lsh_object *, \ - struct lsh_object *, \ - struct command_continuation *, \ - struct exception_handler *); \ - \ -struct command_2 cname = \ -{ { STATIC_HEADER, do_command_2 }, do_##cname }; \ - \ -static void \ -do_##cname - -/* A command taking 3 arguments */ -/* GABA: - (class - (name command_3) - (super command) - (vars - (invoke pointer - (function void "struct lsh_object *a1" - "struct lsh_object *a2" - "struct lsh_object *a3" - "struct command_continuation *c" - "struct exception_handler *e")))) -*/ - -void -do_command_3(struct command *s, - struct lsh_object *a1, - struct command_continuation *c, - struct exception_handler *e); - -struct command * -make_command_3_invoke(struct command_3 *f, - struct lsh_object *a1); - -struct command * -make_command_3_invoke_2(struct command_3 *f, - struct lsh_object *a1, - struct lsh_object *a2); - -#define DEFINE_COMMAND3(cname) \ -static void \ -do_##cname(struct lsh_object *, \ - struct lsh_object *, \ - struct lsh_object *, \ - struct command_continuation *, \ - struct exception_handler *); \ - \ -struct command_3 cname = \ -{ { STATIC_HEADER, do_command_3 }, do_##cname }; \ - \ -static void \ -do_##cname - - -/* A command taking 4 arguments */ -/* GABA: - (class - (name command_4) - (super command) - (vars - (invoke pointer - (function void "struct lsh_object *a1" - "struct lsh_object *a2" - "struct lsh_object *a3" - "struct lsh_object *a4" - "struct command_continuation *c" - "struct exception_handler *e")))) -*/ - -void -do_command_4(struct command *s, - struct lsh_object *a1, - struct command_continuation *c, - struct exception_handler *e); - -struct command * -make_command_4_invoke(struct command_4 *f, - struct lsh_object *a1); - -struct command * -make_command_4_invoke_2(struct command_4 *f, - struct lsh_object *a1, - struct lsh_object *a2); - -struct command * -make_command_4_invoke_3(struct command_4 *f, - struct lsh_object *a1, - struct lsh_object *a2, - struct lsh_object *a3); - -#define DEFINE_COMMAND4(cname) \ -static void \ -do_##cname(struct lsh_object *, \ - struct lsh_object *, \ - struct lsh_object *, \ - struct lsh_object *, \ - struct command_continuation *, \ - struct exception_handler *); \ - \ -struct command_4 cname = \ -{ { STATIC_HEADER, do_command_4 }, do_##cname }; \ - \ -static void \ -do_##cname - - -void do_call_simple_command(struct command *s, - struct lsh_object *arg, - struct command_continuation *c, - struct exception_handler *e); - -struct command *make_parallell_progn(struct object_list *body); -extern struct command progn_command; - -extern struct command_continuation discard_continuation; - -#define CONTINUATION_USED_P(c) ((c) != &discard_continuation) - -/* GABA: - (class - (name command_frame) - (super command_continuation) - (vars - (up object command_continuation) - (e object exception_handler))) -*/ - -/* Used when the execution context must be saved for later use. - * - * Primarily used in channel_commands.c. - */ -/* GABA: - (class - (name command_context) - (vars - (c object command_continuation) - (e object exception_handler))) -*/ - -struct command_context * -make_command_context(struct command_continuation *c, - struct exception_handler *e); - -/* catch command, - * - * (catch handler body x) - */ - -/* GABA: - (class - (name catch_command) - (super command) - (vars - (mask . UINT32) - (value . UINT32) - - ; Ignore return values from body. This means that the catch - ; will return *only* if some exception is raised. Useful for - ; reading until some EOF exception is raised. - (ignore_value . int))) */ - -struct catch_handler_info * -make_catch_handler_info(UINT32 mask, UINT32 value, - int ignore_value, - struct command *handler); - -struct command * -make_catch_apply(struct catch_handler_info *info, - struct command *body); - -void -do_catch_simple(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e); - -#define STATIC_CATCH_COMMAND(m, v, i) \ -{ STATIC_COMMAND(do_catch_simple), (m), (v), (i) } - - -/* GABA: - (class - (name catch_report_collect) - (super command) - (vars - (info object report_exception_info))) -*/ - -struct command * -make_catch_report_apply(struct report_exception_info *info, - struct command *body); - -void -do_catch_report_collect(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e); - -#define STATIC_CATCH_REPORT(i) \ -{ STATIC_COMMAND(do_catch_report_collect), i } - - -#if DEBUG_TRACE -struct command *make_trace(const char *name, struct command *real); -struct lsh_object *collect_trace(const char *name, struct lsh_object *real); - -#define MAKE_TRACE collect_trace -#else /* !DEBUG_TRACE */ -#define MAKE_TRACE(name, real) (real) -#endif /* !DEBUG_TRACE */ - -/* Useful clobal commands */ -#define PROG1 (&command_K.super.super) -#define PROGN (&progn_command.super) - -/* The GABA_* macros are used by automatically generated evaluation code */ - -struct command_continuation * -make_apply(struct command *f, - struct command_continuation *c, struct exception_handler *e); - -struct lsh_object *gaba_apply(struct lsh_object *f, - struct lsh_object *x); - -#define GABA_APPLY gaba_apply - -extern struct command command_I; -#define GABA_VALUE_I (&command_I.super) -#define GABA_APPLY_I_1(x) (x) - -extern struct command_2 command_K; -struct command *make_command_K_1(struct lsh_object *x); - -#define GABA_VALUE_K (&command_K.super.super) -#define GABA_APPLY_K_1(x) \ -((struct lsh_object *) make_command_2_invoke(&command_K, (x))) - -extern struct command_3 command_S; - -#define GABA_VALUE_S (&command_S.super.super) -#define GABA_APPLY_S_1(f) \ -((struct lsh_object *) make_command_3_invoke(&command_S, (f))) -#define GABA_APPLY_S_2(f, g) \ -((struct lsh_object *) make_command_3_invoke_2(&command_S, (f), (g))) - -extern struct command_4 command_Sp; - -#define GABA_VALUE_Sp (&command_Sp.super.super) -#define GABA_APPLY_Sp_1(c) \ -((struct lsh_object *) make_command_4_invoke(&command_Sp, (f))) -#define GABA_APPLY_Sp_2(c, f) \ -((struct lsh_object *) make_command_4_invoke_2(&command_Sp, (c), (f))) -#define GABA_APPLY_Sp_3(c, f, g) \ -((struct lsh_object *) make_command_4_invoke_3(&command_Sp, (c), (f), (g))) - -extern struct command_3 command_B; - -#define GABA_VALUE_B (&command_B.super.super) -#define GABA_APPLY_B_1(f) \ -((struct lsh_object *) make_command_3_invoke(&command_B, (f))) -#define GABA_APPLY_B_2(f, g) \ -((struct lsh_object *) make_command_3_invoke_2(&command_B, (f), (g))) - -extern struct command_4 command_Bp; - -#define GABA_VALUE_Bp (&command_Bp.super.super) -#define GABA_APPLY_Bp_1(c) \ -((struct lsh_object *) make_command_4_invoke(&command_Bp, (c))) -#define GABA_APPLY_Bp_2(c, f) \ -((struct lsh_object *) make_command_4_invoke_2(&command_Bp, (c), (f))) -#define GABA_APPLY_Bp_3(c, f, g) \ -((struct lsh_object *) make_command_4_invoke_3(&command_Bp, (c), (f), (g))) - -extern struct command_3 command_C; - -#define GABA_VALUE_C (&command_C.super.super) -#define GABA_APPLY_C_1(f) \ -((struct lsh_object *) make_command_3_invoke(&command_C, (f))) -#define GABA_APPLY_C_2(f, g) \ -((struct lsh_object *) make_command_3_invoke_2(&command_C, (f), (g))) - -#if 1 -extern struct command_4 command_Cp; - -#define GABA_VALUE_Cp (&command_Cp.super.super) -#define GABA_APPLY_Cp_1(c) \ -((struct lsh_object *) make_command_4_invoke(&command_Cp, (c))) -#define GABA_APPLY_Cp_2(c, f) \ -((struct lsh_object *) make_command_4_invoke_2(&command_Cp, (c), (f))) -#define GABA_APPLY_Cp_3(c, f, g) \ -((struct lsh_object *) make_command_4_invoke_3(&command_Cp, (c), (f), (g))) -#else - -extern struct collect_info_1 command_Cp; -extern struct collect_info_2 collect_info_Cp_2; -extern struct collect_info_3 collect_info_Cp_3; - -struct command * -make_command_Cp_3(struct command *c, - struct command *f, - struct lsh_object *y); -struct lsh_object * -collect_Cp_3(struct collect_info_3 *info, - struct lsh_object *c, - struct lsh_object *f, - struct lsh_object *y); - -#define GABA_VALUE_Cp (&command_Cp.super.super.super) -#define GABA_APPLY_Cp_1(c) (make_collect_state_1(&command_Cp, (c))) -#define GABA_APPLY_Cp_2(c, f) \ - (make_collect_state_2(&collect_info_Cp_2, (c), (f))) -#define GABA_APPLY_Cp_3(c, f, y) (collect_Cp_3(&collect_info_Cp_3, (c), (f), (y))) - -#endif - -#endif /* LSH_COMMAND_H_INCLUDED */ diff --git a/lsh/src/command.h.x b/lsh/src/command.h.x deleted file mode 100755 index 150968d..0000000 Binary files a/lsh/src/command.h.x and /dev/null differ diff --git a/lsh/src/compress.c b/lsh/src/compress.c deleted file mode 100755 index d00d22a..0000000 --- a/lsh/src/compress.c +++ /dev/null @@ -1,98 +0,0 @@ -/* compress.c - * - * packet compressor - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "compress.h" - -#include "exception.h" -#include "ssh.h" -#include "xalloc.h" - -#include "compress.c.x" - -#include - -/* GABA: - (class - (name packet_compressor) - (super abstract_write_pipe) - (vars - (compressor object compress_instance) - (connection object ssh_connection))) -*/ - -static void -do_packet_deflate(struct abstract_write *closure, - struct lsh_string *packet) -{ - CAST(packet_compressor, self, closure); - - if (self->connection->send_compress) - { - packet = CODEC(self->connection->send_compress, packet, 1); - assert(packet); - } - - A_WRITE(self->super.next, packet); -} - -static void -do_packet_inflate(struct abstract_write *closure, - struct lsh_string *packet) -{ - CAST(packet_compressor, self, closure); - - if (self->connection->rec_compress) - { - packet = CODEC(self->connection->rec_compress, packet, 1); - if (!packet) - { - /* FIXME: It would be nice to pass the error message from zlib on - * to the exception handler. */ - EXCEPTION_RAISE - (self->connection->e, - make_protocol_exception(SSH_DISCONNECT_COMPRESSION_ERROR, - "Inflating compressed data failed.")); - return; - } - } - A_WRITE(self->super.next, packet); -} - -struct abstract_write * -make_packet_codec(struct abstract_write *next, - struct ssh_connection *connection, - int mode) -{ - NEW(packet_compressor, res); - - res->super.super.write = (mode == COMPRESS_INFLATE) - ? do_packet_inflate - : do_packet_deflate; - - res->super.next = next; - res->connection = connection; - - return &res->super.super; -} diff --git a/lsh/src/compress.c.x b/lsh/src/compress.c.x deleted file mode 100755 index 2fb7b59..0000000 Binary files a/lsh/src/compress.c.x and /dev/null differ diff --git a/lsh/src/compress.h b/lsh/src/compress.h deleted file mode 100755 index 75f0676..0000000 --- a/lsh/src/compress.h +++ /dev/null @@ -1,47 +0,0 @@ -/* compress.h - * - * header for compression algorithms - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_COMPRESS_H_INCLUDED -#define LSH_COMPRESS_H_INCLUDED - -#include "abstract_io.h" -#include "abstract_compress.h" - -#include "connection.h" - -struct compress_algorithm *make_zlib_algorithm(int level); -struct compress_algorithm *make_zlib(void); - -struct abstract_write *make_packet_codec(struct abstract_write *next, - struct ssh_connection *connection, - int mode); - -#define make_packet_deflate(next, connection) \ - make_packet_codec(next, connection, COMPRESS_DEFLATE) -#define make_packet_inflate(next, connection) \ - make_packet_codec(next, connection, COMPRESS_INFLATE) - -#endif /* LSH_COMPRESS_H_INCLUDED */ - diff --git a/lsh/src/connection.c b/lsh/src/connection.c deleted file mode 100755 index 09cff17..0000000 --- a/lsh/src/connection.c +++ /dev/null @@ -1,425 +0,0 @@ -/* connection.c - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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. - */ - -#include "connection.h" - -#include "compress.h" -#include "debug.h" -#include "disconnect.h" -#include "encrypt.h" -#include "exception.h" -#include "format.h" -#include "io.h" -#include "keyexchange.h" -#include "pad.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "connection.h.x" -#undef GABA_DEFINE - -#include "connection.c.x" - -const char *packet_types[0x100] = -#include "packet_types.h" -; - -static void -connection_handle_packet(struct ssh_connection *closure, - struct lsh_string *packet) -{ - UINT8 msg; - - assert(!closure->paused); - - if (!packet->length) - { - werror("connection.c: Received empty packet!\n"); - PROTOCOL_ERROR(closure->e, "Received empty packet."); - lsh_string_free(packet); - return; - } - - if (packet->length > closure->rec_max_packet) - { - werror("connection.c: Packet too large!\n"); - PROTOCOL_ERROR(closure->e, "Packet too large"); - lsh_string_free(packet); - return; - } - - msg = packet->data[0]; - - debug("handle_connection: Received packet of type %i (%z)\n", - msg, packet_types[msg]); - - switch(closure->kex_state) - { - case KEX_STATE_INIT: - if (msg == SSH_MSG_NEWKEYS) - { - werror("Unexpected NEWKEYS message!\n"); - PROTOCOL_ERROR(closure->e, "Unexpected NEWKEYS message!"); - lsh_string_free(packet); - return; - } - break; - case KEX_STATE_IGNORE: - debug("handle_connection: Ignoring packet %i\n", msg); - - /* It's conceivable with key exchange methods for which one - * wants to switch to the NEWKEYS state immediately. But for - * now, we always switch to the IN_PROGRESS state, to wait for a - * KEXDH_INIT or KEXDH_REPLY message. */ - closure->kex_state = KEX_STATE_IN_PROGRESS; - lsh_string_free(packet); - return; - - case KEX_STATE_IN_PROGRESS: - if ( (msg == SSH_MSG_NEWKEYS) - || (msg == SSH_MSG_KEXINIT)) - { - werror("Unexpected KEXINIT or NEWKEYS message!\n"); - PROTOCOL_ERROR(closure->e, "Unexpected KEXINIT or NEWKEYS message!"); - lsh_string_free(packet); - return; - } - break; - case KEX_STATE_NEWKEYS: - if (! ((msg == SSH_MSG_NEWKEYS) - || (msg == SSH_MSG_DISCONNECT) - || (msg == SSH_MSG_IGNORE) - || (msg == SSH_MSG_DEBUG))) - { - werror("Expected NEWKEYS message, but received message %i!\n", - msg); - PROTOCOL_ERROR(closure->e, "Expected NEWKEYS message"); - lsh_string_free(packet); - return; - } - break; - default: - fatal("handle_connection: Internal error.\n"); - } - - HANDLE_PACKET(closure->dispatch[msg], closure, packet); - lsh_string_free(packet); -} - -static void -connection_handle_pending(struct ssh_connection *self) -{ - while (!self->paused && !string_queue_is_empty(&self->pending)) - connection_handle_packet(self, string_queue_remove_head(&self->pending)); -} - -/* Deal with pausing of the connection. */ -static void -do_handle_connection(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(ssh_connection, self, w); - - if (self->paused) - string_queue_add_tail(&self->pending, packet); - - else if (string_queue_is_empty(&self->pending)) - connection_handle_packet(self, packet); - - else - { - string_queue_add_tail(&self->pending, packet); - connection_handle_pending(self); - } -} - -DEFINE_PACKET_HANDLER(, connection_ignore_handler, - connection UNUSED, packet UNUSED) -{ -} - -DEFINE_PACKET_HANDLER(, connection_fail_handler, connection, packet UNUSED) -{ - PROTOCOL_ERROR(connection->e, NULL); -} - -DEFINE_PACKET_HANDLER(, connection_unimplemented_handler, connection, packet) -{ - werror("Received packet of unimplemented type %i.\n", - packet->data[0]); - - C_WRITE(connection, - ssh_format("%c%i", - SSH_MSG_UNIMPLEMENTED, - packet->sequence_number)); -} - -DEFINE_PACKET_HANDLER(, connection_forward_handler, connection, packet) -{ - assert(connection->chain); - C_WRITE(connection->chain, packet); -} - - -/* GABA: - (class - (name exc_connection_handler) - (super exception_handler) - (vars - (backend object io_backend) - (connection object ssh_connection))) -*/ - -static void -do_exc_connection_handler(struct exception_handler *s, - const struct exception *e) -{ - CAST(exc_connection_handler, self, s); - - switch (e->type) - { - case EXC_PROTOCOL: - { - CAST_SUBTYPE(protocol_exception, exc, e); - - werror("Protocol error: %z\n", e->msg); - - if (exc->reason) - C_WRITE(self->connection, format_disconnect(exc->reason, exc->super.msg, "")); - - EXCEPTION_RAISE(self->super.parent, &finish_read_exception); - } - break; - - case EXC_PAUSE_CONNECTION: - assert(!self->connection->paused); - self->connection->paused = 1; - EXCEPTION_RAISE(self->super.parent, - make_simple_exception(EXC_PAUSE_READ, "locking connection.")); - break; - - case EXC_PAUSE_START_CONNECTION: - /* NOTE: Raising EXC_PAUSE_START_READ will not by itself make - * the connection start processing pending packets. Not until - * the peer sends us more data. - * - * So any code that raises EXC_PAUSE_START_CONNECTION should - * also call connection_handle_pending at a safe place. We - * can't call it here, as we may be in the middle of the - * handling of a packet. Installing a callout would be best. */ - - assert(self->connection->paused); - EXCEPTION_RAISE(self->super.parent, - make_simple_exception(EXC_PAUSE_START_READ, "unlocking connection.")); - - self->connection->paused = 0; - - break; - - default: - EXCEPTION_RAISE(self->super.parent, e); - } -} - -static struct exception_handler * -make_exc_connection_handler(struct ssh_connection *connection, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_connection_handler, self); - - self->super.parent = parent; - self->super.raise = do_exc_connection_handler; - self->super.context = context; - - self->connection = connection; - - return &self->super; -} - -struct ssh_connection * -make_ssh_connection(UINT32 flags, - struct address_info *peer, - const char *debug_comment, - struct command_continuation *c, - struct exception_handler *e) -{ - int i; - - NEW(ssh_connection, connection); - - connection->flags = flags; - connection->peer = peer; - - connection->debug_comment = debug_comment; - connection->super.write = do_handle_connection; - - /* Exception handler that sends a proper disconnect message on protocol errors */ - connection->e = make_exc_connection_handler(connection, e, HANDLER_CONTEXT); - - connection->established = c; - - /* Initialize instance variables */ - - connection->versions[CONNECTION_SERVER] - = connection->versions[CONNECTION_CLIENT] - = connection->session_id = NULL; - - connection->peer_flags = 0; - connection->user = NULL; - - connection->resources = empty_resource_list(); - - connection->rec_max_packet = SSH_MAX_PACKET; - - /* Initial encryption state */ - connection->send_crypto = connection->rec_crypto = NULL; - connection->send_mac = connection->rec_mac = NULL; - connection->send_compress = connection->rec_compress = NULL; - - connection->paused = 0; - string_queue_init(&connection->pending); - - connection->kex_state = KEX_STATE_INIT; - - connection->kexinits[CONNECTION_CLIENT] - = connection->kexinits[CONNECTION_SERVER] = NULL; - - connection->literal_kexinits[CONNECTION_CLIENT] - = connection->literal_kexinits[CONNECTION_SERVER] = NULL; - - for (i = 0; i < 0x100; i++) - connection->dispatch[i] = &connection_unimplemented_handler; - - connection->dispatch[0] = &connection_fail_handler; - connection->dispatch[SSH_MSG_DISCONNECT] = &disconnect_handler; - connection->dispatch[SSH_MSG_IGNORE] = &connection_ignore_handler; - - /* So far, all messages we send have to be supported. */ - connection->dispatch[SSH_MSG_UNIMPLEMENTED] = &connection_fail_handler; - - connection->dispatch[SSH_MSG_DEBUG] = &connection_debug_handler; - - /* Make all other known message types terminate the connection */ - - connection->dispatch[SSH_MSG_SERVICE_REQUEST] = &connection_fail_handler; - connection->dispatch[SSH_MSG_SERVICE_ACCEPT] = &connection_fail_handler; - connection->dispatch[SSH_MSG_NEWKEYS] = &connection_fail_handler; - connection->dispatch[SSH_MSG_KEXDH_INIT] = &connection_fail_handler; - connection->dispatch[SSH_MSG_KEXDH_REPLY] = &connection_fail_handler; - connection->dispatch[SSH_MSG_USERAUTH_REQUEST] = &connection_fail_handler; - connection->dispatch[SSH_MSG_USERAUTH_FAILURE] = &connection_fail_handler; - connection->dispatch[SSH_MSG_USERAUTH_SUCCESS] = &connection_fail_handler; - connection->dispatch[SSH_MSG_USERAUTH_BANNER] = &connection_fail_handler; - connection->dispatch[SSH_MSG_USERAUTH_PK_OK] = &connection_fail_handler; - connection->dispatch[SSH_MSG_USERAUTH_PASSWD_CHANGEREQ] = &connection_fail_handler; - connection->dispatch[SSH_MSG_GLOBAL_REQUEST] = &connection_fail_handler; - connection->dispatch[SSH_MSG_REQUEST_SUCCESS] = &connection_fail_handler; - connection->dispatch[SSH_MSG_REQUEST_FAILURE] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_OPEN] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_OPEN_CONFIRMATION] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_OPEN_FAILURE] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_WINDOW_ADJUST] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_DATA] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_EXTENDED_DATA] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_EOF] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_CLOSE] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_REQUEST] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_SUCCESS] = &connection_fail_handler; - connection->dispatch[SSH_MSG_CHANNEL_FAILURE] = &connection_fail_handler; - - return connection; -} - -void -connection_init_io(struct ssh_connection *connection, - struct abstract_write *raw, - struct randomness *r) -{ - /* Initialize i/o hooks */ - connection->raw = raw; - connection->write = - make_packet_debug( - make_packet_deflate( - make_packet_pad( - make_packet_encrypt(raw, connection), - connection, - r), - connection), - (connection->debug_comment - ? ssh_format("%lz sent", connection->debug_comment) - : ssh_format("Sent"))); -} - - -/* GABA: - (class - (name connection_close_handler) - (super lsh_callback) - (vars - (connection object ssh_connection))) -*/ - -static void -connection_die(struct lsh_callback *c) -{ - CAST(connection_close_handler, closure, c); - - verbose("Connection died.\n"); - - KILL_RESOURCE_LIST(closure->connection->resources); -} - -struct lsh_callback * -make_connection_close_handler(struct ssh_connection *c) -{ - NEW(connection_close_handler, closure); - - closure->connection = c; - closure->super.f = connection_die; - - return &closure->super; -} - - -/* Serialization. */ - -void connection_lock(struct ssh_connection *self) -{ - const struct exception pause - = STATIC_EXCEPTION(EXC_PAUSE_CONNECTION, "locking connection."); - - EXCEPTION_RAISE(self->e, &pause); -} - -void connection_unlock(struct ssh_connection *self) -{ - const struct exception unpause - = STATIC_EXCEPTION(EXC_PAUSE_START_CONNECTION, "unlocking connection."); - - EXCEPTION_RAISE(self->e, &unpause); -} diff --git a/lsh/src/connection.c.x b/lsh/src/connection.c.x deleted file mode 100755 index 413dc99..0000000 Binary files a/lsh/src/connection.c.x and /dev/null differ diff --git a/lsh/src/connection.h b/lsh/src/connection.h deleted file mode 100755 index 242e0e7..0000000 --- a/lsh/src/connection.h +++ /dev/null @@ -1,216 +0,0 @@ -/* connection.h - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CONNECTION_H_INCLUDED -#define LSH_CONNECTION_H_INCLUDED - -#include "abstract_io.h" -#include "abstract_compress.h" -#include "queue.h" -#include "resource.h" -#include "randomness.h" - - -#define GABA_DECLARE -#include "connection.h.x" -#undef GABA_DECLARE - -/* This is almost a write handler; difference is that it gets an extra - * argument with a connection object. */ - -/* GABA: - (class - (name packet_handler) - (vars - (handler method void - "struct ssh_connection *connection" - "struct lsh_string *packet"))) -*/ - -#define HANDLE_PACKET(closure, connection, packet) \ -((closure)->handler((closure), (connection), (packet))) - -#define DEFINE_PACKET_HANDLER(SPEC, NAME, CARG, PARG) \ -static void \ -do_##NAME(struct packet_handler *, \ - struct ssh_connection *, \ - struct lsh_string *); \ - \ -SPEC struct packet_handler NAME = \ -{ STATIC_HEADER, do_##NAME }; \ - \ -static void \ -do_##NAME(struct packet_handler *s UNUSED, \ - struct ssh_connection *CARG, \ - struct lsh_string *PARG) - - -/* NOTE: These are used both for indexing the two-element arrays in - * the connection object. But they are also used in the flags field, - * to indicate our role in the protocol. - * For instance, - * - * connection->versions[connection->flags & CONNECTION_MODE] - * - * is the version string we sent. Furthermore, install_keys() depends - * on the numerical values of CONNECTION_SERVER and CONNECTION_CLIENT. */ - -#define CONNECTION_MODE 1 - -#define CONNECTION_CLIENT 0 -#define CONNECTION_SERVER 1 - -/* Set if SRP keyexchange was used. */ -#define CONNECTION_SRP 2 - -/* Use a different encoding of ssh-dss signatures, for compatibility with - * SSH Inc's ssh version 2.0.x and 2.1.0 */ -#define PEER_SSH_DSS_KLUDGE 0x00000001 - -/* Support SSH_MSG_SERVICE_ACCEPT with omitted service name, for - * compatibility with SSH Inc's ssh version 2.0.x */ -#define PEER_SERVICE_ACCEPT_KLUDGE 0x00000002 - -/* Replace the service name with the string "ssh-userauth" in - * publickey userauth requests, for compatibility with SSH Inc's ssh - * version 2.0.x and 2.1.0 */ -#define PEER_USERAUTH_REQUEST_KLUDGE 0x00000004 - -/* Never send a debug message after successful keyexchange, as SSH - * Inc's ssh version 2.0.x and 2.1 can't handle that. */ -#define PEER_SEND_NO_DEBUG 0x00000008 - -/* Don't include the originator port in X11 channel open messages, for - * compatibility with SSH Inc's ssh version 2.0.x */ -#define PEER_X11_OPEN_KLUDGE 0x00000010 - -/* ssh version 2.0.13 workaround */ -#define PEER_WRONG_PK_OK 0x00000020 - -/* GABA: - (class - (name ssh_connection) - (super abstract_write) - (vars - ; Where to pass errors - (e object exception_handler) - - ; Connection flags - (flags . UINT32) - - ; Sent and received version strings - (versions array (string) 2) - (session_id string) - - ; Connection description, used for debug messages. - (debug_comment . "const char *") - - ; Features or bugs peculiar to the peer - (peer_flags . UINT32) - - ; Information about a logged in user. NULL unless some kind of - ; user authentication has been performed. - (user object lsh_user) - - ; The chained connection in the proxy, or gateway. - (chain object ssh_connection) - - ; Cleanup - (resources object resource_list) - - ; Connected peer - ; FIXME: Perhaps this should be a sockaddr or some other object - ; that facilitates reverse lookups? - (peer object address_info); - - ; Receiving - (rec_max_packet . UINT32) - (rec_mac object mac_instance) - (rec_crypto object crypto_instance) - (rec_compress object compress_instance) - - ; Sending - (raw object abstract_write) ; Socket connected to the other end - (write object abstract_write) ; Where to send packets through the - ; pipeline. - - (send_mac object mac_instance) - (send_crypto object crypto_instance) - (send_compress object compress_instance) - - ; For operations that require serialization. In particular - ; the server side of user authentication. - - (paused . int) - (pending struct string_queue) - - ; Key exchange - (kex_state . int) - - ; What to do once the connection is established - (established object command_continuation) - - (kexinits array (object kexinit) 2) - (literal_kexinits array (string) 2) - - ; Table of all known message types - (dispatch array (object packet_handler) "0x100") - - ; Table of all opened channels - (table object channel_table) - - ; (provides_privacy . int) - ; (provides_integrity . int) - )) -*/ - -#define C_WRITE(c, s) A_WRITE((c)->write, (s) ) - -struct ssh_connection * -make_ssh_connection(UINT32 flags, - struct address_info *peer, - const char *id_comment, - struct command_continuation *c, - struct exception_handler *e); - -void connection_init_io(struct ssh_connection *connection, - struct abstract_write *raw, - struct randomness *r); - -struct lsh_callback * -make_connection_close_handler(struct ssh_connection *c); - -/* Serialization */ -void connection_lock(struct ssh_connection *self); -void connection_unlock(struct ssh_connection *self); - -/* Table of packet types */ -extern const char *packet_types[0x100]; - -/* Simple packet handlers. */ -extern struct packet_handler connection_ignore_handler; -extern struct packet_handler connection_unimplemented_handler; -extern struct packet_handler connection_fail_handler; -extern struct packet_handler connection_forward_handler; - -#endif /* LSH_CONNECTION_H_INCLUDED */ diff --git a/lsh/src/connection.h.x b/lsh/src/connection.h.x deleted file mode 100755 index aa8a28f..0000000 Binary files a/lsh/src/connection.h.x and /dev/null differ diff --git a/lsh/src/connection_commands.c b/lsh/src/connection_commands.c deleted file mode 100755 index 2e9d56d..0000000 --- a/lsh/src/connection_commands.c +++ /dev/null @@ -1,69 +0,0 @@ -/* connection_commands.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "connection_commands.h" - -#include "connection.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "connection_commands.h.x" -#undef GABA_DEFINE - -/* (remember connection resource) */ -DEFINE_COMMAND2(connection_remember) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(ssh_connection, connection, a1); - CAST_SUBTYPE(resource, resource, a2); - - if (resource) - REMEMBER_RESOURCE(connection->resources, resource); - - COMMAND_RETURN(c, resource); -} - - -DEFINE_COMMAND(connection_require_userauth) - (struct command *s UNUSED, struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(ssh_connection, connection, a); - - if (connection->user) - COMMAND_RETURN(c, connection); - else - EXCEPTION_RAISE(connection->e, - make_protocol_exception(SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, - "Access denied.")); -} diff --git a/lsh/src/connection_commands.h b/lsh/src/connection_commands.h deleted file mode 100755 index 770985e..0000000 --- a/lsh/src/connection_commands.h +++ /dev/null @@ -1,54 +0,0 @@ -/* connection_commands.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ -#ifndef LSH_CONNECTION_COMMANDS_H_INCLUDED -#define LSH_CONNECTION_COMMANDS_H_INCLUDED - -#include "command.h" - -#define GABA_DECLARE -#include "connection_commands.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name connection_command) - (super command) - (vars - (connection object ssh_connection))) -*/ - -extern struct command_2 connection_remember; -#define CONNECTION_REMEMBER (&connection_remember.super.super) - -struct command * -make_connection_if_srp(struct command *then_f, - struct command *else_f); - -extern struct command_3 connection_if_srp; -#define CONNECTION_IF_SRP (&connection_if_srp_command.super.super) - -extern struct command connection_require_userauth; -#define CONNECTION_REQUIRE_USERAUTH (&connection_require_userauth.super) - -#endif /* LSH_CONNECTION_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/connection_commands.h.x b/lsh/src/connection_commands.h.x deleted file mode 100755 index e03eb33..0000000 Binary files a/lsh/src/connection_commands.h.x and /dev/null differ diff --git a/lsh/src/crypto.h b/lsh/src/crypto.h deleted file mode 100755 index b025fad..0000000 --- a/lsh/src/crypto.h +++ /dev/null @@ -1,82 +0,0 @@ -/* crypto.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_CRYPTO_H_INCLUDED -#define LSH_CRYPTO_H_INCLUDED - -#include "abstract_crypto.h" - -/* Macro to make it easier to loop over several blocks. */ -#define FOR_BLOCKS(length, src, dst, blocksize) \ - assert( !((length) % (blocksize))); \ - for (; (length); ((length) -= (blocksize), \ - (src) += (blocksize), \ - (dst) += (blocksize)) ) - -extern struct crypto_algorithm crypto_arcfour_algorithm; -extern struct crypto_algorithm crypto_des_algorithm; -struct crypto_algorithm *make_des3(void); - -struct crypto_algorithm *make_cast_algorithm(UINT32 key_size); -extern struct crypto_algorithm cast128_algorithm; - -struct crypto_algorithm *make_blowfish_algorithm(UINT32 key_size); -extern struct crypto_algorithm blowfish_algorithm; - -struct crypto_algorithm *make_twofish_algorithm(UINT32 key_size); -extern struct crypto_algorithm twofish128_algorithm; -extern struct crypto_algorithm twofish192_algorithm; -extern struct crypto_algorithm twofish256_algorithm; - -struct crypto_algorithm *make_rijndael_algorithm(UINT32 key_size); -extern struct crypto_algorithm rijndael128_algorithm; -extern struct crypto_algorithm rijndael192_algorithm; -extern struct crypto_algorithm rijndael256_algorithm; - -struct crypto_algorithm *make_serpent_algorithm(UINT32 key_size); -extern struct crypto_algorithm serpent128_algorithm; -extern struct crypto_algorithm serpent192_algorithm; -extern struct crypto_algorithm serpent256_algorithm; - -#ifdef WITH_IDEA -extern struct crypto_algorithm idea_algorithm; -#endif - -extern struct hash_algorithm sha1_algorithm; -extern struct hash_algorithm md5_algorithm; - -struct mac_algorithm *make_hmac_algorithm(struct hash_algorithm *h); - -/* 10 million iterations would take 5 hours on my machine */ -#define PKCS5_MAX_ITERATIONS 10000000 - -void -pkcs5_derive_key(struct mac_algorithm *prf, - UINT32 password_length, const UINT8 *password, - UINT32 salt_length, const UINT8 *salt, - UINT32 iterations, - UINT32 key_length, UINT8 *key); - -#endif /* LSH_CRYPTO_H_INCLUDED */ diff --git a/lsh/src/daemon.c b/lsh/src/daemon.c deleted file mode 100755 index 6f2884a..0000000 --- a/lsh/src/daemon.c +++ /dev/null @@ -1,483 +0,0 @@ -/* daemon.c - * - * Derived from - * http://www.zip.com.au/~raf2/lib/software/daemon - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 raf, Niels Möller - * - * 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 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 should 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 - */ - -#include "daemon.h" - -#include "format.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#include - -/* For setrlimit */ -#include /* Needed on BSD */ -#include - -#include -#include -#include - -#include -#include - -#ifndef PID_DIR -#define PID_DIR "/var/run" -#endif - -#ifndef ROOT_DIR -#define ROOT_DIR "/" -#endif - -#ifndef PID_SUFFIX -#define PID_SUFFIX ".pid" -#endif - -/* -** struct lsh_string *daemon_pidfile(const char *name) -** -** Creates a pid file for a daemon and locks it. -** The file has one line containing the process id of the daemon. -** The well-known location for the file is defined in PID_DIR -** ("/var/run" by default). The name of the file is the name of -** the daemon (given by the name argument) followed by ".pid". -** -** Returns 1 on success or 0 on failure (with errno set -** appropriately). Reasons for failure are: ENAMETOOLONG If the pid -** file's path is longer than the system path limit. open(2). -** fcntl(2). write(2). */ - - -int daemon_pidfile(const char *name) -{ - int fd; - - /* Try to open the file atomically. This provides sufficient locking - * on normal (non-NFS) file systems. */ - - fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0644); - - if (fd < 0) - { - if (errno != EEXIST) - { - werror("Failed to open pid file '%z' (errno = %i): %z\n", - name, errno, STRERROR(errno)); - return 0; - } - - werror("Pid file '%z' already exists.\n", name); - return 0; - - /* FIXME: Various trickery to detect and ignore stale pid files. - * Disabled for now. */ -#if 0 - /* Attempt to lock and read the file */ - { - struct flock lock; - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - - int fd = open(name, O_RDWR); - - if (fcntl(fd, F_SETLK, &lock) < 0) - { - werror("pid file '%z' exists and is locked.\n"); - return 0; - } - } - fd = open(name, O_RDONLY); - if (fd < 0) - { - werror("Pid file '%z' already exists, and is unreadable (errno = %i): %z\n", - name, errno, STRERROR(errno)); - return 0; - } - { - /* Read some characters */ -#define BUF_SIZE 20 - char buffer[BUF_SIZE]; - - int length = read(fd, buffer, BUF_SIZE); - close(fd); - - if (length < 0) - { - werror("Pid file '%z' already exists, but read failed (errno = %i): %z\n", - name, errno, STRERROR(errno)); - return 0; - } - if ( !length|| !buffer[0] || (length == BUF_SIZE) ) - { - werror("Pid file '%z' already exists, but contents is garbled (errno = %i): %z\n", - name, errno, STRERROR(errno)); - return 0; - } - - buffer[length] = '\0'; - - { - long other; - char *end; - - /* FIXME: strtol is somewhat inconvenient, too forgiving, - * and possibly locale dependent. */ - other = strtol(buffer, &end, 10); - errno = 0; - - if ( (errno == ERANGE) || (end != buffer + length) - || (other <= 0) || (other != (pid_t) other)) - { - werror("Pid file '%z' already exists, but contents is garbled (errno = %i): %z\n", - name, errno, STRERROR(errno)); - return 0; - } - - if ( (kill((pid_t) other, 0) < 0) - && (errno == SRCH)) - { - werror("pid lock '%z' owned by process %i, which appear to be dead.\n", - name, other); - /* We could try to be clever and delete the file in this - * case, but then we get into race conditions if two - * processes tries to do that simultaneously. */ - } - else - werror("pid lock '%z' owned by process %i, which appears to be alive.\n"); - return 0; - } - } -#endif - } - else - { - struct lsh_string *pid = ssh_format("%di", getpid()); - - int res = write(fd, pid->data, pid->length); - close(fd); - - if ( (res > 0) && ((unsigned) res == pid->length) ) - { - /* Success! */ - lsh_string_free(pid); - return 1; - } - werror("Writing pid file '%z' failed (errno = %i): %z", - name, errno, STRERROR(errno)); - - /* Attempt unlinking file */ - if (unlink(name) < 0) - werror("Unlinking pid file '%z' failed (errno = %i): %z", - name, errno, STRERROR(errno)); - - lsh_string_free(pid); - - return 0; - } -} - -/* -** int daemon_started_by_init(void) -** -** Determines whether or not this process was started by init(8). -** If it was, we might be getting respawned so fork(2) and exit(2) -** would be a big mistake. -*/ - -int daemon_started_by_init(void) -{ - return (getppid() == 1); -} - -/* -** int daemon_started_by_inetd(void) -** -** Determines whether or not this process was started by inetd(8). -** If it was, stdin, stdout and stderr would be opened to a socket. -** Closing them would be a big mistake. We also wouldn't need to -** fork(2) and exec(2) because there isn't a controlling terminal -** in sight. -*/ - -/* FIXME: Do we need to detect if the socket is listening or connected - * to a peer? */ -int -daemon_started_by_inetd(void) -{ - int optval; - socklen_t optlen = sizeof(optval); - - return (getsockopt(STDIN_FILENO, SOL_SOCKET, SO_TYPE, &optval, &optlen) == 0); -} - -/* Disable core files */ -int -daemon_disable_core(void) -{ - struct rlimit limit = { 0, 0 }; - - /* - ** Disable core files to prevent security holes. - */ - - if (getrlimit(RLIMIT_CORE, &limit) == -1) - return 0; - - limit.rlim_cur = 0; - - if (setrlimit(RLIMIT_CORE, &limit) == -1) - return 0; - - return 1; -} - -/* -** int daemon_init(void) -** -** Initialises a daemon: -** Disables core files to prevent security holes. -** If the process wasn't started by init(8) or inetd(8): -** Backgrounds the process to lose process group leadership. -** Becomes a process session leader. -** When SVR4 is defined: -** Backgrounds the process again to lose process group leadership. -** This prevents the process from gaining a controlling terminal. -** Under BSD, you must still include O_NOCTTY when opening terminals -** to prevent the process from gaining a controlling terminal. -** Changes directory to the root directory so as not to hamper umounts. -** Clears the umask to enable explicit file modes. -** If the process wasn't started by inetd(8): -** Closes all files (as determined by sysconf(2)). -** Opens stdin, stdout and stderr to /dev/null in case something needs them. -** If the hup parameter is non-null, -** Registers a SIGHUP handler. -** If the term parameter is non-null, -** Registers a SIGTERM handler. -** If the name parameter is non-null, -** Places the process id in the file system and locks it. -** -** Returns DAEMON_NORMAL, DAEMON_INIT or DAEMON_INETD on success, 0 on -** error (with errno set appropriately). -** -** Reasons for failure are: getrlimit(2), setrlimit(2), fork(2), chdir(2), -** sysconf(2), open(2), dup2(2), daemon_pidfile(), sigemptyset(2), -** sigaddset(2), sigaction(2). */ - -int daemon_init(void) -{ - int mode = DAEMON_NORMAL; - - if (daemon_started_by_init()) - mode = DAEMON_INIT; - else if (daemon_started_by_inetd()) - mode = DAEMON_INETD; - - /* - ** Don't setup a daemon-friendly process context - ** if started by init(8) or inetd(8). - */ - - if (mode == DAEMON_NORMAL) - { - /* - ** Background the process. - ** Lose process group leadership. - */ - - switch (fork()) - { - case -1: - return 0; - case 0: - /* Child */ - break; - default: - /* Parant */ - exit(0); - } - /* - ** Become a process session leader. - */ - - if (setsid() < 0) - fatal("daemon_init: setsid failed.\n"); - - /* This should not be needed. All potential tty:s should be - * opened with O_NOCTTY. FIXME: What if a user links, say, - * ~/.lsh/authorized_keys to a tty? Perhaps we have to make sure - * that we never ever call open without the O_NOCTTY flag? */ -#if 0 -#ifdef SVR4 - /* - ** Lose process session leadership - ** to prevent gaining a controlling - ** terminal in SVR4. - */ - switch (fork()) - { - case -1: - return 0; - case 0: - break; - default: - exit(0); - } -#endif -#endif - } - - /* - ** Enter the root directory to prevent hampering umounts. - */ - - if (chdir(ROOT_DIR) == -1) - return 0; - - /* - ** Clear umask to enable explicit file modes. - */ - - umask(0); - - { - int fd; - - fd = open("/dev/null", O_RDWR); - - if (fd < 0) - return 0; - - /* Don't close stdin if we are started from inetd. */ - - if ( (mode != DAEMON_INETD) - && (dup2(fd, STDIN_FILENO) < 0)) - { - werror("daemon_init: Failed to redirect stdin to /dev/null.\n"); - close(fd); - return 0; - } - - if ( (dup2(fd, STDOUT_FILENO) < 0) - || (dup2(fd, STDERR_FILENO) < 0) ) - { - werror("daemon_init: Failed to redirect stdout and stderr to /dev/null.\n"); - close(fd); - return 0; - } - - close(fd); - - /* It seems unfriendly to try toclose all fds (and on some - * systems, e.g. the HURD, there are no limits to the number of - * open files. It should be good enough to take care of stdio. */ - -#if 0 - /* - ** Close all open files. - ** Don't forget to open any future - ** tty devices with O_NOCTTY so as - ** to prevent gaining a controlling - ** terminal (not necessary with SVR4). - */ - - if ((nopen = limit_open()) == -1) - return -1; - - for (fd = 0; fd < nopen; ++fd) - close(fd); - - /* - ** Open stdin, stdout and stderr to /dev/null - ** just in case someone expects them to be open. - */ - - if ((fd = open("/dev/null", O_RDWR)) == -1) - return -1; - - /* - ** This is only needed for very strange - ** (hypothetical) posix implementations - ** where STDIN_FILENO != 0 or STDOUT_FILE != 1 - ** or STERR_FILENO != 2 (yeah, right). - */ - - if (fd != STDIN_FILENO) - { - if (dup2(fd, STDIN_FILENO) == -1) - return -1; - - close(fd); - } - - if (dup2(STDIN_FILENO, STDOUT_FILENO) == -1) - return -1; - - if (dup2(STDIN_FILENO, STDERR_FILENO) == -1) - return -1; -#endif - } - -#if 0 - /* - ** Register a SIGHUP handler, if required. - */ - - if (hup && signal_set_handler(SIGHUP, 0, hup) == -1) - return -1; - - /* - ** Register a SIGTERM handler, if required. - */ - - if (term && signal_set_handler(SIGTERM, 0, term) == -1) - return -1; -#endif - - return 1; -} - -/* -** int daemon_close() -** -** Unlinks the daemon's (locked) process id file. -*/ - -int daemon_close(const char *name) -{ - if (unlink(name) < 0) - { - werror("daemon_close: Unlink of pid file '%z' failed (errno = %i): %z\n", - name, errno, STRERROR(errno)); - return 0; - } - return 1; -} diff --git a/lsh/src/daemon.h b/lsh/src/daemon.h deleted file mode 100755 index 71d49ff..0000000 --- a/lsh/src/daemon.h +++ /dev/null @@ -1,52 +0,0 @@ -/* daemon.h - * - * Derived from - * http://www.zip.com.au/~raf2/lib/software/daemon - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 raf, Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_DAEMON_H_INCLUDED -#define LSH_DAEMON_H_INCLUDED - -#include "lsh.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define DAEMON_NORMAL 1 -#define DAEMON_INIT 2 -#define DAEMON_INETD 3 - -int daemon_started_by_init(void); -int daemon_started_by_inetd(void); -int daemon_disable_core(void); -int daemon_pidfile(const char *name); -int daemon_init(void); -int daemon_close(const char *name); - -#ifdef __cplusplus -} -#endif - -#endif /* LSH_DAEMON_H_INCLUDED */ diff --git a/lsh/src/debug.c b/lsh/src/debug.c deleted file mode 100755 index 76ce62e..0000000 --- a/lsh/src/debug.c +++ /dev/null @@ -1,144 +0,0 @@ -/* debug.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "debug.h" - -#include "connection.h" -#include "format.h" -#include "parse.h" -#include "ssh.h" -#include "xalloc.h" -#include "werror.h" - -#include "debug.c.x" - -#if MACOS -#include "lsh_context.h" -#endif - -/* GABA: - (class - (name packet_debug) - (super abstract_write_pipe) - (vars - (prefix string))) -*/ - -static void -do_debug(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(packet_debug, closure, w); - - if (!packet->length) - debug("DEBUG: %S empty packet\n", closure->prefix); - else - { - UINT8 type = packet->data[0]; - if (type == SSH_MSG_USERAUTH_REQUEST) - debug("DEBUG: %S %z *****\n", - closure->prefix, packet_types[type]); - else - debug("DEBUG: %S %z %xS\n", - closure->prefix, packet_types[type], - packet); - } - A_WRITE(closure->super.next, packet); -} - -struct abstract_write * -make_packet_debug(struct abstract_write *next, - struct lsh_string *prefix) -{ - NEW(packet_debug, closure); - - closure->super.super.write = do_debug; - closure->super.next = next; - closure->prefix = prefix; - - return &closure->super.super; -} - - -static struct lsh_string * -make_debug_packet(const char *msg, int always_display) -{ - return ssh_format("%c%c%z%z", - SSH_MSG_DEBUG, - always_display, - msg, - /* Empty language tag */ - ""); -} - -/* Send a debug message to the other end. */ -void -send_debug_message(struct abstract_write *write, const char *msg, int always_display) -{ - A_WRITE(write, make_debug_packet(msg, always_display)); -} - -void -send_debug(struct abstract_write *write, const char *msg, int always_display) -{ - if (debug_flag) - send_debug_message(write, msg, always_display); -} - -void -send_verbose(struct abstract_write *write, const char *msg, int always_display) -{ - if (verbose_flag) - send_debug_message(write, msg, always_display); -} - -DEFINE_PACKET_HANDLER(, connection_debug_handler, connection UNUSED, packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - unsigned always_display; - UINT32 length; - const UINT8 *msg; - int language; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (!(parse_uint8(&buffer, &msg_number) - && parse_uint8(&buffer, &always_display) - && parse_string(&buffer, &length, &msg) - && parse_atom(&buffer, &language) - && parse_eod(&buffer))) - { - PROTOCOL_ERROR(connection->e, "Invalid DEBUG message."); - } - else - { - if (always_display) - werror("Received debug: %ups\n", length, msg); - - else - verbose("Received debug: %ups\n", length, msg); - } -} diff --git a/lsh/src/debug.c.x b/lsh/src/debug.c.x deleted file mode 100755 index 704c699..0000000 Binary files a/lsh/src/debug.c.x and /dev/null differ diff --git a/lsh/src/debug.h b/lsh/src/debug.h deleted file mode 100755 index 3245840..0000000 --- a/lsh/src/debug.h +++ /dev/null @@ -1,43 +0,0 @@ -/* debug.h - * - * Packet processor dumping packets to a file. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_DEBUG_H_INCLUDED -#define LSH_DEBUG_H_INCLUDED - -#include -#include "abstract_io.h" -#include "connection.h" - -struct abstract_write * -make_packet_debug(struct abstract_write *continuation, - struct lsh_string *prefix); - -void send_debug_message(struct abstract_write *write, const char *msg, int always_display); -void send_debug(struct abstract_write *write, const char *msg, int always_display); -void send_verbose(struct abstract_write *write, const char *msg, int always_display); - -extern struct packet_handler connection_debug_handler; - -#endif /* LSH_DEBUG_H_INCLUDED */ diff --git a/lsh/src/des.c b/lsh/src/des.c deleted file mode 100755 index a8486d2..0000000 --- a/lsh/src/des.c +++ /dev/null @@ -1,115 +0,0 @@ -/* des.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/des.h" - -#include - -#include "des.c.x" - -/* GABA: - (class - (name des_instance) - (super crypto_instance) - (vars - (ctx . "struct des_ctx"))) -*/ - -static void do_des_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(des_instance, self, s); - - des_encrypt(&self->ctx, length, dst, src); -} - -static void do_des_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(des_instance, self, s); - - des_decrypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_des_instance(struct crypto_algorithm *algorithm UNUSED, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(des_instance, self); - UINT8 pkey[DES_KEY_SIZE]; - unsigned i; - - /* Fix odd parity */ - for (i=0; i> 4); - p ^= (p >> 2); - p ^= (p >> 1); - pkey[i] = key[i] ^ (p & 1) ^ 1; -#if 0 - debug("make_des_instance: computing parity: key[%i] = %xi,\n" - " pkey[%i] = %xi,\n" - " parity = %xi\n", - i, key[i], i, pkey[i], p); -#endif - } - - self->super.block_size = DES_BLOCK_SIZE; - self->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_des_encrypt - : do_des_decrypt); - - if (des_set_key(&self->ctx, pkey)) - return &self->super; - - switch(self->ctx.status) - { - case DES_BAD_PARITY: - fatal("Internal error! Bad parity in make_des_instance.\n"); - case DES_WEAK_KEY: - werror("Detected weak DES key.\n"); - KILL(self); - return NULL; - default: - fatal("Internal error!\n"); - } -} - -struct crypto_algorithm crypto_des_algorithm = -{ STATIC_HEADER, - DES_BLOCK_SIZE, DES_KEY_SIZE, 0, make_des_instance }; - -struct crypto_algorithm *make_des3(void) -{ - return crypto_cascade(3, - &crypto_des_algorithm, - crypto_invert(&crypto_des_algorithm), - &crypto_des_algorithm, - -1); -} diff --git a/lsh/src/des.c.x b/lsh/src/des.c.x deleted file mode 100755 index 60f8565..0000000 Binary files a/lsh/src/des.c.x and /dev/null differ diff --git a/lsh/src/dh_exchange.c b/lsh/src/dh_exchange.c deleted file mode 100755 index 3327786..0000000 --- a/lsh/src/dh_exchange.c +++ /dev/null @@ -1,230 +0,0 @@ -/* dh_exchange.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "publickey_crypto.h" - -#include "connection.h" -#include "crypto.h" -#include "format.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -void -init_dh_instance(struct dh_method *m, - struct dh_instance *self, - struct ssh_connection *c) -{ - struct lsh_string *s; - /* FIXME: The allocator could do this kind of initialization - * automatically. */ - mpz_init(self->e); - mpz_init(self->f); - mpz_init(self->secret); - - self->K = NULL; - - self->method = m; - self->hash = MAKE_HASH(m->H); - self->exchange_hash = NULL; - - debug("init_dh_instance\n" - " V_C: %pS\n", c->versions[CONNECTION_CLIENT]); - debug(" V_S: %pS\n", c->versions[CONNECTION_SERVER]); - debug(" I_C: %xS\n", c->literal_kexinits[CONNECTION_CLIENT]); - debug(" I_S: %xS\n", c->literal_kexinits[CONNECTION_SERVER]); - - s = ssh_format("%S%S%S%S", - c->versions[CONNECTION_CLIENT], - c->versions[CONNECTION_SERVER], - c->literal_kexinits[CONNECTION_CLIENT], - c->literal_kexinits[CONNECTION_SERVER]); - HASH_UPDATE(self->hash, s->length, s->data); - - lsh_string_free(s); -} - -struct dh_method * -make_dh(struct abstract_group *G, struct hash_algorithm *H, - struct randomness *r) -{ - NEW(dh_method, res); - res->G = G; - res->H = H; - res->random = r; - - return res; - -} - -struct dh_method * -make_dh1(struct randomness *r) -{ - return make_dh(make_ssh_group1(), &sha1_algorithm, r); -} - -/* R is set to a random, secret, exponent, and V set to is g^r */ -void -dh_generate_secret(struct dh_method *self, - mpz_t r, mpz_t v) -{ - mpz_t tmp; - - /* Generate a random number, 1 < x <= p-1 = O(G) */ - mpz_init_set(tmp, self->G->order); - mpz_sub_ui(tmp, tmp, 1); - bignum_random(r, self->random, tmp); - mpz_add_ui(r, r, 1); - mpz_clear(tmp); - - GROUP_POWER(self->G, v, self->G->generator, r); -} - -struct lsh_string * -dh_make_client_msg(struct dh_instance *self) -{ - dh_generate_secret(self->method, self->secret, self->e); - return ssh_format("%c%n", SSH_MSG_KEXDH_INIT, self->e); -} - -int -dh_process_client_msg(struct dh_instance *self, - struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - mpz_t tmp; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (! (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_KEXDH_INIT) - && parse_bignum(&buffer, self->e, 0) - && (mpz_cmp_ui(self->e, 1) > 0) - && GROUP_RANGE(self->method->G, self->e) - && parse_eod(&buffer) )) - return 0; - - mpz_init(tmp); - - GROUP_POWER(self->method->G, tmp, self->e, self->secret); - self->K = ssh_format("%ln", tmp); - - mpz_clear(tmp); - - return 1; -} - -void -dh_hash_update(struct dh_instance *self, - struct lsh_string *s, int free) -{ - debug("dh_hash_update: %xS\n", s); - - HASH_UPDATE(self->hash, s->length, s->data); - if (free) - lsh_string_free(s); -} - -/* Hashes e, f, and the shared secret key */ -void -dh_hash_digest(struct dh_instance *self) -{ - dh_hash_update(self, ssh_format("%n%n%S", - self->e, self->f, - self->K), 1); - self->exchange_hash = lsh_string_alloc(self->hash->hash_size); - HASH_DIGEST(self->hash, self->exchange_hash->data); - - debug("dh_hash_digest: %xS\n", self->exchange_hash); -} - -void -dh_make_server_secret(struct dh_instance *self) -{ - dh_generate_secret(self->method, self->secret, self->f); -} - -struct lsh_string * -dh_make_server_msg(struct dh_instance *self, - struct lsh_string *server_key, - int hostkey_algorithm, - struct signer *s) -{ - dh_hash_update(self, ssh_format("%S", server_key), 1); - dh_hash_digest(self); - - return ssh_format("%c%S%n%fS", - SSH_MSG_KEXDH_REPLY, - server_key, - self->f, SIGN(s, hostkey_algorithm, - self->exchange_hash->length, - self->exchange_hash->data)); -} - -/* Returns the host key. */ -struct lsh_string * -dh_process_server_msg(struct dh_instance *self, - struct lsh_string **signature, - struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - mpz_t tmp; - - struct lsh_string *key = NULL; - struct lsh_string *s = NULL; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (! (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_KEXDH_REPLY) - && (key = parse_string_copy(&buffer)) - /* FIXME: Pass a more restrictive limit to parse_bignum. */ - && (parse_bignum(&buffer, self->f, 0)) - && (mpz_cmp_ui(self->f, 1) > 0) - && GROUP_RANGE(self->method->G, self->f) - && (s = parse_string_copy(&buffer)) - && parse_eod(&buffer))) - { - lsh_string_free(key); - lsh_string_free(s); - return NULL; - } - - mpz_init(tmp); - - GROUP_POWER(self->method->G, tmp, self->f, self->secret); - self->K = ssh_format("%ln", tmp); - - mpz_clear(tmp); - - dh_hash_update(self, ssh_format("%S", key), 1); - dh_hash_digest(self); - - *signature = s; - return key; -} - diff --git a/lsh/src/digit_table.c b/lsh/src/digit_table.c deleted file mode 100755 index f942061..0000000 --- a/lsh/src/digit_table.c +++ /dev/null @@ -1,91 +0,0 @@ -/* digit_table.c - * - * Generate the tables for reading hex and base64. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -/* Defines int sexp_char_classes[0x100] */ -#define CHAR_CLASSES_TABLE sexp_char_classes -#include "sexp_table.h" -#undef CHAR_CLASSES_TABLE -#include "sexp_table.h" - -#include "lsh_types.h" - -#include - -static void write_table(int *table) -{ - unsigned i; - - printf("{"); - for (i = 0; i<0x100; i++) - { - if (!(i % 16)) - printf("\n "); - printf("%2d", table[i]); - if (i != 0xff) - printf(","); - } - printf("\n}"); -} - -int main(int argc UNUSED, char **argv UNUSED) -{ - int table[0x100]; - unsigned i; - const UINT8 base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - - printf("/* Automatically generated by digits_table.c.\n" - " * Do not edit. */\n\n"); - - for (i = 0; i<0x100; i++) - table[i] = -1; - - for (i = 0; i <= 9; i++) - table['0' + i] = i; - - for (i = 0; i < 6; i++) - table['a' + i] = table['A' + i] = 10 + i; - - table['#'] = -2; - - printf("int hex_digits[0x100] =\n"); - write_table(table); - printf(";\n\n"); - - for (i = 0; i<0x100; i++) - table[i] = (sexp_char_classes[i] & CHAR_base64_space) - ? -3 : -1; - - for(i = 0; i<64; i++) - table[base64[i]] = i; - - printf("int base64_digits[0x100] =\n"); - write_table(table); - printf(";\n\n"); - - return 0; -} diff --git a/lsh/src/digit_table.h b/lsh/src/digit_table.h deleted file mode 100755 index aa2762e..0000000 --- a/lsh/src/digit_table.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Automatically generated by digits_table.c. - * Do not edit. */ - -int hex_digits[0x100] = -{ - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -}; - -int base64_digits[0x100] = -{ - -1,-1,-1,-1,-1,-1,-1,-1,-1,-3,-3,-1,-1,-3,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, - 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-3,-1,-1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, - 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, - -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, - 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -}; - diff --git a/lsh/src/digits.c b/lsh/src/digits.c deleted file mode 100755 index add35b4..0000000 --- a/lsh/src/digits.c +++ /dev/null @@ -1,133 +0,0 @@ -/* digits.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "digits.h" - -#include "digit_table.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -void -base64_init(struct base64_state *state, UINT8 terminator) -{ - state->buffer = 0; - state->bits = 0; - state->terminator = terminator; -} - -int -base64_decode(struct base64_state *state, UINT8 c) -{ - unsigned res; - int digit; - - assert(state->bits < 8); - if (c == state->terminator) - { - /* Check for unused bits */ - if (state->bits && ( ( (1<bits) - 1) & state->buffer)) - { - werror("base64_decode: Base64 terminated with %i leftover bits.\n", - state->bits); - return BASE64_INVALID; - } - return BASE64_END; - } - - digit = base64_digits[c]; - switch(digit) - { - case BASE64_SPACE: - case BASE64_INVALID: - return digit; - default: - assert(digit >= 0); - state->buffer = (state->buffer << 6) | (unsigned) digit; - state->bits += 6; - } - if (state->bits < 8) - return BASE64_PARTIAL; - - res = (state->buffer >> (state->bits - 8)) & 0xff; - state->bits -= 8; - - return res; -} - -struct lsh_string * -simple_decode_hex(const unsigned char *in) -{ - unsigned length = strlen(in); - unsigned i, j; - - struct lsh_string *out; - - assert(!(length % 2)); - out = lsh_string_alloc(length/2); - - for (i = j = 0; i= 0); - assert(d2 >= 0); - - out->data[j++] = (d1 << 4) | d2; - } - - return out; -} - -struct lsh_string * -decode_base64(UINT32 length, const UINT8 *in) -{ - struct base64_state state; - struct lsh_string *out = lsh_string_alloc(length * 3 / 4 + 1); - UINT32 i; - UINT32 j; - - base64_init(&state, 0); - for (i=0, j=0; ilength); - out->data[j++] = digit; - } - } - out->length = j; - return out; -} diff --git a/lsh/src/digits.h b/lsh/src/digits.h deleted file mode 100755 index ad318e8..0000000 --- a/lsh/src/digits.h +++ /dev/null @@ -1,67 +0,0 @@ -/* digits.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_DIGITS_H_INCLUDED -#define LSH_DIGITS_H_INCLUDED - -#include "lsh_types.h" - -#define HEX_INVALID -1 -#define HEX_END -2 - -extern int hex_digits[0x100]; - -#define BASE64_INVALID -1 -#define BASE64_END -2 -#define BASE64_SPACE -3 -#define BASE64_PARTIAL -4 - -extern int base64_digits[0x100]; - -struct base64_state -{ - /* Bits are shifted into the buffer from the right, 6 at a time */ - unsigned buffer; - /* Bits currently in the buffer */ - unsigned bits; - - UINT8 terminator; -}; - -#define BASE64_INIT(t) {0, 0, (t)} - -void -base64_init(struct base64_state *state, UINT8 terminator); - -int -base64_decode(struct base64_state *state, UINT8 c); - -struct lsh_string * -decode_base64(UINT32 length, const UINT8 *in); - - -/* Only used by the testsuite */ -struct lsh_string * -simple_decode_hex(const unsigned char *in); - -#endif /* LSH_DIGITS_H_INCLUDED */ diff --git a/lsh/src/disconnect.c b/lsh/src/disconnect.c deleted file mode 100755 index aef6022..0000000 --- a/lsh/src/disconnect.c +++ /dev/null @@ -1,79 +0,0 @@ -/* disconnect.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "disconnect.h" - -#include "connection.h" -#include "format.h" -#include "parse.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -struct lsh_string *format_disconnect(int code, const char *msg, - const char *language) -{ - return ssh_format("%c%i%z%z", - SSH_MSG_DISCONNECT, - code, - msg, language); -} - -static void -do_disconnect(struct packet_handler *closure UNUSED, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - UINT32 reason; - - UINT32 length; - const UINT8 *msg; - - const UINT8 *language; - UINT32 language_length; - - static const struct exception disconnect_exception = - STATIC_EXCEPTION(EXC_FINISH_IO, "Received disconnect message."); - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_DISCONNECT) - && (parse_uint32(&buffer, &reason)) - && (parse_string(&buffer, &length, &msg)) - && (parse_string(&buffer, &language_length, &language)) - && parse_eod(&buffer)) - { - /* FIXME: Display a better message */ - werror("Disconnect for reason %i: %ups\n", reason, length, msg); - } - else - werror("Invalid disconnect message!\n"); - - EXCEPTION_RAISE(connection->e, &disconnect_exception); -} - -struct packet_handler disconnect_handler = -{ STATIC_HEADER, do_disconnect }; diff --git a/lsh/src/disconnect.h b/lsh/src/disconnect.h deleted file mode 100755 index 1811d8c..0000000 --- a/lsh/src/disconnect.h +++ /dev/null @@ -1,34 +0,0 @@ -/* disconnect.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_DISCONNECT_H_INCLUDED -#define LSH_DISCONNECT_H_INCLUDED - -#include "lsh_types.h" - -struct lsh_string *format_disconnect(int code, const char *msg, - const char *language); - -extern struct packet_handler disconnect_handler; - -#endif /* LSH_DISCONNECT_H_INCLUDED */ diff --git a/lsh/src/dsa.c b/lsh/src/dsa.c deleted file mode 100755 index e473bca..0000000 --- a/lsh/src/dsa.c +++ /dev/null @@ -1,634 +0,0 @@ -/* dsa.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "dsa.h" - -#include "atoms.h" -#include "crypto.h" -#include "format.h" -#include "parse.h" -#include "sexp.h" -#include "spki.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include "nettle/sha1.h" - -#include - -#include "dsa.c.x" - -/* The standard says that DSA public keys are at most 1024 bits, i.e. - * 128 octets. We are a little more liberal than that. Note that - * allowing really large keys opens for Denial-of-service attacks. */ - -#define DSA_MAX_SIZE 300 - -#define DSA_MAX_QSIZE SHA1_DIGEST_SIZE - -#define SA(x) sexp_a(ATOM_##x) - -/* DSA signatures */ - -/* GABA: - (class - (name dsa_algorithm) - (super signature_algorithm) - (vars - (random object randomness))) -*/ - -/* GABA: - (class - (name dsa_verifier) - (super verifier) - (vars - (p bignum) - (q bignum) - (g bignum) - (y bignum))) -*/ - -/* GABA: - (class - (name dsa_signer) - (super signer) - (vars - (verifier object dsa_verifier) - (random object randomness) - (a bignum))) -*/ - - -/* Utility functions */ - -static void -dsa_hash(mpz_t h, UINT32 length, const UINT8 *msg) -{ - /* Compute hash */ - UINT8 digest[SHA1_DIGEST_SIZE]; - struct sha1_ctx ctx; - sha1_init(&ctx); - sha1_update(&ctx, length, msg); - sha1_final(&ctx); - sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - - bignum_parse_u(h, SHA1_DIGEST_SIZE, digest); - - debug("DSA hash: %xn\n", h); -} - -static struct sexp * -encode_dsa_sig_val(mpz_t r, mpz_t s) -{ - return sexp_l(2, sexp_l(2, SA(R), sexp_un(r), -1), - sexp_l(2, SA(S), sexp_un(s), -1), -1); -} - -static int -decode_dsa_sig_val(struct sexp *e, mpz_t r, mpz_t s) -{ - if (sexp_atomp(e)) - return 0; - else - { - struct sexp_iterator *i = SEXP_ITER(e); - return ( (SEXP_LEFT(i) == 2) - && sexp_get_un(i, ATOM_R, r, DSA_MAX_QSIZE) - && sexp_get_un(i, ATOM_S, s, DSA_MAX_QSIZE)); - } -} - - -/* Verifying DSA signatures */ - -/* The caller should make sure that r and s are non-negative, and not - * extremely large. That they are less than q is checked here. */ -static int -generic_dsa_verify(struct dsa_verifier *key, - UINT32 length, - const UINT8 *msg, - mpz_t r, mpz_t s) -{ - mpz_t w, tmp, v; - int res; - - debug("generic_dsa_verify, r: %xn\n" - " s: %xn\n", r, s); - - if ( (mpz_cmp(r, key->q) >= 0) - || (mpz_cmp(s, key->q) >= 0) ) - return 0; - - /* Compute w = s^-1 (mod q) */ - mpz_init(w); - - /* NOTE: In gmp-2, mpz_invert sometimes generates negative inverses. */ - if (!mpz_invert(w, s, key->q)) - { - werror("generic_dsa_verify: s non-invertible.\n"); - mpz_clear(w); - return 0; - } - - debug("generic_dsa_verify, w: %xn\n", w); - - /* Compute hash */ - mpz_init(tmp); - dsa_hash(tmp, length, msg); - - /* g^{w * h (mod q)} (mod p) */ - - mpz_init(v); - - mpz_mul(tmp, tmp, w); - mpz_fdiv_r(tmp, tmp, key->q); - - debug("u1: %xn\n", tmp); - - mpz_powm(v, key->g, tmp, key->p); - - /* y^{w * r (mod q) } (mod p) */ - mpz_mul(tmp, r, w); - mpz_fdiv_r(tmp, tmp, key->q); - - debug("u2: %xn\n", tmp); - - mpz_powm(tmp, key->y, tmp, key->p); - - /* (g^{w * h} * y^{w * r} (mod p) ) (mod q) */ - mpz_mul(v, v, tmp); - mpz_fdiv_r(v, v, key->p); - - debug("generic_dsa_verify, group element: %xn\n", v); - - mpz_fdiv_r(v, v, key->q); - - debug("generic_dsa_verify, v: %xn\n", v); - - res = !mpz_cmp(v, r); - - mpz_clear(w); - mpz_clear(tmp); - mpz_clear(v); - - return res; -} - -static int -do_dsa_verify(struct verifier *c, int algorithm, - UINT32 length, - const UINT8 *msg, - UINT32 signature_length, - const UINT8 *signature_data) -{ - CAST(dsa_verifier, self, c); - struct simple_buffer buffer; - - int res = 0; - - mpz_t r, s; - - trace("do_dsa_verify: Verifying %a signature\n", algorithm); - - mpz_init(r); - mpz_init(s); - - switch (algorithm) - { - case ATOM_SSH_DSS: - { - /* NOTE: draft-ietf-secsh-transport-X.txt (x <= 07) uses an extra - * length field, which should be removed in the next version. */ - - UINT32 buf_length; - const UINT8 *buf; - int atom; - - simple_buffer_init(&buffer, signature_length, signature_data); - if (!(parse_atom(&buffer, &atom) - && (atom == ATOM_SSH_DSS) - && parse_string(&buffer, &buf_length, &buf) - && !(buf_length % 2) - && (buf_length <= (2 * DSA_MAX_QSIZE)) - && parse_eod(&buffer))) - goto fail; - - buf_length /= 2; - - bignum_parse_u(r, buf_length, buf); - bignum_parse_u(s, buf_length, buf + buf_length); - - break; - } - -#if DATAFELLOWS_WORKAROUNDS - case ATOM_SSH_DSS_KLUDGE_LOCAL: - { - UINT32 buf_length; - - /* NOTE: This doesn't include any length field. Is that right? */ - - if ( (signature_length % 2) - || (signature_length > (2 * DSA_MAX_QSIZE)) ) - goto fail; - - buf_length = signature_length / 2; - - bignum_parse_u(r, buf_length, signature_data); - bignum_parse_u(s, buf_length, signature_data + buf_length); - break; - } -#endif - /* It doesn't matter here which flavour of SPKI is used. */ - case ATOM_SPKI_SIGN_RSA: - case ATOM_SPKI_SIGN_DSS: - { - struct simple_buffer buffer; - struct sexp *e; - - simple_buffer_init(&buffer, signature_length, signature_data); - - if (! ( (e = sexp_parse_canonical(&buffer)) - && parse_eod(&buffer) - && decode_dsa_sig_val(e, r, s)) ) - goto fail; - - break; - } - default: - fatal("do_dsa_verify: Internal error!\n"); - } - res = generic_dsa_verify(self, length, msg, r, s); - fail: - mpz_clear(r); - mpz_clear(s); - - return res; -} - -static int -do_dsa_verify_spki(struct verifier *c, - UINT32 length, - const UINT8 *msg, - struct sexp *e) -{ - CAST(dsa_verifier, self, c); - - int res; - mpz_t r, s; - - mpz_init(r); - mpz_init(s); - - /* NOTE: With the current definition of sexp_get_un, there are no - * requirements on the order in which r and s occur. */ - res = (decode_dsa_sig_val(e, r, s) - && generic_dsa_verify(self, length, msg, r, s)); - - mpz_clear(r); - mpz_clear(s); - - return res; -} - -static struct lsh_string * -do_dsa_public_key(struct verifier *s) -{ - CAST(dsa_verifier, self, s); - return ssh_format("%a%n%n%n%n", - ATOM_SSH_DSS, - self->p, self->q, - self->g, self->y); -} - -static struct sexp * -do_dsa_public_spki_key(struct verifier *s) -{ - CAST(dsa_verifier, self, s); - - return sexp_l(5, SA(DSA), - sexp_l(2, SA(P), sexp_un(self->p), -1), - sexp_l(2, SA(Q), sexp_un(self->q), -1), - sexp_l(2, SA(G), sexp_un(self->g), -1), - sexp_l(2, SA(Y), sexp_un(self->y), -1), - -1); -} - -static void -init_dsa_verifier(struct dsa_verifier *self) -{ - /* FIXME: The allocator could do this kind of initialization - * automatically. */ - mpz_init(self->p); - mpz_init(self->q); - mpz_init(self->g); - mpz_init(self->y); - - self->super.verify = do_dsa_verify; - self->super.verify_spki = do_dsa_verify_spki; - self->super.public_spki_key = do_dsa_public_spki_key; - self->super.public_key = do_dsa_public_key; -} - -static struct dsa_verifier * -make_dsa_verifier_internal(struct sexp_iterator *i) -{ - NEW(dsa_verifier, res); - init_dsa_verifier(res); - - assert(SEXP_LEFT(i) >= 4); - - if (sexp_get_un(i, ATOM_P, res->p, DSA_MAX_SIZE) - && sexp_get_un(i, ATOM_Q, res->q, DSA_MAX_QSIZE) - && sexp_get_un(i, ATOM_G, res->g, DSA_MAX_SIZE) - && sexp_get_un(i, ATOM_Y, res->y, DSA_MAX_SIZE)) - { - return res; - } - else - { - KILL(res); - return NULL; - } -} - -/* Alternative constructor using a key of type ssh-dss, when the atom - * "ssh-dss" is already read from the buffer. */ -struct verifier * -parse_ssh_dss_public(struct simple_buffer *buffer) -{ - NEW(dsa_verifier, res); - init_dsa_verifier(res); - - if (parse_bignum(buffer, res->p, DSA_MAX_SIZE) - && (mpz_sgn(res->p) == 1) - && parse_bignum(buffer, res->q, DSA_MAX_QSIZE) - && (mpz_sgn(res->q) == 1) - && (mpz_cmp(res->q, res->p) < 0) /* q < p */ - && parse_bignum(buffer, res->g, DSA_MAX_SIZE) - && (mpz_sgn(res->g) == 1) - && (mpz_cmp(res->g, res->p) < 0) /* g < p */ - && parse_bignum(buffer, res->y, DSA_MAX_SIZE) - && (mpz_sgn(res->y) == 1) - && (mpz_cmp(res->y, res->p) < 0) /* y < p */ - && parse_eod(buffer)) - - return &res->super; - - else - { - KILL(res); - return NULL; - } -} - - -/* Creating signatures */ -static void -generic_dsa_sign(struct dsa_signer *self, - UINT32 length, const UINT8 *msg, - mpz_t r, mpz_t s) -{ - mpz_t k, tmp; - - assert(r && s); - - /* Select k, 0verifier->q); - mpz_sub_ui(tmp, tmp, 1); - - mpz_init(k); - bignum_random(k, self->random, tmp); - mpz_add_ui(k, k, 1); - - /* NOTE: Enabling this leaks information about the secret - * key to the debug output. */ - /* debug("generic_dsa_sign, k: %xn\n", k); */ - - /* Compute r = (g^k (mod p)) (mod q) */ - mpz_powm(r, self->verifier->g, k, self->verifier->p); - - debug("generic_dsa_sign, group element: %xn\n", r); - - mpz_fdiv_r(r, r, self->verifier->q); - - debug("generic_dsa_sign, r: %xn\n", r); - - /* Compute hash */ - dsa_hash(tmp, length, msg); - - /* Compute k^-1 (mod q) */ - if (!mpz_invert(k, k, self->verifier->q)) - { - fatal("generic_dsa_sign: k non-invertible\n"); - } - - /* Compute signature s = k^-1(h + ar) (mod q) */ - mpz_mul(s, r, self->a); - mpz_fdiv_r(s, s, self->verifier->q); - mpz_add(s, s, tmp); - mpz_mul(s, s, k); - mpz_fdiv_r(s, s, self->verifier->q); - - debug("generic_dsa_sign, s: %xn\n", s); - - mpz_clear(k); - mpz_clear(tmp); -} - -static UINT32 -dsa_blob_length(mpz_t r, mpz_t s) -{ - UINT32 r_length = bignum_format_u_length(r); - UINT32 s_length = bignum_format_u_length(s); - - return MAX(r_length, s_length); -} - -static void -dsa_blob_write(mpz_t r, mpz_t s, UINT32 length, UINT8 *buf) -{ - bignum_write(r, length, buf); - bignum_write(s, length, buf + length); -} - -static struct lsh_string * -do_dsa_sign(struct signer *c, - int algorithm, - UINT32 msg_length, - const UINT8 *msg) -{ - CAST(dsa_signer, self, c); - mpz_t r, s; - struct lsh_string *signature; - UINT32 buf_length; - UINT8 *p; - - trace("do_dsa_sign: Signing according to %a\n", algorithm); - - mpz_init(r); mpz_init(s); - generic_dsa_sign(self, msg_length, msg, r, s); - - /* Build signature */ - buf_length = dsa_blob_length(r, s); - - switch (algorithm) - { - case ATOM_SSH_DSS: - /* NOTE: draft-ietf-secsh-transport-X.txt (x <= 07) uses an extra - * length field, which should be removed in the next version. */ - signature = ssh_format("%a%r", ATOM_SSH_DSS, buf_length * 2, &p); - dsa_blob_write(r, s, buf_length, p); - - break; - -#if DATAFELLOWS_WORKAROUNDS - case ATOM_SSH_DSS_KLUDGE_LOCAL: - - /* NOTE: This doesn't include any length field. Is that right? */ - signature = ssh_format("%lr", buf_length * 2, &p); - dsa_blob_write(r, s, buf_length, p); - - break; - -#endif - /* It doesn't matter here which flavour of SPKI is used. */ - case ATOM_SPKI_SIGN_RSA: - case ATOM_SPKI_SIGN_DSS: - - /* NOTE: Generates the only. */ - signature - = sexp_format(encode_dsa_sig_val(r, s), - SEXP_CANONICAL, 0); - - break; - default: - fatal("do_dsa_sign: Internal error."); - } - mpz_clear(r); - mpz_clear(s); - - return signature; -} - -static struct sexp * -do_dsa_sign_spki(struct signer *c, - /* struct sexp *hash, struct sexp *principal, */ - UINT32 msg_length, - const UINT8 *msg) -{ - CAST(dsa_signer, self, c); - mpz_t r, s; - struct sexp *signature; - - mpz_init(r); mpz_init(s); - generic_dsa_sign(self, msg_length, msg, r, s); - - /* Build signature */ - signature = encode_dsa_sig_val(r, s); - - mpz_clear(r); - mpz_clear(s); - - return signature; -} - -static struct verifier * -do_dsa_get_verifier(struct signer *s) -{ - CAST(dsa_signer, self, s); - return &self->verifier->super; -} - - -static struct verifier * -make_dsa_verifier(struct signature_algorithm *self UNUSED, - struct sexp_iterator *i) -{ - return ( (SEXP_LEFT(i) == 4) - ? &make_dsa_verifier_internal(i)->super - : NULL); -} - -static struct signer * -make_dsa_signer(struct signature_algorithm *c, - struct sexp_iterator *i) -{ - CAST(dsa_algorithm, self, c); - NEW(dsa_signer, res); - mpz_init(res->a); - -#if 0 - debug("make_dsa_signer: SEXP_LEFT(i) == %i\n"); - debug("make_dsa_signer: SEXP_GET(i) == %fS\n", - sexp_format(SEXP_GET(i), SEXP_ADVANCED, 0)); -#endif - - if ( (SEXP_LEFT(i) == 5) - && ( (res->verifier = make_dsa_verifier_internal(i)) ) - && sexp_get_un(i, ATOM_X, res->a, DSA_MAX_QSIZE) ) - { - res->random = self->random; - res->super.sign = do_dsa_sign; - res->super.sign_spki = do_dsa_sign_spki; - res->super.get_verifier = do_dsa_get_verifier; - - return &res->super; - } - else - { - KILL(res); - return NULL; - } -} - -struct signature_algorithm * -make_dsa_algorithm(struct randomness *random) -{ - NEW(dsa_algorithm, dsa); - - dsa->super.make_signer = make_dsa_signer; - dsa->super.make_verifier = make_dsa_verifier; - dsa->random = random; - - return &dsa->super; -} - - -struct verifier * -make_ssh_dss_verifier(UINT32 public_length, - const UINT8 *public) -{ - struct simple_buffer buffer; - int atom; - - simple_buffer_init(&buffer, public_length, public); - - return ( (parse_atom(&buffer, &atom) - && (atom == ATOM_SSH_DSS)) - ? parse_ssh_dss_public(&buffer) - : NULL); -} diff --git a/lsh/src/dsa.c.x b/lsh/src/dsa.c.x deleted file mode 100755 index 3bd5970..0000000 Binary files a/lsh/src/dsa.c.x and /dev/null differ diff --git a/lsh/src/dsa.h b/lsh/src/dsa.h deleted file mode 100755 index 81a5c41..0000000 --- a/lsh/src/dsa.h +++ /dev/null @@ -1,50 +0,0 @@ -/* dsa.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_DSA_H_INCLUDED -#define LSH_DSA_H_INCLUDED - -#include "bignum.h" -#include "publickey_crypto.h" - -/* DSA signatures */ - -struct signature_algorithm * -make_dsa_algorithm(struct randomness *random); - -/* Non spki keys */ -struct verifier * -parse_ssh_dss_public(struct simple_buffer *buffer); - -struct verifier * -make_ssh_dss_verifier(UINT32 public_length, - const UINT8 *public); - -void dsa_nist_gen(mpz_t p, mpz_t q, struct randomness *r, unsigned l); -void dsa_find_generator(mpz_t g, struct randomness *r, mpz_t p, mpz_t q); - -struct sexp * -dsa_generate_key(struct randomness *r, unsigned level); - -#endif /* LSH_DSA_H_INCLUDED */ diff --git a/lsh/src/dsa_keygen.c b/lsh/src/dsa_keygen.c deleted file mode 100755 index 3c21110..0000000 --- a/lsh/src/dsa_keygen.c +++ /dev/null @@ -1,268 +0,0 @@ -/* dsa_keygen.c - * - * Generate dsa key pairs.. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "dsa.h" - -#include "randomness.h" -#include "sexp.h" -#include "werror.h" - -#include "nettle/sha1.h" - -#if !HAVE_MEMXOR -#include "nettle/memxor.h" -#endif - -#include - -#define SA(x) sexp_a(ATOM_##x) - -/* The (slow) NIST method of generating DSA primes. Algorithm 4.56 of - * Handbook of Applied Cryptography. */ - -#define SEED_LENGTH SHA1_DIGEST_SIZE -#define SEED_BITS (SEED_LENGTH * 8) - -static void -hash(mpz_t x, UINT8 *digest) -{ - mpz_t t; - UINT8 data[SEED_LENGTH]; - struct sha1_ctx ctx; - - mpz_init_set(t, x); - mpz_fdiv_r_2exp(t, t, SEED_BITS); - - bignum_write(t, SEED_LENGTH, data); - mpz_clear(t); - - sha1_init(&ctx); - sha1_update(&ctx, SEED_LENGTH, data); - sha1_final(&ctx); - sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); -} - -void -dsa_nist_gen(mpz_t p, mpz_t q, struct randomness *r, unsigned l) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - unsigned L; - unsigned n, b; - mpz_t s, t, c; - - assert(l <= 8); - - L = 512 + 64*l; - n = (L-1) / 160; b = (L-1) % 160; - - mpz_init(s); - mpz_init(t); - mpz_init(c); - - for (;;) - { - { /* Generate q */ - UINT8 h1[SHA1_DIGEST_SIZE]; - UINT8 h2[SHA1_DIGEST_SIZE]; - - bignum_random_size(s, r, SEED_BITS); - - hash(s, h1); - - mpz_set(t, s); - mpz_add_ui(t, t, 1); - - hash(t, h2); - - memxor(h1, h2, SHA1_DIGEST_SIZE); - - h1[0] |= 0x80; - h1[SHA1_DIGEST_SIZE - 1] |= 1; - - bignum_parse_u(q, SHA1_DIGEST_SIZE, h1); - - if (bignum_small_factor(q, 1000) - || !mpz_probab_prime_p(q, 18)) - /* Try new seed. */ - continue; - } - /* q is a prime, with overwelming probability. */ - - { - unsigned size = (n+1) * SHA1_DIGEST_SIZE; - UINT8 *buffer = alloca(size); - unsigned i, j; - - for (i = 0, j = 2; i<4096; i++, j+= n+1) - { - unsigned k; - -#if MACOS - extern void ssh2_sched(); - ssh2_sched(); -#endif - for (k = 0; k<=n ; k++) - { - mpz_set(t, s); - mpz_add_ui(t, t, j + k); - hash(t, buffer + ( (n-k) * SHA1_DIGEST_SIZE)); - } - bignum_parse_u(p, size, buffer); - - mpz_fdiv_r_2exp(p, p, L); - mpz_setbit(p, L-1); - - mpz_set(t, q); - mpz_mul_2exp(t, t, 1); - - mpz_fdiv_r(c, p, t); - - mpz_sub_ui(c, c, 1); - - mpz_sub(p, p, c); - - if (!bignum_small_factor(p, 1000) - && mpz_probab_prime_p(p, 5)) - { - /* Done! */ - mpz_clear(s); - mpz_clear(t); - mpz_clear(c); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - } - } - } -} - -void -dsa_find_generator(mpz_t g, struct randomness *r, mpz_t p, mpz_t q) -{ - mpz_t e; - mpz_t n; - - /* e = (p-1)/q */ - mpz_init_set(e, p); - mpz_sub_ui(e, e, 1); - mpz_divexact(e, e, q); - - /* n = p-2 = |2, 3, ... p-1| */ - mpz_init_set(n, p); - mpz_sub_ui(n, n, 2); - - for (;;) - { -#if MACOS - extern void ssh2_sched(); - ssh2_sched(); -#endif - bignum_random(g, r, n); - mpz_add_ui(g, g, 2); - - mpz_powm(g, g, e, p); - if (mpz_cmp_ui(g, 1)) - { - /* g != 1. Finished. */ - mpz_clear(e); - mpz_clear(n); - - return; - } - } -} - -struct sexp * -dsa_generate_key(struct randomness *r, unsigned level) -{ - struct sexp *key = NULL; - - mpz_t p; mpz_t q; - mpz_t g; mpz_t y; - mpz_t x; - mpz_t t; - - mpz_init(p); mpz_init(q); - mpz_init(g); mpz_init(y); - mpz_init(x); - mpz_init(t); - - dsa_nist_gen(p, q, r, level); - - debug("p = %xn\nq = %xn\n", p, q); - - /* Sanity check. */ - if (!mpz_probab_prime_p(p, 10)) - { - werror("p not a prime!\n"); - goto done; - } - - if (!mpz_probab_prime_p(q, 10)) - { - werror("q not a prime!\n"); - goto done; - } - - mpz_fdiv_r(t, p, q); - if (mpz_cmp_ui(t, 1)) - { - fatal("q doesn't divide p-1 !\n"); - goto done; - } - - dsa_find_generator(g, r, p, q); - - mpz_set(t, q); - mpz_sub_ui(t, t, 2); - bignum_random(x, r, t); - - mpz_add_ui(x, x, 1); - - mpz_powm(y, g, x, p); - - key = sexp_l(2, SA(PRIVATE_KEY), - sexp_l(6, SA(DSA), - sexp_l(2, SA(P), sexp_un(p), -1), - sexp_l(2, SA(Q), sexp_un(q), -1), - sexp_l(2, SA(G), sexp_un(g), -1), - sexp_l(2, SA(Y), sexp_un(y), -1), - sexp_l(2, SA(X), sexp_un(x), -1), -1), -1); - - done: - - mpz_clear(p); mpz_clear(q); - mpz_clear(g); mpz_clear(y); - mpz_clear(x); - mpz_clear(t); - - return key; -} diff --git a/lsh/src/encrypt.c b/lsh/src/encrypt.c deleted file mode 100755 index 998fa1f..0000000 --- a/lsh/src/encrypt.c +++ /dev/null @@ -1,92 +0,0 @@ -/* encrypt.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "encrypt.h" - -#include "format.h" -#include "xalloc.h" - -#include - -#include "encrypt.c.x" - -/* GABA: - (class - (name packet_encrypt) - (super abstract_write_pipe) - (vars - (sequence_number . UINT32) - (connection object ssh_connection))) -*/ - -static void -do_encrypt(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(packet_encrypt, closure, w); - struct ssh_connection *connection = closure->connection; - struct lsh_string *new; - UINT8 *mac; - - new = ssh_format("%lr%lr", packet->length, NULL, - connection->send_mac ? connection->send_mac->mac_size : 0, - &mac); - - if (connection->send_crypto) - CRYPT(connection->send_crypto, packet->length, packet->data, new->data); - else - memcpy(new->data, packet->data, packet->length); - - if (connection->send_mac) - { - UINT8 s[4]; - WRITE_UINT32(s, closure->sequence_number); - - HASH_UPDATE(connection->send_mac, 4, s); - HASH_UPDATE(connection->send_mac, packet->length, packet->data); - HASH_DIGEST(connection->send_mac, mac); - } - lsh_string_free(packet); - - closure->sequence_number++; - - A_WRITE(closure->super.next, new); -} - -struct abstract_write * -make_packet_encrypt(struct abstract_write *next, - struct ssh_connection *connection) -{ - NEW(packet_encrypt, closure); - - closure->super.super.write = do_encrypt; - closure->super.next = next; - closure->sequence_number = 0; - closure->connection = connection; - - return &closure->super.super; -} - - diff --git a/lsh/src/encrypt.c.x b/lsh/src/encrypt.c.x deleted file mode 100755 index 654b45e..0000000 Binary files a/lsh/src/encrypt.c.x and /dev/null differ diff --git a/lsh/src/encrypt.h b/lsh/src/encrypt.h deleted file mode 100755 index f1d9931..0000000 --- a/lsh/src/encrypt.h +++ /dev/null @@ -1,37 +0,0 @@ -/* encrypt.h - * - * Handler to encrypt and authenticate packets. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ENCRYPT_H_INCLUDED -#define LSH_ENCRYPT_H_INCLUDED - -#include "abstract_io.h" -#include "abstract_crypto.h" -#include "connection.h" - -struct abstract_write * -make_packet_encrypt(struct abstract_write *continuation, - struct ssh_connection *connection); - -#endif /* LSH_ENCRYPT_H_INCLUDED */ diff --git a/lsh/src/exception.c b/lsh/src/exception.c deleted file mode 100755 index 200cf4d..0000000 --- a/lsh/src/exception.c +++ /dev/null @@ -1,171 +0,0 @@ -/* exception.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "exception.h" - -#include "io.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "exception.h.x" -#undef GABA_DEFINE - -#include "exception.c.x" - -static void -do_default_handler(struct exception_handler *ignored UNUSED, - const struct exception *e) -{ - fatal("Unhandled exception of type 0x%xi: %z\n", e->type, e->msg); -} - -struct exception_handler default_exception_handler = -STATIC_EXCEPTION_HANDLER(do_default_handler, NULL); - -static void -do_ignore_exception_handler(struct exception_handler *self UNUSED, - const struct exception *e UNUSED) -{} - -struct exception_handler ignore_exception_handler = -STATIC_EXCEPTION_HANDLER(do_ignore_exception_handler, NULL); - -struct exception_handler * -make_exception_handler(void (*raise)(struct exception_handler *s, - const struct exception *x), - struct exception_handler *parent, - const char *context) -{ - NEW(exception_handler, self); - self->raise = raise; - self->parent = parent; - self->context = context; - - return self; -} - -struct report_exception_info * -make_report_exception_info(UINT32 mask, UINT32 value, - const char *prefix) -{ - NEW(report_exception_info, self); - - self->mask = mask; - self->value = value; - self->prefix = prefix; - - return self; -} - -/* GABA: - (class - (name report_exception_handler) - (super exception_handler) - (vars - (info object report_exception_info))) -*/ - -static void -do_report_exception_handler(struct exception_handler *s, - const struct exception *x) -{ - CAST(report_exception_handler, self, s); - struct report_exception_info *info = self->info; - - if ( (x->type & info->mask) == info->value) - werror("%z exception: %z\n", info->prefix, x->msg); - else - EXCEPTION_RAISE(self->super.parent, x); -} - -struct exception_handler * -make_report_exception_handler(struct report_exception_info *info, - struct exception_handler *parent, - const char *context) -{ - NEW(report_exception_handler, self); - self->super.raise = do_report_exception_handler; - self->super.parent = parent; - self->super.context = context; - - self->info = info; - - return &self->super; -} - -struct exception *make_simple_exception(UINT32 type, const char *msg) -{ - NEW(exception, e); - e->type = type; - e->msg = msg; - - return e; -} - -/* Reason == 0 means disconnect without sending any disconnect - * message. */ - -struct exception * -make_protocol_exception(UINT32 reason, const char *msg) -{ - NEW(protocol_exception, self); - -#define MAX_REASON 15 - const char *messages[MAX_REASON+1] = - { - NULL, "Host not allowed to connect", - "Protocol error", "Key exchange failed", - "Host authentication failed", "MAC error", - "Compression error", "Service not available", - "Protocol version not supported", "Host key not verifiable", - "Connection lost", "By application", - "Too many connections", "Auth cancelled by user", - "No more auth methods available", "Illegal user name" - }; - - assert(reason <= MAX_REASON); - assert(reason != SSH_DISCONNECT_RESERVED); -#undef MAX_REASON - - self->super.type = EXC_PROTOCOL; - self->super.msg = msg ? msg : messages[reason]; - - self->reason = reason; - - return &self->super; -} - -#if DEBUG_TRACE -void exception_raise(struct exception_handler *h, - const struct exception *e, - const char *context) -{ - trace ("%z: Raising exception %z (type %i), using handler installed by %z\n", - context, e->msg, e->type, h->context); - h->raise(h, e); -} -#endif /* DEBUG_TRACE */ diff --git a/lsh/src/exception.c.x b/lsh/src/exception.c.x deleted file mode 100755 index 0a250c3..0000000 Binary files a/lsh/src/exception.c.x and /dev/null differ diff --git a/lsh/src/exception.h b/lsh/src/exception.h deleted file mode 100755 index 0967737..0000000 --- a/lsh/src/exception.h +++ /dev/null @@ -1,214 +0,0 @@ -/* exception.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_EXCEPTION_H_INCLUDED -#define LSH_EXCEPTION_H_INCLUDED - -#include "lsh.h" - -#define GABA_DECLARE -#include "exception.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name exception) - (vars - (type . UINT32) - (msg . "const char *"))) -*/ - -#define STATIC_EXCEPTION(type, name) \ -{ STATIC_HEADER, (type), (name) } - -/* GABA: - (class - (name exception_handler) - (vars - (raise method void "const struct exception *") - (parent object exception_handler) - - ; Provide some context for debugging unhandled exceptions - (context . "const char *"))) -*/ - -void exception_raise(struct exception_handler *e, - const struct exception *h, - const char *context); - -#if DEBUG_TRACE -# define EXCEPTION_RAISE(h, e) exception_raise((h), (e), HANDLER_CONTEXT) -#else /* !DEBUG_TRACE */ -# define EXCEPTION_RAISE(h, e) ((h)->raise((h), (e))) -#endif /* !DEBUG_TRACE */ - -/* NOTE: This is pretty useless, as it requires that the parent be - * static as well. Used only for the default_exception_handler and - * ignore_exception_handler, and perhaps some others with NULL parent. - * */ -#define STATIC_EXCEPTION_HANDLER(r, p) \ -{ STATIC_HEADER, (r), (p), __FILE__ ":" STRING_LINE ": Static" } - - -#define HANDLER_CONTEXT (__FILE__ ":" STRING_LINE ": " FUNCTION_NAME) - - -/* Exception types. */ - -/* FIXME: This is an inappropriate name, as this exception type is - * used for all events that should result in a disconnect message. */ - -/* Protocol errors */ -#define EXC_PROTOCOL 0x1000 - -/* IO related errors */ -#define EXC_IO 0x2000 -#define EXC_IO_CONNECT 0x2001 -#define EXC_IO_BLOCKING_WRITE 0x2003 -#define EXC_IO_BLOCKING_READ 0x2004 -#define EXC_IO_READ 0x2005 -#define EXC_IO_WRITE 0x2006 -#define EXC_IO_OPEN_WRITE 0x2007 -#define EXC_IO_OPEN_READ 0x2008 -#define EXC_IO_LISTEN 0x2009 -#define EXC_IO_CLOSE 0x200A - -/* Authorization errors */ -#define EXC_AUTH 0x4000 -#define EXC_USERAUTH 0x4001 - -/* Implies an exception struct with a reply packet in it. */ -#define EXC_USERAUTH_SPECIAL 0x4002 - -/* Services */ -#define EXC_SERVICE 0x8000 -#define EXC_GLOBAL_REQUEST 0x8001 -#define EXC_CHANNEL_REQUEST 0x8002 - -/* Use subtypes for the different error codes? */ -#define EXC_CHANNEL_OPEN 0x8003 - -/* Closing down things */ -#define EXC_FINISH 0x10000 - -/* Close a channel */ -#define EXC_FINISH_CHANNEL 0x10001 - -/* Stop reading on some fd */ -#define EXC_FINISH_READ 0x10002 - -/* Close the connection immediately */ -#define EXC_FINISH_IO 0x10003 - -/* Put the connection into pending-close mode, - * i.e. don't open any new channels, and close it - * as soon as all channels are gone. */ -#define EXC_FINISH_PENDING 0x10004 - -/* DNS errors */ -#define EXC_RESOLVE 0x20001 - -/* SEXP parse errors */ -#define EXC_SEXP 0x40000 -#define EXC_SEXP_SYNTAX 0x40001 -#define EXC_SEXP_EOF 0x40002 - -/* SPKI errors */ -#define EXC_SPKI 0x80000 -/* Unexpected or unsupported expression type */ -#define EXC_SPKI_TYPE 0x80001 - -/* Pausing, used to temporarily stop reading packets on a connection. */ -#define EXC_PAUSE 0x100000 - -#define EXC_PAUSE_READ 0x100001 -#define EXC_PAUSE_START_READ 0x100002 -#define EXC_PAUSE_CONNECTION 0x100003 -#define EXC_PAUSE_START_CONNECTION 0x100004 - -#define EXC_RANDOMNESS 0x200000 -#define EXC_RANDOMNESS_LOW_ENTROPY 0x200001 - -/* Application specific exceptions */ -#define EXC_APP 0x400000 - -#define EXC_ALL (~0) - -extern struct exception_handler default_exception_handler; -extern struct exception_handler ignore_exception_handler; - -/* GABA: - (class - (name report_exception_info) - (vars - (mask . UINT32) - (value . UINT32) - (prefix . "const char *"))) -*/ - -struct report_exception_info * -make_report_exception_info(UINT32 mask, UINT32 value, - const char *prefix); - -#define STATIC_REPORT_EXCEPTION_INFO(m, v, p) \ -{ STATIC_HEADER, m, v, p } - -struct exception_handler * -make_report_exception_handler(struct report_exception_info *info, - struct exception_handler *parent, - const char *context); - -struct exception * -make_simple_exception(UINT32 type, const char *msg); - -/* Create a simple exception handler, with no internal state */ -struct exception_handler * -make_exception_handler(void (*raise)(struct exception_handler *s, - const struct exception *x), - struct exception_handler *parent, - const char *context); - -/* A protocol exception, that normally terminates the connection */ -/* GABA: - (class - (name protocol_exception) - (super exception) - (vars - ; A reason code that can be passed in a SSH_MSG_DISCONNECT message. - ; Zero means terminate the connection without sending such a message. - (reason . UINT32))) -*/ - - -/* If msg is NULL, it is derived from the reason value */ -struct exception * -make_protocol_exception(UINT32 reason, const char *msg); - -#define STATIC_PROTOCOL_EXCEPTION(reason, msg) \ -{ { STATIC_HEADER, EXC_PROTOCOL, (msg) }, (reason) } - -#define PROTOCOL_ERROR(e, msg) \ -EXCEPTION_RAISE((e), \ - make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR, (msg))) - -#endif /* LSH_EXCEPTION_H_INCLUDED */ diff --git a/lsh/src/exception.h.x b/lsh/src/exception.h.x deleted file mode 100755 index 37d2f61..0000000 Binary files a/lsh/src/exception.h.x and /dev/null differ diff --git a/lsh/src/format.c b/lsh/src/format.c deleted file mode 100755 index 3a26de8..0000000 --- a/lsh/src/format.c +++ /dev/null @@ -1,629 +0,0 @@ -/* format.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "format.h" - -#include "list.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -struct lsh_string *ssh_format(const char *format, ...) -{ - va_list args; - UINT32 length; - struct lsh_string *packet; - - va_start(args, format); - length = ssh_vformat_length(format, args); - va_end(args); - - packet = lsh_string_alloc(length); - - va_start(args, format); - ssh_vformat_write(format, length, packet->data, args); - va_end(args); - - return packet; -} - -UINT32 ssh_format_length(const char *format, ...) -{ - va_list args; - UINT32 length; - - va_start(args, format); - length = ssh_vformat_length(format, args); - va_end(args); - - return length; -} - -void ssh_format_write(const char *format, UINT32 length, UINT8 *buffer, ...) -{ - va_list args; - - va_start(args, buffer); - ssh_vformat_write(format, length, buffer, args); - va_end(args); -} - -static int write_decimal_length(UINT8 *buffer, UINT32 n); -static void format_hex_string(UINT8 *buffer, UINT32 length, const UINT8 *data); - -UINT32 ssh_vformat_length(const char *f, va_list args) -{ - UINT32 length = 0; - - while(*f) - { - if (*f == '%') - { - int literal = 0; - int decimal = 0; - int unsigned_form = 0; - int hex = 0; - - while(*++f) - { - switch (*f) - { - case 'l': - literal = 1; - break; - case 'd': - decimal = 1; - break; - case 'f': - /* Do nothing */ - break; - case 'u': - unsigned_form = 1; - break; - case 'x': - hex = 1; - break; - default: - goto end_options; - } - } -end_options: - - if (literal && decimal) - fatal("Internal error!\n"); - - switch(*f++) - { - case 'c': - (void) va_arg(args, int); - /* Fall through */ - case '%': - length++; - break; - - case 'i': - { - UINT32 i = va_arg(args, UINT32); - if (decimal) - length += format_size_in_decimal(i); - else - length += 4; - break; - } - - case 's': - { - UINT32 l = va_arg(args, UINT32); /* String length */ - (void) va_arg(args, const UINT8 *); /* data */ - - length += l; - - if (hex) - length += l; - - if (decimal) - length += format_size_in_decimal(l) + 1; - else if (!literal) - length += 4; - - break; - } - case 'S': - { - struct lsh_string *s = va_arg(args, struct lsh_string *); - length += s->length; - - if (hex) - length += s->length; - - if (decimal) - length += format_size_in_decimal(s->length) + 1; - else if (!literal) - length += 4; - - break; - } - case 'z': - { - unsigned l = strlen(va_arg(args, const char *)); - length += l; - - if (decimal) - length += format_size_in_decimal(l) + 1; - - else if (!literal) - length += 4; - break; - } - case 'r': - { - UINT32 l = va_arg(args, UINT32); - length += l; - (void) va_arg(args, UINT8 **); /* pointer */ - - if (decimal) - length += format_size_in_decimal(l) + 1; - else if (!literal) - length += 4; - - break; - } - case 'a': - { - int atom = va_arg(args, int); - int l; - - assert(atom); - - l = get_atom_length(atom); - length += l; - - if (decimal) - length += format_size_in_decimal(l) + 1; - else if (!literal) - length += 4; - - break; - } - case 'A': - { - struct int_list *l = va_arg(args, struct int_list *); - UINT32 n, i; - - if (decimal) - fatal("ssh_format: Decimal lengths not supported for %%A\n"); - - for(n = i =0; i < LIST_LENGTH(l); i++) - { - if (LIST(l)[i]) - { - n++; - length += get_atom_length(LIST(l)[i]); - } - } - if (n) - /* One ','-character less than the number of atoms */ - length += (n-1); - - if (!literal) - length += 4; - - break; - } - case 'n': - { - MP_INT *n = va_arg(args, MP_INT*); - - /* Calculate length of written number */ - unsigned l; - if (unsigned_form) - { - assert(mpz_sgn(n) >= 0); - l = bignum_format_u_length(n); - } - else - l = bignum_format_s_length(n); - - length += l; - - /* Decimal not supported. */ - assert(!decimal); -#if 0 - if (decimal) - { - length += format_size_in_decimal(l) + 1; - } - else -#endif - if (!literal) - length += 4; - - break; - } - default: - fatal("ssh_vformat_length: bad format string"); - break; - } - } - else - { - length++; - f++; - } - } - return length; -} - -void ssh_vformat_write(const char *f, UINT32 size, UINT8 *buffer, va_list args) -{ - UINT8 *start = buffer; - - while(*f) - { - if (*f == '%') - { - int literal = 0; - int do_free = 0; - int decimal = 0; - int hex = 0; - int unsigned_form = 0; - - while(*++f) - { - switch (*f) - { - case 'l': - literal = 1; - break; - case 'd': - decimal = 1; - break; - case 'f': - do_free = 1; - break; - case 'u': - unsigned_form = 1; - break; - case 'x': - hex = 1; - break; - default: - goto end_options; - } - } - end_options: - - if (literal && decimal) - fatal("Internal error!\n"); - - switch(*f++) - { - case 'c': - *buffer++ = va_arg(args, int); - - break; - case '%': - *buffer++ = '%'; - - break; - - case 'i': - { - UINT32 i = va_arg(args, UINT32); - if (decimal) - { - unsigned length = format_size_in_decimal(i); - format_decimal(length, buffer, i); - buffer += length; - } - else - { - WRITE_UINT32(buffer, i); - buffer += 4; - } - break; - } - - case 's': - { - UINT32 size = va_arg(args, UINT32); - const UINT8 *data = va_arg(args, const UINT8 *); - - UINT32 length = hex ? (2*size) : size; - - if (decimal) - buffer += write_decimal_length(buffer, length); - else if (!literal) - { - WRITE_UINT32(buffer, length); - buffer += 4; - } - - if (hex) - format_hex_string(buffer, size, data); - else - memcpy(buffer, data, size); - - buffer += length; - - break; - } - case 'S': - { - struct lsh_string *s = va_arg(args, struct lsh_string *); - UINT32 length = s->length; - - if (hex) - length *= 2; - - if (decimal) - buffer += write_decimal_length(buffer, length); - - else if (!literal) - { - WRITE_UINT32(buffer, length); - buffer += 4; - } - - if (hex) - format_hex_string(buffer, s->length, s->data); - else - memcpy(buffer, s->data, s->length); - - buffer += length; - - if (do_free) - lsh_string_free(s); - - break; - } - case 'z': - { - const char *s = va_arg(args, const char *); - UINT32 length = strlen(s); - - if (decimal) - buffer += write_decimal_length(buffer, length); - - if (!literal) - { - WRITE_UINT32(buffer, length); - buffer += 4; - } - - memcpy(buffer, s, length); - buffer += length; - - break; - } - case 'r': - { - UINT32 length = va_arg(args, UINT32); - UINT8 **p = va_arg(args, UINT8 **); - - if (decimal) - buffer += write_decimal_length(buffer, length); - else if (!literal) - { - WRITE_UINT32(buffer, length); - buffer += 4; - } - - if (p) - *p = buffer; - buffer += length; - - break; - } - - case 'a': - { - UINT32 length; - int atom = va_arg(args, int); - - assert(atom); - - length = get_atom_length(atom); - - if (decimal) - buffer += write_decimal_length(buffer, length); - else if (!literal) - { - WRITE_UINT32(buffer, length); - buffer += 4; - } - - memcpy(buffer, get_atom_name(atom), length); - buffer += length; - - break; - } - case 'A': - { - struct int_list *l = va_arg(args, struct int_list *); - UINT8 *start = buffer; /* Where to store the length */ - UINT32 n, i; - - if (decimal) - fatal("ssh_format: Decimal lengths not supported for %%A\n"); - - if (!literal) - buffer += 4; - - for(n = i = 0; i < LIST_LENGTH(l); i++) - { - if (LIST(l)[i]) - { - UINT32 length = get_atom_length(LIST(l)[i]); - - if (n) - /* Not the first atom */ - *buffer++ = ','; - - memcpy(buffer, get_atom_name(LIST(l)[i]), length); - buffer += length; - - n++; - } - } - - if (!literal) - { - UINT32 total = buffer - start - 4; - WRITE_UINT32(start, total); - } - break; - } - case 'n': - { - MP_INT *n = va_arg(args, MP_INT *); - UINT32 length; - UINT8 *start = buffer; /* Where to store the length */ - - /* Decimal not supported */ - assert(!decimal); - - if (!literal) - buffer += 4; - - if (unsigned_form) - { - assert(mpz_sgn(n) >= 0); - - length = bignum_format_u(n, buffer); - } - else - length = bignum_format_s(n, buffer); - - buffer += length; - - if (!literal) - WRITE_UINT32(start, length); - - break; - } - default: - fatal("ssh_vformat_write: bad format string"); - break; - } - } - else - { - *buffer++ = *f++; - } - } - - assert(buffer == start + size); -} - -unsigned format_size_in_decimal(UINT32 n) -{ - int i; - int e; - - /* Table of 10^(2^n) */ - static const UINT32 powers[] = { 10UL, 100UL, 10000UL, 100000000UL }; - -#define SIZE (sizeof(powers) / sizeof(powers[0])) - - /* Determine the smallest e such that n < 10^e */ - for (i = SIZE - 1 , e = 0; i >= 0; i--) - { - if (n >= powers[i]) - { - e += 1UL << i; - n /= powers[i]; - } - } - -#undef SIZE - - return e+1; -} - - -static void format_hex_string(UINT8 *buffer, UINT32 length, const UINT8 *data) -{ - static const UINT8 hexchars[16] = "0123456789abcdef"; - UINT32 i; - - for (i = 0; i < length; i++) - { - *buffer++ = hexchars[ (data[i] & 0xf0) >> 4 ]; - *buffer++ = hexchars[ data[i] & 0x0f ]; - } -} - -void format_decimal(unsigned length, UINT8 *buffer, UINT32 n) -{ - unsigned i; - - for (i = 0; idata, '\0', s->length) ? s->data : NULL); -} - -int -lsh_string_eq(const struct lsh_string *a, const struct lsh_string *b) -{ - return ( (a->length == b->length) - && !memcmp(a->data, b->data, a->length)); -} - -int -lsh_string_eq_l(const struct lsh_string *a, - UINT32 length, const UINT8 *b) -{ - return ( (a->length == length) - && !memcmp(a->data, b, length)); -} - -int -lsh_string_prefixp(const struct lsh_string *prefix, - const struct lsh_string *s) -{ - return ( (prefix->length <= s->length) - && !memcmp(prefix->data, s->data, prefix->length)); -} diff --git a/lsh/src/format.h b/lsh/src/format.h deleted file mode 100755 index 0a59dcf..0000000 --- a/lsh/src/format.h +++ /dev/null @@ -1,108 +0,0 @@ -/* format.h - * - * Create a packet from a format string and arguments. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_FORMAT_H_INCLUDED -#define LSH_FORMAT_H_INCLUDED - -#include - -#include "atoms.h" -#include "bignum.h" - -/* Format strings can contain the following %-specifications: - * - * %% Insert a %-sign - * - * %c Insert an 8-bit character - * - * %i Insert a 32-bit integer, in network byte order - * - * %s Insert a string, given by a length and a pointer. - * - * %S Insert a string, given as a struct lsh_string pointer. - * - * %z Insert a string, using a null-terminated argument. - * - * %r Reserves space in the string, and stores a pointer to this space - * into the given UINT8 ** argument. - * - * %a Insert a string containing one atom. - * - * %A Insert a string containing a list of atoms. The input is an - * int_list object. Zero elements are allowed and ignored. - * - * %X Insert a string containing a list of atoms. The corresponding - * argument sublist should be terminated with a zero. (Not used) - * - * %n Insert a string containing a bignum. - * - * There are three valid modifiers: - * - * "l" (as in literal). It is applicable to the s, a, A, n and r - * specifiers, and outputs strings *without* a length field. - * - * "d" (as in decimal). For integers, convert the integer to decimal - * digits. For strings, format the input string using sexp syntax; - * i.e. prefixed with the length in decimal. - * - * "x" (as in heXadecimal). For strings, format each character as two - * hexadecimal digits. Does not currently mean any thing for numbers. - * Note that this modifier is orthogonal to the decimal modifier. - * - * "f" (as in free). Frees the input string after it has been copied. - * Applicable to %S only. - * - * "u" (as in unsigned). Used with bignums, to use unsigned-only - * number format. */ - -struct lsh_string *ssh_format(const char *format, ...); -UINT32 ssh_format_length(const char *format, ...); -void ssh_format_write(const char *format, UINT32 length, UINT8 *buffer, ...); - -UINT32 ssh_vformat_length(const char *format, va_list args); -void ssh_vformat_write(const char *format, UINT32 length, UINT8 *buffer, va_list args); - -/* FIXME: Do we need a variant that handles non-const strings? */ -/* Returns an ordinary NUL-terminated string, or NULL if the string - * contains any NUL-character. */ -const char * -lsh_get_cstring(const struct lsh_string *s); - -/* Short cuts */ -#define lsh_string_dup(s) (ssh_format("%lS", (s))) - -#define make_string(s) (ssh_format("%lz", (s))) - -unsigned format_size_in_decimal(UINT32 n); -void format_decimal(unsigned length, UINT8 *buffer, UINT32 n); - -/* FIXME: This function doesn't really belong here */ -int lsh_string_eq(const struct lsh_string *a, const struct lsh_string *b); -int lsh_string_eq_l(const struct lsh_string *a, UINT32 length, const UINT8 *b); - -int lsh_string_prefixp(const struct lsh_string *prefix, - const struct lsh_string *s); - -#endif /* LSH_FORMAT_H_INCLUDED */ diff --git a/lsh/src/gateway.c b/lsh/src/gateway.c deleted file mode 100755 index d3f4014..0000000 --- a/lsh/src/gateway.c +++ /dev/null @@ -1,103 +0,0 @@ -/* gateway.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "gateway.h" - -#include "format.h" -#include "io.h" - -/* A gateway is a mechanism to delegate some channels to a separate - * process. The main lsh process opens a unix domain socket, and other - * processes can connect and read and write cleartext ssh packets. - * Packets written to the gateway socket are forwarded to the remote - * server. And certain packets received from the remote server are - * delegated and can be read from the gateway. */ - - -/* The gateway socket is named "TMP/x-lsh-USER/HOST%REMOTE-USER". - * - * The choice of the '%' separator in the socket name makes sure we - * don't collide with any valid dns names, or with literal IPv4 or IPv6 - * addresses. And it should be really rare in usernames. */ - -static int -check_string_l(unsigned length, const UINT8 *s) -{ - unsigned i; - for (i = 0; iip->length, target->ip->data)) - return make_local_info(ssh_format("%lz/x-lsh-%lz", tmp, local_user), - ssh_format("%lS:%lz", target->ip, remote_user)); - else - return NULL; -} - -/* Keeps track of one connection to the gateway. */ - -/* ;;GABA: - (class - (name gateway) - (vars - ; Where to send packets - (local object abstract_write))) -*/ - diff --git a/lsh/src/gateway.h b/lsh/src/gateway.h deleted file mode 100755 index e1f4c6f..0000000 --- a/lsh/src/gateway.h +++ /dev/null @@ -1,36 +0,0 @@ -/* gateway.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef GATEWAY_H_INCLUDED -#define GATEWAY_H_INCLUDED - -#include "lsh.h" - -/* Formats the address of the local gateway socket. */ - -struct local_info * -make_gateway_address(char *local_user, char *remote_user, - struct address_info *target); - -#endif /* GATEWAY_H_INCLUDED */ diff --git a/lsh/src/gateway_channel.c b/lsh/src/gateway_channel.c deleted file mode 100755 index f7e145e..0000000 --- a/lsh/src/gateway_channel.c +++ /dev/null @@ -1,384 +0,0 @@ -/* gateway_channel.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "gateway_channel.h" - -#include "channel_commands.h" -#include "format.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#define GABA_DEFINE -#include "gateway_channel.h.x" -#undef GABA_DEFINE - -#include "gateway_channel.c.x" - -/* A pair of gateway_channel objects are chained together so that - * requests and data received on one of the channels are directed to - * the other. - * - * Chaining happens as follows: - * - * 1. First a CHANNEL_OPEN request is received on one connection, and - * a channel object is created. We refer to this object as the - * _originating_ channel. - * - * 2. Next, we send a similar CHANNEL_OPEN request on some other - * connection, and create a channel object referred to as the - * _target_ channel. - * - * 3. When we receive a reply to the CHANNEL_OPEN request sent in (2), - * we chain the two channel objects together, and reply to the - * CHANNEL_OPEN request we received in (1). */ - -/* FIXME: A gateway may want to handle unknown types of channel data. */ -static void -do_receive(struct ssh_channel *c, - int type, - struct lsh_string *data) -{ - CAST(gateway_channel, channel, c); - - switch(type) - { - case CHANNEL_DATA: - C_WRITE(channel->chain->super.connection, - channel_transmit_data(&channel->chain->super, data)); - break; - case CHANNEL_STDERR_DATA: - C_WRITE(channel->chain->super.connection, - channel_transmit_extended(&channel->chain->super, CHANNEL_STDERR_DATA, data)); - break; - default: - fatal("Internal error!\n"); - } -} - -/* We may send more data */ -static void -do_send_adjust(struct ssh_channel *s, - UINT32 i) -{ - CAST(gateway_channel, self, s); - FLOW_CONTROL_REPORT(&self->chain->super.super, i); -} - -static void -do_eof(struct ssh_channel *c) -{ - CAST(gateway_channel, channel, c); - channel_eof(&channel->chain->super); -} - -static void -do_close(struct ssh_channel *c) -{ - CAST(gateway_channel, channel, c); - channel_close(&channel->chain->super); -} - -static void -gateway_init_io(struct gateway_channel *channel) -{ - channel->super.send_adjust = do_send_adjust; - channel->super.receive = do_receive; - channel->super.eof = do_eof; - channel->super.close = do_close; -} - -/* NOTE: We don't initialize the rec_window_size and rec_max_packet fields here. - * - * The origin's rec_window_size and rec_max_packet are filled in - * later, by do_gateway_channel_open_continuation. The target's - * rec_window_size, on the other hand, must be filled in manually. */ - -struct gateway_channel * -make_gateway_channel(struct alist *request_types) -{ - NEW(gateway_channel, self); - init_channel(&self->super); - - self->super.request_types = request_types; - - /* Never initiate close; let each end point decide when it is time - * to send SSH_MSG_CHANNEL_CLOSE. */ - self->super.flags &= ~CHANNEL_CLOSE_AT_EOF; - - return self; -} - - -/* Command to request a channel open. Typically used after we have - * received a CHANNEL_OPEN request from the originating end, to create - * a channel to the target. */ -/* GABA: - (class - (name gateway_channel_open_command) - (super channel_open_command) - (vars - ; The channel type is represented as a string, as - ; we should be able to forward unknown channel - ; types (i.e. types not listen in atoms.in). - (type string) - (rec_window_size . UINT32) - (rec_max_packet . UINT32) - (requests object alist) - (args string))) -*/ - -static struct ssh_channel * -do_gateway_channel_open(struct channel_open_command *c, - struct ssh_connection *connection, - UINT32 local_channel_number, - struct lsh_string **request) -{ - CAST(gateway_channel_open_command, closure, c); - - struct gateway_channel *target - = make_gateway_channel(closure->requests); - - target->super.rec_window_size = closure->rec_window_size; - target->super.rec_max_packet = closure->rec_max_packet; - target->super.connection = connection; - - *request = format_channel_open_s(closure->type, - local_channel_number, - &target->super, - closure->args); - - return &target->super; -} - -struct command * -make_gateway_channel_open_command(struct channel_open_info *info, - struct lsh_string *args, - struct alist *requests) -{ - NEW(gateway_channel_open_command, self); - - self->super.new_channel = do_gateway_channel_open; - self->super.super.call = do_channel_open_command; - - self->type = ssh_format("%ls", info->type_length, - info->type_data); - - self->rec_window_size = info->send_window_size; - self->rec_max_packet = info->send_max_packet; - self->requests = requests; - self->args = args; - - return &self->super.super; -} - - -/* General channel requests */ - -/* GABA: - (class - (name general_channel_request_command) - (super channel_request_command) - (vars - ; NOTE: This is only used once. - (request string))) -*/ - -static struct lsh_string * -do_format_channel_general(struct channel_request_command *s, - struct ssh_channel *ch UNUSED, - struct command_continuation **c UNUSED) -{ - CAST(general_channel_request_command, self, s); - - struct lsh_string *r = self->request; - self->request = NULL; - return r; -} - -static struct command * -make_general_channel_request_command(struct lsh_string *request) -{ - NEW(general_channel_request_command, self); - self->super.super.call = do_channel_request_command; - self->super.format_request = do_format_channel_general; - self->request = request; - return &self->super.super; -} - -static void -do_gateway_channel_request(struct channel_request *s UNUSED, - struct ssh_channel *ch, - struct channel_request_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(gateway_channel, channel, ch); - UINT32 args_length; - const UINT8 *args_data; - struct command *command; - - parse_rest(args, &args_length, &args_data); - - command = make_general_channel_request_command - (format_channel_request_i(info, &channel->chain->super, - args_length, args_data)); - COMMAND_CALL(command, channel->chain, c, e); -} - -struct channel_request gateway_channel_request = -{ STATIC_HEADER, do_gateway_channel_request }; - - -/* GABA: - (class - (name general_global_request_command) - (super global_request_command) - (vars - (request string))) -*/ - -static struct lsh_string * -do_format_general_global_request(struct global_request_command *s, - struct ssh_connection *connection UNUSED, - struct command_continuation **c UNUSED) -{ - CAST(general_global_request_command, self, s); - - struct lsh_string *r = self->request; - self->request = NULL; - return r; -} - -static struct command * -make_general_global_request_command(struct lsh_string *request) -{ - NEW(general_global_request_command, self); - - self->super.super.call = do_channel_global_command; - self->super.format_request = do_format_general_global_request; - self->request = request; - return &self->super.super; -} - -static void -do_gateway_global_request(struct global_request *s UNUSED, - struct ssh_connection *connection, - UINT32 type, - int want_reply, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - struct lsh_string *request = - format_global_request(type, want_reply, "%ls", - args->capacity - args->pos, &args->data[args->pos]); - - struct command *send = make_general_global_request_command(request); - - COMMAND_CALL(send, connection->chain, c, e); -} - -struct global_request gateway_global_request = -{ STATIC_HEADER, do_gateway_global_request }; - -/* Continuation to handle the returned channel, and chain two channels - * together. - * - * CHANNEL is the "originating" end of the channel. The argument to - * the continuation is a new channel connected to the other end. */ - -/* GABA: - (class - (name gateway_channel_open_continuation) - (super command_continuation) - (vars - (up object command_continuation) - (fallback object channel_request fallback) - (origin object gateway_channel))) -*/ - -static void -do_gateway_channel_open_continuation(struct command_continuation *c, - struct lsh_object *x) -{ - CAST(gateway_channel_open_continuation, self, c); - CAST(gateway_channel, target, x); - - self->origin->chain = target; - target->chain = self->origin; - - self->origin->super.rec_window_size = target->super.send_window_size; - self->origin->super.rec_max_packet = target->super.send_max_packet; - - gateway_init_io(self->origin); - gateway_init_io(target); - - target->super.request_fallback = self->fallback; - - COMMAND_RETURN(self->up, self->origin); -} - -struct command_continuation * -make_gateway_channel_open_continuation(struct command_continuation *up, - struct channel_request *fallback, - struct gateway_channel *origin) -{ - NEW(gateway_channel_open_continuation, self); - - self->super.c = do_gateway_channel_open_continuation; - self->origin = origin; - self->fallback = fallback; - self->up = up; - - return &self->super; -} - -static void -do_channel_open_forward(struct channel_open *s UNUSED, - struct ssh_connection *connection, - struct channel_open_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - struct gateway_channel *origin - = make_gateway_channel(NULL); - - struct command *command - = make_gateway_channel_open_command(info, parse_rest_copy(args), NULL); - - origin->super.request_fallback = &gateway_channel_request; - - COMMAND_CALL(command, - connection->chain, - make_gateway_channel_open_continuation - (c, &gateway_channel_request, origin), - e); -} - -struct channel_open gateway_channel_open_forward = -{ STATIC_HEADER, do_channel_open_forward }; - diff --git a/lsh/src/gateway_channel.c.x b/lsh/src/gateway_channel.c.x deleted file mode 100755 index dc60bdf..0000000 Binary files a/lsh/src/gateway_channel.c.x and /dev/null differ diff --git a/lsh/src/gateway_channel.h b/lsh/src/gateway_channel.h deleted file mode 100755 index 0b96b8b..0000000 --- a/lsh/src/gateway_channel.h +++ /dev/null @@ -1,63 +0,0 @@ -/* gateway_channel.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999, 2000 Niels Möller, Balázs Scheidler - * - * 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 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 should 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 - */ - -#ifndef LSH_GATEWAY_CHANNEL_H_INCLUDED -#define LSH_GATEWAY_CHANNEL_H_INCLUDED - -#include "channel.h" -#include "command.h" - -#define GABA_DECLARE -#include "gateway_channel.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name gateway_channel) - (super ssh_channel) - (vars - (chain object gateway_channel))) -*/ - -struct gateway_channel * -make_gateway_channel(struct alist *request_types); - -struct command * -make_gateway_channel_open_command(struct channel_open_info *info, - struct lsh_string *args, - struct alist *requests); - -struct command_continuation * -make_gateway_channel_open_continuation(struct command_continuation *up, - struct channel_request *fallback, - struct gateway_channel *origin); - -extern struct channel_request gateway_channel_request; -extern struct global_request gateway_global_request; - -extern struct channel_open gateway_channel_open_forward; - -#endif /* LSH_GATEWAY_CHANNEL_H_INCLUDED */ - - diff --git a/lsh/src/gateway_channel.h.x b/lsh/src/gateway_channel.h.x deleted file mode 100755 index 5962fd7..0000000 Binary files a/lsh/src/gateway_channel.h.x and /dev/null differ diff --git a/lsh/src/gateway_commands.c b/lsh/src/gateway_commands.c deleted file mode 100755 index 1eae480..0000000 --- a/lsh/src/gateway_commands.c +++ /dev/null @@ -1,213 +0,0 @@ -/* gateway_commands.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "gateway_commands.h" - -#include "channel.h" -#include "connection_commands.h" -#include "debug.h" -#include "format.h" -#include "gateway_channel.h" -#include "io_commands.h" -#include "read_packet.h" -#include "ssh.h" -#include "unpad.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include "gateway_commands.c.x" - -/* A simplified version of do_pad in pad.c. This one uses - * a fixed block size and pads with zeros. */ - -/* FIXME: It seems very unnecessary to pad at all; we could just use - * - * uint32 packet_length - * byte[n] payload; n = packet_length - * - * But then we can reuse the plain read_packet class. */ - -static void -do_gateway_pad(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(abstract_write_pipe, closure, w); - - struct lsh_string *new; - - UINT32 new_size; - UINT8 padding; - - UINT8 *data; - - /* new_size is (packet->length + 9) rounded up to a multiple of - * block_size. But the block_size if fixed to 8 octets. */ - new_size = 8 * (2 + packet->length / 8); - - padding = new_size - packet->length - 5; - assert(padding >= 4); - - new = ssh_format("%i%c%lr", packet->length + padding + 1, - padding, packet->length + padding, &data); - - assert(new->length == new_size); - - memcpy(data, packet->data, packet->length); - memset(data + packet->length, '\0', padding); - - lsh_string_free(packet); - - A_WRITE(closure->next, new); -} - -static struct abstract_write * -make_gateway_pad(struct abstract_write *next) -{ - NEW(abstract_write_pipe, closure); - - closure->super.write = do_gateway_pad; - closure->next = next; - - return &closure->super; -} - - -/* Buffer size when reading from the socket */ -#define BUF_SIZE (1<<14) - -/* Blocksize when writing */ -#define BLOCK_SIZE 2000 - -static struct ssh_connection * -gateway_make_connection(struct listen_value *lv, - struct exception_handler *e) -{ - /* NOTE: lv->peer is usually NULL here. */ - struct ssh_connection *connection - = make_ssh_connection(0, /* flags */ - lv->peer, "gateway", - NULL, /* established_continuation */ - make_exc_finish_read_handler(lv->fd, e, HANDLER_CONTEXT)); - - /* Instead of calling connection_init_io. */ - connection->raw = - &io_read_write(lv->fd, - make_buffered_read( - BUF_SIZE, - make_read_packet( - make_packet_unpad( - connection, - make_packet_debug(&connection->super, - ssh_format("%lz received", connection->debug_comment))), - connection)), - BLOCK_SIZE, - make_connection_close_handler(connection))->write_buffer->super; - - connection->write = make_packet_debug( - make_gateway_pad(connection->raw), - ssh_format("%lz sent", connection->debug_comment)); - - init_connection_service(connection); - - connection->table->open_fallback = &gateway_channel_open_forward; - - connection->dispatch[SSH_MSG_DEBUG] = &connection_forward_handler; - connection->dispatch[SSH_MSG_IGNORE] = &connection_forward_handler; - - return connection; -} - -DEFINE_COMMAND(gateway_init) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(listen_value, lv, a); - - COMMAND_RETURN(c, gateway_make_connection(lv, e)); -} - - -/* (gateway_accept main-connection gateway-connection) */ -DEFINE_COMMAND2(gateway_accept) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(ssh_connection, connection, a1); - CAST(listen_value, lv, a2); - - struct ssh_connection *gateway = gateway_make_connection(lv, e); - - /* Kill gateway connection if the main connection goes down. */ - REMEMBER_RESOURCE(connection->resources, &lv->fd->super); - - gateway->chain = connection; - - COMMAND_RETURN(c, gateway); -} - - -/* GABA: - (expr - (name gateway_setup) - (params - (listen object command)) - (expr - (lambda (connection) - (connection_remember connection - (listen - (lambda (peer) - (gateway_accept connection peer))))))) -*/ - -struct command * -make_gateway_setup(struct command *listen) -{ - CAST_SUBTYPE(command, res, - gateway_setup(listen)); - - trace("make_gateway_setup\n"); - - return res; -} - -DEFINE_COMMAND(gateway_setup_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command, listen, a); - CAST_SUBTYPE(command, res, - gateway_setup(listen)); - - COMMAND_RETURN(c, res); -} diff --git a/lsh/src/gateway_commands.c.x b/lsh/src/gateway_commands.c.x deleted file mode 100755 index 3399639..0000000 Binary files a/lsh/src/gateway_commands.c.x and /dev/null differ diff --git a/lsh/src/gateway_commands.h b/lsh/src/gateway_commands.h deleted file mode 100755 index 6e89330..0000000 --- a/lsh/src/gateway_commands.h +++ /dev/null @@ -1,42 +0,0 @@ -/* gateway_commands.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef GATEWAY_COMMANDS_H_INCLUDED -#define GATEWAY_COMMANDS_H_INCLUDED - -#include "command.h" - -extern struct command gateway_init; -#define GATEWAY_INIT (&gateway_init.super) - -extern struct command_2 gateway_accept; -#define GATEWAY_ACCEPT (&gateway_accept.super.super) - -struct command * -make_gateway_setup(struct command *listen); - -extern struct command gateway_setup_command; -#define GATEWAY_SETUP (&gateway_setup_command.super) - -#endif /* GATEWAY_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/gc.c b/lsh/src/gc.c deleted file mode 100755 index 75373a8..0000000 --- a/lsh/src/gc.c +++ /dev/null @@ -1,257 +0,0 @@ -/* gc.c - * - * Simple mark&sweep garbage collector. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "gc.h" - -#include "werror.h" -#include "xalloc.h" - -#include - -/* Global variables */ -#ifndef MACOS -static struct lsh_object *all_objects = NULL; -static unsigned number_of_objects = 0; -static unsigned live_objects = 0; -#else -#include "lsh_context.h" -#endif - -#if DEBUG_ALLOC -static void sanity_check_object_list(void) -{ - unsigned i = 0; - struct lsh_object *o; - -#if 0 - wwrite("sanity_check_object_list: Objects on list:\n"); - for(o = all_objects; o; o = o->next) - werror(" %xi, class: %z\n", (UINT32) o, o->isa ? o->isa->name : "UNKNOWN"); -#endif - - for(o = all_objects; o; o = o->next) - i++; - - if (i != number_of_objects) - fatal("sanity_check_object_list: Found %i objects, expected %i.\n", - i, number_of_objects); -} -#else -#define sanity_check_object_list() -#endif - -/* FIXME: This function recurses heavily. One could use some trickery - * to emulate tail recursion, which would help marking linked lists. - * Or one could use some more efficient datastructures than the C - * stack for keeping track of the marked but not yet traced objects. - * Or use something more sophisticated, like pointer reversal. */ -static void gc_mark(struct lsh_object *o) -{ - if (!o) - return; - - switch(o->alloc_method) - { - case LSH_ALLOC_STACK: - fatal("gc_mark: Unexpected stack object!\n"); - - case LSH_ALLOC_HEAP: - if (o->marked) - return; - o->marked = 1; - /* Fall through */ - case LSH_ALLOC_STATIC: - /* Can't use mark bit on static objects, as there's no way to - * reset all the bits */ - assert(!o->dead); - { - struct lsh_class *class; - -#if 0 - debug("gc_mark: Marking object of class '%z'\n", - o->isa ? o->isa->name : "UNKNOWN"); -#endif - - for (class = o->isa; class; class = class->super_class) - { - if (class->mark_instance) - MARK_INSTANCE(class, o, gc_mark); - } - } - break; - default: - fatal("gc_mark: Memory corrupted!\n"); - } -} - -static void gc_sweep(void) -{ - struct lsh_object *o; - struct lsh_object **o_p; - - live_objects = 0; - - for(o_p = &all_objects; (o = *o_p); ) - { - if (o->marked) - { - /* Paralyze the living... */ - live_objects++; - o->marked = 0; - } - else - { - /* ... and resurrect the dead. */ - struct lsh_class *class; - -#if 0 - debug("gc_sweep: Freeing object of class '%z'\n", - o->isa->name); -#endif - for (class = o->isa; class; class = class->super_class) - if (class->free_instance) - FREE_INSTANCE(class, o); - - *o_p = o->next; - number_of_objects--; - - lsh_object_free(o); - continue; - } - o_p = &o->next; - } - assert(live_objects == number_of_objects); -} - -void gc_register(struct lsh_object *o) -{ - sanity_check_object_list(); - - o->marked = o->dead = 0; - o->next = all_objects; - all_objects = o; - - number_of_objects ++; - - sanity_check_object_list(); -} - -/* NOTE: If the object is close to the start of the object list, it is - * deallocated and forgotten immedietely. If the object is not found, - * we don't search the entire list, but instead defer deallocation to - * gc_sweep. */ -void gc_kill(struct lsh_object *o) -{ - sanity_check_object_list(); - - if (!o) - return; - - assert(!o->dead); - - o->dead = 1; - -#if 0 - debug("gc_kill: Killing object of type %z.\n", - o->isa ? o->isa->name : "UNKNOWN"); -#endif - - if (o == all_objects) - { - struct lsh_class *class; - -#if 0 - debug("gc_kill: Deallocating immediately.\n"); -#endif - - for (class = o->isa; class; class = class->super_class) - if (class->free_instance) - FREE_INSTANCE(class, o); - - all_objects = o->next; - number_of_objects--; - lsh_object_free(o); - } - else - { -#if 0 - debug("gc_kill: Deferring deallocation to gc_sweep\n"); -#endif - } - - sanity_check_object_list(); -} - -void gc(struct lsh_object *root) -{ - unsigned objects_before = number_of_objects; -#if DEBUG_ALLOC - unsigned strings_before = number_of_strings; -#endif - - gc_mark(root); - gc_sweep(); - - verbose("Objects alive: %i, garbage collected: %i\n", - live_objects, objects_before - live_objects); -#if DEBUG_ALLOC - verbose("Used strings: %i, garbage collected: %i\n", - number_of_strings, strings_before - number_of_strings); -#endif -} - -void gc_maybe(struct lsh_object *root, int busy) -{ - sanity_check_object_list(); - - if (number_of_objects > (100 + live_objects*(2+busy))) - { - verbose("Garbage collecting while %z...\n", busy ? "busy" : "idle"); - gc(root); - } -} - -#if DEBUG_ALLOC -/* Deallocate all objects. */ - -int gc_final_p = 0; - -void gc_final(void) -{ - gc_final_p = 1; - - gc_sweep(); - assert(!number_of_objects); - - if (number_of_strings) - { - struct lsh_string *s; - werror("gc_final: %i strings leaked!\n", number_of_strings); - for (s = all_strings; s; s = s->header.next) - werror(" clue: %z\n", s->header.clue); - fatal("gc_final: Internal error!\n"); - } -} -#endif /* DEBUG_ALLOC */ diff --git a/lsh/src/gc.h b/lsh/src/gc.h deleted file mode 100755 index 22f493e..0000000 --- a/lsh/src/gc.h +++ /dev/null @@ -1,44 +0,0 @@ -/* gc.h - * - * Simple mark&sweep garbage collector. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_GC_H_INCLUDED -#define LSH_GC_H_INCLUDED - -#include "lsh.h" - -void gc_register(struct lsh_object *o); -void gc_kill(struct lsh_object *o); - -void gc(struct lsh_object *root); -void gc_maybe(struct lsh_object *root, int busy); - -#if DEBUG_ALLOC -extern int gc_final_p; -void gc_final(void); -#else -#define gc_final() -#endif - -#endif /* LSH_GC_H_INCLUDED */ diff --git a/lsh/src/handshake.c b/lsh/src/handshake.c deleted file mode 100755 index 837e3bf..0000000 --- a/lsh/src/handshake.c +++ /dev/null @@ -1,400 +0,0 @@ -/* handshake.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "handshake.h" - -#include "compress.h" -#include "connection.h" -#include "debug.h" -#include "format.h" -#include "io.h" -#include "keyexchange.h" -#include "read_line.h" -#include "read_packet.h" -#include "ssh.h" -#include "unpad.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#define GABA_DEFINE -#include "handshake.h.x" -#undef GABA_DEFINE - -#include "handshake.c.x" - -/* GABA: - (class - (name connection_line_handler) - (super line_handler) - (vars - (connection object ssh_connection) - ; Needed for fallback. - (fd . int) - (fallback object ssh1_fallback))) -*/ - -/* Returns -1 if the line is not the start of a SSH handshake, - * 0 if the line appears to be an SSH handshake, but with bogus version fields, - * or 1 if the line was parsed sucessfully. */ -static int -split_version_string(UINT32 length, UINT8 *line, - UINT32 *protover_len, UINT8 **protover, - UINT32 *swver_len, UINT8 **swver, - UINT32 *comment_len, UINT8 **comment) -{ - UINT8 *sep; - - if (length < 4 || memcmp(line, "SSH-", 4) != 0) - { - /* not an ssh identification string */ - return -1; - } - line += 4; length -= 4; - sep = memchr(line, '-', length); - if (!sep) - { - return 0; - } - *protover_len = sep - line; - *protover = line; - - line = sep + 1; - length -= *protover_len + 1; - - /* FIXME: The spec is not clear about the separator here. Can there - * be other white space than a single space character? */ - sep = memchr(line, ' ', length); - if (!sep) - { - *swver_len = length; - *swver = line; - *comment = NULL; - *comment_len = 0; - return 1; - } - - *swver_len = sep - line; - *swver = line; - *comment = sep + 1; - *comment_len = length - *swver_len - 1; - return 1; -} - -static void -do_line(struct line_handler **h, - struct read_handler **r, - UINT32 length, - UINT8 *line, - struct exception_handler *e) -{ - CAST(connection_line_handler, closure, *h); - UINT32 protover_len, swver_len, comment_len; - UINT8 *protover, *swver, *comment; - - struct ssh_connection *connection = closure->connection; - int mode = connection->flags & CONNECTION_MODE; - - switch(split_version_string(length, line, - &protover_len, &protover, - &swver_len, &swver, - &comment_len, &comment)) - { - case 1: - { - /* Parse and remember format string */ - /* NOTE: According to the spec, there's no reason for the server - * to accept a client that wants version 1.99. But Datafellow's - * ssh2 client does exactly that, so we have to support it. And - * I don't think it causes any harm. */ - - if ( ((protover_len >= 3) && !memcmp(protover, "2.0", 3)) - || ((protover_len == 4) && !memcmp(protover, "1.99", 4)) ) - { - struct read_handler *new; -#if WITH_SSH1_FALLBACK - if (closure->fallback) - { - assert(mode == CONNECTION_SERVER); - - /* Sending keyexchange packet was delayed. Do it now */ - initiate_keyexchange(connection); - } -#endif /* WITH_SSH1_FALLBACK */ - -#if DATAFELLOWS_WORKAROUNDS - if ( (swver_len >= 6) && !memcmp(swver, "2.0.", 4) - /* FIXME: Perhaps do a numerical comparison here? */ - && (memcmp(swver + 4, "13", 2) <= 0) ) - { - connection->peer_flags - |= (PEER_SSH_DSS_KLUDGE | PEER_SERVICE_ACCEPT_KLUDGE - | PEER_USERAUTH_REQUEST_KLUDGE | PEER_SEND_NO_DEBUG - | PEER_X11_OPEN_KLUDGE); - } - else if ( (swver_len >= 5) && !memcmp(swver, "2.1.0", 5) ) - { - connection->peer_flags - |= (PEER_SSH_DSS_KLUDGE - | PEER_USERAUTH_REQUEST_KLUDGE | PEER_SEND_NO_DEBUG); - verbose("ssh.com 2.1.0\n"); - } -#endif /* DATAFELLOWS_WORKAROUNDS */ -#if MACOS - if ( (swver_len >= 6) && !memcmp(swver, "2.0.13", 6) ) - connection->peer_flags |= PEER_WRONG_PK_OK; -#endif - new = - make_read_packet( - make_packet_unpad( - connection, - make_packet_inflate( - make_packet_debug(&connection->super, - (connection->debug_comment - ? ssh_format("%lz received", connection->debug_comment) - : ssh_format("Received"))), - connection - ) - ), - connection - ); - - connection->versions[!mode] - = ssh_format("%ls", length, line); - - verbose("Client version: %pS\n" - "Server version: %pS\n", - connection->versions[CONNECTION_CLIENT], - connection->versions[CONNECTION_SERVER]); - - *r = new; - return; - } -#if WITH_SSH1_FALLBACK - else if (closure->fallback - && (protover_len >= 2) - && !memcmp(protover, "1.", 2)) - { - *h = NULL; - SSH1_FALLBACK(closure->fallback, - closure->fd, - length, line, - e); - - return; - } -#endif /* WITH_SSH1_FALLBACK */ - else - { - werror("Unsupported protocol version: %ps\n", - length, line); - - *h = NULL; - - EXCEPTION_RAISE(connection->e, - make_protocol_exception - (SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, - NULL)); - return; - } - fatal("Internal error!\n"); - } - case 0: - werror("Incorrectly formatted version string: %s\n", length, line); - KILL(closure); - *h = NULL; - - PROTOCOL_ERROR(connection->e, - "Incorrectly version string."); - - return; - case -1: - /* Display line */ - werror("%ps\n", length, line); - - /* Read next line */ - break; - default: - fatal("Internal error!\n"); - } -} - -static struct read_handler * -make_connection_read_line(struct ssh_connection *connection, - int fd, - struct ssh1_fallback *fallback) -{ - NEW(connection_line_handler, closure); - - closure->super.handler = do_line; - closure->connection = connection; - closure->fd = fd; - closure->fallback = fallback; - return make_read_line(&closure->super, connection->e); -} - - -struct handshake_info * -make_handshake_info(UINT32 flags, - const char *id_comment, - const char *debug_comment, - UINT32 block_size, - struct randomness *r, - struct alist *algorithms, - struct ssh1_fallback *fallback) -{ - NEW(handshake_info, self); - self->flags = flags; - self->id_comment = id_comment; - self->debug_comment = debug_comment; - self->block_size = block_size; - self->random = r; - self->algorithms = algorithms; - self->fallback = fallback; - - return self; -} - -/* (handshake handshake_info make_kexinit extra listen_value) -> connection - * - * extra is passed on to KEYEXCHANGE_INIT, it is typically a set of - * private keys (for the server) or a hostkey database (for the - * client). */ - -/* GABA: - (class - (name handshake_command_2) - (super command) - (vars - (info object handshake_info) - (init object make_kexinit) - (extra object lsh_object))) -*/ - -/* Buffer size when reading from the socket */ -#define BUF_SIZE (1<<14) - -DEFINE_COMMAND4(handshake_command) - (struct lsh_object *a1, - struct lsh_object *a2, - struct lsh_object *extra, - struct lsh_object *a4, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(handshake_info, info, a1); - CAST_SUBTYPE(make_kexinit, init, a2); - CAST(listen_value, lv, a4); - - struct lsh_string *version; - struct ssh_connection *connection; - int mode = info->flags & CONNECTION_MODE; - - verbose("Initiating handshake with %S\n", lv->peer->ip); - - switch (mode) - { - case CONNECTION_CLIENT: - version = ssh_format("SSH-%lz-%lz %lz", - CLIENT_PROTOCOL_VERSION, - SOFTWARE_CLIENT_VERSION, - info->id_comment); - break; - case CONNECTION_SERVER: -#if WITH_SSH1_FALLBACK - if (info->fallback) - { - version = - ssh_format("SSH-%lz-%lz %lz", - SSH1_SERVER_PROTOCOL_VERSION, - SOFTWARE_SERVER_VERSION, - info->id_comment); - } - else -#endif - version = - ssh_format("SSH-%lz-%lz %lz", - SERVER_PROTOCOL_VERSION, - SOFTWARE_SERVER_VERSION, - info->id_comment); - break; - default: - fatal("do_handshake: Internal error\n"); - } - - /* Installing the right exception handler is a little tricky. The - * passed in handler is typically the top-level handler provided by - * lsh.c or lshd.c. On top of this, we add the io_exception_handler - * which takes care of EXC_FINISH_READ exceptions and closes the - * connection's socket. And on top of this, we have a - * connection_exception handler, which takes care of EXC_PROTOCOL - * exceptions, sends a disconnect message, and then raises an - * EXC_FINISH_READ exception. */ - - connection = make_ssh_connection - (info->flags, - lv->peer, info->debug_comment, - c, - make_exc_finish_read_handler(lv->fd, e, HANDLER_CONTEXT)); - - connection_init_io - (connection, - &io_read_write(lv->fd, - make_buffered_read - (BUF_SIZE, - make_connection_read_line(connection, - lv->fd->fd, info->fallback)), - info->block_size, - make_connection_close_handler(connection)) - ->write_buffer->super, - info->random); - - connection->versions[mode] = version; - connection->kexinits[mode] = MAKE_KEXINIT(init); - connection->dispatch[SSH_MSG_KEXINIT] - = make_kexinit_handler(init, - extra, info->algorithms); - -#if WITH_SSH1_FALLBACK - /* In this mode the server SHOULD NOT send carriage return character (ascii - * 13) after the version identification string. - * - * Furthermore, it should not send any data after the identification string, - * until the client's identification string is received. */ - if (info->fallback) - { - A_WRITE(connection->raw, - ssh_format("%lS\n", version)); - return; - } -#endif /* WITH_SSH1_FALLBACK */ - - A_WRITE(connection->raw, - ssh_format("%lS\r\n", version)); - - initiate_keyexchange(connection); -} diff --git a/lsh/src/handshake.c.x b/lsh/src/handshake.c.x deleted file mode 100755 index 23e9f31..0000000 Binary files a/lsh/src/handshake.c.x and /dev/null differ diff --git a/lsh/src/handshake.h b/lsh/src/handshake.h deleted file mode 100755 index 5a30c20..0000000 --- a/lsh/src/handshake.h +++ /dev/null @@ -1,67 +0,0 @@ -/* handshake.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef HANDSHAKE_H_INCLUDED -#define HANDSHAKE_H_INCLUDED - -#include "alist.h" -#include "command.h" -#include "ssh1_fallback.h" - -#define GABA_DECLARE -#include "handshake.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name handshake_info) - (vars - ; Initial value for the connection flags. Usually - ; CONNECTION_SERVER or CONNECTION_CLIENT - (flags . UINT32) - - (block_size . UINT32) - (id_comment . "const char *") - (debug_comment . "const char *") - - (random object randomness) - (algorithms object alist) - - ; Used only on the server - (fallback object ssh1_fallback))) -*/ - -struct handshake_info * -make_handshake_info(UINT32 flags, - const char *id_comment, - const char *debug_comment, - UINT32 block_size, - struct randomness *r, - struct alist *algorithms, - struct ssh1_fallback *fallback); - -extern struct command_4 handshake_command; -#define CONNECTION_HANDSHAKE (&handshake_command.super.super) - -#endif /* HANDSHAKE_H_INCLUDED */ diff --git a/lsh/src/handshake.h.x b/lsh/src/handshake.h.x deleted file mode 100755 index 3ec38eb..0000000 Binary files a/lsh/src/handshake.h.x and /dev/null differ diff --git a/lsh/src/hmac.c b/lsh/src/hmac.c deleted file mode 100755 index c4b4ff2..0000000 --- a/lsh/src/hmac.c +++ /dev/null @@ -1,163 +0,0 @@ -/* hmac.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "xalloc.h" - -#include - -#include "hmac.c.x" - -#if !HAVE_MEMXOR -#include "nettle/memxor.h" -#endif - -/* The HMAC (rfc-2104) construction */ -/* GABA: - (class - (name hmac_algorithm) - (super mac_algorithm) - (vars - (hash object hash_algorithm))) -*/ - -/* GABA: - (class - (name hmac_instance) - (super mac_instance) - (vars - ; Initialized hash objects - (hinner object hash_instance) - (houter object hash_instance) - - ; Modified by update. - (state object hash_instance))) -*/ - -static void -do_hmac_update(struct mac_instance *s, - UINT32 length, const UINT8 *data) -{ - CAST(hmac_instance, self, s); - - HASH_UPDATE(self->state, length, data); -} - -static void -do_hmac_digest(struct mac_instance *s, - UINT8 *data) -{ - CAST(hmac_instance, self, s); - struct hash_instance *h = self->state; - - HASH_DIGEST(h, data); /* Inner hash */ - KILL(h); - h = HASH_COPY(self->houter); - HASH_UPDATE(h, self->super.mac_size, data); - HASH_DIGEST(h, data); - KILL(h); - - self->state = HASH_COPY(self->hinner); -} - -static struct mac_instance * -do_hmac_copy(struct mac_instance *s) -{ - CAST(hmac_instance, self, s); - CLONED(hmac_instance, new, self); - - new->state = HASH_COPY(self->state); - - return &new->super; -} - -#define IPAD 0x36 -#define OPAD 0x5c - -static struct mac_instance * -make_hmac_instance(struct mac_algorithm *s, - UINT32 key_length, - const UINT8 *key) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(hmac_algorithm, self, s); - NEW(hmac_instance, instance); - UINT8 *pad = alloca(self->hash->block_size); - - if (key_length > self->hash->block_size) - { - /* Reduce key to the algorithm's hash size */ - UINT8 *digest = alloca(self->hash->hash_size); - struct hash_instance *h = MAKE_HASH(self->hash); - - HASH_UPDATE(h, key_length, key); - HASH_DIGEST(h, digest); - - key = digest; - key_length = self->hash->hash_size; - } - - instance->super.hash_size = self->super.hash_size; - instance->super.update = do_hmac_update; - instance->super.digest = do_hmac_digest; - instance->super.copy = do_hmac_copy; - - instance->hinner = MAKE_HASH(self->hash); - - memset(pad, IPAD, self->hash->block_size); - memxor(pad, key, key_length); - - HASH_UPDATE(instance->hinner, self->hash->block_size, pad); - - instance->houter = MAKE_HASH(self->hash); - - memset(pad, OPAD, self->hash->block_size); - memxor(pad, key, key_length); - - HASH_UPDATE(instance->houter, self->hash->block_size, pad); - - instance->state = HASH_COPY(instance->hinner); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return &instance->super; -} - -struct mac_algorithm * -make_hmac_algorithm(struct hash_algorithm *h) -{ - NEW(hmac_algorithm, self); - - self->super.hash_size = h->hash_size; - /* Recommended in RFC-2104 */ - self->super.key_size = h->hash_size; - self->super.make_mac = make_hmac_instance; - - self->hash = h; - - return &self->super; -} diff --git a/lsh/src/hmac.c.x b/lsh/src/hmac.c.x deleted file mode 100755 index a793176..0000000 Binary files a/lsh/src/hmac.c.x and /dev/null differ diff --git a/lsh/src/idea.c b/lsh/src/idea.c deleted file mode 100755 index e1a98e4..0000000 --- a/lsh/src/idea.c +++ /dev/null @@ -1,72 +0,0 @@ -/* idea.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - - -#include "crypto.h" -#include "werror.h" -#include "xalloc.h" - -#ifdef WITH_IDEA - -#include "idea.h" - -#include - -#include "idea.c.x" - -/* GABA: - (class - (name idea_instance) - (super crypto_instance) - (vars - (ctx array UINT16 IDEA_KEYLEN))) -*/ - -static void do_idea_crypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(idea_instance, self, s); - - FOR_BLOCKS(length, src, dst, IDEA_BLOCKSIZE) - idea_crypt(self->ctx, dst, src); -} - -static struct crypto_instance * -make_idea_instance(struct crypto_algorithm *algorithm UNUSED, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(idea_instance, self); - - idea_expand(self->ctx, key); - if (mode == CRYPTO_DECRYPT) - idea_invert(self->ctx, self->ctx); - - self->super.block_size = IDEA_BLOCKSIZE; - self->super.crypt = do_idea_crypt; - return &self->super; -} - -struct crypto_algorithm idea_algorithm = -{ STATIC_HEADER, IDEA_BLOCKSIZE, IDEA_KEYSIZE, 0, make_idea_instance }; - -#endif /* WITH_IDEA */ diff --git a/lsh/src/interact.c b/lsh/src/interact.c deleted file mode 100755 index b689f12..0000000 --- a/lsh/src/interact.c +++ /dev/null @@ -1,43 +0,0 @@ -/* interact.c - * - * Interact with the user. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller - * - * 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 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 should 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 - */ - -#include "interact.h" - -#include "io.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include -#include - -#define GABA_DEFINE -#include "interact.h.x" -#undef GABA_DEFINE diff --git a/lsh/src/interact.h b/lsh/src/interact.h deleted file mode 100755 index e5ea7ac..0000000 --- a/lsh/src/interact.h +++ /dev/null @@ -1,103 +0,0 @@ -/* interact.h - * - * Interact with the user. - * - * $Id$*/ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_INTERACT_H_INCLUDED -#define LSH_INTERACT_H_INCLUDED - -#include "lsh.h" - -/* Forward declaration */ -struct interact; -struct terminal_dimensions; - -#define GABA_DECLARE -#include "interact.h.x" -#undef GABA_DECLARE - -/* Abstract class defining methods needed to communicate with the - * user's terminal. */ - -/* GABA: - (class - (name terminal_attributes) - (vars - (make_raw method (object terminal_attributes)) - (encode method (string)))) -*/ - -#define TERM_MAKE_RAW(t) ((t)->make_raw((t))) -#define TERM_ENCODE(t) ((t)->encode((t))) - -/* GABA: - (class - (name window_change_callback) - (vars - (f method void "struct interact *i"))) -*/ - -#define WINDOW_CHANGE_CALLBACK(c, i) ((c)->f((c), (i))) - -/* GABA: - (class - (name interact) - (vars - (is_tty method int) - ; (read_line method int "UINT32 size" "UINT8 *buffer") - ;; FIXME: Do we really need the FREE parameter? - (read_password method (string) - "UINT32 max_length" - "const struct lsh_string *prompt" - "int free") - (yes_or_no method int - "const struct lsh_string *prompt" - "int def" "int free") - - (get_attributes method (object terminal_attributes) ) - (set_attributes method int "struct terminal_attributes *attr") - - (window_size method int "struct terminal_dimensions *") - (window_change_subscribe method (object resource) - "struct window_change_callback *callback"))) -*/ - -#define INTERACT_IS_TTY(i) \ - ((i)->is_tty((i))) -#define INTERACT_READ_PASSWORD(i, l, p, f) \ - ((i)->read_password((i), (l), (p), (f))) -#define INTERACT_YES_OR_NO(i, p, d, f) \ - ((i)->yes_or_no((i), (p), (d), (f))) -#define INTERACT_GET_ATTRIBUTES(i) \ - ((i)->get_attributes((i))) -#define INTERACT_SET_ATTRIBUTES(i, t) \ - ((i)->set_attributes((i), (t))) -#define INTERACT_WINDOW_SIZE(i, d) \ - ((i)->window_size((i), (d))) -#define INTERACT_WINDOW_SUBSCRIBE(i, c) \ - ((i)->window_change_subscribe((i), (c))) - -struct interact * -make_unix_interact(struct io_backend *backend); - -#endif /* LSH_INTERACT_H_INCLUDED */ diff --git a/lsh/src/interact.h.x b/lsh/src/interact.h.x deleted file mode 100755 index e6db365..0000000 Binary files a/lsh/src/interact.h.x and /dev/null differ diff --git a/lsh/src/invert-defs b/lsh/src/invert-defs deleted file mode 100755 index c436b34..0000000 Binary files a/lsh/src/invert-defs and /dev/null differ diff --git a/lsh/src/io.c b/lsh/src/io.c deleted file mode 100755 index e50e759..0000000 --- a/lsh/src/io.c +++ /dev/null @@ -1,2150 +0,0 @@ -/* io.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "io.h" - -#include "format.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_POLL -# if HAVE_POLL_H -# include -# elif HAVE_SYS_POLL_H -# include -# endif -#else -# include "jpoll.h" -#endif - -/* Workaround for some version of FreeBSD. */ -#ifdef POLLRDNORM -# define MY_POLLIN (POLLIN | POLLRDNORM) -#else /* !POLLRDNORM */ -# define MY_POLLIN POLLIN -#endif /* !POLLRDNORM */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -#define GABA_DEFINE -#include "io.h.x" -#undef GABA_DEFINE - -#include "io.c.x" - -/* Calls trigged by a signal handler. */ -/* GABA: - (class - (name lsh_signal_handler) - (super resource) - (vars - (next object lsh_signal_handler) - (flag . "volatile sig_atomic_t *") - (action object lsh_callback))) -*/ - -/* Scheduled calls. FIXME: For now, no scheduling in time. */ -/* GABA: - (class - (name lsh_callout) - (super resource) - (vars - (next object lsh_callout) - (action object lsh_callback))) - ;; (when . time_t) -*/ - -/* GABA: - (class - (name io_backend) - (super resource) - (vars - ; Linked list of fds. - (files object lsh_fd) - - ; Stack of closed files - ;; (closed object lsh_fd) - - ; Flags - (signals object lsh_signal_handler) - - ; Callouts - (callouts object lsh_callout))) -*/ - - -/* Backend loop */ - -/* If there's nothing to do for this amount of time (ms), do - * spontaneous gc. */ - -#define IDLE_TIME 100 - -int io_iter(struct io_backend *b) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - unsigned long nfds; /* FIXME: Should be nfds_t if that type is defined */ - struct pollfd *fds; - struct lsh_fd **active_fds; - - /* FIXME: Real scheduling of callouts not implemented */ - /* int timeout; */ - int res; - - /* Check all flags */ - if (b->signals) - { - struct lsh_signal_handler *f; - struct lsh_signal_handler **f_p; - for (f_p = &b->signals; (f = *f_p); ) - { - if (!f->super.alive) - *f_p = f->next; - else - { - if (*f->flag) - { - *f->flag = 0; - LSH_CALLBACK(f->action); - } - f_p = &f->next; - } - } - } - - /* Invoke all callouts. Clear the list first; if any callout - * installs another one, that will not be invoked until the next - * iteration. */ - if (b->callouts) - { - struct lsh_callout *p; - - for (p = b->callouts, b->callouts = NULL; - p; p = p->next) - if (p->super.alive) - { - LSH_CALLBACK(p->action); - p->super.alive = 0; - } - } - - /* Prepare fds. */ - { - struct lsh_fd *fd; - - for (fd = b->files; fd; fd = fd->next) - /* NOTE: The prepare callback is allowed to close files. */ - if (fd->super.alive && fd->prepare) - FD_PREPARE(fd); - } - - /* This phase unlinks any closed fd:s, and also counts how many - * fd:s there are. */ - { - struct lsh_fd *fd; - struct lsh_fd **fd_p; - nfds = 0; - - for(fd_p = &b->files; (fd = *fd_p); ) - { - if (!fd->super.alive) - /* Unlink this fd */ - *fd_p = fd->next; - - else - { - if (fd->want_read || fd->want_write) - nfds++; - - fd_p = &fd->next; - } - } - } - - if (!nfds) - /* Nothing more to do. - * - * NOTE: There might be some callouts left, but we won't wait for them. */ - return 0; - - fds = alloca(sizeof(struct pollfd) * nfds); - active_fds = alloca(sizeof(struct lsh_fd *) *nfds); - - /* Fill out fds-array */ - { - struct lsh_fd *fd; - unsigned long i; - int all_events = 0; - - for (fd = b->files, i = 0; fd; fd = fd->next) - { - assert(fd->super.alive); - - if (fd->want_read || fd->want_write) - { - assert(i < nfds); - - active_fds[i] = fd; - - fds[i].fd = fd->fd; - fds[i].events = 0; - - if (fd->want_read) - fds[i].events |= MY_POLLIN; - - if (fd->want_write) - fds[i].events |= POLLOUT; - - all_events |= fds[i].events; - i++; - } - } - assert(i == nfds); - assert(all_events); - } - - res = poll(fds, nfds, IDLE_TIME); - - if (!res) - { - gc_maybe(&b->super.super, 0); - res = poll(fds, nfds, -1); - } - else - gc_maybe(&b->super.super, 1); - - if (!res) - { - /* Callouts are not implemented */ - fatal("Unexpected timeout\n"); - } - if (res < 0) - switch(errno) - { - case EAGAIN: - case EINTR: -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return 1; - default: - fatal("io_iter: poll failed: %z", STRERROR(errno)); - } - - { - /* Do io. Note that the callback functions may add new fds to the - * head of the list, or clear the alive flag on any fd. But this - * is less of a problem now, as we use the active_fd array.*/ - - /* struct lsh_fd *fd; */ - unsigned long i; - - for(i=0; isuper.alive) - continue; - - /* On systems without poll, we use jpoll.c to emulate some - * of poll, but we lack POLLNVAL, POLLPRI and POLLHUP. */ -#ifdef POLLNVAL - if (fds[i].revents & POLLNVAL) - { - werror("io.c: poll request on fd %i, for events of type %xi\n" - " return POLLNVAL, revents = %xi\n", - fds[i].fd, fds[i].events, fds[i].revents); - close_fd(fd); - continue; - } -#endif /* POLLNVAL */ - -#ifdef POLLHUP - /* NOTE: The behaviour of poll at EOF varies quite a lot - * between systems. - * - * According to Solaris' man page, POLLHUP is mutually - * exclusive with POLLOUT, but orthogonal to POLLIN. - * - * However, on my system (sparc-linux) POLLHUP is set when we - * get EOF on an fd we are reading. - * - * I.e. on some systems, EOF is indicated by poll setting - * POLLIN and read returning 0 (in particular, this happens - * if the poll-by-select-code in jpoll.c is used), while on - * other systems, poll sets POLLHUP and subsequent read - * calls will return -1, not 0. - * - * But to complicate things some more, we can (also on Linux) - * get both POLLHUP and POLLIN set. In that case, we do an - * ordinary read. - * - * We set the hanged_up flag before calling FD_READ, which - * tells the io_callback that it should avoid calling read. */ - - if (fds[i].revents & POLLHUP) - { - if (fd->want_write) - /* Will raise an i/o error */ - FD_WRITE(fd); - else if (fd->want_read) - { - if (!fd->super.alive) - continue; - - /* If reading is not possible, treat this as EOF. */ - if (!(fds[i].revents & MY_POLLIN)) - fd->hanged_up = 1; - - FD_READ(fd); - } - else - { - werror("io.c: poll said POLLHUP on an inactive fd.\n"); - close_fd(fd); - } - continue; - } -#endif /* POLLHUP */ - -#ifdef POLLERR - if (fds[i].revents & POLLERR) - { - werror("io.c: POLLERR. Hanging up.\n"); - - /* FIXME: Should we raise any exception here? */ - - close_fd(fd); - - continue; - } -#endif /* POLLERR */ - -#ifdef POLLPRI - if (fds[i].revents & POLLPRI) - { - werror("io.c: Peer is trying to send Out of Band data. Hanging up.\n"); - - /* FIXME: Should we raise any exception here? */ - - close_fd(fd); - - continue; - } -#endif /* POLLPRI */ - if (fds[i].revents & POLLOUT) - FD_WRITE(fd); - - if (!fd->super.alive) - continue; - - if (fds[i].revents & MY_POLLIN) - FD_READ(fd); - } - assert(i == nfds); - } - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return 1; -} - -void -io_run(struct io_backend *b) -{ - struct sigaction pipe; - memset(&pipe, 0, sizeof(pipe)); - - pipe.sa_handler = SIG_IGN; - sigemptyset(&pipe.sa_mask); - pipe.sa_flags = 0; - - if (sigaction(SIGPIPE, &pipe, NULL) < 0) - fatal("Failed to ignore SIGPIPE.\n"); - - while(io_iter(b)) - ; -} - -static void -do_kill_io_backend(struct resource *s) -{ - CAST(io_backend, backend, s); - - if (backend->super.alive) - { - struct lsh_fd *fd; - struct lsh_signal_handler *signal; - - for (fd = backend->files, backend->files = NULL; - fd; fd = fd->next) - close_fd(fd); - - /* Check that no callback has opened new files. */ - assert(!backend->files); - - for (signal = backend->signals, backend->signals = NULL; - signal; signal = signal->next) - signal->super.alive = 0; - - backend->super.alive = 0; - } -} - -struct io_backend * -make_io_backend(void) -{ - NEW(io_backend, b); - - init_resource(&b->super, do_kill_io_backend); - - b->files = NULL; - b->signals = NULL; - b->callouts = NULL; - - return b; -} - -void -io_final(struct io_backend *b) -{ - KILL_RESOURCE(&b->super); -} - -struct resource * -io_signal_handler(struct io_backend *b, - volatile sig_atomic_t *flag, - struct lsh_callback *action) -{ - NEW(lsh_signal_handler, handler); - init_resource(&handler->super, NULL); - - handler->next = b->signals; - handler->flag = flag; - handler->action = action; - - b->signals = handler; - - return &handler->super; -} - -/* Delays not implemented. */ -struct resource * -io_callout(struct io_backend *b, - UINT32 delay UNUSED, - struct lsh_callback *action) -{ - NEW(lsh_callout, callout); - init_resource(&callout->super, NULL); - - callout->next = b->callouts; - callout->action = action; - b->callouts = callout; - - return &callout->super; -} - -/* Read-related callbacks */ - -static void -do_buffered_read(struct io_callback *s, - struct lsh_fd *fd) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(io_buffered_read, self, s); - UINT8 *buffer = alloca(self->buffer_size); - int res; - - assert(fd->want_read); - - /* If hanged_up is set, pretend that read returned 0 */ - res = fd->hanged_up ? 0 : read(fd->fd, buffer, self->buffer_size); - - if (res < 0) - switch(errno) - { - case EINTR: - break; - case EWOULDBLOCK: - werror("io.c: read_callback: Unexpected EWOULDBLOCK\n"); - break; - case EPIPE: - /* Getting EPIPE from read seems strange, but appearantly - * it happens sometimes. */ - werror("Unexpected EPIPE.\n"); - default: - EXCEPTION_RAISE(fd->e, - make_io_exception(EXC_IO_READ, fd, - errno, NULL)); - /* Close the fd, unless it has a write callback. */ - close_fd_read(fd); - - break; - } - else if (res > 0) - { - UINT32 left = res; - - while (fd->super.alive && fd->read && left) - { - UINT32 done; - - /* NOTE: What to do if want_read is false? To improve the - * connection_lock mechanism, it must be possible to - * temporarily stop reading, which means that fd->want_read - * has to be cleared. - * - * But when doing this, we have to keep the data that we - * have read, some of which is buffered here, on the stack, - * and the rest inside the read-handler. - * - * There are two alternatives: Save our buffer here, or - * continue looping, letting the read-handler process it - * into packets. In the latter case, the ssh_connection - * could keep a queue of waiting packets, but it would still - * have to clear the want_read flag, to prevent that queue - * from growing arbitrarily large. - * - * We now go with the second alternative. */ - - assert(self->handler); - - /* NOTE: This call may replace self->handler */ - done = READ_HANDLER(self->handler, left, buffer); - - buffer += done; - left -= done; - - if (!fd->want_read) - debug("do_buffered_read: want_read = 0; handler needs a pause.\n"); - - if (fd->want_read && !self->handler) - { - werror("do_buffered_read: Handler disappeared! Ignoring %i bytes\n", - left); - fd->want_read = 0; -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - } - - if (left) - verbose("read_buffered: fd died, %i buffered bytes discarded\n", - left); - } - else - { - /* We have read EOF. Pass available == 0 to the handler */ - assert(fd->super.alive); - assert(fd->read); - assert(fd->want_read); - assert(self->handler); - - /* Close the fd, unless it has a write callback. */ - close_fd_read(fd); - - READ_HANDLER(self->handler, 0, NULL); - } - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -struct io_callback * -make_buffered_read(UINT32 buffer_size, - struct read_handler *handler) -{ - NEW(io_buffered_read, self); - - self->super.f = do_buffered_read; - self->buffer_size = buffer_size; - self->handler = handler; - - return &self->super; -} - -static void -do_consuming_read(struct io_callback *c, - struct lsh_fd *fd) -{ - CAST_SUBTYPE(io_consuming_read, self, c); - UINT32 wanted = READ_QUERY(self); - - assert(fd->want_read); - - if (fd->hanged_up) - { - /* If hanged_up is set, pretend that read returned 0 */ - goto eof; - } - - if (!wanted) - { - fd->want_read = 0; - } - else - { - struct lsh_string *s = lsh_string_alloc(wanted); - int res = read(fd->fd, s->data, wanted); - - if (res < 0) - { - switch(errno) - { - case EINTR: - break; - case EWOULDBLOCK: - werror("io.c: read_consume: Unexpected EWOULDBLOCK\n"); - break; - case EPIPE: - /* FIXME: I don't understand why reading should return - * EPIPE, but it happens occasionally under linux. Perhaps - * we should treat it as EOF instead? */ - werror("io.c: read_consume: Unexpected EPIPE.\n"); - default: - EXCEPTION_RAISE(fd->e, - make_io_exception(EXC_IO_READ, - fd, errno, NULL)); - break; - } - lsh_string_free(s); - } - else if (res > 0) - { - s->length = res; - A_WRITE(self->consumer, s); - } - else - { - lsh_string_free(s); - eof: - /* Close the fd, unless it has a write callback. */ - A_WRITE(self->consumer, NULL); - close_fd_read(fd); - } - } -} - -/* NOTE: Doesn't initialize the query field. That should be done in - * the subclass's constructor. */ -void init_consuming_read(struct io_consuming_read *self, - struct abstract_write *consumer) -{ - self->super.f = do_consuming_read; - self->consumer = consumer; -} - - -/* Write related callbacks */ -static void -do_write_callback(struct io_callback *s UNUSED, - struct lsh_fd *fd) -{ - /* CAST(io_write_callback, self, s); */ - UINT32 size; - int res; - - size = MIN(fd->write_buffer->end - fd->write_buffer->start, - fd->write_buffer->block_size); - assert(size); - - res = write(fd->fd, - fd->write_buffer->buffer + fd->write_buffer->start, - size); - if (!res) - fatal("Closed?"); - if (res < 0) - switch(errno) - { - case EINTR: - case EAGAIN: - break; - case EPIPE: - debug("io.c: Broken pipe.\n"); - - /* Fall through */ - default: - werror("io.c: write failed, %z\n", STRERROR(errno)); - EXCEPTION_RAISE(fd->e, - make_io_exception(EXC_IO_WRITE, fd, errno, NULL)); - close_fd(fd); - - break; - } - else - write_buffer_consume(fd->write_buffer, res); -} - -static struct io_callback io_write_callback = -{ STATIC_HEADER, do_write_callback }; - -static void -do_write_prepare(struct lsh_fd *fd) -{ - assert(fd->write_buffer); - - if (! (fd->want_write = write_buffer_pre_write(fd->write_buffer)) - && fd->write_buffer->closed) - close_fd(fd); -} - -static void -do_write_close(struct lsh_fd *fd) -{ - /* CAST(io_write_callback, self, s); */ - - assert(fd->write_buffer); - - write_buffer_close(fd->write_buffer); -} - -struct listen_value * -make_listen_value(struct lsh_fd *fd, - struct address_info *peer) -{ - NEW(listen_value, self); - - self->fd = fd; - self->peer = peer; - - return self; -} - - -/* Listen callback */ - -/* GABA: - (class - (name io_listen_callback) - (super io_callback) - (vars - (backend object io_backend) - (c object command_continuation) - (e object exception_handler))) -*/ - -static void -do_listen_callback(struct io_callback *s, - struct lsh_fd *fd) -{ - CAST(io_listen_callback, self, s); - -#if WITH_IPV6 - struct sockaddr_storage peer; -#else - struct sockaddr peer; -#endif - - socklen_t addr_len = sizeof(peer); - int conn; - - conn = accept(fd->fd, - (struct sockaddr *) &peer, &addr_len); - if (conn < 0) - { - werror("io.c: accept failed, %z", STRERROR(errno)); - return; - } - trace("io.c: accept on fd %i\n", conn); - COMMAND_RETURN(self->c, - make_listen_value(make_lsh_fd(self->backend, - conn, "accepted socket", self->e), - sockaddr2info(addr_len, - (struct sockaddr *) &peer))); -} - -struct io_callback * -make_listen_callback(struct io_backend *backend, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(io_listen_callback, self); - self->super.f = do_listen_callback; - self->backend = backend; - self->c = c; - self->e = e; - - return &self->super; -} - -/* Connect callback */ - -/* GABA: - (class - (name io_connect_callback) - (super io_callback) - (vars - (c object command_continuation))) -*/ - -static void -do_connect_callback(struct io_callback *s, - struct lsh_fd *fd) -{ - CAST(io_connect_callback, self, s); - int socket_error; - socklen_t len = sizeof(socket_error); - - /* Check if the connection was successful */ - if ((getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, - (char *) &socket_error, &len) < 0) - || socket_error) - { - debug("io.c: connect_callback: Connect failed.\n"); - EXCEPTION_RAISE(fd->e, - make_io_exception(EXC_IO_CONNECT, fd, 0, "connect failed.")); - close_fd(fd); - } - else - { - fd->write = NULL; - fd->want_write = 0; - fd->label = "connected socket"; - COMMAND_RETURN(self->c, fd); - } -} - -static struct io_callback * -make_connect_callback(struct command_continuation *c) -{ - NEW(io_connect_callback, self); - - self->super.f = do_connect_callback; - self->c = c; - - return &self->super; -} - - -/* This function is called if a connection this file somehow depends - * on disappears. For instance, the connection may have spawned a - * child process, and this file may be the stdin of that process. */ - -/* To kill a file, mark it for closing and the backend will do the work. */ -static void do_kill_fd(struct resource *r) -{ - CAST_SUBTYPE(lsh_fd, fd, r); - - /* We use close_fd_nicely, so that any data in the write buffer is - * flushed before the fd is closed. */ - if (r->alive) - close_fd_nicely(fd); -} - -/* Closes the file on i/o errors, and passes the exception on */ - -static void -do_exc_io_handler(struct exception_handler *self, - const struct exception *x) -{ - if (x->type & EXC_IO) - { - CAST_SUBTYPE(io_exception, e, x); - - if (e->fd) - close_fd(e->fd); - } - EXCEPTION_RAISE(self->parent, x); - return; -} - -/* Initializes a file structure, and adds it to the backend's list. */ -static void -init_file(struct io_backend *b, struct lsh_fd *f, int fd, - const char *label, - struct exception_handler *e) -{ - init_resource(&f->super, do_kill_fd); - - f->fd = fd; - f->label = label; - - f->e = make_exception_handler(do_exc_io_handler, e, HANDLER_CONTEXT); - - f->close_callback = NULL; - - f->prepare = NULL; - - f->hanged_up = 0; - - f->want_read = 0; - f->read = NULL; - - f->want_write = 0; - f->write = NULL; - f->write_close = NULL; - - f->next = b->files; - b->files = f; -} - -/* These functions are used by werror and friends */ - -/* For fd:s in blocking mode. */ -const struct exception * -write_raw(int fd, UINT32 length, const UINT8 *data) -{ - while(length) - { - int written = write(fd, data, length); - - if (written < 0) - switch(errno) - { - case EINTR: - case EAGAIN: - continue; - default: - return make_io_exception(EXC_IO_BLOCKING_WRITE, - NULL, errno, NULL); - } - - length -= written; - data += written; - } - return NULL; -} - -const struct exception * -write_raw_with_poll(int fd, UINT32 length, const UINT8 *data) -{ - while(length) - { - struct pollfd pfd; - int res; - int written; - - pfd.fd = fd; - pfd.events = POLLOUT; - - res = poll(&pfd, 1, -1); - - if (res < 0) - switch(errno) - { - case EINTR: - case EAGAIN: - continue; - default: - return make_io_exception(EXC_IO_BLOCKING_WRITE, - NULL, errno, NULL); - } - - written = write(fd, data, length); - - if (written < 0) - switch(errno) - { - case EINTR: - case EAGAIN: - continue; - default: - return make_io_exception(EXC_IO_BLOCKING_WRITE, - NULL, errno, NULL); - } - - length -= written; - data += written; - } - return NULL; -} - -/* For fd:s in blocking mode. */ -const struct exception * -read_raw(int fd, UINT32 length, UINT8 *data) -{ - while(length) - { - int done = read(fd, data, length); - - if (done < 0) - switch(errno) - { - case EINTR: - case EAGAIN: - continue; - default: - return make_io_exception(EXC_IO_BLOCKING_READ, - NULL, errno, NULL); - } - else if (done == 0) - { - /* EOF. */ - /* FIXME: Indicate the amount of data read, somehow. */ - return make_io_exception(EXC_IO_BLOCKING_READ, - NULL, 0, NULL); - } - - length -= done; - data += done; - } - return NULL; -} - -/* Network utility functions */ - -/* Converts a string port number or service name to a port number. - * Returns the port number in _host_ byte order, or 0 if lookup - * fails. */ - -int get_portno(const char *service, const char *protocol) -{ - if (service == NULL) - return 0; - else - { - char *end; - long portno; - - portno = strtol(service, &end, 10); - if (portno > 0 - && portno <= 65535 - && end != service - && *end == '\0') - return portno; - else - { - struct servent * serv; - - serv = getservbyname(service, protocol); - if (!serv) - return 0; - return ntohs(serv->s_port); - } - } -} - - -/* If def != 0, use that value as a fallback if the lookup fails. */ -struct address_info * -make_address_info_c(const char *host, - const char *port, - int def) -{ - int portno = get_portno(port, "tcp"); - if (!portno) - portno = def; - - if (!portno) - return NULL; - - else - { - NEW(address_info, info); - - info->port = portno; - info->ip = host ? ssh_format("%lz", host) : NULL; - - return info; - } -} - -struct address_info * -make_address_info(struct lsh_string *host, UINT32 port) -{ - NEW(address_info, info); - - info->port = port; /* htons(port); */ - info->ip = host; - return info; -} - -struct address_info * -sockaddr2info(size_t addr_len UNUSED, - struct sockaddr *addr) -{ - NEW(address_info, info); - - switch(addr->sa_family) - { - case AF_INET: - { - struct sockaddr_in *in = (struct sockaddr_in *) addr; - UINT32 ip = ntohl(in->sin_addr.s_addr); - info->port = ntohs(in->sin_port); - info->ip = ssh_format("%di.%di.%di.%di", - (ip >> 24) & 0xff, - (ip >> 16) & 0xff, - (ip >> 8) & 0xff, - ip & 0xff); - return info; - } -#if WITH_IPV6 - case AF_INET6: - { - struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; - UINT8 *ip = in->sin6_addr.s6_addr; - info->port = ntohs(in->sin6_port); - info->ip = ssh_format("%xi:%xi:%xi:%xi:%xi:%xi:%xi:%xi", - (ip[0] << 8) | ip[1], - (ip[2] << 8) | ip[3], - (ip[4] << 8) | ip[5], - (ip[6] << 8) | ip[7], - (ip[8] << 8) | ip[9], - (ip[10] << 8) | ip[11], - (ip[12] << 8) | ip[13], - (ip[14] << 8) | ip[15]); - return info; - } -#endif - case AF_UNIX: - /* Silently return NULL. This happens when a gateway client - * connects. */ - return NULL; - default: - werror("io.c: sockaddr2info: Unsupported address family.\n"); - return NULL; - } -} - -#if HAVE_GETADDRINFO -static struct addrinfo * -choose_address(struct addrinfo *list, - const int *preference) -{ - int i; - for (i = 0; preference[i]; i++) - { - struct addrinfo *p; - for (p = list; p; p = p->ai_next) - if (preference[i] == p->ai_family) - return p; - } - return NULL; -} -#endif /* HAVE_GETADDRINFO */ - -/* FIXME: Perhaps this function should be changed to return a list of - * sockaddr:s? */ -struct sockaddr * -address_info2sockaddr(socklen_t *length, - struct address_info *a, - /* Preferred address families. Zero-terminated array. */ - const int *preference, - int lookup) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - char *host; - - if (a->ip) - { - host = alloca(a->ip->length + 1); - - memcpy(host, a->ip->data, a->ip->length); - host[a->ip->length] = '\0'; - } - else - host = NULL; - -/* Some systems have getaddrinfo, but still doesn't implement all of - * RFC 2553 */ -#if defined(HAVE_GETADDRINFO) && \ - defined(HAVE_GAI_STRERROR) && defined(HAVE_AI_NUMERICHOST) - { - struct addrinfo hints; - struct addrinfo *list; - struct addrinfo *chosen; - struct sockaddr *res; - const int default_preference -#if WITH_IPV6 - [3] = { AF_INET6, AF_INET } -#else - [2] = { AF_INET, 0 } -#endif - ; - int err; - /* FIXME: It seems ugly to have to convert the port number to a - * string. */ - struct lsh_string *service = ssh_format("%di", a->port); - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - - if (!lookup) - hints.ai_flags |= AI_NUMERICHOST; - - err = getaddrinfo(host, lsh_get_cstring(service), &hints, &list); - lsh_string_free(service); - - if (err) - { - debug("address_info2sockaddr: getaddrinfo failed (err = %d): %z\n", - err, gai_strerror(err)); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - - chosen = choose_address(list, - preference ? preference : default_preference); - if (!chosen) - { - freeaddrinfo(list); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - - *length = chosen->ai_addrlen; - - res = lsh_space_alloc(*length); - memcpy(res, chosen->ai_addr, *length); - freeaddrinfo(list); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return res; - } -#else -/* !(defined(HAVE_GETADDRINFO) && - defined(HAVE_GAI_STRERROR) && defined(HAVE_AI_NUMERICHOST) */ - -#if WITH_IPV6 -#error IPv6 enabled, but getaddrinfo and friends were not found. -#endif - - if (a->ip && memchr(a->ip->data, ':', a->ip->length)) - { - debug("address_info2sockaddr: Literal IPv6 used. Failing.\n"); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - else - { - struct sockaddr_in *addr; - NEW_SPACE(addr); - - *length = sizeof(*addr); - addr->sin_port = htons(a->port); - - /* Use IPv4 only */ - addr->sin_family = AF_INET; - - if (!host) - /* Any interface */ - addr->sin_addr.s_addr = INADDR_ANY; - - else - { - /* First check for numerical ip-number */ -#if HAVE_INET_ATON - if (!inet_aton(host, &addr->sin_addr)) -#else /* !HAVE_INET_ATON */ - /* NOTE: It is wrong to work with ((unsigned long int) -1) - * directly, as this breaks Linux/Alpha systems. But - * INADDR_NONE isn't portable. That's what inet_aton is for; - * see the GNU libc documentation. */ -# ifndef INADDR_NONE -# define INADDR_NONE ((unsigned long int) -1) -# endif /* !INADDR_NONE */ - addr->sin_addr.s_addr = inet_addr(host); - if (addr->sin_addr.s_addr == INADDR_NONE) -#endif /* !HAVE_INET_ATON */ - { - struct hostent *hp; - - if (! (lookup - && (hp = gethostbyname(host)) - && (hp->h_addrtype == AF_INET))) - { - lsh_space_free(addr); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - - memcpy(&addr->sin_addr, hp->h_addr, hp->h_length); - } - } -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return (struct sockaddr *) addr; - } -#endif /* !HAVE_GETADDRINFO */ -} - - -void io_set_nonblocking(int fd) -{ -#ifndef MACOS - int old = fcntl(fd, F_GETFL); - - if (old < 0) - fatal("io_set_nonblocking: fcntl(F_GETFL) failed, %z", STRERROR(errno)); - - if (fcntl(fd, F_SETFL, old | O_NONBLOCK) < 0) - fatal("io_set_nonblocking: fcntl(F_SETFL) failed, %z", STRERROR(errno)); -#else - /*printf("io_set_nonblocking: fd : %d\n", fd); - fflush(stdout);*/ -#endif -} - -void io_set_blocking(int fd) -{ -#ifndef MACOS - int old = fcntl(fd, F_GETFL); - - if (old < 0) - fatal("io_set_blocking: fcntl(F_GETFL) failed, %z", STRERROR(errno)); - - if (fcntl(fd, F_SETFL, old & ~O_NONBLOCK) < 0) - fatal("io_set_blocking: fcntl(F_SETFL) failed, %z", STRERROR(errno)); -#else - /*printf("io_set_blocking: fd : %d\n", fd); - fflush(stdout);*/ -#endif -} - -void io_set_close_on_exec(int fd) -{ -#ifndef MACOS - /* NOTE: There's only one documented flag bit, so reading the old - * value should be redundant. */ - - int old = fcntl(fd, F_GETFD); - - if (old < 0) - fatal("io_set_nonblocking: fcntl(F_GETFD) failed, %z", STRERROR(errno)); - - if (fcntl(fd, F_SETFD, old | 1) < 0) - fatal("Can't set close-on-exec flag for fd %i: %z\n", - fd, STRERROR(errno)); -#else - /*printf("io_set_close_on_exec: fd : %d\n", fd); - fflush(stdout);*/ -#endif -} - - -/* ALL file descripters handled by the backend should use non-blocking mode, - * and have the close-on-exec flag set. */ - -void io_init_fd(int fd) -{ - io_set_nonblocking(fd); - io_set_close_on_exec(fd); -} - -struct lsh_fd * -make_lsh_fd(struct io_backend *b, - int fd, const char *label, - struct exception_handler *e) -{ - NEW(lsh_fd, f); - - io_init_fd(fd); - init_file(b, f, fd, label, e); - - return f; -} - -/* Some code is taken from Thomas Bellman's tcputils. */ -struct lsh_fd * -io_connect(struct io_backend *b, - struct sockaddr *remote, - socklen_t remote_length, - struct command_continuation *c, - struct exception_handler *e) -{ - int s = socket(remote->sa_family, SOCK_STREAM, 0); - struct lsh_fd *fd; - - if (s<0) - return NULL; - - trace("io.c: Connecting using fd %i\n", s); - - io_init_fd(s); - -#if 0 - if (local && bind(s, (struct sockaddr *)local, sizeof *local) < 0) - { - int saved_errno = errno; - close(s); - errno = saved_errno; - return NULL; - } -#endif - - if ( (connect(s, remote, remote_length) < 0) - && (errno != EINPROGRESS) ) - { - int saved_errno = errno; - close(s); - errno = saved_errno; - return NULL; - } - - fd = make_lsh_fd(b, s, "connecting socket", e); - - fd->want_write = 1; - fd->write = make_connect_callback(c); - - return fd; -} - -struct lsh_fd * -io_listen(struct io_backend *b, - struct sockaddr *local, - socklen_t length, - struct io_callback *callback, - struct exception_handler *e) -{ - int s = socket(local->sa_family, SOCK_STREAM, 0); - struct lsh_fd *fd; - - if (s<0) - return NULL; - - trace("io.c: Listening on fd %i\n", s); - - io_init_fd(s); - -#ifndef MACOS - { - int yes = 1; - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, sizeof yes); - } -#endif - - if (bind(s, (struct sockaddr *)local, length) < 0) - { - close(s); - return NULL; - } - - if (listen(s, 256) < 0) - { - close(s); - return NULL; - } - - fd = make_lsh_fd(b, s, "listening socket", e); - - fd->want_read = 1; - fd->read = callback; - - return fd; -} - - -/* AF_LOCAL sockets */ - -/* Requires DIRECTORY and NAME to be NUL-terminated */ - -struct local_info * -make_local_info(struct lsh_string *directory, - struct lsh_string *name) -{ - if (!directory || !name || memchr(name->data, '/', name->length)) - return NULL; - - assert(lsh_get_cstring(directory)); - assert(lsh_get_cstring(name)); - - { - NEW(local_info, self); - self->directory = directory; - self->name = name; - return self; - } -} - -static void -safe_popd(int old_cd, const char *directory) -{ - while (fchdir(old_cd) < 0) - if (errno != EINTR) - fatal("io.c: Failed to cd back from %z (errno = %i): %z\n", - directory, errno, STRERROR(errno)); - - close(old_cd); -} - -/* Changes the cwd, making sure that it it has reasonable permissions, - * and that we can change back later. */ -static int -safe_pushd(const char *directory, - int create) -{ - int old_cd; - struct stat sbuf; - - if (create) - { - /* First create the directory, in case it doesn't yet exist. */ - if ( (mkdir(directory, 0700) < 0) - && (errno != EEXIST) ) - { - werror("io.c: Creating directory %z failed " - "(errno = %i): %z\n", directory, errno, STRERROR(errno)); - } - } - - /* cd to it, but first save old cwd */ - - old_cd = open(".", O_RDONLY); - if (old_cd < 0) - { - werror("io.c: open(\".\") failed.\n"); - return -1; - } - - /* Test if we are allowed to cd to our current working directory. */ - while (fchdir(old_cd) < 0) - if (errno != EINTR) - { - werror("io.c: fchdir(\".\") failed (errno = %i): %z\n", - errno, strerror(errno)); - close(old_cd); - return -1; - } - - /* As far as I have been able to determine, all checks for - * fchdir:ability is performed at the time the directory was opened. - * Even if the directory is chmod:et to zero, or unlinked, we can - * probably fchdir back to old_cd later. */ - - while (chdir(directory) < 0) - if (errno != EINTR) - { - close(old_cd); - return -1; - } - - /* Check that it has reasonable permissions */ - if (stat(".", &sbuf) < 0) - { - werror("io.c: Failed to stat \".\" (supposed to be %z).\n" - " (errno = %i): %z\n", directory, errno, STRERROR(errno)); - - safe_popd(old_cd, directory); - return -1; - } - - if (sbuf.st_uid != getuid()) - { - werror("io.c: Socket directory %z not owned by user.\n", directory); - - safe_popd(old_cd, directory); - return -1; - } - - if (sbuf.st_mode & (S_IRWXG | S_IRWXO)) - { - werror("io.c: Permission bits on %z are too loose.\n", directory); - - safe_popd(old_cd, directory); - return -1; - } - - return old_cd; -} - - -struct lsh_fd * -io_listen_local(struct io_backend *b, - struct local_info *info, - struct io_callback *callback, - struct exception_handler *e) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - int old_cd; - - mode_t old_umask; - struct sockaddr_un *local; - socklen_t local_length; - - struct lsh_fd *fd; - - const char *cdir = lsh_get_cstring(info->directory); - const char *cname = lsh_get_cstring(info->name); - - assert(cdir); - assert(cname); - - /* NAME should not be a plain filename, with no directory separators. - * In particular, it should not be an absolute filename. */ - assert(!memchr(info->name->data, '/', info->name->length)); - - local_length = offsetof(struct sockaddr_un, sun_path) + info->name->length; - local = alloca(local_length); - - local->sun_family = AF_UNIX; - memcpy(local->sun_path, info->name->data, info->name->length); - - /* cd to it, but first save old cwd */ - - old_cd = safe_pushd(cdir, 1); - if (old_cd < 0) - { -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - - /* Ok, now the current directory should be a decent place for - * creating a socket. */ - - /* Try unlinking any existing file. */ - if ( (unlink(cname) < 0) - && (errno != ENOENT)) - { - werror("io.c: unlink '%S'/'%S' failed (errno = %i): %z\n", - info->directory, info->name, errno, STRERROR(errno)); - safe_popd(old_cd, cdir); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - - /* We have to change the umask, as that's the only way to control - * the permissions that bind uses. */ - -#ifndef MACOS - old_umask = umask(0077); -#endif - - /* Bind and listen */ - fd = io_listen(b, (struct sockaddr *) local, local_length, callback, e); - - /* Ok, now we restore umask and cwd */ -#ifndef MACOS - umask(old_umask); -#endif - - safe_popd(old_cd, info->directory->data); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return fd; -} - -/* Requires DIRECTORY and NAME to be NUL-terminated */ -struct lsh_fd * -io_connect_local(struct io_backend *b, - struct local_info *info, - struct command_continuation *c, - struct exception_handler *e) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - int old_cd; - - struct sockaddr_un *addr; - socklen_t addr_length; - - struct lsh_fd *fd; - - const char *cdir = lsh_get_cstring(info->directory); - - assert(cdir); - assert(lsh_get_cstring(info->name)); - - /* NAME should not be a plain filename, with no directory separators. - * In particular, it should not be an absolute filename. */ - assert(!memchr(info->name->data, '/', info->name->length)); - - addr_length = offsetof(struct sockaddr_un, sun_path) + info->name->length; - addr = alloca(addr_length); - - addr->sun_family = AF_UNIX; - memcpy(addr->sun_path, info->name->data, info->name->length); - - /* cd to it, but first save old cwd */ - - old_cd = safe_pushd(cdir, 0); - if (old_cd < 0) - { -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return NULL; - } - - fd = io_connect(b, (struct sockaddr *) addr, addr_length, c, e); - - safe_popd(old_cd, cdir); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return fd; -} - -/* Constructors */ - -struct lsh_fd * -io_read_write(struct lsh_fd *fd, - struct io_callback *read, - UINT32 block_size, - struct lsh_callback *close_callback) -{ - trace("io.c: Preparing fd %i for reading and writing\n", - fd->fd); - - /* Reading */ - fd->read = read; - fd->want_read = !!read; - - /* Writing */ - fd->write_buffer = make_write_buffer(block_size); - fd->write = &io_write_callback; - - fd->prepare = do_write_prepare; - fd->write_close = do_write_close; - - /* Closing */ - fd->close_callback = close_callback; - - return fd; -} - -struct lsh_fd * -io_read(struct lsh_fd *fd, - struct io_callback *read, - struct lsh_callback *close_callback) -{ - trace("io.c: Preparing fd %i for reading\n", fd->fd); - - /* Reading */ - fd->want_read = !!read; - fd->read = read; - - fd->close_callback = close_callback; - - return fd; -} - -struct lsh_fd * -io_write(struct lsh_fd *fd, - UINT32 block_size, - struct lsh_callback *close_callback) -{ - trace("io.c: Preparing fd %i for writing\n", fd->fd); - - /* Writing */ - fd->write_buffer = make_write_buffer(block_size); - fd->write = &io_write_callback; - - fd->prepare = do_write_prepare; - fd->write_close = do_write_close; - - fd->close_callback = close_callback; - - return fd; -} - -struct lsh_fd * -io_write_file(struct io_backend *backend, - const char *fname, int flags, int mode, - UINT32 block_size, - struct lsh_callback *c, - struct exception_handler *e) -{ - int fd = open(fname, flags, mode); - if (fd < 0) - return NULL; - - return io_write(make_lsh_fd(backend, fd, "write-only file", e), - block_size, c); -} - -struct lsh_fd * -io_read_file(struct io_backend *backend, - const char *fname, - struct exception_handler *e) -{ - int fd = open(fname, O_RDONLY); - if (fd < 0) - return NULL; - - return make_lsh_fd(backend, fd, "read-only file", e); -} - -void close_fd(struct lsh_fd *fd) -{ - trace("io.c: Closing fd %i: %z.\n", - fd->fd, fd->label); - - if (fd->super.alive) - { - fd->super.alive = 0; - - if (fd->fd < 0) - /* Unlink the file object, but don't close any - * underlying file. */ - return; - - /* Used by write fd:s to make sure that writing to its - * buffer fails. */ - if (fd->write_close) - FD_WRITE_CLOSE(fd); - - if (fd->close_callback) - LSH_CALLBACK(fd->close_callback); - - if (close(fd->fd) < 0) - { - werror("io.c: close failed, (errno = %i): %z\n", - errno, STRERROR(errno)); - EXCEPTION_RAISE(fd->e, - make_io_exception(EXC_IO_CLOSE, fd, - errno, NULL)); - } - } - else - werror("Closed already.\n"); -} - -void close_fd_nicely(struct lsh_fd *fd) -{ - /* Don't attempt to read any further. */ - - trace("io.c: close_fd_nicely called on fd %i: %z\n", - fd->fd, fd->label); - - fd->want_read = 0; - fd->read = NULL; - - if (fd->write_close) - /* Mark the write_buffer as closed */ - FD_WRITE_CLOSE(fd); - else - /* There's no data buffered for write. */ - close_fd(fd); -} - -/* Stop reading, but if the fd has a write callback, keep it open. */ -void close_fd_read(struct lsh_fd *fd) -{ - fd->want_read = 0; - fd->read = NULL; - - if (!fd->write) - /* We won't be writing anything on this fd, so close it. */ - close_fd(fd); -} - -/* Responsible for handling the EXC_FINISH_READ exception. It should - * be a parent to the connection related exception handlers, as for - * instance the protocol error handler will raise the EXC_FINISH_READ - * exception. */ -/* GABA: - (class - (name exc_finish_read_handler) - (super exception_handler) - (vars - (fd object lsh_fd))) -*/ - -static void -do_exc_finish_read_handler(struct exception_handler *s, - const struct exception *e) -{ - CAST(exc_finish_read_handler, self, s); - switch(e->type) - { - case EXC_FINISH_READ: - close_fd_nicely(self->fd); - break; - case EXC_FINISH_IO: - close_fd(self->fd); - break; - case EXC_PAUSE_READ: - self->fd->want_read = 0; - break; - case EXC_PAUSE_START_READ: - if (self->fd->read) - self->fd->want_read = 1; - break; - default: - EXCEPTION_RAISE(self->super.parent, e); - } -} - -struct exception_handler * -make_exc_finish_read_handler(struct lsh_fd *fd, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_finish_read_handler, self); - - self->super.parent = parent; - self->super.raise = do_exc_finish_read_handler; - self->super.context = context; - - self->fd = fd; - - return &self->super; -} - -const struct exception finish_read_exception = -STATIC_EXCEPTION(EXC_FINISH_READ, "Stop reading"); - -const struct exception finish_io_exception = -STATIC_EXCEPTION(EXC_FINISH_IO, "Stop i/o"); - -struct exception * -make_io_exception(UINT32 type, struct lsh_fd *fd, int error, const char *msg) -{ - NEW(io_exception, self); - assert(type & EXC_IO); - - self->super.type = type; - - if (msg) - self->super.msg = msg; - else - self->super.msg = error ? strerror(error) : "Unknown i/o error"; - - self->error = error; - self->fd = fd; - - return &self->super; -} - - -/* Creates a one-way socket connection. Returns 1 on success, 0 on - * failure. fds[0] is for reading, fds[1] for writing (like for the - * pipe system call). */ -int -lsh_make_pipe(int *fds) -{ - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) - { - werror("socketpair failed: %z\n", STRERROR(errno)); - return 0; - } - debug("Created socket pair. Using fd:s %i <-- %i\n", fds[0], fds[1]); - - if (SHUTDOWN_UNIX(fds[0], SHUT_WR_UNIX) < 0) - { - werror("shutdown(%i, SHUT_WR) failed: %z\n", fds[0], STRERROR(errno)); - goto fail; - } - if (SHUTDOWN_UNIX(fds[1], SHUT_RD_UNIX) < 0) - { - werror("shutdown(%i, SHUT_RD_UNIX) failed: %z\n", fds[0], STRERROR(errno)); - fail: - { - int saved_errno = errno; - - close(fds[0]); - close(fds[1]); - - errno = saved_errno; - return 0; - } - } - - return 1; -} - -/* Copies data from one fd to another. Works no matter if the fd:s are - * in blocking or non-blocking mode. Tries hard not to do premature - * reads; we don't want to read data into the buffer, and then - * discover that we can't write it out. - * - * The src fd may be the process stdin, and if we are too gready - * reading it, we may consume data that belongs to the user's next - * command. */ -int -lsh_copy_file(int src, int dst) -{ -#define BUF_SIZE 1024 - char buf[BUF_SIZE]; - struct pollfd src_poll; - struct pollfd dst_poll; - - src_poll.fd = src; - dst_poll.fd = dst; - - for (;;) - { - int res; - UINT32 i, length; - - /* First wait until dst is writable; otherwise there's no point - * in reading the input. */ - - dst_poll.events = POLLOUT; - - do - res = poll(&dst_poll, 1, -1); - while ( (res < 0) && (errno == EINTR)); - - debug("lsh_copy_file, initial poll on destination:\n" - " res = %i, src = %i, dst = %i, events = %xi, revents = %xi.\n", - res, src, dst, dst_poll.events, dst_poll.revents); - - assert(res == 1); - - if (!(dst_poll.revents & POLLOUT)) - /* Most likely, dst is a pipe, and there are no readers. */ - return 1; - - /* Ok, can we read anything? */ - src_poll.events = MY_POLLIN; - - do - res = poll(&src_poll, 1, -1); - while ( (res < 0) && (errno == EINTR)); - - if (res < 0) - return 0; - - debug("lsh_copy_file, poll on src:\n" - " res = %i, src = %i, dst = %i, events = %xi, revents = %xi.\n", - res, src, dst, src_poll.events, src_poll.revents); - - assert(res == 1); - - /* On linux, it seems that POLLHUP is set on read eof. */ - if (!(src_poll.revents & MY_POLLIN)) - /* EOF */ - return 1; - - assert(src_poll.revents & MY_POLLIN); - - /* Before actually reading anything, we need to check that - * the dst fd is still alive. */ - - dst_poll.events = POLLOUT; - do - res = poll(&dst_poll, 1, 0); - while ( (res < 0) && (errno == EINTR)); - - debug("lsh_copy_file, second poll on destination:\n" - " res = %i, src = %i, dst = %i, events = %xi, revents = %xi.\n", - res, src, dst, dst_poll.events, dst_poll.revents); - - if (res && !(dst_poll.revents & POLLOUT)) - { - /* NOTE: Either somebody else filled up the buffer, or - * the fd is dead. How do we know which happened? We - * can't check POLLHUP, because it seems linux always - * sets it. As a kludge, and because this condition - * should be really rare, we check our ppid to see if - * the main process have died and left us to init. */ - - debug("lsh_copy_file: ppid = %i\n", getppid()); - -#if !MACOS - if (getppid() == 1) -#endif - return 1; - } - - do - res = read(src, buf, BUF_SIZE); - while ( (res < 0) && (errno == EINTR)); - - debug("lsh_copy_file: read on fd %i returned = %i\n", src, res); - - if (res < 0) - return 0; - else if (!res) - /* EOF */ - return 1; - - length = res; - - for (i = 0; i -#include -/* For sig_atomic_t */ -#include -#include -#include -#include - - -#define GABA_DECLARE -#include "io.h.x" -#undef GABA_DECLARE - - -/* Declare the class object, so that io_commands.c can refer to it for - * type-checking. */ -extern struct lsh_class io_backend_class; - -/* GABA: - (class - (name lsh_callback) - (vars - (f method void))) -*/ - -#define LSH_CALLBACK(c) ((c)->f((c))) - -/* The fd io callback is a closure, in order to support different - * reading styles (buffered and consuming). Also used for writing. */ - -/* GABA: - (class - (name io_callback) - (vars - (f method void "struct lsh_fd *fd"))) -*/ - -#define IO_CALLBACK(c, fd) ((c)->f((c), (fd))) - -/* GABA: - (class - (name lsh_fd) - (super resource) - (vars - (next object lsh_fd) - (fd . int) - - ; For debugging purposes - (label . "const char *") - - ;; (backend object io_backend) - ;; (next_closed object lsh_fd) - - ; Used for raising i/o-exceptions. - ; Also passed on to readers of the consuming type, - ; which seems kind of bogus. - (e object exception_handler) - - ; User's close callback - (close_callback object lsh_callback) - - ; Called before poll - (prepare method void) - - ; This flag is set by the backend if it detects that a - ; connection is hanged up. - - (hanged_up . int) - - (want_read . int) - ; Called if poll indicates that data can be read. - (read object io_callback) - - (want_write . int) - ; Called if poll indicates that data can be written. - (write object io_callback) - - ; NOTE: We could put write_buffer inside the write callback, - ; but it seems simpler to keep it here, as it is needed by the - ; prepare and write_close methods. - (write_buffer object write_buffer) - - ; Called to when fd is closed for writing. - (write_close method void))) -*/ - -#define FD_PREPARE(fd) ((fd)->prepare(fd)) -#define FD_READ(fd) IO_CALLBACK((fd)->read, (fd)) -#define FD_WRITE(fd) IO_CALLBACK((fd)->write, (fd)) -#define FD_WRITE_CLOSE(fd) ((fd)->write_close(fd)) - - -/* Used for read handlers like read_line and read_packet that - * processes a little data at a time, possibly replacing the handler - * and leaving some data for the new one. */ - -/* GABA: - (class - (name io_buffered_read) - (super io_callback) - (vars - (buffer_size . UINT32) - (handler object read_handler))) -*/ - -struct io_callback * -make_buffered_read(UINT32 buffer_size, - struct read_handler *handler); - -/* Used for read handlers like read_data, that know how much data they - * can consume. */ - -/* GABA: - (class - (name io_consuming_read) - (super io_callback) - (vars - (query method UINT32) - ; Returns the maximum number of octets that - ; can be consumed immediately. - (consumer object abstract_write))) -*/ - -#define READ_QUERY(r) ((r)->query((r))) - -void init_consuming_read(struct io_consuming_read *self, - struct abstract_write *consumer); - -/* Passed to the listen callback, and to other functions and commands - * dealing with addresses. */ -/* GABA: - (class - (name address_info) - (vars - ; An ipnumber, in decimal dot notation, ipv6 format, or - ; a dns name. - (ip string) - ; The port number here is always in host byte order - (port . UINT32))) */ - -/* Used for listening and connecting to local sockets. - * Both strings have to be NUL-terminated. */ - -/* GABA: - (class - (name local_info) - (vars - (directory string) - (name string))) -*/ - -struct local_info * -make_local_info(struct lsh_string *directory, - struct lsh_string *name); - -/* Returned by listen. And also by connect, so this is an improper name. - * Functions related to AF_UNIX sockets leave the peer field as NULL. */ -/* GABA: - (class - (name listen_value) - (vars - (fd object lsh_fd) - (peer object address_info))) -*/ - -struct listen_value * -make_listen_value(struct lsh_fd *fd, - struct address_info *peer); - -/* I/O exceptions */ -/* GABA: - (class - (name io_exception) - (super exception) - (vars - ; NULL if no fd was involved - (fd object lsh_fd) - ; errno code, or zero if not available - (error . int)))) -*/ - -/* If msg is NULL, it is derived from errno */ -struct exception * -make_io_exception(UINT32 type, struct lsh_fd *fd, int error, const char *msg); - -/* Used in cases where the fd and errno are not available */ -#define STATIC_IO_EXCEPTION(type, name) \ -{ { STATIC_HEADER, (type), (name) }, NULL, 0} - -extern const struct exception finish_read_exception; -extern const struct exception finish_io_exception; - -struct io_backend * -make_io_backend(void); - -int io_iter(struct io_backend *b); -void io_run(struct io_backend *b); - -void -io_final(struct io_backend *b); - -struct resource * -io_signal_handler(struct io_backend *b, - volatile sig_atomic_t *flag, - struct lsh_callback *action); - -struct resource * -io_callout(struct io_backend *b, - UINT32 delay, - struct lsh_callback *action); - -int blocking_read(int fd, struct read_handler *r); - -int get_portno(const char *service, const char *protocol); - -struct address_info * -make_address_info_c(const char *host, - const char *port, - int def); - -struct address_info * -make_address_info(struct lsh_string *host, - UINT32 port); - -struct address_info * -sockaddr2info(size_t addr_len, - struct sockaddr *addr); - -struct sockaddr * -address_info2sockaddr(socklen_t *length, - struct address_info *a, - const int *preference, - int lookup); - -/* Returns an exception, if anything went wrong */ -const struct exception * -write_raw(int fd, UINT32 length, const UINT8 *data); -const struct exception * -write_raw_with_poll(int fd, UINT32 length, const UINT8 *data); - -const struct exception * -read_raw(int fd, UINT32 length, UINT8 *data); - -void io_set_nonblocking(int fd); -void io_set_blocking(int fd); -void io_set_close_on_exec(int fd); -void io_init_fd(int fd); - -struct lsh_fd * -make_lsh_fd(struct io_backend *b, - int fd, const char *label, - struct exception_handler *e); - -struct exception_handler * -make_exc_finish_read_handler(struct lsh_fd *fd, - struct exception_handler *parent, - const char *context); - -struct lsh_fd * -io_connect(struct io_backend *b, - struct sockaddr *remote, - socklen_t remote_length, - struct command_continuation *c, - struct exception_handler *e); - -struct lsh_fd * -io_listen(struct io_backend *b, - struct sockaddr *local, - socklen_t length, - struct io_callback *callback, - struct exception_handler *e); - -struct lsh_fd * -io_listen_local(struct io_backend *b, - struct local_info *info, - struct io_callback *callback, - struct exception_handler *e); - -struct lsh_fd * -io_connect_local(struct io_backend *b, - struct local_info *info, - struct command_continuation *c, - struct exception_handler *e); - -struct io_callback * -make_listen_callback(struct io_backend *backend, - struct command_continuation *c, - struct exception_handler *e); - -struct lsh_fd *io_read_write(struct lsh_fd *fd, - struct io_callback *read, - UINT32 block_size, - struct lsh_callback *close_callback); - -struct lsh_fd *io_read(struct lsh_fd *fd, - struct io_callback *read, - struct lsh_callback *close_callback); - -struct lsh_fd *io_write(struct lsh_fd *fd, - UINT32 block_size, - struct lsh_callback *close_callback); - -void close_fd(struct lsh_fd *fd); - -/* Stop reading from the fd, and close it as soon as the buffer - * is completely written. */ -void close_fd_nicely(struct lsh_fd *fd); - -/* Stop reading, but if the fd has a write callback, keep it open. */ -void close_fd_read(struct lsh_fd *fd); - -struct lsh_fd * -io_write_file(struct io_backend *backend, - const char *fname, int flags, - int mode, - UINT32 block_size, - struct lsh_callback *c, - struct exception_handler *e); - -struct lsh_fd * -io_read_file(struct io_backend *backend, - const char *fname, - struct exception_handler *e); - -int -lsh_make_pipe(int *fds); - -int -lsh_copy_file(int src, int dst); - -/* Socket workaround */ -#ifndef SHUTDOWN_WORKS_WITH_UNIX_SOCKETS - -/* There's an how++ missing in the af_unix shutdown implementation of - * some linux versions. Try an ugly workaround. */ -#ifdef linux - -/* From src/linux/include/net/sock.h */ -#define RCV_SHUTDOWN 1 -#define SEND_SHUTDOWN 2 - -#define SHUT_RD_UNIX RCV_SHUTDOWN -#define SHUT_WR_UNIX SEND_SHUTDOWN -#define SHUT_RD_WR_UNIX (RCV_SHUTDOWN | SEND_SHUTDOWN) - -#else /* !linux */ - -/* Don't know how to work around the broken shutdown. So disable it - * completely. */ - -#define SHUTDOWN_UNIX(fd, how) 0 - -#endif /* !linux */ -#endif /* !SHUTDOWN_WORKS_WITH_UNIX_SOCKETS */ - -#ifndef SHUTDOWN_UNIX -#define SHUTDOWN_UNIX(fd, how) (shutdown((fd), (how))) -#endif - -#ifndef SHUT_RD -#define SHUT_RD 0 -#endif - -#ifndef SHUT_WR -#define SHUT_WR 1 -#endif - -#ifndef SHUT_RD_WR -#define SHUT_RD_WR 2 -#endif - -#ifndef SHUT_RD_UNIX -#define SHUT_RD_UNIX SHUT_RD -#endif - -#ifndef SHUT_WR_UNIX -#define SHUT_WR_UNIX SHUT_WR -#endif - -#ifndef SHUT_RD_WR_UNIX -#define SHUT_RD_WR_UNIX SHUT_RD_WR -#endif - -#endif /* LSH_IO_H_INCLUDED */ diff --git a/lsh/src/io.h.x b/lsh/src/io.h.x deleted file mode 100755 index a128486..0000000 Binary files a/lsh/src/io.h.x and /dev/null differ diff --git a/lsh/src/io_commands.c b/lsh/src/io_commands.c deleted file mode 100755 index 66e366f..0000000 --- a/lsh/src/io_commands.c +++ /dev/null @@ -1,489 +0,0 @@ -/* io_commands.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "io_commands.h" - -#include "command.h" -#include "connection.h" -#include "io.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Needed only to get the error code from failed calls to io_connect */ -#include - -/* For STDIN_FILENO */ -#include - -#define GABA_DEFINE -#include "io_commands.h.x" -#undef GABA_DEFINE - -#include "io_commands.c.x" - -/* Used only by lsh-writekey */ -/* GABA: - (class - (name backend_command) - (super command) - (vars - (backend object io_backend))) -*/ - -/* (write file_info backend) - * - * Opens a file for write, and returns the corresponding write_buffer. - * */ - -static void -do_io_write_file(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(backend_command, self, s); - CAST(io_write_file_info, info, a); - - struct lsh_fd *fd = io_write_file(self->backend, - info->name, - info->flags, - info->mode, - info->block_size, - NULL, - e); - if (fd) - COMMAND_RETURN(c, fd->write_buffer); - else - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_WRITE, NULL, errno, NULL)); -} - -DEFINE_COMMAND(io_write_file_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(io_backend, backend, a); - - NEW(backend_command, self); - self->super.call = do_io_write_file; - self->backend = backend; - - COMMAND_RETURN(c, self); -} - -struct io_write_file_info * -make_io_write_file_info(const char *name, int flags, int mode, UINT32 block_size) -{ - NEW(io_write_file_info, self); - self->name = name; - self->flags = flags; - self->mode = mode; - self->block_size = block_size; - - return self; -} - -/* FIXME: Used only by lsh-writekey. Delete? */ -void do_io_read_fd(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(io_read_fd, self, s); - CAST(io_backend, backend, a); - - COMMAND_RETURN(c, make_lsh_fd(backend, - self->fd, "io_read_stdin", e)); -} - -struct io_read_fd io_read_stdin -= STATIC_IO_READ_FD(STDIN_FILENO); - - -static struct exception resolve_exception = -STATIC_EXCEPTION(EXC_RESOLVE, "address could not be resolved"); - -/* Used by do_listen_callback and any other listen variants. Currently - * doesn't perform any dns lookups. */ -static void -do_listen(struct io_backend *backend, - struct address_info *a, - /* Continuation if listen succeeds. */ - struct command_continuation *listen_c, - /* Continuation if accept succeeds. */ - struct command_continuation *accept_c, - struct exception_handler *e) -{ - struct sockaddr *addr; - socklen_t addr_length; - - struct lsh_fd *fd; - - addr = address_info2sockaddr(&addr_length, a, NULL, 0); - if (!addr) - { - EXCEPTION_RAISE(e, &resolve_exception); - return; - } - - fd = io_listen(backend, - addr, addr_length, - make_listen_callback(backend, accept_c, e), - e); - lsh_space_free(addr); - - if (!fd) - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_LISTEN, - NULL, errno, NULL)); - else - COMMAND_RETURN(listen_c, fd); - } - -/* A listen function taking three arguments: - * (listen callback backend port). - * - * Suitable for handling forwarding requests. NOTE: The calling - * function has to do all remembering of the fd:s. */ - -DEFINE_COMMAND3(listen_with_callback) - (struct lsh_object *a1, - struct lsh_object *a2, - struct lsh_object *a3, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, callback, a1); - CAST(io_backend, backend, a2); - CAST(address_info, address, a3); - - /* No dns lookups */ - do_listen(backend, address, - c, - make_apply(callback, - &discard_continuation, e), e); -} - - -/* GABA: - (class - (name connect_continuation) - (super command_continuation) - (vars - (target object address_info) - (up object command_continuation))) -*/ - -static void -do_connect_continuation(struct command_continuation *c, - struct lsh_object *x) -{ - CAST(connect_continuation, self, c); - CAST(lsh_fd, fd, x); - - COMMAND_RETURN(self->up, make_listen_value(fd, self->target)); -} - -static struct command_continuation * -make_connect_continuation(struct address_info *target, - struct command_continuation *up) -{ - NEW(connect_continuation, self); - self->super.c = do_connect_continuation; - self->target = target; - self->up = up; - - return &self->super; -} - -static void -do_connect(struct io_backend *backend, - struct address_info *a, - struct resource_list *resources, - struct command_continuation *c, - struct exception_handler *e) -{ - struct sockaddr *addr; - socklen_t addr_length; - struct lsh_fd *fd; - - /* Address must specify a host */ - assert(a->ip); - - /* Performs dns lookups */ - addr = address_info2sockaddr(&addr_length, a, NULL, 1); - if (!addr) - { - EXCEPTION_RAISE(e, &resolve_exception); - return; - } - - /* If the name is canonicalized in any way, we should pass the - * canonical name to make_connect_continuation .*/ - fd = io_connect(backend, addr, addr_length, - make_connect_continuation(a, c), e); - lsh_space_free(addr); - - if (!fd) - { - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_CONNECT, NULL, errno, NULL)); - return; - } - - if (resources) - REMEMBER_RESOURCE(resources, - &fd->super); -} - - -/* Connect variant, taking a connection object as argument (used for - * rememembering the connected fd). - * - * (connect backend port connection) -> fd */ - -/* GABA: - (class - (name connect_port) - (super command) - (vars - (backend object io_backend) - (target object address_info))) -*/ - -static void -do_connect_port(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(connect_port, self, s); - CAST(ssh_connection, connection, x); - - do_connect(self->backend, self->target, connection->resources, c, e); -} - - -struct command * -make_connect_port(struct io_backend *backend, - struct address_info *target) -{ - NEW(connect_port, self); - self->super.call = do_connect_port; - self->backend = backend; - self->target = target; - - return &self->super; -} - - -/* GABA: - (class - (name simple_io_command) - (super command) - (vars - (backend object io_backend) - (resources object resource_list))) -*/ - -/* Simple connect function taking port only as argument. Also used for - * listen. - * - * (connect address) */ - -static void -do_simple_connect(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(simple_io_command, self, s); - CAST(address_info, address, a); - - do_connect(self->backend, address, NULL, c, e); -} - -struct command * -make_simple_connect(struct io_backend *backend, - struct resource_list *resources) -{ - NEW(simple_io_command, self); - self->backend = backend; - self->resources = resources; - - self->super.call = do_simple_connect; - - return &self->super; -} - - -/* (connect connection port) */ -/* GABA: - (class - (name connect_connection) - (super command) - (vars - (backend object io_backend))) -*/ - -static void -do_connect_connection(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(connect_connection, self, s); - CAST(ssh_connection, connection, x); - - COMMAND_RETURN(c, - make_simple_connect(self->backend, connection->resources)); -} - -struct command * -make_connect_connection(struct io_backend *backend) -{ - NEW(connect_connection, self); - self->super.call = do_connect_connection; - self->backend = backend; - - return &self->super; -} - - -/* GABA: - (class - (name listen_local) - (super command) - (vars - (backend object io_backend) - (info object local_info))) -*/ - -static void -do_listen_local(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(listen_local, self, s); - CAST_SUBTYPE(command, callback, x); - - struct lsh_fd *fd - = io_listen_local(self->backend, - self->info, - make_listen_callback(self->backend, - make_apply(callback, - &discard_continuation, e), - e), - e); - if (!fd) - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_LISTEN, - NULL, errno, NULL)); - else - COMMAND_RETURN(c, fd); -} - -struct command * -make_listen_local(struct io_backend *backend, - struct local_info *info) -{ - NEW(listen_local, self); - self->backend = backend; - self->info = info; - - self->super.call = do_listen_local; - - return &self->super; -} - -/* GABA: - (class - (name connect_local) - (super command) - (vars - (backend object io_backend))) -*/ - -static void -do_connect_local(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(connect_local, self, s); - CAST(local_info, info, x); - - io_connect_local(self->backend, info, - make_connect_continuation(NULL, c), - e); -} - -struct command * -make_connect_local(struct io_backend *backend) -{ - NEW(connect_local, self); - self->backend = backend; - - self->super.call = do_connect_local; - - return &self->super; -} - -DEFINE_COMMAND(connect_local_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(io_backend, backend, a); - COMMAND_RETURN(c, make_connect_local(backend)); -} - - -/* Takes a listen_value as argument, logs the peer address, and - * returns the fd object. */ - -DEFINE_COMMAND(io_log_peer_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(listen_value, lv, a); - - verbose("Accepting connection from %S, port %i\n", - lv->peer->ip, lv->peer->port); - - COMMAND_RETURN(c, lv); -} - - -/* *** - * - * (lambda (backend connection port) - (listen backend connection port - (lambda (peer) - (start-io peer (request-forwarded-tcpip connection peer))))) - */ diff --git a/lsh/src/io_commands.c.x b/lsh/src/io_commands.c.x deleted file mode 100755 index a84da45..0000000 Binary files a/lsh/src/io_commands.c.x and /dev/null differ diff --git a/lsh/src/io_commands.h b/lsh/src/io_commands.h deleted file mode 100755 index 027b005..0000000 --- a/lsh/src/io_commands.h +++ /dev/null @@ -1,106 +0,0 @@ -/* io_commands.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_IO_COMMANDS_H_INCLUDED -#define LSH_IO_COMMANDS_H_INCLUDED - -#include "command.h" -#include "connection.h" -#include "io.h" - -#define GABA_DECLARE -#include "io_commands.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name io_write_file_info) - (vars - (name . "const char *") - (flags . int) - (mode . int) - (block_size . UINT32))) -*/ - -struct io_write_file_info * -make_io_write_file_info(const char *name, int flags, int mode, UINT32 block_size); - -extern struct command io_write_file_command; - -#define IO_WRITE_FILE (&io_write_file_command.super) - -/* Read a certain fd */ - -/* GABA: - (class - (name io_read_fd) - (super command) - (vars - (fd . int))) -*/ - -void do_io_read_fd(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e); - -#define STATIC_IO_READ_FD(fd) \ -{ STATIC_COMMAND(do_io_read_fd), fd } - -extern struct io_read_fd io_read_stdin; -#define IO_READ_STDIN (&io_read_stdin.super.super) - - -struct command * -make_listen_with_callback(struct command *callback, - struct io_backend *backend); - -extern struct command_3 listen_with_callback; -#define LISTEN_CALLBACK (&listen_with_callback.super.super) - -struct command * -make_connect_port(struct io_backend *backend, - struct address_info *target); - -struct command * -make_connect_connection(struct io_backend *backend); - -struct command * -make_simple_connect(struct io_backend *backend, - struct resource_list *resources); - -struct command * -make_listen_local(struct io_backend *backend, - struct local_info *info); - -struct command * -make_connect_local(struct io_backend *backend); - -extern struct command connect_local_command; -#define CONNECT_LOCAL (&connect_local_command.super) - -extern struct command io_log_peer_command; -#define LOG_PEER (&io_log_peer_command.super) - -#endif /* LSH_IO_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/io_commands.h.x b/lsh/src/io_commands.h.x deleted file mode 100755 index f0c8890..0000000 Binary files a/lsh/src/io_commands.h.x and /dev/null differ diff --git a/lsh/src/jpoll.c b/lsh/src/jpoll.c deleted file mode 100755 index 64d0471..0000000 --- a/lsh/src/jpoll.c +++ /dev/null @@ -1,68 +0,0 @@ -/* jpoll.c - * - * This code emulates a minimal poll function, and can be used as a drop-in - * replacement for the SVID3 implementation. Note that at this time it only - * emulates the POLLIN and POLLOUT events. - * - * $id:$ */ - -/* - * AUTHOR: Sean Reifschneider - * DATE: 1998-10-10 - * COPYING: Free for unlimited use. No warranty expressed or implied. - * If it breaks, you get to keep both parts. - */ - -#include "jpoll.h" - -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -int poll(struct pollfd *fdlist, nfds_t count, int timeoutInMS) -{ - struct timeval timeout, *to; - fd_set readfdset, writefdset; - nfds_t i; - int ret, fdcount = 0; - int tsize = getdtablesize(); - - - if (timeoutInMS < 0) - to = NULL; - else { - to = &timeout; - timeout.tv_sec = timeoutInMS / 1000; - timeout.tv_usec = (timeoutInMS % 1000) * 1000; - } - - FD_ZERO(&readfdset); - FD_ZERO(&writefdset); - for (i = 0; i < count; i++) { - if (fdlist[i].fd < 0) continue; - if (fdlist[i].events & POLLIN) FD_SET(fdlist[i].fd, &readfdset); - if (fdlist[i].events & POLLOUT) FD_SET(fdlist[i].fd, &writefdset); - fdcount++; - } - - /* spec says that if all FDs are negative, then *ONLY* return zero */ - if (fdcount == 0) - return(0); - - /* clear all events */ - for (i = 0; i < count; i++) fdlist[i].revents = 0; - - if ((ret = select(tsize, &readfdset, &writefdset, NULL, to)) == -1) - return(-1); - - for (i = 0; i < count; i++) { - if (FD_ISSET(fdlist[i].fd, &readfdset)) fdlist[i].revents |= POLLIN; - if (FD_ISSET(fdlist[i].fd, &writefdset)) fdlist[i].revents |= POLLOUT; - /*trace("jpoll.c: Set FD %i = %i\n", i, fdlist[i].revents);*/ - } - /*trace("jpoll.c: Returning %i\n", ret);*/ - return(ret); -} diff --git a/lsh/src/jpoll.h b/lsh/src/jpoll.h deleted file mode 100755 index da10a28..0000000 --- a/lsh/src/jpoll.h +++ /dev/null @@ -1,30 +0,0 @@ -/* jpoll.h - * - * Header file for my poll() SVID3 emulation function. - * - * $Id$ */ - -/* - * AUTHOR: Sean Reifschneider - * DATE: 1998-10-10 - * Copyright (c) 1998 Sean Reifschneider - * - */ - -#ifndef LSH_POLL_H_INCLUDED -#define LSH_POLL_H_INCLUDED - -#define POLLIN 0x0001 /* check for input */ -#define POLLOUT 0x0004 /* check for output */ - -struct pollfd { - int fd; /* file descriptor to poll */ - short events; /* events we are interested in */ - short revents; /* events that occured */ - }; - -typedef unsigned int nfds_t; - -int poll(struct pollfd *fdlist, nfds_t count, int timeoutInMS); - -#endif /* LSH_POLL_H_INCLUDED */ diff --git a/lsh/src/keyexchange.c b/lsh/src/keyexchange.c deleted file mode 100755 index 2594090..0000000 --- a/lsh/src/keyexchange.c +++ /dev/null @@ -1,867 +0,0 @@ -/* keyexchange.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "keyexchange.h" - -#include "abstract_io.h" -/* For filter_algorithms */ -#include "algorithms.h" -#include "alist.h" -#include "command.h" -#include "connection.h" -#include "debug.h" -#include "disconnect.h" -#include "format.h" -#include "parse.h" -#include "publickey_crypto.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#define GABA_DEFINE -#include "keyexchange.h.x" -#undef GABA_DEFINE - -#include "keyexchange.c.x" - -/* GABA: - (class - (name kexinit_handler) - (super packet_handler) - (vars - (init object make_kexinit) - - ; Extra rgument for the KEYEXCHANGE_INIT call. - (extra object lsh_object) - - ; Maps names to algorithms. It's dangerous to lookup random atoms - ; in this table, as not all objects have the same type. This - ; mapping is used only on atoms that have appeared in *both* the - ; client's and the server's list of algorithms (of a certain - ; type), and therefore the remote side can't screw things up. - (algorithms object alist))) -*/ - -#define NLISTS 10 - -/* Arbitrary limit on list length */ -//#define KEXINIT_MAX_ALGORITMS 47 -#define KEXINIT_MAX_ALGORITMS 1024 - -static struct kexinit * -parse_kexinit(struct lsh_string *packet) -{ - NEW(kexinit, res); - struct simple_buffer buffer; - unsigned msg_number; - UINT32 reserved; - - struct int_list *lists[NLISTS]; - int i; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (!parse_uint8(&buffer, &msg_number) - || (msg_number != SSH_MSG_KEXINIT) ) - { - KILL(res); - return NULL; - } - - if (!parse_octets(&buffer, 16, res->cookie)) - { - KILL(res); - return NULL; - } - - for (i = 0; ifirst_kex_packet_follows) - || !parse_uint32(&buffer, &reserved) - || reserved || !parse_eod(&buffer) ) - { - /* Bad format */ - int j; - for (j = 0; jkex_algorithms = lists[0]; - res->server_hostkey_algorithms = lists[1]; - - for (i=0; iparameters[i] = lists[2 + i]; - - res->languages_client_to_server = lists[8]; - res->languages_server_to_client = lists[9]; - - return res; -} - -struct lsh_string * -format_kex(struct kexinit *kex) -{ - return ssh_format("%c%ls%A%A%A%A%A%A%A%A%A%A%c%i", - SSH_MSG_KEXINIT, - 16, kex->cookie, - kex->kex_algorithms, - kex->server_hostkey_algorithms, - kex->parameters[KEX_ENCRYPTION_CLIENT_TO_SERVER], - kex->parameters[KEX_ENCRYPTION_SERVER_TO_CLIENT], - kex->parameters[KEX_MAC_CLIENT_TO_SERVER], - kex->parameters[KEX_MAC_SERVER_TO_CLIENT], - kex->parameters[KEX_COMPRESSION_CLIENT_TO_SERVER], - kex->parameters[KEX_COMPRESSION_SERVER_TO_CLIENT], - kex->languages_client_to_server, - kex->languages_server_to_client, - kex->first_kex_packet_follows, 0); -} - -void -initiate_keyexchange(struct ssh_connection *connection) -{ - struct lsh_string *s; - int mode = connection->flags & CONNECTION_MODE; - - struct kexinit *kex = connection->kexinits[mode]; - - assert(kex->first_kex_packet_follows == !!kex->first_kex_packet); - assert(connection->kex_state == KEX_STATE_INIT); - - s = format_kex(kex); - - /* Save value for later signing */ -#if 0 - debug("initiate_keyexchange: Storing literal_kexinits[%i]\n", mode); -#endif - - connection->literal_kexinits[mode] = s; - - C_WRITE(connection, lsh_string_dup(s)); - - if (kex->first_kex_packet_follows) - { - s = kex->first_kex_packet; - kex->first_kex_packet = NULL; - - C_WRITE(connection, s); - } -} - -static int -select_algorithm(struct int_list *client_list, - struct int_list *server_list) -{ - /* FIXME: This quadratic complexity algorithm should do as long as - * the lists are short. To avoid DOS-attacks, there should probably - * be some limit on the list lengths. */ - unsigned i, j; - - for(i = 0; i < LIST_LENGTH(client_list); i++) - { - int a = LIST(client_list)[i]; - if (!a) - /* Unknown algorithm */ - continue; - for(j = 0; j < LIST_LENGTH(server_list); j++) - if (a == LIST(server_list)[j]) - return a; - } - - return 0; -} - -void -disconnect_kex_failed(struct ssh_connection *connection, const char *msg) -{ - EXCEPTION_RAISE - (connection->e, - make_protocol_exception(SSH_DISCONNECT_KEY_EXCHANGE_FAILED, - msg)); -} - -static void -do_handle_kexinit(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(kexinit_handler, closure, c); - - int kex_algorithm_atom; - int hostkey_algorithm_atom; - - int parameters[KEX_PARAMETERS]; - struct object_list *algorithms; - - int mode = connection->flags & CONNECTION_MODE; - struct kexinit *msg = parse_kexinit(packet); - - int i; - - verbose("Received KEXINIT message. Key exchange initated.\n"); - - if (connection->kex_state != KEX_STATE_INIT) - { - PROTOCOL_ERROR(connection->e, "Unexpected KEXINIT message."); - return; - } - - if (!msg) - { - disconnect_kex_failed(connection, "Invalid KEXINIT message."); - return; - } - - if (!LIST_LENGTH(msg->kex_algorithms)) - { - disconnect_kex_failed(connection, "No keyexchange method."); - return; - } - - - /* Save value for later signing */ -#if 0 - debug("do_handle_kexinit: Storing literal_kexinits[%i]\n", !mode); -#endif - connection->literal_kexinits[!mode] = lsh_string_dup(packet); - - connection->kexinits[!mode] = msg; - - /* Have we sent a kexinit message already? */ - if (!connection->kexinits[mode]) - { - struct lsh_string *packet; - struct kexinit *sent = MAKE_KEXINIT(closure->init); - connection->kexinits[mode] = sent; - packet = format_kex(sent); -#if 0 - debug("do_handle_kexinit: Storing literal_kexinits[%i]\n", mode); -#endif - connection->literal_kexinits[mode] = lsh_string_dup(packet); - - C_WRITE(connection, packet); - } - - /* Select key exchange algorithms */ - - /* FIXME: Look at the hostkey algorithm as well. */ - if (LIST(connection->kexinits[CONNECTION_CLIENT]->kex_algorithms)[0] - == LIST(connection->kexinits[CONNECTION_SERVER]->kex_algorithms)[0]) - { - /* Use this algorithm */ - kex_algorithm_atom - = LIST(connection->kexinits[CONNECTION_CLIENT]->kex_algorithms)[0]; - - connection->kex_state = KEX_STATE_IN_PROGRESS; - } - else - { - if (msg->first_kex_packet_follows) - { - /* Wrong guess */ - connection->kex_state = KEX_STATE_IGNORE; - } - - /* FIXME: Ignores that some keyexchange algorithms require - * certain features of the host key algorithms. */ - - kex_algorithm_atom - = select_algorithm(connection->kexinits[CONNECTION_CLIENT]->kex_algorithms, - connection->kexinits[CONNECTION_SERVER]->kex_algorithms); - - /* FIXME: This is actually ok for SRP. */ - if (!kex_algorithm_atom) - { - disconnect_kex_failed(connection, - "No common key exchange method.\r\n"); - return; - } - } - - hostkey_algorithm_atom - = select_algorithm(connection->kexinits[CONNECTION_CLIENT]->server_hostkey_algorithms, - connection->kexinits[CONNECTION_SERVER]->server_hostkey_algorithms); - - if (!hostkey_algorithm_atom) - { - disconnect_kex_failed(connection, "No common hostkey algorithm.\r\n"); - return; - } - - verbose("Selected keyexchange algorithm: %a\n" - " with hostkey algorithm: %a\n", - kex_algorithm_atom, hostkey_algorithm_atom); - - for(i = 0; ikexinits[CONNECTION_CLIENT]->parameters[i], - connection->kexinits[CONNECTION_SERVER]->parameters[i]); - - if (!parameters[i]) - { - disconnect_kex_failed(connection, "Algorithm negotiation failed."); - return; - } - } - - verbose("Selected bulk algorithms: (client to server, server to client)\n" - " Encryption: (%a, %a)\n" - " Message authentication: (%a, %a)\n" - " Compression: (%a, %a)\n", - parameters[0], parameters[1], - parameters[2], parameters[3], - parameters[4], parameters[5]); - - algorithms = alloc_object_list(KEX_PARAMETERS); - - for (i = 0; ialgorithms, parameters[i]); - - { - CAST_SUBTYPE(keyexchange_algorithm, kex_algorithm, - ALIST_GET(closure->algorithms, kex_algorithm_atom)); - - KEYEXCHANGE_INIT( kex_algorithm, - connection, - hostkey_algorithm_atom, - closure->extra, /* hostkey_algorithm, */ - algorithms); - } -} - -struct packet_handler * -make_kexinit_handler(struct make_kexinit *init, - struct lsh_object *extra, - struct alist *algorithms) -{ - NEW(kexinit_handler, self); - - self->super.handler = do_handle_kexinit; - - self->init = init; - self->extra = extra; - self->algorithms = algorithms; - - return &self->super; -} - -#define IV_TYPE(t) ((t) + 4) - -static struct lsh_string * -kex_make_key(struct hash_instance *secret, - UINT32 key_length, - int type, - struct lsh_string *session_id) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - /* Indexed by the KEX_* values */ - static const UINT8 tags[] = "CDEFAB"; - - struct lsh_string *key; - struct hash_instance *hash; - UINT8 *digest; - - key = lsh_string_alloc(key_length); - - debug("\nConstructing session key of type %i\n", type); - - if (!key_length) - return key; - - hash = HASH_COPY(secret); - digest = alloca(hash->hash_size); - - HASH_UPDATE(hash, 1, tags + type); - HASH_UPDATE(hash, session_id->length, session_id->data); - HASH_DIGEST(hash, digest); - - /* Is one digest large anough? */ - if (key_length <= hash->hash_size) - memcpy(key->data, digest, key_length); - - else - { - unsigned left = key_length; - UINT8 *dst = key->data; - - KILL(hash); - hash = HASH_COPY(secret); - - for (;;) - { - /* The n:th time we enter this loop, digest holds K_n (using - * the notation of section 5.2 of the ssh "transport" - * specification), and hash contains the hash state - * corresponding to - * - * H(secret | K_1 | ... | K_{n-1}) */ - - struct hash_instance *tmp; - - /* Append digest to the key data. */ - memcpy(dst, digest, hash->hash_size); - dst += hash->hash_size; - left -= hash->hash_size; - - /* And to the hash state */ - HASH_UPDATE(hash, hash->hash_size, digest); - - if (left <= hash->hash_size) - break; - - /* Get a new digest, without disturbing the hash object (as - * we'll need it again). We use another temporary hash for - * extracting the digest. */ - - tmp = HASH_COPY(hash); - HASH_DIGEST(tmp, digest); - KILL(tmp); - } - - /* Get the final digest, and use some of it for the key. */ - HASH_DIGEST(hash, digest); - memcpy(dst, digest, left); - } - KILL(hash); - - debug("Expanded key: %xs", - key->length, key->data); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return key; -} - -struct crypto_instance * -kex_make_encrypt(struct hash_instance *secret, - struct object_list *algorithms, - int type, - struct lsh_string *session_id) -{ - CAST_SUBTYPE(crypto_algorithm, algorithm, LIST(algorithms)[type]); - - struct lsh_string *key; - struct lsh_string *iv = NULL; - struct crypto_instance *crypto; - - assert(LIST_LENGTH(algorithms) == KEX_PARAMETERS); - - if (!algorithm) - return NULL; - - key = kex_make_key(secret, algorithm->key_size, - type, session_id); - - if (algorithm->iv_size) - iv = kex_make_key(secret, algorithm->iv_size, - IV_TYPE(type), session_id); - - crypto = MAKE_ENCRYPT(algorithm, key->data, - iv ? iv->data : NULL); - - lsh_string_free(key); - lsh_string_free(iv); - - return crypto; -} - -struct crypto_instance * -kex_make_decrypt(struct hash_instance *secret, - struct object_list *algorithms, - int type, - struct lsh_string *session_id) -{ - CAST_SUBTYPE(crypto_algorithm, algorithm, LIST(algorithms)[type]); - - struct lsh_string *key; - struct lsh_string *iv = NULL; - struct crypto_instance *crypto; - - assert(LIST_LENGTH(algorithms) == KEX_PARAMETERS); - - if (!algorithm) - return NULL; - - key = kex_make_key(secret, algorithm->key_size, - type, session_id); - - if (algorithm->iv_size) - iv = kex_make_key(secret, algorithm->iv_size, - IV_TYPE(type), session_id); - - crypto = MAKE_DECRYPT(algorithm, key->data, iv ? iv->data : NULL); - - lsh_string_free(key); - lsh_string_free(iv); - - return crypto; -} - -struct mac_instance * -kex_make_mac(struct hash_instance *secret, - struct object_list *algorithms, - int type, - struct lsh_string *session_id) -{ - CAST_SUBTYPE(mac_algorithm, algorithm, LIST(algorithms)[type]); - - struct mac_instance *mac; - struct lsh_string *key; - - assert(LIST_LENGTH(algorithms) == KEX_PARAMETERS); - - if (!algorithm) - return NULL; - - key = kex_make_key(secret, algorithm->key_size, - type, session_id); - - mac = MAKE_MAC(algorithm, algorithm->key_size, key->data); - - lsh_string_free(key); - return mac; -} - -static struct compress_instance * -kex_make_deflate(struct object_list *algorithms, - int type) -{ - CAST_SUBTYPE(compress_algorithm, algorithm, LIST(algorithms)[type]); - - return algorithm ? MAKE_DEFLATE(algorithm) : NULL; -} - -static struct compress_instance * -kex_make_inflate(struct object_list *algorithms, - int type) -{ - CAST_SUBTYPE(compress_algorithm, algorithm, LIST(algorithms)[type]); - - return algorithm ? MAKE_INFLATE(algorithm) : NULL; -} - -/* GABA: - (class - (name newkeys_handler) - (super packet_handler) - (vars - (crypto object crypto_instance) - (mac object mac_instance) - (compression object compress_instance))) -*/ - -static void -do_handle_newkeys(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(newkeys_handler, closure, c); - struct simple_buffer buffer; - unsigned msg_number; - - simple_buffer_init(&buffer, packet->length, packet->data); - - verbose("Received NEWKEYS. Key exchange finished.\n"); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_NEWKEYS) - && (parse_eod(&buffer))) - { - connection->rec_crypto = closure->crypto; - connection->rec_mac = closure->mac; - connection->rec_compress = closure->compression; - - connection->kex_state = KEX_STATE_INIT; - - connection->kexinits[CONNECTION_CLIENT] - = connection->kexinits[CONNECTION_SERVER] = NULL; - - lsh_string_free(connection->literal_kexinits[CONNECTION_CLIENT]); - lsh_string_free(connection->literal_kexinits[CONNECTION_SERVER]); - - connection->literal_kexinits[CONNECTION_CLIENT] - = connection->literal_kexinits[CONNECTION_SERVER] = NULL; - - connection->dispatch[SSH_MSG_NEWKEYS] = NULL; - - KILL(closure); - } - else - PROTOCOL_ERROR(connection->e, "Invalid NEWKEYS message"); -} - -struct packet_handler * -make_newkeys_handler(struct crypto_instance *crypto, - struct mac_instance *mac, - struct compress_instance *compression) -{ - NEW(newkeys_handler,self); - - self->super.handler = do_handle_newkeys; - self->crypto = crypto; - self->mac = mac; - self->compression = compression; - - return &self->super; -} - -/* Uses the same algorithms for both directions */ -/* GABA: - (class - (name simple_kexinit) - (super make_kexinit) - (vars - (r object randomness) - (kex_algorithms object int_list) - (hostkey_algorithms object int_list) - (crypto_algorithms object int_list) - (mac_algorithms object int_list) - (compression_algorithms object int_list) - (languages object int_list))) -*/ - -static struct kexinit * -do_make_simple_kexinit(struct make_kexinit *c) -{ - CAST(simple_kexinit, closure, c); - NEW(kexinit, kex); - - RANDOM(closure->r, 16, kex->cookie); - - kex->kex_algorithms = closure->kex_algorithms; - kex->server_hostkey_algorithms = closure->hostkey_algorithms; - kex->parameters[KEX_ENCRYPTION_CLIENT_TO_SERVER] - = closure->crypto_algorithms; - kex->parameters[KEX_ENCRYPTION_SERVER_TO_CLIENT] - = closure->crypto_algorithms; - kex->parameters[KEX_MAC_CLIENT_TO_SERVER] = closure->mac_algorithms; - kex->parameters[KEX_MAC_SERVER_TO_CLIENT] = closure->mac_algorithms; - kex->parameters[KEX_COMPRESSION_CLIENT_TO_SERVER] - = closure->compression_algorithms; - kex->parameters[KEX_COMPRESSION_SERVER_TO_CLIENT] - = closure->compression_algorithms; - kex->languages_client_to_server = closure->languages; - kex->languages_server_to_client = closure->languages; - kex->first_kex_packet_follows = 0; - - kex->first_kex_packet = NULL; - - return kex; -} - -struct make_kexinit * -make_simple_kexinit(struct randomness *r, - struct int_list *kex_algorithms, - struct int_list *hostkey_algorithms, - struct int_list *crypto_algorithms, - struct int_list *mac_algorithms, - struct int_list *compression_algorithms, - struct int_list *languages) -{ - NEW(simple_kexinit, res); - - res->super.make = do_make_simple_kexinit; - res->r = r; - res->kex_algorithms = kex_algorithms; - res->hostkey_algorithms = hostkey_algorithms; - res->crypto_algorithms = crypto_algorithms; - res->mac_algorithms = mac_algorithms; - res->compression_algorithms = compression_algorithms; - res->languages = languages; - - return &res->super; -} - - -/* FIXME: Move this to a separate file keyexchange_commands.c? */ -/* (kexinit_filter simple_kexinit alist) - * - * Destructively modifies the simple_kexinit to include only hostkey - * algorithms that have keys in alist. */ - -DEFINE_COMMAND2(kexinit_filter) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(simple_kexinit, init, a1); - CAST_SUBTYPE(alist, keys, a2); - - init->hostkey_algorithms - = filter_algorithms(keys, init->hostkey_algorithms); - - if (!init->hostkey_algorithms) - { - werror("No hostkey algorithms advertised.\n"); - init->hostkey_algorithms = make_int_list(1, ATOM_NONE, -1); - } - - assert(LIST_LENGTH(init->hostkey_algorithms)); - - COMMAND_RETURN(c, init); -} - - -static int -install_keys(struct object_list *algorithms, - struct ssh_connection *connection, - struct hash_instance *secret) -{ - struct crypto_instance *rec; - struct crypto_instance *send; - int is_server = connection->flags & CONNECTION_SERVER; - - assert(LIST_LENGTH(algorithms) == KEX_PARAMETERS); - - rec = kex_make_decrypt(secret, algorithms, - KEX_ENCRYPTION_SERVER_TO_CLIENT ^ is_server, - connection->session_id); - if (!rec) - /* Weak or invalid key */ - return 0; - - send = kex_make_encrypt(secret, algorithms, - KEX_ENCRYPTION_CLIENT_TO_SERVER ^ is_server, - connection->session_id); - if (!send) - { - KILL(rec); - return 0; - } - - /* Keys for receiving */ - connection->dispatch[SSH_MSG_NEWKEYS] = make_newkeys_handler - (rec, - kex_make_mac(secret, algorithms, - KEX_MAC_SERVER_TO_CLIENT ^ is_server, - connection->session_id), - kex_make_inflate(algorithms, - KEX_COMPRESSION_SERVER_TO_CLIENT ^ is_server)); - - /* Keys for sending */ - /* NOTE: The NEWKEYS-message should have been sent before this - * is done. */ - connection->send_crypto = send; - - connection->send_mac - = kex_make_mac(secret, algorithms, - KEX_MAC_CLIENT_TO_SERVER ^ is_server, - connection->session_id); - - connection->send_compress - = kex_make_deflate(algorithms, - KEX_COMPRESSION_CLIENT_TO_SERVER ^ is_server); - - return 1; -} - - -/* Returns a hash instance for generating various session keys. NOTE: - * This mechanism changed in the transport-05 draft. Before this, the - * exchange hash was not included at this point. */ -static struct hash_instance * -kex_build_secret(struct hash_algorithm *H, - struct lsh_string *exchange_hash, - struct lsh_string *K) -{ - /* We include a length field for the key, but not for the exchange - * hash. */ - - struct hash_instance *hash = MAKE_HASH(H); - struct lsh_string *s = ssh_format("%S%lS", K, exchange_hash); - - HASH_UPDATE(hash, s->length, s->data); - lsh_string_free(s); - - return hash; -} - -/* NOTE: Consumes both the exchange_hash and K */ -void -keyexchange_finish(struct ssh_connection *connection, - struct object_list *algorithms, - struct hash_algorithm *H, - struct lsh_string *exchange_hash, - struct lsh_string *K) -{ - struct hash_instance *hash; - - /* Send a newkeys message, and install a handler for receiving the - * newkeys message. */ - - C_WRITE(connection, ssh_format("%c", SSH_MSG_NEWKEYS)); - - /* A hash instance initialized with the key, to be used for key - * generation */ - hash = kex_build_secret(H, exchange_hash, K); - lsh_string_free(K); - - /* Record session id */ - if (!connection->session_id) - connection->session_id = exchange_hash; - else - lsh_string_free(exchange_hash); - - if (!install_keys(algorithms, connection, hash)) - { - werror("Installing new keys failed. Hanging up.\n"); - KILL(hash); - - PROTOCOL_ERROR(connection->e, "Refusing to use weak key."); - - return; - } - - KILL(hash); - - connection->kex_state = KEX_STATE_NEWKEYS; - -#if DATAFELLOWS_WORKAROUNDS - if (! (connection->peer_flags & PEER_SEND_NO_DEBUG)) -#endif - send_verbose(connection->write, "Key exchange successful!", 0); - - if (connection->established) - { - struct command_continuation *c = connection->established; - connection->established = NULL; - - COMMAND_RETURN(c, connection); - } -} diff --git a/lsh/src/keyexchange.c.x b/lsh/src/keyexchange.c.x deleted file mode 100755 index 65b85ce..0000000 Binary files a/lsh/src/keyexchange.c.x and /dev/null differ diff --git a/lsh/src/keyexchange.h b/lsh/src/keyexchange.h deleted file mode 100755 index 5824938..0000000 --- a/lsh/src/keyexchange.h +++ /dev/null @@ -1,167 +0,0 @@ -/* keyexchange.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_KEYEXCHANGE_H_INCLUDED -#define LSH_KEYEXCHANGE_H_INCLUDED - -#include "abstract_crypto.h" -#include "abstract_compress.h" -#include "alist.h" - -/* NOTE: The only thing in this file that needs bignum.h is the - * declaration of kex_build_secret(). Perhaps, that indicates that the - * function doesn't really belong here? */ - -#include "bignum.h" -#include "list.h" -#include "connection.h" - -#define KEX_ENCRYPTION_CLIENT_TO_SERVER 0 -#define KEX_ENCRYPTION_SERVER_TO_CLIENT 1 -#define KEX_MAC_CLIENT_TO_SERVER 2 -#define KEX_MAC_SERVER_TO_CLIENT 3 -#define KEX_COMPRESSION_CLIENT_TO_SERVER 4 -#define KEX_COMPRESSION_SERVER_TO_CLIENT 5 - -#define KEX_PARAMETERS 6 - -/* A KEX_INIT msg can be accepted. This is true, most of the time. */ -#define KEX_STATE_INIT 0 - -/* Ignore next packet */ -#define KEX_STATE_IGNORE 1 - -/* Key exchange is in progress. Neither KEX_INIT or NEWKEYS messages - * can be received */ -#define KEX_STATE_IN_PROGRESS 2 - -/* Key exchange is finished. A NEWKEYS message should be received, and - * nothing else. */ -#define KEX_STATE_NEWKEYS 3 - -#define GABA_DECLARE -#include "keyexchange.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name keyexchange_algorithm) - (vars - ;; FIXME: Add some method or attribute describing - ;; the requirements on the hostkey algorithm. - - ; Algorithms is an array indexed by the KEX_* values above - (init method void - "struct ssh_connection *connection" - "int hostkey_algorithm_atom" - "struct lsh_object *extra" - "struct object_list *algorithms"))) -*/ - -#define KEYEXCHANGE_INIT(kex, connection, ha, e, a) \ -((kex)->init((kex), (connection), (ha), (e), (a))) - -/* GABA: - (class - (name kexinit) - (vars - (cookie array UINT8 16); - ; Lists of atoms - (kex_algorithms object int_list) - (server_hostkey_algorithms object int_list) - (parameters array (object int_list) KEX_PARAMETERS) - (languages_client_to_server object int_list) - (languages_server_to_client object int_list) - (first_kex_packet_follows . int) - ; May be NULL. Used only for sending. - (first_kex_packet string))) -*/ - -/* This function generates a new kexinit message. - * - * If a speculative packet follows, it is stored in the last field. */ - -/* GABA: - (class - (name make_kexinit) - (vars - (make method (object kexinit)) )) -*/ - -#define MAKE_KEXINIT(s) ((s)->make((s))) - -struct lsh_string *format_kex(struct kexinit *kex); -void disconnect_kex_failed(struct ssh_connection *connection, const char *msg); - -struct crypto_instance * -kex_make_encrypt(struct hash_instance *secret, - struct object_list *algorithms, - int type, - struct lsh_string *session_id); - -struct crypto_instance * -kex_make_decrypt(struct hash_instance *secret, - struct object_list *algorithms, - int type, - struct lsh_string *session_id); - -struct mac_instance * -kex_make_mac(struct hash_instance *secret, - struct object_list *algorithms, - int type, - struct lsh_string *session_id); - -struct make_kexinit * -make_simple_kexinit(struct randomness *r, - struct int_list *kex_algorithms, - struct int_list *hostkey_algorithms, - struct int_list *crypto_algorithms, - struct int_list *mac_algorithms, - struct int_list *compression_algorithms, - struct int_list *languages); - -extern struct command_2 kexinit_filter; -#define KEXINIT_FILTER (&kexinit_filter.super.super) - -void initiate_keyexchange(struct ssh_connection *connection); - -struct packet_handler * -make_kexinit_handler(struct make_kexinit *init, - struct lsh_object *extra, - struct alist *algorithms); - -struct packet_handler * -make_newkeys_handler(struct crypto_instance *crypto, - struct mac_instance *mac, - struct compress_instance *compression); - -void -keyexchange_finish(struct ssh_connection *connection, - struct object_list *algorithms, - struct hash_algorithm *H, - struct lsh_string *exchange_hash, - struct lsh_string *K); - -#endif /* LSH_KEYEXCHANGE_H_INCLUDED */ diff --git a/lsh/src/keyexchange.h.x b/lsh/src/keyexchange.h.x deleted file mode 100755 index 0fce63e..0000000 Binary files a/lsh/src/keyexchange.h.x and /dev/null differ diff --git a/lsh/src/lcp b/lsh/src/lcp deleted file mode 100644 index fab51ae..0000000 --- a/lsh/src/lcp +++ /dev/null @@ -1,200 +0,0 @@ -#! /bin/sh - -# rcp-like copying program. Requires bash on the remote machine, but -# no other special programs. - -# lsh, an implementation of the ssh protocol -# -# Copyright (C) 2001 Niels Möller -# -# 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 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 should 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 - -set -e - -verbose=no -dry_run=no -force=no - -function werror () { - if [ "x$verbose" = xyes ] ; then - echo 1>&2 "$@" - fi -} - -function usage () { - echo "Usage: lcp [OPTIONS] SOURCE DESTINATION" - echo - echo "Both SOURCE and DESTINATION can be files on remote machines." - echo "Valid file specifications are:" - echo - echo " file" - echo " machine:file" - echo " user@machine:file" - echo - echo "Valid options are:" - echo - echo " --help display this message" - echo " -f, --force overwrite existing files" - echo " -v, --verbose display commands before they are executed" - echo " -n, --dry-run don't execute any commands. Implies -v" -} - -# This could be improved, e.g. by inserting a backslash -# before each character. -function quote () { - echo '"'"$1"'"' -} - -# Splits an argument of the form [[user@]host:]file -function split_spec () { - host='' - user='' - file="$1" - case "$file" in - *:*) - host=${1%:*} - file=${1#*:} - case "$host" in - *@*) - user=${host%@*} - host=${host#*@} - ;; - esac - ;; - esac -} - -# Arguments USER HOST FILE -function read_src () { - local user="${1:+-l}$1" - local host="$2" - local file="$3" - - if [ -z "$host" ]; then - werror "From: cat "`quote "$file"` - if [ "x$dry_run" = xno ] ; then - cat "$file" - fi - else - file=`quote "$file"` - werror "From: " ${LCP_SSH:-lsh} $user "$host" cat "$file" - if [ "x$dry_run" = no ] ; then - ${LCP_SSH:-lsh} $user "$host" cat "$file" - fi - fi -} - -# Arguments USER HOST FILE SRC_FILE -function write_dst () { - local user="${1:+-l}$1" - local host="$2" - local file="$3" - local src_file=`quote "$4"` - - if [ -z "$host" ]; then - werror "To: cat >"`quote "$file"` - if [ "x$dry_run" = xno ] ; then - cat > "$file" - fi - else - file=`quote "$file"` - command="$set_clobber ; if [ -d $file ] ; then cat > $file/$src_file ; else cat > $file ; fi" - - werror "To: " ${LCP_SSH:-lsh} $user "$host" "bash -c '$command'" - - if [ $dry_run = no ] ; then - ${LCP_SSH:-lsh} $user "$host" bash -c "'$command'" - fi - fi -} - -function foo () -{ - split_spec "$1" - echo user: `quote "$user"` - echo host: `quote "$host"` - echo file: `quote "$file"` -} - -while [ $# -ge 1 ]; do - case "$1" in - --usage|--help) - usage - exit 1; - ;; - -v|--verbose) - verbose=yes - ;; - -n|--dry-run) - dry_run=yes - verbose=yes - ;; - -f|--force) - force=yes - ;; - --) - shift - if [ $# != 2 ] ; then - usage - exit 1 - fi - break - ;; - -*) - echo "lcp: unrecognized option \`$1'" - echo "Try \`lcp --help' or \`lcp --usage' for more information." - exit 1; - ;; - *) - break - ;; - esac - shift -done - -if [ $# != 2 ] ; then - usage - exit 1 -fi - -split_spec "$1" -src_user="$user" -src_host="$host" -src_file="$file" - -split_spec "$2" -dst_user="$user" -dst_host="$host" -dst_file="$file" - -# echo dry_run: $dry_run -# echo verbose: $verbose - -if [ "x$force" = xyes ] ; then - set_clobber='set +C' -else - # noclobber - set_clobber='set -C' -fi - -$set_clobber - -if [ "x$dry_run" = xyes ] ; then - read_src "$src_user" "$src_host" "$src_file" - write_dst "$dst_user" "$dst_host" "$dst_file" "$src_file" -else - read_src "$src_user" "$src_host" "$src_file" \ - | write_dst "$dst_user" "$dst_host" "$dst_file" "$src_file" -fi diff --git a/lsh/src/list.c b/lsh/src/list.c deleted file mode 100755 index 7b4fd98..0000000 --- a/lsh/src/list.c +++ /dev/null @@ -1,94 +0,0 @@ -/* list.h - * - * Variable length lists of atoms (or other integers). - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "list.h" - -#include -#include - -#define GABA_DEFINE -#include "list.h.x" -#undef GABA_DEFINE - -#include "xalloc.h" - -struct int_list *make_int_listv(unsigned n, va_list args) -{ - unsigned i; - - struct int_list *l = alloc_int_list(n); - - for (i=0; i= 0); - LIST(l)[i] = atom; - } - - assert(va_arg(args, int) == -1); - - return l; -} - -struct int_list *make_int_list(unsigned n, ...) -{ - va_list args; - struct int_list *l; - - va_start(args, n); - l = make_int_listv(n, args); - va_end(args); - - return l; -} - -struct object_list *make_object_listv(unsigned n, va_list args) -{ - unsigned i; - - struct object_list *l = alloc_object_list(n); - - /* FIXME: Add sanity type checking */ - for (i=0; i - -#define GABA_DECLARE -#include "list.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name list_header) - (vars - (length . unsigned))) -*/ - -/* FIXME: Should this be a list of unsigned ints? */ -/* GABA: - (class - (name int_list) - (super list_header) - (vars - ; This is really of variable size - (elements var-array int "super.length"))) -*/ - -/* GABA: - (class - (name object_list) - (super list_header) - (vars - ; This is really of variable size - (elements var-array (object lsh_object) "super.length"))) -*/ - -#define LIST(x) ((x)->elements) -#define LIST_LENGTH(x) ((x)->super.length) - - -struct list_header * -lsh_list_alloc(struct lsh_class *class, - unsigned length, size_t element_size); - -#define alloc_int_list(n) \ - ((struct int_list *) lsh_list_alloc(&CLASS(int_list), (n), sizeof(int))) - -struct int_list *make_int_listv(unsigned length, va_list args); -struct int_list *make_int_list(unsigned length, ...); - -#define alloc_object_list(n) \ - ((struct object_list *) \ - lsh_list_alloc(&CLASS(object_list), (n), sizeof(struct lsh_object *))) - -struct object_list *make_object_listv(unsigned length, va_list args); -struct object_list *make_object_list(unsigned length, ...); - -#endif /* LSH_LIST_H_INCLUDED */ diff --git a/lsh/src/list.h.x b/lsh/src/list.h.x deleted file mode 100755 index d1fcc66..0000000 Binary files a/lsh/src/list.h.x and /dev/null differ diff --git a/lsh/src/lookup_verifier.c b/lsh/src/lookup_verifier.c deleted file mode 100755 index 036a478..0000000 --- a/lsh/src/lookup_verifier.c +++ /dev/null @@ -1,31 +0,0 @@ -/* lookup_verifier.h - * - * Lookup signature verifiers of a public key - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should 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 - */ - -#include "lookup_verifier.h" - -#define GABA_DEFINE -#include "lookup_verifier.h.x" -#undef GABA_DEFINE - diff --git a/lsh/src/lookup_verifier.h b/lsh/src/lookup_verifier.h deleted file mode 100755 index 71936ad..0000000 --- a/lsh/src/lookup_verifier.h +++ /dev/null @@ -1,54 +0,0 @@ -/* lookup_verifier.h - * - * Lookup signature verifiers of a public key - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should 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 - */ - -#ifndef LSH_LOOKUP_VERIFIER_H_INCLUDED -#define LSH_LOOKUP_VERIFIER_H_INCLUDED - -#include "lsh.h" -#include "abstract_crypto.h" - -#define GABA_DECLARE -#include "lookup_verifier.h.x" -#undef GABA_DECLARE - -/* Maps a key blob to a signature verifier, using some signature - * algorithm and some method to determine the authenticity of the key. - * Returns NULL if the key is invalid or not trusted. */ - -/* GABA: - (class - (name lookup_verifier) - (vars - (lookup method (object verifier) - "int method" - - ; NOTE: The user is only needed on the server side. - "struct lsh_user *user" - "struct lsh_string *key"))) -*/ - -#define LOOKUP_VERIFIER(l, m, kh, key) ((l)->lookup((l), (m), (kh), (key))) - -#endif /* LSH_LOOKUP_VERIFIER_H_INCLUDED */ diff --git a/lsh/src/lookup_verifier.h.x b/lsh/src/lookup_verifier.h.x deleted file mode 100755 index 7a7589b..0000000 Binary files a/lsh/src/lookup_verifier.h.x and /dev/null differ diff --git a/lsh/src/lsh-authorize b/lsh/src/lsh-authorize deleted file mode 100755 index 73aa083..0000000 Binary files a/lsh/src/lsh-authorize and /dev/null differ diff --git a/lsh/src/lsh-decode-key.c b/lsh/src/lsh-decode-key.c deleted file mode 100755 index 653d709..0000000 --- a/lsh/src/lsh-decode-key.c +++ /dev/null @@ -1,278 +0,0 @@ -/* lsh-decode-key.c - * - * Decode ssh2 keys. - * - * $Id$ - */ - -#if macintosh -#include "lshprefix.h" -#include "lsh_context.h" -#endif - -#include "dsa.h" -#include "io.h" -#include "lsh_argp.h" -#include "publickey_crypto.h" -#include "read_file.h" -#include "rsa.h" -#include "sexp_commands.h" -#include "spki.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include "lsh-decode-key.c.x" - -/* Option parsing */ - -const char *argp_program_version -= "lsh-decode-key-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -/* GABA: - (class - (name lsh_decode_key_options) - (vars - ; Output filename - (file . "char *") - - ; Assume input is base64 - (base64 . int) - (style . sexp_argp_state))) -*/ - -static struct lsh_decode_key_options * -make_lsh_decode_key_options(void) -{ - NEW(lsh_decode_key_options, self); - self->file = NULL; - self->base64 = 0; - self->style = -1; - - return self; -} - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "output-file", 'o', "Filename", 0, "Default is stdout", 0 }, - { "base64", 'b', NULL, 0, "Input is base64 encoded", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_output_argp, 0, NULL, 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lsh_decode_key_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->style; - break; - - case ARGP_KEY_END: - if (self->style < 0) - self->style = self->file ? SEXP_CANONICAL : SEXP_TRANSPORT; - break; - - case 'b': - self->base64 = 1; - break; - - case 'o': - self->file = arg; - break; - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - NULL, - ( "Converts a raw OpenSSH/ssh2 public key to sexp-format.\v" - "Usually invoked by the ssh-conv script."), - main_argp_children, - NULL, NULL -}; - - -#define EXC_APP_UNKNOWN_KEY (EXC_APP + 1) -#define EXC_APP_BAD_KEY (EXC_APP + 2) -#define EXC_APP_BAD_ARMOUR (EXC_APP + 3) -#define EXC_APP_BAD_FORMAT (EXC_APP + 4) - -/* GABA: - (class - (name decode_key) - (super abstract_write) - (vars - (c object command_continuation) - (e object exception_handler))) -*/ - -static void -do_decode_key(struct abstract_write *s, - struct lsh_string *contents) -{ - CAST(decode_key, self, s); - - /* Stop reading. */ - EXCEPTION_RAISE(self->e, &finish_io_exception); - - if (!contents) - { - EXCEPTION_RAISE(self->e, - make_simple_exception(EXC_APP_BAD_ARMOUR, - "Invalid base64 data.")); - } - else - { - struct simple_buffer buffer; - int type; - - simple_buffer_init(&buffer, contents->length, contents->data); - - if (!parse_atom(&buffer, &type)) - EXCEPTION_RAISE(self->e, - make_simple_exception(EXC_APP_BAD_FORMAT, - "Invalid (binary) input data.\n")); - else - switch (type) - { - case ATOM_SSH_DSS: - { - struct verifier *v; - - werror("lsh-decode-key: Reading key of type ssh-dss...\n"); - - if (! ( (v = parse_ssh_dss_public(&buffer)) )) - { - EXCEPTION_RAISE(self->e, - make_simple_exception(EXC_APP_BAD_KEY, - "Invalid dsa key.\n")); - return; - } - - COMMAND_RETURN(self->c, spki_make_public_key(v)); - break; - } - case ATOM_SSH_RSA: - { - struct verifier *v; - - werror("lsh-decode-key: Reading key of type ssh-rsa...\n"); - - if (! ( (v = parse_ssh_rsa_public(&buffer)) )) - { - EXCEPTION_RAISE(self->e, - make_simple_exception(EXC_APP_BAD_KEY, - "Invalid rsa key.\n")); - return; - } - - COMMAND_RETURN(self->c, spki_make_public_key(v)); - break; - } - default: - EXCEPTION_RAISE(self->e, - make_simple_exception(EXC_APP_BAD_KEY, - "Unknown key type.")); - } - - } -} - -static struct abstract_write * -make_decode_key(struct command_continuation *c, - struct exception_handler *e) -{ - NEW(decode_key, self); - self->super.write = do_decode_key; - self->c = c; - self->e = e; - - return &self->super; -} - -static void -do_exc_lsh_decode_key(struct exception_handler *s UNUSED, - const struct exception *e) -{ - werror("lsh-decode-key: %z\n", e->msg); - - exit(EXIT_FAILURE); -} - -static struct exception_handler exc_handler = -STATIC_EXCEPTION_HANDLER(do_exc_lsh_decode_key, NULL); - -#define MAX_FILE 30000 -#define BLOCKSIZE 1024 - -#ifdef MACOS -char *applname = "lsh-decode-key"; -char *defargstr = ""; -int appl_main(int argc, char **argv); -#define main appl_main -#endif - -int main(int argc, char **argv) -{ - struct io_backend *backend = make_io_backend(); - - struct lsh_decode_key_options *options = make_lsh_decode_key_options(); - struct exception_handler *e; - struct lsh_fd *in; - struct lsh_fd *out; - - argp_parse(&main_argp, argc, argv, 0, NULL, options); - - in = make_lsh_fd(backend, STDIN_FILENO, "stdin", - &exc_handler); - - /* We want an exception handler that deals with EXC_FINISH_IO. */ - e = make_exc_finish_read_handler(in, &exc_handler, HANDLER_CONTEXT); - - if (options->file) - out = io_write_file(backend, options->file, - O_WRONLY | O_CREAT, 0666, - BLOCKSIZE, NULL, e); - else - out = io_write(make_lsh_fd(backend, STDOUT_FILENO, - "stdout", e), - BLOCKSIZE, NULL); - io_read - (in, - make_buffered_read(BLOCKSIZE, - (options->base64 ? make_read_base64 : make_read_file) - (make_decode_key - (make_apply - (make_sexp_print_to(options->style, - &out->write_buffer->super), - &discard_continuation, e), e), - MAX_FILE)), - NULL); - - io_run(backend); - - return EXIT_SUCCESS; -} diff --git a/lsh/src/lsh-decode-key.c.x b/lsh/src/lsh-decode-key.c.x deleted file mode 100755 index d84eefb..0000000 Binary files a/lsh/src/lsh-decode-key.c.x and /dev/null differ diff --git a/lsh/src/lsh-export-key.c b/lsh/src/lsh-export-key.c deleted file mode 100755 index 4a61e1e..0000000 --- a/lsh/src/lsh-export-key.c +++ /dev/null @@ -1,410 +0,0 @@ -/* lsh-export-key.c - * - * Reads an sexp in given form, and writes it in ssh2 form. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Jean-Pierre Stierlin, Niels Möller - * - * 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 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 should 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 - */ - -/* Test output: -[nisse@cuckoo src]$ ./lsh-export-key < testkey.pub ----- BEGIN SSH2 PUBLIC KEY ---- -Comment: "768-bit dsa" -AAAAB3NzaC1kc3MAAABhAJw3J7CMyAKiX8F1Mz1dNguVQi7VZQQrLl8DeWNQaSkqmIPjsc -zSn4Cjv9BOt8FM46AZbw+aSou0jpiFPJJiQjpT5U1ArPLoMqRpopqcZqcVubRKALTzytgw -vvXyoHb84wAAABUAmm14nnnHQtwx5ZUgRrjv98iv4KcAAABgENZmq1qm4jdJJB7IAC5Ecr -vcjhlACNcPD4UQ0Bgk66/MJOxvrwf0V+ZtTfb8ZaQlKdu84vB2VxVcB8zo0ds01I6eLG2f -/nDENvwp0TkNKf1uyEWPjNQGI/ImAqukiSWjAAAAYDe6o/C8faYCpuduLPQrl8Co6z7HgC -yIaRCzBjD8bY6L5qZp4G//8PVJVhxXh3vAS6LbgDCFoa2HZ1/vxHpML+gl3FPjAOxZPs27 -B2CTISEmV3KYx5NJpyKC3IBw/ckP6Q== ----- END SSH2 PUBLIC KEY ---- -*/ - -#if 0 -#if macintosh -#include "lshprefix.h" -#include "lsh_context.h" -#endif -#endif - -#include "algorithms.h" -#include "alist.h" -#include "atoms.h" -#include "crypto.h" -#include "format.h" -#include "io.h" -#include "lsh.h" -#include "lsh_argp.h" -#include "sexp_commands.h" -#include "spki.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include -#include - -#include "lsh-export-key.c.x" - - -/* Global, for simplicity */ -int exit_code = EXIT_SUCCESS; - -/* (print out sexp) */ -/* GABA: - (class - (name ssh2_print_command) - (super command_2) - (vars - (algorithms object alist) - (subject . "const char *") - (comment . "const char *"))) -*/ - -static struct lsh_string * -make_header(const char *name, const char *value) -{ - return value - ? ssh_format("%lz: %lz\n", name, value) - : ssh_format(""); -} - -static struct lsh_string * -insert_newlines(struct lsh_string *input, unsigned width, int free) -{ - unsigned out = input->length + ((input->length > width) ? input->length / width + 1 : 1); - struct lsh_string *output = lsh_string_alloc(out); - unsigned in = 0; - out = 0; - while ( in < input->length ) - { - int len = (input->length - in < width) ? input->length - in : width; - memcpy(output->data + out, input->data + in, len ); - in += len; - out += len; - output->data[out++] = '\n'; - } - if (free) - lsh_string_free(input); - return output; -} - -static void -do_ssh2_print_command(struct command_2 *s, - struct lsh_object *a1, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(ssh2_print_command, self, s); - CAST_SUBTYPE(abstract_write, dest, a1); - CAST_SUBTYPE(sexp, expr, x); - - struct sexp_iterator *i; - struct verifier *v; - - if (!sexp_check_type(expr, ATOM_PUBLIC_KEY, &i)) - { - EXCEPTION_RAISE - (e, make_simple_exception - (EXC_APP, - "Only conversion of public keys implemented.\n")); - return; - } - - expr = SEXP_GET(i); - - if (!expr) - { - EXCEPTION_RAISE - (e, make_simple_exception - (EXC_APP, - "Invalid (empty) public key expression.\n")); - return; - } - - v = spki_make_verifier(self->algorithms, expr); - if (!v) - { - EXCEPTION_RAISE - (e, make_simple_exception - (EXC_APP, - "Unsupported algorithm.")); - } - -#if MACOS - A_WRITE(dest, ssh_format("---- BEGIN SSH2 PUBLIC KEY ----\n" - "%lfS" - "%lfS" - "%lfS" - "---- END SSH2 PUBLIC KEY ----\n", - make_header("Subject", self->subject), - make_header("Comment", self->comment), - insert_newlines(encode_base64(PUBLIC_KEY(v), NULL, 0, 0, 1), 70, 1))); -#else - A_WRITE(dest, ssh_format("---- BEGIN SSH2 PUBLIC KEY ----\n" - "%lfS" - "%lfS" - "\n%lfS\n" - "---- END SSH2 PUBLIC KEY ----\n", - make_header("Subject", self->subject), - make_header("Comment", self->comment), - encode_base64(PUBLIC_KEY(v), NULL, 1, 0, 1))); -#endif - COMMAND_RETURN(c, x); -} - -static struct command * -make_ssh2_print_command(struct alist *algorithms, - const char *s, const char *c) -{ - NEW(ssh2_print_command, self); - self->super.super.call = do_command_2; - self->super.invoke = do_ssh2_print_command; - self->algorithms = algorithms; - self->subject = s; - self->comment = c; - return &self->super.super; -} - - -/* GABA: - (expr - (name make_export_key) - (params - (read object command) - (print object command) - (dest object abstract_write)) - (expr - (lambda (in) - (print dest (read in))))) -*/ - - -static void -do_exc_export_key_handler(struct exception_handler *self, - const struct exception *x) -{ - /* CAST(exc_export_key_handler, self, s); */ - - switch (x->type) - { - case EXC_APP: - werror("%z", x->msg); - break; - case EXC_SEXP_SYNTAX: - werror("Invalid SEXP input.\n"); - exit_code = EXIT_FAILURE; - /* Fall through */ - case EXC_SEXP_EOF: - /* Normal termination */ - EXCEPTION_RAISE(self->parent, &finish_read_exception); - break; - case EXC_IO_WRITE: - case EXC_IO_READ: - { - CAST(io_exception, e, x); - exit_code = EXIT_FAILURE; - werror("lsh-export-key: %z, (errno = %i)\n", x->msg, e->error); - break; - } - default: - exit_code = EXIT_FAILURE; - EXCEPTION_RAISE(self->parent, x); - return; - } -} - -/* Option parsing */ - -const char *argp_program_version -= "lsh-export-key-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -#define OPT_INFILE 'r' -#define OPT_OUTFILE 'o' -#define OPT_SUBJECT 's' -#define OPT_COMMENT 'c' - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "input-file", OPT_INFILE, "Filename", 0, "Default is stdin", 0 }, - { "output-file", OPT_OUTFILE, "Filename", 0, "Default is stdout", 0 }, - { "subject", OPT_SUBJECT, "subject string", 0, "Add subject to output key.", 0 }, - { "comment", OPT_COMMENT, "comment string", 0, "Add comment to output key.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -/* GABA: -(class - (name export_key_options) - (vars - (input . sexp_argp_state) - (algorithms object alist) - (infile . "const char *") - (outfile . "const char *") - (subject . "const char *") - (comment . "const char *") - (print object command) -)) -*/ - -static struct export_key_options *make_options(void) -{ - NEW(export_key_options, self); - self->input = SEXP_TRANSPORT; - self->infile = NULL; - self->subject = NULL; - self->comment = NULL; - self->algorithms = all_signature_algorithms(NULL); - - return self; -} - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_input_argp, 0, NULL, 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(export_key_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->input; - // state->child_inputs[1] = &self->output; - state->child_inputs[1] = NULL; - break; - case ARGP_KEY_END: - self->print = make_ssh2_print_command(self->algorithms, - self->subject, - self->comment); - break; - case OPT_INFILE: - self->infile = arg; - break; - case OPT_OUTFILE: - self->outfile = arg; - break; - case OPT_SUBJECT: - self->subject = arg; - break; - case OPT_COMMENT: - self->comment = arg; - break; - } - - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, NULL, - "Reads an s-expression on stdin, and outputs the same " - "s-expression on stdout, using OpenSSH/SSH2 encoding format.", - main_argp_children, - NULL, NULL -}; - - -#define SEXP_BUFFER_SIZE 1024 - -#ifdef MACOS -char *applname = "lsh-export-key"; -//char *defargstr = "-r identity.pub"; -char *defargstr = ""; -int appl_main(int argc, char **argv); -#define main appl_main -#endif - -#define MAX_KEY_SIZE 10000 - -int main(int argc, char **argv) -{ - struct export_key_options *options = make_options(); - struct exception_handler *e; - struct lsh_fd *in; - struct lsh_fd *out; - - struct io_backend *backend = make_io_backend(); - - argp_parse(&main_argp, argc, argv, 0, NULL, options); - - /* Patch the parent pointer later */ - e = make_exception_handler(do_exc_export_key_handler, - NULL, HANDLER_CONTEXT); - - if (options->infile) - { - in = io_read_file(backend, options->infile, e); - if (!in) - { - werror("Failed to open '%z': %z\n", - options->infile, STRERROR(errno)); - return EXIT_FAILURE; - } - } - else - in = make_lsh_fd(backend, STDIN_FILENO, "stdin", e); - - if (options->outfile) - { - out = io_write_file(backend, options->outfile, - O_WRONLY | O_CREAT, 0666, - SEXP_BUFFER_SIZE, NULL, e); - } - else - out = io_write(make_lsh_fd(backend, STDOUT_FILENO, - "stdout", e), - SEXP_BUFFER_SIZE, NULL); - - { - CAST_SUBTYPE(command, work, - make_export_key( - make_read_sexp_command(options->input, 0, MAX_KEY_SIZE), - options->print, - &(out->write_buffer->super))); - - /* Fixing the exception handler creates a circularity */ - e->parent = make_exc_finish_read_handler(in, - &default_exception_handler, - HANDLER_CONTEXT); - - COMMAND_CALL(work, in, - &discard_continuation, e); - } - io_run(backend); - - return exit_code; - } - diff --git a/lsh/src/lsh-export-key.c.x b/lsh/src/lsh-export-key.c.x deleted file mode 100755 index 5e1ff62..0000000 Binary files a/lsh/src/lsh-export-key.c.x and /dev/null differ diff --git a/lsh/src/lsh-keygen.c b/lsh/src/lsh-keygen.c deleted file mode 100755 index 0ac29e3..0000000 --- a/lsh/src/lsh-keygen.c +++ /dev/null @@ -1,262 +0,0 @@ -/* lsh-keygen.c - * - * Generic key-generation program. Writes a spki-packaged private key - * on stdout. You would usually pipe this to some other program to - * extract the public key, encrypt the private key, and save the - * results in two separate files. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" -#include "dsa.h" -#include "format.h" -#include "io.h" -#include "publickey_crypto.h" -#include "randomness.h" -#include "rsa.h" -#include "sexp.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include "lsh_argp.h" - -#include -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include "lsh-keygen.c.x" - -/* Option parsing */ - -const char *argp_program_version -= "lsh-keygen-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -/* GABA: - (class - (name lsh_keygen_options) - (vars - (style . sexp_argp_state) - ; 'd' means dsa, 'r' rsa - (algorithm . int) - (level . int))) -*/ - -static struct lsh_keygen_options * -make_lsh_keygen_options(void) -{ - NEW(lsh_keygen_options, self); - self->style = SEXP_TRANSPORT; - self->level = -1; - self->algorithm = 'd'; - return self; -} - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "algorithm", 'a', "Algorithm", 0, "DSA or RSA. " - "Default is to generate DSA keys", 0 }, - { "nist-level", 'l', "Security level", 0, "For DSA keys, this is the " - "NIST security level: Level 0 uses 512-bit primes, level 8 uses " - "1024 bit primes, and the default is 8. For RSA keys, it's the " - "bit length of the modulus, and the default is 2048 bits.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_output_argp, 0, NULL, 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lsh_keygen_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->style; - state->child_inputs[1] = NULL; - break; - - case ARGP_KEY_END: - switch (self->algorithm) - { - case 'd': - if (self->level < 0) - self->level = 8; - else if (self->level > 8) - argp_error(state, "Security level for DSA should be in the range 0-8."); - - break; - case 'r': - if (self->level < 0) - self->level = 2048; - else if (self->level < 512) - argp_error(state, "RSA keys should be at least 512 bits."); - break; - default: - fatal("Internal error!\n"); - } - break; - - case 'l': - { - char *end; - long l = strtol(arg, &end, 0); - - if (!*arg || *end) - { - argp_error(state, "Invalid security level."); - break; - } - if (l<0) - { - argp_error(state, "Security level can't be negative."); - break; - } - self->level = l; - break; - } - - case 'a': - if (!strcasecmp(arg, "dsa")) - self->algorithm = 'd'; - else if (!strcasecmp(arg, "rsa")) - self->algorithm = 'r'; - else - argp_error(state, "Unknown algorithm. The supported algorithms are " - "RSA and DSA."); - - break; - - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - "[-l LEVEL] [-a ALGORITHM]", - ( "Generates a new private key for the given algorithm and security level.\v" - "You will usually want to pipe the new key into a program like lsh-writekey, " - "to split it into its private and public parts, and optionally encrypt " - "the private information."), - main_argp_children, - NULL, NULL -}; - -static void -do_lsh_keygen_handler(struct exception_handler *s UNUSED, - const struct exception *e) -{ - werror("lsh-keygen: %z\n", e->msg); - - exit(EXIT_FAILURE); -} - -static struct exception_handler handler = -STATIC_EXCEPTION_HANDLER(do_lsh_keygen_handler, NULL); - -#ifdef MACOS -char *applname = "lsh-keygen"; -char *defargstr = ""; -int appl_main(int argc, char **argv); -#define main appl_main -#endif - -int main(int argc, char **argv) -{ - struct lsh_keygen_options * options - = make_lsh_keygen_options(); - - struct sexp *key; - struct randomness_with_poll *r; - - struct lsh_string *out; - const struct exception *e; - - argp_parse(&main_argp, argc, argv, 0, NULL, options); - - r = make_default_random(NULL, &handler); - - switch (options->algorithm) - { - case 'd': - key = dsa_generate_key(&r->super, options->level); - break; - case 'r': - { - mpz_t e; - mpz_init(e); - - for (;;) - { - /* Use a reasonably small random e, and make sure that at - * it is odd and has at most one more one bit. */ - bignum_random_size(e, &r->super, 30); - mpz_setbit(e, 0); - mpz_setbit(e, 17); - - key = rsa_generate_key(e, &r->super, options->level); - if (key) - break; - - verbose("Bad choice of public exponent. Trying another...\n"); - } - - mpz_clear(e); - } - break; - default: - fatal("Internal error!\n"); - } - - /* Now, output a private key spki structure. */ - - out = sexp_format(key, options->style, 0); - e = write_raw(STDOUT_FILENO, out->length, out->data); - - if (e) - { - werror("lsh-keygen: %z\n", e->msg); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - - diff --git a/lsh/src/lsh-keygen.c.x b/lsh/src/lsh-keygen.c.x deleted file mode 100755 index 956347c..0000000 Binary files a/lsh/src/lsh-keygen.c.x and /dev/null differ diff --git a/lsh/src/lsh-krb-checkpw.c b/lsh/src/lsh-krb-checkpw.c deleted file mode 100755 index f62807c..0000000 --- a/lsh/src/lsh-krb-checkpw.c +++ /dev/null @@ -1,125 +0,0 @@ -/* lsh-krb-checkpw.c - * - * $Id$ - * - * This is a helper program to verify a name and password against the - * local kerberos infrastructure. It is loosely based on Heimdal's - * implementation of "su". */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "lsh_types.h" - -#include -#include -#include - -#include - -static void usage(void) NORETURN; -static void die(char *msg) NORETURN; - -/* NOTE: It is essential that this program never ever exits successfully unless - * the the user was accepted by kerberos. */ -static void -usage(void) -{ - printf("Usage: lsh-krb-checkpw user < password\n"); - exit(EXIT_FAILURE); -} - -static void -die(char *msg) -{ - fprintf(stderr, "lsh-krb-checkpw: %s\n", msg); - exit(EXIT_FAILURE); -} - -#define PW_MAX_SIZE 40 - -static char * -read_pw(FILE *f) -{ - /* An extra byte for the terminating NUL. */ - char *buf = malloc(PW_MAX_SIZE+1); - size_t length; - - if (!buf) - return NULL; - - length = fread(buf, 1, PW_MAX_SIZE, f); - - if (!length || !feof(f)) - { - free(buf); - return NULL; - } - - assert(length <= PW_MAX_SIZE); - buf[length] = '\0'; - - return buf; -} - -int -main(int argc, char **argv) -{ - krb5_context context; - krb5_ccache ccache; - krb5_principal p; - char *name; - char *pw; - - if (argc != 2) - usage(); - - name = argv[1]; - pw = read_pw(stdin); - - if (!pw) - die("No proper password provided."); - - if (!strcmp(name, "root")) - /* In this case, heimdal's su.c creates a principal for the - * current uid, but I don't quite understand why. */ - die("Won't log in root."); - - if (krb5_init_context (&context)) - die("krb5_init_context failed."); - - if (krb5_make_principal(context, &p, NULL, name, NULL)) - die("krb5_init_context failed."); - - if (!krb5_kuserok(context, p, name)) - die("krb5_kuserok doesn't know the user."); - - if (krb5_cc_gen_new(context, &krb5_mcc_ops, &ccache)) - die("krb5_cc_gen_new failed."); - - if (krb5_verify_user_lrealm(context, p, ccache, pw, TRUE, NULL)) - die("krb5_verify_user_lrealm failed."); - - /* Authentication successful. */ - - /* TODO: Keep the credential cache in some way. Perhaps write it to - * disk, and, write the file name used to stdout. */ - - return EXIT_SUCCESS; -} diff --git a/lsh/src/lsh-writekey.c b/lsh/src/lsh-writekey.c deleted file mode 100755 index f73dd35..0000000 --- a/lsh/src/lsh-writekey.c +++ /dev/null @@ -1,497 +0,0 @@ -/* lsh-writekey.c - * - * Reads a (private) key on stdin, and saves it a private and a public file. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "algorithms.h" -#include "crypto.h" -#include "dsa.h" -#include "format.h" -#include "io_commands.h" -#include "interact.h" -#include "rsa.h" -#include "sexp_commands.h" -#include "spki_commands.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#include -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#define BLOCK_SIZE 2000 -#define MAX_SEXP_SIZE 5000 - -static struct read_sexp_command read_sexp -= STATIC_READ_SEXP(SEXP_TRANSPORT, 0, MAX_SEXP_SIZE); - -#define READ_SEXP (&read_sexp.super.super) - -struct lsh_writekey_options; - -extern struct command lsh_writekey_print_public; -#define PRINT_PUBLIC (&lsh_writekey_print_public.super) - -extern struct command lsh_writekey_print_private; -#define PRINT_PRIVATE (&lsh_writekey_print_private.super) - -extern struct command lsh_writekey_options2algorithms; -#define OPTIONS2ALGORITHMS (&lsh_writekey_options2algorithms.super) - -extern struct command lsh_writekey_options2transform; -#define TRANSFORM (&lsh_writekey_options2transform.super) - -extern struct command lsh_writekey_options2public_file; -#define OPTIONS2PUBLIC_FILE (&lsh_writekey_options2public_file.super) - -extern struct command lsh_writekey_options2private_file; -#define OPTIONS2PRIVATE_FILE (&lsh_writekey_options2private_file.super) - -#include "lsh-writekey.c.x" - - -/* Option parsing */ - -const char *argp_program_version -= "lsh-writekey-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -/* GABA: - (class - (name lsh_writekey_options) - (vars - ; Base filename - (file string) - - (tty object interact) - - (label string) - (style . sexp_argp_state) - (passphrase string) - - (crypto_algorithms object alist) - (signature_algorithms object alist) - (r object randomness) - - (crypto_name . int) - (crypto object crypto_algorithm) - (iterations . UINT32))) -*/ - -static struct lsh_writekey_options * -make_lsh_writekey_options(void) -{ - NEW(lsh_writekey_options, self); - self->file = NULL; - - /* We don't need window change tracking. */ - self->tty = make_unix_interact(NULL); - - self->label = NULL; - self->style = -1; - - self->passphrase = NULL; - self->iterations = 1500; - - self->crypto_algorithms = all_symmetric_algorithms(); - - /* NOTE: We don't need any randomness here, as we won't be signing - * anything. */ - self->signature_algorithms = all_signature_algorithms(NULL); - - /* We use this only for salt and iv generation. */ - self->r = make_bad_random(); - - /* A better default would be crypto_cbc(make_des3()) */ - self->crypto = NULL; - - return self; -} - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "output-file", 'o', "Filename", 0, "Default is ~/.lsh/identity", 0 }, - { "iteration-count", 'i', "PKCS#5 iteration count", 0, "Default is 1500", 0 }, - { "crypto", 'c', "Algorithm", 0, "Encryption algorithm for the private key file.", 0 }, - { "label", 'l', "Text", 0, "Unencrypted label for the key.", 0 }, - { "passphrase", 'p', "Password", 0, NULL, 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_output_argp, 0, NULL, 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lsh_writekey_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->style; - state->child_inputs[1] = NULL; - break; - - case ARGP_KEY_END: - if (!self->file) - { - char *home = getenv("HOME"); - struct lsh_string *s; - - if (!home) - { - argp_failure(state, EXIT_FAILURE, 0, "$HOME not set."); - return EINVAL; - } - else - { -#ifndef MACOS - s = ssh_format("%lz/.lsh", home); - if (mkdir(lsh_get_cstring(s), 0755) < 0) - { - if (errno != EEXIST) - argp_failure(state, EXIT_FAILURE, errno, "Creating directory %s failed.", s->data); - } - lsh_string_free(s); - self->file = ssh_format("%lz/.lsh/identity", home); -#else - self->file = ssh_format("%lzidentity", home); -#endif - } - } - if (self->crypto) - { - if (!self->label) - { - const char *name = getenv("LOGNAME"); -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 300 -#endif - char host[MAXHOSTNAMELEN]; - - if (!name) - { - argp_failure(state, EXIT_FAILURE, 0, - "LOGNAME not set. Please use the -l option."); - return EINVAL; - } - - if ( (gethostname(host, sizeof(host)) < 0) - && (errno != ENAMETOOLONG) ) - argp_failure(state, EXIT_FAILURE, errno, - "Can't get the host name. Please use the -l option."); - - self->label = ssh_format("%lz@%lz", name, host); - } - while (!self->passphrase) - { - struct lsh_string *pw; - struct lsh_string *again; - - pw = INTERACT_READ_PASSWORD(self->tty, 500, - ssh_format("Enter new passphrase: "), 1); - if (!pw) - argp_failure(state, EXIT_FAILURE, 0, "Aborted."); - - again = INTERACT_READ_PASSWORD(self->tty, 500, - ssh_format("Again: "), 1); - if (!again) - argp_failure(state, EXIT_FAILURE, 0, "Aborted."); - - if (lsh_string_eq(pw, again)) - self->passphrase = pw; - else - lsh_string_free(pw); - - lsh_string_free(again); - } - } - break; - - case 'o': - self->file = make_string(arg); - break; - - case 'i': - { - long i; - char *end; - i = strtol(arg, &end, 0); - - if ((end == arg) || *end || (i < 1)) - { - argp_failure(state, EXIT_FAILURE, 0, "Invalid iteration count."); - return EINVAL; - } - else if (i > PKCS5_MAX_ITERATIONS) - { - argp_error(state, "Iteration count ridiculously large (> %d).", - PKCS5_MAX_ITERATIONS); - return EINVAL; - } - else - self->iterations = i; - - break; - } - - case 'c': - { - int name = lookup_crypto(self->crypto_algorithms, arg, &self->crypto); - - if (name) - self->crypto_name = name; - else - { - list_crypto_algorithms(state, self->crypto_algorithms); - argp_error(state, "Unknown crypto algorithm '%s'.", arg); - } - break; - } - - case 'l': - self->label = ssh_format("%lz", arg); - break; - - case 'p': - self->passphrase = ssh_format("%lz", arg); - break; - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - NULL, - ( "Splits a keypair in one private and one public file, " - "optionally encrypting the private file using a passphrase.\v" - "Common usage is to pipe the output from lsh-keygen into this program." - ), - main_argp_children, - NULL, NULL -}; - -DEFINE_COMMAND(lsh_writekey_print_public) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_writekey_options, options, a); - - COMMAND_RETURN(c, - make_sexp_print_command - ((options->style > 0) - ? options->style : SEXP_TRANSPORT)); -} - -DEFINE_COMMAND(lsh_writekey_print_private) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_writekey_options, options, a); - - COMMAND_RETURN(c, - make_sexp_print_command - ((options->style > 0) - ? options->style : SEXP_CANONICAL)); -} - -DEFINE_COMMAND(lsh_writekey_options2algorithms) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_writekey_options, options, a); - COMMAND_RETURN(c, options->signature_algorithms); -} - -DEFINE_COMMAND(lsh_writekey_options2transform) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_writekey_options, options, a); - if (!options->crypto) - COMMAND_RETURN(c, &command_I); - else - { - CAST_SUBTYPE(mac_algorithm, hmac, - ALIST_GET(options->crypto_algorithms, ATOM_HMAC_SHA1)); - assert(hmac); - - COMMAND_RETURN(c, - make_pkcs5_encrypt(options->r, - lsh_string_dup(options->label), - ATOM_HMAC_SHA1, - hmac, - options->crypto_name, - options->crypto, - 10, /* Salt length */ - lsh_string_dup(options->passphrase), - options->iterations)); - } -} - -DEFINE_COMMAND(lsh_writekey_options2public_file) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_writekey_options, options, a); - struct lsh_string *public = ssh_format("%lS.pub", options->file); - - COMMAND_RETURN(c, - make_io_write_file_info(lsh_get_cstring(public), - O_CREAT | O_EXCL | O_WRONLY, - 0644, - BLOCK_SIZE)); -} - -DEFINE_COMMAND(lsh_writekey_options2private_file) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_writekey_options, options, a); - - COMMAND_RETURN(c, - make_io_write_file_info(lsh_get_cstring(options->file), - O_CREAT | O_EXCL | O_WRONLY, - 0600, - BLOCK_SIZE)); -} - -/* GABA: - (expr - (name make_writekey) - (params - (options object lsh_writekey_options)) - (expr - (lambda (backend) - (let ((key (read_sexp (io_read_stdin backend)))) - (prog1 (print_public options - (io_write_file backend - (options2public_file options)) - (verifier2public - (signer2verifier - (sexp2signer (options2algorithms options) - key)))) - (print_private options - (io_write_file backend - (options2private_file options)) - (transform options key))))))) -*/ - -static void -do_lsh_writekey_handler(struct exception_handler *s UNUSED, - const struct exception *e) -{ - /* NOTE: This is quite a complicated way to just write a friendlier - * message if we fail because the output files already exists. This - * way, it is easier to handle other kinds of errors later, as the - * need arises. */ - - switch (e->type) - { - case EXC_IO_OPEN_WRITE: - { - CAST_SUBTYPE(io_exception, x, e); - switch(x->error) - { - case EEXIST: - werror("\nlsh-writekey doesn't overwrite existing key files.\n" - "If you *really* want to do that, you should delete\n" - "the existing files \"FOO\" and \"FOO.pub\" first\n" - "(where \"FOO\" usually is \"~/.lsh/identity\").\n"); - break; - - default: - goto outer_default; - } - break; - } - outer_default: - default: - werror("lsh-writekey: %z\n", e->msg); - } - exit(EXIT_FAILURE); -} - -static struct exception_handler exc_handler = -STATIC_EXCEPTION_HANDLER(do_lsh_writekey_handler, NULL); - -#ifdef MACOS -char *applname = "lsh-writekey"; -char *defargstr = ""; -int appl_main(int argc, char **argv); -#define main appl_main -#endif - -int main(int argc, char **argv) -{ - struct io_backend *backend = make_io_backend(); - struct lsh_writekey_options *options = make_lsh_writekey_options(); - - argp_parse(&main_argp, argc, argv, 0, NULL, options); - - { - CAST_SUBTYPE - (command, work, - make_writekey(options)); - - COMMAND_CALL(work, backend, &discard_continuation, &exc_handler); - } - io_run(backend); - - return EXIT_SUCCESS; -} diff --git a/lsh/src/lsh-writekey.c.x b/lsh/src/lsh-writekey.c.x deleted file mode 100755 index dd11c8a..0000000 Binary files a/lsh/src/lsh-writekey.c.x and /dev/null differ diff --git a/lsh/src/lsh.c b/lsh/src/lsh.c deleted file mode 100755 index 8d6b8f9..0000000 --- a/lsh/src/lsh.c +++ /dev/null @@ -1,1064 +0,0 @@ -/* lsh.c - * - * client main program - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "algorithms.h" -#include "alist.h" -#include "atoms.h" -#include "channel.h" -#include "charset.h" -#include "client.h" -#include "client_keyexchange.h" -#include "client_userauth.h" -#include "compress.h" -#include "connection_commands.h" -#include "crypto.h" -#include "dsa.h" -#include "format.h" -#include "interact.h" -#include "io.h" -#include "io_commands.h" -#include "gateway.h" -#include "gateway_commands.h" -#include "handshake.h" -#include "lookup_verifier.h" -#include "randomness.h" -#include "rsa.h" -#include "sexp.h" -#include "spki_commands.h" -#include "srp.h" -#include "ssh.h" -#include "tcpforward_commands.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "lsh_argp.h" - -#if MACOS -#include "lsh_context.h" -#endif - -/* Forward declarations */ -struct command_2 lsh_verifier_command; -#define OPTIONS2VERIFIER (&lsh_verifier_command.super.super) - -struct command_2 lsh_login_command; -#define LSH_LOGIN (&lsh_login_command.super.super) - -static struct command options2known_hosts; -#define OPTIONS2KNOWN_HOSTS (&options2known_hosts.super) - -struct command options2service; -#define OPTIONS2SERVICE (&options2service.super) - -static struct command options2identities; -#define OPTIONS2IDENTITIES (&options2identities.super) - -static struct request_service request_userauth_service = -STATIC_REQUEST_SERVICE(ATOM_SSH_USERAUTH); -#define REQUEST_USERAUTH_SERVICE (&request_userauth_service.super.super) - - -#include "lsh.c.x" - -/* Block size for stdout and stderr buffers */ -#define BLOCK_SIZE 32768 - -/* Window size for the session channel - * - * NOTE: Large windows seem to trig a bug in sshd2. */ -#define WINDOW_SIZE 10000 - -/* GABA: - (class - (name lsh_options) - (super client_options) - (vars - (algorithms object algorithms_options) - - (signature_algorithms object alist) - (home . "const char *") - - (identity . "char *") - (with_publickey . int) - - (with_srp_keyexchange . int) - (with_dh_keyexchange . int) - - ; Command to invoke to start ssh-connection service) - (service object command) - - ;; (kexinit object make_kexinit) - (kex_algorithms object int_list) - - (sloppy . int) - (capture . "const char *") - (capture_file object abstract_write) - - (known_hosts . "const char *") - - (start_gateway . int))) -*/ - - -static struct lsh_options * -make_options(struct io_backend *backend, - struct exception_handler *handler, - int *exit_code) -{ - NEW(lsh_options, self); - init_client_options(&self->super, backend, - make_default_random(NULL, handler), - handler, exit_code); - - self->algorithms - = make_algorithms_options(all_symmetric_algorithms()); - - self->home = getenv("HOME"); - - self->signature_algorithms = all_signature_algorithms(&self->super.random->super); - - self->sloppy = 0; - self->capture = NULL; - self->capture_file = NULL; - - self->known_hosts = NULL; - - self->start_gateway = 0; - - self->with_publickey = 1; - - self->with_srp_keyexchange = 0; - - /* By default, enable only one of dh and srp. */ - self->with_dh_keyexchange = -1; - - self->kex_algorithms = NULL; - - return self; -} - - -/* Request ssh-userauth or ssh-connection service, as appropriate, - * and pass the options as a first argument. */ -DEFINE_COMMAND(options2service) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_options, options, a); - COMMAND_RETURN(c, options->service); -} - -/* Open hostkey database. By default, "~/.lsh/known_hosts". */ - -static void -do_options2known_hosts(struct command *ignored UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(lsh_options, options, a); - - struct lsh_string *tmp = NULL; - const char *s = NULL; - struct lsh_fd *f; - - if (options->known_hosts) - s = options->known_hosts; - else - { -#ifndef MACOS - tmp = ssh_format("%lz/.lsh/known_hosts", options->home); -#else - tmp = ssh_format("%lzknown_hosts", options->home); -#endif - s = lsh_get_cstring(tmp); - } - - f = io_read_file(options->super.backend, s, e); - - if (!f) - { -#ifndef MACOS - werror("Failed to open '%z' (errno = %i): %z.\n", - s, errno, STRERROR(errno)); -#else - verbose("Failed to open '%z' (errno = %i): %z.\n", - s, errno, STRERROR(errno)); -#endif - COMMAND_RETURN(c, make_spki_context(options->signature_algorithms)); - } - else - { - CAST_SUBTYPE(command, read, - make_spki_read_acls(options->signature_algorithms)); - COMMAND_CALL(read, f, c, e); - } - lsh_string_free(tmp); -} - -static struct command options2known_hosts = -STATIC_COMMAND(do_options2known_hosts); - -/* Read user's private keys. By default, "~/.lsh/identity". */ -static void -do_options2identities(struct command *ignored UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(lsh_options, options, a); - - struct lsh_string *tmp = NULL; - const char *s = NULL; - struct lsh_fd *f = NULL; - - trace("do_options2identities\n"); - - if (!options->with_publickey) - { - COMMAND_RETURN(c, make_object_list(0, -1)); - return; - } - if (options->identity) - { - s = options->identity; -#if MACOS - if ( access( s, R_OK ) != 0 ) { - tmp = ssh_format("%lz%lz", options->home, s); - s = lsh_get_cstring(tmp); - } -#endif - } - else - { -#ifndef MACOS - tmp = ssh_format("%lz/.lsh/identity", options->home); -#else - tmp = ssh_format("%lzidentity", options->home); -#endif - s = lsh_get_cstring(tmp); - } - - f = io_read_file(options->super.backend, s, e); - - if (!f) - { -#ifndef MACOS - werror("Failed to open '%z' (errno = %i): %z.\n", - s, errno, STRERROR(errno)); -#else - verbose("Failed to open '%z' (errno = %i): %z.\n", - s, errno, STRERROR(errno)); -#endif - COMMAND_RETURN(c, make_object_list(0, -1)); - } - else - { - struct command *command - = make_spki_read_userkeys(options->algorithms->algorithms, - options->signature_algorithms, - options->super.tty); - COMMAND_CALL(command, f, c, e); - } - lsh_string_free(tmp); -} - -static struct command options2identities = -STATIC_COMMAND(do_options2identities); - - -/* Maps a host key to a (trusted) verifier object. */ - -/* GABA: - (class - (name lsh_host_db) - (super lookup_verifier) - (vars - (db object spki_context) - (tty object interact) - (access object sexp) - (host object address_info) - ; Allow unauthorized keys - (sloppy . int) - ; If non-null, append an ACL for the received key to this file. - (file object abstract_write) - ; For fingerprinting - (hash object hash_algorithm))) -*/ - -static struct verifier * -do_lsh_lookup(struct lookup_verifier *c, - int method, - struct lsh_user *keyholder UNUSED, - struct lsh_string *key) -{ - CAST(lsh_host_db, self, c); - struct spki_subject *subject; - - switch (method) - { - case ATOM_SSH_DSS: - { - struct verifier *v = make_ssh_dss_verifier(key->length, key->data); - if (!v) - { - werror("do_lsh_lookup: Invalid ssh-dss key.\n"); - return NULL; - } - subject = SPKI_LOOKUP(self->db, - spki_make_public_key(v), - v); - assert(subject); - assert(subject->verifier); - break; - } - case ATOM_SSH_RSA: - { - struct verifier *v = make_ssh_rsa_verifier(key->length, key->data); - if (!v) - { - werror("do_lsh_lookup: Invalid ssh-rsa key.\n"); - return NULL; - } - subject = SPKI_LOOKUP(self->db, - spki_make_public_key(v), - v); - assert(subject); - assert(subject->verifier); - break; - } - -#if 0 - case ATOM_RSA_PKCS1_SHA1_LOCAL: - { - struct rsa_verifier *v = make_ssh_rsa_verifier(key->length, key->data); - if (!v) - { - werror("do_lsh_lookup: Invalid ssh-rsa key.\n"); - return NULL; - } - subject = SPKI_LOOKUP(self->db, - rsa_to_spki_public_key(&v->public), - &v->super); - assert(subject); - assert(subject->verifier); - break; - } - - case ATOM_SPKI: -#endif - /* It doesn't matter here which flavour of SPKI is used. */ - case ATOM_SPKI_SIGN_RSA: - case ATOM_SPKI_SIGN_DSS: - { - struct sexp *e = string_to_sexp(SEXP_CANONICAL, key, 0); - if (!e) - { - werror("do_lsh_lookup: Invalid spki s-expression.\n"); - return NULL; - } - - subject = SPKI_LOOKUP(self->db, e, NULL); - if (!subject) - { - werror("do_lsh_lookup: Invalid spki key.\n"); - return NULL; - } - if (!subject->verifier) - { - werror("do_lsh_lookup: Valid SPKI subject, but no key available.\n"); - return NULL; - } - break; - } - default: - werror("do_lsh_lookup: Unknown key type. Should not happen!\n"); - return NULL; - } - - assert(subject->key); - - /* Check authorization */ - - if (SPKI_AUTHORIZE(self->db, subject, self->access)) - { - verbose("SPKI host authorization successful!\n"); - } - else - { - struct sexp *acl; - - verbose("SPKI authorization failed.\n"); - if (!self->sloppy) - { - werror("Server's hostkey is not trusted. Disconnecting.\n"); - return NULL; - } - - /* Ok, let's see if we want to use this untrusted key. */ - if (!quiet_flag) - { - /* Display fingerprint */ - struct lsh_string *fingerprint - = hash_string(self->hash, - sexp_format(subject->key, SEXP_CANONICAL, 0), - 1); - - if (!INTERACT_YES_OR_NO - (self->tty, - ssh_format("Received unauthenticated key for host %lS\n" - "Fingerprint: %lfxS\n" - "Do you trust this key? (y/n) ", - self->host->ip, fingerprint), 0, 1)) - return NULL; - } - - acl = sexp_l(2, sexp_a(ATOM_ACL), - sexp_l(3, sexp_a(ATOM_ENTRY), - subject->key, - sexp_l(2, sexp_a(ATOM_TAG), - self->access, - -1), - -1), - -1); - - /* Remember this key. We don't want to ask again for key re-exchange */ - spki_add_acl(self->db, acl); - - /* Write an ACL to disk. */ - if (self->file) - { - A_WRITE(self->file, ssh_format("\n; ACL for host %lS\n", self->host->ip)); - A_WRITE(self->file, - sexp_format(acl, SEXP_TRANSPORT, 0)); - A_WRITE(self->file, ssh_format("\n")); - } - } - - return subject->verifier; -} - -static struct lookup_verifier * -make_lsh_host_db(struct spki_context *db, - struct interact *tty, - struct address_info *host, - int sloppy, - struct abstract_write *file) -{ - NEW(lsh_host_db, res); - - res->super.lookup = do_lsh_lookup; - res->db = db; - res->tty = tty; - res->access = make_ssh_hostkey_tag(host); - res->host = host; - res->sloppy = sloppy; - res->file = file; - res->hash = &sha1_algorithm; - - return &res->super; -} - -/* Takes options and an spki_context as argument and returns a - * lookup_verifier */ - -DEFINE_COMMAND2(lsh_verifier_command) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_options, options, a1); - CAST_SUBTYPE(spki_context, db, a2); - COMMAND_RETURN(c, make_lsh_host_db(db, - options->super.tty, - options->super.remote, - options->sloppy, - options->capture_file)); -} - - -/* (login options public-keys connection) */ -DEFINE_COMMAND2(lsh_login_command) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_options, options, a1); - CAST_SUBTYPE(object_list, keys, a2); - - struct client_userauth_method *password - = make_client_password_auth(options->super.tty); - - /* FIXME: Perhaps we should try "none" only when using SRP. */ - struct client_userauth_method *none - = make_client_none_auth(); - - COMMAND_RETURN(c, - make_client_userauth - (ssh_format("%lz", options->super.user), - ATOM_SSH_CONNECTION, - (LIST_LENGTH(keys) - ? make_object_list - (3, - none, - make_client_publickey_auth(keys), - password, - -1) - : make_object_list(2, none, password, -1)))); -} - - -/* NOTE: options2identities can block for reading, so it must not be - * invoked directly. */ - -/* Requests the ssh-userauth service, log in, and request connection - * service. */ -/* GABA: - (expr - (name make_lsh_userauth) - (params - (options object lsh_options)) - (expr - (lambda (connection) - (lsh_login options - - ; The prog1 delay is needed because options2identities - ; may not return immediately. - (options2identities (prog1 options connection)) - - ; Request the userauth service - (request_userauth_service connection))))) */ - -/* GABA: - (expr - (name make_lsh_connect) - (params - (connect object command) - (handshake object handshake_info) - (init object make_kexinit)) - (expr (lambda (options) - ; What to do with the service - ((progn (options2actions options)) - ; Initialize service - (init_connection_service - ; Either requests ssh-connection service, - ; or requests and uses the ssh-userauth service. - (options2service options - ; Start the ssh transport protocol - (connection_handshake - handshake init - (options2verifier options - (options2known_hosts options)) - ; Connect using tcp - (connect (options2remote options))))))))) -*/ - - -/* Option parsing */ - -const char *argp_program_version -= "lsh-" VERSION ", secsh protocol version " CLIENT_PROTOCOL_VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -#define ARG_NOT 0x400 - -#define OPT_PUBLICKEY 0x201 - -#define OPT_SLOPPY 0x202 -#define OPT_STRICT 0x203 -#define OPT_CAPTURE 0x204 - -#define OPT_HOST_DB 0x205 - -#define OPT_DH 0x206 -#define OPT_SRP 0x207 - -#define OPT_STDIN 0x210 -#define OPT_STDOUT 0x211 -#define OPT_STDERR 0x212 - -#define OPT_FORK_STDIO 0x213 - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "identity", 'i', "Identity key", 0, "Use this key to authenticate.", 0 }, - { "publickey", OPT_PUBLICKEY, NULL, 0, - "Try publickey user authentication (default).", 0 }, - { "no-publickey", OPT_PUBLICKEY | ARG_NOT, NULL, 0, - "Don't try publickey user authentication.", 0 }, -#ifndef MACOS - { "host-db", OPT_HOST_DB, "Filename", 0, "By default, ~/.lsh/known_hosts", 0}, -#else - { "host-db", OPT_HOST_DB, "Filename", 0, "By default, known_hosts", 0}, -#endif - { "sloppy-host-authentication", OPT_SLOPPY, NULL, 0, - "Allow untrusted hostkeys.", 0 }, - { "strict-host-authentication", OPT_STRICT, NULL, 0, - "Never, never, ever trust an unknown hostkey. (default)", 0 }, - { "capture-to", OPT_CAPTURE, "File", 0, - "When a new hostkey is received, append an ACL expressing trust in the key. " -#ifndef MACOS - "In sloppy mode, the default is ~/.lsh/captured_keys.", 0 }, -#else - "In sloppy mode, the default is captured_keys.", 0 }, -#endif -#if WITH_SRP - { "srp-keyexchange", OPT_SRP, NULL, 0, "Enable experimental SRP support.", 0 }, - { "no-srp-keyexchange", OPT_SRP | ARG_NOT, NULL, 0, "Disable experimental SRP support (default).", 0 }, -#endif /* WITH_SRP */ - - { "dh-keyexchange", OPT_DH, NULL, 0, - "Enable DH support (default, unless SRP is being used).", 0 }, - - { "no-dh-keyexchange", OPT_DH | ARG_NOT, NULL, 0, "Disable DH support.", 0 }, - -#if 0 - { "userauth", OPT_USERAUTH, NULL, 0, - "Request the ssh-userauth service (default, unless SRP is being used).", 0 }, - { "no-userauth", OPT_USERAUTH | ARG_NOT, NULL, 0, - "Request the ssh-userauth service (default if SRP is used).", 0 }, -#endif - - /* Actions */ - { "forward-remote-port", 'R', "remote-port:target-host:target-port", - 0, "", CLIENT_ARGP_ACTION_GROUP }, -#if !MACOS - { "gateway", 'G', NULL, 0, "Setup a local gateway", 0 }, -#endif - - { "x11-forward", 'x', NULL, 0, "Enable X11 forwarding.", CLIENT_ARGP_MODIFIER_GROUP }, - { "no-x11-forward", 'x' | ARG_NOT, NULL, 0, - "Disable X11 forwarding (default).", 0 }, - - { NULL, 0, NULL, 0, NULL, 0 } -}; - - -static const struct argp_child -main_argp_children[] = -{ - { &client_argp, 0, "", 0 }, - { &algorithms_argp, 0, "", 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -#define CASE_ARG(opt, attr, none) \ - case opt: \ - if (self->super.not) \ - { \ - self->super.not = 0; \ - \ - case opt | ARG_NOT: \ - self->attr = none; \ - break; \ - } \ - \ - self->attr = arg; \ - break - -#define CASE_FLAG(opt, flag) \ - case opt: \ - if (self->super.not) \ - { \ - self->super.not = 0; \ - \ - case opt | ARG_NOT: \ - self->flag = 0; \ - break; \ - } \ - \ - self->flag = 1; \ - break - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lsh_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->super; - state->child_inputs[1] = self->algorithms; - state->child_inputs[2] = NULL; - break; - - case ARGP_KEY_END: - if (!self->home) - { - argp_error(state, "No home directory. Please set HOME in the environment."); - break; - } - - if (self->with_dh_keyexchange < 0) - self->with_dh_keyexchange = !self->with_srp_keyexchange; - - if (self->with_dh_keyexchange || self->with_srp_keyexchange) - { - int i = 0; - self->kex_algorithms - = alloc_int_list(self->with_dh_keyexchange + self->with_srp_keyexchange); - -#if WITH_SRP - if (self->with_srp_keyexchange) - { - LIST(self->kex_algorithms)[i++] = ATOM_SRP_RING1_SHA1_LOCAL; - ALIST_SET(self->algorithms->algorithms, - ATOM_SRP_RING1_SHA1_LOCAL, - &make_srp_client(make_srp1(&self->super.random->super), - self->super.tty, - ssh_format("%lz", self->super.user)) - ->super); - } -#endif /* WITH_SRP */ - if (self->with_dh_keyexchange) - { - LIST(self->kex_algorithms)[i++] = ATOM_DIFFIE_HELLMAN_GROUP1_SHA1; - ALIST_SET(self->algorithms->algorithms, - ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, - &make_dh_client(make_dh1(&self->super.random->super)) - ->super); - } - } - else - argp_error(state, "All keyexchange algorithms disabled."); - - { - CAST_SUBTYPE(command, o, make_lsh_userauth(self)); - self->service = o; - } - - { - struct lsh_string *tmp = NULL; - const char *s = NULL; - - if (self->capture) - s = self->capture; - else if (self->sloppy) - { -#ifndef MACOS - tmp = ssh_format("%lz/.lsh/captured_keys", self->home); -#else - tmp = ssh_format("%lzcaptured_keys", self->home); -#endif - s = lsh_get_cstring(tmp); - } - if (s) - { - struct lsh_fd *f - = io_write_file(self->super.backend, s, - O_CREAT | O_APPEND | O_WRONLY, - 0600, 500, NULL, - make_report_exception_handler - (make_report_exception_info(EXC_IO, EXC_IO, - "Writing new ACL: "), - &default_exception_handler, - HANDLER_CONTEXT)); - if (f) - self->capture_file = &f->write_buffer->super; - else - { - werror("Failed to open '%z' (errno = %i): %z.\n", - s, errno, STRERROR(errno)); - } - } - lsh_string_free(tmp); - } - -#if !MACOS - /* We can't add the gateway action immediately when the -G - * option is encountered, as we need the name and port of the - * remote machine (self->super.remote) first. */ - if (self->start_gateway) - { - struct local_info *gateway; - if (!self->super.local_user) - { - argp_error(state, "You have to set LOGNAME in the environment, " - " if you want to use the gateway feature."); - break; - } - gateway = make_gateway_address(self->super.local_user, - self->super.user, - self->super.remote); - - if (!gateway) - { - argp_error(state, "Local or remote user name, or the target host name, are too " - "strange for the gateway socket name construction."); - break; - } - - client_add_action(&self->super, - make_gateway_setup - (make_listen_local(self->super.backend, gateway))); - } -#endif - - if (object_queue_is_empty(&self->super.actions)) - { - argp_error(state, "No actions given."); - break; - } - - /* Start background poll */ - RANDOM_POLL_BACKGROUND(self->super.random->poller); - - break; - - case 'i': - self->identity = arg; - break; - - CASE_FLAG(OPT_PUBLICKEY, with_publickey); - - case OPT_HOST_DB: - self->known_hosts = arg; - break; - - case OPT_SLOPPY: - self->sloppy = 1; - break; - - case OPT_STRICT: - self->sloppy = 0; - break; - - case OPT_CAPTURE: - self->capture = arg; - break; - - CASE_FLAG(OPT_DH, with_dh_keyexchange); - CASE_FLAG(OPT_SRP, with_srp_keyexchange); - - case 'R': - { - UINT32 listen_port; - struct address_info *target; - - if (!client_parse_forward_arg(arg, &listen_port, &target)) - argp_error(state, "Invalid forward specification '%s'.", arg); - - client_add_action(&self->super, make_forward_remote_port - (self->super.backend, - make_address_info((self->super.with_remote_peers - ? ssh_format("%lz", "0.0.0.0") - : ssh_format("%lz", "127.0.0.1")), - listen_port), - target)); - - self->super.remote_forward = 1; - break; - } - -#if !MACOS - CASE_FLAG('G', start_gateway); -#endif - CASE_FLAG('x', super.with_x11); - } - - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - ( "host\n" - "host command ..."), - ( "Connects to a remote machine\v" - "Connects to the remote machine, and then performs one or more actions, " - "i.e. command execution, various forwarding services. The default " - "action is to start a remote interactive shell or execute a given " - "command on the remote machine." ), - main_argp_children, - NULL, NULL -}; - -/* GABA: - (class - (name lsh_default_handler) - (super exception_handler) - (vars - (status . "int *"))) -*/ - -static void -do_lsh_default_handler(struct exception_handler *s, - const struct exception *e) -{ - CAST(lsh_default_handler, self, s); - - if (e->type & EXC_IO) - { - CAST_SUBTYPE(io_exception, exc, e); - *self->status = EXIT_FAILURE; - - werror("%z, (errno = %i)\n", e->msg, exc->error); - } - else - switch(e->type) - { - case EXC_RESOLVE: - case EXC_USERAUTH: - case EXC_SEXP_SYNTAX: - case EXC_SPKI_TYPE: - case EXC_GLOBAL_REQUEST: - case EXC_CHANNEL_REQUEST: - case EXC_CHANNEL_OPEN: - - werror("%z\n", e->msg); - *self->status = EXIT_FAILURE; - break; - default: - *self->status = EXIT_FAILURE; - EXCEPTION_RAISE(self->super.parent, e); - } -} - -static struct exception_handler * -make_lsh_default_handler(int *status, struct exception_handler *parent, - const char *context) -{ - NEW(lsh_default_handler, self); - self->super.parent = parent; - self->super.raise = do_lsh_default_handler; - self->super.context = context; - - self->status = status; - - return &self->super; -} - -#ifdef MACOS -char *applname = "lsh"; -//char *defargstr = "-ljps -c none --sloppy-host-authentication --debug --verbose --trace 192.168.1.41"; -//char *defargstr = "-lnono --debug --verbose --trace 192.168.1.41"; -//char *defargstr = "-ljps -z --debug --verbose --trace 192.168.1.41"; -//char *defargstr = "-ljps -zzlib --verbose -L22:192.168.1.41:22 192.168.1.41"; -char *defargstr = "-ljps -mmd5 -zzlib --sloppy-host-authentication --verbose 192.168.1.41"; -//char *defargstr = "-ljps -zzlib --debug --verbose --trace -L23:192.168.1.41:22 192.168.1.41"; -//char *defargstr = "-ljps -znone 192.168.1.41"; -//char *defargstr = "-lwebmaster -znone --debug --verbose --trace --sloppy-host-authentication www.tldnames.com"; -//char *defargstr = "-ljps --debug --trace --verbose --sloppy-host-authentication 192.168.1.62"; -//char *defargstr = "-lwebmaster www.tldnames.com"; -//char *defargstr = "-lwebmaster --debug --trace --verbose www.tldnames.com"; -//char *defargstr = "-ljps www.bechaotic.org"; -int appl_main(int argc, char **argv); -#define main appl_main -#endif - -int main(int argc, char **argv) -{ - struct lsh_options *options; - - /* Default exit code if something goes wrong. */ - int lsh_exit_code = 17; - - struct exception_handler *handler - = make_lsh_default_handler(&lsh_exit_code, &default_exception_handler, - HANDLER_CONTEXT); - - struct io_backend *backend = make_io_backend(); - - /* For filtering messages. Could perhaps also be used when converting - * strings to and from UTF8. */ - setlocale(LC_CTYPE, ""); - - /* FIXME: Choose character set depending on the locale */ - set_local_charset(CHARSET_LATIN1); - - options = make_options(backend, handler, &lsh_exit_code); - - argp_parse(&main_argp, argc, argv, ARGP_IN_ORDER, NULL, options); - - { - struct lsh_object *o = - make_lsh_connect( - make_simple_connect(backend, NULL), - make_handshake_info(CONNECTION_CLIENT, - "lsh - a free ssh2 on MacOS9", NULL, - SSH_MAX_PACKET, - &options->super.random->super, - options->algorithms->algorithms, - NULL), - make_simple_kexinit(&options->super.random->super, - options->kex_algorithms, - options->algorithms->hostkey_algorithms, - options->algorithms->crypto_algorithms, - options->algorithms->mac_algorithms, - options->algorithms->compression_algorithms, - make_int_list(0, -1))); - - CAST_SUBTYPE(command, lsh_connect, o); - - COMMAND_CALL(lsh_connect, options, &discard_continuation, - handler); - - } - -#if 0 - /* All commands using stdout have dup:ed stdout by now. We close it, - * because if stdout is a pipe, we want the reader to know whether - * or not anybody is still using it. */ - close(STDOUT_FILENO); - if (open("/dev/null", O_WRONLY) != STDOUT_FILENO) - werror("Strange: Final redirect of stdout to /dev/null failed.\n"); -#endif - - io_run(backend); - - /* Close all files and other resources associated with the backend. */ - io_final(backend); - - gc_final(); - - /* FIXME: Perhaps we have to reset the stdio file descriptors to - * blocking mode? */ - return lsh_exit_code; -} diff --git a/lsh/src/lsh.c.x b/lsh/src/lsh.c.x deleted file mode 100755 index 7b34e16..0000000 Binary files a/lsh/src/lsh.c.x and /dev/null differ diff --git a/lsh/src/lsh.h b/lsh/src/lsh.h deleted file mode 100755 index 2e0f807..0000000 --- a/lsh/src/lsh.h +++ /dev/null @@ -1,144 +0,0 @@ -/* lsh.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_H_INCLUDED -#define LSH_H_INCLUDED - -#include "lsh_types.h" - -#include - -/* Generic object */ - -#define LSH_ALLOC_HEAP 0 -#define LSH_ALLOC_STATIC 1 -#define LSH_ALLOC_STACK 2 - -struct lsh_class; - -struct lsh_object -{ - /* Objects are chained together, for the sweep phase of the gc. */ - struct lsh_object *next; - struct lsh_class *isa; - - char alloc_method; - char marked; - char dead; -}; - -/* NOTE: Static objects have a NULL isa-pointer, and can therefore not - * contain any references to non-static objects. This could be fixed, - * by using an argument to the STATIC_HEADER macro, but then one must - * use some class for lsh_class objects... */ - -#define STATIC_HEADER { NULL, NULL, LSH_ALLOC_STATIC, 0, 0 } -#define STACK_HEADER { NULL, NULL, LSH_ALLOC_STACK, 0, 0 } - -struct lsh_class -{ - struct lsh_object super; - struct lsh_class *super_class; - char *name; /* For debugging */ - - size_t size; - - void (*mark_instance)(struct lsh_object *instance, - void (*mark)(struct lsh_object *o)); - void (*free_instance)(struct lsh_object *instance); - - /* Particular classes may add their own methods here */ -}; - -#define MARK_INSTANCE(c, i, f) ((c)->mark_instance((i), (f))) -#define FREE_INSTANCE(c, i) ((c)->free_instance((i))) - -#define CLASS(c) (c##_class) - -#if DEBUG_ALLOC - -struct lsh_string_header -{ - int magic; /* For a sentinel value */ - /* Where/how the string was allocated */ - const char *clue; - struct lsh_string *prev; - struct lsh_string *next; -}; - -#else /* !DEBUG_ALLOC */ - -/*struct lsh_string_header {};*/ - -#endif /* !DEBUG_ALLOC */ - -struct lsh_string -{ -#if DEBUG_ALLOC - struct lsh_string_header header; -#endif /* DEBUG_ALLOC */ - - UINT32 sequence_number; - /* NOTE: The allocated size may be larger than the string length. */ - UINT32 length; - UINT8 data[1]; -}; - -/* Forward declarations of various structures */ - -/* abstract_crypto.h */ - -/* client_x11.c */ -struct client_x11_display; - -/* connection.h */ -struct ssh_connection; - -/* interact.h */ -struct interact; - -/* io.h */ -struct address_info; -struct io_backend; -struct listen_value; -struct lsh_fd; - -/* list.h */ -struct int_list; -struct object_list; - -/* randomness.h */ -struct randomness; - -/* reaper.h */ -struct exit_callback; -struct reap; - -/* sexp.h */ -struct sexp; -struct sexp_iterator; - -/* userauth.h */ -struct lsh_user; - -#endif /* LSH_H_INCLUDED */ diff --git a/lsh/src/lsh_argp.h b/lsh/src/lsh_argp.h deleted file mode 100755 index 8c1eff7..0000000 --- a/lsh/src/lsh_argp.h +++ /dev/null @@ -1,40 +0,0 @@ -/* lsh_argp.h - * - * Include the right argp header. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_LSH_ARGP_H_INCLUDED -#define LSH_LSH_ARGP_H_INCLUDED - -#include "lsh_types.h" - -#if HAVE_ARGP_PARSE -/* We're using the system's argp implementation */ -# if HAVE_ARGP_H -# include -# endif -#else -# include "argp/argp.h" -#endif - -#endif /* LSH_LSH_ARGP_H_INCLUDED */ diff --git a/lsh/src/lsh_proxy.c b/lsh/src/lsh_proxy.c deleted file mode 100755 index 8e0ce78..0000000 --- a/lsh/src/lsh_proxy.c +++ /dev/null @@ -1,822 +0,0 @@ -/* lsh_proxy.c - * - * main proxy program. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999 Niels Möller, Balázs Scheidler - * - * 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 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 should 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 - */ - -#include "algorithms.h" -#include "alist.h" -#include "atoms.h" -#include "channel.h" -#include "channel_commands.h" -#include "charset.h" -#include "client_keyexchange.h" -#include "compress.h" -#include "connection_commands.h" -#include "crypto.h" -#include "daemon.h" -#include "dsa.h" -#include "format.h" -#include "gateway_channel.h" -#include "handshake.h" -#include "io.h" -#include "io_commands.h" -#include "lookup_verifier.h" -#include "proxy.h" -#include "proxy_agentforward.h" -#include "proxy_session.h" -#include "proxy_tcpforward.h" -#include "proxy_userauth.h" -#include "proxy_x11forward.h" -#include "randomness.h" -#include "reaper.h" -#include "server.h" -#include "server_authorization.h" -#include "server_keyexchange.h" -#include "server_session.h" -#include "server_userauth.h" -#include "sexp.h" -#include "sexp_commands.h" -#include "spki.h" -#include "spki_commands.h" -#include "ssh.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include "lsh_argp.h" - -/* Forward declarations */ -struct command options2local; -#define OPTIONS2LOCAL (&options2local.super) - -struct command options2keyfile; -#define OPTIONS2KEYFILE (&options2keyfile.super) - -struct command options2signature_algorithms; -#define OPTIONS2SIGNATURE_ALGORITHMS \ - (&options2signature_algorithms.super) - -struct command_2 proxy_destination; -#define PROXY_DESTINATION (&proxy_destination.super.super) - - -#include "lsh_proxy.c.x" - -#include - -#include -#include -#include -#include - -#include -#include -#include -#if HAVE_UNISTD_H -#include -#endif - -/* Option parsing */ - -const char *argp_program_version -= "lsh_proxy-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -#define OPT_NO 0x400 -#define OPT_SSH1_FALLBACK 0x200 -#define OPT_INTERFACE 0x201 -#define OPT_TCPIP_FORWARD 0x202 -#define OPT_NO_TCPIP_FORWARD (OPT_TCPIP_FORWARD | OPT_NO) -#define OPT_X11_FORWARD 0x203 -#define OPT_NO_X11_FORWARD (OPT_X11_FORWARD | OPT_NO) -#define OPT_AGENT_FORWARD 0x204 -#define OPT_NO_AGENT_FORWARD (OPT_AGENT_FORWARD | OPT_NO) -#define OPT_DAEMONIC 0x205 -#define OPT_NO_DAEMONIC (OPT_DAEMONIC | OPT_NO) -#define OPT_PIDFILE 0x206 -#define OPT_NO_PIDFILE (OPT_PIDFILE | OPT_NO) -#define OPT_CORE 0x207 - -/* GABA: - (class - (name lsh_proxy_options) - (super algorithms_options) - (vars - (backend object io_backend) - (random object randomness_with_poll) - (signature_algorithms object alist) - (style . sexp_argp_state) - (interface . "char *") - (port . "char *") - (hostkey . "char *") - (local object address_info) - (destination object address_info) - (with_tcpip_forward . int) - (with_x11_forward . int) - (with_agent_forward . int) - (daemonic . int) - (corefile . int) - (pid_file . "const char *") - ; -1 means use pid file iff we're in daemonic mode - (use_pid_file . int))) -*/ - -static struct lsh_proxy_options * -make_lsh_proxy_options(struct io_backend *backend, - struct randomness_with_poll *random, - struct alist *algorithms) -{ - NEW(lsh_proxy_options, self); - - init_algorithms_options(&self->super, algorithms); - self->signature_algorithms - = make_alist(1, - ATOM_DSA, make_dsa_algorithm(&random->super), -1); - - self->backend = backend; - self->random = random; - self->style = SEXP_TRANSPORT; - self->interface = NULL; - - /* Default behaviour is to lookup the "ssh" service, and fall back - * to port 22 if that fails. */ - self->port = NULL; - - /* FIXME: this should perhaps use sysconfdir */ - self->hostkey = "/etc/lsh_host_key"; - self->local = NULL; - - self->with_tcpip_forward = 1; - self->with_x11_forward = 1; - self->with_agent_forward = 1; - - self->daemonic = 0; - - /* FIXME: Make the default a configure time option? */ - self->pid_file = "/var/run/lsh_proxy.pid"; - self->use_pid_file = -1; - self->corefile = 0; - - return self; -} - -/* NOTE: Copied from lshd.c */ -/* Port to listen on */ -DEFINE_COMMAND(options2local) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_proxy_options, options, a); - COMMAND_RETURN(c, options->local); -} - -/* alist of signature algorithms */ -DEFINE_COMMAND(options2signature_algorithms) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_proxy_options, options, a); - COMMAND_RETURN(c, options->signature_algorithms); -} - -/* Read server's private key */ -DEFINE_COMMAND(options2keyfile) - (struct command *ignored UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(lsh_proxy_options, options, a); - - struct lsh_fd *f; - - f = io_read_file(options->backend, options->hostkey, e); - - if (f) - COMMAND_RETURN(c, f); - else - { - werror("Failed to open '%z' (errno = %i): %z.\n", - options->hostkey, errno, STRERROR(errno)); - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, errno, NULL)); - } -} - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "interface", OPT_INTERFACE, "interface", 0, - "Listen on this network interface", 0 }, - { "port", 'p', "Port", 0, "Listen on this port.", 0 }, - { "host-key", 'h', "Key file", 0, "Location of the server's private key.", 0}, - { "destination", 'D', "destination:port", 0, "Destination ssh server address (transparent if not given)", 0 }, - -#if WITH_TCP_FORWARD - { "tcp-forward", OPT_TCPIP_FORWARD, NULL, 0, "Enable tcpip forwarding (default).", 0 }, - { "no-tcp-forward", OPT_NO_TCPIP_FORWARD, NULL, 0, "Disable tcpip forwarding.", 0 }, -#endif /* WITH_TCP_FORWARD */ -#if WITH_X11_FORWARD - { "x11-forward", OPT_X11_FORWARD, NULL, 0, "Enable X11 forwarding (default).", 0 }, - { "no-x11-forward", OPT_NO_X11_FORWARD, NULL, 0, "Disable X11 forwarding.", 0 }, -#endif -#if WITH_AGENT_FORWARD - { "agent-forward", OPT_AGENT_FORWARD, NULL, 0, "Enable auth agent forwarding (default).", 0 }, - { "no-agent-forward", OPT_NO_AGENT_FORWARD, NULL, 0, "Disable auth agent forwarding.", 0 }, -#endif - - { NULL, 0, NULL, 0, "Daemonic behaviour", 0 }, - { "daemonic", OPT_DAEMONIC, NULL, 0, "Run in the background, redirect stdio to /dev/null, and chdir to /.", 0 }, - { "no-daemonic", OPT_NO_DAEMONIC, NULL, 0, "Run in the foreground, with messages to stderr (default).", 0 }, - { "pid-file", OPT_PIDFILE, "file name", 0, "Create a pid file. When running in daemonic mode, " - "the default is /var/run/lsh_proxy.pid.", 0 }, - { "no-pid-file", OPT_NO_PIDFILE, NULL, 0, "Don't use any pid file. Default in non-daemonic mode.", 0 }, - { "enable-core", OPT_CORE, NULL, 0, "Dump core on fatal errors (disabled by default).", 0 }, - - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_input_argp, 0, "", 0 }, - { &algorithms_argp, 0, "", 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static int -parse_dest_arg(char *arg, - struct address_info **target) -{ - char *sep, *end; - int port; - - sep = strchr(arg, ':'); - if (!sep) - return 0; - - port = strtol(sep + 1, &end, 0); - if ( (end == sep + 1) || (*end != '\0') - || (port < 0) || (port > 0xffff) ) - return 0; - - *target = make_address_info(ssh_format("%ls", sep - arg, arg), port); - return 1; -} - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lsh_proxy_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->style; - state->child_inputs[1] = &self->super; - state->child_inputs[2] = NULL; - break; - case ARGP_KEY_ARG: - argp_error(state, "Spurious arguments."); - break; - - case ARGP_KEY_END: - if (self->port) - self->local = make_address_info_c(arg, self->port, 0); - else - self->local = make_address_info_c(arg, "ssh", 22); - - if (!self->local) - argp_error(state, "Invalid interface, port or service, %s:%s'.", - self->interface ? self->interface : "ANY", - self->port); - if (self->use_pid_file < 0) - self->use_pid_file = self->daemonic; - - /* Start background poll */ - RANDOM_POLL_BACKGROUND(self->random->poller); - - break; - - case 'p': - self->port = arg; - break; - - case 'h': - self->hostkey = arg; - break; - - case 'D': - if (!parse_dest_arg(arg, &self->destination)) - { - argp_error(state, "Invalid destination specification '%s'.", arg); - } - - break; - - case OPT_INTERFACE: - self->interface = arg; - break; - - case OPT_TCPIP_FORWARD: - self->with_tcpip_forward = 1; - break; - - case OPT_NO_TCPIP_FORWARD: - self->with_tcpip_forward = 0; - break; - - case OPT_X11_FORWARD: - self->with_x11_forward = 1; - break; - - case OPT_NO_X11_FORWARD: - self->with_x11_forward = 0; - break; - - case OPT_AGENT_FORWARD: - self->with_agent_forward = 1; - break; - - case OPT_NO_AGENT_FORWARD: - self->with_agent_forward = 0; - break; - - case OPT_DAEMONIC: - self->daemonic = 1; - break; - - case OPT_NO_DAEMONIC: - self->daemonic = 0; - break; - - case OPT_PIDFILE: - self->pid_file = arg; - self->use_pid_file = 1; - break; - - case OPT_NO_PIDFILE: - self->use_pid_file = 0; - break; - - case OPT_CORE: - self->corefile = 1; - break; - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - NULL, - "Server for the ssh-2 protocol.", - main_argp_children, - NULL, NULL -}; - -/* GABA: - (class - (name fake_host_db) - (super lookup_verifier) - (vars - ;; (algorithm object signature_algorithm) - )) -*/ - -static struct verifier * -do_host_lookup(struct lookup_verifier *c UNUSED, - int method, - struct lsh_user *user UNUSED, - struct lsh_string *key) -{ - switch(method) - { - case ATOM_SSH_DSS: - return make_ssh_dss_verifier(key->length, key->data); - default: - return NULL; - } -} - -static struct lookup_verifier * -make_fake_host_db(void) -{ - NEW(fake_host_db, res); - - res->super.lookup = do_host_lookup; - - return &res->super; -} - -DEFINE_COMMAND2(proxy_destination) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lsh_proxy_options, options, a1); - CAST(listen_value, client_addr, a2); - - if (options->destination) - COMMAND_RETURN(c, options->destination); - else - { - /* FIXME: Why not use client_addr->peer? /nisse*/ - struct sockaddr_in sa; - int salen = sizeof(sa); - - /* try to be transparent */ - /* FIXME: support non AF_INET address families */ - if (getsockname(client_addr->fd->fd, (struct sockaddr *) &sa, &salen) != -1) - { - COMMAND_RETURN(c, - sockaddr2info(salen, (struct sockaddr *) &sa)); - /* a = make_address_info(ssh_format("localhost"), 1998); */ - } - else - { - struct exception *ex = - make_io_exception(EXC_IO, client_addr->fd, errno, "getsockname failed"); - - EXCEPTION_RAISE(e, ex); - } - } -} - -/* GABA: - (expr - (name lsh_proxy_listen) - (params - (backend object io_backend) - (services object command) - (handshake_server object command) - (handshake_client object command)) - (expr - (lambda (options) - ; accept a connection - (listen_callback - (lambda (client_addr) - ; address of accepted connection - (services - ; chain two connections - (chain_connections - (handshake_server options) ; callback to perform server side handshake - (handshake_client options) ; callback to perform client side handshake - client_addr))) - backend - (options2local options)))) ) - - -*/ - -/* GABA: - (expr - (name lsh_proxy_handshake_client) - (params - (handshake object handshake_info) - (init object make_kexinit)) - (expr - (lambda (options client_addr) - (connection_handshake ; handshake on the client side - handshake init - (spki_read_hostkeys (options2signature_algorithms options) - (options2keyfile options)) - (log_peer client_addr))))) - -*/ - -/* GABA: - (expr - (name lsh_proxy_handshake_server) - (params - (connect object command) - (verifier object lookup_verifier) - (handshake object handshake_info) - (init object make_kexinit)) - (expr - (lambda (options client_addr) - (init_connection_service - (connection_handshake - handshake init - verifier - (connect (proxy_destination options client_addr))))))) -*/ - -/* Invoked when the client requests the userauth service. */ -/* GABA: - (expr - (name lsh_proxy_services) - (params - (userauth object command)) - (expr - (lambda (connection) - ((userauth connection) connection)))) -*/ - -/* Invoked when starting the ssh-connection service */ -/* GABA: - (expr - (name lsh_proxy_connection_service) - (params - (login object command)) - (expr - (lambda (user connection) - (login user - ; We have to initialize the connection - ; before logging in. - (init_connection_service connection))))) -*/ - -#if WITH_ALF -#include "proxy_alf.h" -#endif - - -int main(int argc, char **argv) -{ - struct lsh_proxy_options *options; - - struct alist *keys; - - struct reap *reaper; - - struct randomness_with_poll *r; - struct alist *algorithms_server, *algorithms_client; - struct alist *signature_algorithms; - - struct make_kexinit *make_kexinit; - struct exception_handler *handler; - - struct io_backend *backend; - - backend = make_io_backend(); - -#if WITH_ALF - proxy_alf_init(); - proxy_alf_end(); -#endif - - - /* For filtering messages. Could perhaps also be used when converting - * strings to and from UTF8. */ - setlocale(LC_CTYPE, ""); - /* FIXME: Choose character set depending on the locale */ - set_local_charset(CHARSET_LATIN1); - - handler = make_report_exception_handler - (make_report_exception_info(EXC_IO, EXC_IO, "lsh_proxy: "), - &default_exception_handler, - HANDLER_CONTEXT); - reaper = make_reaper(backend); - r = make_default_random(reaper, handler); - - algorithms_server = all_symmetric_algorithms(); - /* FIXME: copy algorithms_server */ - algorithms_client = all_symmetric_algorithms(); - - signature_algorithms = all_signature_algorithms(&r->super); - - options = make_lsh_proxy_options(backend, r, algorithms_server); - - argp_parse(&main_argp, argc, argv, 0, NULL, options); - - if (!options->corefile && !daemon_disable_core()) - { - werror("Disabling of core dumps failed.\n"); - return EXIT_FAILURE; - } - - if (options->daemonic) - { -#if HAVE_SYSLOG - set_error_syslog("lsh_proxy"); -#else /* !HAVE_SYSLOG */ - werror("lsh_proxy: No syslog. Further messages will be directed to /dev/null.\n"); -#endif /* !HAVE_SYSLOG */ - } - - if (options->daemonic) - switch (daemon_init()) - { - case 0: - werror("lsh_proxy: Spawning into background failed.\n"); - return EXIT_FAILURE; - case DAEMON_INETD: - werror("lsh_proxy: spawning from inetd not yet supported.\n"); - return EXIT_FAILURE; - case DAEMON_INIT: - case DAEMON_NORMAL: - break; - default: - fatal("Internal error\n"); - } - - if (options->use_pid_file && !daemon_pidfile(options->pid_file)) - { - werror("lsh_proxy seems to be running already.\n"); - return EXIT_FAILURE; - } - - /* Read the hostkey */ - keys = make_alist(0, -1); -#if 0 - if (!(hostkey = read_spki_key_file(options->hostkey, - make_alist(1, ATOM_DSA, make_dsa_algorithm(r), -1), - &ignore_exception_handler))) - { - werror("lsh_proxy: Could not read hostkey.\n"); - return EXIT_FAILURE; - } - ALIST_SET(keys, hostkey->type, hostkey); -#endif - - /* FIXME: We should check that we have at least one host key. - * We should also extract the host-key algorithms for which we have keys, - * instead of hardcoding ssh-dss below. */ - -#if 0 - lookup_keys = make_alist(1, - ATOM_SSH_DSS, make_fake_host_db(), - -1); -#endif - - ALIST_SET(algorithms_server, - ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, - &make_dh_server(make_dh1(&r->super))->super); - ALIST_SET(algorithms_client, - ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, - &make_dh_client(make_dh1(&r->super))->super); - - make_kexinit - = make_simple_kexinit(&r->super, - make_int_list(1, ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, - -1), - options->super.hostkey_algorithms, - options->super.crypto_algorithms, - options->super.mac_algorithms, - options->super.compression_algorithms, - make_int_list(0, -1)); - - { - /* Commands to be invoked on the connection */ - struct object_queue connection_server_hooks, connection_client_hooks; - struct alist *server_session_requests, *client_session_requests; - - server_session_requests = make_alist - (4, - ATOM_SHELL, &gateway_channel_request, - ATOM_PTY_REQ, &gateway_channel_request, - ATOM_EXIT_STATUS, &gateway_channel_request, - ATOM_EXIT_SIGNAL, &gateway_channel_request, - -1); - client_session_requests = make_alist(0, -1); - -#if WITH_X11_FORWARD - if (options->with_x11_forward) - { - ALIST_SET(server_session_requests, ATOM_X11_REQ, &gateway_channel_request); - } -#endif -#if WITH_AGENT_FORWARD - if (options->with_agent_forward) - { - ALIST_SET(server_session_requests, ATOM_AUTH_AGENT_REQ, &gateway_channel_request); - } -#endif - - object_queue_init(&connection_server_hooks); - object_queue_init(&connection_client_hooks); - - object_queue_add_tail(&connection_server_hooks, - &make_install_fix_channel_open_handler - (ATOM_SESSION, - make_proxy_open_session(server_session_requests, - client_session_requests))->super); - -#ifdef WITH_TCP_FORWARD - if (options->with_tcpip_forward) - { - object_queue_add_tail(&connection_server_hooks, - &make_install_fix_global_request_handler - (ATOM_TCPIP_FORWARD, &gateway_global_request)->super); - object_queue_add_tail(&connection_server_hooks, - &make_install_fix_global_request_handler - (ATOM_CANCEL_TCPIP_FORWARD, &gateway_global_request)->super); - object_queue_add_tail(&connection_server_hooks, - &make_install_fix_channel_open_handler - (ATOM_DIRECT_TCPIP, - make_proxy_open_direct_tcpip())->super); - - object_queue_add_tail(&connection_client_hooks, - &make_install_fix_channel_open_handler - (ATOM_FORWARDED_TCPIP, - make_proxy_open_forwarded_tcpip())->super); - } -#endif - -#if WITH_X11_FORWARD - if (options->with_x11_forward) - { - object_queue_add_tail(&connection_client_hooks, - &make_install_fix_channel_open_handler - (ATOM_X11, - make_proxy_open_x11())->super); - } -#endif - -#if WITH_AGENT_FORWARD - if (options->with_agent_forward) - { - object_queue_add_tail(&connection_client_hooks, - &make_install_fix_channel_open_handler - (ATOM_AUTH_AGENT, - make_proxy_open_auth_agent())->super); - } -#endif - - { - struct lsh_object *o = lsh_proxy_listen - (backend, - make_proxy_offer_service - (make_alist(1, - ATOM_SSH_USERAUTH, - lsh_proxy_services - (make_proxy_userauth - (make_int_list(1, ATOM_PASSWORD, -1), - make_alist(1, ATOM_PASSWORD, &proxy_password_auth, -1), - make_alist - (1, - ATOM_SSH_CONNECTION, - lsh_proxy_connection_service - (make_proxy_connection_service - (queue_to_list_and_kill(&connection_server_hooks), - queue_to_list_and_kill(&connection_client_hooks))), - -1))), - -1)), - - /* callback to call when client<->proxy handshake finished */ - (struct command *)lsh_proxy_handshake_server(make_simple_connect(backend, NULL), - make_fake_host_db(), - make_handshake_info - (CONNECTION_CLIENT, - "lsh_proxy_client - a free ssh", - "proxy client", - SSH_MAX_PACKET, - &r->super, - algorithms_client, - NULL), - make_kexinit), - (struct command *)lsh_proxy_handshake_client(make_handshake_info - (CONNECTION_SERVER, - "lsh_proxy_server - a free ssh", - "proxy server", - SSH_MAX_PACKET, - &r->super, - algorithms_server, - NULL), - make_kexinit)); - - - - CAST_SUBTYPE(command, server_listen, o); - - COMMAND_CALL(server_listen, options, - &discard_continuation, - handler); - } - } - - io_run(backend); - - return 0; -} diff --git a/lsh/src/lsh_proxy.c.x b/lsh/src/lsh_proxy.c.x deleted file mode 100755 index 4cab77a..0000000 Binary files a/lsh/src/lsh_proxy.c.x and /dev/null differ diff --git a/lsh/src/lsh_types.h b/lsh/src/lsh_types.h deleted file mode 100755 index c75806f..0000000 --- a/lsh/src/lsh_types.h +++ /dev/null @@ -1,149 +0,0 @@ -/* lsh_types.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_TYPES_H_INCLUDED -#define LSH_TYPES_H_INCLUDED - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#ifndef alloca -# ifdef __GNUC__ -# define alloca __builtin_alloca -# define HAVE_ALLOCA 1 -# else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca -char *alloca (); -# endif -# endif -# endif -# endif -#endif - -#if SIZEOF_SHORT >= 4 -# define UINT32 unsigned short -#elif SIZEOF_INT >= 4 -# define UINT32 unsigned int -#elif SIZEOF_LONG >= 4 -# define UINT32 unsigned long -#else -# error No suitable type found to use for UINT32 -#endif /* UINT32 */ - -#if SIZEOF_SHORT >= 2 -# define UINT16 unsigned short -#elif SIZEOF_INT >= 2 -# define UINT16 unsigned int -#else -# error No suitable type found to use for UINT16 -#endif /* UINT16 */ - -#define UINT8 unsigned char - -#if __GNUC__ && HAVE_GCC_ATTRIBUTE -# define NORETURN __attribute__ ((__noreturn__)) -# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) -# define UNUSED __attribute__ ((__unused__)) -#else -# define NORETURN -# define PRINTF_STYLE(f, a) -# define UNUSED -#endif - -#if HAVE_GCC_FUNCTION -# define FUNCTION_NAME __FUNCTION__ -#else -# define FUNCTION_NAME "Unknown" -#endif - -/* Stringizing macros */ -#define STRINGIZE1(x) #x -#define STRINGIZE(x) STRINGIZE1(x) -#define STRING_LINE STRINGIZE(__LINE__) - -#if HAVE_STRERROR -#define STRERROR strerror -#else -#define STRERROR(x) (sys_errlist[x]) -#endif - -#if HAVE_STRSIGNAL -# define STRSIGNAL strsignal -#else /* !HAVE_STRSIGNAL */ -# ifdef _sgi -# define STRSIGNAL(x) (_sys_siglist[x]) -# else /* !_sgi */ -# define STRSIGNAL(x) (sys_siglist[x]) -# endif /* !_sgi */ -#endif /* !HAVE_STRSIGNAL */ - -/* Some macros */ - -/* Reads a 32-bit integer, in network byte order */ -#define READ_UINT32(p) \ -( (((UINT32) (p)[0]) << 24) \ - | (((UINT32) (p)[1]) << 16) \ - | (((UINT32) (p)[2]) << 8) \ - | ((UINT32) (p)[3])) - -#define WRITE_UINT32(p, i) \ -do { \ - (p)[0] = ((i) >> 24) & 0xff; \ - (p)[1] = ((i) >> 16) & 0xff; \ - (p)[2] = ((i) >> 8) & 0xff; \ - (p)[3] = (i) & 0xff; \ -} while(0) - -/* Same, for 24-bit quantities */ -#define READ_UINT24(p) \ -( (((UINT32) (p)[0]) << 24) \ - | (((UINT32) (p)[1]) << 16) \ - | ((UINT32) (p)[2])) - -/* Same, for 16-bit quantities */ -#define READ_UINT16(p) \ -( (((UINT32) (p)[0]) << 8) \ - | ((UINT32) (p)[1])) - -#define WRITE_UINT16(p, i) \ -do { \ - (p)[0] = ((i) >> 8) & 0xff; \ - (p)[1] = (i) & 0xff; \ -} while(0) - -/* Useful macros. */ -#define MIN(a, b) (((a)>(b)) ? (b) : (a)) -#define MAX(a, b) (((a)<(b)) ? (b) : (a)) -#define SQR(x) ((x)*(x)) - - -#endif /* LSH_TYPES_H_INCLUDED */ diff --git a/lsh/src/lshd.c b/lsh/src/lshd.c deleted file mode 100755 index 50dd1ee..0000000 --- a/lsh/src/lshd.c +++ /dev/null @@ -1,939 +0,0 @@ -/* lshd.c - * - * main server program. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "algorithms.h" -#include "alist.h" -#include "atoms.h" -#include "channel.h" -#include "channel_commands.h" -#include "charset.h" -#include "compress.h" -#include "connection_commands.h" -#include "crypto.h" -#include "daemon.h" -#include "dsa.h" -#include "format.h" -#include "handshake.h" -#include "io.h" -#include "io_commands.h" -#include "lookup_verifier.h" -#include "randomness.h" -#include "reaper.h" -#include "server.h" -#include "server_authorization.h" -#include "server_keyexchange.h" -#include "server_pty.h" -#include "server_session.h" -#include "sexp.h" -#include "sexp_commands.h" -#include "spki_commands.h" -#include "srp.h" -#include "ssh.h" -#include "tcpforward.h" -#include "tcpforward_commands.h" -#include "tcpforward_commands.h" -#include "server_userauth.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include "lsh_argp.h" - -/* Forward declarations */ -struct command options2local; -#define OPTIONS2LOCAL (&options2local.super) - -struct command options2keyfile; -#define OPTIONS2KEYFILE (&options2keyfile.super) - -struct command options2signature_algorithms; -#define OPTIONS2SIGNATURE_ALGORITHMS \ - (&options2signature_algorithms.super) - -#include "lshd.c.x" - -#include - -#include -#include -#include -#include - -#include -#include -#include -#if HAVE_UNISTD_H -#include -#endif - -/* Option parsing */ - -const char *argp_program_version -= "lshd-" VERSION ", secsh protocol version " SERVER_PROTOCOL_VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -/* The definition of SBINDIR is currently broken */ -#if 0 -# define KERBEROS_HELPER SBINDIR "/lsh-krb-checkpw" -#else -# define KERBEROS_HELPER PREFIX "/sbin/lsh-krb-checkpw" -#endif - -#define OPT_NO 0x400 -#define OPT_SSH1_FALLBACK 0x200 -#define OPT_INTERFACE 0x201 - -#define OPT_TCPIP_FORWARD 0x202 -#define OPT_NO_TCPIP_FORWARD (OPT_TCPIP_FORWARD | OPT_NO) -#define OPT_PTY 0x203 -#define OPT_NO_PTY (OPT_PTY | OPT_NO) -#define OPT_SUBSYSTEMS 0x204 -#define OPT_NO_SUBSYSTEMS (OPT_SUBSYSTEMS | OPT_NO) - -#define OPT_DAEMONIC 0x205 -#define OPT_NO_DAEMONIC (OPT_DAEMONIC | OPT_NO) -#define OPT_PIDFILE 0x206 -#define OPT_NO_PIDFILE (OPT_PIDFILE | OPT_NO) -#define OPT_CORE 0x207 -#define OPT_SYSLOG 0x208 -#define OPT_NO_SYSLOG (OPT_SYSLOG | OPT_NO) - -#define OPT_SRP 0x210 -#define OPT_NO_SRP (OPT_SRP | OPT_NO) -#define OPT_DH 0x211 -#define OPT_NO_DH (OPT_DH | OPT_NO) - -#define OPT_PUBLICKEY 0x220 -#define OPT_NO_PUBLICKEY (OPT_PUBLICKEY | OPT_NO) -#define OPT_PASSWORD 0x221 -#define OPT_NO_PASSWORD (OPT_PASSWORD | OPT_NO) - -#define OPT_ROOT_LOGIN 0x222 -#define OPT_NO_ROOT_LOGIN (OPT_ROOT_LOGIN | OPT_NO) - -#define OPT_KERBEROS_PASSWD 0x223 -#define OPT_NO_KERBEROS_PASSWD (OPT_KERBEROS_PASSWD | OPT_NO) - -#define OPT_PASSWORD_HELPER 0x224 - -#define OPT_LOGIN_SHELL 0x225 - -/* GABA: - (class - (name lshd_options) - (super algorithms_options) - (vars - (backend object io_backend) - (e object exception_handler) - - (reaper object reap) - (random object randomness_with_poll) - - (signature_algorithms object alist) - (style . sexp_argp_state) - (interface . "char *") - (port . "char *") - (hostkey . "char *") - (local object address_info) - - (with_srp_keyexchange . int) - (with_dh_keyexchange . int) - - ;; (kexinit object make_kexinit) - (kex_algorithms object int_list) - - (with_publickey . int) - (with_password . int) - (allow_root . int) - (pw_helper . "const char *") - (login_shell . "const char *") - - (with_tcpip_forward . int) - (with_pty . int) - (subsystems . "const char **") - - (userauth_methods object int_list) - (userauth_algorithms object alist) - - (sshd1 object ssh1_fallback) - (daemonic . int) - (no_syslog . int) - (corefile . int) - (pid_file . "const char *") - ; -1 means use pid file iff we're in daemonic mode - (use_pid_file . int))) -*/ - -static void -do_exc_lshd_handler(struct exception_handler *s, - const struct exception *e) -{ - switch(e->type) - { - case EXC_RESOLVE: - case EXC_SEXP_SYNTAX: - case EXC_SPKI_TYPE: - case EXC_RANDOMNESS_LOW_ENTROPY: - werror("lshd: %z\n", e->msg); - exit(EXIT_FAILURE); - default: - EXCEPTION_RAISE(s->parent, e); - } -} - -static struct exception_handler * -make_lshd_exception_handler(struct exception_handler *parent, - const char *context) -{ - return make_exception_handler(do_exc_lshd_handler, parent, context); -} - -static struct lshd_options * -make_lshd_options(struct io_backend *backend) -{ - NEW(lshd_options, self); - - init_algorithms_options(&self->super, all_symmetric_algorithms()); - - self->backend = backend; - self->e = make_lshd_exception_handler(&default_exception_handler, - HANDLER_CONTEXT); - self->reaper = make_reaper(backend); - self->random = make_default_random(self->reaper, self->e); - - self->signature_algorithms = all_signature_algorithms(&self->random->super); - self->style = SEXP_TRANSPORT; - self->interface = NULL; - - /* Default behaviour is to lookup the "ssh" service, and fall back - * to port 22 if that fails. */ - self->port = NULL; - - /* FIXME: this should perhaps use sysconfdir */ - self->hostkey = "/etc/lsh_host_key"; - self->local = NULL; - - self->with_dh_keyexchange = 1; - self->with_srp_keyexchange = 0; - - self->kex_algorithms = NULL; - - self->with_publickey = 1; - self->with_password = 1; - self->with_tcpip_forward = 1; - self->with_pty = 1; - self->subsystems = NULL; - - self->allow_root = 0; - self->pw_helper = NULL; - self->login_shell = NULL; - - self->userauth_methods = NULL; - self->userauth_algorithms = NULL; - - self->sshd1 = NULL; - self->daemonic = 0; - self->no_syslog = 0; - - /* FIXME: Make the default a configure time option? */ - self->pid_file = "/var/run/lshd.pid"; - self->use_pid_file = -1; - self->corefile = 0; - - return self; -} - -/* Port to listen on */ -DEFINE_COMMAND(options2local) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lshd_options, options, a); - COMMAND_RETURN(c, options->local); -} - -/* alist of signature algorithms */ -DEFINE_COMMAND(options2signature_algorithms) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lshd_options, options, a); - COMMAND_RETURN(c, options->signature_algorithms); -} - -/* Read server's private key */ - -DEFINE_COMMAND(options2keyfile) - (struct command *ignored UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(lshd_options, options, a); - - struct lsh_fd *f; - - f = io_read_file(options->backend, options->hostkey, e); - - if (f) - COMMAND_RETURN(c, f); - else - { - werror("Failed to open '%z' (errno = %i): %z.\n", - options->hostkey, errno, STRERROR(errno)); - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, errno, NULL)); - } -} - - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "interface", OPT_INTERFACE, "interface", 0, - "Listen on this network interface.", 0 }, - { "port", 'p', "Port", 0, "Listen on this port.", 0 }, - { "host-key", 'h', "Key file", 0, "Location of the server's private key.", 0}, -#if WITH_SSH1_FALLBACK - { "ssh1-fallback", OPT_SSH1_FALLBACK, "File name", OPTION_ARG_OPTIONAL, - "Location of the sshd1 program, for falling back to version 1 of the Secure Shell protocol.", 0 }, -#endif /* WITH_SSH1_FALLBACK */ - - { NULL, 0, NULL, 0, "Keyexchange options:", 0 }, -#if WITH_SRP - { "srp-keyexchange", OPT_SRP, NULL, 0, "Enable experimental SRP support.", 0 }, - { "no-srp-keyexchange", OPT_NO_SRP, NULL, 0, "Disable experimental SRP support (default).", 0 }, -#endif /* WITH_SRP */ - - { "dh-keyexchange", OPT_DH, NULL, 0, "Enable DH support (default).", 0 }, - { "no-dh-keyexchange", OPT_NO_DH, NULL, 0, "Disable DH support.", 0 }, - - { NULL, 0, NULL, 0, "User authentication options:", 0 }, - - { "password", OPT_PASSWORD, NULL, 0, - "Enable password user authentication (default).", 0}, - { "no-password", OPT_NO_PASSWORD, NULL, 0, - "Disable password user authentication.", 0}, - - { "publickey", OPT_PUBLICKEY, NULL, 0, - "Enable publickey user authentication (default).", 0}, - { "no-publickey", OPT_NO_PUBLICKEY, NULL, 0, - "Disable publickey user authentication.", 0}, - - { "root-login", OPT_ROOT_LOGIN, NULL, 0, - "Allow root to login.", 0 }, - { "no-root-login", OPT_NO_ROOT_LOGIN, NULL, 0, - "Don't allow root to login (default).", 0 }, - - { "login-shell", OPT_LOGIN_SHELL, "Program", 0, - "Use this program as the login shell for all users. " - "(Experimental)", 0 }, - - { "kerberos-passwords", OPT_KERBEROS_PASSWD, NULL, 0, - "Recognize kerberos passwords, using the helper program " - "\"" KERBEROS_HELPER "\". This option is experimental.", 0 }, - { "no-kerberos-passwords", OPT_NO_KERBEROS_PASSWD, NULL, 0, - "Don't recognize kerberos passwords (default behaviour).", 0 }, - - { "password-helper", OPT_PASSWORD_HELPER, "Program", 0, - "Use the named helper program for password verification. " - "(Experimental).", 0 }, - - { NULL, 0, NULL, 0, "Offered services:", 0 }, - -#if WITH_PTY_SUPPORT - { "pty-support", OPT_PTY, NULL, 0, "Enable pty allocation (default).", 0 }, - { "no-pty-support", OPT_NO_PTY, NULL, 0, "Disable pty allocation.", 0 }, -#endif /* WITH_PTY_SUPPORT */ - - { "subsystems", OPT_SUBSYSTEMS, "List of subsystem names and programs", 0, - "For example `sftp=/usr/sbin/sftp-server,foosystem=/usr/bin/foo' " - "(experimental).", 0}, - - { NULL, 0, NULL, 0, "Daemonic behaviour", 0 }, - { "daemonic", OPT_DAEMONIC, NULL, 0, "Run in the background, redirect stdio to /dev/null, and chdir to /.", 0 }, - { "no-daemonic", OPT_NO_DAEMONIC, NULL, 0, "Run in the foreground, with messages to stderr (default).", 0 }, - { "pid-file", OPT_PIDFILE, "file name", 0, "Create a pid file. When running in daemonic mode, " - "the default is /var/run/lshd.pid.", 0 }, - { "no-pid-file", OPT_NO_PIDFILE, NULL, 0, "Don't use any pid file. Default in non-daemonic mode.", 0 }, - { "enable-core", OPT_CORE, NULL, 0, "Dump core on fatal errors (disabled by default).", 0 }, - { "no-syslog", OPT_NO_SYSLOG, NULL, 0, "Don't use syslog (by default, syslog is used " - "when running in daemonic mode).", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_input_argp, 0, "", 0 }, - { &algorithms_argp, 0, "", 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -/* NOTE: Modifies the argument string. */ -static const char ** -parse_subsystem_list(char *arg) -{ - const char **subsystems; - char *separator; - unsigned length; - unsigned i; - - /* First count the number of elements. */ - for (length = 1, i = 0; arg[i]; i++) - if (arg[i] == ',') - length++; - - subsystems = lsh_space_alloc((length * 2 + 1) * sizeof(*subsystems)); - - for (i = 0; ; i++) - { - subsystems[2*i] = arg; - - separator = strchr(arg, '='); - - if (!separator) - goto fail; - - *separator = '\0'; - - subsystems[2*i+1] = arg = separator + 1; - - separator = strchr(arg, ','); - - if (i == (length - 1)) - break; - - if (!separator) - goto fail; - - *separator = '\0'; - arg = separator + 1; - } - if (separator) - { - fail: - lsh_space_free(subsystems); - return NULL; - } - return subsystems; -} - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lshd_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->style; - state->child_inputs[1] = &self->super; - state->child_inputs[2] = NULL; - break; - case ARGP_KEY_END: - { - struct user_db *user_db = NULL; - - if (self->with_password || self->with_publickey || self->with_srp_keyexchange) - user_db = make_unix_user_db(self->backend, self->reaper, - self->pw_helper, self->login_shell, - self->allow_root); - - if (self->with_dh_keyexchange || self->with_srp_keyexchange) - { - int i = 0; - self->kex_algorithms - = alloc_int_list(self->with_dh_keyexchange + self->with_srp_keyexchange); - - if (self->with_dh_keyexchange) - { - LIST(self->kex_algorithms)[i++] = ATOM_DIFFIE_HELLMAN_GROUP1_SHA1; - ALIST_SET(self->super.algorithms, - ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, - &make_dh_server(make_dh1(&self->random->super)) - ->super); - } -#if WITH_SRP - if (self->with_srp_keyexchange) - { - assert(user_db); - LIST(self->kex_algorithms)[i++] = ATOM_SRP_RING1_SHA1_LOCAL; - ALIST_SET(self->super.algorithms, - ATOM_SRP_RING1_SHA1_LOCAL, - &make_srp_server(make_srp1(&self->random->super), - user_db) - ->super); - } -#endif /* WITH_SRP */ - } - else - argp_error(state, "All keyexchange algorithms disabled."); - - if (self->port) - self->local = make_address_info_c(self->interface, self->port, 0); - else - self->local = make_address_info_c(self->interface, "ssh", 22); - - if (!self->local) - argp_error(state, "Invalid interface, port or service, %s:%s'.", - self->interface ? self->interface : "ANY", - self->port); - - if (self->use_pid_file < 0) - self->use_pid_file = self->daemonic; - - if (self->with_password || self->with_publickey) - { - int i = 0; - - self->userauth_methods - = alloc_int_list(self->with_password + self->with_publickey); - self->userauth_algorithms = make_alist(0, -1); - - if (self->with_password) - { - LIST(self->userauth_methods)[i++] = ATOM_PASSWORD; - ALIST_SET(self->userauth_algorithms, - ATOM_PASSWORD, - &make_userauth_password(user_db)->super); - } - if (self->with_publickey) - { - /* FIXME: Doesn't use spki */ - struct lookup_verifier *key_db - = make_authorization_db(ssh_format("authorized_keys_sha1"), - &sha1_algorithm); - - LIST(self->userauth_methods)[i++] = ATOM_PUBLICKEY; - ALIST_SET(self->userauth_algorithms, - ATOM_PUBLICKEY, - &make_userauth_publickey - (user_db, - make_alist(2, - ATOM_SSH_DSS, key_db, - ATOM_SSH_RSA, key_db, - -1)) - ->super); - } - } - if (self->with_srp_keyexchange) - ALIST_SET(self->userauth_algorithms, - ATOM_NONE, - &server_userauth_none.super); - - if (!self->userauth_algorithms->size) - argp_error(state, "All user authentication methods disabled."); - - break; - } - case 'p': - self->port = arg; - break; - - case 'h': - self->hostkey = arg; - break; - - case OPT_INTERFACE: - self->interface = arg; - break; - -#if WITH_SSH1_FALLBACK - case OPT_SSH1_FALLBACK: - self->sshd1 = make_ssh1_fallback(arg ? arg : SSHD1); - break; -#endif - - case OPT_SRP: - self->with_srp_keyexchange = 1; - break; - - case OPT_NO_SRP: - self->with_srp_keyexchange = 0; - break; - - case OPT_DH: - self->with_dh_keyexchange = 1; - break; - - case OPT_NO_DH: - self->with_dh_keyexchange = 0; - break; - - case OPT_PASSWORD: - self->with_password = 1; - break; - - case OPT_NO_PASSWORD: - self->with_password = 0; - break; - - case OPT_PUBLICKEY: - self->with_publickey = 1; - break; - - case OPT_NO_PUBLICKEY: - self->with_publickey = 0; - break; - - case OPT_ROOT_LOGIN: - self->allow_root = 1; - break; - - case OPT_KERBEROS_PASSWD: - self->pw_helper = KERBEROS_HELPER; - break; - - case OPT_NO_KERBEROS_PASSWD: - self->pw_helper = NULL; - break; - - case OPT_PASSWORD_HELPER: - self->pw_helper = arg; - break; - - case OPT_LOGIN_SHELL: - self->login_shell = arg; - break; - -#if WITH_TCP_FORWARD - case OPT_TCPIP_FORWARD: - self->with_tcpip_forward = 1; - break; - - case OPT_NO_TCPIP_FORWARD: - self->with_tcpip_forward = 0; - break; -#endif /* WITH_TCP_FORWARD */ - -#if WITH_PTY_SUPPORT - case OPT_PTY: - self->with_pty = 1; - break; - case OPT_NO_PTY: - self->with_pty = 0; - break; -#endif /* WITH_PTY_SUPPORT */ - - case OPT_SUBSYSTEMS: - self->subsystems = parse_subsystem_list(arg); - if (!self->subsystems) - argp_error(state, "Invalid subsystem list."); - break; - - case OPT_NO_SUBSYSTEMS: - self->subsystems = NULL; - break; - - case OPT_DAEMONIC: - self->daemonic = 1; - break; - - case OPT_NO_DAEMONIC: - self->daemonic = 0; - break; - - case OPT_NO_SYSLOG: - self->no_syslog = 1; - break; - - case OPT_PIDFILE: - self->pid_file = arg; - self->use_pid_file = 1; - break; - - case OPT_NO_PIDFILE: - self->use_pid_file = 0; - break; - - case OPT_CORE: - self->corefile = 1; - break; - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - NULL, - "Server for the ssh-2 protocol.", - main_argp_children, - NULL, NULL -}; - - -/* GABA: - (expr - (name make_lshd_listen) - (params - (backend object io_backend) - (handshake object handshake_info) - (init object make_kexinit) - (services object command) ) - (expr (lambda (options) - (let ((keys - (spki_read_hostkeys (options2signature_algorithms options) - (options2keyfile options)))) - (listen_callback - (lambda (lv) - (services (connection_handshake - handshake - (kexinit_filter init keys) - keys - (log_peer lv)))) - backend - (options2local options)))))) -*/ - - -/* Invoked when starting the ssh-connection service */ -/* GABA: - (expr - (name make_lshd_connection_service) - (params - (hooks object object_list)) - (expr - (lambda (connection) - ((progn hooks) - ; We have to initialize the connection - ; before adding handlers. - (init_connection_service - ; Disconnect if connection->user is NULL - (connection_require_userauth connection))))))) -*/ - -#if WITH_GCOV -/* FIXME: Perhaps move to daemon.c? */ -/* Catch SIGTERM and call exit(). That way, profiling info is written - * properly when the process is terminated. */ - -static volatile sig_atomic_t terminate; - -static void terminate_handler(int signum) -{ - assert(signum == SIGTERM); - - terminate = 1; -} - -static void -do_terminate_callback(struct lsh_callback *s UNUSED) -{ - gc_final(); - exit(0); -} - -static struct lsh_callback -terminate_callback = -{ STATIC_HEADER, do_terminate_callback }; - -static void -install_terminate_handler(struct io_backend *backend) -{ - struct sigaction term; - memset(&term, 0, sizeof(term)); - - term.sa_handler = terminate_handler; - sigemptyset(&term.sa_mask); - term.sa_flags = 0; - - if (sigaction(SIGTERM, &term, NULL) < 0) - { - werror ("Failed to install SIGTERM handler (errno = %i): %z\n", - errno, STRERROR(errno)); - exit(EXIT_FAILURE); - } - io_signal_handler(backend, &terminate, &terminate_callback); -} -#endif /* WITH_GCOV */ - -int main(int argc, char **argv) -{ - struct lshd_options *options; - - struct io_backend *backend = make_io_backend(); - -#if WITH_GCOV - install_terminate_handler(backend); -#endif - - /* For filtering messages. Could perhaps also be used when converting - * strings to and from UTF8. */ - setlocale(LC_CTYPE, ""); - - /* FIXME: Choose character set depending on the locale */ - set_local_charset(CHARSET_LATIN1); - - options = make_lshd_options(backend); - - trace("Parsing options...\n"); - argp_parse(&main_argp, argc, argv, 0, NULL, options); - trace("Parsing options...\n"); - - if (!options->corefile && !daemon_disable_core()) - { - werror("Disabling of core dumps failed.\n"); - return EXIT_FAILURE; - } - - if (options->daemonic && !options->no_syslog) - { -#if HAVE_SYSLOG - set_error_syslog("lshd"); -#else /* !HAVE_SYSLOG */ - werror("lshd: No syslog. Further messages will be directed to /dev/null.\n"); -#endif /* !HAVE_SYSLOG */ - } - - if (options->daemonic) - switch (daemon_init()) - { - case 0: - werror("lshd: Spawning into background failed.\n"); - return EXIT_FAILURE; - case DAEMON_INETD: - werror("lshd: spawning from inetd not yet supported.\n"); - return EXIT_FAILURE; - case DAEMON_INIT: - case DAEMON_NORMAL: - break; - default: - fatal("Internal error\n"); - } - - if (options->use_pid_file && !daemon_pidfile(options->pid_file)) - { - werror("lshd seems to be running already.\n"); - return EXIT_FAILURE; - } - - /* NOTE: We have to do this *after* forking into the background, - * because otherwise we won't be able to waitpid() on the background - * process. */ - - /* Start background poll */ - RANDOM_POLL_BACKGROUND(options->random->poller); - - { - /* Commands to be invoked on the connection */ - struct object_list *connection_hooks; - struct command *session_setup; - - /* Supported channel requests */ - struct alist *supported_channel_requests - = make_alist(2, - ATOM_SHELL, make_shell_handler(backend), - ATOM_EXEC, make_exec_handler(backend), - -1); - -#if WITH_PTY_SUPPORT - if (options->with_pty) - ALIST_SET(supported_channel_requests, - ATOM_PTY_REQ, &pty_request_handler.super); -#endif /* WITH_PTY_SUPPORT */ - - if (options->subsystems) - ALIST_SET(supported_channel_requests, - ATOM_SUBSYSTEM, - &make_subsystem_handler(backend, - options->subsystems)->super); - - session_setup = make_install_fix_channel_open_handler - (ATOM_SESSION, make_open_session(supported_channel_requests)); - -#if WITH_TCP_FORWARD - if (options->with_tcpip_forward) - connection_hooks = make_object_list - (4, - session_setup, - make_tcpip_forward_hook(backend), - make_install_fix_global_request_handler - (ATOM_CANCEL_TCPIP_FORWARD, &tcpip_cancel_forward), - make_direct_tcpip_hook(backend), - -1); - else -#endif - connection_hooks - = make_object_list (1, session_setup, -1); - { - /* FIXME: We should check that we have at least one host key. We - * should also extract the host-key algorithms for which we have - * keys, instead of hardcoding ssh-dss below. */ - - CAST_SUBTYPE(command, connection_service, - make_lshd_connection_service(connection_hooks)); - CAST_SUBTYPE(command, server_listen, - make_lshd_listen - (backend, - make_handshake_info(CONNECTION_SERVER, - "lsh - a free ssh", - NULL, - SSH_MAX_PACKET, - &options->random->super, - options->super.algorithms, - options->sshd1), - make_simple_kexinit - (&options->random->super, - options->kex_algorithms, - options->super.hostkey_algorithms, - options->super.crypto_algorithms, - options->super.mac_algorithms, - options->super.compression_algorithms, - make_int_list(0, -1)), - make_offer_service - (make_alist - (1, - ATOM_SSH_USERAUTH, - make_userauth_service(options->userauth_methods, - options->userauth_algorithms, - make_alist(1, ATOM_SSH_CONNECTION, - connection_service,-1)), - -1)))); - - COMMAND_CALL(server_listen, options, - &discard_continuation, - make_report_exception_handler - (make_report_exception_info(EXC_IO, EXC_IO, "lshd: "), - options->e, - HANDLER_CONTEXT)); - } - } - - io_run(backend); - - gc_final(); - - return 0; -} diff --git a/lsh/src/lshd.c.x b/lsh/src/lshd.c.x deleted file mode 100755 index 139600b..0000000 Binary files a/lsh/src/lshd.c.x and /dev/null differ diff --git a/lsh/src/lshg.c b/lsh/src/lshg.c deleted file mode 100755 index 0bfd986..0000000 --- a/lsh/src/lshg.c +++ /dev/null @@ -1,297 +0,0 @@ -/* lshg.c - * - * $Id$ - * - * Connect to a gateway. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "charset.h" -#include "client.h" -#include "connection.h" -#include "debug.h" -#include "format.h" -#include "gateway.h" -#include "gateway_commands.h" -#include "interact.h" -#include "io_commands.h" -#include "ssh.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include "lsh_argp.h" - -/* Forward declarations */ -struct command options2info; -#define OPTIONS2INFO (&options2info.super) - - -#include "lshg.c.x" - -/* GABA: - (class - (name lshg_options) - (super client_options) - (vars - (gateway object local_info))) -*/ - -static struct lshg_options * -make_options(struct io_backend *backend, - struct exception_handler *handler, - int *exit_code) -{ - NEW(lshg_options, self); - init_client_options(&self->super, backend, NULL, handler, exit_code); - - self->gateway = NULL; - - return self; -} - -DEFINE_COMMAND(options2info) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(lshg_options, self, a); - - COMMAND_RETURN(c, self->gateway); -} - - -/* GABA: - (expr - (name make_lshg_connect) - (params - (backend object io_backend)) - (expr - (lambda (options) - ((progn (options2actions options)) - (gateway_init - (connect_local backend (options2info options))))))) -*/ - -/* GABA: - (class - (name lshg_simple_action) - (super command) - (vars - (msg . "const char *"))) -*/ - -static void -do_lshg_send_debug(struct command *s, - struct lsh_object *x, - struct command_continuation *c UNUSED, - struct exception_handler *e UNUSED) -{ - CAST(lshg_simple_action, self, s); - CAST(ssh_connection, connection, x); - - send_debug_message(connection->write, self->msg, 1); -} - -static struct command * -make_lshg_send_debug(const char *msg) -{ - NEW(lshg_simple_action, self); - self->msg = msg; - self->super.call = do_lshg_send_debug; - - return &self->super; -} - -static void -do_lshg_send_ignore(struct command *s, - struct lsh_object *x, - struct command_continuation *c UNUSED, - struct exception_handler *e UNUSED) -{ - CAST(lshg_simple_action, self, s); - CAST(ssh_connection, connection, x); - - C_WRITE(connection, ssh_format("%c%z", SSH_MSG_IGNORE, self->msg)); -} - -static struct command * -make_lshg_send_ignore(const char *msg) -{ - NEW(lshg_simple_action, self); - self->msg = msg; - self->super.call = do_lshg_send_ignore; - - return &self->super; -} - - -/* Option parsing */ - -const char *argp_program_version -= "lshg-" VERSION ", secsh protocol version " CLIENT_PROTOCOL_VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -#define ARG_NOT 0x400 - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "send-debug", 'D', "Message", 0, "Send a debug message " - "to the remote machine.", CLIENT_ARGP_ACTION_GROUP }, - { "send-ignore", 'I', "Message", 0, "Send an ignore message " - "to the remote machine.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &client_argp, 0, "", 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(lshg_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->super; - state->child_inputs[1] = NULL; - break; - - case ARGP_KEY_END: - if (!self->super.local_user) - { - argp_error(state, "You have to set LOGNAME in the environment."); - break; - } - assert(self->super.user); - assert(self->super.remote); - - if (object_queue_is_empty(&self->super.actions)) - { - argp_error(state, "No actions given."); - break; - } - - self->gateway = make_gateway_address(self->super.local_user, - self->super.user, - self->super.remote); - - if (!self->gateway) - { - argp_error(state, "Local or remote user name, or the target host name, are too " - "strange for the gateway socket name construction."); - break; - } - break; - - case 'D': - client_add_action(&self->super, make_lshg_send_debug(arg)); - break; - - case 'I': - client_add_action(&self->super, make_lshg_send_ignore(arg)); - break; - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - "host\nhost command", - "Connects to a remote machine, using a gateway\v" - "Connects to the remote machine, using a local gateway, previously setup" - "by running lsh -G.", - main_argp_children, - NULL, NULL -}; - -static void -do_exc_lshg_handler(struct exception_handler *s UNUSED, - const struct exception *e) -{ - werror("Exiting: %z\n", e->msg); - exit(EXIT_FAILURE); -} - -static struct exception_handler * -make_lshg_exception_handler(struct exception_handler *parent, - const char *context) -{ - return make_exception_handler(do_exc_lshg_handler, parent, context); -} - -int -main(int argc, char **argv) -{ - struct lshg_options *options; - struct io_backend *backend = make_io_backend(); - - int exit_code = 17; - - /* For filtering messages. Could perhaps also be used when converting - * strings to and from UTF8. */ - setlocale(LC_CTYPE, ""); - - /* FIXME: Choose character set depending on the locale */ - set_local_charset(CHARSET_LATIN1); - - options = make_options(backend, - make_lshg_exception_handler - (&default_exception_handler, - HANDLER_CONTEXT), - &exit_code); - - argp_parse(&main_argp, argc, argv, ARGP_IN_ORDER, NULL, options); - - { - CAST_SUBTYPE(command, lshg_connect, - make_lshg_connect(backend)); - - COMMAND_CALL(lshg_connect, options, &discard_continuation, - make_lshg_exception_handler(&default_exception_handler, - HANDLER_CONTEXT)); - } - - io_run(backend); - - /* Close all files and other resources associated with the backend. */ - io_final(backend); - - gc_final(); - - return exit_code; -} diff --git a/lsh/src/lshg.c.x b/lsh/src/lshg.c.x deleted file mode 100755 index 6f8c2e4..0000000 Binary files a/lsh/src/lshg.c.x and /dev/null differ diff --git a/lsh/src/md5.c b/lsh/src/md5.c deleted file mode 100755 index 22968be..0000000 --- a/lsh/src/md5.c +++ /dev/null @@ -1,85 +0,0 @@ -/* md5.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "xalloc.h" - -#include "nettle/md5.h" - -#include "md5.c.x" - -/* MD5 hash */ -/* GABA: - (class - (name md5_instance) - (super hash_instance) - (vars - (ctx . "struct md5_ctx"))) -*/ - -static void -do_md5_update(struct hash_instance *s, - UINT32 length, const UINT8 *data) -{ - CAST(md5_instance, self, s); - - md5_update(&self->ctx, length, data); -} - -static void -do_md5_digest(struct hash_instance *s, - UINT8 *dst) -{ - CAST(md5_instance, self, s); - - md5_final(&self->ctx); - md5_digest(&self->ctx, MD5_DIGEST_SIZE, dst); - md5_init(&self->ctx); -} - -static struct hash_instance * -do_md5_copy(struct hash_instance *s) -{ - return &CLONE(md5_instance, s)->super; -} - -static struct hash_instance * -make_md5_instance(struct hash_algorithm *ignored UNUSED) -{ - NEW(md5_instance, res); - - res->super.hash_size = 16; - res->super.update = do_md5_update; - res->super.digest = do_md5_digest; - res->super.copy = do_md5_copy; - - md5_init(&res->ctx); - - return &res->super; -} - -struct hash_algorithm md5_algorithm = -{ STATIC_HEADER, - MD5_DATA_SIZE, MD5_DIGEST_SIZE, make_md5_instance }; - diff --git a/lsh/src/md5.c.x b/lsh/src/md5.c.x deleted file mode 100755 index d4663ef..0000000 Binary files a/lsh/src/md5.c.x and /dev/null differ diff --git a/lsh/src/memcmp.c b/lsh/src/memcmp.c deleted file mode 100755 index 2c14977..0000000 --- a/lsh/src/memcmp.c +++ /dev/null @@ -1,371 +0,0 @@ -/* Copyright (C) 1991, 1993, 1995 Free Software Foundation, Inc. - Contributed by Torbjorn Granlund (tege@sics.se). - -NOTE: The canonical source of this file is maintained with the GNU C Library. -Bugs can be reported to bug-glibc@prep.ai.mit.edu. - -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, or (at your option) any -later version. - -This program 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 should 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. */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#undef __ptr_t -#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) -#define __ptr_t void * -#else /* Not C++ or ANSI C. */ -#undef const -#define const -#define __ptr_t char * -#endif /* C++ or ANSI C. */ - -#if defined (HAVE_STRING_H) || defined (_LIBC) -#include -#endif - -#ifdef _LIBC - -#include - -#else /* Not in the GNU C library. */ - -#include - -/* Type to use for aligned memory operations. - This should normally be the biggest type supported by a single load - and store. Must be an unsigned type. */ -#define op_t unsigned long int -#define OPSIZ (sizeof(op_t)) - -/* Threshold value for when to enter the unrolled loops. */ -#define OP_T_THRES 16 - -/* Type to use for unaligned operations. */ -typedef unsigned char byte; - -#ifndef WORDS_BIGENDIAN -#define MERGE(w0, sh_1, w1, sh_2) (((w0) >> (sh_1)) | ((w1) << (sh_2))) -#else -#define MERGE(w0, sh_1, w1, sh_2) (((w0) << (sh_1)) | ((w1) >> (sh_2))) -#endif - -#endif /* In the GNU C library. */ - -#ifdef WORDS_BIGENDIAN -#define CMP_LT_OR_GT(a, b) ((a) > (b) ? 1 : -1) -#else -#define CMP_LT_OR_GT(a, b) memcmp_bytes ((a), (b)) -#endif - -/* BE VERY CAREFUL IF YOU CHANGE THIS CODE! */ - -/* The strategy of this memcmp is: - - 1. Compare bytes until one of the block pointers is aligned. - - 2. Compare using memcmp_common_alignment or - memcmp_not_common_alignment, regarding the alignment of the other - block after the initial byte operations. The maximum number of - full words (of type op_t) are compared in this way. - - 3. Compare the few remaining bytes. */ - -#ifndef WORDS_BIGENDIAN -/* memcmp_bytes -- Compare A and B bytewise in the byte order of the machine. - A and B are known to be different. - This is needed only on little-endian machines. */ -#ifdef __GNUC__ -__inline -#endif -static int -memcmp_bytes (a, b) - op_t a, b; -{ - long int srcp1 = (long int) &a; - long int srcp2 = (long int) &b; - op_t a0, b0; - - do - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - } - while (a0 == b0); - return a0 - b0; -} -#endif - -/* memcmp_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t' - objects (not LEN bytes!). Both SRCP1 and SRCP2 should be aligned for - memory operations on `op_t's. */ -#ifdef __GNUC__ -__inline -#endif -static int -memcmp_common_alignment (srcp1, srcp2, len) - long int srcp1; - long int srcp2; - size_t len; -{ - op_t a0, a1; - op_t b0, b1; - - switch (len % 4) - { - case 2: - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - srcp1 -= 2 * OPSIZ; - srcp2 -= 2 * OPSIZ; - len += 2; - goto do1; - case 3: - a1 = ((op_t *) srcp1)[0]; - b1 = ((op_t *) srcp2)[0]; - srcp1 -= OPSIZ; - srcp2 -= OPSIZ; - len += 1; - goto do2; - case 0: - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - return 0; - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - goto do3; - case 1: - a1 = ((op_t *) srcp1)[0]; - b1 = ((op_t *) srcp2)[0]; - srcp1 += OPSIZ; - srcp2 += OPSIZ; - len -= 1; - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - goto do0; - /* Fall through. */ - } - - do - { - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); - - do3: - a1 = ((op_t *) srcp1)[1]; - b1 = ((op_t *) srcp2)[1]; - if (a0 != b0) - return CMP_LT_OR_GT (a0, b0); - - do2: - a0 = ((op_t *) srcp1)[2]; - b0 = ((op_t *) srcp2)[2]; - if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); - - do1: - a1 = ((op_t *) srcp1)[3]; - b1 = ((op_t *) srcp2)[3]; - if (a0 != b0) - return CMP_LT_OR_GT (a0, b0); - - srcp1 += 4 * OPSIZ; - srcp2 += 4 * OPSIZ; - len -= 4; - } - while (len != 0); - - /* This is the right position for do0. Please don't move - it into the loop. */ - do0: - if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); - return 0; -} - -/* memcmp_not_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN - `op_t' objects (not LEN bytes!). SRCP2 should be aligned for memory - operations on `op_t', but SRCP1 *should be unaligned*. */ -#ifdef __GNUC__ -__inline -#endif -static int -memcmp_not_common_alignment (srcp1, srcp2, len) - long int srcp1; - long int srcp2; - size_t len; -{ - op_t a0, a1, a2, a3; - op_t b0, b1, b2, b3; - op_t x; - int shl, shr; - - /* Calculate how to shift a word read at the memory operation - aligned srcp1 to make it aligned for comparison. */ - - shl = 8 * (srcp1 % OPSIZ); - shr = 8 * OPSIZ - shl; - - /* Make SRCP1 aligned by rounding it down to the beginning of the `op_t' - it points in the middle of. */ - srcp1 &= -OPSIZ; - - switch (len % 4) - { - case 2: - a1 = ((op_t *) srcp1)[0]; - a2 = ((op_t *) srcp1)[1]; - b2 = ((op_t *) srcp2)[0]; - srcp1 -= 1 * OPSIZ; - srcp2 -= 2 * OPSIZ; - len += 2; - goto do1; - case 3: - a0 = ((op_t *) srcp1)[0]; - a1 = ((op_t *) srcp1)[1]; - b1 = ((op_t *) srcp2)[0]; - srcp2 -= 1 * OPSIZ; - len += 1; - goto do2; - case 0: - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - return 0; - a3 = ((op_t *) srcp1)[0]; - a0 = ((op_t *) srcp1)[1]; - b0 = ((op_t *) srcp2)[0]; - srcp1 += 1 * OPSIZ; - goto do3; - case 1: - a2 = ((op_t *) srcp1)[0]; - a3 = ((op_t *) srcp1)[1]; - b3 = ((op_t *) srcp2)[0]; - srcp1 += 2 * OPSIZ; - srcp2 += 1 * OPSIZ; - len -= 1; - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - goto do0; - /* Fall through. */ - } - - do - { - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - x = MERGE(a2, shl, a3, shr); - if (x != b3) - return CMP_LT_OR_GT (x, b3); - - do3: - a1 = ((op_t *) srcp1)[1]; - b1 = ((op_t *) srcp2)[1]; - x = MERGE(a3, shl, a0, shr); - if (x != b0) - return CMP_LT_OR_GT (x, b0); - - do2: - a2 = ((op_t *) srcp1)[2]; - b2 = ((op_t *) srcp2)[2]; - x = MERGE(a0, shl, a1, shr); - if (x != b1) - return CMP_LT_OR_GT (x, b1); - - do1: - a3 = ((op_t *) srcp1)[3]; - b3 = ((op_t *) srcp2)[3]; - x = MERGE(a1, shl, a2, shr); - if (x != b2) - return CMP_LT_OR_GT (x, b2); - - srcp1 += 4 * OPSIZ; - srcp2 += 4 * OPSIZ; - len -= 4; - } - while (len != 0); - - /* This is the right position for do0. Please don't move - it into the loop. */ - do0: - x = MERGE(a2, shl, a3, shr); - if (x != b3) - return CMP_LT_OR_GT (x, b3); - return 0; -} - -int -memcmp (s1, s2, len) - const __ptr_t s1; - const __ptr_t s2; - size_t len; -{ - op_t a0; - op_t b0; - long int srcp1 = (long int) s1; - long int srcp2 = (long int) s2; - op_t res; - - if (len >= OP_T_THRES) - { - /* There are at least some bytes to compare. No need to test - for LEN == 0 in this alignment loop. */ - while (srcp2 % OPSIZ != 0) - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - res = a0 - b0; - if (res != 0) - return res; - len -= 1; - } - - /* SRCP2 is now aligned for memory operations on `op_t'. - SRCP1 alignment determines if we can do a simple, - aligned compare or need to shuffle bits. */ - - if (srcp1 % OPSIZ == 0) - res = memcmp_common_alignment (srcp1, srcp2, len / OPSIZ); - else - res = memcmp_not_common_alignment (srcp1, srcp2, len / OPSIZ); - if (res != 0) - return res; - - /* Number of bytes remaining in the interval [0..OPSIZ-1]. */ - srcp1 += len & -OPSIZ; - srcp2 += len & -OPSIZ; - len %= OPSIZ; - } - - /* There are just a few bytes to compare. Use byte memory operations. */ - while (len != 0) - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - res = a0 - b0; - if (res != 0) - return res; - len -= 1; - } - - return 0; -} - -#ifdef weak_alias -#undef bcmp -weak_alias (memcmp, bcmp) -#endif diff --git a/lsh/src/memxor.c b/lsh/src/memxor.c deleted file mode 100755 index a5e4b19..0000000 --- a/lsh/src/memxor.c +++ /dev/null @@ -1,19 +0,0 @@ -/* memxor.c - * - * $Id$ - */ - -/* XOR LEN bytes starting at SRCADDR onto DESTADDR. Result undefined - if the source overlaps with the destination. - Return DESTADDR. */ - -#include "memxor.h" - -UINT8 *memxor(UINT8 *dst, const UINT8 *src, size_t n) -{ - size_t i; - for (i = 0; i - -UINT8 *memxor(UINT8 *dst, const UINT8 *src, size_t n); - -#endif /* LSH_MEMXOR_H_INCLUDED */ diff --git a/lsh/src/nettle/AUTHORS b/lsh/src/nettle/AUTHORS deleted file mode 100644 index e69de29..0000000 diff --git a/lsh/src/nettle/COPYING b/lsh/src/nettle/COPYING deleted file mode 100644 index d60c31a..0000000 --- a/lsh/src/nettle/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 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 should 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 - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/lsh/src/nettle/ChangeLog b/lsh/src/nettle/ChangeLog deleted file mode 100644 index e791e1e..0000000 --- a/lsh/src/nettle/ChangeLog +++ /dev/null @@ -1,148 +0,0 @@ -2001-09-02 Niels Möller - - * twofish.c (twofish_decrypt): Fixed for();-bug in the block-loop. - Spotted by Jean-Pierre. - (twofish_encrypt): Likewise. - -2001-07-03 Niels Möller - - * testsuite/testutils.c: Include string.h. - - * twofish.c: Include string.h. - -2001-06-17 Niels Möller - - * Makefile.am (des_headers): Dont use $(srcdir)/-prefixes as that - seems to break with GNU make 3.79.1. - - * testsuite/testutils.c, testsuite/testutils.h: Use , - not . - Include . - -2001-06-17 Niels Möller - - * Use , not . - - * blowfish.h (BLOWFISH_MAX_KEY_SIZE): Fixed, should be 56. - - * Fixed copyright notices. - - * Makefile.am (libnettle_a_SOURCES): Added desinfo.h and - desCode.h. - (info_TEXINFOS): Added manual. - (EXTRA_DIST): Added nettle.html. - (%.html): Added rule for building nettle.html. - - * nettle.texinfo: New manual. - - * configure.in: Bumped version to 0.2. - - * testsuite/Makefile.am (TS_PROGS): Added cast128 test. - - * Added CAST128. - - * testsuite/serpent-test.m4: Added a few rudimentary tests - extracted from the serpent package. - - * twofish.c: Adapted to nettle. Made constant tables const. - Deleted bytes_to_word and word_to_bytes; use LE_READ_UINT32 and - LE_WRITE_UINT32 instead. - (twofish_selftest): Deleted. Moved the tests to the external - testsuite. - (twofish_set_key): Don't silently truncate too large keys. - - * sha1.c (sha1_update): Use unsigned for length. - - * serpent.c (serpent_set_key): Read the key backwards. Fixed - padding (but there are no test vectors for key_size not a multiple - of 4). - (serpent_encrypt): Read and write data in the strange order used - by the reference implementation. - (serpent_decrypt): Likewise. - - * macros.h (FOR_BLOCKS): New macro, taken from lsh. - - * blowfish.h (struct blowfish_ctx): Use a two-dimensional array - for s. - - * blowfish.c (initial_ctx): Arrange constants into a struct, to - simplify key setup. - (F): Deleted all but one definitions of the F function/macro. - Added a context argument, and use that to find the subkeys. - (R): Added context argument, and use that to find the subkeys. - (blowfish_set_key): Some simplification. - - (encrypt): Deleted code for non-standard number of rounds. Deleted - a bunch of local variables. Using the context pointer for - everything should consume less registers. - (decrypt): Likewise. - - * Makefile.am (libnettle_a_SOURCES): Added twofish. - -2001-06-16 Niels Möller - - * testsuite/blowfish-test.m4: Fixed test. - - * Added twofish implementation. - - * blowfish.h (struct blowfish_ctx): Use the correct size for the p - array. - -2001-06-15 Niels Möller - - * testsuite/blowfish-test.m4: Fixed testcase, use correct key - length. - - * Makefile.am (libnettle_a_SOURCES): Added blowfish files. - ($(des_headers)): Strip directory part when passing file name to - desdata. - - * testsuite/blowfish-test.m4: Added one test, from GNUPG. - - * Created blowfish.c and blowfish.h (from GNUPG via LSH). Needs - more work. - - * aes.h: Fixed copyright notice to not mention GNU MP. XXX: Review - all nettle copyrights. - - * testsuite/Makefile.am (TS_PROGS): Added tests for twofish and - blowfish. - -2001-06-13 Niels Möller - - * Makefile.am (libnettle_a_SOURCES): Added serpent files. - -2001-06-12 Niels Möller - - * des.c (des_encrypt, des_decrypt): Assert that the key setup was - successful. - - * testsuite/Makefile.am (TS_PROGS): Added tests for des and sha1. - - * testsuite/sha1-test.m4: New file. - - * testsuite/des-test.m4: New file. - - * Added SHA1 files. - - * Added desCore files. - - * Makefile.am: Added desCore and sha1. - -2001-04-17 Niels Möller - - * install-sh: Copied the standard install script. - - * testsuite/Makefile.am (CFLAGS): Disable optimization. Add - $(top_srcdir) to the include path. - (EXTRA_DIST): Added testutils.h, testutils.c and run-tests. - (run-tests): Fixed path to run-tests. - - * Makefile.am (EXTRA_DIST): Added memxor.h. - (libnettleinclude_HEADERS): Install headers in - $(libnettleincludedir). - -2001-04-13 Niels Möller - - * Initial checkin. - diff --git a/lsh/src/nettle/INSTALL b/lsh/src/nettle/INSTALL deleted file mode 100644 index b42a17a..0000000 --- a/lsh/src/nettle/INSTALL +++ /dev/null @@ -1,182 +0,0 @@ -Basic Installation -================== - - These are generic installation instructions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, a file -`config.cache' that saves the results of its tests to speed up -reconfiguring, and a file `config.log' containing compiler output -(useful mainly for debugging `configure'). - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If at some point `config.cache' -contains results you don't want to keep, you may remove or edit it. - - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. You can give `configure' -initial values for variables by setting them in the environment. Using -a Bourne-compatible shell, you can do that on the command line like -this: - CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure - -Or on systems that have the `env' program, you can do it like this: - env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not supports the `VPATH' -variable, you have to compile the package for one architecture at a time -in the source code directory. After you have installed the package for -one architecture, use `make distclean' before reconfiguring for another -architecture. - -Installation Names -================== - - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=PATH' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - - There may be some features `configure' can not figure out -automatically, but needs to determine by the type of host the package -will run on. Usually `configure' can figure that out, but if it prints -a message saying it can not guess the host type, give it the -`--host=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name with three fields: - CPU-COMPANY-SYSTEM - -See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the host type. - - If you are building compiler tools for cross-compiling, you can also -use the `--target=TYPE' option to select the type of system they will -produce code for and the `--build=TYPE' option to select the type of -system on which you are compiling the package. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Operation Controls -================== - - `configure' recognizes the following options to control how it -operates. - -`--cache-file=FILE' - Use and save the results of the tests in FILE instead of - `./config.cache'. Set FILE to `/dev/null' to disable caching, for - debugging `configure'. - -`--help' - Print a summary of the options to `configure', and exit. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--version' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`configure' also accepts some other, not widely useful, options. diff --git a/lsh/src/nettle/Makefile.am b/lsh/src/nettle/Makefile.am deleted file mode 100644 index c6ceaa4..0000000 --- a/lsh/src/nettle/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -SUBDIRS = . testsuite - -noinst_PROGRAMS = desdata - -libnettleincludedir = $(includedir)/nettle - -lib_LIBRARIES = libnettle.a -libnettleinclude_HEADERS = aes.h arcfour.h des.h md5.h sha1.h - -libnettle_a_SOURCES = aes.c aes.h arcfour.c arcfour.h \ - cast128.c cast128.h cast128_sboxes.h \ - blowfish.h blowfish.c \ - des.c des.h desinfo.h desCode.h \ - md5.c md5.h sha1.c sha1.h \ - serpent.c serpent.h serpent_sboxes.h \ - twofish.c twofish.h - -libnettle_a_LIBADD = @LIBOBJS@ - -info_TEXINFOS = nettle.texinfo - -all-local: nettle.html - -EXTRA_DIST = macros.h memxor.h $(des_headers) descore.README nettle.html - -# BUILT_SOURCE = $(des_headers) - -%.html : %.texinfo - (cd $(srcdir) \ - && $(MAKEINFO) --html --no-split --output $@T $( $@T - test -s $@T && mv -f $@T $@ - -des.o: des.c des.h $(des_headers) diff --git a/lsh/src/nettle/Makefile.in b/lsh/src/nettle/Makefile.in deleted file mode 100644 index 4f8ecca..0000000 --- a/lsh/src/nettle/Makefile.in +++ /dev/null @@ -1,655 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = . - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -VERSION = @VERSION@ - -SUBDIRS = . testsuite - -noinst_PROGRAMS = desdata - -libnettleincludedir = $(includedir)/nettle - -lib_LIBRARIES = libnettle.a -libnettleinclude_HEADERS = aes.h arcfour.h des.h md5.h sha1.h - -libnettle_a_SOURCES = aes.c aes.h arcfour.c arcfour.h cast128.c cast128.h cast128_sboxes.h blowfish.h blowfish.c des.c des.h desinfo.h desCode.h md5.c md5.h sha1.c sha1.h serpent.c serpent.h serpent_sboxes.h twofish.c twofish.h - - -libnettle_a_LIBADD = @LIBOBJS@ - -info_TEXINFOS = nettle.texinfo - -EXTRA_DIST = macros.h memxor.h $(des_headers) descore.README nettle.html - -# desCore rules -# It seems using $(srcdir)/ doesn't work with GNU make 3.79.1 -# des_headers = $(srcdir)/parity.h $(srcdir)/rotors.h $(srcdir)/keymap.h -des_headers = parity.h rotors.h keymap.h -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = -LIBRARIES = $(lib_LIBRARIES) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -libnettle_a_DEPENDENCIES = @LIBOBJS@ -libnettle_a_OBJECTS = aes.o arcfour.o cast128.o blowfish.o des.o md5.o \ -sha1.o serpent.o twofish.o -AR = ar -PROGRAMS = $(noinst_PROGRAMS) - -desdata_SOURCES = desdata.c -desdata_OBJECTS = desdata.o -desdata_LDADD = $(LDADD) -desdata_DEPENDENCIES = -desdata_LDFLAGS = -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -TEXI2DVI = texi2dvi -INFO_DEPS = nettle.info -DVIS = nettle.dvi -TEXINFOS = nettle.texinfo -HEADERS = $(libnettleinclude_HEADERS) - -DIST_COMMON = README ./stamp-h.in AUTHORS COPYING ChangeLog INSTALL \ -Makefile.am Makefile.in NEWS aclocal.m4 config.h.in configure \ -configure.in install-sh memxor.c missing mkinstalldirs texinfo.tex - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = $(libnettle_a_SOURCES) desdata.c -OBJECTS = $(libnettle_a_OBJECTS) desdata.o - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .dvi .info .o .ps .s .texi .texinfo .txi -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -$(ACLOCAL_M4): configure.in - cd $(srcdir) && $(ACLOCAL) - -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) - -config.h: stamp-h - @if test ! -f $@; then \ - rm -f stamp-h; \ - $(MAKE) stamp-h; \ - else :; fi -stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=config.h \ - $(SHELL) ./config.status - @echo timestamp > stamp-h 2> /dev/null -$(srcdir)/config.h.in: $(srcdir)/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/stamp-h.in; \ - $(MAKE) $(srcdir)/stamp-h.in; \ - else :; fi -$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f config.h - -maintainer-clean-hdr: - -mostlyclean-libLIBRARIES: - -clean-libLIBRARIES: - -test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES) - -distclean-libLIBRARIES: - -maintainer-clean-libLIBRARIES: - -install-libLIBRARIES: $(lib_LIBRARIES) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(libdir) - @list='$(lib_LIBRARIES)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$p"; \ - $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$p; \ - else :; fi; \ - done - @$(POST_INSTALL) - @list='$(lib_LIBRARIES)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(RANLIB) $(DESTDIR)$(libdir)/$$p"; \ - $(RANLIB) $(DESTDIR)$(libdir)/$$p; \ - else :; fi; \ - done - -uninstall-libLIBRARIES: - @$(NORMAL_UNINSTALL) - list='$(lib_LIBRARIES)'; for p in $$list; do \ - rm -f $(DESTDIR)$(libdir)/$$p; \ - done - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -libnettle.a: $(libnettle_a_OBJECTS) $(libnettle_a_DEPENDENCIES) - -rm -f libnettle.a - $(AR) cru libnettle.a $(libnettle_a_OBJECTS) $(libnettle_a_LIBADD) - $(RANLIB) libnettle.a - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -desdata: $(desdata_OBJECTS) $(desdata_DEPENDENCIES) - @rm -f desdata - $(LINK) $(desdata_LDFLAGS) $(desdata_OBJECTS) $(desdata_LDADD) $(LIBS) - -nettle.info: nettle.texinfo -nettle.dvi: nettle.texinfo - - -DVIPS = dvips - -.texi.info: - @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9] - cd $(srcdir) \ - && $(MAKEINFO) `echo $< | sed 's,.*/,,'` - -.texi.dvi: - TEXINPUTS=.:$$TEXINPUTS \ - MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $< - -.texi: - @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9] - cd $(srcdir) \ - && $(MAKEINFO) `echo $< | sed 's,.*/,,'` - -.texinfo.info: - @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9] - cd $(srcdir) \ - && $(MAKEINFO) `echo $< | sed 's,.*/,,'` - -.texinfo: - @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9] - cd $(srcdir) \ - && $(MAKEINFO) `echo $< | sed 's,.*/,,'` - -.texinfo.dvi: - TEXINPUTS=.:$$TEXINPUTS \ - MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $< - -.txi.info: - @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9] - cd $(srcdir) \ - && $(MAKEINFO) `echo $< | sed 's,.*/,,'` - -.txi.dvi: - TEXINPUTS=.:$$TEXINPUTS \ - MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $< - -.txi: - @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9] - cd $(srcdir) \ - && $(MAKEINFO) `echo $< | sed 's,.*/,,'` -.dvi.ps: - $(DVIPS) $< -o $@ - -install-info-am: $(INFO_DEPS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(infodir) - @list='$(INFO_DEPS)'; \ - for file in $$list; do \ - d=$(srcdir); \ - for ifile in `cd $$d && echo $$file $$file-[0-9] $$file-[0-9][0-9]`; do \ - if test -f $$d/$$ifile; then \ - echo " $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile"; \ - $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile; \ - else : ; fi; \ - done; \ - done - @$(POST_INSTALL) - @if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \ - list='$(INFO_DEPS)'; \ - for file in $$list; do \ - echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file";\ - install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file || :;\ - done; \ - else : ; fi - -uninstall-info: - $(PRE_UNINSTALL) - @if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \ - ii=yes; \ - else ii=; fi; \ - list='$(INFO_DEPS)'; \ - for file in $$list; do \ - test -z "$ii" \ - || install-info --info-dir=$(DESTDIR)$(infodir) --remove $$file; \ - done - @$(NORMAL_UNINSTALL) - list='$(INFO_DEPS)'; \ - for file in $$list; do \ - (cd $(DESTDIR)$(infodir) && rm -f $$file $$file-[0-9] $$file-[0-9][0-9]); \ - done - -dist-info: $(INFO_DEPS) - list='$(INFO_DEPS)'; \ - for base in $$list; do \ - d=$(srcdir); \ - for file in `cd $$d && eval echo $$base*`; do \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file; \ - done; \ - done - -mostlyclean-aminfo: - -rm -f nettle.aux nettle.cp nettle.cps nettle.dvi nettle.fn nettle.fns \ - nettle.ky nettle.kys nettle.ps nettle.log nettle.pg \ - nettle.toc nettle.tp nettle.tps nettle.vr nettle.vrs \ - nettle.op nettle.tr nettle.cv nettle.cn - -clean-aminfo: - -distclean-aminfo: - -maintainer-clean-aminfo: - cd $(srcdir) && for i in $(INFO_DEPS); do \ - rm -f $$i; \ - if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then \ - rm -f $$i-[0-9]*; \ - fi; \ - done - -install-libnettleincludeHEADERS: $(libnettleinclude_HEADERS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(libnettleincludedir) - @list='$(libnettleinclude_HEADERS)'; for p in $$list; do \ - if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \ - echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libnettleincludedir)/$$p"; \ - $(INSTALL_DATA) $$d$$p $(DESTDIR)$(libnettleincludedir)/$$p; \ - done - -uninstall-libnettleincludeHEADERS: - @$(NORMAL_UNINSTALL) - list='$(libnettleinclude_HEADERS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(libnettleincludedir)/$$p; \ - done - -# This directory's subdirectories are mostly independent; you can cd -# into them and run `make' without going through this Makefile. -# To change the values of `make' variables: instead of editing Makefiles, -# (1) if the variable is set in `config.status', edit `config.status' -# (which will cause the Makefiles to be regenerated when you run `make'); -# (2) otherwise, pass the desired values on the `make' command line. - -@SET_MAKE@ - -all-recursive install-data-recursive install-exec-recursive \ -installdirs-recursive install-recursive uninstall-recursive \ -check-recursive installcheck-recursive info-recursive dvi-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -mostlyclean-recursive clean-recursive distclean-recursive \ -maintainer-clean-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ - rev="$$subdir $$rev"; \ - test "$$subdir" = "." && dot_seen=yes; \ - done; \ - test "$$dot_seen" = "no" && rev=". $$rev"; \ - target=`echo $@ | sed s/-recursive//`; \ - for subdir in $$rev; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done && test -z "$$fail" -tags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ - done - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \ - fi; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - -rm -rf $(distdir) - GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz - mkdir $(distdir)/=build - mkdir $(distdir)/=inst - dc_install_base=`cd $(distdir)/=inst && pwd`; \ - cd $(distdir)/=build \ - && ../configure --srcdir=.. --prefix=$$dc_install_base \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) dist - -rm -rf $(distdir) - @banner="$(distdir).tar.gz is ready for distribution"; \ - dashes=`echo "$$banner" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - echo "$$dashes" -dist: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -dist-all: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -distdir: $(DISTFILES) - -rm -rf $(distdir) - mkdir $(distdir) - -chmod 777 $(distdir) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - for subdir in $(SUBDIRS); do \ - if test "$$subdir" = .; then :; else \ - test -d $(distdir)/$$subdir \ - || mkdir $(distdir)/$$subdir \ - || exit 1; \ - chmod 777 $(distdir)/$$subdir; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \ - || exit 1; \ - fi; \ - done - $(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-info -aes.o: aes.c aes.h -arcfour.o: arcfour.c arcfour.h -blowfish.o: blowfish.c blowfish.h macros.h -cast128.o: cast128.c cast128.h cast128_sboxes.h macros.h -des.o: des.c des.h desCode.h keymap.h rotors.h parity.h -desdata.o: desdata.c desinfo.h desCode.h des.h -md5.o: md5.c md5.h macros.h -memxor.o: memxor.c memxor.h -serpent.o: serpent.c serpent.h serpent_sboxes.h macros.h -sha1.o: sha1.c sha1.h macros.h -twofish.o: twofish.c twofish.h macros.h - -info-am: $(INFO_DEPS) -info: info-recursive -dvi-am: $(DVIS) -dvi: dvi-recursive -check-am: all-am -check: check-recursive -installcheck-am: -installcheck: installcheck-recursive -all-recursive-am: config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -install-exec-am: install-libLIBRARIES -install-exec: install-exec-recursive - -install-data-am: install-info-am install-libnettleincludeHEADERS -install-data: install-data-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-recursive -uninstall-am: uninstall-libLIBRARIES uninstall-info \ - uninstall-libnettleincludeHEADERS -uninstall: uninstall-recursive -all-am: Makefile $(INFO_DEPS) $(LIBRARIES) $(PROGRAMS) $(HEADERS) \ - config.h all-local -all-redirect: all-recursive-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: installdirs-recursive -installdirs-am: - $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \ - $(DESTDIR)$(libnettleincludedir) - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-hdr mostlyclean-libLIBRARIES \ - mostlyclean-compile mostlyclean-noinstPROGRAMS \ - mostlyclean-aminfo mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-recursive - -clean-am: clean-hdr clean-libLIBRARIES clean-compile \ - clean-noinstPROGRAMS clean-aminfo clean-tags \ - clean-generic mostlyclean-am - -clean: clean-recursive - -distclean-am: distclean-hdr distclean-libLIBRARIES distclean-compile \ - distclean-noinstPROGRAMS distclean-aminfo \ - distclean-tags distclean-generic clean-am - -distclean: distclean-recursive - -rm -f config.status - -maintainer-clean-am: maintainer-clean-hdr maintainer-clean-libLIBRARIES \ - maintainer-clean-compile \ - maintainer-clean-noinstPROGRAMS maintainer-clean-aminfo \ - maintainer-clean-tags maintainer-clean-generic \ - distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-recursive - -rm -f config.status - -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -mostlyclean-libLIBRARIES distclean-libLIBRARIES clean-libLIBRARIES \ -maintainer-clean-libLIBRARIES uninstall-libLIBRARIES \ -install-libLIBRARIES mostlyclean-compile distclean-compile \ -clean-compile maintainer-clean-compile mostlyclean-noinstPROGRAMS \ -distclean-noinstPROGRAMS clean-noinstPROGRAMS \ -maintainer-clean-noinstPROGRAMS install-info-am uninstall-info \ -mostlyclean-aminfo distclean-aminfo clean-aminfo \ -maintainer-clean-aminfo uninstall-libnettleincludeHEADERS \ -install-libnettleincludeHEADERS install-data-recursive \ -uninstall-data-recursive install-exec-recursive \ -uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \ -all-recursive check-recursive installcheck-recursive info-recursive \ -dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \ -maintainer-clean-recursive tags tags-recursive mostlyclean-tags \ -distclean-tags clean-tags maintainer-clean-tags distdir info-am info \ -dvi-am dvi check check-am installcheck-am installcheck all-recursive-am \ -install-exec-am install-exec install-data-am install-data install-am \ -install uninstall-am uninstall all-local all-redirect all-am all \ -installdirs-am installdirs mostlyclean-generic distclean-generic \ -clean-generic maintainer-clean-generic clean mostlyclean distclean \ -maintainer-clean - - -all-local: nettle.html - -# BUILT_SOURCE = $(des_headers) - -%.html : %.texinfo - (cd $(srcdir) \ - && $(MAKEINFO) --html --no-split --output $@T $( $@T - test -s $@T && mv -f $@T $@ - -des.o: des.c des.h $(des_headers) - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/nettle/NEWS b/lsh/src/nettle/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/lsh/src/nettle/README b/lsh/src/nettle/README deleted file mode 100644 index e69de29..0000000 diff --git a/lsh/src/nettle/aclocal.m4 b/lsh/src/nettle/aclocal.m4 deleted file mode 100644 index 749952f..0000000 --- a/lsh/src/nettle/aclocal.m4 +++ /dev/null @@ -1,215 +0,0 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4 - -dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without -dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A -dnl PARTICULAR PURPOSE. - -# Do all the work for Automake. This macro actually does too much -- -# some checks are only needed if your package does certain things. -# But this isn't really a big deal. - -# serial 1 - -dnl Usage: -dnl AM_INIT_AUTOMAKE(package,version, [no-define]) - -AC_DEFUN(AM_INIT_AUTOMAKE, -[AC_REQUIRE([AC_PROG_INSTALL]) -PACKAGE=[$1] -AC_SUBST(PACKAGE) -VERSION=[$2] -AC_SUBST(VERSION) -dnl test to see if srcdir already configured -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) -fi -ifelse([$3],, -AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) -AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) -AC_REQUIRE([AM_SANITY_CHECK]) -AC_REQUIRE([AC_ARG_PROGRAM]) -dnl FIXME This is truly gross. -missing_dir=`cd $ac_aux_dir && pwd` -AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) -AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) -AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) -AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) -AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) -AC_REQUIRE([AC_PROG_MAKE_SET])]) - -# -# Check to make sure that the build environment is sane. -# - -AC_DEFUN(AM_SANITY_CHECK, -[AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "[$]*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "[$]*" != "X $srcdir/configure conftestfile" \ - && test "[$]*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi - - test "[$]2" = conftestfile - ) -then - # Ok. - : -else - AC_MSG_ERROR([newly created file is older than distributed files! -Check your system clock]) -fi -rm -f conftest* -AC_MSG_RESULT(yes)]) - -dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) -dnl The program must properly implement --version. -AC_DEFUN(AM_MISSING_PROG, -[AC_MSG_CHECKING(for working $2) -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if ($2 --version) < /dev/null > /dev/null 2>&1; then - $1=$2 - AC_MSG_RESULT(found) -else - $1="$3/missing $2" - AC_MSG_RESULT(missing) -fi -AC_SUBST($1)]) - -# Like AC_CONFIG_HEADER, but automatically create stamp file. - -AC_DEFUN(AM_CONFIG_HEADER, -[AC_PREREQ([2.12]) -AC_CONFIG_HEADER([$1]) -dnl When config.status generates a header, we must update the stamp-h file. -dnl This file resides in the same directory as the config header -dnl that is generated. We must strip everything past the first ":", -dnl and everything past the last "/". -AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl -ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>, -<>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>, -<>; do - case " <<$>>CONFIG_HEADERS " in - *" <<$>>am_file "*<<)>> - echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx - ;; - esac - am_indx=`expr "<<$>>am_indx" + 1` -done<<>>dnl>>) -changequote([,]))]) - - -# serial 1 - -# @defmac AC_PROG_CC_STDC -# @maindex PROG_CC_STDC -# @ovindex CC -# If the C compiler in not in ANSI C mode by default, try to add an option -# to output variable @code{CC} to make it so. This macro tries various -# options that select ANSI C on some system or another. It considers the -# compiler to be in ANSI C mode if it handles function prototypes correctly. -# -# If you use this macro, you should check after calling it whether the C -# compiler has been set to accept ANSI C; if not, the shell variable -# @code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source -# code in ANSI C, you can make an un-ANSIfied copy of it by using the -# program @code{ansi2knr}, which comes with Ghostscript. -# @end defmac - -AC_DEFUN(AM_PROG_CC_STDC, -[AC_REQUIRE([AC_PROG_CC]) -AC_BEFORE([$0], [AC_C_INLINE]) -AC_BEFORE([$0], [AC_C_CONST]) -dnl Force this before AC_PROG_CPP. Some cpp's, eg on HPUX, require -dnl a magic option to avoid problems with ANSI preprocessor commands -dnl like #elif. -dnl FIXME: can't do this because then AC_AIX won't work due to a -dnl circular dependency. -dnl AC_BEFORE([$0], [AC_PROG_CPP]) -AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C) -AC_CACHE_VAL(am_cv_prog_cc_stdc, -[am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - AC_TRY_COMPILE( -[#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -], [ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; -], -[am_cv_prog_cc_stdc="$ac_arg"; break]) -done -CC="$ac_save_CC" -]) -if test -z "$am_cv_prog_cc_stdc"; then - AC_MSG_RESULT([none needed]) -else - AC_MSG_RESULT($am_cv_prog_cc_stdc) -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac -]) - diff --git a/lsh/src/nettle/aes.c b/lsh/src/nettle/aes.c deleted file mode 100644 index 9436f62..0000000 --- a/lsh/src/nettle/aes.c +++ /dev/null @@ -1,505 +0,0 @@ -/* aes.c - * - * The aes/rijndael block cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2000, 2001 Rafael R. Sevilla, Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* Originally written by Rafael R. Sevilla */ - -#include "aes.h" - -#include - -/* These tables combine both the S-boxes and the mixcolumn - * transformation, so that we can perform a round's encryption or by - * means of four table lookups and four XOR's per column of state. - * They were generated by the makertbls.pl script. */ -static const uint32_t dtbl[] = { - 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, - 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, - 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56, - 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec, - 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa, - 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb, - 0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, - 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b, - 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c, - 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83, - 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, - 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a, - 0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d, - 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f, - 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df, - 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, - 0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34, - 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b, - 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d, - 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413, - 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, - 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, - 0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972, - 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85, - 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, - 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511, - 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe, - 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b, - 0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05, - 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1, - 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, - 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf, - 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3, - 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e, - 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a, - 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6, - 0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3, - 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b, - 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428, - 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad, - 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, - 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8, - 0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4, - 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2, - 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda, - 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, - 0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, - 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810, - 0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c, - 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697, - 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, - 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, - 0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc, - 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c, - 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, - 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27, - 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122, - 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433, - 0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9, - 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5, - 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, - 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0, - 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e, - 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c, -}; - -static const uint32_t itbl[] = { - 0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a, - 0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b, - 0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5, - 0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5, - 0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d, - 0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b, - 0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295, - 0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e, - 0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927, - 0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d, - 0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362, - 0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9, - 0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52, - 0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566, - 0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3, - 0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed, - 0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e, - 0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4, - 0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4, - 0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd, - 0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d, - 0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060, - 0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967, - 0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879, - 0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000, - 0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c, - 0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36, - 0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624, - 0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b, - 0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c, - 0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12, - 0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14, - 0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3, - 0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b, - 0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8, - 0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684, - 0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7, - 0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177, - 0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947, - 0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322, - 0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498, - 0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f, - 0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54, - 0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382, - 0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf, - 0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb, - 0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83, - 0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef, - 0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029, - 0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235, - 0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733, - 0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117, - 0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4, - 0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546, - 0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb, - 0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d, - 0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb, - 0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a, - 0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773, - 0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478, - 0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2, - 0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff, - 0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664, - 0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0, -}; - - -/* Needed only for the key schedule and for final rounds */ -static const uint8_t sbox[256] = { - 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, - 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, - 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, - 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, - 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, - 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, - 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, - 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, - 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68, - 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, - 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, - 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, - 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, - 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, - 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, - 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, - 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, - 22, -}; - -static const uint8_t isbox[256] = { - 82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, - 251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, - 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, - 250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, - 109, 139, 209, 37, 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, - 204, 93, 101, 182, 146, 108, 112, 72, 80, 253, 237, 185, 218, 94, 21, - 70, 87, 167, 141, 157, 132, 144, 216, 171, 0, 140, 188, 211, 10, 247, - 228, 88, 5, 184, 179, 69, 6, 208, 44, 30, 143, 202, 63, 15, 2, - 193, 175, 189, 3, 1, 19, 138, 107, 58, 145, 17, 65, 79, 103, 220, - 234, 151, 242, 207, 206, 240, 180, 230, 115, 150, 172, 116, 34, 231, 173, - 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, 71, 241, 26, 113, 29, - 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, 252, 86, 62, 75, - 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, 31, 221, 168, - 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81, - 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160, - 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, - 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, - 125, -}; - -/* Used only by the key schedule */ -static const uint8_t Logtable[256] = { - 0, 0, 25, 1, 50, 2, 26, 198, 75, 199, 27, 104, 51, 238, 223, 3, - 100, 4, 224, 14, 52, 141, 129, 239, 76, 113, 8, 200, 248, 105, 28, - 193, 125, 194, 29, 181, 249, 185, 39, 106, 77, 228, 166, 114, 154, 201, - 9, 120, 101, 47, 138, 5, 33, 15, 225, 36, 18, 240, 130, 69, 53, - 147, 218, 142, 150, 143, 219, 189, 54, 208, 206, 148, 19, 92, 210, 241, - 64, 70, 131, 56, 102, 221, 253, 48, 191, 6, 139, 98, 179, 37, 226, - 152, 34, 136, 145, 16, 126, 110, 72, 195, 163, 182, 30, 66, 58, 107, - 40, 84, 250, 133, 61, 186, 43, 121, 10, 21, 155, 159, 94, 202, 78, - 212, 172, 229, 243, 115, 167, 87, 175, 88, 168, 80, 244, 234, 214, 116, - 79, 174, 233, 213, 231, 230, 173, 232, 44, 215, 117, 122, 235, 22, 11, - 245, 89, 203, 95, 176, 156, 169, 81, 160, 127, 12, 246, 111, 23, 196, - 73, 236, 216, 67, 31, 45, 164, 118, 123, 183, 204, 187, 62, 90, 251, - 96, 177, 134, 59, 82, 161, 108, 170, 85, 41, 157, 151, 178, 135, 144, - 97, 190, 220, 252, 188, 149, 207, 205, 55, 63, 91, 209, 83, 57, 132, - 60, 65, 162, 109, 71, 20, 42, 158, 93, 86, 242, 211, 171, 68, 17, - 146, 217, 35, 32, 46, 137, 180, 124, 184, 38, 119, 153, 227, 165, 103, - 74, 237, 222, 197, 49, 254, 24, 13, 99, 140, 128, 192, 247, 112, 7, -}; - -static const uint8_t Alogtable[256] = { - 1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, - 53, 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, - 102, 170, 229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, - 171, 230, 49, 83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, - 211, 110, 178, 205, 76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, - 8, 24, 40, 120, 136, 131, 158, 185, 208, 107, 189, 220, 127, 129, 152, - 179, 206, 73, 219, 118, 154, 181, 196, 87, 249, 16, 48, 80, 240, 11, - 29, 39, 105, 187, 214, 97, 163, 254, 25, 43, 125, 135, 146, 173, 236, - 47, 113, 147, 174, 233, 32, 96, 160, 251, 22, 58, 78, 210, 109, 183, - 194, 93, 231, 50, 86, 250, 21, 63, 65, 195, 94, 226, 61, 71, 201, - 64, 192, 91, 237, 44, 116, 156, 191, 218, 117, 159, 186, 213, 100, 172, - 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128, 155, 182, 193, 88, - 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84, 252, 31, 33, - 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, 69, 207, - 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14, 18, - 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23, - 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1, -}; - -#define ROTBYTE(x) (((x) >> 8) | (((x) & 0xff) << 24)) -#define ROTRBYTE(x) (((x) << 8) | (((x) >> 24) & 0xff)) -#define SUBBYTE(x, box) (((box)[((x) & 0xff)]) | \ - ((box)[(((x) >> 8) & 0xff)] << 8) | \ - ((box)[(((x) >> 16) & 0xff)] << 16) | \ - ((box)[(((x) >> 24) & 0xff)] << 24)) - -static uint8_t -xtime(uint8_t a) -{ - uint8_t b; - - b = (a & 0x80) ? 0x1b : 0; - a<<=1; - a^=b; - return(a); -} - -static uint8_t -mul(uint8_t a, uint8_t b) -{ - if (a && b) return Alogtable[(Logtable[a] + Logtable[b])%255]; - else return 0; -} - -static void -inv_mix_column(uint32_t *a, uint32_t *b) -{ - uint8_t c[4][4]; - unsigned i, j; - - for(j = 0; j < 4; j++) - { - for(i = 0; i < 4; i++) - { - c[j][i] = mul(0xe, (a[j] >> i*8) & 0xff) - ^ mul(0xb, (a[j] >> ((i+1)%4)*8) & 0xff) - ^ mul(0xd, (a[j] >> ((i+2)%4)*8) & 0xff) - ^ mul(0x9, (a[j] >> ((i+3)%4)*8) & 0xff); - } - } - for(i = 0; i < 4; i++) - { - b[i] = 0; - for(j = 0; j < 4; j++) - b[i] |= c[i][j] << (j*8); - } -} - -/* FIXME: Perhaps we should have separate fucntion for encryption and decryption keys? - * It seems unnecessary to compute the inverse subkeys if we're not going to use them. - * Can one define an aes_inverse function? */ - -void -aes_set_key(struct aes_ctx *ctx, unsigned keysize, const uint8_t *key) -{ - unsigned nk, nr, i, lastkey; - uint32_t temp, rcon; - - assert(keysize >= AES_MIN_KEY_SIZE); - assert(keysize <= AES_MAX_KEY_SIZE); - - /* Truncate keysizes to the valid key sizes provided by Rijndael */ - if (keysize == 32) { - nk = 8; - nr = 14; - } else if (keysize >= 24) { - nk = 6; - nr = 12; - } else { /* must be 16 or more */ - nk = 4; - nr = 10; - } - - lastkey = (AES_BLOCK_SIZE/4) * (nr + 1); - ctx->nrounds = nr; - rcon = 1; - for (i=0; ikeys[i] = key[i*4] + (key[i*4+1]<<8) + (key[i*4+2]<<16) + - (key[i*4+3]<<24); - } - - for (i=nk; ikeys[i-1]; - if (i % nk == 0) - { - temp = SUBBYTE(ROTBYTE(temp), sbox) ^ rcon; - rcon = (uint32_t)xtime((uint8_t)rcon&0xff); - } - else if (nk > 6 && (i%nk) == 4) - { - temp = SUBBYTE(temp, sbox); - } - ctx->keys[i] = ctx->keys[i-nk] ^ temp; - } - - /* Generate the inverse keys */ - for (i=0; i<4; i++) - { - ctx->ikeys[i] = ctx->keys[i]; - ctx->ikeys[lastkey-4 + i] = ctx->keys[lastkey-4 + i]; - } - for (i=4; ikeys[i]), &(ctx->ikeys[i])); -} - -/* Key addition that also packs every byte in the key to a word rep. */ -static void -key_addition_8to32(const uint8_t *txt, const uint32_t *keys, uint32_t *out) -{ - const uint8_t *ptr; - unsigned i, j; - uint32_t val; - - ptr = txt; - for (i=0; i<4; i++) - { - /* FIXME: Use the READ_UINT32 or LE_READ_UINT32 macro. */ - val = 0; - for (j=0; j<4; j++) - val |= (*ptr++ << 8*j); - out[i] = keys[i]^val; - } -} - -static void -key_addition32(const uint32_t *txt, const uint32_t *keys, uint32_t *out) -{ - unsigned i; - - for (i=0; i<4; i++) - out[i] = keys[i] ^ txt[i]; -} - -static void -key_addition32to8(const uint32_t *txt, const uint32_t *keys, uint8_t *out) -{ - uint8_t *ptr; - unsigned i, j; - uint32_t val; - - ptr = out; - for (i=0; i<4; i++) - { - /* FIXME: Use WRITE_UINT32 or LE_WRITE_UINT32 */ - val = txt[i] ^ keys[i]; - for (j=0; j<4; j++) - *ptr++ = (val >> 8*j) & 0xff; - } -} - -static const unsigned idx[4][4] = { - { 0, 1, 2, 3 }, - { 1, 2, 3, 0 }, - { 2, 3, 0, 1 }, - { 3, 0, 1, 2 } }; - -void -aes_encrypt(struct aes_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - unsigned r, j; - uint32_t wtxt[4], t[4]; /* working ciphertext */ - uint32_t e; - - assert(!(length % AES_BLOCK_SIZE)); - - for (; length; - length -= AES_BLOCK_SIZE, src += AES_BLOCK_SIZE, dst += AES_BLOCK_SIZE) - { - key_addition_8to32(src, ctx->keys, wtxt); - for (r=1; rnrounds; r++) - { - for (j=0; j<4; j++) - { - t[j] = dtbl[wtxt[j] & 0xff] ^ - ROTRBYTE(dtbl[(wtxt[idx[1][j]] >> 8) & 0xff]^ - ROTRBYTE(dtbl[(wtxt[idx[2][j]] >> 16) & 0xff] ^ - ROTRBYTE(dtbl[(wtxt[idx[3][j]] >> 24) & 0xff]))); - } - key_addition32(t, ctx->keys + r*4, wtxt); - } - - /* last round is special: there is no mixcolumn, so we can't use the big - tables. */ - for (j=0; j<4; j++) - { - e = wtxt[j] & 0xff; - e |= (wtxt[idx[1][j]]) & (0xff << 8); - e |= (wtxt[idx[2][j]]) & (0xff << 16); - e |= (wtxt[idx[3][j]]) & (0xff << 24); - t[j] = e; - } - for (j=0; j<4; j++) - t[j] = SUBBYTE(t[j], sbox); - - key_addition32to8(t, ctx->keys + 4*ctx->nrounds, dst); - } -} - -static const unsigned iidx[4][4] = { - { 0, 1, 2, 3 }, - { 3, 0, 1, 2 }, - { 2, 3, 0, 1 }, - { 1, 2, 3, 0 } }; - -void -aes_decrypt(struct aes_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - unsigned r, j; - uint32_t wtxt[4], t[4]; /* working ciphertext */ - uint32_t e; - - assert(!(length % AES_BLOCK_SIZE)); - - for (; length; - length -= AES_BLOCK_SIZE, src += AES_BLOCK_SIZE, dst += AES_BLOCK_SIZE) - { - key_addition_8to32(src, ctx->ikeys + 4*ctx->nrounds, wtxt); - for (r=ctx->nrounds-1; r> 0; r--) - { - for (j=0; j<4; j++) - { - t[j] = itbl[wtxt[j] & 0xff] ^ - ROTRBYTE(itbl[(wtxt[iidx[1][j]] >> 8) & 0xff]^ - ROTRBYTE(itbl[(wtxt[iidx[2][j]] >> 16) & 0xff] ^ - ROTRBYTE(itbl[(wtxt[iidx[3][j]] >> 24) & 0xff]))); - } - key_addition32(t, ctx->ikeys + r*4, wtxt); - } - /* last round is special: there is no mixcolumn, so we can't use the big - tables. */ - for (j=0; j<4; j++) - { - e = wtxt[j] & 0xff; - e |= (wtxt[iidx[1][j]]) & (0xff << 8); - e |= (wtxt[iidx[2][j]]) & (0xff << 16); - e |= (wtxt[iidx[3][j]]) & (0xff << 24); - t[j] = e; - } - for (j=0; j<4; j++) - t[j] = SUBBYTE(t[j], isbox); - - key_addition32to8(t, ctx->ikeys, dst); - } -} diff --git a/lsh/src/nettle/aes.h b/lsh/src/nettle/aes.h deleted file mode 100644 index 398ac7e..0000000 --- a/lsh/src/nettle/aes.h +++ /dev/null @@ -1,60 +0,0 @@ -/* aes.h - * - * The aes/rijndael block cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_AES_H_INCLUDED -#define NETTLE_AES_H_INCLUDED - -#include - -#define AES_BLOCK_SIZE 16 - -/* Variable key size between 128 and 256 bits. But the only valid - * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */ -#define AES_MIN_KEY_SIZE 16 -#define AES_MAX_KEY_SIZE 32 - -#define AES_KEY_SIZE 32 - -struct aes_ctx -{ - uint32_t keys[60]; /* maximum size of key schedule */ - uint32_t ikeys[60]; /* inverse key schedule */ - unsigned nrounds; /* number of rounds to use for our key size */ -}; - -void -aes_set_key(struct aes_ctx *ctx, - unsigned length, const uint8_t *key); - -void -aes_encrypt(struct aes_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); -void -aes_decrypt(struct aes_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -#endif /* NETTLE_AES_H_INCLUDED */ diff --git a/lsh/src/nettle/arcfour.c b/lsh/src/nettle/arcfour.c deleted file mode 100644 index 70d0fd3..0000000 --- a/lsh/src/nettle/arcfour.c +++ /dev/null @@ -1,90 +0,0 @@ -/* arcfour.c - * - * The arcfour/rc4 stream cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#include "arcfour.h" - -#include - -#define SWAP(a,b) do { int _t = a; a = b; b = _t; } while(0) - -void -arcfour_set_key(struct arcfour_ctx *ctx, - unsigned length, const uint8_t *key) -{ - unsigned i, j, k; - - assert(length >= ARCFOUR_MIN_KEY_SIZE); - assert(length <= ARCFOUR_MAX_KEY_SIZE); - - /* Initialize context */ - for (i = 0; i<256; i++) - ctx->S[i] = i; - - for (i = j = k = 0; i<256; i++) - { - j += ctx->S[i] + key[k]; j &= 0xff; - SWAP(ctx->S[i], ctx->S[j]); - /* Repeat key as needed */ - k = (k + 1) % length; - } - ctx->i = ctx->j = 0; -} - - -void -arcfour_crypt(struct arcfour_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - register uint8_t i, j; - - i = ctx->i; j = ctx->j; - while(length--) - { - i++; i &= 0xff; - j += ctx->S[i]; j &= 0xff; - SWAP(ctx->S[i], ctx->S[j]); - *dst++ = *src++ ^ ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ]; - } - ctx->i = i; ctx->j = j; -} - -void -arcfour_stream(struct arcfour_ctx *ctx, - unsigned length, uint8_t *dst) -{ - register uint8_t i, j; - - i = ctx->i; j = ctx->j; - while(length--) - { - i++; i &= 0xff; - j += ctx->S[i]; j &= 0xff; - SWAP(ctx->S[i], ctx->S[j]); - *dst++ = ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ]; - } - ctx->i = i; ctx->j = j; -} - diff --git a/lsh/src/nettle/arcfour.h b/lsh/src/nettle/arcfour.h deleted file mode 100644 index 54aee47..0000000 --- a/lsh/src/nettle/arcfour.h +++ /dev/null @@ -1,58 +0,0 @@ -/* arcfour.h - * - * The arcfour/rc4 stream cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_ARCFOUR_H_INCLUDED -#define NETTLE_ARCFOUR_H_INCLUDED - -#include - -/* Minimum and maximum keysizes, and a reasonable default. In - * octets.*/ -#define ARCFOUR_MIN_KEY_SIZE 1 -#define ARCFOUR_MAX_KEY_SIZE 256 -#define ARCFOUR_KEY_SIZE 16 - -struct arcfour_ctx -{ - uint8_t S[256]; - uint8_t i; - uint8_t j; -}; - -void -arcfour_set_key(struct arcfour_ctx *ctx, - unsigned length, const uint8_t *key); - -void -arcfour_crypt(struct arcfour_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -void -arcfour_stream(struct arcfour_ctx *ctx, - unsigned length, uint8_t *dst); - -#endif /* NETTLE_ARCFOUR_H_INCLUDED */ - diff --git a/lsh/src/nettle/blowfish.c b/lsh/src/nettle/blowfish.c deleted file mode 100644 index 1a82797..0000000 --- a/lsh/src/nettle/blowfish.c +++ /dev/null @@ -1,421 +0,0 @@ -/* blowfish.c - * - * The blowfish block cipher. - * - * For a description of the algorithm, see: - * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. - * ISBN 0-471-11709-9. Pages 336 ff. - */ - -/* NOTE: This file is distributed under the GPL, not the LGPL. */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 1998, 2001 - * Free Software Foundation, Inc, Ray Dassen, Niels Möller - * - * This file is part of GNUPG. - * - * GNUPG 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. - * - * GNUPG 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 should 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 - */ - -#include "blowfish.h" - -#include "macros.h" - -#include - -/* Initial keysetup state */ -static const struct blowfish_ctx -initial_ctx = -{ /* precomputed S boxes */ - { - { - 0xD1310BA6,0x98DFB5AC,0x2FFD72DB,0xD01ADFB7,0xB8E1AFED,0x6A267E96, - 0xBA7C9045,0xF12C7F99,0x24A19947,0xB3916CF7,0x0801F2E2,0x858EFC16, - 0x636920D8,0x71574E69,0xA458FEA3,0xF4933D7E,0x0D95748F,0x728EB658, - 0x718BCD58,0x82154AEE,0x7B54A41D,0xC25A59B5,0x9C30D539,0x2AF26013, - 0xC5D1B023,0x286085F0,0xCA417918,0xB8DB38EF,0x8E79DCB0,0x603A180E, - 0x6C9E0E8B,0xB01E8A3E,0xD71577C1,0xBD314B27,0x78AF2FDA,0x55605C60, - 0xE65525F3,0xAA55AB94,0x57489862,0x63E81440,0x55CA396A,0x2AAB10B6, - 0xB4CC5C34,0x1141E8CE,0xA15486AF,0x7C72E993,0xB3EE1411,0x636FBC2A, - 0x2BA9C55D,0x741831F6,0xCE5C3E16,0x9B87931E,0xAFD6BA33,0x6C24CF5C, - 0x7A325381,0x28958677,0x3B8F4898,0x6B4BB9AF,0xC4BFE81B,0x66282193, - 0x61D809CC,0xFB21A991,0x487CAC60,0x5DEC8032,0xEF845D5D,0xE98575B1, - 0xDC262302,0xEB651B88,0x23893E81,0xD396ACC5,0x0F6D6FF3,0x83F44239, - 0x2E0B4482,0xA4842004,0x69C8F04A,0x9E1F9B5E,0x21C66842,0xF6E96C9A, - 0x670C9C61,0xABD388F0,0x6A51A0D2,0xD8542F68,0x960FA728,0xAB5133A3, - 0x6EEF0B6C,0x137A3BE4,0xBA3BF050,0x7EFB2A98,0xA1F1651D,0x39AF0176, - 0x66CA593E,0x82430E88,0x8CEE8619,0x456F9FB4,0x7D84A5C3,0x3B8B5EBE, - 0xE06F75D8,0x85C12073,0x401A449F,0x56C16AA6,0x4ED3AA62,0x363F7706, - 0x1BFEDF72,0x429B023D,0x37D0D724,0xD00A1248,0xDB0FEAD3,0x49F1C09B, - 0x075372C9,0x80991B7B,0x25D479D8,0xF6E8DEF7,0xE3FE501A,0xB6794C3B, - 0x976CE0BD,0x04C006BA,0xC1A94FB6,0x409F60C4,0x5E5C9EC2,0x196A2463, - 0x68FB6FAF,0x3E6C53B5,0x1339B2EB,0x3B52EC6F,0x6DFC511F,0x9B30952C, - 0xCC814544,0xAF5EBD09,0xBEE3D004,0xDE334AFD,0x660F2807,0x192E4BB3, - 0xC0CBA857,0x45C8740F,0xD20B5F39,0xB9D3FBDB,0x5579C0BD,0x1A60320A, - 0xD6A100C6,0x402C7279,0x679F25FE,0xFB1FA3CC,0x8EA5E9F8,0xDB3222F8, - 0x3C7516DF,0xFD616B15,0x2F501EC8,0xAD0552AB,0x323DB5FA,0xFD238760, - 0x53317B48,0x3E00DF82,0x9E5C57BB,0xCA6F8CA0,0x1A87562E,0xDF1769DB, - 0xD542A8F6,0x287EFFC3,0xAC6732C6,0x8C4F5573,0x695B27B0,0xBBCA58C8, - 0xE1FFA35D,0xB8F011A0,0x10FA3D98,0xFD2183B8,0x4AFCB56C,0x2DD1D35B, - 0x9A53E479,0xB6F84565,0xD28E49BC,0x4BFB9790,0xE1DDF2DA,0xA4CB7E33, - 0x62FB1341,0xCEE4C6E8,0xEF20CADA,0x36774C01,0xD07E9EFE,0x2BF11FB4, - 0x95DBDA4D,0xAE909198,0xEAAD8E71,0x6B93D5A0,0xD08ED1D0,0xAFC725E0, - 0x8E3C5B2F,0x8E7594B7,0x8FF6E2FB,0xF2122B64,0x8888B812,0x900DF01C, - 0x4FAD5EA0,0x688FC31C,0xD1CFF191,0xB3A8C1AD,0x2F2F2218,0xBE0E1777, - 0xEA752DFE,0x8B021FA1,0xE5A0CC0F,0xB56F74E8,0x18ACF3D6,0xCE89E299, - 0xB4A84FE0,0xFD13E0B7,0x7CC43B81,0xD2ADA8D9,0x165FA266,0x80957705, - 0x93CC7314,0x211A1477,0xE6AD2065,0x77B5FA86,0xC75442F5,0xFB9D35CF, - 0xEBCDAF0C,0x7B3E89A0,0xD6411BD3,0xAE1E7E49,0x00250E2D,0x2071B35E, - 0x226800BB,0x57B8E0AF,0x2464369B,0xF009B91E,0x5563911D,0x59DFA6AA, - 0x78C14389,0xD95A537F,0x207D5BA2,0x02E5B9C5,0x83260376,0x6295CFA9, - 0x11C81968,0x4E734A41,0xB3472DCA,0x7B14A94A,0x1B510052,0x9A532915, - 0xD60F573F,0xBC9BC6E4,0x2B60A476,0x81E67400,0x08BA6FB5,0x571BE91F, - 0xF296EC6B,0x2A0DD915,0xB6636521,0xE7B9F9B6,0xFF34052E,0xC5855664, - 0x53B02D5D,0xA99F8FA1,0x08BA4799,0x6E85076A - }, { - 0x4B7A70E9,0xB5B32944,0xDB75092E,0xC4192623,0xAD6EA6B0,0x49A7DF7D, - 0x9CEE60B8,0x8FEDB266,0xECAA8C71,0x699A17FF,0x5664526C,0xC2B19EE1, - 0x193602A5,0x75094C29,0xA0591340,0xE4183A3E,0x3F54989A,0x5B429D65, - 0x6B8FE4D6,0x99F73FD6,0xA1D29C07,0xEFE830F5,0x4D2D38E6,0xF0255DC1, - 0x4CDD2086,0x8470EB26,0x6382E9C6,0x021ECC5E,0x09686B3F,0x3EBAEFC9, - 0x3C971814,0x6B6A70A1,0x687F3584,0x52A0E286,0xB79C5305,0xAA500737, - 0x3E07841C,0x7FDEAE5C,0x8E7D44EC,0x5716F2B8,0xB03ADA37,0xF0500C0D, - 0xF01C1F04,0x0200B3FF,0xAE0CF51A,0x3CB574B2,0x25837A58,0xDC0921BD, - 0xD19113F9,0x7CA92FF6,0x94324773,0x22F54701,0x3AE5E581,0x37C2DADC, - 0xC8B57634,0x9AF3DDA7,0xA9446146,0x0FD0030E,0xECC8C73E,0xA4751E41, - 0xE238CD99,0x3BEA0E2F,0x3280BBA1,0x183EB331,0x4E548B38,0x4F6DB908, - 0x6F420D03,0xF60A04BF,0x2CB81290,0x24977C79,0x5679B072,0xBCAF89AF, - 0xDE9A771F,0xD9930810,0xB38BAE12,0xDCCF3F2E,0x5512721F,0x2E6B7124, - 0x501ADDE6,0x9F84CD87,0x7A584718,0x7408DA17,0xBC9F9ABC,0xE94B7D8C, - 0xEC7AEC3A,0xDB851DFA,0x63094366,0xC464C3D2,0xEF1C1847,0x3215D908, - 0xDD433B37,0x24C2BA16,0x12A14D43,0x2A65C451,0x50940002,0x133AE4DD, - 0x71DFF89E,0x10314E55,0x81AC77D6,0x5F11199B,0x043556F1,0xD7A3C76B, - 0x3C11183B,0x5924A509,0xF28FE6ED,0x97F1FBFA,0x9EBABF2C,0x1E153C6E, - 0x86E34570,0xEAE96FB1,0x860E5E0A,0x5A3E2AB3,0x771FE71C,0x4E3D06FA, - 0x2965DCB9,0x99E71D0F,0x803E89D6,0x5266C825,0x2E4CC978,0x9C10B36A, - 0xC6150EBA,0x94E2EA78,0xA5FC3C53,0x1E0A2DF4,0xF2F74EA7,0x361D2B3D, - 0x1939260F,0x19C27960,0x5223A708,0xF71312B6,0xEBADFE6E,0xEAC31F66, - 0xE3BC4595,0xA67BC883,0xB17F37D1,0x018CFF28,0xC332DDEF,0xBE6C5AA5, - 0x65582185,0x68AB9802,0xEECEA50F,0xDB2F953B,0x2AEF7DAD,0x5B6E2F84, - 0x1521B628,0x29076170,0xECDD4775,0x619F1510,0x13CCA830,0xEB61BD96, - 0x0334FE1E,0xAA0363CF,0xB5735C90,0x4C70A239,0xD59E9E0B,0xCBAADE14, - 0xEECC86BC,0x60622CA7,0x9CAB5CAB,0xB2F3846E,0x648B1EAF,0x19BDF0CA, - 0xA02369B9,0x655ABB50,0x40685A32,0x3C2AB4B3,0x319EE9D5,0xC021B8F7, - 0x9B540B19,0x875FA099,0x95F7997E,0x623D7DA8,0xF837889A,0x97E32D77, - 0x11ED935F,0x16681281,0x0E358829,0xC7E61FD6,0x96DEDFA1,0x7858BA99, - 0x57F584A5,0x1B227263,0x9B83C3FF,0x1AC24696,0xCDB30AEB,0x532E3054, - 0x8FD948E4,0x6DBC3128,0x58EBF2EF,0x34C6FFEA,0xFE28ED61,0xEE7C3C73, - 0x5D4A14D9,0xE864B7E3,0x42105D14,0x203E13E0,0x45EEE2B6,0xA3AAABEA, - 0xDB6C4F15,0xFACB4FD0,0xC742F442,0xEF6ABBB5,0x654F3B1D,0x41CD2105, - 0xD81E799E,0x86854DC7,0xE44B476A,0x3D816250,0xCF62A1F2,0x5B8D2646, - 0xFC8883A0,0xC1C7B6A3,0x7F1524C3,0x69CB7492,0x47848A0B,0x5692B285, - 0x095BBF00,0xAD19489D,0x1462B174,0x23820E00,0x58428D2A,0x0C55F5EA, - 0x1DADF43E,0x233F7061,0x3372F092,0x8D937E41,0xD65FECF1,0x6C223BDB, - 0x7CDE3759,0xCBEE7460,0x4085F2A7,0xCE77326E,0xA6078084,0x19F8509E, - 0xE8EFD855,0x61D99735,0xA969A7AA,0xC50C06C2,0x5A04ABFC,0x800BCADC, - 0x9E447A2E,0xC3453484,0xFDD56705,0x0E1E9EC9,0xDB73DBD3,0x105588CD, - 0x675FDA79,0xE3674340,0xC5C43465,0x713E38D8,0x3D28F89E,0xF16DFF20, - 0x153E21E7,0x8FB03D4A,0xE6E39F2B,0xDB83ADF7 - }, { - 0xE93D5A68,0x948140F7,0xF64C261C,0x94692934,0x411520F7,0x7602D4F7, - 0xBCF46B2E,0xD4A20068,0xD4082471,0x3320F46A,0x43B7D4B7,0x500061AF, - 0x1E39F62E,0x97244546,0x14214F74,0xBF8B8840,0x4D95FC1D,0x96B591AF, - 0x70F4DDD3,0x66A02F45,0xBFBC09EC,0x03BD9785,0x7FAC6DD0,0x31CB8504, - 0x96EB27B3,0x55FD3941,0xDA2547E6,0xABCA0A9A,0x28507825,0x530429F4, - 0x0A2C86DA,0xE9B66DFB,0x68DC1462,0xD7486900,0x680EC0A4,0x27A18DEE, - 0x4F3FFEA2,0xE887AD8C,0xB58CE006,0x7AF4D6B6,0xAACE1E7C,0xD3375FEC, - 0xCE78A399,0x406B2A42,0x20FE9E35,0xD9F385B9,0xEE39D7AB,0x3B124E8B, - 0x1DC9FAF7,0x4B6D1856,0x26A36631,0xEAE397B2,0x3A6EFA74,0xDD5B4332, - 0x6841E7F7,0xCA7820FB,0xFB0AF54E,0xD8FEB397,0x454056AC,0xBA489527, - 0x55533A3A,0x20838D87,0xFE6BA9B7,0xD096954B,0x55A867BC,0xA1159A58, - 0xCCA92963,0x99E1DB33,0xA62A4A56,0x3F3125F9,0x5EF47E1C,0x9029317C, - 0xFDF8E802,0x04272F70,0x80BB155C,0x05282CE3,0x95C11548,0xE4C66D22, - 0x48C1133F,0xC70F86DC,0x07F9C9EE,0x41041F0F,0x404779A4,0x5D886E17, - 0x325F51EB,0xD59BC0D1,0xF2BCC18F,0x41113564,0x257B7834,0x602A9C60, - 0xDFF8E8A3,0x1F636C1B,0x0E12B4C2,0x02E1329E,0xAF664FD1,0xCAD18115, - 0x6B2395E0,0x333E92E1,0x3B240B62,0xEEBEB922,0x85B2A20E,0xE6BA0D99, - 0xDE720C8C,0x2DA2F728,0xD0127845,0x95B794FD,0x647D0862,0xE7CCF5F0, - 0x5449A36F,0x877D48FA,0xC39DFD27,0xF33E8D1E,0x0A476341,0x992EFF74, - 0x3A6F6EAB,0xF4F8FD37,0xA812DC60,0xA1EBDDF8,0x991BE14C,0xDB6E6B0D, - 0xC67B5510,0x6D672C37,0x2765D43B,0xDCD0E804,0xF1290DC7,0xCC00FFA3, - 0xB5390F92,0x690FED0B,0x667B9FFB,0xCEDB7D9C,0xA091CF0B,0xD9155EA3, - 0xBB132F88,0x515BAD24,0x7B9479BF,0x763BD6EB,0x37392EB3,0xCC115979, - 0x8026E297,0xF42E312D,0x6842ADA7,0xC66A2B3B,0x12754CCC,0x782EF11C, - 0x6A124237,0xB79251E7,0x06A1BBE6,0x4BFB6350,0x1A6B1018,0x11CAEDFA, - 0x3D25BDD8,0xE2E1C3C9,0x44421659,0x0A121386,0xD90CEC6E,0xD5ABEA2A, - 0x64AF674E,0xDA86A85F,0xBEBFE988,0x64E4C3FE,0x9DBC8057,0xF0F7C086, - 0x60787BF8,0x6003604D,0xD1FD8346,0xF6381FB0,0x7745AE04,0xD736FCCC, - 0x83426B33,0xF01EAB71,0xB0804187,0x3C005E5F,0x77A057BE,0xBDE8AE24, - 0x55464299,0xBF582E61,0x4E58F48F,0xF2DDFDA2,0xF474EF38,0x8789BDC2, - 0x5366F9C3,0xC8B38E74,0xB475F255,0x46FCD9B9,0x7AEB2661,0x8B1DDF84, - 0x846A0E79,0x915F95E2,0x466E598E,0x20B45770,0x8CD55591,0xC902DE4C, - 0xB90BACE1,0xBB8205D0,0x11A86248,0x7574A99E,0xB77F19B6,0xE0A9DC09, - 0x662D09A1,0xC4324633,0xE85A1F02,0x09F0BE8C,0x4A99A025,0x1D6EFE10, - 0x1AB93D1D,0x0BA5A4DF,0xA186F20F,0x2868F169,0xDCB7DA83,0x573906FE, - 0xA1E2CE9B,0x4FCD7F52,0x50115E01,0xA70683FA,0xA002B5C4,0x0DE6D027, - 0x9AF88C27,0x773F8641,0xC3604C06,0x61A806B5,0xF0177A28,0xC0F586E0, - 0x006058AA,0x30DC7D62,0x11E69ED7,0x2338EA63,0x53C2DD94,0xC2C21634, - 0xBBCBEE56,0x90BCB6DE,0xEBFC7DA1,0xCE591D76,0x6F05E409,0x4B7C0188, - 0x39720A3D,0x7C927C24,0x86E3725F,0x724D9DB9,0x1AC15BB4,0xD39EB8FC, - 0xED545578,0x08FCA5B5,0xD83D7CD3,0x4DAD0FC4,0x1E50EF5E,0xB161E6F8, - 0xA28514D9,0x6C51133C,0x6FD5C7E7,0x56E14EC4,0x362ABFCE,0xDDC6C837, - 0xD79A3234,0x92638212,0x670EFA8E,0x406000E0 - }, { - 0x3A39CE37,0xD3FAF5CF,0xABC27737,0x5AC52D1B,0x5CB0679E,0x4FA33742, - 0xD3822740,0x99BC9BBE,0xD5118E9D,0xBF0F7315,0xD62D1C7E,0xC700C47B, - 0xB78C1B6B,0x21A19045,0xB26EB1BE,0x6A366EB4,0x5748AB2F,0xBC946E79, - 0xC6A376D2,0x6549C2C8,0x530FF8EE,0x468DDE7D,0xD5730A1D,0x4CD04DC6, - 0x2939BBDB,0xA9BA4650,0xAC9526E8,0xBE5EE304,0xA1FAD5F0,0x6A2D519A, - 0x63EF8CE2,0x9A86EE22,0xC089C2B8,0x43242EF6,0xA51E03AA,0x9CF2D0A4, - 0x83C061BA,0x9BE96A4D,0x8FE51550,0xBA645BD6,0x2826A2F9,0xA73A3AE1, - 0x4BA99586,0xEF5562E9,0xC72FEFD3,0xF752F7DA,0x3F046F69,0x77FA0A59, - 0x80E4A915,0x87B08601,0x9B09E6AD,0x3B3EE593,0xE990FD5A,0x9E34D797, - 0x2CF0B7D9,0x022B8B51,0x96D5AC3A,0x017DA67D,0xD1CF3ED6,0x7C7D2D28, - 0x1F9F25CF,0xADF2B89B,0x5AD6B472,0x5A88F54C,0xE029AC71,0xE019A5E6, - 0x47B0ACFD,0xED93FA9B,0xE8D3C48D,0x283B57CC,0xF8D56629,0x79132E28, - 0x785F0191,0xED756055,0xF7960E44,0xE3D35E8C,0x15056DD4,0x88F46DBA, - 0x03A16125,0x0564F0BD,0xC3EB9E15,0x3C9057A2,0x97271AEC,0xA93A072A, - 0x1B3F6D9B,0x1E6321F5,0xF59C66FB,0x26DCF319,0x7533D928,0xB155FDF5, - 0x03563482,0x8ABA3CBB,0x28517711,0xC20AD9F8,0xABCC5167,0xCCAD925F, - 0x4DE81751,0x3830DC8E,0x379D5862,0x9320F991,0xEA7A90C2,0xFB3E7BCE, - 0x5121CE64,0x774FBE32,0xA8B6E37E,0xC3293D46,0x48DE5369,0x6413E680, - 0xA2AE0810,0xDD6DB224,0x69852DFD,0x09072166,0xB39A460A,0x6445C0DD, - 0x586CDECF,0x1C20C8AE,0x5BBEF7DD,0x1B588D40,0xCCD2017F,0x6BB4E3BB, - 0xDDA26A7E,0x3A59FF45,0x3E350A44,0xBCB4CDD5,0x72EACEA8,0xFA6484BB, - 0x8D6612AE,0xBF3C6F47,0xD29BE463,0x542F5D9E,0xAEC2771B,0xF64E6370, - 0x740E0D8D,0xE75B1357,0xF8721671,0xAF537D5D,0x4040CB08,0x4EB4E2CC, - 0x34D2466A,0x0115AF84,0xE1B00428,0x95983A1D,0x06B89FB4,0xCE6EA048, - 0x6F3F3B82,0x3520AB82,0x011A1D4B,0x277227F8,0x611560B1,0xE7933FDC, - 0xBB3A792B,0x344525BD,0xA08839E1,0x51CE794B,0x2F32C9B7,0xA01FBAC9, - 0xE01CC87E,0xBCC7D1F6,0xCF0111C3,0xA1E8AAC7,0x1A908749,0xD44FBD9A, - 0xD0DADECB,0xD50ADA38,0x0339C32A,0xC6913667,0x8DF9317C,0xE0B12B4F, - 0xF79E59B7,0x43F5BB3A,0xF2D519FF,0x27D9459C,0xBF97222C,0x15E6FC2A, - 0x0F91FC71,0x9B941525,0xFAE59361,0xCEB69CEB,0xC2A86459,0x12BAA8D1, - 0xB6C1075E,0xE3056A0C,0x10D25065,0xCB03A442,0xE0EC6E0E,0x1698DB3B, - 0x4C98A0BE,0x3278E964,0x9F1F9532,0xE0D392DF,0xD3A0342B,0x8971F21E, - 0x1B0A7441,0x4BA3348C,0xC5BE7120,0xC37632D8,0xDF359F8D,0x9B992F2E, - 0xE60B6F47,0x0FE3F11D,0xE54CDA54,0x1EDAD891,0xCE6279CF,0xCD3E7E6F, - 0x1618B166,0xFD2C1D05,0x848FD2C5,0xF6FB2299,0xF523F357,0xA6327623, - 0x93A83531,0x56CCCD02,0xACF08162,0x5A75EBB5,0x6E163697,0x88D273CC, - 0xDE966292,0x81B949D0,0x4C50901B,0x71C65614,0xE6C6C7BD,0x327A140A, - 0x45E1D006,0xC3F27B9A,0xC9AA53FD,0x62A80F00,0xBB25BFE2,0x35BDD2F6, - 0x71126905,0xB2040222,0xB6CBCF7C,0xCD769C2B,0x53113EC0,0x1640E3D3, - 0x38ABBD60,0x2547ADF0,0xBA38209C,0xF746CE76,0x77AFA1C5,0x20756060, - 0x85CBFE4E,0x8AE88DD8,0x7AAAF9B0,0x4CF9AA7E,0x1948C25C,0x02FB8A8C, - 0x01C36AE4,0xD6EBE1F9,0x90D4F869,0xA65CDEA0,0x3F09252D,0xC208E69F, - 0xB74E6132,0xCE77E25B,0x578FDFE3,0x3AC372E6 - } - }, - /* p constants */ - { - 0x243F6A88,0x85A308D3,0x13198A2E,0x03707344,0xA4093822,0x299F31D0, - 0x082EFA98,0xEC4E6C89,0x452821E6,0x38D01377,0xBE5466CF,0x34E90C6C, - 0xC0AC29B7,0xC97C50DD,0x3F84D5B5,0xB5470917,0x9216D5D9,0x8979FB1B - }, - /* Initial value, reset after key is checked. */ - BLOWFISH_WEAK_KEY -}; - -/* It's unfortunate to have to pick the bytes apart in the round - * function. Werner's GNUPG code stored took the address of x, and - * then read the individual bytes depending on the endianness. But xr - * and xl ought to live in registers, so I'm not sure that really is a - * good way to do it. */ - -#define F(c, x) \ - ((( (c->s[0][(x>>24) &0xff] + c->s[1][(x>>16) & 0xff]) \ - ^ c->s[2][(x>>8) & 0xff]) + c->s[3][x & 0xff]) & 0xffffffff) - -#define R(c, l, r, i) do { l ^= c->p[i]; r ^= F(c, l); } while(0) - -static void -bf_encrypt(struct blowfish_ctx *bc, uint32_t *ret_xl, uint32_t *ret_xr) -{ - uint32_t xl, xr; - - xl = *ret_xl; - xr = *ret_xr; - R(bc, xl, xr, 0); - R(bc, xr, xl, 1); - R(bc, xl, xr, 2); - R(bc, xr, xl, 3); - R(bc, xl, xr, 4); - R(bc, xr, xl, 5); - R(bc, xl, xr, 6); - R(bc, xr, xl, 7); - R(bc, xl, xr, 8); - R(bc, xr, xl, 9); - R(bc, xl, xr, 10); - R(bc, xr, xl, 11); - R(bc, xl, xr, 12); - R(bc, xr, xl, 13); - R(bc, xl, xr, 14); - R(bc, xr, xl, 15); - - xl ^= bc->p[_BLOWFISH_ROUNDS]; - xr ^= bc->p[_BLOWFISH_ROUNDS+1]; - - *ret_xl = xr; - *ret_xr = xl; -} - -static void -decrypt(struct blowfish_ctx *bc, uint32_t *ret_xl, uint32_t *ret_xr ) -{ - uint32_t xl, xr; - - xl = *ret_xl; - xr = *ret_xr; - - R(bc, xl, xr, 17); - R(bc, xr, xl, 16); - R(bc, xl, xr, 15); - R(bc, xr, xl, 14); - R(bc, xl, xr, 13); - R(bc, xr, xl, 12); - R(bc, xl, xr, 11); - R(bc, xr, xl, 10); - R(bc, xl, xr, 9); - R(bc, xr, xl, 8); - R(bc, xl, xr, 7); - R(bc, xr, xl, 6); - R(bc, xl, xr, 5); - R(bc, xr, xl, 4); - R(bc, xl, xr, 3); - R(bc, xr, xl, 2); - - xl ^= bc->p[1]; - xr ^= bc->p[0]; - - *ret_xl = xr; - *ret_xr = xl; -} - -#undef F -#undef R - -void -blowfish_encrypt(struct blowfish_ctx *bc, unsigned length, - uint8_t *outbuf, const uint8_t *inbuf) -{ - uint32_t d1, d2; - - assert(!bc->status); - - FOR_BLOCKS(length, outbuf, inbuf, BLOWFISH_BLOCK_SIZE) - { - d1 = READ_UINT32(inbuf); - d2 = READ_UINT32(inbuf+ 4); - - bf_encrypt( bc, &d1, &d2 ); - - WRITE_UINT32(outbuf, d1); - WRITE_UINT32(outbuf + 4, d2); - } -} - - -void -blowfish_decrypt(struct blowfish_ctx *bc, unsigned length, - uint8_t *outbuf, const uint8_t *inbuf ) -{ - uint32_t d1, d2; - - assert(!bc->status); - - FOR_BLOCKS(length, outbuf, inbuf, BLOWFISH_BLOCK_SIZE) - { - d1 = READ_UINT32(inbuf); - d2 = READ_UINT32(inbuf+ 4); - - decrypt( bc, &d1, &d2 ); - - WRITE_UINT32(outbuf, d1); - WRITE_UINT32(outbuf + 4, d2); - } -} - -int -blowfish_set_key(struct blowfish_ctx *ctx, - unsigned keylen, const uint8_t *key) -{ - int i, j; - uint32_t data, datal, datar; - -#if 0 - static int initialized = 0; - - if( !initialized ) { - initialized = 1; - assert(selftest()); - } -#endif - - *ctx = initial_ctx; - - for(i=j=0; i < _BLOWFISH_ROUNDS+2; i++ ) - { - data = key[j] << 24 | key[(j+1) % keylen] <<16 - | key[(j+2)%keylen] << 8 | key[(j+3)%keylen]; - - ctx->p[i] ^= data; - j = (j+4) % keylen; - } - - datal = datar = 0; - for(i=0; i < _BLOWFISH_ROUNDS+2; i += 2 ) - { - bf_encrypt( ctx, &datal, &datar ); - ctx->p[i] = datal; - ctx->p[i+1] = datar; - } - for(i=0; i < 256; i += 2 ) - { - bf_encrypt( ctx, &datal, &datar ); - ctx->s[0][i] = datal; - ctx->s[0][i+1] = datar; - } - for(i=0; i < 256; i += 2 ) - { - bf_encrypt( ctx, &datal, &datar ); - ctx->s[1][i] = datal; - ctx->s[1][i+1] = datar; - } - for(i=0; i < 256; i += 2 ) - { - bf_encrypt( ctx, &datal, &datar ); - ctx->s[2][i] = datal; - ctx->s[2][i+1] = datar; - } - for(i=0; i < 256; i += 2 ) - { - bf_encrypt( ctx, &datal, &datar ); - ctx->s[3][i] = datal; - ctx->s[3][i+1] = datar; - } - - /* Check for weak key. A weak key is a key in which a value in */ - /* the P-array (here c) occurs more than once per table. */ - for(i=0; i < 255; i++ ) - for( j=i+1; j < 256; j++) - if( (ctx->s[0][i] == ctx->s[0][j]) || (ctx->s[1][i] == ctx->s[1][j]) || - (ctx->s[2][i] == ctx->s[2][j]) || (ctx->s[3][i] == ctx->s[3][j]) ) - return 0; - - ctx->status = BLOWFISH_OK; - return 1; -} diff --git a/lsh/src/nettle/blowfish.h b/lsh/src/nettle/blowfish.h deleted file mode 100644 index 72934da..0000000 --- a/lsh/src/nettle/blowfish.h +++ /dev/null @@ -1,66 +0,0 @@ -/* blowfish.h - * - * Blowfish block cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_BLOWFISH_H_INCLUDED -#define NETTLE_BLOWFISH_H_INCLUDED - -#include - -#define BLOWFISH_BLOCK_SIZE 8 - -/* Variable key size between 64 and 448 bits. */ -#define BLOWFISH_MIN_KEY_SIZE 8 -#define BLOWFISH_MAX_KEY_SIZE 56 - -/* Default to 128 bits */ -#define BLOWFISH_KEY_SIZE 16 - -#define _BLOWFISH_ROUNDS 16 - -enum blowfish_error { BLOWFISH_OK, BLOWFISH_WEAK_KEY }; - -struct blowfish_ctx -{ - uint32_t s[4][256]; - uint32_t p[_BLOWFISH_ROUNDS+2]; - enum blowfish_error status; -}; - -/* On success, returns 1 and sets ctx->status to BLOWFISH_OK (zero). - * On error, returns 0 and sets ctx->status to BLOWFISH_WEAK_KEY. */ -int -blowfish_set_key(struct blowfish_ctx *ctx, - unsigned length, const uint8_t *key); - -void -blowfish_encrypt(struct blowfish_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); -void -blowfish_decrypt(struct blowfish_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -#endif /* NETTLE_BLOWFISH_H_INCLUDED */ diff --git a/lsh/src/nettle/cast128.c b/lsh/src/nettle/cast128.c deleted file mode 100644 index a2b04d7..0000000 --- a/lsh/src/nettle/cast128.c +++ /dev/null @@ -1,270 +0,0 @@ -/* cast128.c - * - * The CAST-128 block cipher. - */ - -/* CAST-128 in C - * Written by Steve Reid - * 100% Public Domain - no warranty - * Released 1997.10.11 - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#include "cast128.h" -#include "cast128_sboxes.h" - -#include "macros.h" - -#include - -#define CAST_SMALL_KEY 10 -#define CAST_SMALL_ROUNDS 12 -#define CAST_FULL_ROUNDS 16 - -/* Macros to access 8-bit bytes out of a 32-bit word */ -#define U8a(x) ( (uint8_t) (x>>24) ) -#define U8b(x) ( (uint8_t) ((x>>16)&0xff) ) -#define U8c(x) ( (uint8_t) ((x>>8)&0xff) ) -#define U8d(x) ( (uint8_t) ((x)&0xff) ) - -/* Circular left shift */ -#define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) ) - -/* CAST-128 uses three different round functions */ -#define F1(l, r, i) \ - t = ROL(ctx->keys[i] + r, ctx->keys[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) \ - - cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)]; -#define F2(l, r, i) \ - t = ROL(ctx->keys[i] ^ r, ctx->keys[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) \ - + cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)]; -#define F3(l, r, i) \ - t = ROL(ctx->keys[i] - r, ctx->keys[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) \ - ^ cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)]; - - -/***** Encryption Function *****/ - -void -cast128_encrypt(struct cast128_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - FOR_BLOCKS(length, dst, src, CAST128_BLOCK_SIZE) - { - uint32_t t, l, r; - - /* Get inblock into l,r */ - l = READ_UINT32(src); - r = READ_UINT32(src+4); - - /* Do the work */ - F1(l, r, 0); - F2(r, l, 1); - F3(l, r, 2); - F1(r, l, 3); - F2(l, r, 4); - F3(r, l, 5); - F1(l, r, 6); - F2(r, l, 7); - F3(l, r, 8); - F1(r, l, 9); - F2(l, r, 10); - F3(r, l, 11); - /* Only do full 16 rounds if key length > 80 bits */ - if (ctx->rounds > 12) { - F1(l, r, 12); - F2(r, l, 13); - F3(l, r, 14); - F1(r, l, 15); - } - /* Put l,r into outblock */ - WRITE_UINT32(dst, r); - WRITE_UINT32(dst + 4, l); - /* Wipe clean */ - t = l = r = 0; - } -} - - -/***** Decryption Function *****/ - -void -cast128_decrypt(struct cast128_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - FOR_BLOCKS(length, dst, src, CAST128_BLOCK_SIZE) - { - uint32_t t, l, r; - - /* Get inblock into l,r */ - r = READ_UINT32(src); - l = READ_UINT32(src+4); - - /* Do the work */ - /* Only do full 16 rounds if key length > 80 bits */ - if (ctx->rounds > 12) { - F1(r, l, 15); - F3(l, r, 14); - F2(r, l, 13); - F1(l, r, 12); - } - F3(r, l, 11); - F2(l, r, 10); - F1(r, l, 9); - F3(l, r, 8); - F2(r, l, 7); - F1(l, r, 6); - F3(r, l, 5); - F2(l, r, 4); - F1(r, l, 3); - F3(l, r, 2); - F2(r, l, 1); - F1(l, r, 0); - - /* Put l,r into outblock */ - WRITE_UINT32(dst, l); - WRITE_UINT32(dst + 4, r); - - /* Wipe clean */ - t = l = r = 0; - } -} - -/***** Key Schedule *****/ - -void -cast128_set_key(struct cast128_ctx *ctx, - unsigned keybytes, const uint8_t *rawkey) -{ - uint32_t t[4], z[4], x[4]; - unsigned i; - - /* Set number of rounds to 12 or 16, depending on key length */ - ctx->rounds = (keybytes <= CAST_SMALL_KEY) - ? CAST_SMALL_ROUNDS : CAST_FULL_ROUNDS; - - /* Copy key to workspace x */ - for (i = 0; i < 4; i++) { - x[i] = 0; - if ((i*4+0) < keybytes) x[i] = (uint32_t)rawkey[i*4+0] << 24; - if ((i*4+1) < keybytes) x[i] |= (uint32_t)rawkey[i*4+1] << 16; - if ((i*4+2) < keybytes) x[i] |= (uint32_t)rawkey[i*4+2] << 8; - if ((i*4+3) < keybytes) x[i] |= (uint32_t)rawkey[i*4+3]; - } - /* Generate 32 subkeys, four at a time */ - for (i = 0; i < 32; i+=4) { - switch (i & 4) { - case 0: - t[0] = z[0] = x[0] ^ cast_sbox5[U8b(x[3])] - ^ cast_sbox6[U8d(x[3])] ^ cast_sbox7[U8a(x[3])] - ^ cast_sbox8[U8c(x[3])] ^ cast_sbox7[U8a(x[2])]; - t[1] = z[1] = x[2] ^ cast_sbox5[U8a(z[0])] - ^ cast_sbox6[U8c(z[0])] ^ cast_sbox7[U8b(z[0])] - ^ cast_sbox8[U8d(z[0])] ^ cast_sbox8[U8c(x[2])]; - t[2] = z[2] = x[3] ^ cast_sbox5[U8d(z[1])] - ^ cast_sbox6[U8c(z[1])] ^ cast_sbox7[U8b(z[1])] - ^ cast_sbox8[U8a(z[1])] ^ cast_sbox5[U8b(x[2])]; - t[3] = z[3] = x[1] ^ cast_sbox5[U8c(z[2])] ^ - cast_sbox6[U8b(z[2])] ^ cast_sbox7[U8d(z[2])] - ^ cast_sbox8[U8a(z[2])] ^ cast_sbox6[U8d(x[2])]; - break; - case 4: - t[0] = x[0] = z[2] ^ cast_sbox5[U8b(z[1])] - ^ cast_sbox6[U8d(z[1])] ^ cast_sbox7[U8a(z[1])] - ^ cast_sbox8[U8c(z[1])] ^ cast_sbox7[U8a(z[0])]; - t[1] = x[1] = z[0] ^ cast_sbox5[U8a(x[0])] - ^ cast_sbox6[U8c(x[0])] ^ cast_sbox7[U8b(x[0])] - ^ cast_sbox8[U8d(x[0])] ^ cast_sbox8[U8c(z[0])]; - t[2] = x[2] = z[1] ^ cast_sbox5[U8d(x[1])] - ^ cast_sbox6[U8c(x[1])] ^ cast_sbox7[U8b(x[1])] - ^ cast_sbox8[U8a(x[1])] ^ cast_sbox5[U8b(z[0])]; - t[3] = x[3] = z[3] ^ cast_sbox5[U8c(x[2])] - ^ cast_sbox6[U8b(x[2])] ^ cast_sbox7[U8d(x[2])] - ^ cast_sbox8[U8a(x[2])] ^ cast_sbox6[U8d(z[0])]; - break; - } - switch (i & 12) { - case 0: - case 12: - ctx->keys[i+0] = cast_sbox5[U8a(t[2])] ^ cast_sbox6[U8b(t[2])] - ^ cast_sbox7[U8d(t[1])] ^ cast_sbox8[U8c(t[1])]; - ctx->keys[i+1] = cast_sbox5[U8c(t[2])] ^ cast_sbox6[U8d(t[2])] - ^ cast_sbox7[U8b(t[1])] ^ cast_sbox8[U8a(t[1])]; - ctx->keys[i+2] = cast_sbox5[U8a(t[3])] ^ cast_sbox6[U8b(t[3])] - ^ cast_sbox7[U8d(t[0])] ^ cast_sbox8[U8c(t[0])]; - ctx->keys[i+3] = cast_sbox5[U8c(t[3])] ^ cast_sbox6[U8d(t[3])] - ^ cast_sbox7[U8b(t[0])] ^ cast_sbox8[U8a(t[0])]; - break; - case 4: - case 8: - ctx->keys[i+0] = cast_sbox5[U8d(t[0])] ^ cast_sbox6[U8c(t[0])] - ^ cast_sbox7[U8a(t[3])] ^ cast_sbox8[U8b(t[3])]; - ctx->keys[i+1] = cast_sbox5[U8b(t[0])] ^ cast_sbox6[U8a(t[0])] - ^ cast_sbox7[U8c(t[3])] ^ cast_sbox8[U8d(t[3])]; - ctx->keys[i+2] = cast_sbox5[U8d(t[1])] ^ cast_sbox6[U8c(t[1])] - ^ cast_sbox7[U8a(t[2])] ^ cast_sbox8[U8b(t[2])]; - ctx->keys[i+3] = cast_sbox5[U8b(t[1])] ^ cast_sbox6[U8a(t[1])] - ^ cast_sbox7[U8c(t[2])] ^ cast_sbox8[U8d(t[2])]; - break; - } - switch (i & 12) { - case 0: - ctx->keys[i+0] ^= cast_sbox5[U8c(z[0])]; - ctx->keys[i+1] ^= cast_sbox6[U8c(z[1])]; - ctx->keys[i+2] ^= cast_sbox7[U8b(z[2])]; - ctx->keys[i+3] ^= cast_sbox8[U8a(z[3])]; - break; - case 4: - ctx->keys[i+0] ^= cast_sbox5[U8a(x[2])]; - ctx->keys[i+1] ^= cast_sbox6[U8b(x[3])]; - ctx->keys[i+2] ^= cast_sbox7[U8d(x[0])]; - ctx->keys[i+3] ^= cast_sbox8[U8d(x[1])]; - break; - case 8: - ctx->keys[i+0] ^= cast_sbox5[U8b(z[2])]; - ctx->keys[i+1] ^= cast_sbox6[U8a(z[3])]; - ctx->keys[i+2] ^= cast_sbox7[U8c(z[0])]; - ctx->keys[i+3] ^= cast_sbox8[U8c(z[1])]; - break; - case 12: - ctx->keys[i+0] ^= cast_sbox5[U8d(x[0])]; - ctx->keys[i+1] ^= cast_sbox6[U8d(x[1])]; - ctx->keys[i+2] ^= cast_sbox7[U8a(x[2])]; - ctx->keys[i+3] ^= cast_sbox8[U8b(x[3])]; - break; - } - if (i >= 16) { - ctx->keys[i+0] &= 31; - ctx->keys[i+1] &= 31; - ctx->keys[i+2] &= 31; - ctx->keys[i+3] &= 31; - } - } - /* Wipe clean */ - for (i = 0; i < 4; i++) { - t[i] = x[i] = z[i] = 0; - } -} diff --git a/lsh/src/nettle/cast128.h b/lsh/src/nettle/cast128.h deleted file mode 100644 index 0d1e044..0000000 --- a/lsh/src/nettle/cast128.h +++ /dev/null @@ -1,64 +0,0 @@ -/* cast128.h - * - * The CAST-128 block cipher. - */ - -/* CAST-128 in C - * Written by Steve Reid - * 100% Public Domain - no warranty - * Released 1997.10.11 - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_CAST128_H_INCLUDED -#define NETTLE_CAST128_H_INCLUDED - -#include - -#define CAST128_BLOCK_SIZE 8 - -/* Variable key size between 40 and 128. */ -#define CAST128_MIN_KEY_SIZE 5 -#define CAST128_MAX_KEY_SIZE 16 - -#define CAST128_KEY_SIZE 16 - -struct cast128_ctx -{ - uint32_t keys[32]; /* Key, after expansion */ - unsigned rounds; /* Number of rounds to use, 12 or 16 */ -}; - -void -cast128_set_key(struct cast128_ctx *ctx, - unsigned length, const uint8_t *key); - -void -cast128_encrypt(struct cast128_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); -void -cast128_decrypt(struct cast128_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -#endif /* NETTLE_CAST128_H_INCLUDED */ diff --git a/lsh/src/nettle/cast128_sboxes.h b/lsh/src/nettle/cast128_sboxes.h deleted file mode 100644 index afc299a..0000000 --- a/lsh/src/nettle/cast128_sboxes.h +++ /dev/null @@ -1,545 +0,0 @@ -/* - * $Id$ - * - * CAST-128 in C - * Written by Steve Reid - * 100% Public Domain - no warranty - * Released 1997.10.11 - */ - -static const uint32_t cast_sbox1[256] = { - 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, - 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, - 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, - 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, - 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, - 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, - 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, - 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, - 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, - 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, - 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, - 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, - 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, - 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, - 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, - 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, - 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, - 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, - 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, - 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, - 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, - 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, - 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, - 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, - 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, - 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, - 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, - 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, - 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, - 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, - 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, - 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, - 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, - 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, - 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, - 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, - 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, - 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, - 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, - 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, - 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, - 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, - 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, - 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, - 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, - 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, - 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, - 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, - 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, - 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, - 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, - 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, - 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, - 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, - 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, - 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, - 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, - 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, - 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, - 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, - 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, - 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, - 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, - 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF -}; - -static const uint32_t cast_sbox2[256] = { - 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, - 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, - 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, - 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, - 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, - 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, - 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, - 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, - 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, - 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, - 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, - 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, - 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, - 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, - 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, - 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, - 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, - 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, - 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, - 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, - 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, - 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, - 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, - 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, - 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, - 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, - 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, - 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, - 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, - 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, - 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, - 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, - 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, - 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, - 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, - 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, - 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, - 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, - 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, - 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, - 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, - 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, - 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, - 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, - 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, - 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, - 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, - 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, - 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, - 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, - 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, - 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, - 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, - 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, - 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, - 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, - 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, - 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, - 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, - 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, - 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, - 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, - 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, - 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 -}; - -static const uint32_t cast_sbox3[256] = { - 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, - 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, - 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, - 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, - 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, - 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, - 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, - 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, - 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, - 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, - 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, - 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, - 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, - 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, - 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, - 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, - 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, - 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, - 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, - 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, - 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, - 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, - 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, - 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, - 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, - 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, - 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, - 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, - 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, - 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, - 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, - 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, - 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, - 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, - 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, - 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, - 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, - 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, - 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, - 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, - 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, - 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, - 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, - 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, - 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, - 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, - 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, - 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, - 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, - 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, - 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, - 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, - 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, - 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, - 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, - 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, - 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, - 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, - 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, - 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, - 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, - 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, - 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, - 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 -}; - -static const uint32_t cast_sbox4[256] = { - 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, - 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, - 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, - 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, - 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, - 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, - 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, - 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, - 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, - 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, - 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, - 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, - 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, - 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, - 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, - 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, - 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, - 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, - 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, - 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, - 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, - 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, - 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, - 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, - 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, - 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, - 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, - 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, - 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, - 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, - 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, - 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, - 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, - 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, - 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, - 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, - 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, - 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, - 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, - 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, - 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, - 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, - 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, - 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, - 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, - 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, - 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, - 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, - 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, - 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, - 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, - 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, - 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, - 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, - 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, - 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, - 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, - 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, - 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, - 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, - 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, - 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, - 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, - 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 -}; - -static const uint32_t cast_sbox5[256] = { - 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, - 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F, - 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00, - 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, - 0xE6A2E77F, 0xF0C720CD, 0xC4494816, 0xCCF5C180, - 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF, - 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2, - 0x4E40B48D, 0x248EB6FB, 0x8DBA1CFE, 0x41A99B02, - 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725, - 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A, - 0xF2F3F763, 0x68AF8040, 0xED0C9E56, 0x11B4958B, - 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7, - 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571, - 0x0C05372A, 0x578535F2, 0x2261BE02, 0xD642A0C9, - 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC, - 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981, - 0x5C1FF900, 0xFE38D399, 0x0C4EFF0B, 0x062407EA, - 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774, - 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263, - 0xDF65001F, 0x0EC50966, 0xDFDD55BC, 0x29DE0655, - 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468, - 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2, - 0xBCF3F0AA, 0x87AC36E9, 0xE53A7426, 0x01B3D82B, - 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910, - 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284, - 0x636737B6, 0x50F5B616, 0xF24766E3, 0x8ECA36C1, - 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4, - 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA, - 0x26E46695, 0xB7566419, 0xF654EFC5, 0xD08D58B7, - 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049, - 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE, - 0xC62BF3CD, 0x9E0885F9, 0x68CB3E47, 0x086C010F, - 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6, - 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA, - 0x0AB378D5, 0xD951FB0C, 0xDED7DA56, 0x4124BBE4, - 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE, - 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561, - 0xC3DC0280, 0x05687715, 0x646C6BD7, 0x44904DB3, - 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6, - 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840, - 0x76F0AE02, 0x083BE84D, 0x28421C9A, 0x44489406, - 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4, - 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472, - 0x3CA5D717, 0x7D161BBA, 0x9CAD9010, 0xAF462BA2, - 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487, - 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7, - 0x445F7382, 0x175683F4, 0xCDC66A97, 0x70BE0288, - 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5, - 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2, - 0x1C5C1572, 0xF6721B2C, 0x1AD2FFF3, 0x8C25404E, - 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78, - 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E, - 0x44094F85, 0x3F481D87, 0xFCFEAE7B, 0x77B5FF76, - 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801, - 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0, - 0xDF3B0874, 0x95055110, 0x1B5AD7A8, 0xF61ED5AD, - 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58, - 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0, - 0x5CE96C28, 0xE176EDA3, 0x6BAC307F, 0x376829D2, - 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20, - 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE, - 0xF9E0659A, 0xEEB9491D, 0x34010718, 0xBB30CAB8, - 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55, - 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 -}; - -static const uint32_t cast_sbox6[256] = { - 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, - 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC, - 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9, - 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, - 0x33F14961, 0xC01937BD, 0xF506C6DA, 0xE4625E7E, - 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367, - 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866, - 0xA084DB2D, 0x09A8486F, 0xA888614A, 0x2900AF98, - 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C, - 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072, - 0xFD41197E, 0x9305A6B0, 0xE86BE3DA, 0x74BED3CD, - 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3, - 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53, - 0x5C3D9C01, 0x64BDB941, 0x2C0E636A, 0xBA7DD9CD, - 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D, - 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8, - 0x284CAF89, 0xAA928223, 0x9334BE53, 0x3B3A21BF, - 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9, - 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807, - 0x5B7C5ECC, 0x221DB3A6, 0x9A69A02F, 0x68818A54, - 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A, - 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387, - 0x53BDDB65, 0xE76FFBE7, 0xE967FD78, 0x0BA93563, - 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC, - 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0, - 0xE81F994F, 0x9528CD89, 0xFD339FED, 0xB87834BF, - 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE, - 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF, - 0x4EC75B95, 0x24F2C3C0, 0x42D15D99, 0xCD0D7FA0, - 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F, - 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2, - 0x372B74AF, 0x692573E4, 0xE9A9D848, 0xF3160289, - 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853, - 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950, - 0x36F73523, 0x4CFB6E87, 0x7DA4CEC0, 0x6C152DAA, - 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F, - 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9, - 0x2B05D08D, 0x48B9D585, 0xDC049441, 0xC8098F9B, - 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751, - 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE, - 0xBF32679D, 0xD45B5B75, 0xB353FD00, 0xCBB0E358, - 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13, - 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397, - 0x47CF8E7A, 0xB6C85283, 0x3CC2ACFB, 0x3FC06976, - 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459, - 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0, - 0x3007CD3E, 0x74719EEF, 0xDC872681, 0x073340D4, - 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891, - 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F, - 0x6FE4AC98, 0xB173ECC0, 0xBC60B42A, 0x953498DA, - 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB, - 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC, - 0xE8816F4A, 0x3814F200, 0xA3F94043, 0x9C7A54C2, - 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084, - 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB, - 0xBA5AC7B5, 0xB6F6DEAF, 0x3A479C3A, 0x5302DA25, - 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B, - 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121, - 0xB81A928A, 0x60ED5869, 0x97C55B96, 0xEAEC991B, - 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5, - 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855, - 0xD36B4CF1, 0xF544EDEB, 0xB0E93524, 0xBEBB8FBD, - 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454, - 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F -}; - -static const uint32_t cast_sbox7[256] = { - 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, - 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F, - 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82, - 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, - 0xA05FBCF6, 0xCD4181E9, 0xE150210C, 0xE24EF1BD, - 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43, - 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F, - 0x089766BE, 0xBAEEADF4, 0x1286BECF, 0xB6EACB19, - 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9, - 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2, - 0x107789BE, 0xB3B2E9CE, 0x0502AA8F, 0x0BC0351E, - 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516, - 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83, - 0x334266CE, 0x8C9341B7, 0xD0D854C0, 0xCB3A6C88, - 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E, - 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816, - 0x0A961288, 0xE1A5C06E, 0x13749E67, 0x72FC081A, - 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756, - 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F, - 0xBC8EC511, 0x38BC46E9, 0xC6E6FA14, 0xBAE8584A, - 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B, - 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264, - 0x92544A8B, 0x009B4FC3, 0xABA68CED, 0x9AC96F78, - 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688, - 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D, - 0xF7DEBB85, 0x61FE033C, 0x16746233, 0x3C034C28, - 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802, - 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3, - 0x0C4FB99A, 0xBB325778, 0x3EC6D97B, 0x6E77A6A9, - 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7, - 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302, - 0xB96D8C32, 0xEBD4E7BE, 0xBE8B9D2D, 0x7979FB06, - 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858, - 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033, - 0xF28EBFB0, 0xF5B9C310, 0xA0EAC280, 0x08B9767A, - 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A, - 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4, - 0x826D2BEF, 0x4EEB8476, 0x488DCF25, 0x36C9D566, - 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF, - 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509, - 0xF22B017D, 0xA4173F70, 0xDD1E16C3, 0x15E0D7F9, - 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962, - 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C, - 0x93D29A22, 0xE32DBF9A, 0x058745B9, 0x3453DC1E, - 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07, - 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C, - 0x66626C1C, 0x7154C24C, 0xEA082B2A, 0x93EB2939, - 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C, - 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E, - 0xD3A0C108, 0xA1E7160E, 0xE4F2DFA6, 0x693ED285, - 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378, - 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301, - 0xC79F022F, 0x3C997E7E, 0x5E4F9504, 0x3FFAFBBD, - 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE, - 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567, - 0x5592A33D, 0xB5229301, 0xCFD2A87F, 0x60AEB767, - 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2, - 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647, - 0x97FD61A9, 0xEA7759F4, 0x2D57539D, 0x569A58CF, - 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914, - 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2, - 0x3FFA50BC, 0x3D40F021, 0xC3C0BDAE, 0x4958C24C, - 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA, - 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 -}; - -static const uint32_t cast_sbox8[256] = { - 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, - 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5, - 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174, - 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, - 0xDE9ADEB1, 0x0A0CC32C, 0xBE197029, 0x84A00940, - 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD, - 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42, - 0xC7ECE831, 0x3F8F95E7, 0x72DF191B, 0x7580330D, - 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164, - 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2, - 0x12A8DDEC, 0xFDAA335D, 0x176F43E8, 0x71FB46D4, - 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862, - 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0, - 0x4CFDE06F, 0xC28EC4B8, 0x57E8726E, 0x647A78FC, - 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6, - 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C, - 0xBBD35049, 0x2998DF04, 0x980CF42A, 0x9B6DF491, - 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E, - 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B, - 0x3CF1D2E2, 0x19B47A38, 0x424F7618, 0x35856039, - 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8, - 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8, - 0x7170C608, 0x2D5E3354, 0xD4DE495A, 0x64C6D006, - 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42, - 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564, - 0xF8D7E54E, 0x3E378160, 0x7895CDA5, 0x859C15A5, - 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB, - 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472, - 0x835FFCB8, 0x6DF4C1F2, 0x96F5B195, 0xFD0AF0FC, - 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225, - 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8, - 0xC4618187, 0xEA7A6E98, 0x7CD16EFC, 0x1436876C, - 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441, - 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB, - 0xA842EEDF, 0xFDBA60B4, 0xF1907B75, 0x20E3030F, - 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054, - 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504, - 0xF1E47D8D, 0x844A1BE5, 0xBAE7DFDC, 0x42CBDA70, - 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C, - 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC, - 0x77853B53, 0x37EFFCB5, 0xC5068778, 0xE580B3E6, - 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C, - 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD, - 0xDD06CAA2, 0x37DF932B, 0xC4248289, 0xACF3EBC3, - 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4, - 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4, - 0xE87B40E4, 0xE98EA084, 0x5889E9E1, 0xEFD390FC, - 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101, - 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA, - 0x646F1282, 0x7523D24A, 0xE0779695, 0xF9C17A8F, - 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF, - 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E, - 0x11403092, 0x00DA6D77, 0x4A0CDD61, 0xAD1F4603, - 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A, - 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37, - 0x2DE705CA, 0x8951570F, 0xDF09822B, 0xBD691A6C, - 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819, - 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384, - 0x5938FA0F, 0x42399EF3, 0x36997B07, 0x0E84093D, - 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C, - 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347, - 0x589E8D82, 0x0D2059D1, 0xA466BB1E, 0xF8DA0A82, - 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D, - 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E -}; - diff --git a/lsh/src/nettle/config.h.in b/lsh/src/nettle/config.h.in deleted file mode 100644 index a92563a..0000000 --- a/lsh/src/nettle/config.h.in +++ /dev/null @@ -1,63 +0,0 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ - -/* Define if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define if you have the `memxor' function. */ -#undef HAVE_MEMXOR - -/* Define if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STRING_H - -/* Define if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Name of package */ -#undef PACKAGE - -/* The size of a `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of a `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of a `short', as computed by sizeof. */ -#undef SIZEOF_SHORT - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Version number of package */ -#undef VERSION - -/* Define if your processor stores words with the most significant byte first - (like Motorola and SPARC, unlike Intel and VAX). */ -#undef WORDS_BIGENDIAN - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define to `int' if doesn't define. */ -#undef gid_t - -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ -#undef inline - -/* Define to `unsigned' if does not define. */ -#undef size_t - -/* Define to `int' if doesn't define. */ -#undef uid_t diff --git a/lsh/src/nettle/configure b/lsh/src/nettle/configure deleted file mode 100644 index be00550..0000000 --- a/lsh/src/nettle/configure +++ /dev/null @@ -1,4648 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by Autoconf 2.50. -# -# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -# Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -exec 6>&1 - -# -# Initializations. -# -ac_default_prefix=/usr/local -cross_compiling=no -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - -# Avoid depending upon Character Ranges. -ac_cr_az='abcdefghijklmnopqrstuvwxyz' -ac_cr_AZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -ac_cr_09='0123456789' -ac_cr_alnum=$ac_cr_az$ac_cr_AZ$ac_cr_09 - -# Sed expression to map a string onto a valid sh and CPP variable names. -ac_tr_sh="sed y%*+%pp%;s%[^_$ac_cr_alnum]%_%g" -ac_tr_cpp="sed y%*$ac_cr_az%P$ac_cr_AZ%;s%[^_$ac_cr_alnum]%_%g" - -ac_unique_file="arcfour.c" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#include -#include -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#else -# if HAVE_STRINGS_H -# include -# endif -#endif -#if HAVE_INTTYPES_H -# include -#endif -#if HAVE_UNISTD_H -# include -#endif" - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Identity of this package. -PACKAGE_NAME= -PACKAGE_TARNAME= -PACKAGE_VERSION= -PACKAGE_STRING= -PACKAGE_BUGREPORT= - -ac_prev= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_option in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - eval "enable_$ac_feature=no" ;; - - -enable-* | --enable-*) - ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "enable_$ac_feature='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package| sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "with_$ac_package='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/-/_/g'` - eval "with_$ac_package=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` - eval "$ac_envvar='$ac_optarg'" - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$ac_cr_alnum]" >/dev/null && - echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -# Be sure to have absolute paths. -for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ - localstatedir libdir includedir oldincludedir infodir mandir \ - exec_prefix prefix -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* ) ;; - NONE ) ;; - *) { echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: should be removed in autoconf 3.0. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo "$ac_prog" | sed 's%[\\/][^\\/][^\\/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "$as_me: error: cannot find sources in $ac_confdir or .." >&2 - { (exit 1); exit 1; }; } - else - { echo "$as_me: error: cannot find sources in $srcdir" >&2 - { (exit 1); exit 1; }; } - fi -fi -srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` -ac_env_build_alias_set=${build_alias+set} -ac_env_build_alias_value=$build_alias -ac_cv_env_build_alias_set=${build_alias+set} -ac_cv_env_build_alias_value=$build_alias -ac_env_host_alias_set=${host_alias+set} -ac_env_host_alias_value=$host_alias -ac_cv_env_host_alias_set=${host_alias+set} -ac_cv_env_host_alias_value=$host_alias -ac_env_target_alias_set=${target_alias+set} -ac_env_target_alias_value=$target_alias -ac_cv_env_target_alias_set=${target_alias+set} -ac_cv_env_target_alias_value=$target_alias -ac_env_CC_set=${CC+set} -ac_env_CC_value=$CC -ac_cv_env_CC_set=${CC+set} -ac_cv_env_CC_value=$CC -ac_env_CFLAGS_set=${CFLAGS+set} -ac_env_CFLAGS_value=$CFLAGS -ac_cv_env_CFLAGS_set=${CFLAGS+set} -ac_cv_env_CFLAGS_value=$CFLAGS -ac_env_LDFLAGS_set=${LDFLAGS+set} -ac_env_LDFLAGS_value=$LDFLAGS -ac_cv_env_LDFLAGS_set=${LDFLAGS+set} -ac_cv_env_LDFLAGS_value=$LDFLAGS -ac_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_env_CPPFLAGS_value=$CPPFLAGS -ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat < if you have libraries in a - nonstandard directory - CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have - headers in a nonstandard directory - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -EOF -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - ac_popdir=`pwd` - for ac_subdir in : $ac_subdirs_all; do test "x$ac_subdir" = x: && continue - cd $ac_subdir - # A "../" for each directory in /$ac_subdir. - ac_dots=`echo $ac_subdir | - sed 's,^\./,,;s,[^/]$,&/,;s,[^/]*/,../,g'` - - case $srcdir in - .) # No --srcdir option. We are building in place. - ac_sub_srcdir=$srcdir ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_sub_srcdir=$srcdir/$ac_subdir ;; - *) # Relative path. - ac_sub_srcdir=$ac_dots$srcdir/$ac_subdir ;; - esac - - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_sub_srcdir/configure.gnu; then - echo - $SHELL $ac_sub_srcdir/configure.gnu --help=recursive - elif test -f $ac_sub_srcdir/configure; then - echo - $SHELL $ac_sub_srcdir/configure --help=recursive - elif test -f $ac_sub_srcdir/configure.ac || - test -f $ac_sub_srcdir/configure.in; then - echo - $ac_configure --help - else - echo "$as_me: WARNING: no configuration information is in $ac_subdir" >&2 - fi - cd $ac_popdir - done -fi - -test -n "$ac_init_help" && exit 0 -if $ac_init_version; then - cat <<\EOF - -Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -EOF - exit 0 -fi -exec 5>config.log -cat >&5 </dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -hostinfo = `(hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -PATH = $PATH - -_ASUNAME -} >&5 - -cat >&5 <\?\"\']*) - ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` - ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" - ac_sep=" " ;; - *) ac_configure_args="$ac_configure_args$ac_sep$ac_arg" - ac_sep=" " ;; - esac - # Get rid of the leading space. -done - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - echo >&5 - echo "## ----------------- ##" >&5 - echo "## Cache variables. ##" >&5 - echo "## ----------------- ##" >&5 - echo >&5 - # The following way of writing the cache mishandles newlines in values, -{ - (set) 2>&1 | - case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in - *ac_space=\ *) - sed -n \ - "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" - ;; - *) - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} >&5 - sed "/^$/d" confdefs.h >conftest.log - if test -s conftest.log; then - echo >&5 - echo "## ------------ ##" >&5 - echo "## confdefs.h. ##" >&5 - echo "## ------------ ##" >&5 - echo >&5 - cat conftest.log >&5 - fi - (echo; echo) >&5 - test "$ac_signal" != 0 && - echo "$as_me: caught signal $ac_signal" >&5 - echo "$as_me: exit $exit_status" >&5 - rm -rf conftest* confdefs* core core.* *.core conf$$* $ac_clean_files && - exit $exit_status - ' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_status=$?; ac_signal='$ac_signal'; { (exit $ac_status); exit $ac_status; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo >confdefs.h - -# Let the site file select an alternate cache file if it wants to. -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - { echo "$as_me:841: loading site script $ac_site_file" >&5 -echo "$as_me: loading site script $ac_site_file" >&6;} - cat "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { echo "$as_me:852: loading cache $cache_file" >&5 -echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . $cache_file;; - *) . ./$cache_file;; - esac - fi -else - { echo "$as_me:860: creating cache $cache_file" >&5 -echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_suggest_removing_cache=false -for ac_var in `(set) 2>&1 | - sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val="\$ac_cv_env_${ac_var}_value" - eval ac_new_val="\$ac_env_${ac_var}_value" - case $ac_old_set,$ac_new_set in - set,) - { echo "$as_me:876: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,set) - { echo "$as_me:880: WARNING: \`$ac_var' was not set in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was not set in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - { echo "$as_me:886: WARNING: \`$ac_var' has changed since the previous run:" >&5 -echo "$as_me: WARNING: \`$ac_var' has changed since the previous run:" >&2;} - { echo "$as_me:888: WARNING: former value: $ac_old_val" >&5 -echo "$as_me: WARNING: former value: $ac_old_val" >&2;} - { echo "$as_me:890: WARNING: current value: $ac_new_val" >&5 -echo "$as_me: WARNING: current value: $ac_new_val" >&2;} - ac_suggest_removing_cache=: - fi;; - esac -done -if $ac_suggest_removing_cache; then - { echo "$as_me:897: WARNING: changes in the environment can compromise the build" >&5 -echo "$as_me: WARNING: changes in the environment can compromise the build" >&2;} - { echo "$as_me:899: WARNING: consider removing $cache_file and starting over" >&5 -echo "$as_me: WARNING: consider removing $cache_file and starting over" >&2;} -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac -echo "#! $SHELL" >conftest.sh -echo "exit 0" >>conftest.sh -chmod +x conftest.sh -if { (echo "$as_me:918: PATH=\".;.\"; conftest.sh") >&5 - (PATH=".;."; conftest.sh) 2>&5 - ac_status=$? - echo "$as_me:921: \$? = $ac_status" >&5 - (exit $ac_status); }; then - ac_path_separator=';' -else - ac_path_separator=: -fi -PATH_SEPARATOR="$ac_path_separator" -rm -f conftest.sh - -ac_aux_dir= -for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do - if test -f $ac_dir/install-sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f $ac_dir/install.sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f $ac_dir/shtool; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - { { echo "$as_me:947: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 -echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} - { (exit 1); exit 1; }; } -fi -ac_config_guess="$SHELL $ac_aux_dir/config.guess" -ac_config_sub="$SHELL $ac_aux_dir/config.sub" -ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# ./install, which can be erroneously created by make from ./install.sh. -echo "$as_me:967: checking for a BSD compatible install" >&5 -echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6 -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_save_IFS=$IFS; IFS=$ac_path_separator - for ac_dir in $PATH; do - IFS=$ac_save_IFS - # Account for people who put trailing slashes in PATH elements. - case $ac_dir/ in - / | ./ | .// | /cC/* \ - | /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* \ - | /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - if $as_executable_p "$ac_dir/$ac_prog"; then - if test $ac_prog = install && - grep dspmsg "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - ac_cv_path_install="$ac_dir/$ac_prog -c" - break 2 - fi - fi - done - ;; - esac - done - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. We don't cache a - # path for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the path is relative. - INSTALL=$ac_install_sh - fi -fi -echo "$as_me:1016: result: $INSTALL" >&5 -echo "${ECHO_T}$INSTALL" >&6 - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -echo "$as_me:1027: checking whether build environment is sane" >&5 -echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6 -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "$*" != "X $srcdir/configure conftestfile" \ - && test "$*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - { { echo "$as_me:1050: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&5 -echo "$as_me: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&2;} - { (exit 1); exit 1; }; } - fi - - test "$2" = conftestfile - ) -then - # Ok. - : -else - { { echo "$as_me:1063: error: newly created file is older than distributed files! -Check your system clock" >&5 -echo "$as_me: error: newly created file is older than distributed files! -Check your system clock" >&2;} - { (exit 1); exit 1; }; } -fi -rm -f conftest* -echo "$as_me:1070: result: yes" >&5 -echo "${ECHO_T}yes" >&6 -if test "$program_transform_name" = s,x,x,; then - program_transform_name= -else - # Double any \ or $. echo might interpret backslashes. - cat <<\EOF >conftest.sed -s,\\,\\\\,g; s,\$,$$,g -EOF - program_transform_name=`echo $program_transform_name | sed -f conftest.sed` - rm -f conftest.sed -fi -test "$program_prefix" != NONE && - program_transform_name="s,^,${program_prefix},;$program_transform_name" -# Use a double $ so make ignores it. -test "$program_suffix" != NONE && - program_transform_name="s,\$\$,${program_suffix},;$program_transform_name" - -# sed with no file args requires a program. -test -z "$program_transform_name" && program_transform_name="s,x,x," - -echo "$as_me:1091: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1111: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1115: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -PACKAGE=libnettle - -VERSION=0.2 - -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - { { echo "$as_me:1125: error: source directory already configured; run \"make distclean\" there first" >&5 -echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;} - { (exit 1); exit 1; }; } -fi - -cat >>confdefs.h <>confdefs.h <&5 -echo $ECHO_N "checking for working aclocal... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (aclocal --version) < /dev/null > /dev/null 2>&1; then - ACLOCAL=aclocal - echo "$as_me:1146: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - ACLOCAL="$missing_dir/missing aclocal" - echo "$as_me:1150: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1154: checking for working autoconf" >&5 -echo $ECHO_N "checking for working autoconf... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoconf --version) < /dev/null > /dev/null 2>&1; then - AUTOCONF=autoconf - echo "$as_me:1161: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOCONF="$missing_dir/missing autoconf" - echo "$as_me:1165: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1169: checking for working automake" >&5 -echo $ECHO_N "checking for working automake... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (automake --version) < /dev/null > /dev/null 2>&1; then - AUTOMAKE=automake - echo "$as_me:1176: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOMAKE="$missing_dir/missing automake" - echo "$as_me:1180: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1184: checking for working autoheader" >&5 -echo $ECHO_N "checking for working autoheader... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoheader --version) < /dev/null > /dev/null 2>&1; then - AUTOHEADER=autoheader - echo "$as_me:1191: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOHEADER="$missing_dir/missing autoheader" - echo "$as_me:1195: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1199: checking for working makeinfo" >&5 -echo $ECHO_N "checking for working makeinfo... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (makeinfo --version) < /dev/null > /dev/null 2>&1; then - MAKEINFO=makeinfo - echo "$as_me:1206: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - MAKEINFO="$missing_dir/missing makeinfo" - echo "$as_me:1210: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -ac_config_headers="$ac_config_headers config.h" - -ac_config_commands="$ac_config_commands default-1" - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -echo "$as_me:1226: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}gcc" -echo "$as_me:1241: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1249: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1252: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo "$as_me:1261: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="gcc" -echo "$as_me:1276: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1284: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1287: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -echo "$as_me:1300: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}cc" -echo "$as_me:1315: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1323: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1326: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1335: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="cc" -echo "$as_me:1350: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1358: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1361: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1374: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue -fi -ac_cv_prog_CC="cc" -echo "$as_me:1394: found $ac_dir/$ac_word" >&5 -break -done - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - set dummy "$ac_dir/$ac_word" ${1+"$@"} - shift - ac_cv_prog_CC="$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1416: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1419: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:1430: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="$ac_tool_prefix$ac_prog" -echo "$as_me:1445: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1453: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1456: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:1469: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="$ac_prog" -echo "$as_me:1484: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1492: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1495: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CC" && break -done - - CC=$ac_ct_CC -fi - -fi - -test -z "$CC" && { { echo "$as_me:1507: error: no acceptable cc found in \$PATH" >&5 -echo "$as_me: error: no acceptable cc found in \$PATH" >&2;} - { (exit 1); exit 1; }; } - -cat >conftest.$ac_ext <<_ACEOF -#line 1512 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.exe" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compiler, and finding out an intuition -# of exeext. -echo "$as_me:1528: checking for C compiler default output" >&5 -echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6 -ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` -if { (eval echo "$as_me:1531: \"$ac_link_default\"") >&5 - (eval $ac_link_default) 2>&5 - ac_status=$? - echo "$as_me:1534: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `ls a.exe conftest.exe a.* conftest conftest.* 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - a.out ) # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1551: error: C compiler cannot create executables" >&5 -echo "$as_me: error: C compiler cannot create executables" >&2;} - { (exit 77); exit 77; }; } -fi - -ac_exeext=$ac_cv_exeext -echo "$as_me:1557: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6 - -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1562: checking whether the C compiler works" >&5 -echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (eval echo "$as_me:1568: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1571: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { echo "$as_me:1578: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&5 -echo "$as_me: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&2;} - { (exit 1); exit 1; }; } - fi - fi -fi -echo "$as_me:1586: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - -rm -f a.out a.exe conftest$ac_cv_exeext -ac_clean_files=$ac_clean_files_save -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1593: checking whether we are cross compiling" >&5 -echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 -echo "$as_me:1595: result: $cross_compiling" >&5 -echo "${ECHO_T}$cross_compiling" >&6 - -echo "$as_me:1598: checking for executable suffix" >&5 -echo $ECHO_N "checking for executable suffix... $ECHO_C" >&6 -if { (eval echo "$as_me:1600: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:1603: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in `(ls conftest.exe; ls conftest; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - { { echo "$as_me:1619: error: cannot compute EXEEXT: cannot compile and link" >&5 -echo "$as_me: error: cannot compute EXEEXT: cannot compile and link" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest$ac_cv_exeext -echo "$as_me:1625: result: $ac_cv_exeext" >&5 -echo "${ECHO_T}$ac_cv_exeext" >&6 - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -echo "$as_me:1631: checking for object suffix" >&5 -echo $ECHO_N "checking for object suffix... $ECHO_C" >&6 -if test "${ac_cv_objext+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1637 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (eval echo "$as_me:1649: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1652: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1664: error: cannot compute OBJEXT: cannot compile" >&5 -echo "$as_me: error: cannot compute OBJEXT: cannot compile" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -echo "$as_me:1671: result: $ac_cv_objext" >&5 -echo "${ECHO_T}$ac_cv_objext" >&6 -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -echo "$as_me:1675: checking whether we are using the GNU C compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 -if test "${ac_cv_c_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1681 "configure" -#include "confdefs.h" - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1696: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1699: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1702: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1705: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_compiler_gnu=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:1717: result: $ac_cv_c_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 -GCC=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" -echo "$as_me:1723: checking whether $CC accepts -g" >&5 -echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1729 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1741: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1744: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1747: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1750: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_g=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_prog_cc_g=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:1760: result: $ac_cv_prog_cc_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -# Some people use a C++ compiler to compile C. Since we use `exit', -# in C++ we need to declare it. In case someone uses the same compiler -# for both compiling C and C++ we need to have the C++ compiler decide -# the declaration of exit, since it's the most demanding environment. -cat >conftest.$ac_ext <<_ACEOF -#ifndef __cplusplus - choke me -#endif -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1787: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1790: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1793: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1796: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - for ac_declaration in \ - ''\ - '#include ' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -#line 1808 "configure" -#include "confdefs.h" -#include -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1821: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1824: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1827: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1830: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -continue -fi -rm -f conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -#line 1840 "configure" -#include "confdefs.h" -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1852: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1855: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1858: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1861: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -echo '#ifdef __cplusplus' >>confdefs.h -echo $ac_declaration >>confdefs.h -echo '#endif' >>confdefs.h - -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:1885: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1905: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1909: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -echo "$as_me:1917: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" -echo "$as_me:1932: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - echo "$as_me:1940: result: $RANLIB" >&5 -echo "${ECHO_T}$RANLIB" >&6 -else - echo "$as_me:1943: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -echo "$as_me:1952: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_RANLIB="ranlib" -echo "$as_me:1967: found $ac_dir/$ac_word" >&5 -break -done - - test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":" -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - echo "$as_me:1976: result: $ac_ct_RANLIB" >&5 -echo "${ECHO_T}$ac_ct_RANLIB" >&6 -else - echo "$as_me:1979: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - RANLIB=$ac_ct_RANLIB -else - RANLIB="$ac_cv_prog_RANLIB" -fi - -echo "$as_me:1988: checking for ${CC-cc} option to accept ANSI C" >&5 -echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6 -if test "${am_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - cat >conftest.$ac_ext <<_ACEOF -#line 2005 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; - -int -main () -{ - -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2047: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2050: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2053: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2056: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - am_cv_prog_cc_stdc="$ac_arg"; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -CC="$ac_save_CC" - -fi - -if test -z "$am_cv_prog_cc_stdc"; then - echo "$as_me:2070: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 -else - echo "$as_me:2073: result: $am_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$am_cv_prog_cc_stdc" >&6 -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac - -if test "x$am_cv_prog_cc_stdc" = xno ; then - { { echo "$as_me:2082: error: the C compiler doesn't handle ANSI-C" >&5 -echo "$as_me: error: the C compiler doesn't handle ANSI-C" >&2;} - { (exit 1); exit 1; }; } -fi - -# Extract the first word of "m4", so it can be a program name with args. -set dummy m4; ac_word=$2 -echo "$as_me:2089: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_path_M4+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - case $M4 in - [\\/]* | ?:[\\/]*) - ac_cv_path_M4="$M4" # Let the user override the test with a path. - ;; - *) - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - if $as_executable_p "$ac_dir/$ac_word"; then - ac_cv_path_M4="$ac_dir/$ac_word" - echo "$as_me:2106: found $ac_dir/$ac_word" >&5 - break -fi -done - - test -z "$ac_cv_path_M4" && ac_cv_path_M4="m4" - ;; -esac -fi -M4=$ac_cv_path_M4 - -if test -n "$M4"; then - echo "$as_me:2118: result: $M4" >&5 -echo "${ECHO_T}$M4" >&6 -else - echo "$as_me:2121: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -echo "$as_me:2125: checking for $CC option to accept ANSI C" >&5 -echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_prog_cc_stdc=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -#line 2133 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (eval echo "$as_me:2182: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2185: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2188: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2191: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_stdc=$ac_arg -break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext -done -rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC - -fi - -case "x$ac_cv_prog_cc_stdc" in - x|xno) - echo "$as_me:2208: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 ;; - *) - echo "$as_me:2211: result: $ac_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 - CC="$CC $ac_cv_prog_cc_stdc" ;; -esac - -echo "$as_me:2216: checking for an ANSI C-conforming const" >&5 -echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6 -if test "${ac_cv_c_const+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2222 "configure" -#include "confdefs.h" - -int -main () -{ -/* FIXME: Include the comments suggested by Paul. */ -#ifndef __cplusplus - /* Ultrix mips cc rejects this. */ - typedef int charset[2]; - const charset x; - /* SunOS 4.1.1 cc rejects this. */ - char const *const *ccp; - char **p; - /* NEC SVR4.0.2 mips cc rejects this. */ - struct point {int x, y;}; - static struct point const zero = {0,0}; - /* AIX XL C 1.02.0.0 rejects this. - It does not let you subtract one const X* pointer from another in - an arm of an if-expression whose if-part is not a constant - expression */ - const char *g = "string"; - ccp = &g + (g ? g-g : 0); - /* HPUX 7.0 cc rejects these. */ - ++ccp; - p = (char**) ccp; - ccp = (char const *const *) p; - { /* SCO 3.2v4 cc rejects this. */ - char *t; - char const *s = 0 ? (char *) 0 : (char const *) 0; - - *t++ = 0; - } - { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ - int x[] = {25, 17}; - const int *foo = &x[0]; - ++foo; - } - { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ - typedef const int *iptr; - iptr p = 0; - ++p; - } - { /* AIX XL C 1.02.0.0 rejects this saying - "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; }; - struct s *b; b->j = 5; - } - { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ - const int foo = 10; - } -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2280: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2283: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2286: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2289: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_const=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_const=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2299: result: $ac_cv_c_const" >&5 -echo "${ECHO_T}$ac_cv_c_const" >&6 -if test $ac_cv_c_const = no; then - -cat >>confdefs.h <<\EOF -#define const -EOF - -fi - -echo "$as_me:2309: checking for inline" >&5 -echo $ECHO_N "checking for inline... $ECHO_C" >&6 -if test "${ac_cv_c_inline+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_inline=no -for ac_kw in inline __inline__ __inline; do - cat >conftest.$ac_ext <<_ACEOF -#line 2317 "configure" -#include "confdefs.h" -#ifndef __cplusplus -static $ac_kw int static_foo () {return 0; } -$ac_kw int foo () {return 0; } -#endif - -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2326: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2329: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2332: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2335: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_inline=$ac_kw; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done - -fi -echo "$as_me:2346: result: $ac_cv_c_inline" >&5 -echo "${ECHO_T}$ac_cv_c_inline" >&6 -case $ac_cv_c_inline in - inline | yes) ;; - no) -cat >>confdefs.h <<\EOF -#define inline -EOF - ;; - *) cat >>confdefs.h <&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - # break 2 since there is a loop in there. - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2388 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2393: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2399: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2422 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2426: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2432: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break 2 -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:2469: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2479 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2484: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2490: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2513 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2517: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2523: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:2551: error: C preprocessor \"$CPP\" fails sanity check" >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:2562: checking for uid_t in sys/types.h" >&5 -echo $ECHO_N "checking for uid_t in sys/types.h... $ECHO_C" >&6 -if test "${ac_cv_type_uid_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2568 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "uid_t" >/dev/null 2>&1; then - ac_cv_type_uid_t=yes -else - ac_cv_type_uid_t=no -fi -rm -f conftest* - -fi -echo "$as_me:2582: result: $ac_cv_type_uid_t" >&5 -echo "${ECHO_T}$ac_cv_type_uid_t" >&6 -if test $ac_cv_type_uid_t = no; then - -cat >>confdefs.h <<\EOF -#define uid_t int -EOF - -cat >>confdefs.h <<\EOF -#define gid_t int -EOF - -fi - -echo "$as_me:2596: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2602 "configure" -#include "confdefs.h" -#include -#include -#include -#include - -_ACEOF -if { (eval echo "$as_me:2610: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2616: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_header_stdc=no -fi -rm -f conftest.err conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2638 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2656 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 2677 "configure" -#include "confdefs.h" -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:2703: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2706: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:2708: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2711: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_stdc=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -fi -echo "$as_me:2724: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\EOF -#define STDC_HEADERS 1 -EOF - -fi - -for ac_header in stdlib.h string.h memory.h strings.h inttypes.h unistd.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:2737: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2743 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:2747: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2753: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:2772: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for size_t... $ECHO_C" >&6 -if test "${ac_cv_type_size_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2788 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((size_t *) 0) - return 0; -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2803: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2806: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2809: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2812: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_size_t=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_size_t=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2822: result: $ac_cv_type_size_t" >&5 -echo "${ECHO_T}$ac_cv_type_size_t" >&6 -if test $ac_cv_type_size_t = yes; then - : -else - -cat >>confdefs.h <&5 -echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6 -if test "${ac_cv_header_time+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2840 "configure" -#include "confdefs.h" -#include -#include -#include - -int -main () -{ -struct tm *tp; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2855: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2858: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2861: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2864: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_time=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_time=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2874: result: $ac_cv_header_time" >&5 -echo "${ECHO_T}$ac_cv_header_time" >&6 -if test $ac_cv_header_time = yes; then - -cat >>confdefs.h <<\EOF -#define TIME_WITH_SYS_TIME 1 -EOF - -fi - -echo "$as_me:2884: checking whether byte ordering is bigendian" >&5 -echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6 -if test "${ac_cv_c_bigendian+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_bigendian=unknown -# See if sys/param.h defines the BYTE_ORDER macro. -cat >conftest.$ac_ext <<_ACEOF -#line 2892 "configure" -#include "confdefs.h" -#include -#include - -int -main () -{ -#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN - bogus endian macros -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2909: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2912: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2915: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2918: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - # It does; now see whether it defined to BIG_ENDIAN or not. -cat >conftest.$ac_ext <<_ACEOF -#line 2922 "configure" -#include "confdefs.h" -#include -#include - -int -main () -{ -#if BYTE_ORDER != BIG_ENDIAN - not big endian -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2939: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2942: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2945: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2948: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_bigendian=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -if test $ac_cv_c_bigendian = unknown; then -if test "$cross_compiling" = yes; then - { { echo "$as_me:2964: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 2969 "configure" -#include "confdefs.h" -int -main () -{ - /* Are we little or big endian? From Harbison&Steele. */ - union - { - long l; - char c[sizeof (long)]; - } u; - u.l = 1; - exit (u.c[sizeof (long) - 1] == 1); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:2985: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2988: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:2990: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2993: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=no -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_bigendian=yes -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -fi -echo "$as_me:3006: result: $ac_cv_c_bigendian" >&5 -echo "${ECHO_T}$ac_cv_c_bigendian" >&6 -if test $ac_cv_c_bigendian = yes; then - -cat >>confdefs.h <<\EOF -#define WORDS_BIGENDIAN 1 -EOF - -fi - -echo "$as_me:3016: checking for short" >&5 -echo $ECHO_N "checking for short... $ECHO_C" >&6 -if test "${ac_cv_type_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3022 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((short *) 0) - return 0; -if (sizeof (short)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3037: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3040: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3043: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3046: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_short=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_short=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3056: result: $ac_cv_type_short" >&5 -echo "${ECHO_T}$ac_cv_type_short" >&6 - -echo "$as_me:3059: checking size of short" >&5 -echo $ECHO_N "checking size of short... $ECHO_C" >&6 -if test "${ac_cv_sizeof_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_short" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 3068 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3080: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3083: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3086: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3089: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3094 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3106: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3109: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3112: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3115: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3131 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3143: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3146: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3149: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3152: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3168 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3180: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3183: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3186: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3189: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_short=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3202: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3207 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (short))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3223: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3226: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3228: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3231: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_short=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_short=0 -fi -fi -echo "$as_me:3247: result: $ac_cv_sizeof_short" >&5 -echo "${ECHO_T}$ac_cv_sizeof_short" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for int... $ECHO_C" >&6 -if test "${ac_cv_type_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3259 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((int *) 0) - return 0; -if (sizeof (int)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3274: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3277: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3280: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3283: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_int=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_int=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3293: result: $ac_cv_type_int" >&5 -echo "${ECHO_T}$ac_cv_type_int" >&6 - -echo "$as_me:3296: checking size of int" >&5 -echo $ECHO_N "checking size of int... $ECHO_C" >&6 -if test "${ac_cv_sizeof_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_int" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 3305 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3317: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3320: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3323: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3326: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3331 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3343: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3346: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3349: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3352: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3368 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3380: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3383: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3386: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3389: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3405 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3417: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3420: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3423: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3426: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_int=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3439: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3444 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (int))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3460: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3463: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3465: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3468: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_int=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_int=0 -fi -fi -echo "$as_me:3484: result: $ac_cv_sizeof_int" >&5 -echo "${ECHO_T}$ac_cv_sizeof_int" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for long... $ECHO_C" >&6 -if test "${ac_cv_type_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3496 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((long *) 0) - return 0; -if (sizeof (long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3511: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3514: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3517: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3520: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_long=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3530: result: $ac_cv_type_long" >&5 -echo "${ECHO_T}$ac_cv_type_long" >&6 - -echo "$as_me:3533: checking size of long" >&5 -echo $ECHO_N "checking size of long... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 3542 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3554: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3557: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3560: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3563: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3568 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3580: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3583: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3586: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3589: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3605 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3617: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3620: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3623: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3626: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3642 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3654: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3657: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3660: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3663: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_long=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3676: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3681 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (long))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3697: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3700: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3702: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3705: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long=0 -fi -fi -echo "$as_me:3721: result: $ac_cv_sizeof_long" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3736 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3767: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3770: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3773: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3776: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3786: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overriden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -{ - (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} | - sed ' - t clear - : clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - : end' >>confcache -if cmp -s $cache_file confcache; then :; else - if test -w $cache_file; then - test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" - cat confcache >$cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/; -s/:*\${srcdir}:*/:/; -s/:*@srcdir@:*/:/; -s/^\([^=]*=[ ]*\):*/\1/; -s/:*$//; -s/^[^=]*=[ ]*$//; -}' -fi - -DEFS=-DHAVE_CONFIG_H - -: ${CONFIG_STATUS=./config.status} -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ echo "$as_me:3890: creating $CONFIG_STATUS" >&5 -echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF -#! $SHELL -# Generated automatically by configure. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -SHELL=\${CONFIG_SHELL-$SHELL} -ac_cs_invocation="\$0 \$@" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -exec 6>&1 - -_ACEOF - -# Files that config.status was made for. -if test -n "$ac_config_files"; then - echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_headers"; then - echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_links"; then - echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_commands"; then - echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS -fi - -cat >>$CONFIG_STATUS <<\EOF - -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTIONS] [FILE]... - - -h, --help print this help, then exit - -V, --version print version number, then exit - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to ." -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -# If no file are specified by the user, then we need to provide default -# value. By we need to know if files were specified by the user. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "x$1" : 'x\([^=]*\)='` - ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` - shift - set dummy "$ac_option" "$ac_optarg" ${1+"$@"} - shift - ;; - -*);; - *) # This is not an option, so the user has probably given explicit - # arguments. - ac_need_defaults=false;; - esac - - case $1 in - # Handling of the options. -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF - --version | --vers* | -V ) - echo "$ac_cs_version"; exit 0 ;; - --he | --h) - # Conflict between --help and --header - { { echo "$as_me:4066: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - echo "$ac_cs_usage"; exit 0 ;; - --debug | --d* | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - shift - CONFIG_FILES="$CONFIG_FILES $1" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - shift - CONFIG_HEADERS="$CONFIG_HEADERS $1" - ac_need_defaults=false;; - - # Handling of arguments. - 'Makefile' ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; - 'testsuite/Makefile' ) CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;; - 'default-1' ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; - 'config.h' ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - - # This is an error. - -*) { { echo "$as_me:4091: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; } ;; - *) { { echo "$as_me:4096: error: invalid argument: $1" >&5 -echo "$as_me: error: invalid argument: $1" >&2;} - { (exit 1); exit 1; }; };; - esac - shift -done - -exec 5>>config.log -cat >&5 << _ACEOF - -## ----------------------- ## -## Running config.status. ## -## ----------------------- ## - -This file was extended by $as_me 2.50, executed with - > $ac_cs_invocation -on `(hostname || uname -n) 2>/dev/null | sed 1q` - -_ACEOF -EOF - -cat >>$CONFIG_STATUS <<\EOF -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Create a temporary directory, and hook for its removal unless debugging. -$debug || -{ - trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 - trap '{ (exit $?); exit $?; }' 1 2 13 15 -} - -# Create a (secure) tmp directory for tmp files. -: ${TMPDIR=/tmp} -{ - tmp=`(umask 077 && mktemp -d -q "$TMPDIR/csXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=$TMPDIR/cs$$-$RANDOM - (umask 077 && mkdir $tmp) -} || -{ - echo "$me: cannot create a temporary directory in $TMPDIR" >&2 - { (exit 1); exit 1; } -} - -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <\$tmp/subs.sed <<\\CEOF -s,@SHELL@,$SHELL,;t t -s,@exec_prefix@,$exec_prefix,;t t -s,@prefix@,$prefix,;t t -s,@program_transform_name@,$program_transform_name,;t t -s,@bindir@,$bindir,;t t -s,@sbindir@,$sbindir,;t t -s,@libexecdir@,$libexecdir,;t t -s,@datadir@,$datadir,;t t -s,@sysconfdir@,$sysconfdir,;t t -s,@sharedstatedir@,$sharedstatedir,;t t -s,@localstatedir@,$localstatedir,;t t -s,@libdir@,$libdir,;t t -s,@includedir@,$includedir,;t t -s,@oldincludedir@,$oldincludedir,;t t -s,@infodir@,$infodir,;t t -s,@mandir@,$mandir,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t -s,@ECHO_C@,$ECHO_C,;t t -s,@ECHO_N@,$ECHO_N,;t t -s,@ECHO_T@,$ECHO_T,;t t -s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t -s,@DEFS@,$DEFS,;t t -s,@LIBS@,$LIBS,;t t -s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t -s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t -s,@INSTALL_DATA@,$INSTALL_DATA,;t t -s,@PACKAGE@,$PACKAGE,;t t -s,@VERSION@,$VERSION,;t t -s,@ACLOCAL@,$ACLOCAL,;t t -s,@AUTOCONF@,$AUTOCONF,;t t -s,@AUTOMAKE@,$AUTOMAKE,;t t -s,@AUTOHEADER@,$AUTOHEADER,;t t -s,@MAKEINFO@,$MAKEINFO,;t t -s,@SET_MAKE@,$SET_MAKE,;t t -s,@CC@,$CC,;t t -s,@CFLAGS@,$CFLAGS,;t t -s,@LDFLAGS@,$LDFLAGS,;t t -s,@CPPFLAGS@,$CPPFLAGS,;t t -s,@ac_ct_CC@,$ac_ct_CC,;t t -s,@EXEEXT@,$EXEEXT,;t t -s,@OBJEXT@,$OBJEXT,;t t -s,@RANLIB@,$RANLIB,;t t -s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t -s,@M4@,$M4,;t t -s,@CPP@,$CPP,;t t -s,@LIBOBJS@,$LIBOBJS,;t t -CEOF - -EOF - - cat >>$CONFIG_STATUS <<\EOF - # Split the substitutions into bite-sized pieces for seds with - # small command number limits, like on Digital OSF/1 and HP-UX. - ac_max_sed_lines=48 - ac_sed_frag=1 # Number of current file. - ac_beg=1 # First line for current file. - ac_end=$ac_max_sed_lines # Line after last line for current file. - ac_more_lines=: - ac_sed_cmds= - while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - else - sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - fi - if test ! -s $tmp/subs.frag; then - ac_more_lines=false - else - # The purpose of the label and of the branching condition is to - # speed up the sed processing (if there are no `@' at all, there - # is no need to browse any of the substitutions). - # These are the two extra sed commands mentioned above. - (echo ':t - /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" - else - ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" - fi - ac_sed_frag=`expr $ac_sed_frag + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_lines` - fi - done - if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat - fi -fi # test -n "$CONFIG_FILES" - -EOF -cat >>$CONFIG_STATUS <<\EOF -for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - ac_dir_suffix="/`echo $ac_dir|sed 's,^\./,,'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo "$ac_dir_suffix" | sed 's,/[^/]*,../,g'` - else - ac_dir_suffix= ac_dots= - fi - - case $srcdir in - .) ac_srcdir=. - if test -z "$ac_dots"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_dots | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_dots$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_dots$srcdir ;; - esac - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_dots$INSTALL ;; - esac - - if test x"$ac_file" != x-; then - { echo "$as_me:4335: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - configure_input="Generated automatically from `echo $ac_file_in | - sed 's,.*/,,'` by configure." - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:4353: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:4366: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s,@configure_input@,$configure_input,;t t -s,@srcdir@,$ac_srcdir,;t t -s,@top_srcdir@,$ac_top_srcdir,;t t -s,@INSTALL@,$ac_INSTALL,;t t -" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out - rm -f $tmp/stdin - if test x"$ac_file" != x-; then - mv $tmp/out $ac_file - else - cat $tmp/out - rm -f $tmp/out - fi - -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_HEADER section. -# - -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' -ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t' - -for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - test x"$ac_file" != x- && { echo "$as_me:4427: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:4438: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:4451: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } - # Remove the trailing spaces. - sed 's/[ ]*$//' $ac_file_inputs >$tmp/in - -EOF - -# Transform confdefs.h into two sed scripts, `conftest.defines' and -# `conftest.undefs', that substitutes the proper values into -# config.h.in to produce config.h. The first handles `#define' -# templates, and the second `#undef' templates. -# And first: Protect against being on the right side of a sed subst in -# config.status. Protect against being in an unquoted here document -# in config.status. -rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. -# Putting comments in sed scripts is not portable. -# -# `end' is used to avoid that the second main sed command (meant for -# 0-ary CPP macros) applies to n-ary macro definitions. -# See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\EOF -s/[\\&,]/\\&/g -s,[\\$`],\\&,g -t clear -: clear -s,^[ ]*#[ ]*define[ ][ ]*\(\([^ (][^ (]*\)([^)]*)\)[ ]*\(.*\)$,${ac_dA}\2${ac_dB}\1${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end -EOF -# If some macros were called several times there might be several times -# the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. -uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs -rm -f confdef2sed.sed - -# This sed command replaces #undef with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\EOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -EOF - -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if egrep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.defines >/dev/null -do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/defines.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail - rm -f conftest.defines - mv conftest.tail conftest.defines -done -rm -f conftest.defines -echo ' fi # egrep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/undefs.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs - -cat >>$CONFIG_STATUS <<\EOF - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - if test x"$ac_file" = x-; then - echo "/* Generated automatically by configure. */" >$tmp/config.h - else - echo "/* $ac_file. Generated automatically by configure. */" >$tmp/config.h - fi - cat $tmp/in >>$tmp/config.h - rm -f $tmp/in - if test x"$ac_file" != x-; then - if cmp -s $ac_file $tmp/config.h 2>/dev/null; then - { echo "$as_me:4568: $ac_file is unchanged" >&5 -echo "$as_me: $ac_file is unchanged" >&6;} - else - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - fi - rm -f $ac_file - mv $tmp/config.h $ac_file - fi - else - cat $tmp/config.h - rm -f $tmp/config.h - fi -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_COMMANDS section. -# -for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue - ac_dest=`echo "$ac_file" | sed 's,:.*,,'` - ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'` - - case $ac_dest in - default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;; - esac -done -EOF - -cat >>$CONFIG_STATUS <<\EOF - -{ (exit 0); exit 0; } -EOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - exec 5>/dev/null - $SHELL $CONFIG_STATUS || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi - diff --git a/lsh/src/nettle/configure.in b/lsh/src/nettle/configure.in deleted file mode 100644 index d1b43c4..0000000 --- a/lsh/src/nettle/configure.in +++ /dev/null @@ -1,53 +0,0 @@ -dnl -*- mode: shell-script; sh-indentation: 2; -*- -dnl $Id$ - -dnl Process this file with autoconf to produce a configure script. - -AC_INIT(arcfour.c) - -AM_INIT_AUTOMAKE(libnettle, 0.2) - -AM_CONFIG_HEADER(config.h) - -dnl Checks for programs. -AC_PROG_CC -AC_PROG_MAKE_SET -AC_PROG_RANLIB -AM_PROG_CC_STDC - -if test "x$am_cv_prog_cc_stdc" = xno ; then - AC_ERROR([the C compiler doesn't handle ANSI-C]) -fi - -AC_PATH_PROG(M4, m4, m4) - -dnl Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE -AC_TYPE_UID_T -AC_TYPE_SIZE_T -AC_HEADER_TIME - -dnl Needed by the supplied memcmp.c -AC_C_BIGENDIAN - -AC_CHECK_SIZEOF(short, 2) -AC_CHECK_SIZEOF(int, 4) -AC_CHECK_SIZEOF(long, 4) - -AC_REPLACE_FUNCS(memxor) - -# Set these flags *last*, or else the test programs won't compile -if test x$GCC = xyes ; then - CFLAGS="$CFLAGS -ggdb3 -Wall -W \ - -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \ - -Waggregate-return \ - -Wpointer-arith -Wbad-function-cast -Wnested-externs" - -# Don't enable -Wcast-align as it results in tons of warnings in the -# DES code. And when using stdio. - -fi - -AC_OUTPUT(Makefile testsuite/Makefile) - diff --git a/lsh/src/nettle/des.c b/lsh/src/nettle/des.c deleted file mode 100644 index c95f08b..0000000 --- a/lsh/src/nettle/des.c +++ /dev/null @@ -1,238 +0,0 @@ -/* des.c - * - * The des block cipher. - * - * $Id$ - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* des - fast & portable DES encryption & decryption. - * Copyright (C) 1992 Dana L. How - * Please see the file `descore.README' for the complete copyright notice. - */ - -#include "des.h" - -#include "desCode.h" - -#include - -static ENCRYPT(DesSmallFipsEncrypt,TEMPSMALL, LOADFIPS,KEYMAPSMALL,SAVEFIPS) -static DECRYPT(DesSmallFipsDecrypt,TEMPSMALL, LOADFIPS,KEYMAPSMALL,SAVEFIPS) - -/* various tables */ - -uint32_t des_keymap[] = { -#include "keymap.h" -}; - -static uint8_t rotors[] = { -#include "rotors.h" -}; -static char parity[] = { -#include "parity.h" -}; - -int -des_set_key(struct des_ctx *ctx, const uint8_t *key) -{ - register uint32_t n, w; - register char * b0, * b1; - char bits0[56], bits1[56]; - uint32_t *method; - uint8_t *k; - - /* check for bad parity and weak keys */ - b0 = parity; - n = b0[key[0]]; n <<= 4; - n |= b0[key[1]]; n <<= 4; - n |= b0[key[2]]; n <<= 4; - n |= b0[key[3]]; n <<= 4; - n |= b0[key[4]]; n <<= 4; - n |= b0[key[5]]; n <<= 4; - n |= b0[key[6]]; n <<= 4; - n |= b0[key[7]]; - w = 0x88888888l; - /* report bad parity in key */ - if ( n & w ) - { - ctx->status = DES_BAD_PARITY; - return 0; - } - ctx->status = DES_WEAK_KEY; - /* report a weak or semi-weak key */ - if ( !((n - (w >> 3)) & w) ) { /* 1 in 10^10 keys passes this test */ - if ( n < 0X41415151 ) { - if ( n < 0X31312121 ) { - if ( n < 0X14141515 ) { - /* 01 01 01 01 01 01 01 01 */ - if ( n == 0X11111111 ) return 0; - /* 01 1F 01 1F 01 0E 01 0E */ - if ( n == 0X13131212 ) return 0; - } else { - /* 01 E0 01 E0 01 F1 01 F1 */ - if ( n == 0X14141515 ) return 0; - /* 01 FE 01 FE 01 FE 01 FE */ - if ( n == 0X16161616 ) return 0; - } - } else { - if ( n < 0X34342525 ) { - /* 1F 01 1F 01 0E 01 0E 01 */ - if ( n == 0X31312121 ) return 0; - /* 1F 1F 1F 1F 0E 0E 0E 0E */ /* ? */ - if ( n == 0X33332222 ) return 0;; - } else { - /* 1F E0 1F E0 0E F1 0E F1 */ - if ( n == 0X34342525 ) return 0;; - /* 1F FE 1F FE 0E FE 0E FE */ - if ( n == 0X36362626 ) return 0;; - } - } - } else { - if ( n < 0X61616161 ) { - if ( n < 0X44445555 ) { - /* E0 01 E0 01 F1 01 F1 01 */ - if ( n == 0X41415151 ) return 0; - /* E0 1F E0 1F F1 0E F1 0E */ - if ( n == 0X43435252 ) return 0; - } else { - /* E0 E0 E0 E0 F1 F1 F1 F1 */ /* ? */ - if ( n == 0X44445555 ) return 0; - /* E0 FE E0 FE F1 FE F1 FE */ - if ( n == 0X46465656 ) return 0; - } - } else { - if ( n < 0X64646565 ) { - /* FE 01 FE 01 FE 01 FE 01 */ - if ( n == 0X61616161 ) return 0; - /* FE 1F FE 1F FE 0E FE 0E */ - if ( n == 0X63636262 ) return 0; - } else { - /* FE E0 FE E0 FE F1 FE F1 */ - if ( n == 0X64646565 ) return 0; - /* FE FE FE FE FE FE FE FE */ - if ( n == 0X66666666 ) return 0; - } - } - } - } - - /* key is ok */ - ctx->status = DES_OK; - - /* explode the bits */ - n = 56; - b0 = bits0; - b1 = bits1; - do { - w = (256 | *key++) << 2; - do { - --n; - b1[n] = 8 & w; - w >>= 1; - b0[n] = 4 & w; - } while ( w >= 16 ); - } while ( n ); - - /* put the bits in the correct places */ - n = 16; - k = rotors; - method = ctx->key; - - do { - w = (b1[k[ 0 ]] | b0[k[ 1 ]]) << 4; - w |= (b1[k[ 2 ]] | b0[k[ 3 ]]) << 2; - w |= b1[k[ 4 ]] | b0[k[ 5 ]]; - w <<= 8; - w |= (b1[k[ 6 ]] | b0[k[ 7 ]]) << 4; - w |= (b1[k[ 8 ]] | b0[k[ 9 ]]) << 2; - w |= b1[k[10 ]] | b0[k[11 ]]; - w <<= 8; - w |= (b1[k[12 ]] | b0[k[13 ]]) << 4; - w |= (b1[k[14 ]] | b0[k[15 ]]) << 2; - w |= b1[k[16 ]] | b0[k[17 ]]; - w <<= 8; - w |= (b1[k[18 ]] | b0[k[19 ]]) << 4; - w |= (b1[k[20 ]] | b0[k[21 ]]) << 2; - w |= b1[k[22 ]] | b0[k[23 ]]; - - method[0] = w; - - w = (b1[k[ 0+24]] | b0[k[ 1+24]]) << 4; - w |= (b1[k[ 2+24]] | b0[k[ 3+24]]) << 2; - w |= b1[k[ 4+24]] | b0[k[ 5+24]]; - w <<= 8; - w |= (b1[k[ 6+24]] | b0[k[ 7+24]]) << 4; - w |= (b1[k[ 8+24]] | b0[k[ 9+24]]) << 2; - w |= b1[k[10+24]] | b0[k[11+24]]; - w <<= 8; - w |= (b1[k[12+24]] | b0[k[13+24]]) << 4; - w |= (b1[k[14+24]] | b0[k[15+24]]) << 2; - w |= b1[k[16+24]] | b0[k[17+24]]; - w <<= 8; - w |= (b1[k[18+24]] | b0[k[19+24]]) << 4; - w |= (b1[k[20+24]] | b0[k[21+24]]) << 2; - w |= b1[k[22+24]] | b0[k[23+24]]; - - ROR(w, 4, 28); /* could be eliminated */ - method[1] = w; - - k += 48; - method += 2; - } while ( --n ); - - return 1; -} - -void -des_encrypt(struct des_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - assert(!(length % DES_BLOCK_SIZE)); - assert(ctx->status == DES_OK); - - while (length) - { - DesSmallFipsEncrypt(dst, ctx->key, src); - length -= DES_BLOCK_SIZE; - src += DES_BLOCK_SIZE; - dst += DES_BLOCK_SIZE; - } -} - -void -des_decrypt(struct des_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src) -{ - assert(!(length % DES_BLOCK_SIZE)); - assert(ctx->status == DES_OK); - - while (length) - { - DesSmallFipsDecrypt(dst, ctx->key, src); - length -= DES_BLOCK_SIZE; - src += DES_BLOCK_SIZE; - dst += DES_BLOCK_SIZE; - } -} diff --git a/lsh/src/nettle/des.h b/lsh/src/nettle/des.h deleted file mode 100644 index 9c09a5d..0000000 --- a/lsh/src/nettle/des.h +++ /dev/null @@ -1,68 +0,0 @@ -/* des.h - * - * The des block cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 1992, 2001, Dana L. How, Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* - * des - fast & portable DES encryption & decryption. - * Copyright (C) 1992 Dana L. How - * Please see the file `../lib/descore.README' for the complete copyright - * notice. - * - * Slightly edited by Niels Möller, 1997 - */ - -#ifndef NETTLE_DES_H -#define NETTLE_DES_H - -#include - -#define DES_KEY_SIZE 8 -#define DES_BLOCK_SIZE 8 - -/* Expanded key length */ -#define _DES_KEY_LENGTH 32 - -enum des_error { DES_OK, DES_BAD_PARITY, DES_WEAK_KEY }; - -struct des_ctx -{ - uint32_t key[_DES_KEY_LENGTH]; - enum des_error status; -}; - -/* On success, returns 1 and sets ctx->status to DES_OK (zero). On - * error, returns 0 and sets ctx->status accordingly. */ -int -des_set_key(struct des_ctx *ctx, const uint8_t *key); - -void -des_encrypt(struct des_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); -void -des_decrypt(struct des_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -#endif /* NETTLE_DES_H */ diff --git a/lsh/src/nettle/desCode.h b/lsh/src/nettle/desCode.h deleted file mode 100644 index d27df60..0000000 --- a/lsh/src/nettle/desCode.h +++ /dev/null @@ -1,415 +0,0 @@ -/* desCode.h - * - * $Id$ */ - -/* des - fast & portable DES encryption & decryption. - * Copyright (C) 1992 Dana L. How - * Please see the file `descore.README' for the complete copyright notice. - */ - -#include "des.h" - -extern uint32_t des_keymap[]; -extern uint32_t des_bigmap[]; - -/* optional customization: - * the idea here is to alter the code so it will still run correctly - * on any machine, but the quickest on the specific machine in mind. - * note that these silly tweaks can give you a 15%-20% speed improvement - * on the sparc -- it's probably even more significant on the 68000. */ - -/* take care of machines with incredibly few registers */ -#if defined(i386) -#define REGISTER /* only x, y, z will be declared register */ -#else -#define REGISTER register -#endif /* i386 */ - -/* is auto inc/dec faster than 7bit unsigned indexing? */ -#if defined(vax) || defined(mc68000) -#define FIXR r += 32; -#define FIXS s += 8; -#define PREV(v,o) *--v -#define NEXT(v,o) *v++ -#else -#define FIXR -#define FIXS -#define PREV(v,o) v[o] -#define NEXT(v,o) v[o] -#endif - -/* if no machine type, default is indexing, 6 registers and cheap literals */ -#if !defined(i386) && !defined(vax) && !defined(mc68000) && !defined(sparc) -#define vax -#endif - - -/* handle a compiler which can't reallocate registers */ -/* The BYTE type is used as parameter for the encrypt/decrypt functions. - * It's pretty bad to have the function prototypes depend on - * a macro definition that the users of the function doesn't - * know about. /Niels */ -#if 0 /* didn't feel like deleting */ -#define SREGFREE ; s = (uint8_t *) D -#define DEST s -#define D m0 -#define BYTE uint32_t -#else -#define SREGFREE -#define DEST d -#define D d -#define BYTE uint8_t -#endif - -/* handle constants in the optimal way for 386 & vax */ -/* 386: we declare 3 register variables (see above) and use 3 more variables; - * vax: we use 6 variables, all declared register; - * we assume address literals are cheap & unrestricted; - * we assume immediate constants are cheap & unrestricted. */ -#if defined(i386) || defined(vax) -#define MQ0 des_bigmap -#define MQ1 (des_bigmap + 64) -#define MQ2 (des_bigmap + 128) -#define MQ3 (des_bigmap + 192) -#define HQ0(z) /* z |= 0x01000000L; */ -#define HQ2(z) /* z |= 0x03000200L; */ -#define LQ0(z) 0xFCFC & z -#define LQ1(z) 0xFCFC & z -#define LQ2(z) 0xFCFC & z -#define LQ3(z) 0xFCFC & z -#define SQ 16 -#define MS0 des_keymap -#define MS1 (des_keymap + 64) -#define MS2 (des_keymap + 128) -#define MS3 (des_keymap + 192) -#define MS4 (des_keymap + 256) -#define MS5 (des_keymap + 320) -#define MS6 (des_keymap + 384) -#define MS7 (des_keymap + 448) -#define HS(z) -#define LS0(z) 0xFC & z -#define LS1(z) 0xFC & z -#define LS2(z) 0xFC & z -#define LS3(z) 0xFC & z -#define REGQUICK -#define SETQUICK -#define REGSMALL -#define SETSMALL -#endif /* defined(i386) || defined(vax) */ - -/* handle constants in the optimal way for mc68000 */ -/* in addition to the core 6 variables, we declare 3 registers holding constants - * and 4 registers holding address literals. - * at most 6 data values and 5 address values are actively used at once. - * we assume address literals are so expensive we never use them; - * we assume constant index offsets > 127 are expensive, so they are not used. - * we assume all constants are expensive and put them in registers, - * including shift counts greater than 8. */ -#if defined(mc68000) -#define MQ0 m0 -#define MQ1 m1 -#define MQ2 m2 -#define MQ3 m3 -#define HQ0(z) -#define HQ2(z) -#define LQ0(z) k0 & z -#define LQ1(z) k0 & z -#define LQ2(z) k0 & z -#define LQ3(z) k0 & z -#define SQ k1 -#define MS0 m0 -#define MS1 m0 -#define MS2 m1 -#define MS3 m1 -#define MS4 m2 -#define MS5 m2 -#define MS6 m3 -#define MS7 m3 -#define HS(z) z |= k0; -#define LS0(z) k1 & z -#define LS1(z) k2 & z -#define LS2(z) k1 & z -#define LS3(z) k2 & z -#define REGQUICK \ - register uint32_t k0, k1; \ - register uint32_t *m0, *m1, *m2, *m3; -#define SETQUICK \ - ; k0 = 0xFCFC \ - ; k1 = 16 \ - /*k2 = 28 to speed up ROL */ \ - ; m0 = des_bigmap \ - ; m1 = m0 + 64 \ - ; m2 = m1 + 64 \ - ; m3 = m2 + 64 -#define REGSMALL \ - register uint32_t k0, k1, k2; \ - register uint32_t *m0, *m1, *m2, *m3; -#define SETSMALL \ - ; k0 = 0x01000100L \ - ; k1 = 0x0FC \ - ; k2 = 0x1FC \ - ; m0 = des_keymap \ - ; m1 = m0 + 128 \ - ; m2 = m1 + 128 \ - ; m3 = m2 + 128 -#endif /* defined(mc68000) */ - -/* handle constants in the optimal way for sparc */ -/* in addition to the core 6 variables, we either declare: - * 4 registers holding address literals and 1 register holding a constant, or - * 8 registers holding address literals. - * up to 14 register variables are declared (sparc has %i0-%i5, %l0-%l7). - * we assume address literals are so expensive we never use them; - * we assume any constant with >10 bits is expensive and put it in a register, - * and any other is cheap and is coded in-line. */ -#if defined(sparc) -#define MQ0 m0 -#define MQ1 m1 -#define MQ2 m2 -#define MQ3 m3 -#define HQ0(z) -#define HQ2(z) -#define LQ0(z) k0 & z -#define LQ1(z) k0 & z -#define LQ2(z) k0 & z -#define LQ3(z) k0 & z -#define SQ 16 -#define MS0 m0 -#define MS1 m1 -#define MS2 m2 -#define MS3 m3 -#define MS4 m4 -#define MS5 m5 -#define MS6 m6 -#define MS7 m7 -#define HS(z) -#define LS0(z) 0xFC & z -#define LS1(z) 0xFC & z -#define LS2(z) 0xFC & z -#define LS3(z) 0xFC & z -#define REGQUICK \ - register uint32_t k0; \ - register uint32_t *m0, *m1, *m2, *m3; -#define SETQUICK \ - ; k0 = 0xFCFC \ - ; m0 = des_bigmap \ - ; m1 = m0 + 64 \ - ; m2 = m1 + 64 \ - ; m3 = m2 + 64 -#define REGSMALL \ - register uint32_t *m0, *m1, *m2, *m3, *m4, *m5, *m6, *m7; -#define SETSMALL \ - ; m0 = des_keymap \ - ; m1 = m0 + 64 \ - ; m2 = m1 + 64 \ - ; m3 = m2 + 64 \ - ; m4 = m3 + 64 \ - ; m5 = m4 + 64 \ - ; m6 = m5 + 64 \ - ; m7 = m6 + 64 -#endif /* defined(sparc) */ - - -/* some basic stuff */ - -/* generate addresses from a base and an index */ -/* FIXME: This is used only as *ADD(msi,lsi(z)) or *ADD(mqi,lqi(z)). - * Why not use plain indexing instead? /Niels */ -#define ADD(b,x) (uint32_t *) ((uint8_t *)b + (x)) - -/* low level rotate operations */ -#define NOP(d,c,o) -#define ROL(d,c,o) d = d << c | d >> o -#define ROR(d,c,o) d = d >> c | d << o -#define ROL1(d) ROL(d, 1, 31) -#define ROR1(d) ROR(d, 1, 31) - -/* elementary swap for doing IP/FP */ -#define SWAP(x,y,m,b) \ - z = ((x >> b) ^ y) & m; \ - x ^= z << b; \ - y ^= z - - -/* the following macros contain all the important code fragments */ - -/* load input data, then setup special registers holding constants */ -#define TEMPQUICK(LOAD) \ - REGQUICK \ - LOAD() \ - SETQUICK -#define TEMPSMALL(LOAD) \ - REGSMALL \ - LOAD() \ - SETSMALL - -/* load data */ -#define LOADDATA(x,y) \ - FIXS \ - y = PREV(s, 7); y<<= 8; \ - y |= PREV(s, 6); y<<= 8; \ - y |= PREV(s, 5); y<<= 8; \ - y |= PREV(s, 4); \ - x = PREV(s, 3); x<<= 8; \ - x |= PREV(s, 2); x<<= 8; \ - x |= PREV(s, 1); x<<= 8; \ - x |= PREV(s, 0) \ - SREGFREE -/* load data without initial permutation and put into efficient position */ -#define LOADCORE() \ - LOADDATA(x, y); \ - ROR1(x); \ - ROR1(y) -/* load data, do the initial permutation and put into efficient position */ -#define LOADFIPS() \ - LOADDATA(y, x); \ - SWAP(x, y, 0x0F0F0F0FL, 004); \ - SWAP(y, x, 0x0000FFFFL, 020); \ - SWAP(x, y, 0x33333333L, 002); \ - SWAP(y, x, 0x00FF00FFL, 010); \ - ROR1(x); \ - z = (x ^ y) & 0x55555555L; \ - y ^= z; \ - x ^= z; \ - ROR1(y) - - -/* core encryption/decryption operations */ -/* S box mapping and P perm */ -#define KEYMAPSMALL(x,z,mq0,mq1,hq,lq0,lq1,sq,ms0,ms1,ms2,ms3,hs,ls0,ls1,ls2,ls3)\ - hs(z) \ - x ^= *ADD(ms3, ls3(z)); \ - z>>= 8; \ - x ^= *ADD(ms2, ls2(z)); \ - z>>= 8; \ - x ^= *ADD(ms1, ls1(z)); \ - z>>= 8; \ - x ^= *ADD(ms0, ls0(z)) -/* alternate version: use 64k of tables */ -#define KEYMAPQUICK(x,z,mq0,mq1,hq,lq0,lq1,sq,ms0,ms1,ms2,ms3,hs,ls0,ls1,ls2,ls3)\ - hq(z) \ - x ^= *ADD(mq0, lq0(z)); \ - z>>= sq; \ - x ^= *ADD(mq1, lq1(z)) -/* apply 24 key bits and do the odd s boxes */ -#define S7S1(x,y,z,r,m,KEYMAP,LOAD) \ - z = LOAD(r, m); \ - z ^= y; \ - KEYMAP(x,z,MQ0,MQ1,HQ0,LQ0,LQ1,SQ,MS0,MS1,MS2,MS3,HS,LS0,LS1,LS2,LS3) -/* apply 24 key bits and do the even s boxes */ -#define S6S0(x,y,z,r,m,KEYMAP,LOAD) \ - z = LOAD(r, m); \ - z ^= y; \ - ROL(z, 4, 28); \ - KEYMAP(x,z,MQ2,MQ3,HQ2,LQ2,LQ3,SQ,MS4,MS5,MS6,MS7,HS,LS0,LS1,LS2,LS3) -/* actual iterations. equivalent except for UPDATE & swapping m and n */ -#define ENCR(x,y,z,r,m,n,KEYMAP) \ - S7S1(x,y,z,r,m,KEYMAP,NEXT); \ - S6S0(x,y,z,r,n,KEYMAP,NEXT) -#define DECR(x,y,z,r,m,n,KEYMAP) \ - S6S0(x,y,z,r,m,KEYMAP,PREV); \ - S7S1(x,y,z,r,n,KEYMAP,PREV) - -/* write out result in correct byte order */ -#define SAVEDATA(x,y) \ - NEXT(DEST, 0) = x; x>>= 8; \ - NEXT(DEST, 1) = x; x>>= 8; \ - NEXT(DEST, 2) = x; x>>= 8; \ - NEXT(DEST, 3) = x; \ - NEXT(DEST, 4) = y; y>>= 8; \ - NEXT(DEST, 5) = y; y>>= 8; \ - NEXT(DEST, 6) = y; y>>= 8; \ - NEXT(DEST, 7) = y -/* write out result */ -#define SAVECORE() \ - ROL1(x); \ - ROL1(y); \ - SAVEDATA(y, x) -/* do final permutation and write out result */ -#define SAVEFIPS() \ - ROL1(x); \ - z = (x ^ y) & 0x55555555L; \ - y ^= z; \ - x ^= z; \ - ROL1(y); \ - SWAP(x, y, 0x00FF00FFL, 010); \ - SWAP(y, x, 0x33333333L, 002); \ - SWAP(x, y, 0x0000FFFFL, 020); \ - SWAP(y, x, 0x0F0F0F0FL, 004); \ - SAVEDATA(x, y) - - -/* the following macros contain the encryption/decryption skeletons */ - -#define ENCRYPT(NAME, TEMP, LOAD, KEYMAP, SAVE) \ - \ -void \ -NAME(REGISTER BYTE *D, \ - REGISTER const uint32_t *r, \ - REGISTER const uint8_t *s) \ -{ \ - register uint32_t x, y, z; \ - \ - /* declare temps & load data */ \ - TEMP(LOAD); \ - \ - /* do the 16 iterations */ \ - ENCR(x,y,z,r, 0, 1,KEYMAP); \ - ENCR(y,x,z,r, 2, 3,KEYMAP); \ - ENCR(x,y,z,r, 4, 5,KEYMAP); \ - ENCR(y,x,z,r, 6, 7,KEYMAP); \ - ENCR(x,y,z,r, 8, 9,KEYMAP); \ - ENCR(y,x,z,r,10,11,KEYMAP); \ - ENCR(x,y,z,r,12,13,KEYMAP); \ - ENCR(y,x,z,r,14,15,KEYMAP); \ - ENCR(x,y,z,r,16,17,KEYMAP); \ - ENCR(y,x,z,r,18,19,KEYMAP); \ - ENCR(x,y,z,r,20,21,KEYMAP); \ - ENCR(y,x,z,r,22,23,KEYMAP); \ - ENCR(x,y,z,r,24,25,KEYMAP); \ - ENCR(y,x,z,r,26,27,KEYMAP); \ - ENCR(x,y,z,r,28,29,KEYMAP); \ - ENCR(y,x,z,r,30,31,KEYMAP); \ - \ - /* save result */ \ - SAVE(); \ - \ - return; \ -} - -#define DECRYPT(NAME, TEMP, LOAD, KEYMAP, SAVE) \ - \ -void \ -NAME(REGISTER BYTE *D, \ - REGISTER const uint32_t *r, \ - REGISTER const uint8_t *s) \ -{ \ - register uint32_t x, y, z; \ - \ - /* declare temps & load data */ \ - TEMP(LOAD); \ - \ - /* do the 16 iterations */ \ - FIXR \ - DECR(x,y,z,r,31,30,KEYMAP); \ - DECR(y,x,z,r,29,28,KEYMAP); \ - DECR(x,y,z,r,27,26,KEYMAP); \ - DECR(y,x,z,r,25,24,KEYMAP); \ - DECR(x,y,z,r,23,22,KEYMAP); \ - DECR(y,x,z,r,21,20,KEYMAP); \ - DECR(x,y,z,r,19,18,KEYMAP); \ - DECR(y,x,z,r,17,16,KEYMAP); \ - DECR(x,y,z,r,15,14,KEYMAP); \ - DECR(y,x,z,r,13,12,KEYMAP); \ - DECR(x,y,z,r,11,10,KEYMAP); \ - DECR(y,x,z,r, 9, 8,KEYMAP); \ - DECR(x,y,z,r, 7, 6,KEYMAP); \ - DECR(y,x,z,r, 5, 4,KEYMAP); \ - DECR(x,y,z,r, 3, 2,KEYMAP); \ - DECR(y,x,z,r, 1, 0,KEYMAP); \ - \ - /* save result */ \ - SAVE(); \ - \ - return; \ -} diff --git a/lsh/src/nettle/descore.README b/lsh/src/nettle/descore.README deleted file mode 100644 index 2692f94..0000000 --- a/lsh/src/nettle/descore.README +++ /dev/null @@ -1,313 +0,0 @@ -des - fast & portable DES encryption & decryption. -Copyright (C) 1992 Dana L. How - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Library 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 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 Library General Public License for more details. - -You should have received a copy of the GNU Library 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 - -Author's address: how@isl.stanford.edu - -$Id$ - - -==>> To compile after untarring/unsharring, just `make' <<== - - -This package was designed with the following goals: -1. Highest possible encryption/decryption PERFORMANCE. -2. PORTABILITY to any byte-addressable machine with a 32bit unsigned C type -3. Plug-compatible replacement for KERBEROS's low-level routines. - - -performance comparison to other available des code which i could -compile on a SPARCStation 1 (cc -O4): - -this code (byte-order independent): - 30us per encryption (options: 64k tables, no IP/FP) - 33us per encryption (options: 64k tables, FIPS standard bit ordering) - 45us per encryption (options: 2k tables, no IP/FP) - 49us per encryption (options: 2k tables, FIPS standard bit ordering) - 275us to set a new key (uses 1k of key tables) - this has the quickest encryption/decryption routines i've seen. - since i was interested in fast des filters rather than crypt(3) - and password cracking, i haven't really bothered yet to speed up - the key setting routine. also, i have no interest in re-implementing - all the other junk in the mit kerberos des library, so i've just - provided my routines with little stub interfaces so they can be - used as drop-in replacements with mit's code or any of the mit- - compatible packages below. (note that the first two timings above - are highly variable because of cache effects). - -kerberos des replacement from australia: - 68us per encryption (uses 2k of tables) - 96us to set a new key (uses 2.25k of key tables) - this is a very nice package which implements the most important - of the optimizations which i did in my encryption routines. - it's a bit weak on common low-level optimizations which is why - it's 39%-106% slower. because he was interested in fast crypt(3) and - password-cracking applications, he also used the same ideas to - speed up the key-setting routines with impressive results. - (at some point i may do the same in my package). he also implements - the rest of the mit des library. - (code from eay@psych.psy.uq.oz.au via comp.sources.misc) - -fast crypt(3) package from denmark: - the des routine here is buried inside a loop to do the - crypt function and i didn't feel like ripping it out and measuring - performance. his code takes 26 sparc instructions to compute one - des iteration; above, Quick (64k) takes 21 and Small (2k) takes 37. - he claims to use 280k of tables but the iteration calculation seems - to use only 128k. his tables and code are machine independent. - (code from glad@daimi.aau.dk via alt.sources or comp.sources.misc) - -swedish reimplementation of Kerberos des library - 108us per encryption (uses 34k worth of tables) - 134us to set a new key (uses 32k of key tables to get this speed!) - the tables used seem to be machine-independent; - he seems to have included a lot of special case code - so that, e.g., `long' loads can be used instead of 4 `char' loads - when the machine's architecture allows it. - (code obtained from chalmers.se:pub/des) - -crack 3.3c package from england: - as in crypt above, the des routine is buried in a loop. it's - also very modified for crypt. his iteration code uses 16k - of tables and appears to be slow. - (code obtained from aem@aber.ac.uk via alt.sources or comp.sources.misc) - -``highly optimized'' and tweaked Kerberos/Athena code (byte-order dependent): - 165us per encryption (uses 6k worth of tables) - 478us to set a new key (uses <1k of key tables) - so despite the comments in this code, it was possible to get - faster code AND smaller tables, as well as making the tables - machine-independent. - (code obtained from prep.ai.mit.edu) - -UC Berkeley code (depends on machine-endedness): - 226us per encryption -10848us to set a new key - table sizes are unclear, but they don't look very small - (code obtained from wuarchive.wustl.edu) - - -motivation and history - -a while ago i wanted some des routines and the routines documented on sun's -man pages either didn't exist or dumped core. i had heard of kerberos, -and knew that it used des, so i figured i'd use its routines. but once -i got it and looked at the code, it really set off a lot of pet peeves - -it was too convoluted, the code had been written without taking -advantage of the regular structure of operations such as IP, E, and FP -(i.e. the author didn't sit down and think before coding), -it was excessively slow, the author had attempted to clarify the code -by adding MORE statements to make the data movement more `consistent' -instead of simplifying his implementation and cutting down on all data -movement (in particular, his use of L1, R1, L2, R2), and it was full of -idiotic `tweaks' for particular machines which failed to deliver significant -speedups but which did obfuscate everything. so i took the test data -from his verification program and rewrote everything else. - -a while later i ran across the great crypt(3) package mentioned above. -the fact that this guy was computing 2 sboxes per table lookup rather -than one (and using a MUCH larger table in the process) emboldened me to -do the same - it was a trivial change from which i had been scared away -by the larger table size. in his case he didn't realize you don't need to keep -the working data in TWO forms, one for easy use of half the sboxes in -indexing, the other for easy use of the other half; instead you can keep -it in the form for the first half and use a simple rotate to get the other -half. this means i have (almost) half the data manipulation and half -the table size. in fairness though he might be encoding something particular -to crypt(3) in his tables - i didn't check. - -i'm glad that i implemented it the way i did, because this C version is -portable (the ifdef's are performance enhancements) and it is faster -than versions hand-written in assembly for the sparc! - - -porting notes - -one thing i did not want to do was write an enormous mess -which depended on endedness and other machine quirks, -and which necessarily produced different code and different lookup tables -for different machines. see the kerberos code for an example -of what i didn't want to do; all their endedness-specific `optimizations' -obfuscate the code and in the end were slower than a simpler machine -independent approach. however, there are always some portability -considerations of some kind, and i have included some options -for varying numbers of register variables. -perhaps some will still regard the result as a mess! - -1) i assume everything is byte addressable, although i don't actually - depend on the byte order, and that bytes are 8 bits. - i assume word pointers can be freely cast to and from char pointers. - note that 99% of C programs make these assumptions. - i always use unsigned char's if the high bit could be set. -2) the typedef `word' means a 32 bit unsigned integral type. - if `unsigned long' is not 32 bits, change the typedef in desCore.h. - i assume sizeof(word) == 4 EVERYWHERE. - -the (worst-case) cost of my NOT doing endedness-specific optimizations -in the data loading and storing code surrounding the key iterations -is less than 12%. also, there is the added benefit that -the input and output work areas do not need to be word-aligned. - - -OPTIONAL performance optimizations - -1) you should define one of `i386,' `vax,' `mc68000,' or `sparc,' - whichever one is closest to the capabilities of your machine. - see the start of desCode.h to see exactly what this selection implies. - note that if you select the wrong one, the des code will still work; - these are just performance tweaks. -2) for those with functional `asm' keywords: you should change the - ROR and ROL macros to use machine rotate instructions if you have them. - this will save 2 instructions and a temporary per use, - or about 32 to 40 instructions per en/decryption. - -these optimizations are all rather persnickety, yet with them you should -be able to get performance equal to assembly-coding, except that: -1) with the lack of a bit rotate operator in C, rotates have to be synthesized - from shifts. so access to `asm' will speed things up if your machine - has rotates, as explained above in (3). -2) if your machine has less than 12 32-bit registers i doubt your compiler will - generate good code. - `i386' tries to configure the code for a 386 by only declaring 3 registers - (it appears that gcc can use ebx, esi and edi to hold register variables). - however, if you like assembly coding, the 386 does have 7 32-bit registers, - and if you use ALL of them, use `scaled by 8' address modes with displacement - and other tricks, you can get reasonable routines for DesQuickCore... with - about 250 instructions apiece. For DesSmall... it will help to rearrange - des_keymap, i.e., now the sbox # is the high part of the index and - the 6 bits of data is the low part; it helps to exchange these. - since i have no way to conveniently test it i have not provided my - shoehorned 386 version. - -coding notes - -the en/decryption routines each use 6 necessary register variables, -with 4 being actively used at once during the inner iterations. -if you don't have 4 register variables get a new machine. -up to 8 more registers are used to hold constants in some configurations. - -i assume that the use of a constant is more expensive than using a register: -a) additionally, i have tried to put the larger constants in registers. - registering priority was by the following: - anything more than 12 bits (bad for RISC and CISC) - greater than 127 in value (can't use movq or byte immediate on CISC) - 9-127 (may not be able to use CISC shift immediate or add/sub quick), - 1-8 were never registered, being the cheapest constants. -b) the compiler may be too stupid to realize table and table+256 should - be assigned to different constant registers and instead repetitively - do the arithmetic, so i assign these to explicit `m' register variables - when possible and helpful. - -i assume that indexing is cheaper or equivalent to auto increment/decrement, -where the index is 7 bits unsigned or smaller. -this assumption is reversed for 68k and vax. - -i assume that addresses can be cheaply formed from two registers, -or from a register and a small constant. i never use the `two registers -and offset' form you see in some CISC machines. -all index scaling is done explicitly - no hidden shifts by log2(sizeof). - -the code is written so that even a dumb compiler -should never need more than one hidden temporary, -increasing the chance that everything will fit in the registers. -KEEP THIS MORE SUBTLE POINT IN MIND IF YOU REWRITE ANYTHING. - - -special efficient data format - -bits are manipulated in this arrangement most of the time (S7 S5 S3 S1): - 003130292827xxxx242322212019xxxx161514131211xxxx080706050403xxxx -(the x bits are still there, i'm just emphasizing where the S boxes are). -bits are rotated left 4 when computing S6 S4 S2 S0: - 282726252423xxxx201918171615xxxx121110090807xxxx040302010031xxxx -the rightmost two bits are usually cleared so the lower byte can be used -as an index into an sbox mapping table. the next two x'd bits are set -to various values to access different parts of the tables. - - -how to use the routines - -datatypes: - pointer to 8 byte area of type DesData - used to hold keys and input/output blocks to des. - - pointer to 128 byte area of type DesKeys - used to hold full 768-bit key. - must be long-aligned. - -DesQuickInit() - call this before using any other routine with `Quick' in its name. - it generates the special 64k table these routines need. -DesQuickDone() - frees this table - -DesMethod(m, k) - m points to a 128byte block, k points to an 8 byte des key - which must have odd parity (or -1 is returned) and which must - not be a (semi-)weak key (or -2 is returned). - normally DesMethod() returns 0. - m is filled in from k so that when one of the routines below - is called with m, the routine will act like standard des - en/decryption with the key k. if you use DesMethod, - you supply a standard 56bit key; however, if you fill in - m yourself, you will get a 768bit key - but then it won't - be standard. it's 768bits not 1024 because the least significant - two bits of each byte are not used. and yes, each byte controls - a specific sbox during a specific iteration. - NOTE: actually, every other word has been rotated right 4 bits - to reduce the number of temporaries needed when the key is used. - you really shouldn't use the 768bit format directly; i should - provide a routine that converts 128 6-bit bytes (specified in - S-box mapping order or something) into the right format for you. - this would entail some byte concatenation and rotation. - -Des{Small|Quick}{Fips|Core}{Encrypt|Decrypt}(d, m, s) - performs des on the 8 bytes at s into the 8 bytes at d. (d,s: char *). - uses m as a 768bit key as explained above. - the Encrypt|Decrypt choice is obvious. - Fips|Core determines whether a completely standard FIPS initial - and final permutation is done; if not, then the data is loaded - and stored in a nonstandard bit order (FIPS w/o IP/FP). - Fips slows down Quick by 10%, Small by 9%. - Small|Quick determines whether you use the normal routine - or the crazy quick one which gobbles up 64k more of memory. - Small is 50% slower then Quick, but Quick needs 32 times as much - memory. Quick is included for programs that do nothing but DES, - e.g., encryption filters, etc. - - -Getting it to compile on your machine - -there are no machine-dependencies in the code (see porting), -except perhaps the `now()' macro in desTest.c. -ALL generated tables are machine independent. -you should edit the Makefile with the appropriate optimization flags -for your compiler (MAX optimization). - - -Speeding up kerberos (and/or its des library) - -note that i have included a kerberos-compatible interface in desUtil.c -through the functions des_key_sched() and des_ecb_encrypt(). -to use these with kerberos or kerberos-compatible code put desCore.a -ahead of the kerberos-compatible library on your linker's command line. -you should not need to #include desCore.h; just include the header -file provided with the kerberos library. - -Other uses - -the macros in desCode.h would be very useful for putting inline des -functions in more complicated encryption routines. diff --git a/lsh/src/nettle/desdata.c b/lsh/src/nettle/desdata.c deleted file mode 100644 index c078e86..0000000 --- a/lsh/src/nettle/desdata.c +++ /dev/null @@ -1,199 +0,0 @@ -/* desdata.c - * - * Generate tables used by des.c and desCode.h. - * - * $Id$ */ - -/* - * des - fast & portable DES encryption & decryption. - * Copyright (C) 1992 Dana L. How - * Please see the file `descore.README' for the complete copyright notice. - * - */ - -#include "desinfo.h" - -#include "desCode.h" - -#if __GNUC__ -# define UNUSED __attribute__ ((__unused__)) -#else -# define UNUSED -#endif - -/* list of weak and semi-weak keys - - +0 +1 +2 +3 +4 +5 +6 +7 - 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 - 0x01 0x1f 0x01 0x1f 0x01 0x0e 0x01 0x0e - 0x01 0xe0 0x01 0xe0 0x01 0xf1 0x01 0xf1 - 0x01 0xfe 0x01 0xfe 0x01 0xfe 0x01 0xfe - 0x1f 0x01 0x1f 0x01 0x0e 0x01 0x0e 0x01 - 0x1f 0x1f 0x1f 0x1f 0x0e 0x0e 0x0e 0x0e - 0x1f 0xe0 0x1f 0xe0 0x0e 0xf1 0x0e 0xf1 - 0x1f 0xfe 0x1f 0xfe 0x0e 0xfe 0x0e 0xfe - 0xe0 0x01 0xe0 0x01 0xf1 0x01 0xf1 0x01 - 0xe0 0x1f 0xe0 0x1f 0xf1 0x0e 0xf1 0x0e - 0xe0 0xe0 0xe0 0xe0 0xf1 0xf1 0xf1 0xf1 - 0xe0 0xfe 0xe0 0xfe 0xf1 0xfe 0xf1 0xfe - 0xfe 0x01 0xfe 0x01 0xfe 0x01 0xfe 0x01 - 0xfe 0x1f 0xfe 0x1f 0xfe 0x0e 0xfe 0x0e - 0xfe 0xe0 0xfe 0xe0 0xfe 0xf1 0xfe 0xf1 - 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe - */ - -/* key bit order in each method pair: bits 31->00 of 1st, bits 31->00 of 2nd */ -/* this does not reflect the rotate of the 2nd word */ - -#define S(box,bit) (box*6+bit) -int korder[] = { - S(7, 5), S(7, 4), S(7, 3), S(7, 2), S(7, 1), S(7, 0), - S(5, 5), S(5, 4), S(5, 3), S(5, 2), S(5, 1), S(5, 0), - S(3, 5), S(3, 4), S(3, 3), S(3, 2), S(3, 1), S(3, 0), - S(1, 5), S(1, 4), S(1, 3), S(1, 2), S(1, 1), S(1, 0), - S(6, 5), S(6, 4), S(6, 3), S(6, 2), S(6, 1), S(6, 0), - S(4, 5), S(4, 4), S(4, 3), S(4, 2), S(4, 1), S(4, 0), - S(2, 5), S(2, 4), S(2, 3), S(2, 2), S(2, 1), S(2, 0), - S(0, 5), S(0, 4), S(0, 3), S(0, 2), S(0, 1), S(0, 0), -}; - -/* the order in which the algorithm accesses the s boxes */ - -int sorder[] = { - 7, 5, 3, 1, 6, 4, 2, 0, -}; - -int printf(const char *, ...); - -int -main(int argc UNUSED, char **argv UNUSED) -{ - uint32_t d, i, j, k, l, m, n, s; - char b[256], ksr[56]; - - switch ( argv[1][0] ) { - - /* - * <<< make the key parity table >>> - */ - -case 'p': - (void)printf( -"/* automagically produced - do not fuss with this information */\n\n"); - - /* store parity information */ - for ( i = 0; i < 256; i++ ) { - j = i; - j ^= j >> 4; /* bits 3-0 have pairs */ - j ^= j << 2; /* bits 3-2 have quads */ - j ^= j << 1; /* bit 3 has the entire eight (no cox) */ - b[i] = 8 & ~j; /* 0 is okay and 8 is bad parity */ - } - - /* only these characters can appear in a weak key */ - b[0x01] = 1; - b[0x0e] = 2; - b[0x1f] = 3; - b[0xe0] = 4; - b[0xf1] = 5; - b[0xfe] = 6; - - /* print it out */ - for ( i = 0; i < 256; i++ ) { - (void)printf("%d,", b[i]); - if ( (i & 31) == 31 ) - (void)printf("\n"); - } - - break; - - - /* - * <<< make the key usage table >>> - */ - -case 'r': - (void)printf("/* automagically made - do not fuss with this */\n\n"); - - /* KL specifies the initial key bit positions */ - for (i = 0; i < 56; i++) - ksr[i] = (KL[i] - 1) ^ 7; - - for (i = 0; i < 16; i++) { - - /* apply the appropriate number of left shifts */ - for (j = 0; j < KS[i]; j++) { - m = ksr[ 0]; - n = ksr[28]; - for (k = 0; k < 27; k++) - ksr[k ] = ksr[k + 1], - ksr[k + 28] = ksr[k + 29]; - ksr[27] = m; - ksr[55] = n; - } - - /* output the key bit numbers */ - for (j = 0; j < 48; j++) { - m = ksr[KC[korder[j]] - 1]; - m = (m / 8) * 7 + (m % 8) - 1; - m = 55 - m; - (void)printf(" %2ld,", (long) m); - if ((j % 12) == 11) - (void)printf("\n"); - } - (void)printf("\n"); - } - - break; - - - /* - * <<< make the keymap table >>> - */ - -case 'k': - (void)printf("/* automagically made - do not fuss with this */\n\n"); - - for ( i = 0; i <= 7 ; i++ ) { - s = sorder[i]; - for ( d = 0; d <= 63; d++ ) { - /* flip bits */ - k = ((d << 5) & 32) | - ((d << 3) & 16) | - ((d << 1) & 8) | - ((d >> 1) & 4) | - ((d >> 3) & 2) | - ((d >> 5) & 1) ; - /* more bit twiddling */ - l = ((k << 0) & 32) | /* overlap bit */ - ((k << 4) & 16) | /* overlap bit */ - ((k >> 1) & 15) ; /* unique bits */ - /* look up s box value */ - m = SB[s][l]; - /* flip bits */ - n = ((m << 3) & 8) | - ((m << 1) & 4) | - ((m >> 1) & 2) | - ((m >> 3) & 1) ; - /* put in correct nybble */ - n <<= (s << 2); - /* perform p permutation */ - for ( m = j = 0; j < 32; j++ ) - if ( n & (1 << (SP[j] - 1)) ) - m |= (1 << j); - /* rotate right (alg keeps everything rotated by 1) */ - ROR(m, 1, 31); - /* print it out */ - (void)printf(" 0x%08lx,", (long) m); - if ( ( d & 3 ) == 3 ) - (void)printf("\n"); - } - (void)printf("\n"); - } - - break; - - } - - return 0; -} diff --git a/lsh/src/nettle/desinfo.h b/lsh/src/nettle/desinfo.h deleted file mode 100644 index 0c4ce3b..0000000 --- a/lsh/src/nettle/desinfo.h +++ /dev/null @@ -1,96 +0,0 @@ -/* desinfo.h - * - * Tables describing DES rather than just this implementation. - * These are used in desdata but NOT in runtime code. - * - * $Id$ */ - -/* des - fast & portable DES encryption & decryption. - * Copyright (C) 1992 Dana L. How - * Please see the file `descore.README' for the complete copyright notice. - */ - -/* the initial permutation, E selection, and final permutation are hardwired */ - -/* Key Load: how to load the shift register from the user key */ - -unsigned char KL[] = { - - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4, -}; - -/* Key Shift: how many times to shift the key shift register */ - -unsigned char KS[] = { - - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, -}; - -/* Key Choose: which key bits from shift reg are used in the key schedule */ - -unsigned char KC[] = { - - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32, -}; - -/* S Boxes */ - -unsigned char SB[8][64] = { - { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, - },{ - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, - },{ - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, - },{ - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, - },{ - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, - },{ - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, - },{ - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, - },{ - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 - } -}; - -/* Sbox Permutation */ - -char SP[] = { - - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25, -}; diff --git a/lsh/src/nettle/install-sh b/lsh/src/nettle/install-sh deleted file mode 100644 index 6bfa7aa..0000000 --- a/lsh/src/nettle/install-sh +++ /dev/null @@ -1,241 +0,0 @@ -#! /bin/sh -# -# $Id$ -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 - diff --git a/lsh/src/nettle/keymap.h b/lsh/src/nettle/keymap.h deleted file mode 100644 index 5600c32..0000000 --- a/lsh/src/nettle/keymap.h +++ /dev/null @@ -1,138 +0,0 @@ -/* automagically made - do not fuss with this */ - - 0x02080008, 0x02082000, 0x00002008, 0x00000000, - 0x02002000, 0x00080008, 0x02080000, 0x02082008, - 0x00000008, 0x02000000, 0x00082000, 0x00002008, - 0x00082008, 0x02002008, 0x02000008, 0x02080000, - 0x00002000, 0x00082008, 0x00080008, 0x02002000, - 0x02082008, 0x02000008, 0x00000000, 0x00082000, - 0x02000000, 0x00080000, 0x02002008, 0x02080008, - 0x00080000, 0x00002000, 0x02082000, 0x00000008, - 0x00080000, 0x00002000, 0x02000008, 0x02082008, - 0x00002008, 0x02000000, 0x00000000, 0x00082000, - 0x02080008, 0x02002008, 0x02002000, 0x00080008, - 0x02082000, 0x00000008, 0x00080008, 0x02002000, - 0x02082008, 0x00080000, 0x02080000, 0x02000008, - 0x00082000, 0x00002008, 0x02002008, 0x02080000, - 0x00000008, 0x02082000, 0x00082008, 0x00000000, - 0x02000000, 0x02080008, 0x00002000, 0x00082008, - - 0x08000004, 0x00020004, 0x00000000, 0x08020200, - 0x00020004, 0x00000200, 0x08000204, 0x00020000, - 0x00000204, 0x08020204, 0x00020200, 0x08000000, - 0x08000200, 0x08000004, 0x08020000, 0x00020204, - 0x00020000, 0x08000204, 0x08020004, 0x00000000, - 0x00000200, 0x00000004, 0x08020200, 0x08020004, - 0x08020204, 0x08020000, 0x08000000, 0x00000204, - 0x00000004, 0x00020200, 0x00020204, 0x08000200, - 0x00000204, 0x08000000, 0x08000200, 0x00020204, - 0x08020200, 0x00020004, 0x00000000, 0x08000200, - 0x08000000, 0x00000200, 0x08020004, 0x00020000, - 0x00020004, 0x08020204, 0x00020200, 0x00000004, - 0x08020204, 0x00020200, 0x00020000, 0x08000204, - 0x08000004, 0x08020000, 0x00020204, 0x00000000, - 0x00000200, 0x08000004, 0x08000204, 0x08020200, - 0x08020000, 0x00000204, 0x00000004, 0x08020004, - - 0x80040100, 0x01000100, 0x80000000, 0x81040100, - 0x00000000, 0x01040000, 0x81000100, 0x80040000, - 0x01040100, 0x81000000, 0x01000000, 0x80000100, - 0x81000000, 0x80040100, 0x00040000, 0x01000000, - 0x81040000, 0x00040100, 0x00000100, 0x80000000, - 0x00040100, 0x81000100, 0x01040000, 0x00000100, - 0x80000100, 0x00000000, 0x80040000, 0x01040100, - 0x01000100, 0x81040000, 0x81040100, 0x00040000, - 0x81040000, 0x80000100, 0x00040000, 0x81000000, - 0x00040100, 0x01000100, 0x80000000, 0x01040000, - 0x81000100, 0x00000000, 0x00000100, 0x80040000, - 0x00000000, 0x81040000, 0x01040100, 0x00000100, - 0x01000000, 0x81040100, 0x80040100, 0x00040000, - 0x81040100, 0x80000000, 0x01000100, 0x80040100, - 0x80040000, 0x00040100, 0x01040000, 0x81000100, - 0x80000100, 0x01000000, 0x81000000, 0x01040100, - - 0x04010801, 0x00000000, 0x00010800, 0x04010000, - 0x04000001, 0x00000801, 0x04000800, 0x00010800, - 0x00000800, 0x04010001, 0x00000001, 0x04000800, - 0x00010001, 0x04010800, 0x04010000, 0x00000001, - 0x00010000, 0x04000801, 0x04010001, 0x00000800, - 0x00010801, 0x04000000, 0x00000000, 0x00010001, - 0x04000801, 0x00010801, 0x04010800, 0x04000001, - 0x04000000, 0x00010000, 0x00000801, 0x04010801, - 0x00010001, 0x04010800, 0x04000800, 0x00010801, - 0x04010801, 0x00010001, 0x04000001, 0x00000000, - 0x04000000, 0x00000801, 0x00010000, 0x04010001, - 0x00000800, 0x04000000, 0x00010801, 0x04000801, - 0x04010800, 0x00000800, 0x00000000, 0x04000001, - 0x00000001, 0x04010801, 0x00010800, 0x04010000, - 0x04010001, 0x00010000, 0x00000801, 0x04000800, - 0x04000801, 0x00000001, 0x04010000, 0x00010800, - - 0x00000400, 0x00000020, 0x00100020, 0x40100000, - 0x40100420, 0x40000400, 0x00000420, 0x00000000, - 0x00100000, 0x40100020, 0x40000020, 0x00100400, - 0x40000000, 0x00100420, 0x00100400, 0x40000020, - 0x40100020, 0x00000400, 0x40000400, 0x40100420, - 0x00000000, 0x00100020, 0x40100000, 0x00000420, - 0x40100400, 0x40000420, 0x00100420, 0x40000000, - 0x40000420, 0x40100400, 0x00000020, 0x00100000, - 0x40000420, 0x00100400, 0x40100400, 0x40000020, - 0x00000400, 0x00000020, 0x00100000, 0x40100400, - 0x40100020, 0x40000420, 0x00000420, 0x00000000, - 0x00000020, 0x40100000, 0x40000000, 0x00100020, - 0x00000000, 0x40100020, 0x00100020, 0x00000420, - 0x40000020, 0x00000400, 0x40100420, 0x00100000, - 0x00100420, 0x40000000, 0x40000400, 0x40100420, - 0x40100000, 0x00100420, 0x00100400, 0x40000400, - - 0x00800000, 0x00001000, 0x00000040, 0x00801042, - 0x00801002, 0x00800040, 0x00001042, 0x00801000, - 0x00001000, 0x00000002, 0x00800002, 0x00001040, - 0x00800042, 0x00801002, 0x00801040, 0x00000000, - 0x00001040, 0x00800000, 0x00001002, 0x00000042, - 0x00800040, 0x00001042, 0x00000000, 0x00800002, - 0x00000002, 0x00800042, 0x00801042, 0x00001002, - 0x00801000, 0x00000040, 0x00000042, 0x00801040, - 0x00801040, 0x00800042, 0x00001002, 0x00801000, - 0x00001000, 0x00000002, 0x00800002, 0x00800040, - 0x00800000, 0x00001040, 0x00801042, 0x00000000, - 0x00001042, 0x00800000, 0x00000040, 0x00001002, - 0x00800042, 0x00000040, 0x00000000, 0x00801042, - 0x00801002, 0x00801040, 0x00000042, 0x00001000, - 0x00001040, 0x00801002, 0x00800040, 0x00000042, - 0x00000002, 0x00001042, 0x00801000, 0x00800002, - - 0x10400000, 0x00404010, 0x00000010, 0x10400010, - 0x10004000, 0x00400000, 0x10400010, 0x00004010, - 0x00400010, 0x00004000, 0x00404000, 0x10000000, - 0x10404010, 0x10000010, 0x10000000, 0x10404000, - 0x00000000, 0x10004000, 0x00404010, 0x00000010, - 0x10000010, 0x10404010, 0x00004000, 0x10400000, - 0x10404000, 0x00400010, 0x10004010, 0x00404000, - 0x00004010, 0x00000000, 0x00400000, 0x10004010, - 0x00404010, 0x00000010, 0x10000000, 0x00004000, - 0x10000010, 0x10004000, 0x00404000, 0x10400010, - 0x00000000, 0x00404010, 0x00004010, 0x10404000, - 0x10004000, 0x00400000, 0x10404010, 0x10000000, - 0x10004010, 0x10400000, 0x00400000, 0x10404010, - 0x00004000, 0x00400010, 0x10400010, 0x00004010, - 0x00400010, 0x00000000, 0x10404000, 0x10000010, - 0x10400000, 0x10004010, 0x00000010, 0x00404000, - - 0x00208080, 0x00008000, 0x20200000, 0x20208080, - 0x00200000, 0x20008080, 0x20008000, 0x20200000, - 0x20008080, 0x00208080, 0x00208000, 0x20000080, - 0x20200080, 0x00200000, 0x00000000, 0x20008000, - 0x00008000, 0x20000000, 0x00200080, 0x00008080, - 0x20208080, 0x00208000, 0x20000080, 0x00200080, - 0x20000000, 0x00000080, 0x00008080, 0x20208000, - 0x00000080, 0x20200080, 0x20208000, 0x00000000, - 0x00000000, 0x20208080, 0x00200080, 0x20008000, - 0x00208080, 0x00008000, 0x20000080, 0x00200080, - 0x20208000, 0x00000080, 0x00008080, 0x20200000, - 0x20008080, 0x20000000, 0x20200000, 0x00208000, - 0x20208080, 0x00008080, 0x00208000, 0x20200080, - 0x00200000, 0x20000080, 0x20008000, 0x00000000, - 0x00008000, 0x00200000, 0x20200080, 0x00208080, - 0x20000000, 0x20208000, 0x00000080, 0x20008080, - diff --git a/lsh/src/nettle/macros.h b/lsh/src/nettle/macros.h deleted file mode 100644 index 4111515..0000000 --- a/lsh/src/nettle/macros.h +++ /dev/null @@ -1,78 +0,0 @@ -/* macros.h - * - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_MACROS_H_INCLUDED -#define NETTLE_MACROS_H_INCLUDED - -#if !MACOS || !defined(READ_UINT32) - -/* Reads a 32-bit integer, in network, big-endian, byte order */ -#define READ_UINT32(p) \ -( (((uint32_t) (p)[0]) << 24) \ - | (((uint32_t) (p)[1]) << 16) \ - | (((uint32_t) (p)[2]) << 8) \ - | ((uint32_t) (p)[3])) - -#endif - -#if !MACOS || !defined(WRITE_UINT32) - -#define WRITE_UINT32(p, i) \ -do { \ - (p)[0] = ((i) >> 24) & 0xff; \ - (p)[1] = ((i) >> 16) & 0xff; \ - (p)[2] = ((i) >> 8) & 0xff; \ - (p)[3] = (i) & 0xff; \ -} while(0) - -#endif - - -/* And the other, little-endian, byteorder */ -#define LE_READ_UINT32(p) \ -( (((uint32_t) (p)[3]) << 24) \ - | (((uint32_t) (p)[2]) << 16) \ - | (((uint32_t) (p)[1]) << 8) \ - | ((uint32_t) (p)[0])) - -#define LE_WRITE_UINT32(p, i) \ -do { \ - (p)[3] = ((i) >> 24) & 0xff; \ - (p)[2] = ((i) >> 16) & 0xff; \ - (p)[1] = ((i) >> 8) & 0xff; \ - (p)[0] = (i) & 0xff; \ -} while(0) - -#if !MACOS || !defined(FOR_BLOCKS) - -/* Macro to make it easier to loop over several blocks. */ -#define FOR_BLOCKS(length, dst, src, blocksize) \ - assert( !((length) % (blocksize))); \ - for (; (length); ((length) -= (blocksize), \ - (dst) += (blocksize), \ - (src) += (blocksize)) ) - -#endif - -#endif /* NETTLE_MACROS_H_INCLUDED */ diff --git a/lsh/src/nettle/md5.c b/lsh/src/nettle/md5.c deleted file mode 100644 index c0d45ad..0000000 --- a/lsh/src/nettle/md5.c +++ /dev/null @@ -1,282 +0,0 @@ -/* md5.c - * - * The md5 hash function. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* Based on public domain code hacked by Colin Plumb, Andrew Kuchling, and - * Niels Möller. */ - -#include "md5.h" - -#include "macros.h" - -#include - -/* A block, treated as a sequence of 32-bit words. */ -#define MD5_DATA_LENGTH 16 - -static void -md5_transform(uint32_t *digest, const uint32_t *data); - -static void -md5_block(struct md5_ctx *ctx, const uint8_t *block); - -void -md5_init(struct md5_ctx *ctx) -{ - ctx->digest[0] = 0x67452301; - ctx->digest[1] = 0xefcdab89; - ctx->digest[2] = 0x98badcfe; - ctx->digest[3] = 0x10325476; - - ctx->count_l = ctx->count_h = 0; - ctx->index = 0; -} - -void -md5_update(struct md5_ctx *ctx, - unsigned length, - const uint8_t *data) -{ - if (ctx->index) - { - /* Try to fill partial block */ - unsigned left = MD5_DATA_SIZE - ctx->index; - if (length < left) - { - memcpy(ctx->block + ctx->index, data, length); - ctx->index += length; - return; /* Finished */ - } - else - { - memcpy(ctx->block + ctx->index, data, left); - md5_block(ctx, ctx->block); - data += left; - length -= left; - } - } - while (length >= MD5_DATA_SIZE) - { - md5_block(ctx, data); - data += MD5_DATA_SIZE; - length -= MD5_DATA_SIZE; - } - if ((ctx->index = length)) /* This assignment is intended */ - /* Buffer leftovers */ - memcpy(ctx->block, data, length); -} - -/* Final wrapup - pad to MD5_DATA_SIZE-byte boundary with the bit - * pattern 1 0* (64-bit count of bits processed, LSB-first) */ - -void -md5_final(struct md5_ctx *ctx) -{ - uint32_t data[MD5_DATA_LENGTH]; - unsigned i; - unsigned words; - - i = ctx->index; - - /* Set the first char of padding to 0x80. This is safe since there - * is always at least one byte free */ - assert(i < MD5_DATA_SIZE); - ctx->block[i++] = 0x80; - - /* Fill rest of word */ - for( ; i & 3; i++) - ctx->block[i] = 0; - - /* i is now a multiple of the word size 4 */ - words = i >> 2; - for (i = 0; i < words; i++) - data[i] = LE_READ_UINT32(ctx->block + 4*i); - - if (words > (MD5_DATA_LENGTH-2)) - { /* No room for length in this block. Process it and - * pad with another one */ - for (i = words ; i < MD5_DATA_LENGTH; i++) - data[i] = 0; - md5_transform(ctx->digest, data); - for (i = 0; i < (MD5_DATA_LENGTH-2); i++) - data[i] = 0; - } - else - for (i = words ; i < MD5_DATA_LENGTH - 2; i++) - data[i] = 0; - - /* There are 512 = 2^9 bits in one block - * Little-endian order => Least significant word first */ - - data[MD5_DATA_LENGTH-1] = (ctx->count_h << 9) | (ctx->count_l >> 23); - data[MD5_DATA_LENGTH-2] = (ctx->count_l << 9) | (ctx->index << 3); - md5_transform(ctx->digest, data); -} - -void -md5_digest(const struct md5_ctx *ctx, - unsigned length, - uint8_t *digest) -{ - unsigned i; - unsigned words; - unsigned leftover; - - assert(length <= MD5_DIGEST_SIZE); - - words = length / 4; - leftover = length % 4; - - /* Little endian order */ - for (i = 0; i < words; i++, digest += 4) - LE_WRITE_UINT32(digest, ctx->digest[i]); - - if (leftover) - { - uint32_t word; - unsigned j; - - assert(i < _MD5_DIGEST_LENGTH); - - /* Still least significant byte first. */ - for (word = ctx->digest[i], j = 0; j < leftover; - j++, word >>= 8) - digest[j] = word & 0xff; - } -} - -/* MD5 functions */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -#define ROUND(f, w, x, y, z, data, s) \ -( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* Perform the MD5 transformation on one full block of 16 32-bit - * words. - * - * Compresses 20 (_MD5_DIGEST_LENGTH + MD5_DATA_LENGTH) words into 4 - * (_MD5_DIGEST_LENGTH) words. */ - -static void -md5_transform(uint32_t *digest, const uint32_t *data) -{ - uint32_t a, b, c, d; - a = digest[0]; - b = digest[1]; - c = digest[2]; - d = digest[3]; - - ROUND(F1, a, b, c, d, data[ 0] + 0xd76aa478, 7); - ROUND(F1, d, a, b, c, data[ 1] + 0xe8c7b756, 12); - ROUND(F1, c, d, a, b, data[ 2] + 0x242070db, 17); - ROUND(F1, b, c, d, a, data[ 3] + 0xc1bdceee, 22); - ROUND(F1, a, b, c, d, data[ 4] + 0xf57c0faf, 7); - ROUND(F1, d, a, b, c, data[ 5] + 0x4787c62a, 12); - ROUND(F1, c, d, a, b, data[ 6] + 0xa8304613, 17); - ROUND(F1, b, c, d, a, data[ 7] + 0xfd469501, 22); - ROUND(F1, a, b, c, d, data[ 8] + 0x698098d8, 7); - ROUND(F1, d, a, b, c, data[ 9] + 0x8b44f7af, 12); - ROUND(F1, c, d, a, b, data[10] + 0xffff5bb1, 17); - ROUND(F1, b, c, d, a, data[11] + 0x895cd7be, 22); - ROUND(F1, a, b, c, d, data[12] + 0x6b901122, 7); - ROUND(F1, d, a, b, c, data[13] + 0xfd987193, 12); - ROUND(F1, c, d, a, b, data[14] + 0xa679438e, 17); - ROUND(F1, b, c, d, a, data[15] + 0x49b40821, 22); - - ROUND(F2, a, b, c, d, data[ 1] + 0xf61e2562, 5); - ROUND(F2, d, a, b, c, data[ 6] + 0xc040b340, 9); - ROUND(F2, c, d, a, b, data[11] + 0x265e5a51, 14); - ROUND(F2, b, c, d, a, data[ 0] + 0xe9b6c7aa, 20); - ROUND(F2, a, b, c, d, data[ 5] + 0xd62f105d, 5); - ROUND(F2, d, a, b, c, data[10] + 0x02441453, 9); - ROUND(F2, c, d, a, b, data[15] + 0xd8a1e681, 14); - ROUND(F2, b, c, d, a, data[ 4] + 0xe7d3fbc8, 20); - ROUND(F2, a, b, c, d, data[ 9] + 0x21e1cde6, 5); - ROUND(F2, d, a, b, c, data[14] + 0xc33707d6, 9); - ROUND(F2, c, d, a, b, data[ 3] + 0xf4d50d87, 14); - ROUND(F2, b, c, d, a, data[ 8] + 0x455a14ed, 20); - ROUND(F2, a, b, c, d, data[13] + 0xa9e3e905, 5); - ROUND(F2, d, a, b, c, data[ 2] + 0xfcefa3f8, 9); - ROUND(F2, c, d, a, b, data[ 7] + 0x676f02d9, 14); - ROUND(F2, b, c, d, a, data[12] + 0x8d2a4c8a, 20); - - ROUND(F3, a, b, c, d, data[ 5] + 0xfffa3942, 4); - ROUND(F3, d, a, b, c, data[ 8] + 0x8771f681, 11); - ROUND(F3, c, d, a, b, data[11] + 0x6d9d6122, 16); - ROUND(F3, b, c, d, a, data[14] + 0xfde5380c, 23); - ROUND(F3, a, b, c, d, data[ 1] + 0xa4beea44, 4); - ROUND(F3, d, a, b, c, data[ 4] + 0x4bdecfa9, 11); - ROUND(F3, c, d, a, b, data[ 7] + 0xf6bb4b60, 16); - ROUND(F3, b, c, d, a, data[10] + 0xbebfbc70, 23); - ROUND(F3, a, b, c, d, data[13] + 0x289b7ec6, 4); - ROUND(F3, d, a, b, c, data[ 0] + 0xeaa127fa, 11); - ROUND(F3, c, d, a, b, data[ 3] + 0xd4ef3085, 16); - ROUND(F3, b, c, d, a, data[ 6] + 0x04881d05, 23); - ROUND(F3, a, b, c, d, data[ 9] + 0xd9d4d039, 4); - ROUND(F3, d, a, b, c, data[12] + 0xe6db99e5, 11); - ROUND(F3, c, d, a, b, data[15] + 0x1fa27cf8, 16); - ROUND(F3, b, c, d, a, data[ 2] + 0xc4ac5665, 23); - - ROUND(F4, a, b, c, d, data[ 0] + 0xf4292244, 6); - ROUND(F4, d, a, b, c, data[ 7] + 0x432aff97, 10); - ROUND(F4, c, d, a, b, data[14] + 0xab9423a7, 15); - ROUND(F4, b, c, d, a, data[ 5] + 0xfc93a039, 21); - ROUND(F4, a, b, c, d, data[12] + 0x655b59c3, 6); - ROUND(F4, d, a, b, c, data[ 3] + 0x8f0ccc92, 10); - ROUND(F4, c, d, a, b, data[10] + 0xffeff47d, 15); - ROUND(F4, b, c, d, a, data[ 1] + 0x85845dd1, 21); - ROUND(F4, a, b, c, d, data[ 8] + 0x6fa87e4f, 6); - ROUND(F4, d, a, b, c, data[15] + 0xfe2ce6e0, 10); - ROUND(F4, c, d, a, b, data[ 6] + 0xa3014314, 15); - ROUND(F4, b, c, d, a, data[13] + 0x4e0811a1, 21); - ROUND(F4, a, b, c, d, data[ 4] + 0xf7537e82, 6); - ROUND(F4, d, a, b, c, data[11] + 0xbd3af235, 10); - ROUND(F4, c, d, a, b, data[ 2] + 0x2ad7d2bb, 15); - ROUND(F4, b, c, d, a, data[ 9] + 0xeb86d391, 21); - - digest[0] += a; - digest[1] += b; - digest[2] += c; - digest[3] += d; -} - -static void -md5_block(struct md5_ctx *ctx, const uint8_t *block) -{ - uint32_t data[MD5_DATA_LENGTH]; - unsigned i; - - /* Update block count */ - if (!++ctx->count_l) - ++ctx->count_h; - - /* Endian independent conversion */ - for (i = 0; i<16; i++, block += 4) - data[i] = LE_READ_UINT32(block); - - md5_transform(ctx->digest, data); -} diff --git a/lsh/src/nettle/md5.h b/lsh/src/nettle/md5.h deleted file mode 100644 index b376f7d..0000000 --- a/lsh/src/nettle/md5.h +++ /dev/null @@ -1,61 +0,0 @@ -/* md5.h - * - * The md5 hash function. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_MD5_H_INCLUDED -#define NETTLE_MD5_H_INCLUDED - -#include - -#define MD5_DIGEST_SIZE 16 -#define MD5_DATA_SIZE 64 - -/* Digest is kept internally as 4 32-bit words. */ -#define _MD5_DIGEST_LENGTH 4 - -struct md5_ctx -{ - uint32_t digest[_MD5_DIGEST_LENGTH]; - uint32_t count_l, count_h; /* Block count */ - uint8_t block[MD5_DATA_SIZE]; /* Block buffer */ - unsigned index; /* Into buffer */ -}; - -void -md5_init(struct md5_ctx *ctx); - -void -md5_update(struct md5_ctx *ctx, - unsigned length, - const uint8_t *data); - -void -md5_final(struct md5_ctx *ctx); - -void -md5_digest(const struct md5_ctx *ctx, - unsigned length, - uint8_t *digest); - -#endif /* NETTLE_MD5_H_INCLUDED */ diff --git a/lsh/src/nettle/memxor.c b/lsh/src/nettle/memxor.c deleted file mode 100644 index b3a8ae2..0000000 --- a/lsh/src/nettle/memxor.c +++ /dev/null @@ -1,19 +0,0 @@ -/* memxor.c - * - * $Id$ - */ - -/* XOR LEN bytes starting at SRCADDR onto DESTADDR. Result undefined - if the source overlaps with the destination. - Return DESTADDR. */ - -#include "memxor.h" - -uint8_t *memxor(uint8_t *dst, const uint8_t *src, size_t n) -{ - size_t i; - for (i = 0; i -#include - -uint8_t *memxor(uint8_t *dst, const uint8_t *src, size_t n); - -#endif /* NETTLE_MEMXOR_H_INCLUDED */ diff --git a/lsh/src/nettle/missing b/lsh/src/nettle/missing deleted file mode 100644 index 7789652..0000000 --- a/lsh/src/nettle/missing +++ /dev/null @@ -1,190 +0,0 @@ -#! /bin/sh -# Common stub for a few missing GNU programs while installing. -# Copyright (C) 1996, 1997 Free Software Foundation, Inc. -# Franc,ois Pinard , 1996. - -# 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, or (at your option) -# any later version. - -# This program 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 should 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. - -if test $# -eq 0; then - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 -fi - -case "$1" in - - -h|--h|--he|--hel|--help) - echo "\ -$0 [OPTION]... PROGRAM [ARGUMENT]... - -Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an -error status if there is no known handling for PROGRAM. - -Options: - -h, --help display this help and exit - -v, --version output version information and exit - -Supported PROGRAM values: - aclocal touch file \`aclocal.m4' - autoconf touch file \`configure' - autoheader touch file \`config.h.in' - automake touch all \`Makefile.in' files - bison create \`y.tab.[ch]', if possible, from existing .[ch] - flex create \`lex.yy.c', if possible, from existing .c - lex create \`lex.yy.c', if possible, from existing .c - makeinfo touch the output file - yacc create \`y.tab.[ch]', if possible, from existing .[ch]" - ;; - - -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing - GNU libit 0.0" - ;; - - -*) - echo 1>&2 "$0: Unknown \`$1' option" - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 - ;; - - aclocal) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`acinclude.m4' or \`configure.in'. You might want - to install the \`Automake' and \`Perl' packages. Grab them from - any GNU archive site." - touch aclocal.m4 - ;; - - autoconf) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`configure.in'. You might want to install the - \`Autoconf' and \`GNU m4' packages. Grab them from any GNU - archive site." - touch configure - ;; - - autoheader) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`acconfig.h' or \`configure.in'. You might want - to install the \`Autoconf' and \`GNU m4' packages. Grab them - from any GNU archive site." - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in` - test -z "$files" && files="config.h" - touch_files= - for f in $files; do - case "$f" in - *:*) touch_files="$touch_files "`echo "$f" | - sed -e 's/^[^:]*://' -e 's/:.*//'`;; - *) touch_files="$touch_files $f.in";; - esac - done - touch $touch_files - ;; - - automake) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`Makefile.am', \`acinclude.m4' or \`configure.in'. - You might want to install the \`Automake' and \`Perl' packages. - Grab them from any GNU archive site." - find . -type f -name Makefile.am -print | - sed 's/\.am$/.in/' | - while read f; do touch "$f"; done - ;; - - bison|yacc) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.y' file. You may need the \`Bison' package - in order for those modifications to take effect. You can get - \`Bison' from any GNU archive site." - rm -f y.tab.c y.tab.h - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.y) - SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.c - fi - SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.h - fi - ;; - esac - fi - if [ ! -f y.tab.h ]; then - echo >y.tab.h - fi - if [ ! -f y.tab.c ]; then - echo 'main() { return 0; }' >y.tab.c - fi - ;; - - lex|flex) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.l' file. You may need the \`Flex' package - in order for those modifications to take effect. You can get - \`Flex' from any GNU archive site." - rm -f lex.yy.c - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.l) - SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" lex.yy.c - fi - ;; - esac - fi - if [ ! -f lex.yy.c ]; then - echo 'main() { return 0; }' >lex.yy.c - fi - ;; - - makeinfo) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.texi' or \`.texinfo' file, or any other file - indirectly affecting the aspect of the manual. The spurious - call might also be the consequence of using a buggy \`make' (AIX, - DU, IRIX). You might want to install the \`Texinfo' package or - the \`GNU make' package. Grab either from any GNU archive site." - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` - file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` - fi - touch $file - ;; - - *) - echo 1>&2 "\ -WARNING: \`$1' is needed, and you do not seem to have it handy on your - system. You might have modified some files without having the - proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequirements for installing - this package. You may also peek at any GNU archive site, in case - some other package would contain this missing \`$1' program." - exit 1 - ;; -esac - -exit 0 diff --git a/lsh/src/nettle/mkinstalldirs b/lsh/src/nettle/mkinstalldirs deleted file mode 100644 index 6b3b5fc..0000000 --- a/lsh/src/nettle/mkinstalldirs +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -# $Id$ - -errstatus=0 - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# mkinstalldirs ends here diff --git a/lsh/src/nettle/nettle.html b/lsh/src/nettle/nettle.html deleted file mode 100644 index cc0f35b..0000000 --- a/lsh/src/nettle/nettle.html +++ /dev/null @@ -1,1518 +0,0 @@ - -The Nettle low-level cryptographic library. - - - - - - -


-Node:Top, -Next:, -Previous:(dir), -Up:(dir) -
- -

- -

This document describes the nettle low-level cryptographic library. You -can use the library directly from your C-programs, or (recommended) -write or use an object-oriented wrapper for your favourite language or -application. - -

This manual coresponds to version 0.2 of the library. - -

- -


-Node:Introduction, -Next:, -Previous:Top, -Up:Top -
- -

Introduction

- -

Nettle is a cryptographic library that is designed to fit easily in more -or less any context: In crypto toolkits for object-oriented languages -(C++, Python, Pike, ...), in applications like LSH or GNUPG, or even in -kernel space. In most contexts, you need more than the basic -cryptographic algorithms, you also need some way to keep track of available -algorithms, their properties and variants. You often have some algorithm -selection process, often dictated by a protocol you want to implement. - -

And as the requirements of applications differ on subtle and not so -subtle ways, an API that fits one application well can be a pain to use -in a different context. And that is why there are so many different -cryptographic libraries around. - -

Nettle tries to avoid this problem by doing one thing, the low-level -crypto stuff, and providing a simple but general interface to it. -In particular, Nettle doesn't do algorithm selection. It doesn't do -memory allocation. It doesn't do any I/O. - -

The idea is that one can build several application and context specific -interfaces on top of Nettle, and share the code, testcases, banchmarks, -documentation, etc. For this first version, the only application using -Nettle is LSH, and it uses an object-oriented abstraction on top of the -library. - -


-Node:Copyright, -Next:, -Previous:Introduction, -Up:Top -
- -

Copyright

- -

Nettle is distributed under the GNU General Public License (see the file -COPYING for details). However, many of the individual files are dual -licensed under less restrictive licenses like the GNU Lesser General -Public License, or public domain. Consult the headers in each file for -details. - -

It is conceivable that future versions will use the LGPL rather than the -GPL, mail me if you have questions or suggestions. - -

A list of the supported algorithms, their origins and licenses: - -

-
AES -
The implementation of the AES cipher (also known as rijndael) is written -by Rafael Sevilla. Released under the LGPL. - -
ARCFOUR -
The implementation of the ARCFOUR (also known as RC4) cipher is written -by Niels Möller. Released under the LGPL. - -
BLOWFISH -
The implementation of the BLOWFISH cipher is written by Werner Koch, -copyright owned by the Free Software Foundation. Also hacked by Ray -Dassen and Niels Möller. Released under the GPL. - -
CAST128 -
The implementation of the CAST128 cipher is written by Steve Reid. -Released into the public domain. - -
DES -
The implementation of the DES cipher is written by Dana L. How, and -released under the LGPL. - -
MD5 -
The implementation of the MD5 message digest is written by Colin Plumb. -It has been hacked some more by Andrew Kuchling and Niels Möller. -Released into the public domain. - -
SERPENT -
The implementation of the SERPENT cipher is written by Ross Anderson, -Eli Biham, and Lars Knudsen, adapted to LSH by Rafael Sevilla, and to -Nettle by Niels Möller. - -
SHA1 -
The implementation of the SHA1 message digest is written by Peter -Gutmann, and hacked some more by Andrew Kuchling and Niels Möller. -Released into the public domain. - -
TWOFISH -
The implementation of the TWOFISH cipher is written by Ruud de Rooij. -Released under the LGPL. -
- -


-Node:Conventions, -Next:, -Previous:Copyright, -Up:Top -
- -

Conventions

- -

For each supported algorithm, there is an include file that defines a -context struct, a few constants, and declares functions for -operating on the state. The context struct encapsulates all information -needed by the algorithm, and it can be copied or moved in memory with no -unexpected effects. - -

The functions for similar algorithms are similar, but there are some -differences, for instance reflecting if the key setup or encryption -function differ for encryption and encryption, and whether or not key -setup can fail. There are also differences that doesn't show in function -prototypes, but which the application must nevertheless be aware of. -There is no difference between stream ciphers and block ciphers, -although they should be used quite differently by the application. - -

If your application uses more than one algorithm, you should probably -create an interface that is tailor-made for your needs, and then write a -few lines of glue code on top of Nettle. - -

By convention, for an algorithm named foo, the struct tag for the -context struct is foo_ctx, constants and functions uses prefixes -like FOO_BLOCK_SIZE (a constant) and foo_set_key (a -function). - -

In all functions, strings are represented with an explicit length, of -type unsigned, and a pointer of type uint8_t * or a -const uint8_t *. For functions that transform one string to -another, the argument order is length, destination pointer and source -pointer. Source and destination areas are of the same length. Source and -destination may be the same, so that you can process strings in place, -but they must not overlap in any other way. - -


-Node:Example, -Next:, -Previous:Conventions, -Up:Top -
- -

Example

- -

A simple example program that reads a file from standard in and writes -its SHA1 checksum on stdout should give the flavour of Nettle. - -

/* FIXME: This code is untested. */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <nettle/sha1.h>
-
-#define BUF_SIZE 1000
-
-static void
-display_hex(unsigned length, uint8_t *data)
-{
-  static const char digits[16] = "0123456789abcdef";
-  unsigned i;
-
-  for (i = 0; i<length; i++)
-  {
-    uint8_t byte = data[i];
-    printf("%c%c ", digits[(byte / 16) & 0xf], digits[byte & 0xf]);
-  }
-}
-
-int
-main(int argc, char **argv)
-{
-  struct sha1_ctx ctx;
-  uint8_t buffer[BUF_SIZE];
-  uint8_t digest[SHA1_DIGEST_SIZE];
-
-  sha1_init(&ctx);
-  for (;;)
-  {
-    int done = fread(buffer, 1, sizeof(buffer), stdin);
-    if (done <= 0)
-      break;
-    sha1_update(&ctx, done, buf);
-  }
-  if (ferror(stdin))
-    return EXIT_FAILURE;
-
-  sha1_finish(&ctx);
-  sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
-
-  display_hex(SHA1_DIGEST_SIZE, digest);
-  return EXIT_SUCCESS;
-}
-
- -


-Node:Reference, -Next:, -Previous:Example, -Up:Top -
- -

Reference

- -

This chapter describes all the Nettle functions, grouped by family. - -

- -


-Node:Hash functions, -Next:, -Previous:Reference, -Up:Reference -
- -

Hash functions

- -

A cryptographic hash function is a function that takes variable -size strings, and maps them to strings of fixed, short, length. There -are naturally lots of collisions, as there are more possible 1MB files -than 20 byte strings. But the function is constructed such that is hard -to find the collisions. More precisely, a cryptographic hash function -H should have the following properties: - -

- -
One-way -
Given a hash value H(x) it is hard to find a string x -that hashes to that value. - -
Collision-resistant -
It is hard to find two different strings, x and y, such -that H(x) = H(y). - -
- -

Hash functions are useful as building blocks for digital signatures, -message authentication codes, pseudo random generators, associating -unique id:s to documents, and many other things. - -

MD5

- -

MD5 is a message digest function constructed by Ronald Rivest, and -described in RFC 1321. It outputs message digests of 128 bits, or -16 octets. Nettle defines MD5 in <nettle/md5.h>. - -

- - - - - -
struct md5_ctx -Context struct
- - -
-
- -

- - - - - -
MD5_DIGEST_SIZE -Constant
- - -
-The size of an MD5 digest, i.e. 16. -
- -

- - - - - -
MD5_DATA_SIZE -Constant
- - -
-The internal block size of MD5. Useful for some special constructions, -in particular HMAC-MD5. -
- -

- - - - - -
void md5_init (struct md5_ctx *ctx) -Function
- - -
-Initialize the MD5 state. -
- -

- - - - - -
void md5_update (struct md5_ctx *ctx, unsigned length, const uint8_t *data) -Function
- - -
-Hash some more data. -
- -

- - - - - -
void md5_final (struct md5_ctx *ctx) -Function
- - -
-Performs final processing that is needed after all input data has been -processed with md5_update. -
- -

- - - - - -
void md5_digest (struct md5_ctx *ctx, unsigned length, uint8_t *digest) -Function
- - -
-Extracts the digest, writing it to digest. length may be smaller than -MD5_DIGEST_SIZE, in which case only the first length octets -of the digest are written. - -

This functions doesn't change the state in any way. -

- -

The normal way to use MD5 is to call the functions in order: First -md5_init, then md5_update zero or more times, then -md5_final, and at last md5_digest zero or more times. - -

To start over, you can call md5_init at any time. - -

SHA1

- -

SHA1 is a hash function specified by NIST (The U.S. National Institute -for Standards and Technology. It outputs hash values of 160 bits, or 20 -octets. Nettle defines SHA1 in <nettle/sha1.h>. - -

The functions are analogous to the MD5 ones. - -

- - - - - -
struct sha1_ctx -Context struct
- - -
-
- -

- - - - - -
SHA1_DIGEST_SIZE -Constant
- - -
-The size of an SHA1 digest, i.e. 20. -
- -

- - - - - -
SHA1_DATA_SIZE -Constant
- - -
-The internal block size of SHA1. Useful for some special constructions, -in particular HMAC-SHA1. -
- -

- - - - - -
void sha1_init (struct sha1_ctx *ctx) -Function
- - -
-Initialize the SHA1 state. -
- -

- - - - - -
void sha1_update (struct sha1_ctx *ctx, unsigned length, const uint8_t *data) -Function
- - -
-Hash some more data. -
- -

- - - - - -
void sha1_final (struct sha1_ctx *ctx) -Function
- - -
-Performs final processing that is needed after all input data has been -processed with sha1_update. -
- -

- - - - - -
void sha1_digest (struct sha1_ctx *ctx, unsigned length, uint8_t *digest) -Function
- - -
-Extracts the digest, writing it to digest. length may be smaller than -SHA1_DIGEST_SIZE, in which case only the first length octets -of the digest are written. - -

This functions doesn't change the state in any way. -

- -


-Node:Cipher functions, -Next:, -Previous:Hash functions, -Up:Reference -
- -

Cipher functions

- -

A cipher is a function that takes a message or plaintext -and a secret key and transforms it to a ciphertext. Given -only the ciphertext, but not the key, it should be hard to find the -cleartext. Given matching pairs of plaintext and ciphertext, it should -be hard to find the key. - -

To do this, you first initialize the cipher context for encryption or -decryption with a particular key, then use it to process plaintext och -ciphertext messages. The initialization is also called key setup. -With Nettle, it is recommended to use each context struct for only one -direction, even if some of the ciphers use a single key setup function -that can be used for both encryption and decryption. - -

There are two main classes of ciphers: Block ciphers and stream ciphers. - -

A block cipher can process data only in fixed size chunks, called -blocks. Typical block sizes are 8 or 16 octets. To encrypt -arbitrary messages, you usually have to pad it to an integral number of -blocks, split it into blocks, and then process each block. The simplest -way is to process one block at a time, independent of each other. That -mode of operation is called ECB, Electronic Code Book mode. -However, using ECB is usually a bad idea. For a start, plaintext blocks -that are equal are transformed to ciphertext blocks that are equal; that -leaks information about the plaintext. Usually you should apply the -cipher is some feedback mode, CBC (Cipher Block Chaining) being one -of the most popular. - -

A stream cipher can be used for messages of arbitrary length; a typical -stream cipher is a keyed pseudorandom generator. To encrypt a plaintext -message of n octets, you key the generator, generate n -octets of pseudorandom data, and XOR it with the plaintext. To decrypt, -regenerate the same stream using the key, XOR it to the ciphertext, and -the plaintext is recovered. - -

Caution: The first rule for this kind of cipher is the -same as for a One Time Pad: never ever use the same key twice. - -

A common misconception is that encryption, by itself, implies -authentication. Say that you and a friend share a secret key, and you -receive an encrypted message, apply the key, and get a cleartext message -that makes sense to you. Can you then be sure that it really was your -friend that wrote the message you're reading? The anser is no. For -example, if you were using a block cipher in ECB mode, an attacker may -pick up the message on its way, and reorder, delete or repeat some of -the blocks. Even if the attacker can't decrypt the message, he can -change it so that you are not reading the same message as your friend -wrote. If you are using a block cipher in CBC mode rather than ECB, or -are using a stream cipher, the possibilities for this sort of attack are -different, but the attacker can still make predictable changes to the -message. - -

It is recommended to always use an authentication mechanism in -addition to encrypting the messages. Popular choices are Message -Authetication Codes like HMAC-SHA1, or digital signatures. - -

Some ciphers have so called "weak keys", keys that results in -undesirable structure after the key setup processing, and should be -avoided. In Nettle, the presence of weak keys for a cipher mean that the -key setup function can fail, so you have to check its return value. In -addition, the context struct has a field status, that is set to a -non-zero value if key setup fails. When possible, avoid algorithm that -have weak keys. There are several good ciphers that don't have any weak -keys. - -

AES

- -

AES is a quite new block cipher, specified by NIST as a replacement for -the older DES standard. It is the result of a competition between cipher -designers, and the winning design, constructed by Joan Daemen and -Vincent Rijnmen. Before it won the competition, it was known under the -name RIJNDAEL. - -

Like all the AES candidates, the winning design uses a block size of 128 -bits, or 16 octets, and variable keysize, 128, 192 and 256 bits (16, 24 -and 32 octets) being the allowed key sizes. It does not have any weak -keys. Nettle defines AES in <nettle/aes.h>. - -

- - - - - -
struct aes_ctx -Context struct
- - -
-
- -

- - - - - -
AES_BLOCK_SIZE -Constant
- - -
-The AES blocksize, 16 -
- -

- - - - - -
AES_MIN_KEY_SIZE -Constant
- - -
-
- -

- - - - - -
AES_MAX_KEY_SIZE -Constant
- - -
-
- -

- - - - - -
AES_KEY_SIZE -Constant
- - -
-Default AES key size, 32 -
- -

- - - - - -
void aes_set_key (struct aes_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. -
- -

- - - - - -
void aes_encrypt (struct aes_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Encryption function. length must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. src and dst may be equal, but they must not overlap -in any other way. -
- -

- - - - - -
void aes_decrypt (struct aes_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Analogous to aes_encrypt -
- -

ARCFOUR

- -

ARCFOUR is a stream cipher, also known under the trade marked name RC4, -and it is one of the fastest ciphers around. A problem is that the key -setup of ARCFOUR is quite weak, you should never use keys with -structure, keys that are ordinary passwords, or sequences of keys like -"secret:1", "secret:2", ..... If you have keys that don't look -like random bit strings, and you want to use ARCFOUR, always hash the -key before feeding it to ARCFOUR. For example - -

/* A more robust key setup function for ARCFOUR */
-void
-my_arcfour_set_key(struct arcfour_ctx *ctx,
-                   unsigned length, const uint8_t *key)
-{
-  struct sha1_ctx hash;
-  uint8_t digest[SHA1_DIGEST_SIZE];
-
-  sha1_init(&hash);
-  sha1_update(&hash, length, key);
-  sha1_final(&hash);
-  sha1_digest(&hash, SHA1_DIGEST_SIZE, digest);
-
-  arcfour_set_key(ctx, SHA1_DIGEST_SIZE, digest);
-}
-
- -

Nettle defines ARCFOUR in <nettle/arcfour.h>. - -

- - - - - -
struct arcfour_ctx -Context struct
- - -
-
- -

- - - - - -
ARCFOUR_BLOCK_SIZE -Constant
- - -
-The ARCFOUR blocksize, 16 -
- -

- - - - - -
ARCFOUR_MIN_KEY_SIZE -Constant
- - -
-Minimum key size, 1 -
- -

- - - - - -
ARCFOUR_MAX_KEY_SIZE -Constant
- - -
-Maximum key size, 256 -
- -

- - - - - -
ARCFOUR_KEY_SIZE -Constant
- - -
-Default ARCFOUR key size, 16 -
- -

- - - - - -
void arcfour_set_key (struct arcfour_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. -
- -

- - - - - -
void arcfour_crypt (struct arcfour_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Encrypt some data. The same function is used for both encryption and -decryption. Unlike the block ciphers, this function modifies the -context, so you can split the data into arbitrary chunks and encrypt -them one after another. The result is the same as if you had called -arcfour_crypt only once with all the data. -
- -

CAST128

- -

CAST-128 is a block cipher, specified in RFC 2144. It uses a 64 -bit (8 octets) block size, and a variable key size of up to 128 bits. -Nettle defines cast128 in <nettle/cast128.h>. - -

- - - - - -
struct cast128_ctx -Context struct
- - -
-
- -

- - - - - -
CAST128_BLOCK_SIZE -Constant
- - -
-The CAST128 blocksize, 8 -
- -

- - - - - -
CAST128_MIN_KEY_SIZE -Constant
- - -
-Minumim CAST128 key size, 5 -
- -

- - - - - -
CAST128_MAX_KEY_SIZE -Constant
- - -
-Maximum CAST128 key size, 16 -
- -

- - - - - -
CAST128_KEY_SIZE -Constant
- - -
-Default CAST128 key size, 16 -
- -

- - - - - -
void cast128_set_key (struct cast128_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. -
- -

- - - - - -
void cast128_encrypt (struct cast128_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Encryption function. length must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. src and dst may be equal, but they must not overlap -in any other way. -
- -

- - - - - -
void cast128_decrypt (struct cast128_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Analogous to cast128_encrypt -
- -

BLOWFISH

- -

BLOWFISH is a block cipher designed by Bruce Schneier. It uses a block -size of 64 bits (8 octets), and a variable key size, up to 448 bits. It -has some weak keys. Nettle defines BLOWFISH in <nettle/blowfish.h>. - -

- - - - - -
struct blowfish_ctx -Context struct
- - -
-
- -

- - - - - -
BLOWFISH_BLOCK_SIZE -Constant
- - -
-The BLOWFISH blocksize, 8 -
- -

- - - - - -
BLOWFISH_MIN_KEY_SIZE -Constant
- - -
-Minimum BLOWFISH key size, 8 -
- -

- - - - - -
BLOWFISH_MAX_KEY_SIZE -Constant
- - -
-Maximum BLOWFISH key size, 56 -
- -

- - - - - -
BLOWFISH_KEY_SIZE -Constant
- - -
-Default BLOWFISH key size, 16 -
- -

- - - - - -
int blowfish_set_key (struct blowfish_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. Returns 1 on success, and 0 if the key was weak. Calling -blowfish_encrypt or blowfish_decrypt with a weak key will -crash with an assert violation. -
- -

- - - - - -
void blowfish_encrypt (struct blowfish_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Encryption function. length must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. src and dst may be equal, but they must not overlap -in any other way. -
- -

- - - - - -
void blowfish_decrypt (struct blowfish_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Analogous to blowfish_encrypt -
- -

DES

- -

DES is the old Data Encryption Standard, specified by NIST. It uses a -block size of 64 bits (8 octets), and a key size of 56 bits. However, -the key bits are distributed over 8 octets, where the least significant -bit of each octet is used for parity. A common way to use DES is to -generate 8 random octets in some way, then set the least significant bit -of each octet to get odd parity, and initialize DES with the resulting -key. - -

The key size of DES is so small that keys can be found by brute force, -using specialized hardware or lots of ordinary work stations in -parallell. One shouldn't be using plain DES at all today, if one uses -DES at all one should be using "triple DES", three DES ciphers piped -together, with three (or sometimes just two) independent keys. - -

DES also has some weak keys. Nettle defines DES in <nettle/des.h>. - -

- - - - - -
struct des_ctx -Context struct
- - -
-
- -

- - - - - -
DES_BLOCK_SIZE -Constant
- - -
-The DES blocksize, 8 -
- -

- - - - - -
DES_KEY_SIZE -Constant
- - -
-DES key size, 8 -
- -

- - - - - -
int des_set_key (struct des_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. Returns 1 on success, and 0 if the key was weak or had bad -parity. Calling des_encrypt or des_decrypt with a bad key -will crash with an assert violation. -
- -

- - - - - -
void des_encrypt (struct des_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Encryption function. length must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. src and dst may be equal, but they must not overlap -in any other way. -
- -

- - - - - -
void des_decrypt (struct des_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Analogous to des_encrypt -
- -

SERPENT

- -

SERPENT is one of the AES finalists, designed by Ross Anderson, Eli -Biham and Lars Knudsen. Thus, the interface and properties are similar -to AES'. One pecularity is that it is quite pointless to use it with -anything but the maximum key size, smaller keys are just padded to -larger ones. Nettle defines SERPENT in <nettle/serpent.h>. - -

- - - - - -
struct serpent_ctx -Context struct
- - -
-
- -

- - - - - -
SERPENT_BLOCK_SIZE -Constant
- - -
-The SERPENT blocksize, 16 -
- -

- - - - - -
SERPENT_MIN_KEY_SIZE -Constant
- - -
-Minumim SERPENT key size, 16 -
- -

- - - - - -
SERPENT_MAX_KEY_SIZE -Constant
- - -
-Maximum SERPENT key size, 32 -
- -

- - - - - -
SERPENT_KEY_SIZE -Constant
- - -
-Default SERPENT key size, 32 -
- -

- - - - - -
void serpent_set_key (struct serpent_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. -
- -

- - - - - -
void serpent_encrypt (struct serpent_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Encryption function. length must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. src and dst may be equal, but they must not overlap -in any other way. -
- -

- - - - - -
void serpent_decrypt (struct serpent_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Analogous to serpent_encrypt -
- -

TWOFISH

- -

Another AES finalist, this one designed by Bruce Schneier and others. -Nettle defines it in <nettle/twofish.h>. - -

- - - - - -
struct twofish_ctx -Context struct
- - -
-
- -

- - - - - -
TWOFISH_BLOCK_SIZE -Constant
- - -
-The TWOFISH blocksize, 16 -
- -

- - - - - -
TWOFISH_MIN_KEY_SIZE -Constant
- - -
-Minumim TWOFISH key size, 16 -
- -

- - - - - -
TWOFISH_MAX_KEY_SIZE -Constant
- - -
-Maximum TWOFISH key size, 32 -
- -

- - - - - -
TWOFISH_KEY_SIZE -Constant
- - -
-Default TWOFISH key size, 32 -
- -

- - - - - -
void twofish_set_key (struct twofish_ctx *ctx, unsigned length, const uint8_t *key) -Function
- - -
-Initialize the cipher. The same function is used for both encryption and -decryption. -
- -

- - - - - -
void twofish_encrypt (struct twofish_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Encryption function. length must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. src and dst may be equal, but they must not overlap -in any other way. -
- -

- - - - - -
void twofish_decrypt (struct twofish_ctx *ctx, unsigned length, const uint8_t *dst, uint8_t *src) -Function
- - -
-Analogous to twofish_encrypt -
- -


-Node:Miscellaneous functions, -Previous:Cipher functions, -Up:Reference -
- -

Miscellaneous functions

- -

- - - - - -
uint8_t * memxor (uint8_t *dst, const uint8_t *src, size_t n) -Function
- - -
-XOR:s the source area on top of the destination area. The interface -doesn't follow the Nettle conventions, because it is intended to be -similar to the ANSI-C memcpy function. -
- -


-Node:Installation, -Next:, -Previous:Reference, -Up:Top -
- -

Installation

- -

Nettle uses autoconf and automake. To build it, -unpack the source and run - -

./configure
-make
-make check
-make install
-
- -

to install in the default location, /usr/local. The library is -installed in /use/local/lib/libnettle.a and the include files are -installed in /use/local/include/nettle/. - -

Only static libraries are installed. - -


-Node:Index, -Previous:Installation, -Up:Top -
- -

Function and Concept Index

- - - - - - diff --git a/lsh/src/nettle/nettle.info b/lsh/src/nettle/nettle.info deleted file mode 100644 index fedcbb0..0000000 --- a/lsh/src/nettle/nettle.info +++ /dev/null @@ -1,799 +0,0 @@ -This is nettle.info, produced by makeinfo version 4.0 from -nettle.texinfo. - -INFO-DIR-SECTION GNU Libraries -START-INFO-DIR-ENTRY -* Nettle: (nettle). A low-level cryptographics library. -END-INFO-DIR-ENTRY - - Draft manual for the Nettle library. This manual corresponds to -version 0.2. - - Copyright 2001 Niels Möller - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the sections entitled "Copying" and "GNU General Public License" -are included exactly as in the original, and provided that the entire -resulting derived work is distributed under the terms of a permission -notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that this permission notice may be stated in a -translation approved by the Free Software Foundation. - - -File: nettle.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) - - - - This document describes the nettle low-level cryptographic library. -You can use the library directly from your C-programs, or (recommended) -write or use an object-oriented wrapper for your favourite language or -application. - - This manual coresponds to version 0.2 of the library. - -* Menu: - -* Introduction:: -* Copyright:: -* Conventions:: -* Example:: -* Reference:: -* Installation:: -* Index:: - - -File: nettle.info, Node: Introduction, Next: Copyright, Prev: Top, Up: Top - -Introduction -************ - - Nettle is a cryptographic library that is designed to fit easily in -more or less any context: In crypto toolkits for object-oriented -languages (C++, Python, Pike, ...), in applications like LSH or GNUPG, -or even in kernel space. In most contexts, you need more than the basic -cryptographic algorithms, you also need some way to keep track of -available algorithms, their properties and variants. You often have -some algorithm selection process, often dictated by a protocol you want -to implement. - - And as the requirements of applications differ on subtle and not so -subtle ways, an API that fits one application well can be a pain to use -in a different context. And that is why there are so many different -cryptographic libraries around. - - Nettle tries to avoid this problem by doing one thing, the low-level -crypto stuff, and providing a _simple_ but general interface to it. In -particular, Nettle doesn't do algorithm selection. It doesn't do memory -allocation. It doesn't do any I/O. - - The idea is that one can build several application and context -specific interfaces on top of Nettle, and share the code, testcases, -banchmarks, documentation, etc. For this first version, the only -application using Nettle is LSH, and it uses an object-oriented -abstraction on top of the library. - - -File: nettle.info, Node: Copyright, Next: Conventions, Prev: Introduction, Up: Top - -Copyright -********* - - Nettle is distributed under the GNU General Public License (see the -file COPYING for details). However, many of the individual files are -dual licensed under less restrictive licenses like the GNU Lesser -General Public License, or public domain. Consult the headers in each -file for details. - - It is conceivable that future versions will use the LGPL rather than -the GPL, mail me if you have questions or suggestions. - - A list of the supported algorithms, their origins and licenses: - -_AES_ - The implementation of the AES cipher (also known as rijndael) is - written by Rafael Sevilla. Released under the LGPL. - -_ARCFOUR_ - The implementation of the ARCFOUR (also known as RC4) cipher is - written by Niels Möller. Released under the LGPL. - -_BLOWFISH_ - The implementation of the BLOWFISH cipher is written by Werner - Koch, copyright owned by the Free Software Foundation. Also hacked - by Ray Dassen and Niels Möller. Released under the GPL. - -_CAST128_ - The implementation of the CAST128 cipher is written by Steve Reid. - Released into the public domain. - -_DES_ - The implementation of the DES cipher is written by Dana L. How, and - released under the LGPL. - -_MD5_ - The implementation of the MD5 message digest is written by Colin - Plumb. It has been hacked some more by Andrew Kuchling and Niels - Möller. Released into the public domain. - -_SERPENT_ - The implementation of the SERPENT cipher is written by Ross - Anderson, Eli Biham, and Lars Knudsen, adapted to LSH by Rafael - Sevilla, and to Nettle by Niels Möller. - -_SHA1_ - The implementation of the SHA1 message digest is written by Peter - Gutmann, and hacked some more by Andrew Kuchling and Niels Möller. - Released into the public domain. - -_TWOFISH_ - The implementation of the TWOFISH cipher is written by Ruud de - Rooij. Released under the LGPL. - - -File: nettle.info, Node: Conventions, Next: Example, Prev: Copyright, Up: Top - -Conventions -*********** - - For each supported algorithm, there is an include file that defines a -_context struct_, a few constants, and declares functions for operating -on the state. The context struct encapsulates all information needed by -the algorithm, and it can be copied or moved in memory with no -unexpected effects. - - The functions for similar algorithms are similar, but there are some -differences, for instance reflecting if the key setup or encryption -function differ for encryption and encryption, and whether or not key -setup can fail. There are also differences that doesn't show in function -prototypes, but which the application must nevertheless be aware of. -There is no difference between stream ciphers and block ciphers, -although they should be used quite differently by the application. - - If your application uses more than one algorithm, you should probably -create an interface that is tailor-made for your needs, and then write a -few lines of glue code on top of Nettle. - - By convention, for an algorithm named `foo', the struct tag for the -context struct is `foo_ctx', constants and functions uses prefixes like -`FOO_BLOCK_SIZE' (a constant) and `foo_set_key' (a function). - - In all functions, strings are represented with an explicit length, of -type `unsigned', and a pointer of type `uint8_t *' or a `const uint8_t -*'. For functions that transform one string to another, the argument -order is length, destination pointer and source pointer. Source and -destination areas are of the same length. Source and destination may be -the same, so that you can process strings in place, but they must not -overlap in any other way. - - -File: nettle.info, Node: Example, Next: Reference, Prev: Conventions, Up: Top - -Example -******* - - A simple example program that reads a file from standard in and -writes its SHA1 checksum on stdout should give the flavour of Nettle. - - /* FIXME: This code is untested. */ - #include - #include - - #include - - #define BUF_SIZE 1000 - - static void - display_hex(unsigned length, uint8_t *data) - { - static const char digits[16] = "0123456789abcdef"; - unsigned i; - - for (i = 0; i'. - - - Context struct: struct md5_ctx - - - Constant: MD5_DIGEST_SIZE - The size of an MD5 digest, i.e. 16. - - - Constant: MD5_DATA_SIZE - The internal block size of MD5. Useful for some special - constructions, in particular HMAC-MD5. - - - Function: void md5_init (struct md5_ctx *CTX) - Initialize the MD5 state. - - - Function: void md5_update (struct md5_ctx *CTX, unsigned LENGTH, - const uint8_t *DATA) - Hash some more data. - - - Function: void md5_final (struct md5_ctx *CTX) - Performs final processing that is needed after all input data has - been processed with `md5_update'. - - - Function: void md5_digest (struct md5_ctx *CTX, unsigned LENGTH, - uint8_t *DIGEST) - Extracts the digest, writing it to DIGEST. LENGTH may be smaller - than `MD5_DIGEST_SIZE', in which case only the first LENGTH octets - of the digest are written. - - This functions doesn't change the state in any way. - - The normal way to use MD5 is to call the functions in order: First -`md5_init', then `md5_update' zero or more times, then `md5_final', and -at last `md5_digest' zero or more times. - - To start over, you can call `md5_init' at any time. - -SHA1 ----- - - SHA1 is a hash function specified by "NIST" (The U.S. National -Institute for Standards and Technology. It outputs hash values of 160 -bits, or 20 octets. Nettle defines SHA1 in `'. - - The functions are analogous to the MD5 ones. - - - Context struct: struct sha1_ctx - - - Constant: SHA1_DIGEST_SIZE - The size of an SHA1 digest, i.e. 20. - - - Constant: SHA1_DATA_SIZE - The internal block size of SHA1. Useful for some special - constructions, in particular HMAC-SHA1. - - - Function: void sha1_init (struct sha1_ctx *CTX) - Initialize the SHA1 state. - - - Function: void sha1_update (struct sha1_ctx *CTX, unsigned LENGTH, - const uint8_t *DATA) - Hash some more data. - - - Function: void sha1_final (struct sha1_ctx *CTX) - Performs final processing that is needed after all input data has - been processed with `sha1_update'. - - - Function: void sha1_digest (struct sha1_ctx *CTX, unsigned LENGTH, - uint8_t *DIGEST) - Extracts the digest, writing it to DIGEST. LENGTH may be smaller - than `SHA1_DIGEST_SIZE', in which case only the first LENGTH octets - of the digest are written. - - This functions doesn't change the state in any way. - - -File: nettle.info, Node: Cipher functions, Next: Miscellaneous functions, Prev: Hash functions, Up: Reference - -Cipher functions -================ - - A "cipher" is a function that takes a message or "plaintext" and a -secret "key" and transforms it to a "ciphertext". Given only the -ciphertext, but not the key, it should be hard to find the cleartext. -Given matching pairs of plaintext and ciphertext, it should be hard to -find the key. - - To do this, you first initialize the cipher context for encryption or -decryption with a particular key, then use it to process plaintext och -ciphertext messages. The initialization is also called "key setup". -With Nettle, it is recommended to use each context struct for only one -direction, even if some of the ciphers use a single key setup function -that can be used for both encryption and decryption. - - There are two main classes of ciphers: Block ciphers and stream -ciphers. - - A block cipher can process data only in fixed size chunks, called -"blocks". Typical block sizes are 8 or 16 octets. To encrypt arbitrary -messages, you usually have to pad it to an integral number of blocks, -split it into blocks, and then process each block. The simplest way is -to process one block at a time, independent of each other. That mode of -operation is called "ECB", Electronic Code Book mode. However, using -ECB is usually a bad idea. For a start, plaintext blocks that are equal -are transformed to ciphertext blocks that are equal; that leaks -information about the plaintext. Usually you should apply the cipher is -some feedback mode, "CBC" (Cipher Block Chaining) being one of the most -popular. - - A stream cipher can be used for messages of arbitrary length; a -typical stream cipher is a keyed pseudorandom generator. To encrypt a -plaintext message of N octets, you key the generator, generate N octets -of pseudorandom data, and XOR it with the plaintext. To decrypt, -regenerate the same stream using the key, XOR it to the ciphertext, and -the plaintext is recovered. - - *Caution:* The first rule for this kind of cipher is the same as for -a One Time Pad: _never_ ever use the same key twice. - - A common misconception is that encryption, by itself, implies -authentication. Say that you and a friend share a secret key, and you -receive an encrypted message, apply the key, and get a cleartext message -that makes sense to you. Can you then be sure that it really was your -friend that wrote the message you're reading? The anser is no. For -example, if you were using a block cipher in ECB mode, an attacker may -pick up the message on its way, and reorder, delete or repeat some of -the blocks. Even if the attacker can't decrypt the message, he can -change it so that you are not reading the same message as your friend -wrote. If you are using a block cipher in CBC mode rather than ECB, or -are using a stream cipher, the possibilities for this sort of attack are -different, but the attacker can still make predictable changes to the -message. - - It is recommended to _always_ use an authentication mechanism in -addition to encrypting the messages. Popular choices are Message -Authetication Codes like HMAC-SHA1, or digital signatures. - - Some ciphers have so called "weak keys", keys that results in -undesirable structure after the key setup processing, and should be -avoided. In Nettle, the presence of weak keys for a cipher mean that the -key setup function can fail, so you have to check its return value. In -addition, the context struct has a field `status', that is set to a -non-zero value if key setup fails. When possible, avoid algorithm that -have weak keys. There are several good ciphers that don't have any weak -keys. - -AES ---- - - AES is a quite new block cipher, specified by NIST as a replacement -for the older DES standard. It is the result of a competition between -cipher designers, and the winning design, constructed by Joan Daemen and -Vincent Rijnmen. Before it won the competition, it was known under the -name RIJNDAEL. - - Like all the AES candidates, the winning design uses a block size of -128 bits, or 16 octets, and variable keysize, 128, 192 and 256 bits -(16, 24 and 32 octets) being the allowed key sizes. It does not have -any weak keys. Nettle defines AES in `'. - - - Context struct: struct aes_ctx - - - Constant: AES_BLOCK_SIZE - The AES blocksize, 16 - - - Constant: AES_MIN_KEY_SIZE - - - Constant: AES_MAX_KEY_SIZE - - - Constant: AES_KEY_SIZE - Default AES key size, 32 - - - Function: void aes_set_key (struct aes_ctx *CTX, unsigned LENGTH, - const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. - - - Function: void aes_encrypt (struct aes_ctx *CTX, unsigned LENGTH, - const uint8_t *DST, uint8_t *SRC) - Encryption function. LENGTH must be an integral multiple of the - block size. If it is more than one block, the data is processed in - ECB mode. `src' and `dst' may be equal, but they must not overlap - in any other way. - - - Function: void aes_decrypt (struct aes_ctx *CTX, unsigned LENGTH, - const uint8_t *DST, uint8_t *SRC) - Analogous to `aes_encrypt' - -ARCFOUR -------- - - ARCFOUR is a stream cipher, also known under the trade marked name -RC4, and it is one of the fastest ciphers around. A problem is that the -key setup of ARCFOUR is quite weak, you should never use keys with -structure, keys that are ordinary passwords, or sequences of keys like -"secret:1", "secret:2", ..... If you have keys that don't look like -random bit strings, and you want to use ARCFOUR, always hash the key -before feeding it to ARCFOUR. For example - - /* A more robust key setup function for ARCFOUR */ - void - my_arcfour_set_key(struct arcfour_ctx *ctx, - unsigned length, const uint8_t *key) - { - struct sha1_ctx hash; - uint8_t digest[SHA1_DIGEST_SIZE]; - - sha1_init(&hash); - sha1_update(&hash, length, key); - sha1_final(&hash); - sha1_digest(&hash, SHA1_DIGEST_SIZE, digest); - - arcfour_set_key(ctx, SHA1_DIGEST_SIZE, digest); - } - - Nettle defines ARCFOUR in `'. - - - Context struct: struct arcfour_ctx - - - Constant: ARCFOUR_BLOCK_SIZE - The ARCFOUR blocksize, 16 - - - Constant: ARCFOUR_MIN_KEY_SIZE - Minimum key size, 1 - - - Constant: ARCFOUR_MAX_KEY_SIZE - Maximum key size, 256 - - - Constant: ARCFOUR_KEY_SIZE - Default ARCFOUR key size, 16 - - - Function: void arcfour_set_key (struct arcfour_ctx *CTX, unsigned - LENGTH, const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. - - - Function: void arcfour_crypt (struct arcfour_ctx *CTX, unsigned - LENGTH, const uint8_t *KEY) - Encrypt some data. The same function is used for both encryption - and decryption. Unlike the block ciphers, this function modifies - the context, so you can split the data into arbitrary chunks and - encrypt them one after another. The result is the same as if you - had called `arcfour_crypt' only once with all the data. - -CAST128 -------- - - CAST-128 is a block cipher, specified in `RFC 2144'. It uses a 64 -bit (8 octets) block size, and a variable key size of up to 128 bits. -Nettle defines cast128 in `'. - - - Context struct: struct cast128_ctx - - - Constant: CAST128_BLOCK_SIZE - The CAST128 blocksize, 8 - - - Constant: CAST128_MIN_KEY_SIZE - Minumim CAST128 key size, 5 - - - Constant: CAST128_MAX_KEY_SIZE - Maximum CAST128 key size, 16 - - - Constant: CAST128_KEY_SIZE - Default CAST128 key size, 16 - - - Function: void cast128_set_key (struct cast128_ctx *CTX, unsigned - LENGTH, const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. - - - Function: void cast128_encrypt (struct cast128_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Encryption function. LENGTH must be an integral multiple of the - block size. If it is more than one block, the data is processed in - ECB mode. `src' and `dst' may be equal, but they must not overlap - in any other way. - - - Function: void cast128_decrypt (struct cast128_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Analogous to `cast128_encrypt' - -BLOWFISH --------- - - BLOWFISH is a block cipher designed by Bruce Schneier. It uses a -block size of 64 bits (8 octets), and a variable key size, up to 448 -bits. It has some weak keys. Nettle defines BLOWFISH in -`'. - - - Context struct: struct blowfish_ctx - - - Constant: BLOWFISH_BLOCK_SIZE - The BLOWFISH blocksize, 8 - - - Constant: BLOWFISH_MIN_KEY_SIZE - Minimum BLOWFISH key size, 8 - - - Constant: BLOWFISH_MAX_KEY_SIZE - Maximum BLOWFISH key size, 56 - - - Constant: BLOWFISH_KEY_SIZE - Default BLOWFISH key size, 16 - - - Function: int blowfish_set_key (struct blowfish_ctx *CTX, unsigned - LENGTH, const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. Returns 1 on success, and 0 if the key - was weak. Calling `blowfish_encrypt' or `blowfish_decrypt' with a - weak key will crash with an assert violation. - - - Function: void blowfish_encrypt (struct blowfish_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Encryption function. LENGTH must be an integral multiple of the - block size. If it is more than one block, the data is processed in - ECB mode. `src' and `dst' may be equal, but they must not overlap - in any other way. - - - Function: void blowfish_decrypt (struct blowfish_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Analogous to `blowfish_encrypt' - -DES ---- - - DES is the old Data Encryption Standard, specified by NIST. It uses a -block size of 64 bits (8 octets), and a key size of 56 bits. However, -the key bits are distributed over 8 octets, where the least significant -bit of each octet is used for parity. A common way to use DES is to -generate 8 random octets in some way, then set the least significant bit -of each octet to get odd parity, and initialize DES with the resulting -key. - - The key size of DES is so small that keys can be found by brute -force, using specialized hardware or lots of ordinary work stations in -parallell. One shouldn't be using plain DES at all today, if one uses -DES at all one should be using "triple DES", three DES ciphers piped -together, with three (or sometimes just two) independent keys. - - DES also has some weak keys. Nettle defines DES in `'. - - - Context struct: struct des_ctx - - - Constant: DES_BLOCK_SIZE - The DES blocksize, 8 - - - Constant: DES_KEY_SIZE - DES key size, 8 - - - Function: int des_set_key (struct des_ctx *CTX, unsigned LENGTH, - const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. Returns 1 on success, and 0 if the key - was weak or had bad parity. Calling `des_encrypt' or `des_decrypt' - with a bad key will crash with an assert violation. - - - Function: void des_encrypt (struct des_ctx *CTX, unsigned LENGTH, - const uint8_t *DST, uint8_t *SRC) - Encryption function. LENGTH must be an integral multiple of the - block size. If it is more than one block, the data is processed in - ECB mode. `src' and `dst' may be equal, but they must not overlap - in any other way. - - - Function: void des_decrypt (struct des_ctx *CTX, unsigned LENGTH, - const uint8_t *DST, uint8_t *SRC) - Analogous to `des_encrypt' - -SERPENT -------- - - SERPENT is one of the AES finalists, designed by Ross Anderson, Eli -Biham and Lars Knudsen. Thus, the interface and properties are similar -to AES'. One pecularity is that it is quite pointless to use it with -anything but the maximum key size, smaller keys are just padded to -larger ones. Nettle defines SERPENT in `'. - - - Context struct: struct serpent_ctx - - - Constant: SERPENT_BLOCK_SIZE - The SERPENT blocksize, 16 - - - Constant: SERPENT_MIN_KEY_SIZE - Minumim SERPENT key size, 16 - - - Constant: SERPENT_MAX_KEY_SIZE - Maximum SERPENT key size, 32 - - - Constant: SERPENT_KEY_SIZE - Default SERPENT key size, 32 - - - Function: void serpent_set_key (struct serpent_ctx *CTX, unsigned - LENGTH, const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. - - - Function: void serpent_encrypt (struct serpent_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Encryption function. LENGTH must be an integral multiple of the - block size. If it is more than one block, the data is processed in - ECB mode. `src' and `dst' may be equal, but they must not overlap - in any other way. - - - Function: void serpent_decrypt (struct serpent_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Analogous to `serpent_encrypt' - -TWOFISH -------- - - Another AES finalist, this one designed by Bruce Schneier and others. -Nettle defines it in `'. - - - Context struct: struct twofish_ctx - - - Constant: TWOFISH_BLOCK_SIZE - The TWOFISH blocksize, 16 - - - Constant: TWOFISH_MIN_KEY_SIZE - Minumim TWOFISH key size, 16 - - - Constant: TWOFISH_MAX_KEY_SIZE - Maximum TWOFISH key size, 32 - - - Constant: TWOFISH_KEY_SIZE - Default TWOFISH key size, 32 - - - Function: void twofish_set_key (struct twofish_ctx *CTX, unsigned - LENGTH, const uint8_t *KEY) - Initialize the cipher. The same function is used for both - encryption and decryption. - - - Function: void twofish_encrypt (struct twofish_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Encryption function. LENGTH must be an integral multiple of the - block size. If it is more than one block, the data is processed in - ECB mode. `src' and `dst' may be equal, but they must not overlap - in any other way. - - - Function: void twofish_decrypt (struct twofish_ctx *CTX, unsigned - LENGTH, const uint8_t *DST, uint8_t *SRC) - Analogous to `twofish_encrypt' - - -File: nettle.info, Node: Miscellaneous functions, Prev: Cipher functions, Up: Reference - -Miscellaneous functions -======================= - - - Function: uint8_t * memxor (uint8_t *DST, const uint8_t *SRC, size_t - N) - XOR:s the source area on top of the destination area. The interface - doesn't follow the Nettle conventions, because it is intended to be - similar to the ANSI-C `memcpy' function. - - -File: nettle.info, Node: Installation, Next: Index, Prev: Reference, Up: Top - -Installation -************ - - Nettle uses `autoconf' and `automake'. To build it, unpack the -source and run - - ./configure - make - make check - make install - - to install in the default location, `/usr/local'. The library is -installed in `/use/local/lib/libnettle.a' and the include files are -installed in `/use/local/include/nettle/'. - - Only static libraries are installed. - - -File: nettle.info, Node: Index, Prev: Installation, Up: Top - -Function and Concept Index -************************** - -* Menu: - -* aes_decrypt: Cipher functions. -* aes_encrypt: Cipher functions. -* aes_set_key: Cipher functions. -* arcfour_crypt: Cipher functions. -* arcfour_set_key: Cipher functions. -* blowfish_decrypt: Cipher functions. -* blowfish_encrypt: Cipher functions. -* blowfish_set_key: Cipher functions. -* cast128_decrypt: Cipher functions. -* cast128_encrypt: Cipher functions. -* cast128_set_key: Cipher functions. -* des_decrypt: Cipher functions. -* des_encrypt: Cipher functions. -* des_set_key: Cipher functions. -* md5_digest: Hash functions. -* md5_final: Hash functions. -* md5_init: Hash functions. -* md5_update: Hash functions. -* memxor: Miscellaneous functions. -* serpent_decrypt: Cipher functions. -* serpent_encrypt: Cipher functions. -* serpent_set_key: Cipher functions. -* sha1_digest: Hash functions. -* sha1_final: Hash functions. -* sha1_init: Hash functions. -* sha1_update: Hash functions. -* twofish_decrypt: Cipher functions. -* twofish_encrypt: Cipher functions. -* twofish_set_key: Cipher functions. - - - -Tag Table: -Node: Top1130 -Node: Introduction1608 -Node: Copyright3013 -Node: Conventions5019 -Node: Example6759 -Node: Reference8076 -Node: Hash functions8333 -Node: Cipher functions11858 -Node: Miscellaneous functions26002 -Node: Installation26423 -Node: Index26899 - -End Tag Table diff --git a/lsh/src/nettle/nettle.texinfo b/lsh/src/nettle/nettle.texinfo deleted file mode 100644 index 62e2a18..0000000 --- a/lsh/src/nettle/nettle.texinfo +++ /dev/null @@ -1,838 +0,0 @@ -\input texinfo @c -*-texinfo-*- - -@c %**start of header -@setfilename nettle.info -@settitle The Nettle low-level cryptographic library. -@c %**end of header - -@syncodeindex fn cp - -@dircategory GNU Libraries -@direntry -* Nettle: (nettle). A low-level cryptographics library. -@end direntry - -@set UPDATED-FOR 0.2 - -@c Latin-1 doesn't work with tex output. -@c Also lookout for é characters. - -@set AUTHOR Niels Möller -@ifinfo -Draft manual for the Nettle library. This manual corresponds to version -@value{UPDATED-FOR}. - -Copyright 2001 @value{AUTHOR} - -Permission is granted to make and distribute verbatim -copies of this manual provided the copyright notice and -this permission notice are preserved on all copies. - -@ignore -Permission is granted to process this file through TeX -and print the results, provided the printed document -carries a copying permission notice identical to this -one except for the removal of this paragraph (this -paragraph not being relevant to the printed manual). - -@end ignore -Permission is granted to copy and distribute modified -versions of this manual under the conditions for -verbatim copying, provided also that the sections -entitled ``Copying'' and ``GNU General Public License'' -are included exactly as in the original, and provided -that the entire resulting derived work is distributed -under the terms of a permission notice identical to this -one. - -Permission is granted to copy and distribute -translations of this manual into another language, -under the above conditions for modified versions, -except that this permission notice may be stated in a -translation approved by the Free Software Foundation. - -@end ifinfo - -@titlepage -@sp 10 -@c @center @titlefont{Nettle Manual} - -@title Nettle Manual -@subtitle For the Nettle Library version @value{UPDATED-FOR} - -@author @value{AUTHOR} - -@c The following two commands start the copyright page. -@page -@vskip 0pt plus 1filll -Copyright @copyright{} 2001 @value{AUTHOR} - -Permission is granted to make and distribute verbatim -copies of this manual provided the copyright notice and -this permission notice are preserved on all copies. - -Permission is granted to copy and distribute modified -versions of this manual under the conditions for -verbatim copying, provided also that the sections -entitled ``Copying'' and ``GNU General Public License'' -are included exactly as in the original, and provided -that the entire resulting derived work is distributed -under the terms of a permission notice identical to this -one. - -Permission is granted to copy and distribute -translations of this manual into another language, -under the above conditions for modified versions, -except that this permission notice may be stated in a -translation approved by the Free Software Foundation. - -@end titlepage - -@ifnottex -@node Top, Introduction, (dir), (dir) -@comment node-name, next, previous, up -@top - -This document describes the nettle low-level cryptographic library. You -can use the library directly from your C-programs, or (recommended) -write or use an object-oriented wrapper for your favourite language or -application. - -This manual coresponds to version @value{UPDATED-FOR} of the library. - -@menu -* Introduction:: -* Copyright:: -* Conventions:: -* Example:: -* Reference:: -* Installation:: -* Index:: -@end menu - -@end ifnottex - -@node Introduction, Copyright, Top, Top -@comment node-name, next, previous, up -@chapter Introduction - -Nettle is a cryptographic library that is designed to fit easily in more -or less any context: In crypto toolkits for object-oriented languages -(C++, Python, Pike, ...), in applications like LSH or GNUPG, or even in -kernel space. In most contexts, you need more than the basic -cryptographic algorithms, you also need some way to keep track of available -algorithms, their properties and variants. You often have some algorithm -selection process, often dictated by a protocol you want to implement. - -And as the requirements of applications differ on subtle and not so -subtle ways, an API that fits one application well can be a pain to use -in a different context. And that is why there are so many different -cryptographic libraries around. - -Nettle tries to avoid this problem by doing one thing, the low-level -crypto stuff, and providing a @emph{simple} but general interface to it. -In particular, Nettle doesn't do algorithm selection. It doesn't do -memory allocation. It doesn't do any I/O. - -The idea is that one can build several application and context specific -interfaces on top of Nettle, and share the code, testcases, banchmarks, -documentation, etc. For this first version, the only application using -Nettle is LSH, and it uses an object-oriented abstraction on top of the -library. - -@node Copyright, Conventions, Introduction, Top -@comment node-name, next, previous, up -@chapter Copyright - -Nettle is distributed under the GNU General Public License (see the file -COPYING for details). However, many of the individual files are dual -licensed under less restrictive licenses like the GNU Lesser General -Public License, or public domain. Consult the headers in each file for -details. - -It is conceivable that future versions will use the LGPL rather than the -GPL, mail me if you have questions or suggestions. - -A list of the supported algorithms, their origins and licenses: - -@table @emph -@item AES -The implementation of the AES cipher (also known as rijndael) is written -by Rafael Sevilla. Released under the LGPL. - -@item ARCFOUR -The implementation of the ARCFOUR (also known as RC4) cipher is written -by Niels Möller. Released under the LGPL. - -@item BLOWFISH -The implementation of the BLOWFISH cipher is written by Werner Koch, -copyright owned by the Free Software Foundation. Also hacked by Ray -Dassen and Niels Möller. Released under the GPL. - -@item CAST128 -The implementation of the CAST128 cipher is written by Steve Reid. -Released into the public domain. - -@item DES -The implementation of the DES cipher is written by Dana L. How, and -released under the LGPL. - -@item MD5 -The implementation of the MD5 message digest is written by Colin Plumb. -It has been hacked some more by Andrew Kuchling and Niels Möller. -Released into the public domain. - -@item SERPENT -The implementation of the SERPENT cipher is written by Ross Anderson, -Eli Biham, and Lars Knudsen, adapted to LSH by Rafael Sevilla, and to -Nettle by Niels Möller. - -@item SHA1 -The implementation of the SHA1 message digest is written by Peter -Gutmann, and hacked some more by Andrew Kuchling and Niels Möller. -Released into the public domain. - -@item TWOFISH -The implementation of the TWOFISH cipher is written by Ruud de Rooij. -Released under the LGPL. -@end table - -@node Conventions, Example, Copyright, Top -@comment node-name, next, previous, up -@chapter Conventions - -For each supported algorithm, there is an include file that defines a -@emph{context struct}, a few constants, and declares functions for -operating on the state. The context struct encapsulates all information -needed by the algorithm, and it can be copied or moved in memory with no -unexpected effects. - -The functions for similar algorithms are similar, but there are some -differences, for instance reflecting if the key setup or encryption -function differ for encryption and encryption, and whether or not key -setup can fail. There are also differences that doesn't show in function -prototypes, but which the application must nevertheless be aware of. -There is no difference between stream ciphers and block ciphers, -although they should be used quite differently by the application. - -If your application uses more than one algorithm, you should probably -create an interface that is tailor-made for your needs, and then write a -few lines of glue code on top of Nettle. - -By convention, for an algorithm named @code{foo}, the struct tag for the -context struct is @code{foo_ctx}, constants and functions uses prefixes -like @code{FOO_BLOCK_SIZE} (a constant) and @code{foo_set_key} (a -function). - -In all functions, strings are represented with an explicit length, of -type @code{unsigned}, and a pointer of type @code{uint8_t *} or a -@code{const uint8_t *}. For functions that transform one string to -another, the argument order is length, destination pointer and source -pointer. Source and destination areas are of the same length. Source and -destination may be the same, so that you can process strings in place, -but they must not overlap in any other way. - -@node Example, Reference, Conventions, Top -@comment node-name, next, previous, up -@chapter Example - -A simple example program that reads a file from standard in and writes -its SHA1 checksum on stdout should give the flavour of Nettle. - -@example -/* FIXME: This code is untested. */ -#include -#include - -#include - -#define BUF_SIZE 1000 - -static void -display_hex(unsigned length, uint8_t *data) -@{ - static const char digits[16] = "0123456789abcdef"; - unsigned i; - - for (i = 0; i}. - -@deftp {Context struct} {struct md5_ctx} -@end deftp - -@defvr Constant MD5_DIGEST_SIZE -The size of an MD5 digest, i.e. 16. -@end defvr - -@defvr Constant MD5_DATA_SIZE -The internal block size of MD5. Useful for some special constructions, -in particular HMAC-MD5. -@end defvr - -@deftypefun void md5_init (struct md5_ctx *@var{ctx}) -Initialize the MD5 state. -@end deftypefun - -@deftypefun void md5_update (struct md5_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{data}) -Hash some more data. -@end deftypefun - -@deftypefun void md5_final (struct md5_ctx *@var{ctx}) -Performs final processing that is needed after all input data has been -processed with @code{md5_update}. -@end deftypefun - -@deftypefun void md5_digest (struct md5_ctx *@var{ctx}, unsigned @var{length}, uint8_t *@var{digest}) -Extracts the digest, writing it to @var{digest}. @var{length} may be smaller than -@code{MD5_DIGEST_SIZE}, in which case only the first @var{length} octets -of the digest are written. - -This functions doesn't change the state in any way. -@end deftypefun - -The normal way to use MD5 is to call the functions in order: First -@code{md5_init}, then @code{md5_update} zero or more times, then -@code{md5_final}, and at last @code{md5_digest} zero or more times. - -To start over, you can call @code{md5_init} at any time. - -@subsection @acronym{SHA1} - -SHA1 is a hash function specified by @dfn{NIST} (The U.S. National Institute -for Standards and Technology. It outputs hash values of 160 bits, or 20 -octets. Nettle defines SHA1 in @file{}. - -The functions are analogous to the MD5 ones. - -@deftp {Context struct} {struct sha1_ctx} -@end deftp - -@defvr Constant SHA1_DIGEST_SIZE -The size of an SHA1 digest, i.e. 20. -@end defvr - -@defvr Constant SHA1_DATA_SIZE -The internal block size of SHA1. Useful for some special constructions, -in particular HMAC-SHA1. -@end defvr - -@deftypefun void sha1_init (struct sha1_ctx *@var{ctx}) -Initialize the SHA1 state. -@end deftypefun - -@deftypefun void sha1_update (struct sha1_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{data}) -Hash some more data. -@end deftypefun - -@deftypefun void sha1_final (struct sha1_ctx *@var{ctx}) -Performs final processing that is needed after all input data has been -processed with @code{sha1_update}. -@end deftypefun - -@deftypefun void sha1_digest (struct sha1_ctx *@var{ctx}, unsigned @var{length}, uint8_t *@var{digest}) -Extracts the digest, writing it to @var{digest}. @var{length} may be smaller than -@code{SHA1_DIGEST_SIZE}, in which case only the first @var{length} octets -of the digest are written. - -This functions doesn't change the state in any way. -@end deftypefun - -@node Cipher functions, Miscellaneous functions, Hash functions, Reference -@comment node-name, next, previous, up -@section Cipher functions - -A @dfn{cipher} is a function that takes a message or @dfn{plaintext} -and a secret @dfn{key} and transforms it to a @dfn{ciphertext}. Given -only the ciphertext, but not the key, it should be hard to find the -cleartext. Given matching pairs of plaintext and ciphertext, it should -be hard to find the key. - -To do this, you first initialize the cipher context for encryption or -decryption with a particular key, then use it to process plaintext och -ciphertext messages. The initialization is also called @dfn{key setup}. -With Nettle, it is recommended to use each context struct for only one -direction, even if some of the ciphers use a single key setup function -that can be used for both encryption and decryption. - -There are two main classes of ciphers: Block ciphers and stream ciphers. - -A block cipher can process data only in fixed size chunks, called -@dfn{blocks}. Typical block sizes are 8 or 16 octets. To encrypt -arbitrary messages, you usually have to pad it to an integral number of -blocks, split it into blocks, and then process each block. The simplest -way is to process one block at a time, independent of each other. That -mode of operation is called @dfn{ECB}, Electronic Code Book mode. -However, using ECB is usually a bad idea. For a start, plaintext blocks -that are equal are transformed to ciphertext blocks that are equal; that -leaks information about the plaintext. Usually you should apply the -cipher is some feedback mode, @dfn{CBC} (Cipher Block Chaining) being one -of the most popular. - -A stream cipher can be used for messages of arbitrary length; a typical -stream cipher is a keyed pseudorandom generator. To encrypt a plaintext -message of @var{n} octets, you key the generator, generate @var{n} -octets of pseudorandom data, and XOR it with the plaintext. To decrypt, -regenerate the same stream using the key, XOR it to the ciphertext, and -the plaintext is recovered. - -@strong{Caution:} The first rule for this kind of cipher is the -same as for a One Time Pad: @emph{never} ever use the same key twice. - -A common misconception is that encryption, by itself, implies -authentication. Say that you and a friend share a secret key, and you -receive an encrypted message, apply the key, and get a cleartext message -that makes sense to you. Can you then be sure that it really was your -friend that wrote the message you're reading? The anser is no. For -example, if you were using a block cipher in ECB mode, an attacker may -pick up the message on its way, and reorder, delete or repeat some of -the blocks. Even if the attacker can't decrypt the message, he can -change it so that you are not reading the same message as your friend -wrote. If you are using a block cipher in CBC mode rather than ECB, or -are using a stream cipher, the possibilities for this sort of attack are -different, but the attacker can still make predictable changes to the -message. - -It is recommended to @emph{always} use an authentication mechanism in -addition to encrypting the messages. Popular choices are Message -Authetication Codes like HMAC-SHA1, or digital signatures. - -Some ciphers have so called "weak keys", keys that results in -undesirable structure after the key setup processing, and should be -avoided. In Nettle, the presence of weak keys for a cipher mean that the -key setup function can fail, so you have to check its return value. In -addition, the context struct has a field @code{status}, that is set to a -non-zero value if key setup fails. When possible, avoid algorithm that -have weak keys. There are several good ciphers that don't have any weak -keys. - -@subsection AES -AES is a quite new block cipher, specified by NIST as a replacement for -the older DES standard. It is the result of a competition between cipher -designers, and the winning design, constructed by Joan Daemen and -Vincent Rijnmen. Before it won the competition, it was known under the -name RIJNDAEL. - -Like all the AES candidates, the winning design uses a block size of 128 -bits, or 16 octets, and variable keysize, 128, 192 and 256 bits (16, 24 -and 32 octets) being the allowed key sizes. It does not have any weak -keys. Nettle defines AES in @file{}. - -@deftp {Context struct} {struct aes_ctx} -@end deftp - -@defvr Constant AES_BLOCK_SIZE -The AES blocksize, 16 -@end defvr - -@defvr Constant AES_MIN_KEY_SIZE -@end defvr - -@defvr Constant AES_MAX_KEY_SIZE -@end defvr - -@defvr Constant AES_KEY_SIZE -Default AES key size, 32 -@end defvr - -@deftypefun void aes_set_key (struct aes_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. -@end deftypefun - -@deftypefun void aes_encrypt (struct aes_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Encryption function. @var{length} must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. @code{src} and @code{dst} may be equal, but they must not overlap -in any other way. -@end deftypefun - -@deftypefun void aes_decrypt (struct aes_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Analogous to @code{aes_encrypt} -@end deftypefun - -@subsection ARCFOUR -ARCFOUR is a stream cipher, also known under the trade marked name RC4, -and it is one of the fastest ciphers around. A problem is that the key -setup of ARCFOUR is quite weak, you should never use keys with -structure, keys that are ordinary passwords, or sequences of keys like -"secret:1", "secret:2", @enddots{}. If you have keys that don't look -like random bit strings, and you want to use ARCFOUR, always hash the -key before feeding it to ARCFOUR. For example - -@example -/* A more robust key setup function for ARCFOUR */ -void -my_arcfour_set_key(struct arcfour_ctx *ctx, - unsigned length, const uint8_t *key) -@{ - struct sha1_ctx hash; - uint8_t digest[SHA1_DIGEST_SIZE]; - - sha1_init(&hash); - sha1_update(&hash, length, key); - sha1_final(&hash); - sha1_digest(&hash, SHA1_DIGEST_SIZE, digest); - - arcfour_set_key(ctx, SHA1_DIGEST_SIZE, digest); -@} -@end example - -Nettle defines ARCFOUR in @file{}. - -@deftp {Context struct} {struct arcfour_ctx} -@end deftp - -@defvr Constant ARCFOUR_BLOCK_SIZE -The ARCFOUR blocksize, 16 -@end defvr - -@defvr Constant ARCFOUR_MIN_KEY_SIZE -Minimum key size, 1 -@end defvr - -@defvr Constant ARCFOUR_MAX_KEY_SIZE -Maximum key size, 256 -@end defvr - -@defvr Constant ARCFOUR_KEY_SIZE -Default ARCFOUR key size, 16 -@end defvr - -@deftypefun void arcfour_set_key (struct arcfour_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. -@end deftypefun - -@deftypefun void arcfour_crypt (struct arcfour_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Encrypt some data. The same function is used for both encryption and -decryption. Unlike the block ciphers, this function modifies the -context, so you can split the data into arbitrary chunks and encrypt -them one after another. The result is the same as if you had called -@code{arcfour_crypt} only once with all the data. -@end deftypefun - -@subsection CAST128 - -CAST-128 is a block cipher, specified in @cite{RFC 2144}. It uses a 64 -bit (8 octets) block size, and a variable key size of up to 128 bits. -Nettle defines cast128 in @file{}. - -@deftp {Context struct} {struct cast128_ctx} -@end deftp - -@defvr Constant CAST128_BLOCK_SIZE -The CAST128 blocksize, 8 -@end defvr - -@defvr Constant CAST128_MIN_KEY_SIZE -Minumim CAST128 key size, 5 -@end defvr - -@defvr Constant CAST128_MAX_KEY_SIZE -Maximum CAST128 key size, 16 -@end defvr - -@defvr Constant CAST128_KEY_SIZE -Default CAST128 key size, 16 -@end defvr - -@deftypefun void cast128_set_key (struct cast128_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. -@end deftypefun - -@deftypefun void cast128_encrypt (struct cast128_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Encryption function. @var{length} must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. @code{src} and @code{dst} may be equal, but they must not overlap -in any other way. -@end deftypefun - -@deftypefun void cast128_decrypt (struct cast128_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Analogous to @code{cast128_encrypt} -@end deftypefun - -@subsection BLOWFISH - -BLOWFISH is a block cipher designed by Bruce Schneier. It uses a block -size of 64 bits (8 octets), and a variable key size, up to 448 bits. It -has some weak keys. Nettle defines BLOWFISH in @file{}. - -@deftp {Context struct} {struct blowfish_ctx} -@end deftp - -@defvr Constant BLOWFISH_BLOCK_SIZE -The BLOWFISH blocksize, 8 -@end defvr - -@defvr Constant BLOWFISH_MIN_KEY_SIZE -Minimum BLOWFISH key size, 8 -@end defvr - -@defvr Constant BLOWFISH_MAX_KEY_SIZE -Maximum BLOWFISH key size, 56 -@end defvr - -@defvr Constant BLOWFISH_KEY_SIZE -Default BLOWFISH key size, 16 -@end defvr - -@deftypefun int blowfish_set_key (struct blowfish_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. Returns 1 on success, and 0 if the key was weak. Calling -@code{blowfish_encrypt} or @code{blowfish_decrypt} with a weak key will -crash with an assert violation. -@end deftypefun - -@deftypefun void blowfish_encrypt (struct blowfish_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Encryption function. @var{length} must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. @code{src} and @code{dst} may be equal, but they must not overlap -in any other way. -@end deftypefun - -@deftypefun void blowfish_decrypt (struct blowfish_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Analogous to @code{blowfish_encrypt} -@end deftypefun - -@subsection DES -DES is the old Data Encryption Standard, specified by NIST. It uses a -block size of 64 bits (8 octets), and a key size of 56 bits. However, -the key bits are distributed over 8 octets, where the least significant -bit of each octet is used for parity. A common way to use DES is to -generate 8 random octets in some way, then set the least significant bit -of each octet to get odd parity, and initialize DES with the resulting -key. - -The key size of DES is so small that keys can be found by brute force, -using specialized hardware or lots of ordinary work stations in -parallell. One shouldn't be using plain DES at all today, if one uses -DES at all one should be using "triple DES", three DES ciphers piped -together, with three (or sometimes just two) independent keys. - -DES also has some weak keys. Nettle defines DES in @file{}. - -@deftp {Context struct} {struct des_ctx} -@end deftp - -@defvr Constant DES_BLOCK_SIZE -The DES blocksize, 8 -@end defvr - -@defvr Constant DES_KEY_SIZE -DES key size, 8 -@end defvr - -@deftypefun int des_set_key (struct des_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. Returns 1 on success, and 0 if the key was weak or had bad -parity. Calling @code{des_encrypt} or @code{des_decrypt} with a bad key -will crash with an assert violation. -@end deftypefun - -@deftypefun void des_encrypt (struct des_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Encryption function. @var{length} must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. @code{src} and @code{dst} may be equal, but they must not overlap -in any other way. -@end deftypefun - -@deftypefun void des_decrypt (struct des_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Analogous to @code{des_encrypt} -@end deftypefun - -@subsection SERPENT -SERPENT is one of the AES finalists, designed by Ross Anderson, Eli -Biham and Lars Knudsen. Thus, the interface and properties are similar -to AES'. One pecularity is that it is quite pointless to use it with -anything but the maximum key size, smaller keys are just padded to -larger ones. Nettle defines SERPENT in @file{}. - -@deftp {Context struct} {struct serpent_ctx} -@end deftp - -@defvr Constant SERPENT_BLOCK_SIZE -The SERPENT blocksize, 16 -@end defvr - -@defvr Constant SERPENT_MIN_KEY_SIZE -Minumim SERPENT key size, 16 -@end defvr - -@defvr Constant SERPENT_MAX_KEY_SIZE -Maximum SERPENT key size, 32 -@end defvr - -@defvr Constant SERPENT_KEY_SIZE -Default SERPENT key size, 32 -@end defvr - -@deftypefun void serpent_set_key (struct serpent_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. -@end deftypefun - -@deftypefun void serpent_encrypt (struct serpent_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Encryption function. @var{length} must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. @code{src} and @code{dst} may be equal, but they must not overlap -in any other way. -@end deftypefun - -@deftypefun void serpent_decrypt (struct serpent_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Analogous to @code{serpent_encrypt} -@end deftypefun - - -@subsection TWOFISH -Another AES finalist, this one designed by Bruce Schneier and others. -Nettle defines it in @file{}. - -@deftp {Context struct} {struct twofish_ctx} -@end deftp - -@defvr Constant TWOFISH_BLOCK_SIZE -The TWOFISH blocksize, 16 -@end defvr - -@defvr Constant TWOFISH_MIN_KEY_SIZE -Minumim TWOFISH key size, 16 -@end defvr - -@defvr Constant TWOFISH_MAX_KEY_SIZE -Maximum TWOFISH key size, 32 -@end defvr - -@defvr Constant TWOFISH_KEY_SIZE -Default TWOFISH key size, 32 -@end defvr - -@deftypefun void twofish_set_key (struct twofish_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{key}) -Initialize the cipher. The same function is used for both encryption and -decryption. -@end deftypefun - -@deftypefun void twofish_encrypt (struct twofish_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Encryption function. @var{length} must be an integral multiple of the -block size. If it is more than one block, the data is processed in ECB -mode. @code{src} and @code{dst} may be equal, but they must not overlap -in any other way. -@end deftypefun - -@deftypefun void twofish_decrypt (struct twofish_ctx *@var{ctx}, unsigned @var{length}, const uint8_t *@var{dst}, uint8_t *@var{src}) -Analogous to @code{twofish_encrypt} -@end deftypefun - - -@node Miscellaneous functions, , Cipher functions, Reference -@comment node-name, next, previous, up -@section Miscellaneous functions - -@deftypefun {uint8_t *} memxor (uint8_t *@var{dst}, const uint8_t *@var{src}, size_t @var{n}) -XOR:s the source area on top of the destination area. The interface -doesn't follow the Nettle conventions, because it is intended to be -similar to the ANSI-C @code{memcpy} function. -@end deftypefun - -@node Installation, Index, Reference, Top -@comment node-name, next, previous, up -@chapter Installation - -Nettle uses @command{autoconf} and @command{automake}. To build it, -unpack the source and run - -@example -./configure -make -make check -make install -@end example - -to install in the default location, @file{/usr/local}. The library is -installed in @file{/use/local/lib/libnettle.a} and the include files are -installed in @file{/use/local/include/nettle/}. - -Only static libraries are installed. - -@node Index, , Installation, Top -@comment node-name, next, previous, up -@unnumbered Function and Concept Index - -@printindex cp - -@bye diff --git a/lsh/src/nettle/parity.h b/lsh/src/nettle/parity.h deleted file mode 100644 index 252ff85..0000000 --- a/lsh/src/nettle/parity.h +++ /dev/null @@ -1,10 +0,0 @@ -/* automagically produced - do not fuss with this information */ - -8,1,0,8,0,8,8,0,0,8,8,0,8,0,2,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,3, -0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, -0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, -8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, -0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, -8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, -8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, -4,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,5,0,8,0,8,8,0,0,8,8,0,8,0,6,8, diff --git a/lsh/src/nettle/rotors.h b/lsh/src/nettle/rotors.h deleted file mode 100644 index 290f5d9..0000000 --- a/lsh/src/nettle/rotors.h +++ /dev/null @@ -1,82 +0,0 @@ -/* automagically made - do not fuss with this */ - - 34, 13, 5, 46, 47, 18, 32, 41, 11, 53, 33, 20, - 14, 36, 30, 24, 49, 2, 15, 37, 42, 50, 0, 21, - 38, 48, 6, 26, 39, 4, 52, 25, 12, 27, 31, 40, - 1, 17, 28, 29, 23, 51, 35, 7, 3, 22, 9, 43, - - 41, 20, 12, 53, 54, 25, 39, 48, 18, 31, 40, 27, - 21, 43, 37, 0, 1, 9, 22, 44, 49, 2, 7, 28, - 45, 55, 13, 33, 46, 11, 6, 32, 19, 34, 38, 47, - 8, 24, 35, 36, 30, 3, 42, 14, 10, 29, 16, 50, - - 55, 34, 26, 38, 11, 39, 53, 5, 32, 45, 54, 41, - 35, 2, 51, 14, 15, 23, 36, 3, 8, 16, 21, 42, - 6, 12, 27, 47, 31, 25, 20, 46, 33, 48, 52, 4, - 22, 7, 49, 50, 44, 17, 1, 28, 24, 43, 30, 9, - - 12, 48, 40, 52, 25, 53, 38, 19, 46, 6, 11, 55, - 49, 16, 10, 28, 29, 37, 50, 17, 22, 30, 35, 1, - 20, 26, 41, 4, 45, 39, 34, 31, 47, 5, 13, 18, - 36, 21, 8, 9, 3, 0, 15, 42, 7, 2, 44, 23, - - 26, 5, 54, 13, 39, 38, 52, 33, 31, 20, 25, 12, - 8, 30, 24, 42, 43, 51, 9, 0, 36, 44, 49, 15, - 34, 40, 55, 18, 6, 53, 48, 45, 4, 19, 27, 32, - 50, 35, 22, 23, 17, 14, 29, 1, 21, 16, 3, 37, - - 40, 19, 11, 27, 53, 52, 13, 47, 45, 34, 39, 26, - 22, 44, 7, 1, 2, 10, 23, 14, 50, 3, 8, 29, - 48, 54, 12, 32, 20, 38, 5, 6, 18, 33, 41, 46, - 9, 49, 36, 37, 0, 28, 43, 15, 35, 30, 17, 51, - - 54, 33, 25, 41, 38, 13, 27, 4, 6, 48, 53, 40, - 36, 3, 21, 15, 16, 24, 37, 28, 9, 17, 22, 43, - 5, 11, 26, 46, 34, 52, 19, 20, 32, 47, 55, 31, - 23, 8, 50, 51, 14, 42, 2, 29, 49, 44, 0, 10, - - 11, 47, 39, 55, 52, 27, 41, 18, 20, 5, 38, 54, - 50, 17, 35, 29, 30, 7, 51, 42, 23, 0, 36, 2, - 19, 25, 40, 31, 48, 13, 33, 34, 46, 4, 12, 45, - 37, 22, 9, 10, 28, 1, 16, 43, 8, 3, 14, 24, - - 18, 54, 46, 5, 6, 34, 48, 25, 27, 12, 45, 4, - 2, 24, 42, 36, 37, 14, 3, 49, 30, 7, 43, 9, - 26, 32, 47, 38, 55, 20, 40, 41, 53, 11, 19, 52, - 44, 29, 16, 17, 35, 8, 23, 50, 15, 10, 21, 0, - - 32, 11, 31, 19, 20, 48, 5, 39, 41, 26, 6, 18, - 16, 7, 1, 50, 51, 28, 17, 8, 44, 21, 2, 23, - 40, 46, 4, 52, 12, 34, 54, 55, 38, 25, 33, 13, - 3, 43, 30, 0, 49, 22, 37, 9, 29, 24, 35, 14, - - 46, 25, 45, 33, 34, 5, 19, 53, 55, 40, 20, 32, - 30, 21, 15, 9, 10, 42, 0, 22, 3, 35, 16, 37, - 54, 31, 18, 13, 26, 48, 11, 12, 52, 39, 47, 27, - 17, 2, 44, 14, 8, 36, 51, 23, 43, 7, 49, 28, - - 31, 39, 6, 47, 48, 19, 33, 38, 12, 54, 34, 46, - 44, 35, 29, 23, 24, 1, 14, 36, 17, 49, 30, 51, - 11, 45, 32, 27, 40, 5, 25, 26, 13, 53, 4, 41, - 0, 16, 3, 28, 22, 50, 10, 37, 2, 21, 8, 42, - - 45, 53, 20, 4, 5, 33, 47, 52, 26, 11, 48, 31, - 3, 49, 43, 37, 7, 15, 28, 50, 0, 8, 44, 10, - 25, 6, 46, 41, 54, 19, 39, 40, 27, 38, 18, 55, - 14, 30, 17, 42, 36, 9, 24, 51, 16, 35, 22, 1, - - 6, 38, 34, 18, 19, 47, 4, 13, 40, 25, 5, 45, - 17, 8, 2, 51, 21, 29, 42, 9, 14, 22, 3, 24, - 39, 20, 31, 55, 11, 33, 53, 54, 41, 52, 32, 12, - 28, 44, 0, 1, 50, 23, 7, 10, 30, 49, 36, 15, - - 20, 52, 48, 32, 33, 4, 18, 27, 54, 39, 19, 6, - 0, 22, 16, 10, 35, 43, 1, 23, 28, 36, 17, 7, - 53, 34, 45, 12, 25, 47, 38, 11, 55, 13, 46, 26, - 42, 3, 14, 15, 9, 37, 21, 24, 44, 8, 50, 29, - - 27, 6, 55, 39, 40, 11, 25, 34, 4, 46, 26, 13, - 7, 29, 23, 17, 42, 50, 8, 30, 35, 43, 24, 14, - 31, 41, 52, 19, 32, 54, 45, 18, 5, 20, 53, 33, - 49, 10, 21, 22, 16, 44, 28, 0, 51, 15, 2, 36, - diff --git a/lsh/src/nettle/serpent.c b/lsh/src/nettle/serpent.c deleted file mode 100644 index 1e7cb41..0000000 --- a/lsh/src/nettle/serpent.c +++ /dev/null @@ -1,373 +0,0 @@ -/* serpent.h - * - * The serpent block cipher. - * - * For more details on this algorithm, see the Serpent website at - * http://www.cl.cam.ac.uk/~rja14/serpent.html - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 1998, 2000, 2001, Ross Anderson, Eli Biham, Lars - * Knudsen, Rafael R. Sevilla, Niels Möller - * - * 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 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 should 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 - */ - -/* I've modified this code a bit so that it interoperates with lsh - * properly. 2000-9-5, Rafael R. Sevilla - */ - -/* NOTE: The copyright notice for the original version of this code - * said "All rights reserved. This code is freely distributed for AES - * selection process. No other use is allowed." However, the authors - * later decided to GPL the code. /nisse */ - -/* FIXME: Use the READ_UINT32 and WRITE_UINT32 macros, where - * applicable. */ - -#include "serpent.h" -#include "serpent_sboxes.h" - -#include "macros.h" - -#include - -void -serpent_set_key(struct serpent_ctx *ctx, - unsigned key_size, const uint8_t *key) -{ - unsigned i, j; - uint32_t w[132], k[132]; - - assert(key_size >= SERPENT_MIN_KEY_SIZE); - assert(key_size <= SERPENT_MAX_KEY_SIZE); - - for (i = key_size, j = 0; - (i >= 4); - i-=4, j++) - { - assert(j<8); - /* Read the key in the reverse direction. Why? */ - w[j] = READ_UINT32(key + i - 4); - } - - if (j < 8) - { - /* Pad key, "aabbccddeeff" -> 0xccddeeff, 0x01aabb" */ - uint32_t partial = 0x01; - while (i) - partial = (partial << 8 ) | *key++; - w[j++] = partial; - - while (j < 8) - w[j++] = 0; - } - - for(i=8; i<16; i++) - w[i]=ROL(w[i-8]^w[i-5]^w[i-3]^w[i-1]^PHI^(i-8),11); - for(i=0; i<8; i++) - w[i]=w[i+8]; - for(i=8; i<132; i++) - w[i]=ROL(w[i-8]^w[i-5]^w[i-3]^w[i-1]^PHI^i,11); - - RND03(w[ 0], w[ 1], w[ 2], w[ 3], k[ 0], k[ 1], k[ 2], k[ 3]); - RND02(w[ 4], w[ 5], w[ 6], w[ 7], k[ 4], k[ 5], k[ 6], k[ 7]); - RND01(w[ 8], w[ 9], w[ 10], w[ 11], k[ 8], k[ 9], k[ 10], k[ 11]); - RND00(w[ 12], w[ 13], w[ 14], w[ 15], k[ 12], k[ 13], k[ 14], k[ 15]); - RND31(w[ 16], w[ 17], w[ 18], w[ 19], k[ 16], k[ 17], k[ 18], k[ 19]); - RND30(w[ 20], w[ 21], w[ 22], w[ 23], k[ 20], k[ 21], k[ 22], k[ 23]); - RND29(w[ 24], w[ 25], w[ 26], w[ 27], k[ 24], k[ 25], k[ 26], k[ 27]); - RND28(w[ 28], w[ 29], w[ 30], w[ 31], k[ 28], k[ 29], k[ 30], k[ 31]); - RND27(w[ 32], w[ 33], w[ 34], w[ 35], k[ 32], k[ 33], k[ 34], k[ 35]); - RND26(w[ 36], w[ 37], w[ 38], w[ 39], k[ 36], k[ 37], k[ 38], k[ 39]); - RND25(w[ 40], w[ 41], w[ 42], w[ 43], k[ 40], k[ 41], k[ 42], k[ 43]); - RND24(w[ 44], w[ 45], w[ 46], w[ 47], k[ 44], k[ 45], k[ 46], k[ 47]); - RND23(w[ 48], w[ 49], w[ 50], w[ 51], k[ 48], k[ 49], k[ 50], k[ 51]); - RND22(w[ 52], w[ 53], w[ 54], w[ 55], k[ 52], k[ 53], k[ 54], k[ 55]); - RND21(w[ 56], w[ 57], w[ 58], w[ 59], k[ 56], k[ 57], k[ 58], k[ 59]); - RND20(w[ 60], w[ 61], w[ 62], w[ 63], k[ 60], k[ 61], k[ 62], k[ 63]); - RND19(w[ 64], w[ 65], w[ 66], w[ 67], k[ 64], k[ 65], k[ 66], k[ 67]); - RND18(w[ 68], w[ 69], w[ 70], w[ 71], k[ 68], k[ 69], k[ 70], k[ 71]); - RND17(w[ 72], w[ 73], w[ 74], w[ 75], k[ 72], k[ 73], k[ 74], k[ 75]); - RND16(w[ 76], w[ 77], w[ 78], w[ 79], k[ 76], k[ 77], k[ 78], k[ 79]); - RND15(w[ 80], w[ 81], w[ 82], w[ 83], k[ 80], k[ 81], k[ 82], k[ 83]); - RND14(w[ 84], w[ 85], w[ 86], w[ 87], k[ 84], k[ 85], k[ 86], k[ 87]); - RND13(w[ 88], w[ 89], w[ 90], w[ 91], k[ 88], k[ 89], k[ 90], k[ 91]); - RND12(w[ 92], w[ 93], w[ 94], w[ 95], k[ 92], k[ 93], k[ 94], k[ 95]); - RND11(w[ 96], w[ 97], w[ 98], w[ 99], k[ 96], k[ 97], k[ 98], k[ 99]); - RND10(w[100], w[101], w[102], w[103], k[100], k[101], k[102], k[103]); - RND09(w[104], w[105], w[106], w[107], k[104], k[105], k[106], k[107]); - RND08(w[108], w[109], w[110], w[111], k[108], k[109], k[110], k[111]); - RND07(w[112], w[113], w[114], w[115], k[112], k[113], k[114], k[115]); - RND06(w[116], w[117], w[118], w[119], k[116], k[117], k[118], k[119]); - RND05(w[120], w[121], w[122], w[123], k[120], k[121], k[122], k[123]); - RND04(w[124], w[125], w[126], w[127], k[124], k[125], k[126], k[127]); - RND03(w[128], w[129], w[130], w[131], k[128], k[129], k[130], k[131]); - - for(i=0; i<=32; i++) - for(j=0; j<4; j++) - ctx->keys[i][j] = k[4*i+j]; -} - -void -serpent_encrypt(struct serpent_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *plain) -{ - register uint32_t x0, x1, x2, x3; - register uint32_t y0, y1, y2, y3; - - FOR_BLOCKS(length, dst, plain, SERPENT_BLOCK_SIZE) - { - /* Why the reverse order? */ - x0=READ_UINT32(plain + 12); - x1=READ_UINT32(plain + 8); - x2=READ_UINT32(plain + 4); - x3=READ_UINT32(plain); - - /* Start to encrypt the plaintext x */ - keying(x0, x1, x2, x3, ctx->keys[ 0]); - RND00(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 1]); - RND01(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 2]); - RND02(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 3]); - RND03(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 4]); - RND04(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 5]); - RND05(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 6]); - RND06(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 7]); - RND07(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 8]); - RND08(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[ 9]); - RND09(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[10]); - RND10(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[11]); - RND11(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[12]); - RND12(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[13]); - RND13(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[14]); - RND14(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[15]); - RND15(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[16]); - RND16(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[17]); - RND17(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[18]); - RND18(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[19]); - RND19(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[20]); - RND20(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[21]); - RND21(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[22]); - RND22(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[23]); - RND23(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[24]); - RND24(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[25]); - RND25(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[26]); - RND26(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[27]); - RND27(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[28]); - RND28(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[29]); - RND29(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[30]); - RND30(x0, x1, x2, x3, y0, y1, y2, y3); - transform(y0, y1, y2, y3, x0, x1, x2, x3); - keying(x0, x1, x2, x3, ctx->keys[31]); - RND31(x0, x1, x2, x3, y0, y1, y2, y3); - x0 = y0; x1 = y1; x2 = y2; x3 = y3; - keying(x0, x1, x2, x3, ctx->keys[32]); - - /* The ciphertext is now in x */ - - /* Why the reverse order? */ - WRITE_UINT32(dst, x3); - WRITE_UINT32(dst+4, x2); - WRITE_UINT32(dst+8, x1); - WRITE_UINT32(dst+12, x0); - } -} - -void -serpent_decrypt(struct serpent_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *cipher) -{ - register uint32_t x0, x1, x2, x3; - register uint32_t y0, y1, y2, y3; - - FOR_BLOCKS(length, dst, cipher, SERPENT_BLOCK_SIZE) - { - /* Why the reverse order? */ - x0 = READ_UINT32(cipher + 12); - x1 = READ_UINT32(cipher + 8); - x2 = READ_UINT32(cipher + 4); - x3 = READ_UINT32(cipher); - - /* Start to decrypt the ciphertext x */ - keying(x0, x1, x2, x3, ctx->keys[32]); - InvRND31(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[31]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND30(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[30]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND29(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[29]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND28(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[28]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND27(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[27]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND26(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[26]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND25(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[25]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND24(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[24]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND23(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[23]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND22(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[22]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND21(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[21]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND20(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[20]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND19(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[19]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND18(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[18]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND17(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[17]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND16(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[16]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND15(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[15]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND14(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[14]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND13(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[13]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND12(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[12]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND11(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[11]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND10(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[10]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND09(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 9]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND08(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 8]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND07(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 7]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND06(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 6]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND05(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 5]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND04(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 4]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND03(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 3]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND02(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 2]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND01(x0, x1, x2, x3, y0, y1, y2, y3); - keying(y0, y1, y2, y3, ctx->keys[ 1]); - inv_transform(y0, y1, y2, y3, x0, x1, x2, x3); - InvRND00(x0, x1, x2, x3, y0, y1, y2, y3); - x0 = y0; x1 = y1; x2 = y2; x3 = y3; - keying(x0, x1, x2, x3, ctx->keys[ 0]); - - /* The plaintext is now in x */ - - /* Why the reverse order? */ - WRITE_UINT32(dst, x3); - WRITE_UINT32(dst+4, x2); - WRITE_UINT32(dst+8, x1); - WRITE_UINT32(dst+12, x0); - } -} diff --git a/lsh/src/nettle/serpent.h b/lsh/src/nettle/serpent.h deleted file mode 100644 index ae8afeb..0000000 --- a/lsh/src/nettle/serpent.h +++ /dev/null @@ -1,68 +0,0 @@ -/* serpent.h - * - * The serpent block cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* Serpent is a 128-bit block cipher that accepts a key size of 256 - * bits, designed by Ross Anderson, Eli Biham, and Lars Knudsen. See - * http://www.cl.cam.ac.uk/~rja14/serpent.html for details. - */ - -#ifndef NETTLE_SERPENT_H_INCLUDED -#define NETTLE_SERPENT_H_INCLUDED - -#include - -#define SERPENT_BLOCK_SIZE 16 - -/* Other key lengths are possible, but the design of Serpent makes - * smaller key lengths quite pointless; they cheated with the AES - * requirements, using a 256-bit key length exclusively and just - * padding it out if the desired key length was less, so there really - * is no advantage to using key lengths less than 256 bits. */ -#define SERPENT_KEY_SIZE 32 - -/* Allow keys of size 128 <= bits <= 256 */ - -#define SERPENT_MIN_KEY_SIZE 16 -#define SERPENT_MAX_KEY_SIZE 32 - -struct serpent_ctx -{ - uint32_t keys[33][4]; /* key schedule */ -}; - -void -serpent_set_key(struct serpent_ctx *ctx, - unsigned length, const uint8_t *key); - -void -serpent_encrypt(struct serpent_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); -void -serpent_decrypt(struct serpent_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -#endif /* NETTLE_SERPENT_H_INCLUDED */ diff --git a/lsh/src/nettle/serpent_sboxes.h b/lsh/src/nettle/serpent_sboxes.h deleted file mode 100644 index 0dc0787..0000000 --- a/lsh/src/nettle/serpent_sboxes.h +++ /dev/null @@ -1,511 +0,0 @@ -/* serpentsboxes.h - * - * $Id$ - * - * For more details on this algorithm, see the Serpent website at - * http://www.cl.cam.ac.uk/~rja14/serpent.html - */ - -/* Copyright (C) 1998 Ross Anderson, Eli Biham, Lars Knudsen - * - * 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 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 should 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 - */ - -/* I've modified this code a bit so that it interoperates with lsh - * properly. 2000-9-5, Rafael R. Sevilla - */ - -/* NOTE: The copyright notice for the original version of this code - * said "All rights reserved. This code is freely distributed for AES - * selection process. No other use is allowed." However, the authors - * later decided to GPL the code. /nisse */ - -#ifndef SERPENT_SBOXES_H_INCLUDED -#define SERPENT_SBOXES_H_INCLUDED - -#include "serpent.h" - -/* S0: 3 8 15 1 10 6 5 11 14 13 4 2 7 0 9 12 */ - -/* depth = 5,7,4,2, Total gates=18 */ -#define RND00(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t05, t06, t07, t08, t09, t11, t12, t13, t14, t15, t17, t01;\ - t01 = b ^ c ; \ - t02 = a | d ; \ - t03 = a ^ b ; \ - z = t02 ^ t01; \ - t05 = c | z ; \ - t06 = a ^ d ; \ - t07 = b | c ; \ - t08 = d & t05; \ - t09 = t03 & t07; \ - y = t09 ^ t08; \ - t11 = t09 & y ; \ - t12 = c ^ d ; \ - t13 = t07 ^ t11; \ - t14 = b & t06; \ - t15 = t06 ^ t13; \ - w = ~ t15; \ - t17 = w ^ t14; \ - x = t12 ^ t17; } - -/* InvS0: 13 3 11 0 10 6 5 12 1 14 4 7 15 9 8 2 */ - -/* depth = 8,4,3,6, Total gates=19 */ -#define InvRND00(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t08, t09, t10, t12, t13, t14, t15, t17, t18, t01;\ - t01 = c ^ d ; \ - t02 = a | b ; \ - t03 = b | c ; \ - t04 = c & t01; \ - t05 = t02 ^ t01; \ - t06 = a | t04; \ - y = ~ t05; \ - t08 = b ^ d ; \ - t09 = t03 & t08; \ - t10 = d | y ; \ - x = t09 ^ t06; \ - t12 = a | t05; \ - t13 = x ^ t12; \ - t14 = t03 ^ t10; \ - t15 = a ^ c ; \ - z = t14 ^ t13; \ - t17 = t05 & t13; \ - t18 = t14 | t17; \ - w = t15 ^ t18; } - -/* S1: 15 12 2 7 9 0 5 10 1 11 14 8 6 13 3 4 */ - -/* depth = 10,7,3,5, Total gates=18 */ -#define RND01(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t07, t08, t10, t11, t12, t13, t16, t17, t01;\ - t01 = a | d ; \ - t02 = c ^ d ; \ - t03 = ~ b ; \ - t04 = a ^ c ; \ - t05 = a | t03; \ - t06 = d & t04; \ - t07 = t01 & t02; \ - t08 = b | t06; \ - y = t02 ^ t05; \ - t10 = t07 ^ t08; \ - t11 = t01 ^ t10; \ - t12 = y ^ t11; \ - t13 = b & d ; \ - z = ~ t10; \ - x = t13 ^ t12; \ - t16 = t10 | x ; \ - t17 = t05 & t16; \ - w = c ^ t17; } - -/* InvS1: 5 8 2 14 15 6 12 3 11 4 7 9 1 13 10 0 */ - -/* depth = 7,4,5,3, Total gates=18 */ -#define InvRND01(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t14, t15, t17, t01;\ - t01 = a ^ b ; \ - t02 = b | d ; \ - t03 = a & c ; \ - t04 = c ^ t02; \ - t05 = a | t04; \ - t06 = t01 & t05; \ - t07 = d | t03; \ - t08 = b ^ t06; \ - t09 = t07 ^ t06; \ - t10 = t04 | t03; \ - t11 = d & t08; \ - y = ~ t09; \ - x = t10 ^ t11; \ - t14 = a | y ; \ - t15 = t06 ^ x ; \ - z = t01 ^ t04; \ - t17 = c ^ t15; \ - w = t14 ^ t17; } - -/* S2: 8 6 7 9 3 12 10 15 13 1 14 4 0 11 5 2 */ - -/* depth = 3,8,11,7, Total gates=16 */ -#define RND02(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t05, t06, t07, t08, t09, t10, t12, t13, t14, t01;\ - t01 = a | c ; \ - t02 = a ^ b ; \ - t03 = d ^ t01; \ - w = t02 ^ t03; \ - t05 = c ^ w ; \ - t06 = b ^ t05; \ - t07 = b | t05; \ - t08 = t01 & t06; \ - t09 = t03 ^ t07; \ - t10 = t02 | t09; \ - x = t10 ^ t08; \ - t12 = a | d ; \ - t13 = t09 ^ x ; \ - t14 = b ^ t13; \ - z = ~ t09; \ - y = t12 ^ t14; } - -/* InvS2: 12 9 15 4 11 14 1 2 0 3 6 13 5 8 10 7 */ - -/* depth = 3,6,8,3, Total gates=18 */ -#define InvRND02(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t06, t07, t08, t09, t10, t11, t12, t15, t16, t17, t01;\ - t01 = a ^ d ; \ - t02 = c ^ d ; \ - t03 = a & c ; \ - t04 = b | t02; \ - w = t01 ^ t04; \ - t06 = a | c ; \ - t07 = d | w ; \ - t08 = ~ d ; \ - t09 = b & t06; \ - t10 = t08 | t03; \ - t11 = b & t07; \ - t12 = t06 & t02; \ - z = t09 ^ t10; \ - x = t12 ^ t11; \ - t15 = c & z ; \ - t16 = w ^ x ; \ - t17 = t10 ^ t15; \ - y = t16 ^ t17; } - -/* S3: 0 15 11 8 12 9 6 3 13 1 2 4 10 7 5 14 */ - -/* depth = 8,3,5,5, Total gates=18 */ -#define RND03(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t13, t14, t15, t01;\ - t01 = a ^ c ; \ - t02 = a | d ; \ - t03 = a & d ; \ - t04 = t01 & t02; \ - t05 = b | t03; \ - t06 = a & b ; \ - t07 = d ^ t04; \ - t08 = c | t06; \ - t09 = b ^ t07; \ - t10 = d & t05; \ - t11 = t02 ^ t10; \ - z = t08 ^ t09; \ - t13 = d | z ; \ - t14 = a | t07; \ - t15 = b & t13; \ - y = t08 ^ t11; \ - w = t14 ^ t15; \ - x = t05 ^ t04; } - -/* InvS3: 0 9 10 7 11 14 6 13 3 5 12 2 4 8 15 1 */ - -/* depth = 3,6,4,4, Total gates=17 */ -#define InvRND03(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t07, t09, t11, t12, t13, t14, t16, t01;\ - t01 = c | d ; \ - t02 = a | d ; \ - t03 = c ^ t02; \ - t04 = b ^ t02; \ - t05 = a ^ d ; \ - t06 = t04 & t03; \ - t07 = b & t01; \ - y = t05 ^ t06; \ - t09 = a ^ t03; \ - w = t07 ^ t03; \ - t11 = w | t05; \ - t12 = t09 & t11; \ - t13 = a & y ; \ - t14 = t01 ^ t05; \ - x = b ^ t12; \ - t16 = b | t13; \ - z = t14 ^ t16; } - -/* S4: 1 15 8 3 12 0 11 6 2 5 4 10 9 14 7 13 */ - -/* depth = 6,7,5,3, Total gates=19 */ -#define RND04(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t08, t09, t10, t11, t12, t13, t14, t15, t16, t01;\ - t01 = a | b ; \ - t02 = b | c ; \ - t03 = a ^ t02; \ - t04 = b ^ d ; \ - t05 = d | t03; \ - t06 = d & t01; \ - z = t03 ^ t06; \ - t08 = z & t04; \ - t09 = t04 & t05; \ - t10 = c ^ t06; \ - t11 = b & c ; \ - t12 = t04 ^ t08; \ - t13 = t11 | t03; \ - t14 = t10 ^ t09; \ - t15 = a & t05; \ - t16 = t11 | t12; \ - y = t13 ^ t08; \ - x = t15 ^ t16; \ - w = ~ t14; } - -/* InvS4: 5 0 8 3 10 9 7 14 2 12 11 6 4 15 13 1 */ - -/* depth = 6,4,7,3, Total gates=17 */ -#define InvRND04(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t07, t09, t10, t11, t12, t13, t15, t01;\ - t01 = b | d ; \ - t02 = c | d ; \ - t03 = a & t01; \ - t04 = b ^ t02; \ - t05 = c ^ d ; \ - t06 = ~ t03; \ - t07 = a & t04; \ - x = t05 ^ t07; \ - t09 = x | t06; \ - t10 = a ^ t07; \ - t11 = t01 ^ t09; \ - t12 = d ^ t04; \ - t13 = c | t10; \ - z = t03 ^ t12; \ - t15 = a ^ t04; \ - y = t11 ^ t13; \ - w = t15 ^ t09; } - -/* S5: 15 5 2 11 4 10 9 12 0 3 14 8 13 6 7 1 */ - -/* depth = 4,6,8,6, Total gates=17 */ -#define RND05(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t07, t08, t09, t10, t11, t12, t13, t14, t01;\ - t01 = b ^ d ; \ - t02 = b | d ; \ - t03 = a & t01; \ - t04 = c ^ t02; \ - t05 = t03 ^ t04; \ - w = ~ t05; \ - t07 = a ^ t01; \ - t08 = d | w ; \ - t09 = b | t05; \ - t10 = d ^ t08; \ - t11 = b | t07; \ - t12 = t03 | w ; \ - t13 = t07 | t10; \ - t14 = t01 ^ t11; \ - y = t09 ^ t13; \ - x = t07 ^ t08; \ - z = t12 ^ t14; } - -/* InvS5: 8 15 2 9 4 1 13 14 11 6 5 3 7 12 10 0 */ - -/* depth = 4,6,9,7, Total gates=17 */ -#define InvRND05(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t07, t08, t09, t10, t12, t13, t15, t16, t01;\ - t01 = a & d ; \ - t02 = c ^ t01; \ - t03 = a ^ d ; \ - t04 = b & t02; \ - t05 = a & c ; \ - w = t03 ^ t04; \ - t07 = a & w ; \ - t08 = t01 ^ w ; \ - t09 = b | t05; \ - t10 = ~ b ; \ - x = t08 ^ t09; \ - t12 = t10 | t07; \ - t13 = w | x ; \ - z = t02 ^ t12; \ - t15 = t02 ^ t13; \ - t16 = b ^ d ; \ - y = t16 ^ t15; } - -/* S6: 7 2 12 5 8 4 6 11 14 9 1 15 13 3 10 0 */ - -/* depth = 8,3,6,3, Total gates=19 */ -#define RND06(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t07, t08, t09, t10, t11, t12, t13, t15, t17, t18, t01;\ - t01 = a & d ; \ - t02 = b ^ c ; \ - t03 = a ^ d ; \ - t04 = t01 ^ t02; \ - t05 = b | c ; \ - x = ~ t04; \ - t07 = t03 & t05; \ - t08 = b & x ; \ - t09 = a | c ; \ - t10 = t07 ^ t08; \ - t11 = b | d ; \ - t12 = c ^ t11; \ - t13 = t09 ^ t10; \ - y = ~ t13; \ - t15 = x & t03; \ - z = t12 ^ t07; \ - t17 = a ^ b ; \ - t18 = y ^ t15; \ - w = t17 ^ t18; } - -/* InvS6: 15 10 1 13 5 3 6 0 4 9 14 7 2 12 8 11 */ - -/* depth = 5,3,8,6, Total gates=19 */ -#define InvRND06(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t07, t08, t09, t12, t13, t14, t15, t16, t17, t01;\ - t01 = a ^ c ; \ - t02 = ~ c ; \ - t03 = b & t01; \ - t04 = b | t02; \ - t05 = d | t03; \ - t06 = b ^ d ; \ - t07 = a & t04; \ - t08 = a | t02; \ - t09 = t07 ^ t05; \ - x = t06 ^ t08; \ - w = ~ t09; \ - t12 = b & w ; \ - t13 = t01 & t05; \ - t14 = t01 ^ t12; \ - t15 = t07 ^ t13; \ - t16 = d | t02; \ - t17 = a ^ x ; \ - z = t17 ^ t15; \ - y = t16 ^ t14; } - -/* S7: 1 13 15 0 14 8 2 11 7 4 12 10 9 3 5 6 */ - -/* depth = 10,7,10,4, Total gates=19 */ -#define RND07(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t05, t06, t08, t09, t10, t11, t13, t14, t15, t16, t17, t01;\ - t01 = a & c ; \ - t02 = ~ d ; \ - t03 = a & t02; \ - t04 = b | t01; \ - t05 = a & b ; \ - t06 = c ^ t04; \ - z = t03 ^ t06; \ - t08 = c | z ; \ - t09 = d | t05; \ - t10 = a ^ t08; \ - t11 = t04 & z ; \ - x = t09 ^ t10; \ - t13 = b ^ x ; \ - t14 = t01 ^ x ; \ - t15 = c ^ t05; \ - t16 = t11 | t13; \ - t17 = t02 | t14; \ - w = t15 ^ t17; \ - y = a ^ t16; } - -/* InvS7: 3 0 6 13 9 14 15 8 5 12 11 7 10 1 4 2 */ - -/* depth = 9,7,3,3, Total gates=18 */ -#define InvRND07(a,b,c,d,w,x,y,z) \ - { register uint32_t t02, t03, t04, t06, t07, t08, t09, t10, t11, t13, t14, t15, t16, t01;\ - t01 = a & b ; \ - t02 = a | b ; \ - t03 = c | t01; \ - t04 = d & t02; \ - z = t03 ^ t04; \ - t06 = b ^ t04; \ - t07 = d ^ z ; \ - t08 = ~ t07; \ - t09 = t06 | t08; \ - t10 = b ^ d ; \ - t11 = a | d ; \ - x = a ^ t09; \ - t13 = c ^ t06; \ - t14 = c & t11; \ - t15 = d | x ; \ - t16 = t01 | t10; \ - w = t13 ^ t15; \ - y = t14 ^ t16; } - -#define RND08(a,b,c,d,e,f,g,h) RND00(a,b,c,d,e,f,g,h) -#define RND09(a,b,c,d,e,f,g,h) RND01(a,b,c,d,e,f,g,h) -#define RND10(a,b,c,d,e,f,g,h) RND02(a,b,c,d,e,f,g,h) -#define RND11(a,b,c,d,e,f,g,h) RND03(a,b,c,d,e,f,g,h) -#define RND12(a,b,c,d,e,f,g,h) RND04(a,b,c,d,e,f,g,h) -#define RND13(a,b,c,d,e,f,g,h) RND05(a,b,c,d,e,f,g,h) -#define RND14(a,b,c,d,e,f,g,h) RND06(a,b,c,d,e,f,g,h) -#define RND15(a,b,c,d,e,f,g,h) RND07(a,b,c,d,e,f,g,h) -#define RND16(a,b,c,d,e,f,g,h) RND00(a,b,c,d,e,f,g,h) -#define RND17(a,b,c,d,e,f,g,h) RND01(a,b,c,d,e,f,g,h) -#define RND18(a,b,c,d,e,f,g,h) RND02(a,b,c,d,e,f,g,h) -#define RND19(a,b,c,d,e,f,g,h) RND03(a,b,c,d,e,f,g,h) -#define RND20(a,b,c,d,e,f,g,h) RND04(a,b,c,d,e,f,g,h) -#define RND21(a,b,c,d,e,f,g,h) RND05(a,b,c,d,e,f,g,h) -#define RND22(a,b,c,d,e,f,g,h) RND06(a,b,c,d,e,f,g,h) -#define RND23(a,b,c,d,e,f,g,h) RND07(a,b,c,d,e,f,g,h) -#define RND24(a,b,c,d,e,f,g,h) RND00(a,b,c,d,e,f,g,h) -#define RND25(a,b,c,d,e,f,g,h) RND01(a,b,c,d,e,f,g,h) -#define RND26(a,b,c,d,e,f,g,h) RND02(a,b,c,d,e,f,g,h) -#define RND27(a,b,c,d,e,f,g,h) RND03(a,b,c,d,e,f,g,h) -#define RND28(a,b,c,d,e,f,g,h) RND04(a,b,c,d,e,f,g,h) -#define RND29(a,b,c,d,e,f,g,h) RND05(a,b,c,d,e,f,g,h) -#define RND30(a,b,c,d,e,f,g,h) RND06(a,b,c,d,e,f,g,h) -#define RND31(a,b,c,d,e,f,g,h) RND07(a,b,c,d,e,f,g,h) - -#define InvRND08(a,b,c,d,e,f,g,h) InvRND00(a,b,c,d,e,f,g,h) -#define InvRND09(a,b,c,d,e,f,g,h) InvRND01(a,b,c,d,e,f,g,h) -#define InvRND10(a,b,c,d,e,f,g,h) InvRND02(a,b,c,d,e,f,g,h) -#define InvRND11(a,b,c,d,e,f,g,h) InvRND03(a,b,c,d,e,f,g,h) -#define InvRND12(a,b,c,d,e,f,g,h) InvRND04(a,b,c,d,e,f,g,h) -#define InvRND13(a,b,c,d,e,f,g,h) InvRND05(a,b,c,d,e,f,g,h) -#define InvRND14(a,b,c,d,e,f,g,h) InvRND06(a,b,c,d,e,f,g,h) -#define InvRND15(a,b,c,d,e,f,g,h) InvRND07(a,b,c,d,e,f,g,h) -#define InvRND16(a,b,c,d,e,f,g,h) InvRND00(a,b,c,d,e,f,g,h) -#define InvRND17(a,b,c,d,e,f,g,h) InvRND01(a,b,c,d,e,f,g,h) -#define InvRND18(a,b,c,d,e,f,g,h) InvRND02(a,b,c,d,e,f,g,h) -#define InvRND19(a,b,c,d,e,f,g,h) InvRND03(a,b,c,d,e,f,g,h) -#define InvRND20(a,b,c,d,e,f,g,h) InvRND04(a,b,c,d,e,f,g,h) -#define InvRND21(a,b,c,d,e,f,g,h) InvRND05(a,b,c,d,e,f,g,h) -#define InvRND22(a,b,c,d,e,f,g,h) InvRND06(a,b,c,d,e,f,g,h) -#define InvRND23(a,b,c,d,e,f,g,h) InvRND07(a,b,c,d,e,f,g,h) -#define InvRND24(a,b,c,d,e,f,g,h) InvRND00(a,b,c,d,e,f,g,h) -#define InvRND25(a,b,c,d,e,f,g,h) InvRND01(a,b,c,d,e,f,g,h) -#define InvRND26(a,b,c,d,e,f,g,h) InvRND02(a,b,c,d,e,f,g,h) -#define InvRND27(a,b,c,d,e,f,g,h) InvRND03(a,b,c,d,e,f,g,h) -#define InvRND28(a,b,c,d,e,f,g,h) InvRND04(a,b,c,d,e,f,g,h) -#define InvRND29(a,b,c,d,e,f,g,h) InvRND05(a,b,c,d,e,f,g,h) -#define InvRND30(a,b,c,d,e,f,g,h) InvRND06(a,b,c,d,e,f,g,h) -#define InvRND31(a,b,c,d,e,f,g,h) InvRND07(a,b,c,d,e,f,g,h) - -/* Linear transformations and key mixing: */ - -#define ROL(x,n) ((((uint32_t)(x))<<(n))| \ - (((uint32_t)(x))>>(32-(n)))) -#define ROR(x,n) ((((uint32_t)(x))<<(32-(n)))| \ - (((uint32_t)(x))>>(n))) - -#define transform(x0, x1, x2, x3, y0, y1, y2, y3) \ - y0 = ROL(x0, 13); \ - y2 = ROL(x2, 3); \ - y1 = x1 ^ y0 ^ y2; \ - y3 = x3 ^ y2 ^ ((uint32_t)y0)<<3; \ - y1 = ROL(y1, 1); \ - y3 = ROL(y3, 7); \ - y0 = y0 ^ y1 ^ y3; \ - y2 = y2 ^ y3 ^ ((uint32_t)y1<<7); \ - y0 = ROL(y0, 5); \ - y2 = ROL(y2, 22) - -#define inv_transform(x0, x1, x2, x3, y0, y1, y2, y3) \ - y2 = ROR(x2, 22);\ - y0 = ROR(x0, 5); \ - y2 = y2 ^ x3 ^ ((uint32_t)x1<<7); \ - y0 = y0 ^ x1 ^ x3; \ - y3 = ROR(x3, 7); \ - y1 = ROR(x1, 1); \ - y3 = y3 ^ y2 ^ ((uint32_t)y0)<<3; \ - y1 = y1 ^ y0 ^ y2; \ - y2 = ROR(y2, 3); \ - y0 = ROR(y0, 13) - -#define keying(x0, x1, x2, x3, subkey) \ - x0^=subkey[0];x1^=subkey[1]; \ - x2^=subkey[2];x3^=subkey[3] - -/* PHI: Constant used in the key schedule */ -#define PHI 0x9e3779b9L - -#endif /* SERPENT_SBOXES_H_INCLUDED */ diff --git a/lsh/src/nettle/sha1.c b/lsh/src/nettle/sha1.c deleted file mode 100644 index 6c2695d..0000000 --- a/lsh/src/nettle/sha1.c +++ /dev/null @@ -1,383 +0,0 @@ -/* sha1.h - * - * The sha1 hash function. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Peter Gutmann, Andrew Kuchling, Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* Here's the first paragraph of Peter Gutmann's posting, - * <30ajo5$oe8@ccu2.auckland.ac.nz>: - * - * The following is my SHA (FIPS 180) code updated to allow use of the "fixed" - * SHA, thanks to Jim Gillogly and an anonymous contributor for the information on - * what's changed in the new version. The fix is a simple change which involves - * adding a single rotate in the initial expansion function. It is unknown - * whether this is an optimal solution to the problem which was discovered in the - * SHA or whether it's simply a bandaid which fixes the problem with a minimum of - * effort (for example the reengineering of a great many Capstone chips). - */ - -#include "sha1.h" - -#include "macros.h" - -#include -#include - -#if MACOS -extern void abort(); -#endif - -/* A block, treated as a sequence of 32-bit words. */ -#define SHA1_DATA_LENGTH 16 - -/* The SHA f()-functions. The f1 and f3 functions can be optimized to - save one boolean operation each - thanks to Rich Schroeppel, - rcs@cs.arizona.edu for discovering this */ - -/* #define f1(x,y,z) ( ( x & y ) | ( ~x & z ) ) Rounds 0-19 */ -#define f1(x,y,z) ( z ^ ( x & ( y ^ z ) ) ) /* Rounds 0-19 */ -#define f2(x,y,z) ( x ^ y ^ z ) /* Rounds 20-39 */ -/* #define f3(x,y,z) ( ( x & y ) | ( x & z ) | ( y & z ) ) Rounds 40-59 */ -#define f3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) ) /* Rounds 40-59 */ -#define f4(x,y,z) ( x ^ y ^ z ) /* Rounds 60-79 */ - -/* The SHA Mysterious Constants */ - -#define K1 0x5A827999L /* Rounds 0-19 */ -#define K2 0x6ED9EBA1L /* Rounds 20-39 */ -#define K3 0x8F1BBCDCL /* Rounds 40-59 */ -#define K4 0xCA62C1D6L /* Rounds 60-79 */ - -/* SHA initial values */ - -#define h0init 0x67452301L -#define h1init 0xEFCDAB89L -#define h2init 0x98BADCFEL -#define h3init 0x10325476L -#define h4init 0xC3D2E1F0L - -/* 32-bit rotate left - kludged with shifts */ - -#define ROTL(n,X) ( ( (X) << (n) ) | ( (X) >> ( 32 - (n) ) ) ) - -/* The initial expanding function. The hash function is defined over an - 80-word expanded input array W, where the first 16 are copies of the input - data, and the remaining 64 are defined by - - W[ i ] = W[ i - 16 ] ^ W[ i - 14 ] ^ W[ i - 8 ] ^ W[ i - 3 ] - - This implementation generates these values on the fly in a circular - buffer - thanks to Colin Plumb, colin@nyx10.cs.du.edu for this - optimization. - - The updated SHA changes the expanding function by adding a rotate of 1 - bit. Thanks to Jim Gillogly, jim@rand.org, and an anonymous contributor - for this information */ - -#define expand(W,i) ( W[ i & 15 ] = \ - ROTL( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \ - W[ (i - 8) & 15 ] ^ W[ (i - 3) & 15 ] ) ) ) - - -/* The prototype SHA sub-round. The fundamental sub-round is: - - a' = e + ROTL( 5, a ) + f( b, c, d ) + k + data; - b' = a; - c' = ROTL( 30, b ); - d' = c; - e' = d; - - but this is implemented by unrolling the loop 5 times and renaming the - variables ( e, a, b, c, d ) = ( a', b', c', d', e' ) each iteration. - This code is then replicated 20 times for each of the 4 functions, using - the next 20 values from the W[] array each time */ - -#define subRound(a, b, c, d, e, f, k, data) \ - ( e += ROTL( 5, a ) + f( b, c, d ) + k + data, b = ROTL( 30, b ) ) - -/* Initialize the SHA values */ - -void -sha1_init(struct sha1_ctx *ctx) -{ - /* Set the h-vars to their initial values */ - ctx->digest[ 0 ] = h0init; - ctx->digest[ 1 ] = h1init; - ctx->digest[ 2 ] = h2init; - ctx->digest[ 3 ] = h3init; - ctx->digest[ 4 ] = h4init; - - /* Initialize bit count */ - ctx->count_low = ctx->count_high = 0; - - /* Initialize buffer */ - ctx->index = 0; -} - -/* Perform the SHA transformation. Note that this code, like MD5, seems to - break some optimizing compilers due to the complexity of the expressions - and the size of the basic block. It may be necessary to split it into - sections, e.g. based on the four subrounds - - Note that this function destroys the data area */ - -static void -sha1_transform(uint32_t *state, uint32_t *data) -{ - uint32_t A, B, C, D, E; /* Local vars */ - - /* Set up first buffer and local data buffer */ - A = state[0]; - B = state[1]; - C = state[2]; - D = state[3]; - E = state[4]; - - /* Heavy mangling, in 4 sub-rounds of 20 interations each. */ - subRound( A, B, C, D, E, f1, K1, data[ 0] ); - subRound( E, A, B, C, D, f1, K1, data[ 1] ); - subRound( D, E, A, B, C, f1, K1, data[ 2] ); - subRound( C, D, E, A, B, f1, K1, data[ 3] ); - subRound( B, C, D, E, A, f1, K1, data[ 4] ); - subRound( A, B, C, D, E, f1, K1, data[ 5] ); - subRound( E, A, B, C, D, f1, K1, data[ 6] ); - subRound( D, E, A, B, C, f1, K1, data[ 7] ); - subRound( C, D, E, A, B, f1, K1, data[ 8] ); - subRound( B, C, D, E, A, f1, K1, data[ 9] ); - subRound( A, B, C, D, E, f1, K1, data[10] ); - subRound( E, A, B, C, D, f1, K1, data[11] ); - subRound( D, E, A, B, C, f1, K1, data[12] ); - subRound( C, D, E, A, B, f1, K1, data[13] ); - subRound( B, C, D, E, A, f1, K1, data[14] ); - subRound( A, B, C, D, E, f1, K1, data[15] ); - subRound( E, A, B, C, D, f1, K1, expand( data, 16 ) ); - subRound( D, E, A, B, C, f1, K1, expand( data, 17 ) ); - subRound( C, D, E, A, B, f1, K1, expand( data, 18 ) ); - subRound( B, C, D, E, A, f1, K1, expand( data, 19 ) ); - - subRound( A, B, C, D, E, f2, K2, expand( data, 20 ) ); - subRound( E, A, B, C, D, f2, K2, expand( data, 21 ) ); - subRound( D, E, A, B, C, f2, K2, expand( data, 22 ) ); - subRound( C, D, E, A, B, f2, K2, expand( data, 23 ) ); - subRound( B, C, D, E, A, f2, K2, expand( data, 24 ) ); - subRound( A, B, C, D, E, f2, K2, expand( data, 25 ) ); - subRound( E, A, B, C, D, f2, K2, expand( data, 26 ) ); - subRound( D, E, A, B, C, f2, K2, expand( data, 27 ) ); - subRound( C, D, E, A, B, f2, K2, expand( data, 28 ) ); - subRound( B, C, D, E, A, f2, K2, expand( data, 29 ) ); - subRound( A, B, C, D, E, f2, K2, expand( data, 30 ) ); - subRound( E, A, B, C, D, f2, K2, expand( data, 31 ) ); - subRound( D, E, A, B, C, f2, K2, expand( data, 32 ) ); - subRound( C, D, E, A, B, f2, K2, expand( data, 33 ) ); - subRound( B, C, D, E, A, f2, K2, expand( data, 34 ) ); - subRound( A, B, C, D, E, f2, K2, expand( data, 35 ) ); - subRound( E, A, B, C, D, f2, K2, expand( data, 36 ) ); - subRound( D, E, A, B, C, f2, K2, expand( data, 37 ) ); - subRound( C, D, E, A, B, f2, K2, expand( data, 38 ) ); - subRound( B, C, D, E, A, f2, K2, expand( data, 39 ) ); - - subRound( A, B, C, D, E, f3, K3, expand( data, 40 ) ); - subRound( E, A, B, C, D, f3, K3, expand( data, 41 ) ); - subRound( D, E, A, B, C, f3, K3, expand( data, 42 ) ); - subRound( C, D, E, A, B, f3, K3, expand( data, 43 ) ); - subRound( B, C, D, E, A, f3, K3, expand( data, 44 ) ); - subRound( A, B, C, D, E, f3, K3, expand( data, 45 ) ); - subRound( E, A, B, C, D, f3, K3, expand( data, 46 ) ); - subRound( D, E, A, B, C, f3, K3, expand( data, 47 ) ); - subRound( C, D, E, A, B, f3, K3, expand( data, 48 ) ); - subRound( B, C, D, E, A, f3, K3, expand( data, 49 ) ); - subRound( A, B, C, D, E, f3, K3, expand( data, 50 ) ); - subRound( E, A, B, C, D, f3, K3, expand( data, 51 ) ); - subRound( D, E, A, B, C, f3, K3, expand( data, 52 ) ); - subRound( C, D, E, A, B, f3, K3, expand( data, 53 ) ); - subRound( B, C, D, E, A, f3, K3, expand( data, 54 ) ); - subRound( A, B, C, D, E, f3, K3, expand( data, 55 ) ); - subRound( E, A, B, C, D, f3, K3, expand( data, 56 ) ); - subRound( D, E, A, B, C, f3, K3, expand( data, 57 ) ); - subRound( C, D, E, A, B, f3, K3, expand( data, 58 ) ); - subRound( B, C, D, E, A, f3, K3, expand( data, 59 ) ); - - subRound( A, B, C, D, E, f4, K4, expand( data, 60 ) ); - subRound( E, A, B, C, D, f4, K4, expand( data, 61 ) ); - subRound( D, E, A, B, C, f4, K4, expand( data, 62 ) ); - subRound( C, D, E, A, B, f4, K4, expand( data, 63 ) ); - subRound( B, C, D, E, A, f4, K4, expand( data, 64 ) ); - subRound( A, B, C, D, E, f4, K4, expand( data, 65 ) ); - subRound( E, A, B, C, D, f4, K4, expand( data, 66 ) ); - subRound( D, E, A, B, C, f4, K4, expand( data, 67 ) ); - subRound( C, D, E, A, B, f4, K4, expand( data, 68 ) ); - subRound( B, C, D, E, A, f4, K4, expand( data, 69 ) ); - subRound( A, B, C, D, E, f4, K4, expand( data, 70 ) ); - subRound( E, A, B, C, D, f4, K4, expand( data, 71 ) ); - subRound( D, E, A, B, C, f4, K4, expand( data, 72 ) ); - subRound( C, D, E, A, B, f4, K4, expand( data, 73 ) ); - subRound( B, C, D, E, A, f4, K4, expand( data, 74 ) ); - subRound( A, B, C, D, E, f4, K4, expand( data, 75 ) ); - subRound( E, A, B, C, D, f4, K4, expand( data, 76 ) ); - subRound( D, E, A, B, C, f4, K4, expand( data, 77 ) ); - subRound( C, D, E, A, B, f4, K4, expand( data, 78 ) ); - subRound( B, C, D, E, A, f4, K4, expand( data, 79 ) ); - - /* Build message digest */ - state[0] += A; - state[1] += B; - state[2] += C; - state[3] += D; - state[4] += E; -} - -static void -sha1_block(struct sha1_ctx *ctx, const uint8_t *block) -{ - uint32_t data[SHA1_DATA_LENGTH]; - int i; - - /* Update block count */ - if (!++ctx->count_low) - ++ctx->count_high; - - /* Endian independent conversion */ - for (i = 0; idigest, data); -} - -void -sha1_update(struct sha1_ctx *ctx, - unsigned length, const uint8_t *buffer) -{ - if (ctx->index) - { /* Try to fill partial block */ - unsigned left = SHA1_DATA_SIZE - ctx->index; - if (length < left) - { - memcpy(ctx->block + ctx->index, buffer, length); - ctx->index += length; - return; /* Finished */ - } - else - { - memcpy(ctx->block + ctx->index, buffer, left); - sha1_block(ctx, ctx->block); - buffer += left; - length -= left; - } - } - while (length >= SHA1_DATA_SIZE) - { - sha1_block(ctx, buffer); - buffer += SHA1_DATA_SIZE; - length -= SHA1_DATA_SIZE; - } - if ((ctx->index = length)) /* This assignment is intended */ - /* Buffer leftovers */ - memcpy(ctx->block, buffer, length); -} - -/* Final wrapup - pad to SHA1_DATA_SIZE-byte boundary with the bit pattern - 1 0* (64-bit count of bits processed, MSB-first) */ - -void -sha1_final(struct sha1_ctx *ctx) -{ - uint32_t data[SHA1_DATA_LENGTH]; - int i; - int words; - - i = ctx->index; - - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - - assert(i < SHA1_DATA_SIZE); - ctx->block[i++] = 0x80; - - /* Fill rest of word */ - for( ; i & 3; i++) - ctx->block[i] = 0; - - /* i is now a multiple of the word size 4 */ - words = i >> 2; - for (i = 0; i < words; i++) - data[i] = READ_UINT32(ctx->block + 4*i); - - if (words > (SHA1_DATA_LENGTH-2)) - { /* No room for length in this block. Process it and - * pad with another one */ - for (i = words ; i < SHA1_DATA_LENGTH; i++) - data[i] = 0; - sha1_transform(ctx->digest, data); - for (i = 0; i < (SHA1_DATA_LENGTH-2); i++) - data[i] = 0; - } - else - for (i = words ; i < SHA1_DATA_LENGTH - 2; i++) - data[i] = 0; - - /* There are 512 = 2^9 bits in one block */ - data[SHA1_DATA_LENGTH-2] = (ctx->count_high << 9) | (ctx->count_low >> 23); - data[SHA1_DATA_LENGTH-1] = (ctx->count_low << 9) | (ctx->index << 3); - sha1_transform(ctx->digest, data); -} - -void -sha1_digest(const struct sha1_ctx *ctx, - unsigned length, - uint8_t *digest) -{ - unsigned i; - unsigned words; - unsigned leftover; - - assert(length <= SHA1_DIGEST_SIZE); - - words = length / 4; - leftover = length % 4; - - for (i = 0; i < words; i++, digest += 4) - WRITE_UINT32(digest, ctx->digest[i]); - - if (leftover) - { - uint32_t word; - unsigned j = leftover; - - assert(i < _SHA1_DIGEST_LENGTH); - - word = ctx->digest[i]; - - switch (leftover) - { - default: - abort(); - case 3: - digest[--j] = (word >> 8) & 0xff; - /* Fall through */ - case 2: - digest[--j] = (word >> 16) & 0xff; - /* Fall through */ - case 1: - digest[--j] = (word >> 24) & 0xff; - } - } -} diff --git a/lsh/src/nettle/sha1.h b/lsh/src/nettle/sha1.h deleted file mode 100644 index ab1a88b..0000000 --- a/lsh/src/nettle/sha1.h +++ /dev/null @@ -1,61 +0,0 @@ -/* sha1.h - * - * The sha1 hash function. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#ifndef NETTLE_SHA1_H_INCLUDED -#define NETTLE_SHA1_H_INCLUDED - -#include - -#define SHA1_DIGEST_SIZE 20 -#define SHA1_DATA_SIZE 64 - -/* Digest is kept internally as 4 32-bit words. */ -#define _SHA1_DIGEST_LENGTH 5 - -struct sha1_ctx -{ - uint32_t digest[_SHA1_DIGEST_LENGTH]; /* Message digest */ - uint32_t count_low, count_high; /* 64-bit block count */ - uint8_t block[SHA1_DATA_SIZE]; /* SHA1 data buffer */ - unsigned int index; /* index into buffer */ -}; - -void -sha1_init(struct sha1_ctx *ctx); - -void -sha1_update(struct sha1_ctx *ctx, - unsigned length, - const uint8_t *data); - -void -sha1_final(struct sha1_ctx *ctx); - -void -sha1_digest(const struct sha1_ctx *ctx, - unsigned length, - uint8_t *digest); - -#endif /* NETTLE_SHA1_H_INCLUDED */ diff --git a/lsh/src/nettle/stamp-h.in b/lsh/src/nettle/stamp-h.in deleted file mode 100644 index 9788f70..0000000 --- a/lsh/src/nettle/stamp-h.in +++ /dev/null @@ -1 +0,0 @@ -timestamp diff --git a/lsh/src/nettle/testsuite/Makefile.am b/lsh/src/nettle/testsuite/Makefile.am deleted file mode 100644 index c3e8990..0000000 --- a/lsh/src/nettle/testsuite/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -CFLAGS = -I$(top_srcdir) @CFLAGS@ -O0 -CPPFLAGS = @CPPFLAGS@ - -TS_PROGS = aes-test arcfour-test blowfish-test cast128-test des-test \ - md5-test sha1-test \ - serpent-test twofish-test - -noinst_PROGRAMS = $(TS_PROGS) - -LDADD = testutils.o ../libnettle.a -EXTRA_DIST = $(SOURCES:.c=.m4) testutils.c testutils.h run-tests - -M4FLAGS = -P -s -%.c: macros.m4 %.m4 - $(M4) $(M4FLAGS) $^ > $@T - test -s $@T && mv -f $@T $@ - -.PNONY: check run-tests - -check: run-tests - -run-tests: $(TS_PROGS) - $(srcdir)/run-tests $^ - diff --git a/lsh/src/nettle/testsuite/Makefile.in b/lsh/src/nettle/testsuite/Makefile.in deleted file mode 100644 index a35cb65..0000000 --- a/lsh/src/nettle/testsuite/Makefile.in +++ /dev/null @@ -1,358 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = .. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -VERSION = @VERSION@ - -CFLAGS = -I$(top_srcdir) @CFLAGS@ -O0 -CPPFLAGS = @CPPFLAGS@ - -TS_PROGS = aes-test arcfour-test blowfish-test cast128-test des-test md5-test sha1-test serpent-test twofish-test - - -noinst_PROGRAMS = $(TS_PROGS) - -LDADD = testutils.o ../libnettle.a -EXTRA_DIST = $(SOURCES:.c=.m4) testutils.c testutils.h run-tests - -M4FLAGS = -P -s -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../config.h -CONFIG_CLEAN_FILES = -PROGRAMS = $(noinst_PROGRAMS) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I.. -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -aes_test_SOURCES = aes-test.c -aes_test_OBJECTS = aes-test.o -aes_test_LDADD = $(LDADD) -aes_test_DEPENDENCIES = testutils.o ../libnettle.a -aes_test_LDFLAGS = -arcfour_test_SOURCES = arcfour-test.c -arcfour_test_OBJECTS = arcfour-test.o -arcfour_test_LDADD = $(LDADD) -arcfour_test_DEPENDENCIES = testutils.o ../libnettle.a -arcfour_test_LDFLAGS = -blowfish_test_SOURCES = blowfish-test.c -blowfish_test_OBJECTS = blowfish-test.o -blowfish_test_LDADD = $(LDADD) -blowfish_test_DEPENDENCIES = testutils.o ../libnettle.a -blowfish_test_LDFLAGS = -cast128_test_SOURCES = cast128-test.c -cast128_test_OBJECTS = cast128-test.o -cast128_test_LDADD = $(LDADD) -cast128_test_DEPENDENCIES = testutils.o ../libnettle.a -cast128_test_LDFLAGS = -des_test_SOURCES = des-test.c -des_test_OBJECTS = des-test.o -des_test_LDADD = $(LDADD) -des_test_DEPENDENCIES = testutils.o ../libnettle.a -des_test_LDFLAGS = -md5_test_SOURCES = md5-test.c -md5_test_OBJECTS = md5-test.o -md5_test_LDADD = $(LDADD) -md5_test_DEPENDENCIES = testutils.o ../libnettle.a -md5_test_LDFLAGS = -sha1_test_SOURCES = sha1-test.c -sha1_test_OBJECTS = sha1-test.o -sha1_test_LDADD = $(LDADD) -sha1_test_DEPENDENCIES = testutils.o ../libnettle.a -sha1_test_LDFLAGS = -serpent_test_SOURCES = serpent-test.c -serpent_test_OBJECTS = serpent-test.o -serpent_test_LDADD = $(LDADD) -serpent_test_DEPENDENCIES = testutils.o ../libnettle.a -serpent_test_LDFLAGS = -twofish_test_SOURCES = twofish-test.c -twofish_test_OBJECTS = twofish-test.o -twofish_test_LDADD = $(LDADD) -twofish_test_DEPENDENCIES = testutils.o ../libnettle.a -twofish_test_LDFLAGS = -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = aes-test.c arcfour-test.c blowfish-test.c cast128-test.c des-test.c md5-test.c sha1-test.c serpent-test.c twofish-test.c -OBJECTS = aes-test.o arcfour-test.o blowfish-test.o cast128-test.o des-test.o md5-test.o sha1-test.o serpent-test.o twofish-test.o - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps testsuite/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -aes-test: $(aes_test_OBJECTS) $(aes_test_DEPENDENCIES) - @rm -f aes-test - $(LINK) $(aes_test_LDFLAGS) $(aes_test_OBJECTS) $(aes_test_LDADD) $(LIBS) - -arcfour-test: $(arcfour_test_OBJECTS) $(arcfour_test_DEPENDENCIES) - @rm -f arcfour-test - $(LINK) $(arcfour_test_LDFLAGS) $(arcfour_test_OBJECTS) $(arcfour_test_LDADD) $(LIBS) - -blowfish-test: $(blowfish_test_OBJECTS) $(blowfish_test_DEPENDENCIES) - @rm -f blowfish-test - $(LINK) $(blowfish_test_LDFLAGS) $(blowfish_test_OBJECTS) $(blowfish_test_LDADD) $(LIBS) - -cast128-test: $(cast128_test_OBJECTS) $(cast128_test_DEPENDENCIES) - @rm -f cast128-test - $(LINK) $(cast128_test_LDFLAGS) $(cast128_test_OBJECTS) $(cast128_test_LDADD) $(LIBS) - -des-test: $(des_test_OBJECTS) $(des_test_DEPENDENCIES) - @rm -f des-test - $(LINK) $(des_test_LDFLAGS) $(des_test_OBJECTS) $(des_test_LDADD) $(LIBS) - -md5-test: $(md5_test_OBJECTS) $(md5_test_DEPENDENCIES) - @rm -f md5-test - $(LINK) $(md5_test_LDFLAGS) $(md5_test_OBJECTS) $(md5_test_LDADD) $(LIBS) - -sha1-test: $(sha1_test_OBJECTS) $(sha1_test_DEPENDENCIES) - @rm -f sha1-test - $(LINK) $(sha1_test_LDFLAGS) $(sha1_test_OBJECTS) $(sha1_test_LDADD) $(LIBS) - -serpent-test: $(serpent_test_OBJECTS) $(serpent_test_DEPENDENCIES) - @rm -f serpent-test - $(LINK) $(serpent_test_LDFLAGS) $(serpent_test_OBJECTS) $(serpent_test_LDADD) $(LIBS) - -twofish-test: $(twofish_test_OBJECTS) $(twofish_test_DEPENDENCIES) - @rm -f twofish-test - $(LINK) $(twofish_test_LDFLAGS) $(twofish_test_OBJECTS) $(twofish_test_LDADD) $(LIBS) - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = testsuite - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -aes-test.o: aes-test.c ../aes.h testutils.h -arcfour-test.o: arcfour-test.c ../arcfour.h testutils.h -blowfish-test.o: blowfish-test.c ../blowfish.h testutils.h -cast128-test.o: cast128-test.c ../cast128.h testutils.h -des-test.o: des-test.c ../des.h testutils.h -md5-test.o: md5-test.c ../md5.h testutils.h -serpent-test.o: serpent-test.c ../serpent.h testutils.h -sha1-test.o: sha1-test.c ../sha1.h testutils.h -testutils.o: testutils.c testutils.h -twofish-test.o: twofish-test.c ../twofish.h testutils.h - -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile $(PROGRAMS) -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \ - mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-noinstPROGRAMS clean-compile clean-tags clean-generic \ - mostlyclean-am - -clean: clean-am - -distclean-am: distclean-noinstPROGRAMS distclean-compile distclean-tags \ - distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-noinstPROGRAMS \ - maintainer-clean-compile maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \ -clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ -check-am installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - -%.c: macros.m4 %.m4 - $(M4) $(M4FLAGS) $^ > $@T - test -s $@T && mv -f $@T $@ - -.PNONY: check run-tests - -check: run-tests - -run-tests: $(TS_PROGS) - $(srcdir)/run-tests $^ - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/nettle/testsuite/aes-test.c b/lsh/src/nettle/testsuite/aes-test.c deleted file mode 100644 index 4502770..0000000 --- a/lsh/src/nettle/testsuite/aes-test.c +++ /dev/null @@ -1,107 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "aes-test.m4" -#include "aes.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct aes_ctx ctx; - -uint8_t msg[AES_BLOCK_SIZE]; -uint8_t cipher[AES_BLOCK_SIZE]; -uint8_t clear[AES_BLOCK_SIZE]; - -/* 128 bit keys */ -decode_hex(msg, "506812A45F08C889 B97F5980038B8359"); - -aes_set_key(&ctx, 16, decode_hex_dup("0001020305060708 0A0B0C0D0F101112")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("D8F532538289EF7D 06B506A4FD5BE9C9"), 16))) - abort(); - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -decode_hex(msg, "5C6D71CA30DE8B8B 00549984D2EC7D4B"); - -aes_set_key(&ctx, 16, decode_hex_dup("14151617191A1B1C 1E1F202123242526")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("59AB30F4D4EE6E4F F9907EF65B1FB68C"), 16))) - abort(); - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -decode_hex(msg, "53F3F4C64F8616E4 E7C56199F48F21F6"); - -aes_set_key(&ctx, 16, decode_hex_dup("28292A2B2D2E2F30 323334353738393A")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("BF1ED2FCB2AF3FD4 1443B56D85025CB1"), 16))) - abort(); - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -decode_hex(msg, "F5F4F7F684878689 A6A7A0A1D2CDCCCF"); - -aes_set_key(&ctx, 16, decode_hex_dup("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("CE52AF650D088CA5 59425223F4D32694"), 16))) - abort(); - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -/* 192 bit keys */ -decode_hex(msg, "2D33EEF2C0430A8A 9EBF45E809C40BB6"); - -aes_set_key(&ctx, 24, decode_hex_dup("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("DFF4945E0336DF4C 1C56BC700EFF837F"), 16))) - abort(); - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -/* 256 bit keys */ -decode_hex(msg, "834EADFCCAC7E1B30664B1ABA44815AB"); - -aes_set_key(&ctx, 32, decode_hex_dup("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C 1E1F202123242526")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("1946DABF6A03A2A2 C3D0B05080AED6FC"), 16))) - abort(); - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/aes-test.m4 b/lsh/src/nettle/testsuite/aes-test.m4 deleted file mode 100644 index ec05c19..0000000 --- a/lsh/src/nettle/testsuite/aes-test.m4 +++ /dev/null @@ -1,80 +0,0 @@ -#include "aes.h" - -BEGIN_TEST - -struct aes_ctx ctx; - -uint8_t msg[AES_BLOCK_SIZE]; -uint8_t cipher[AES_BLOCK_SIZE]; -uint8_t clear[AES_BLOCK_SIZE]; - -/* 128 bit keys */ -H(msg, "506812A45F08C889 B97F5980038B8359"); - -aes_set_key(&ctx, 16, H("0001020305060708 0A0B0C0D0F101112")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("D8F532538289EF7D 06B506A4FD5BE9C9"))) - FAIL; - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -H(msg, "5C6D71CA30DE8B8B 00549984D2EC7D4B"); - -aes_set_key(&ctx, 16, H("14151617191A1B1C 1E1F202123242526")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("59AB30F4D4EE6E4F F9907EF65B1FB68C"))) - FAIL; - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -H(msg, "53F3F4C64F8616E4 E7C56199F48F21F6"); - -aes_set_key(&ctx, 16, H("28292A2B2D2E2F30 323334353738393A")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("BF1ED2FCB2AF3FD4 1443B56D85025CB1"))) - FAIL; - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -H(msg, "F5F4F7F684878689 A6A7A0A1D2CDCCCF"); - -aes_set_key(&ctx, 16, H("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("CE52AF650D088CA5 59425223F4D32694"))) - FAIL; - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -/* 192 bit keys */ -H(msg, "2D33EEF2C0430A8A 9EBF45E809C40BB6"); - -aes_set_key(&ctx, 24, H("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("DFF4945E0336DF4C 1C56BC700EFF837F"))) - FAIL; - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -/* 256 bit keys */ -H(msg, "834EADFCCAC7E1B30664B1ABA44815AB"); - -aes_set_key(&ctx, 32, H("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C 1E1F202123242526")); -aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("1946DABF6A03A2A2 C3D0B05080AED6FC"))) - FAIL; - -aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; diff --git a/lsh/src/nettle/testsuite/arcfour-test.c b/lsh/src/nettle/testsuite/arcfour-test.c deleted file mode 100644 index b112344..0000000 --- a/lsh/src/nettle/testsuite/arcfour-test.c +++ /dev/null @@ -1,38 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "arcfour-test.m4" -#include "arcfour.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct arcfour_ctx ctx; -const uint8_t *clear = decode_hex_dup("01234567 89ABCDEF"); -uint8_t cipher[8]; -arcfour_set_key(&ctx, 16, decode_hex_dup("01234567 89ABCDEF 00000000 00000000")); -arcfour_crypt(&ctx, 8, cipher, clear); -if (!(!memcmp (cipher, decode_hex_dup("69723659 1B5242B1"), 8))) - abort(); -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/arcfour-test.m4 b/lsh/src/nettle/testsuite/arcfour-test.m4 deleted file mode 100644 index 3db86d6..0000000 --- a/lsh/src/nettle/testsuite/arcfour-test.m4 +++ /dev/null @@ -1,11 +0,0 @@ -#include "arcfour.h" - -BEGIN_TEST - -struct arcfour_ctx ctx; -const uint8_t *clear = H("01234567 89ABCDEF"); -uint8_t cipher[8]; -arcfour_set_key(&ctx, 16, H("01234567 89ABCDEF 00000000 00000000")); -arcfour_crypt(&ctx, 8, cipher, clear); -if (!MEMEQ(8, cipher, H("69723659 1B5242B1"))) - FAIL; diff --git a/lsh/src/nettle/testsuite/blowfish-test.c b/lsh/src/nettle/testsuite/blowfish-test.c deleted file mode 100644 index 437934a..0000000 --- a/lsh/src/nettle/testsuite/blowfish-test.c +++ /dev/null @@ -1,121 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "blowfish-test.m4" -#include "blowfish.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct blowfish_ctx ctx; - -uint8_t msg[BLOWFISH_BLOCK_SIZE]; -uint8_t cipher[BLOWFISH_BLOCK_SIZE]; -uint8_t clear[BLOWFISH_BLOCK_SIZE]; - -/* 208 bit key. Test from GNUPG. */ -blowfish_set_key(&ctx, 26, "abcdefghijklmnopqrstuvwxyz"); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, "BLOWFISH"); -if (!(!memcmp (cipher, decode_hex_dup("32 4E D0 FE F4 13 A2 03"), BLOWFISH_BLOCK_SIZE))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp ("BLOWFISH", clear, BLOWFISH_BLOCK_SIZE))) - abort(); - -/* FIXME: All values below are bogus. */ -#if 0 - -/* 128 bit keys */ -decode_hex(msg, "506812A45F08C889 B97F5980038B8359"); - -blowfish_set_key(&ctx, 16, decode_hex_dup("0001020305060708 0A0B0C0D0F101112")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("D8F532538289EF7D 06B506A4FD5BE9C9"), 16))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -decode_hex(msg, "5C6D71CA30DE8B8B 00549984D2EC7D4B"); - -blowfish_set_key(&ctx, 16, decode_hex_dup("14151617191A1B1C 1E1F202123242526")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("59AB30F4D4EE6E4F F9907EF65B1FB68C"), 16))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -decode_hex(msg, "53F3F4C64F8616E4 E7C56199F48F21F6"); - -blowfish_set_key(&ctx, 16, decode_hex_dup("28292A2B2D2E2F30 323334353738393A")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("BF1ED2FCB2AF3FD4 1443B56D85025CB1"), 16))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -decode_hex(msg, "F5F4F7F684878689 A6A7A0A1D2CDCCCF"); - -blowfish_set_key(&ctx, 16, decode_hex_dup("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("CE52AF650D088CA5 59425223F4D32694"), 16))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -/* 192 bit keys */ -decode_hex(msg, "2D33EEF2C0430A8A 9EBF45E809C40BB6"); - -blowfish_set_key(&ctx, 24, decode_hex_dup("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("DFF4945E0336DF4C 1C56BC700EFF837F"), 16))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); - -/* 256 bit keys */ -decode_hex(msg, "834EADFCCAC7E1B30664B1ABA44815AB"); - -blowfish_set_key(&ctx, 32, decode_hex_dup("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C 1E1F202123242526")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("1946DABF6A03A2A2 C3D0B05080AED6FC"), 16))) - abort(); - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, 16))) - abort(); -#endif -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/blowfish-test.m4 b/lsh/src/nettle/testsuite/blowfish-test.m4 deleted file mode 100644 index 0c6157a..0000000 --- a/lsh/src/nettle/testsuite/blowfish-test.m4 +++ /dev/null @@ -1,94 +0,0 @@ -#include "blowfish.h" - -BEGIN_TEST - -struct blowfish_ctx ctx; - -uint8_t msg[BLOWFISH_BLOCK_SIZE]; -uint8_t cipher[BLOWFISH_BLOCK_SIZE]; -uint8_t clear[BLOWFISH_BLOCK_SIZE]; - -/* 208 bit key. Test from GNUPG. */ -blowfish_set_key(&ctx, 26, "abcdefghijklmnopqrstuvwxyz"); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, "BLOWFISH"); -if (!MEMEQ(BLOWFISH_BLOCK_SIZE, cipher, H("32 4E D0 FE F4 13 A2 03"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(BLOWFISH_BLOCK_SIZE, "BLOWFISH", clear)) - FAIL; - -/* FIXME: All values below are bogus. */ -#if 0 - -/* 128 bit keys */ -H(msg, "506812A45F08C889 B97F5980038B8359"); - -blowfish_set_key(&ctx, 16, H("0001020305060708 0A0B0C0D0F101112")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("D8F532538289EF7D 06B506A4FD5BE9C9"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -H(msg, "5C6D71CA30DE8B8B 00549984D2EC7D4B"); - -blowfish_set_key(&ctx, 16, H("14151617191A1B1C 1E1F202123242526")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("59AB30F4D4EE6E4F F9907EF65B1FB68C"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -H(msg, "53F3F4C64F8616E4 E7C56199F48F21F6"); - -blowfish_set_key(&ctx, 16, H("28292A2B2D2E2F30 323334353738393A")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("BF1ED2FCB2AF3FD4 1443B56D85025CB1"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -H(msg, "F5F4F7F684878689 A6A7A0A1D2CDCCCF"); - -blowfish_set_key(&ctx, 16, H("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("CE52AF650D088CA5 59425223F4D32694"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -/* 192 bit keys */ -H(msg, "2D33EEF2C0430A8A 9EBF45E809C40BB6"); - -blowfish_set_key(&ctx, 24, H("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("DFF4945E0336DF4C 1C56BC700EFF837F"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; - -/* 256 bit keys */ -H(msg, "834EADFCCAC7E1B30664B1ABA44815AB"); - -blowfish_set_key(&ctx, 32, H("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C 1E1F202123242526")); -blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(16, cipher, H("1946DABF6A03A2A2 C3D0B05080AED6FC"))) - FAIL; - -blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(16, msg, clear)) - FAIL; -#endif diff --git a/lsh/src/nettle/testsuite/cast128-test.c b/lsh/src/nettle/testsuite/cast128-test.c deleted file mode 100644 index cb9740e..0000000 --- a/lsh/src/nettle/testsuite/cast128-test.c +++ /dev/null @@ -1,79 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "cast128-test.m4" -#include "cast128.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct cast128_ctx ctx; - -uint8_t msg[CAST128_BLOCK_SIZE]; -uint8_t cipher[CAST128_BLOCK_SIZE]; -uint8_t clear[CAST128_BLOCK_SIZE]; - -#line 12 -/* Test vectors from B.1. Single Plaintext-Key-Ciphertext Sets, RFC -#line 12 - * 2144 */ - -/* 128 bit key */ -decode_hex(msg, "01 23 45 67 89 AB CD EF"); - -cast128_set_key(&ctx, 16, decode_hex_dup("01 23 45 67 12 34 56 78" - "23 45 67 89 34 56 78 9A")); -cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("23 8B 4F E5 84 7E 44 B2"), CAST128_BLOCK_SIZE))) - abort(); - -cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, CAST128_BLOCK_SIZE))) - abort(); - -/* 80 bit key */ -decode_hex(msg, "01 23 45 67 89 AB CD EF"); - -cast128_set_key(&ctx, 10, decode_hex_dup("01 23 45 67 12 34 56 78 23 45")); -cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("EB 6A 71 1A 2C 02 27 1B"), CAST128_BLOCK_SIZE))) - abort(); - -cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, CAST128_BLOCK_SIZE))) - abort(); - -/* 40 bit key */ -decode_hex(msg, "01 23 45 67 89 AB CD EF"); - -cast128_set_key(&ctx, 5, decode_hex_dup("01 23 45 67 12")); -cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg); -if (!(!memcmp (cipher, decode_hex_dup("7A C8 16 D1 6E 9B 30 2E"), CAST128_BLOCK_SIZE))) - abort(); - -cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, CAST128_BLOCK_SIZE))) - abort(); - -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/cast128-test.m4 b/lsh/src/nettle/testsuite/cast128-test.m4 deleted file mode 100644 index e640cdd..0000000 --- a/lsh/src/nettle/testsuite/cast128-test.m4 +++ /dev/null @@ -1,50 +0,0 @@ -#include "cast128.h" - -BEGIN_TEST - -struct cast128_ctx ctx; - -uint8_t msg[CAST128_BLOCK_SIZE]; -uint8_t cipher[CAST128_BLOCK_SIZE]; -uint8_t clear[CAST128_BLOCK_SIZE]; - -/* Test vectors from B.1. Single Plaintext-Key-Ciphertext Sets, RFC - * 2144 */ - -/* 128 bit key */ -H(msg, "01 23 45 67 89 AB CD EF"); - -cast128_set_key(&ctx, 16, H("01 23 45 67 12 34 56 78" - "23 45 67 89 34 56 78 9A")); -cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(CAST128_BLOCK_SIZE, cipher, H("23 8B 4F E5 84 7E 44 B2"))) - FAIL; - -cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(CAST128_BLOCK_SIZE, msg, clear)) - FAIL; - -/* 80 bit key */ -H(msg, "01 23 45 67 89 AB CD EF"); - -cast128_set_key(&ctx, 10, H("01 23 45 67 12 34 56 78 23 45")); -cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(CAST128_BLOCK_SIZE, cipher, H("EB 6A 71 1A 2C 02 27 1B"))) - FAIL; - -cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(CAST128_BLOCK_SIZE, msg, clear)) - FAIL; - -/* 40 bit key */ -H(msg, "01 23 45 67 89 AB CD EF"); - -cast128_set_key(&ctx, 5, H("01 23 45 67 12")); -cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg); -if (!MEMEQ(CAST128_BLOCK_SIZE, cipher, H("7A C8 16 D1 6E 9B 30 2E"))) - FAIL; - -cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(CAST128_BLOCK_SIZE, msg, clear)) - FAIL; - diff --git a/lsh/src/nettle/testsuite/des-test.c b/lsh/src/nettle/testsuite/des-test.c deleted file mode 100644 index dc7efd9..0000000 --- a/lsh/src/nettle/testsuite/des-test.c +++ /dev/null @@ -1,113 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "des-test.m4" -#include "des.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct des_ctx ctx; - -uint8_t msg[DES_BLOCK_SIZE]; -uint8_t cipher[DES_BLOCK_SIZE]; -uint8_t clear[DES_BLOCK_SIZE]; - -decode_hex(msg, "00 00 00 00 00 00 00 00"); - -if (!des_set_key(&ctx, decode_hex_dup("01 01 01 01 01 01 01 80"))) - abort(); - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("9C C6 2D F4 3B 6E ED 74"), DES_BLOCK_SIZE))) -#line 20 - abort(); - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, DES_BLOCK_SIZE))) - abort(); - -decode_hex(msg, "00 00 00 00 00 00 00 40"); - -if (!des_set_key(&ctx, decode_hex_dup("80 01 01 01 01 01 01 01"))) - abort(); - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("A3 80 E0 2A 6B E5 46 96"), DES_BLOCK_SIZE))) -#line 35 - abort(); - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, DES_BLOCK_SIZE))) - abort(); - -decode_hex(msg, "00 00 00 00 00 00 00 00"); - -if (!des_set_key(&ctx, decode_hex_dup("08 19 2A 3B 4C 5D 6E 7F"))) - abort(); - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("25 DD AC 3E 96 17 64 67"), DES_BLOCK_SIZE))) -#line 50 - abort(); - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, DES_BLOCK_SIZE))) - abort(); - -if (!des_set_key(&ctx, decode_hex_dup("01 23 45 67 89 AB CD EF"))) - abort(); - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, "Now is t"); - -if (!(!memcmp (cipher, decode_hex_dup("3F A4 0E 8A 98 4D 48 15"), DES_BLOCK_SIZE))) -#line 63 - abort(); - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!(!memcmp ("Now is t", clear, DES_BLOCK_SIZE))) - abort(); - -/* Parity check */ -if (des_set_key(&ctx, decode_hex_dup("01 01 01 01 01 01 01 00")) - || (ctx.status != DES_BAD_PARITY)) - abort(); - -/* Weak key check */ -if (des_set_key(&ctx, decode_hex_dup("01 01 01 01 01 01 01 01")) - || (ctx.status != DES_WEAK_KEY)) - abort(); - -if (des_set_key(&ctx, decode_hex_dup("01 FE 01 FE 01 FE 01 FE")) - || (ctx.status != DES_WEAK_KEY)) - abort(); - -if (des_set_key(&ctx, decode_hex_dup("FE E0 FE E0 FE F1 FE F1")) - || (ctx.status != DES_WEAK_KEY)) - abort(); - -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/des-test.m4 b/lsh/src/nettle/testsuite/des-test.m4 deleted file mode 100644 index 9d2c40c..0000000 --- a/lsh/src/nettle/testsuite/des-test.m4 +++ /dev/null @@ -1,86 +0,0 @@ -#include "des.h" - -BEGIN_TEST - -struct des_ctx ctx; - -uint8_t msg[DES_BLOCK_SIZE]; -uint8_t cipher[DES_BLOCK_SIZE]; -uint8_t clear[DES_BLOCK_SIZE]; - -H(msg, "00 00 00 00 00 00 00 00"); - -if (!des_set_key(&ctx, H("01 01 01 01 01 01 01 80"))) - FAIL; - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(DES_BLOCK_SIZE, cipher, - H("9C C6 2D F4 3B 6E ED 74"))) - FAIL; - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(DES_BLOCK_SIZE, msg, clear)) - FAIL; - -H(msg, "00 00 00 00 00 00 00 40"); - -if (!des_set_key(&ctx, H("80 01 01 01 01 01 01 01"))) - FAIL; - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(DES_BLOCK_SIZE, cipher, - H("A3 80 E0 2A 6B E5 46 96"))) - FAIL; - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(DES_BLOCK_SIZE, msg, clear)) - FAIL; - -H(msg, "00 00 00 00 00 00 00 00"); - -if (!des_set_key(&ctx, H("08 19 2A 3B 4C 5D 6E 7F"))) - FAIL; - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(DES_BLOCK_SIZE, cipher, - H("25 DD AC 3E 96 17 64 67"))) - FAIL; - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(DES_BLOCK_SIZE, msg, clear)) - FAIL; - -if (!des_set_key(&ctx, H("01 23 45 67 89 AB CD EF"))) - FAIL; - -des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, "Now is t"); - -if (!MEMEQ(DES_BLOCK_SIZE, cipher, - H("3F A4 0E 8A 98 4D 48 15"))) - FAIL; - -des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(DES_BLOCK_SIZE, "Now is t", clear)) - FAIL; - -/* Parity check */ -if (des_set_key(&ctx, H("01 01 01 01 01 01 01 00")) - || (ctx.status != DES_BAD_PARITY)) - FAIL; - -/* Weak key check */ -if (des_set_key(&ctx, H("01 01 01 01 01 01 01 01")) - || (ctx.status != DES_WEAK_KEY)) - FAIL; - -if (des_set_key(&ctx, H("01 FE 01 FE 01 FE 01 FE")) - || (ctx.status != DES_WEAK_KEY)) - FAIL; - -if (des_set_key(&ctx, H("FE E0 FE E0 FE F1 FE F1")) - || (ctx.status != DES_WEAK_KEY)) - FAIL; - diff --git a/lsh/src/nettle/testsuite/md5-test.c b/lsh/src/nettle/testsuite/md5-test.c deleted file mode 100644 index 783373f..0000000 --- a/lsh/src/nettle/testsuite/md5-test.c +++ /dev/null @@ -1,96 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "md5-test.m4" -#include "md5.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct md5_ctx ctx; -uint8_t digest[MD5_DIGEST_SIZE]; - -md5_init(&ctx); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("D41D8CD98F00B204 E9800998ECF8427E"), MD5_DIGEST_SIZE))) - abort(); - -memset(digest, 0, MD5_DIGEST_SIZE); -md5_digest(&ctx, MD5_DIGEST_SIZE - 1, digest); - -if (!(!memcmp (digest, decode_hex_dup("D41D8CD98F00B204 E9800998ECF84200"), MD5_DIGEST_SIZE))) - abort(); - -md5_init(&ctx); -md5_update(&ctx, 1, "a"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("0CC175B9C0F1B6A8 31C399E269772661"), MD5_DIGEST_SIZE))) - abort(); - -md5_init(&ctx); -md5_update(&ctx, 3, "abc"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("900150983cd24fb0 D6963F7D28E17F72"), MD5_DIGEST_SIZE))) - abort(); - -md5_init(&ctx); -md5_update(&ctx, 14, "message digest"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("F96B697D7CB7938D 525A2F31AAF161D0"), MD5_DIGEST_SIZE))) - abort(); - -md5_init(&ctx); -md5_update(&ctx, 26, "abcdefghijklmnopqrstuvwxyz"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("C3FCD3D76192E400 7DFB496CCA67E13B"), MD5_DIGEST_SIZE))) - abort(); - -md5_init(&ctx); -md5_update(&ctx, 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("D174AB98D277D9F5 A5611C2C9F419D9F"), MD5_DIGEST_SIZE))) - abort(); - -md5_init(&ctx); -md5_update(&ctx, 80, "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("57EDF4A22BE3C955 AC49DA2E2107B67A"), MD5_DIGEST_SIZE))) - abort(); - -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/md5-test.m4 b/lsh/src/nettle/testsuite/md5-test.m4 deleted file mode 100644 index 8b074d7..0000000 --- a/lsh/src/nettle/testsuite/md5-test.m4 +++ /dev/null @@ -1,69 +0,0 @@ -#include "md5.h" - -BEGIN_TEST - -struct md5_ctx ctx; -uint8_t digest[MD5_DIGEST_SIZE]; - -md5_init(&ctx); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D41D8CD98F00B204 E9800998ECF8427E"))) - FAIL; - -memset(digest, 0, MD5_DIGEST_SIZE); -md5_digest(&ctx, MD5_DIGEST_SIZE - 1, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D41D8CD98F00B204 E9800998ECF84200"))) - FAIL; - -md5_init(&ctx); -md5_update(&ctx, 1, "a"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("0CC175B9C0F1B6A8 31C399E269772661"))) - FAIL; - -md5_init(&ctx); -md5_update(&ctx, 3, "abc"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("900150983cd24fb0 D6963F7D28E17F72"))) - FAIL; - -md5_init(&ctx); -md5_update(&ctx, 14, "message digest"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("F96B697D7CB7938D 525A2F31AAF161D0"))) - FAIL; - -md5_init(&ctx); -md5_update(&ctx, 26, "abcdefghijklmnopqrstuvwxyz"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("C3FCD3D76192E400 7DFB496CCA67E13B"))) - FAIL; - -md5_init(&ctx); -md5_update(&ctx, 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D174AB98D277D9F5 A5611C2C9F419D9F"))) - FAIL; - -md5_init(&ctx); -md5_update(&ctx, 80, "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890"); -md5_final(&ctx); -md5_digest(&ctx, MD5_DIGEST_SIZE, digest); - -if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("57EDF4A22BE3C955 AC49DA2E2107B67A"))) - FAIL; - diff --git a/lsh/src/nettle/testsuite/run-tests b/lsh/src/nettle/testsuite/run-tests deleted file mode 100644 index 9c51642..0000000 --- a/lsh/src/nettle/testsuite/run-tests +++ /dev/null @@ -1,46 +0,0 @@ -#! /bin/bash - -failed=0 -all=0 - -env_program () { - if [ -x ./"$1" ] ; then - if ./"$1"; then : ; else - echo FAIL: $1 - exit 1 - fi - fi -} - -test_program () { - if "./$1" ; then - echo PASS: ${1%-test} - else - echo FAIL: ${1%-test} - failed=`expr $failed + 1` - fi - all=`expr $all + 1` -} - -env_program setup-env - -if [ $# -eq 0 ] ; then - for f in *-test; do test_program "$f"; done -else - for f in "$@" ; do test_program "$f"; done -fi - -if [ $failed -eq 0 ] ; then - banner="All $all tests passed" -else - banner="$failed of $all tests failed" -fi -dashes=`echo "$banner" | sed s/./=/g` -echo "$dashes" -echo "$banner" -echo "$dashes" - -env_program teardown-env - -[ "$failed" -eq 0 ] - diff --git a/lsh/src/nettle/testsuite/serpent-test.c b/lsh/src/nettle/testsuite/serpent-test.c deleted file mode 100644 index ed1ba66..0000000 --- a/lsh/src/nettle/testsuite/serpent-test.c +++ /dev/null @@ -1,136 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "serpent-test.m4" -#include "serpent.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct serpent_ctx ctx; - -uint8_t msg[SERPENT_BLOCK_SIZE]; -uint8_t cipher[SERPENT_BLOCK_SIZE]; -uint8_t clear[SERPENT_BLOCK_SIZE]; - -#line 12 -/* The first test for each key size from the ecb_vk.txt and ecb_vt.txt -#line 12 - * files in the serpent package. */ - -/* 128 bit key */ - -/* vk, 1 */ -decode_hex(msg, "0000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 16, decode_hex_dup("8000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("49AFBFAD9D5A3405 2CD8FFA5986BD2DD"), SERPENT_BLOCK_SIZE))) -#line 24 - abort(); - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, SERPENT_BLOCK_SIZE))) - abort(); - -/* vt, 1 */ -decode_hex(msg, "8000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 16, decode_hex_dup("0000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("10B5FFB720B8CB90 02A1142B0BA2E94A"), SERPENT_BLOCK_SIZE))) -#line 38 - abort(); - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, SERPENT_BLOCK_SIZE))) - abort(); - -/* 192 bit key */ - -/* vk, 1 */ -decode_hex(msg, "0000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 24, decode_hex_dup("8000000000000000 0000000000000000" - "0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("E78E5402C7195568 AC3678F7A3F60C66"), SERPENT_BLOCK_SIZE))) -#line 55 - abort(); - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, SERPENT_BLOCK_SIZE))) - abort(); - -/* vt, 1 */ -decode_hex(msg, "8000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 24, decode_hex_dup("0000000000000000 0000000000000000" - "0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("B10B271BA25257E1 294F2B51F076D0D9"), SERPENT_BLOCK_SIZE))) -#line 70 - abort(); - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, SERPENT_BLOCK_SIZE))) - abort(); - -/* 256 bit key */ - -/* vk, 1 */ -decode_hex(msg, "0000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 32, decode_hex_dup("8000000000000000 0000000000000000" - "0000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("ABED96E766BF28CB C0EBD21A82EF0819"), SERPENT_BLOCK_SIZE))) -#line 87 - abort(); - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, SERPENT_BLOCK_SIZE))) - abort(); - -/* vt, 1 */ -decode_hex(msg, "8000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 32, decode_hex_dup("0000000000000000 0000000000000000" - "0000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("DA5A7992B1B4AE6F 8C004BC8A7DE5520"), SERPENT_BLOCK_SIZE))) -#line 102 - abort(); - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, SERPENT_BLOCK_SIZE))) - abort(); - -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/serpent-test.m4 b/lsh/src/nettle/testsuite/serpent-test.m4 deleted file mode 100644 index f51b540..0000000 --- a/lsh/src/nettle/testsuite/serpent-test.m4 +++ /dev/null @@ -1,107 +0,0 @@ -#include "serpent.h" - -BEGIN_TEST - -struct serpent_ctx ctx; - -uint8_t msg[SERPENT_BLOCK_SIZE]; -uint8_t cipher[SERPENT_BLOCK_SIZE]; -uint8_t clear[SERPENT_BLOCK_SIZE]; - -/* The first test for each key size from the ecb_vk.txt and ecb_vt.txt - * files in the serpent package. */ - -/* 128 bit key */ - -/* vk, 1 */ -H(msg, "0000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 16, H("8000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(SERPENT_BLOCK_SIZE, cipher, - H("49AFBFAD9D5A3405 2CD8FFA5986BD2DD"))) - FAIL; - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(SERPENT_BLOCK_SIZE, msg, clear)) - FAIL; - -/* vt, 1 */ -H(msg, "8000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 16, H("0000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(SERPENT_BLOCK_SIZE, cipher, - H("10B5FFB720B8CB90 02A1142B0BA2E94A"))) - FAIL; - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(SERPENT_BLOCK_SIZE, msg, clear)) - FAIL; - -/* 192 bit key */ - -/* vk, 1 */ -H(msg, "0000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 24, H("8000000000000000 0000000000000000" - "0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(SERPENT_BLOCK_SIZE, cipher, - H("E78E5402C7195568 AC3678F7A3F60C66"))) - FAIL; - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(SERPENT_BLOCK_SIZE, msg, clear)) - FAIL; - -/* vt, 1 */ -H(msg, "8000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 24, H("0000000000000000 0000000000000000" - "0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(SERPENT_BLOCK_SIZE, cipher, - H("B10B271BA25257E1 294F2B51F076D0D9"))) - FAIL; - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(SERPENT_BLOCK_SIZE, msg, clear)) - FAIL; - -/* 256 bit key */ - -/* vk, 1 */ -H(msg, "0000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 32, H("8000000000000000 0000000000000000" - "0000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(SERPENT_BLOCK_SIZE, cipher, - H("ABED96E766BF28CB C0EBD21A82EF0819"))) - FAIL; - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(SERPENT_BLOCK_SIZE, msg, clear)) - FAIL; - -/* vt, 1 */ -H(msg, "8000000000000000 0000000000000000"); - -serpent_set_key(&ctx, 32, H("0000000000000000 0000000000000000" - "0000000000000000 0000000000000000")); -serpent_encrypt(&ctx, SERPENT_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(SERPENT_BLOCK_SIZE, cipher, - H("DA5A7992B1B4AE6F 8C004BC8A7DE5520"))) - FAIL; - -serpent_decrypt(&ctx, SERPENT_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(SERPENT_BLOCK_SIZE, msg, clear)) - FAIL; - diff --git a/lsh/src/nettle/testsuite/sha1-test.c b/lsh/src/nettle/testsuite/sha1-test.c deleted file mode 100644 index 7a11b06..0000000 --- a/lsh/src/nettle/testsuite/sha1-test.c +++ /dev/null @@ -1,112 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "sha1-test.m4" -#include "sha1.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct sha1_ctx ctx; -uint8_t digest[SHA1_DIGEST_SIZE]; - -sha1_init(&ctx); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709"), SHA1_DIGEST_SIZE))) -#line 14 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 1, "a"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8"), SHA1_DIGEST_SIZE))) -#line 23 - abort(); - -memset(digest, 0, SHA1_DIGEST_SIZE); -sha1_digest(&ctx, SHA1_DIGEST_SIZE - 1, digest); - -if (!(!memcmp (digest, decode_hex_dup("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 37766700"), SHA1_DIGEST_SIZE))) -#line 30 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 1, "a"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8"), SHA1_DIGEST_SIZE))) -#line 39 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 3, "abc"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("A9993E364706816A BA3E25717850C26C 9CD0D89D"), SHA1_DIGEST_SIZE))) -#line 48 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 26, "abcdefghijklmnopqrstuvwxyz"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89"), SHA1_DIGEST_SIZE))) -#line 57 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 14, "message digest"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3"), SHA1_DIGEST_SIZE))) -#line 66 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940"), SHA1_DIGEST_SIZE))) -#line 75 - abort(); - -sha1_init(&ctx); -sha1_update(&ctx, 80, "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!(!memcmp (digest, decode_hex_dup("50ABF5706A150990 A08B2C5EA40FA0E5 85554732"), SHA1_DIGEST_SIZE))) -#line 85 - abort(); -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/sha1-test.m4 b/lsh/src/nettle/testsuite/sha1-test.m4 deleted file mode 100644 index fea00db..0000000 --- a/lsh/src/nettle/testsuite/sha1-test.m4 +++ /dev/null @@ -1,85 +0,0 @@ -#include "sha1.h" - -BEGIN_TEST - -struct sha1_ctx ctx; -uint8_t digest[SHA1_DIGEST_SIZE]; - -sha1_init(&ctx); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 1, "a"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8"))) - FAIL; - -memset(digest, 0, SHA1_DIGEST_SIZE); -sha1_digest(&ctx, SHA1_DIGEST_SIZE - 1, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 37766700"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 1, "a"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 3, "abc"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("A9993E364706816A BA3E25717850C26C 9CD0D89D"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 26, "abcdefghijklmnopqrstuvwxyz"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 14, "message digest"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940"))) - FAIL; - -sha1_init(&ctx); -sha1_update(&ctx, 80, "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890"); -sha1_final(&ctx); -sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); - -if (!MEMEQ(SHA1_DIGEST_SIZE, digest, - H("50ABF5706A150990 A08B2C5EA40FA0E5 85554732"))) - FAIL; diff --git a/lsh/src/nettle/testsuite/testutils.c b/lsh/src/nettle/testsuite/testutils.c deleted file mode 100644 index ee0cd5e..0000000 --- a/lsh/src/nettle/testsuite/testutils.c +++ /dev/null @@ -1,80 +0,0 @@ -/* testutils.c */ - -#include "testutils.h" - -#include -#include -#include - -int -decode_hex(uint8_t *dst, const char *hex) -{ - /* -1 means invalid */ - const signed char hex_digits[0x100] = - { - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 - }; - unsigned i = 0; - - for (;;) - { - int high, low; - - while (*hex && isspace((unsigned)*hex)) - hex++; - - if (!*hex) - return 1; - - high = hex_digits[(unsigned)*hex++]; - if (high < 0) - return 0; - - while (*hex && isspace((unsigned)*hex)) - hex++; - - if (!*hex) - return 0; - - low = hex_digits[(unsigned)*hex++]; - if (low < 0) - return 0; - - dst[i++] = (high << 4) | low; - } -} - -const uint8_t * -decode_hex_dup(const char *hex) -{ - uint8_t *p; - unsigned length = strlen(hex); - - /* Allocates a little more than necessary. */ - p = malloc(length/2); - if (!p) - abort(); - - if (decode_hex(p, hex)) - return p; - else - { - free(p); - return NULL; - } -} diff --git a/lsh/src/nettle/testsuite/testutils.h b/lsh/src/nettle/testsuite/testutils.h deleted file mode 100644 index fd23141..0000000 --- a/lsh/src/nettle/testsuite/testutils.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef NETTLE_TESTUTILS_H_INCLUDED -#define NETTLE_TESTUTILS_H_INCLUDED - -#include - -/* Decodes a NUL-terminated hex string. */ -int -decode_hex(uint8_t *dst, const char *hex); - -/* Allocates space */ -const uint8_t * -decode_hex_dup(const char *hex); - - -#endif /* NETTLE_TESTUTILS_H_INCLUDED */ diff --git a/lsh/src/nettle/testsuite/twofish-test.c b/lsh/src/nettle/testsuite/twofish-test.c deleted file mode 100644 index 53d2ba5..0000000 --- a/lsh/src/nettle/testsuite/twofish-test.c +++ /dev/null @@ -1,77 +0,0 @@ -#line 9 "macros.m4" - -#line 26 - - -#line 1 "twofish-test.m4" -#include "twofish.h" - - -#line 3 -#include "testutils.h" -#line 3 - -#line 3 -#include -#line 3 -#include -#line 3 - -#line 3 -int main (int argc, char **argv) -#line 3 -{ -#line 3 - - -struct twofish_ctx ctx; - -uint8_t msg[TWOFISH_BLOCK_SIZE]; -uint8_t cipher[TWOFISH_BLOCK_SIZE]; -uint8_t clear[TWOFISH_BLOCK_SIZE]; - -/* 128 bit key */ -decode_hex(msg, "0000000000000000 0000000000000000"); - -twofish_set_key(&ctx, 16, decode_hex_dup("0000000000000000 0000000000000000")); -twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("9F589F5CF6122C32 B6BFEC2F2AE8C35A"), TWOFISH_BLOCK_SIZE))) -#line 19 - abort(); - -twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, TWOFISH_BLOCK_SIZE))) - abort(); - -/* 192 bit key */ - -twofish_set_key(&ctx, 24, decode_hex_dup("0123456789ABCDEF FEDCBA9876543210" - "0011223344556677")); -twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("CFD1D2E5A9BE9CDF 501F13B892BD2248"), TWOFISH_BLOCK_SIZE))) -#line 33 - abort(); - -twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, TWOFISH_BLOCK_SIZE))) - abort(); - -/* 256 bit key */ -twofish_set_key(&ctx, 32, decode_hex_dup("0123456789ABCDEF FEDCBA9876543210" - "0011223344556677 8899AABBCCDDEEFF")); -twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg); - -if (!(!memcmp (cipher, decode_hex_dup("37527BE0052334B8 9F0CFCCAE87CFA20"), TWOFISH_BLOCK_SIZE))) -#line 46 - abort(); - -twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher); -if (!(!memcmp (msg, clear, TWOFISH_BLOCK_SIZE))) - abort(); -#line 5 "macros.m4" - /* Avoid warnings for argc and argv unused */ - (void) argc; (void) argv; - return 0; -} diff --git a/lsh/src/nettle/testsuite/twofish-test.m4 b/lsh/src/nettle/testsuite/twofish-test.m4 deleted file mode 100644 index 98840bf..0000000 --- a/lsh/src/nettle/testsuite/twofish-test.m4 +++ /dev/null @@ -1,50 +0,0 @@ -#include "twofish.h" - -BEGIN_TEST - -struct twofish_ctx ctx; - -uint8_t msg[TWOFISH_BLOCK_SIZE]; -uint8_t cipher[TWOFISH_BLOCK_SIZE]; -uint8_t clear[TWOFISH_BLOCK_SIZE]; - -/* 128 bit key */ -H(msg, "0000000000000000 0000000000000000"); - -twofish_set_key(&ctx, 16, H("0000000000000000 0000000000000000")); -twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(TWOFISH_BLOCK_SIZE, cipher, - H("9F589F5CF6122C32 B6BFEC2F2AE8C35A"))) - FAIL; - -twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(TWOFISH_BLOCK_SIZE, msg, clear)) - FAIL; - -/* 192 bit key */ - -twofish_set_key(&ctx, 24, H("0123456789ABCDEF FEDCBA9876543210" - "0011223344556677")); -twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(TWOFISH_BLOCK_SIZE, cipher, - H("CFD1D2E5A9BE9CDF 501F13B892BD2248"))) - FAIL; - -twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(TWOFISH_BLOCK_SIZE, msg, clear)) - FAIL; - -/* 256 bit key */ -twofish_set_key(&ctx, 32, H("0123456789ABCDEF FEDCBA9876543210" - "0011223344556677 8899AABBCCDDEEFF")); -twofish_encrypt(&ctx, TWOFISH_BLOCK_SIZE, cipher, msg); - -if (!MEMEQ(TWOFISH_BLOCK_SIZE, cipher, - H("37527BE0052334B8 9F0CFCCAE87CFA20"))) - FAIL; - -twofish_decrypt(&ctx, TWOFISH_BLOCK_SIZE, clear, cipher); -if (!MEMEQ(TWOFISH_BLOCK_SIZE, msg, clear)) - FAIL; diff --git a/lsh/src/nettle/texinfo.tex b/lsh/src/nettle/texinfo.tex deleted file mode 100644 index aa52853..0000000 --- a/lsh/src/nettle/texinfo.tex +++ /dev/null @@ -1,5484 +0,0 @@ -% texinfo.tex -- TeX macros to handle Texinfo files. -% -% Load plain if necessary, i.e., if running under initex. -\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi -% -\def\texinfoversion{1999-01-05}% -% -% Copyright (C) 1985, 86, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98 -% Free Software Foundation, Inc. -% -% This texinfo.tex file 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, or (at -% your option) any later version. -% -% This texinfo.tex 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 should have received a copy of the GNU General Public License -% along with this texinfo.tex file; see the file COPYING. If not, write -% to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -% Boston, MA 02111-1307, USA. -% -% In other words, you are welcome to use, share and improve this program. -% You are forbidden to forbid anyone else to use, share and improve -% what you give them. Help stamp out software-hoarding! -% -% Please try the latest version of texinfo.tex before submitting bug -% reports; you can get the latest version from: -% ftp://ftp.gnu.org/pub/gnu/texinfo.tex -% /home/gd/gnu/doc/texinfo.tex on the GNU machines. -% (and all GNU mirrors, see http://www.gnu.org/order/ftp.html) -% ftp://tug.org/tex/texinfo.tex -% ftp://ctan.org/macros/texinfo/texinfo.tex -% (and all CTAN mirrors, finger ctan@ctan.org for a list). -% The texinfo.tex in the texinfo distribution itself could well be out -% of date, so if that's what you're using, please check. -% -% Send bug reports to bug-texinfo@gnu.org. -% Please include a precise test case in each bug report, -% including a complete document with which we can reproduce the problem. -% -% To process a Texinfo manual with TeX, it's most reliable to use the -% texi2dvi shell script that comes with the distribution. For simple -% manuals, however, you can get away with: -% tex foo.texi -% texindex foo.?? -% tex foo.texi -% tex foo.texi -% dvips foo.dvi -o # or whatever, to process the dvi file. -% The extra runs of TeX get the cross-reference information correct. -% Sometimes one run after texindex suffices, and sometimes you need more -% than two; texi2dvi does it as many times as necessary. - -\message{Loading texinfo [version \texinfoversion]:} - -% If in a .fmt file, print the version number -% and turn on active characters that we couldn't do earlier because -% they might have appeared in the input file name. -\everyjob{\message{[Texinfo version \texinfoversion]}% - \catcode`+=\active \catcode`\_=\active} - -% Save some parts of plain tex whose names we will redefine. - -\let\ptexb=\b -\let\ptexbullet=\bullet -\let\ptexc=\c -\let\ptexcomma=\, -\let\ptexdot=\. -\let\ptexdots=\dots -\let\ptexend=\end -\let\ptexequiv=\equiv -\let\ptexexclam=\! -\let\ptexi=\i -\let\ptexlbrace=\{ -\let\ptexrbrace=\} -\let\ptexstar=\* -\let\ptext=\t - -% We never want plain's outer \+ definition in Texinfo. -% For @tex, we can use \tabalign. -\let\+ = \relax - - -\message{Basics,} -\chardef\other=12 - -% If this character appears in an error message or help string, it -% starts a new line in the output. -\newlinechar = `^^J - -% Set up fixed words for English if not already set. -\ifx\putwordAppendix\undefined \gdef\putwordAppendix{Appendix}\fi -\ifx\putwordChapter\undefined \gdef\putwordChapter{Chapter}\fi -\ifx\putwordfile\undefined \gdef\putwordfile{file}\fi -\ifx\putwordInfo\undefined \gdef\putwordInfo{Info}\fi -\ifx\putwordMethodon\undefined \gdef\putwordMethodon{Method on}\fi -\ifx\putwordon\undefined \gdef\putwordon{on}\fi -\ifx\putwordpage\undefined \gdef\putwordpage{page}\fi -\ifx\putwordsection\undefined \gdef\putwordsection{section}\fi -\ifx\putwordSection\undefined \gdef\putwordSection{Section}\fi -\ifx\putwordsee\undefined \gdef\putwordsee{see}\fi -\ifx\putwordSee\undefined \gdef\putwordSee{See}\fi -\ifx\putwordShortContents\undefined \gdef\putwordShortContents{Short Contents}\fi -\ifx\putwordTableofContents\undefined\gdef\putwordTableofContents{Table of Contents}\fi - -% Ignore a token. -% -\def\gobble#1{} - -\hyphenation{ap-pen-dix} -\hyphenation{mini-buf-fer mini-buf-fers} -\hyphenation{eshell} -\hyphenation{white-space} - -% Margin to add to right of even pages, to left of odd pages. -\newdimen \bindingoffset -\newdimen \normaloffset -\newdimen\pagewidth \newdimen\pageheight - -% Sometimes it is convenient to have everything in the transcript file -% and nothing on the terminal. We don't just call \tracingall here, -% since that produces some useless output on the terminal. -% -\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}% -\ifx\eTeXversion\undefined -\def\loggingall{\tracingcommands2 \tracingstats2 - \tracingpages1 \tracingoutput1 \tracinglostchars1 - \tracingmacros2 \tracingparagraphs1 \tracingrestores1 - \showboxbreadth\maxdimen\showboxdepth\maxdimen -}% -\else -\def\loggingall{\tracingcommands3 \tracingstats2 - \tracingpages1 \tracingoutput1 \tracinglostchars1 - \tracingmacros2 \tracingparagraphs1 \tracingrestores1 - \tracingscantokens1 \tracingassigns1 \tracingifs1 - \tracinggroups1 \tracingnesting2 - \showboxbreadth\maxdimen\showboxdepth\maxdimen -}% -\fi - -% For @cropmarks command. -% Do @cropmarks to get crop marks. -% -\newif\ifcropmarks -\let\cropmarks = \cropmarkstrue -% -% Dimensions to add cropmarks at corners. -% Added by P. A. MacKay, 12 Nov. 1986 -% -\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines -\newdimen\cornerlong \cornerlong=1pc -\newdimen\cornerthick \cornerthick=.3pt -\newdimen\topandbottommargin \topandbottommargin=.75in - -% Main output routine. -\chardef\PAGE = 255 -\output = {\onepageout{\pagecontents\PAGE}} - -\newbox\headlinebox -\newbox\footlinebox - -% \onepageout takes a vbox as an argument. Note that \pagecontents -% does insertions, but you have to call it yourself. -\def\onepageout#1{% - \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi - % - \ifodd\pageno \advance\hoffset by \bindingoffset - \else \advance\hoffset by -\bindingoffset\fi - % - % Do this outside of the \shipout so @code etc. will be expanded in - % the headline as they should be, not taken literally (outputting ''code). - \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}% - \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}% - % - {% - % Have to do this stuff outside the \shipout because we want it to - % take effect in \write's, yet the group defined by the \vbox ends - % before the \shipout runs. - % - \escapechar = `\\ % use backslash in output files. - \indexdummies % don't expand commands in the output. - \normalturnoffactive % \ in index entries must not stay \, e.g., if - % the page break happens to be in the middle of an example. - \shipout\vbox{% - \ifcropmarks \vbox to \outervsize\bgroup - \hsize = \outerhsize - \vskip-\topandbottommargin - \vtop to0pt{% - \line{\ewtop\hfil\ewtop}% - \nointerlineskip - \line{% - \vbox{\moveleft\cornerthick\nstop}% - \hfill - \vbox{\moveright\cornerthick\nstop}% - }% - \vss}% - \vskip\topandbottommargin - \line\bgroup - \hfil % center the page within the outer (page) hsize. - \ifodd\pageno\hskip\bindingoffset\fi - \vbox\bgroup - \fi - % - \unvbox\headlinebox - \pagebody{#1}% - \ifdim\ht\footlinebox > 0pt - % Only leave this space if the footline is nonempty. - % (We lessened \vsize for it in \oddfootingxxx.) - % The \baselineskip=24pt in plain's \makefootline has no effect. - \vskip 2\baselineskip - \unvbox\footlinebox - \fi - % - \ifcropmarks - \egroup % end of \vbox\bgroup - \hfil\egroup % end of (centering) \line\bgroup - \vskip\topandbottommargin plus1fill minus1fill - \boxmaxdepth = \cornerthick - \vbox to0pt{\vss - \line{% - \vbox{\moveleft\cornerthick\nsbot}% - \hfill - \vbox{\moveright\cornerthick\nsbot}% - }% - \nointerlineskip - \line{\ewbot\hfil\ewbot}% - }% - \egroup % \vbox from first cropmarks clause - \fi - }% end of \shipout\vbox - }% end of group with \turnoffactive - \advancepageno - \ifnum\outputpenalty>-20000 \else\dosupereject\fi -} - -\newinsert\margin \dimen\margin=\maxdimen - -\def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}} -{\catcode`\@ =11 -\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi -% marginal hacks, juha@viisa.uucp (Juha Takala) -\ifvoid\margin\else % marginal info is present - \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi -\dimen@=\dp#1 \unvbox#1 -\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi -\ifr@ggedbottom \kern-\dimen@ \vfil \fi} -} - -% Here are the rules for the cropmarks. Note that they are -% offset so that the space between them is truly \outerhsize or \outervsize -% (P. A. MacKay, 12 November, 1986) -% -\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong} -\def\nstop{\vbox - {\hrule height\cornerthick depth\cornerlong width\cornerthick}} -\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong} -\def\nsbot{\vbox - {\hrule height\cornerlong depth\cornerthick width\cornerthick}} - -% Parse an argument, then pass it to #1. The argument is the rest of -% the input line (except we remove a trailing comment). #1 should be a -% macro which expects an ordinary undelimited TeX argument. -% -\def\parsearg#1{% - \let\next = #1% - \begingroup - \obeylines - \futurelet\temp\parseargx -} - -% If the next token is an obeyed space (from an @example environment or -% the like), remove it and recurse. Otherwise, we're done. -\def\parseargx{% - % \obeyedspace is defined far below, after the definition of \sepspaces. - \ifx\obeyedspace\temp - \expandafter\parseargdiscardspace - \else - \expandafter\parseargline - \fi -} - -% Remove a single space (as the delimiter token to the macro call). -{\obeyspaces % - \gdef\parseargdiscardspace {\futurelet\temp\parseargx}} - -{\obeylines % - \gdef\parseargline#1^^M{% - \endgroup % End of the group started in \parsearg. - % - % First remove any @c comment, then any @comment. - % Result of each macro is put in \toks0. - \argremovec #1\c\relax % - \expandafter\argremovecomment \the\toks0 \comment\relax % - % - % Call the caller's macro, saved as \next in \parsearg. - \expandafter\next\expandafter{\the\toks0}% - }% -} - -% Since all \c{,omment} does is throw away the argument, we can let TeX -% do that for us. The \relax here is matched by the \relax in the call -% in \parseargline; it could be more or less anything, its purpose is -% just to delimit the argument to the \c. -\def\argremovec#1\c#2\relax{\toks0 = {#1}} -\def\argremovecomment#1\comment#2\relax{\toks0 = {#1}} - -% \argremovec{,omment} might leave us with trailing spaces, though; e.g., -% @end itemize @c foo -% will have two active spaces as part of the argument with the -% `itemize'. Here we remove all active spaces from #1, and assign the -% result to \toks0. -% -% This loses if there are any *other* active characters besides spaces -% in the argument -- _ ^ +, for example -- since they get expanded. -% Fortunately, Texinfo does not define any such commands. (If it ever -% does, the catcode of the characters in questionwill have to be changed -% here.) But this means we cannot call \removeactivespaces as part of -% \argremovec{,omment}, since @c uses \parsearg, and thus the argument -% that \parsearg gets might well have any character at all in it. -% -\def\removeactivespaces#1{% - \begingroup - \ignoreactivespaces - \edef\temp{#1}% - \global\toks0 = \expandafter{\temp}% - \endgroup -} - -% Change the active space to expand to nothing. -% -\begingroup - \obeyspaces - \gdef\ignoreactivespaces{\obeyspaces\let =\empty} -\endgroup - - -\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next} - -%% These are used to keep @begin/@end levels from running away -%% Call \inENV within environments (after a \begingroup) -\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi} -\def\ENVcheck{% -\ifENV\errmessage{Still within an environment; press RETURN to continue} -\endgroup\fi} % This is not perfect, but it should reduce lossage - -% @begin foo is the same as @foo, for now. -\newhelp\EMsimple{Press RETURN to continue.} - -\outer\def\begin{\parsearg\beginxxx} - -\def\beginxxx #1{% -\expandafter\ifx\csname #1\endcsname\relax -{\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else -\csname #1\endcsname\fi} - -% @end foo executes the definition of \Efoo. -% -\def\end{\parsearg\endxxx} -\def\endxxx #1{% - \removeactivespaces{#1}% - \edef\endthing{\the\toks0}% - % - \expandafter\ifx\csname E\endthing\endcsname\relax - \expandafter\ifx\csname \endthing\endcsname\relax - % There's no \foo, i.e., no ``environment'' foo. - \errhelp = \EMsimple - \errmessage{Undefined command `@end \endthing'}% - \else - \unmatchedenderror\endthing - \fi - \else - % Everything's ok; the right environment has been started. - \csname E\endthing\endcsname - \fi -} - -% There is an environment #1, but it hasn't been started. Give an error. -% -\def\unmatchedenderror#1{% - \errhelp = \EMsimple - \errmessage{This `@end #1' doesn't have a matching `@#1'}% -} - -% Define the control sequence \E#1 to give an unmatched @end error. -% -\def\defineunmatchedend#1{% - \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}% -} - - -% Single-spacing is done by various environments (specifically, in -% \nonfillstart and \quotations). -\newskip\singlespaceskip \singlespaceskip = 12.5pt -\def\singlespace{% - % Why was this kern here? It messes up equalizing space above and below - % environments. --karl, 6may93 - %{\advance \baselineskip by -\singlespaceskip - %\kern \baselineskip}% - \setleading \singlespaceskip -} - -%% Simple single-character @ commands - -% @@ prints an @ -% Kludge this until the fonts are right (grr). -\def\@{{\tt\char64}} - -% This is turned off because it was never documented -% and you can use @w{...} around a quote to suppress ligatures. -%% Define @` and @' to be the same as ` and ' -%% but suppressing ligatures. -%\def\`{{`}} -%\def\'{{'}} - -% Used to generate quoted braces. -\def\mylbrace {{\tt\char123}} -\def\myrbrace {{\tt\char125}} -\let\{=\mylbrace -\let\}=\myrbrace -\begingroup - % Definitions to produce actual \{ & \} command in an index. - \catcode`\{ = 12 \catcode`\} = 12 - \catcode`\[ = 1 \catcode`\] = 2 - \catcode`\@ = 0 \catcode`\\ = 12 - @gdef@lbracecmd[\{]% - @gdef@rbracecmd[\}]% -@endgroup - -% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent -% Others are defined by plain TeX: @` @' @" @^ @~ @= @v @H. -\let\, = \c -\let\dotaccent = \. -\def\ringaccent#1{{\accent23 #1}} -\let\tieaccent = \t -\let\ubaraccent = \b -\let\udotaccent = \d - -% Other special characters: @questiondown @exclamdown -% Plain TeX defines: @AA @AE @O @OE @L (and lowercase versions) @ss. -\def\questiondown{?`} -\def\exclamdown{!`} - -% Dotless i and dotless j, used for accents. -\def\imacro{i} -\def\jmacro{j} -\def\dotless#1{% - \def\temp{#1}% - \ifx\temp\imacro \ptexi - \else\ifx\temp\jmacro \j - \else \errmessage{@dotless can be used only with i or j}% - \fi\fi -} - -% Be sure we're in horizontal mode when doing a tie, since we make space -% equivalent to this in @example-like environments. Otherwise, a space -% at the beginning of a line will start with \penalty -- and -% since \penalty is valid in vertical mode, we'd end up putting the -% penalty on the vertical list instead of in the new paragraph. -{\catcode`@ = 11 - % Avoid using \@M directly, because that causes trouble - % if the definition is written into an index file. - \global\let\tiepenalty = \@M - \gdef\tie{\leavevmode\penalty\tiepenalty\ } -} - -% @: forces normal size whitespace following. -\def\:{\spacefactor=1000 } - -% @* forces a line break. -\def\*{\hfil\break\hbox{}\ignorespaces} - -% @. is an end-of-sentence period. -\def\.{.\spacefactor=3000 } - -% @! is an end-of-sentence bang. -\def\!{!\spacefactor=3000 } - -% @? is an end-of-sentence query. -\def\?{?\spacefactor=3000 } - -% @w prevents a word break. Without the \leavevmode, @w at the -% beginning of a paragraph, when TeX is still in vertical mode, would -% produce a whole line of output instead of starting the paragraph. -\def\w#1{\leavevmode\hbox{#1}} - -% @group ... @end group forces ... to be all on one page, by enclosing -% it in a TeX vbox. We use \vtop instead of \vbox to construct the box -% to keep its height that of a normal line. According to the rules for -% \topskip (p.114 of the TeXbook), the glue inserted is -% max (\topskip - \ht (first item), 0). If that height is large, -% therefore, no glue is inserted, and the space between the headline and -% the text is small, which looks bad. -% -\def\group{\begingroup - \ifnum\catcode13=\active \else - \errhelp = \groupinvalidhelp - \errmessage{@group invalid in context where filling is enabled}% - \fi - % - % The \vtop we start below produces a box with normal height and large - % depth; thus, TeX puts \baselineskip glue before it, and (when the - % next line of text is done) \lineskip glue after it. (See p.82 of - % the TeXbook.) Thus, space below is not quite equal to space - % above. But it's pretty close. - \def\Egroup{% - \egroup % End the \vtop. - \endgroup % End the \group. - }% - % - \vtop\bgroup - % We have to put a strut on the last line in case the @group is in - % the midst of an example, rather than completely enclosing it. - % Otherwise, the interline space between the last line of the group - % and the first line afterwards is too small. But we can't put the - % strut in \Egroup, since there it would be on a line by itself. - % Hence this just inserts a strut at the beginning of each line. - \everypar = {\strut}% - % - % Since we have a strut on every line, we don't need any of TeX's - % normal interline spacing. - \offinterlineskip - % - % OK, but now we have to do something about blank - % lines in the input in @example-like environments, which normally - % just turn into \lisppar, which will insert no space now that we've - % turned off the interline space. Simplest is to make them be an - % empty paragraph. - \ifx\par\lisppar - \edef\par{\leavevmode \par}% - % - % Reset ^^M's definition to new definition of \par. - \obeylines - \fi - % - % Do @comment since we are called inside an environment such as - % @example, where each end-of-line in the input causes an - % end-of-line in the output. We don't want the end-of-line after - % the `@group' to put extra space in the output. Since @group - % should appear on a line by itself (according to the Texinfo - % manual), we don't worry about eating any user text. - \comment -} -% -% TeX puts in an \escapechar (i.e., `@') at the beginning of the help -% message, so this ends up printing `@group can only ...'. -% -\newhelp\groupinvalidhelp{% -group can only be used in environments such as @example,^^J% -where each line of input produces a line of output.} - -% @need space-in-mils -% forces a page break if there is not space-in-mils remaining. - -\newdimen\mil \mil=0.001in - -\def\need{\parsearg\needx} - -% Old definition--didn't work. -%\def\needx #1{\par % -%% This method tries to make TeX break the page naturally -%% if the depth of the box does not fit. -%{\baselineskip=0pt% -%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak -%\prevdepth=-1000pt -%}} - -\def\needx#1{% - % Go into vertical mode, so we don't make a big box in the middle of a - % paragraph. - \par - % - % Don't add any leading before our big empty box, but allow a page - % break, since the best break might be right here. - \allowbreak - \nointerlineskip - \vtop to #1\mil{\vfil}% - % - % TeX does not even consider page breaks if a penalty added to the - % main vertical list is 10000 or more. But in order to see if the - % empty box we just added fits on the page, we must make it consider - % page breaks. On the other hand, we don't want to actually break the - % page after the empty box. So we use a penalty of 9999. - % - % There is an extremely small chance that TeX will actually break the - % page at this \penalty, if there are no other feasible breakpoints in - % sight. (If the user is using lots of big @group commands, which - % almost-but-not-quite fill up a page, TeX will have a hard time doing - % good page breaking, for example.) However, I could not construct an - % example where a page broke at this \penalty; if it happens in a real - % document, then we can reconsider our strategy. - \penalty9999 - % - % Back up by the size of the box, whether we did a page break or not. - \kern -#1\mil - % - % Do not allow a page break right after this kern. - \nobreak -} - -% @br forces paragraph break - -\let\br = \par - -% @dots{} output an ellipsis using the current font. -% We do .5em per period so that it has the same spacing in a typewriter -% font as three actual period characters. -% -\def\dots{% - \leavevmode - \hbox to 1.5em{% - \hskip 0pt plus 0.25fil minus 0.25fil - .\hss.\hss.% - \hskip 0pt plus 0.5fil minus 0.5fil - }% -} - -% @enddots{} is an end-of-sentence ellipsis. -% -\def\enddots{% - \leavevmode - \hbox to 2em{% - \hskip 0pt plus 0.25fil minus 0.25fil - .\hss.\hss.\hss.% - \hskip 0pt plus 0.5fil minus 0.5fil - }% - \spacefactor=3000 -} - - -% @page forces the start of a new page -% -\def\page{\par\vfill\supereject} - -% @exdent text.... -% outputs text on separate line in roman font, starting at standard page margin - -% This records the amount of indent in the innermost environment. -% That's how much \exdent should take out. -\newskip\exdentamount - -% This defn is used inside fill environments such as @defun. -\def\exdent{\parsearg\exdentyyy} -\def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}} - -% This defn is used inside nofill environments such as @example. -\def\nofillexdent{\parsearg\nofillexdentyyy} -\def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount -\leftline{\hskip\leftskip{\rm#1}}}} - -% @inmargin{TEXT} puts TEXT in the margin next to the current paragraph. - -\def\inmargin#1{% -\strut\vadjust{\nobreak\kern-\strutdepth - \vtop to \strutdepth{\baselineskip\strutdepth\vss - \llap{\rightskip=\inmarginspacing \vbox{\noindent #1}}\null}}} -\newskip\inmarginspacing \inmarginspacing=1cm -\def\strutdepth{\dp\strutbox} - -%\hbox{{\rm#1}}\hfil\break}} - -% @include file insert text of that file as input. -% Allow normal characters that we make active in the argument (a file name). -\def\include{\begingroup - \catcode`\\=12 - \catcode`~=12 - \catcode`^=12 - \catcode`_=12 - \catcode`|=12 - \catcode`<=12 - \catcode`>=12 - \catcode`+=12 - \parsearg\includezzz} -% Restore active chars for included file. -\def\includezzz#1{\endgroup\begingroup - % Read the included file in a group so nested @include's work. - \def\thisfile{#1}% - \input\thisfile -\endgroup} - -\def\thisfile{} - -% @center line outputs that line, centered - -\def\center{\parsearg\centerzzz} -\def\centerzzz #1{{\advance\hsize by -\leftskip -\advance\hsize by -\rightskip -\centerline{#1}}} - -% @sp n outputs n lines of vertical space - -\def\sp{\parsearg\spxxx} -\def\spxxx #1{\vskip #1\baselineskip} - -% @comment ...line which is ignored... -% @c is the same as @comment -% @ignore ... @end ignore is another way to write a comment - -\def\comment{\begingroup \catcode`\^^M=\other% -\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other% -\commentxxx} -{\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}} - -\let\c=\comment - -% @paragraphindent is defined for the Info formatting commands only. -\let\paragraphindent=\comment - -% Prevent errors for section commands. -% Used in @ignore and in failing conditionals. -\def\ignoresections{% -\let\chapter=\relax -\let\unnumbered=\relax -\let\top=\relax -\let\unnumberedsec=\relax -\let\unnumberedsection=\relax -\let\unnumberedsubsec=\relax -\let\unnumberedsubsection=\relax -\let\unnumberedsubsubsec=\relax -\let\unnumberedsubsubsection=\relax -\let\section=\relax -\let\subsec=\relax -\let\subsubsec=\relax -\let\subsection=\relax -\let\subsubsection=\relax -\let\appendix=\relax -\let\appendixsec=\relax -\let\appendixsection=\relax -\let\appendixsubsec=\relax -\let\appendixsubsection=\relax -\let\appendixsubsubsec=\relax -\let\appendixsubsubsection=\relax -\let\contents=\relax -\let\smallbook=\relax -\let\titlepage=\relax -} - -% Used in nested conditionals, where we have to parse the Texinfo source -% and so want to turn off most commands, in case they are used -% incorrectly. -% -\def\ignoremorecommands{% - \let\defcodeindex = \relax - \let\defcv = \relax - \let\deffn = \relax - \let\deffnx = \relax - \let\defindex = \relax - \let\defivar = \relax - \let\defmac = \relax - \let\defmethod = \relax - \let\defop = \relax - \let\defopt = \relax - \let\defspec = \relax - \let\deftp = \relax - \let\deftypefn = \relax - \let\deftypefun = \relax - \let\deftypevar = \relax - \let\deftypevr = \relax - \let\defun = \relax - \let\defvar = \relax - \let\defvr = \relax - \let\ref = \relax - \let\xref = \relax - \let\printindex = \relax - \let\pxref = \relax - \let\settitle = \relax - \let\setchapternewpage = \relax - \let\setchapterstyle = \relax - \let\everyheading = \relax - \let\evenheading = \relax - \let\oddheading = \relax - \let\everyfooting = \relax - \let\evenfooting = \relax - \let\oddfooting = \relax - \let\headings = \relax - \let\include = \relax - \let\lowersections = \relax - \let\down = \relax - \let\raisesections = \relax - \let\up = \relax - \let\set = \relax - \let\clear = \relax - \let\item = \relax -} - -% Ignore @ignore ... @end ignore. -% -\def\ignore{\doignore{ignore}} - -% Ignore @ifinfo, @ifhtml, @ifnottex, @html, @menu, and @direntry text. -% -\def\ifinfo{\doignore{ifinfo}} -\def\ifhtml{\doignore{ifhtml}} -\def\ifnottex{\doignore{ifnottex}} -\def\html{\doignore{html}} -\def\menu{\doignore{menu}} -\def\direntry{\doignore{direntry}} - -% @dircategory CATEGORY -- specify a category of the dir file -% which this file should belong to. Ignore this in TeX. -\let\dircategory = \comment - -% Ignore text until a line `@end #1'. -% -\def\doignore#1{\begingroup - % Don't complain about control sequences we have declared \outer. - \ignoresections - % - % Define a command to swallow text until we reach `@end #1'. - % This @ is a catcode 12 token (that is the normal catcode of @ in - % this texinfo.tex file). We change the catcode of @ below to match. - \long\def\doignoretext##1@end #1{\enddoignore}% - % - % Make sure that spaces turn into tokens that match what \doignoretext wants. - \catcode32 = 10 - % - % Ignore braces, too, so mismatched braces don't cause trouble. - \catcode`\{ = 9 - \catcode`\} = 9 - % - % We must not have @c interpreted as a control sequence. - \catcode`\@ = 12 - % - % Make the letter c a comment character so that the rest of the line - % will be ignored. This way, the document can have (for example) - % @c @end ifinfo - % and the @end ifinfo will be properly ignored. - % (We've just changed @ to catcode 12.) - \catcode`\c = 14 - % - % And now expand that command. - \doignoretext -} - -% What we do to finish off ignored text. -% -\def\enddoignore{\endgroup\ignorespaces}% - -\newif\ifwarnedobs\warnedobsfalse -\def\obstexwarn{% - \ifwarnedobs\relax\else - % We need to warn folks that they may have trouble with TeX 3.0. - % This uses \immediate\write16 rather than \message to get newlines. - \immediate\write16{} - \immediate\write16{***WARNING*** for users of Unix TeX 3.0!} - \immediate\write16{This manual trips a bug in TeX version 3.0 (tex hangs).} - \immediate\write16{If you are running another version of TeX, relax.} - \immediate\write16{If you are running Unix TeX 3.0, kill this TeX process.} - \immediate\write16{ Then upgrade your TeX installation if you can.} - \immediate\write16{ (See ftp://ftp.gnu.org/pub/gnu/TeX.README.)} - \immediate\write16{If you are stuck with version 3.0, run the} - \immediate\write16{ script ``tex3patch'' from the Texinfo distribution} - \immediate\write16{ to use a workaround.} - \immediate\write16{} - \global\warnedobstrue - \fi -} - -% **In TeX 3.0, setting text in \nullfont hangs tex. For a -% workaround (which requires the file ``dummy.tfm'' to be installed), -% uncomment the following line: -%%%%%\font\nullfont=dummy\let\obstexwarn=\relax - -% Ignore text, except that we keep track of conditional commands for -% purposes of nesting, up to an `@end #1' command. -% -\def\nestedignore#1{% - \obstexwarn - % We must actually expand the ignored text to look for the @end - % command, so that nested ignore constructs work. Thus, we put the - % text into a \vbox and then do nothing with the result. To minimize - % the change of memory overflow, we follow the approach outlined on - % page 401 of the TeXbook: make the current font be a dummy font. - % - \setbox0 = \vbox\bgroup - % Don't complain about control sequences we have declared \outer. - \ignoresections - % - % Define `@end #1' to end the box, which will in turn undefine the - % @end command again. - \expandafter\def\csname E#1\endcsname{\egroup\ignorespaces}% - % - % We are going to be parsing Texinfo commands. Most cause no - % trouble when they are used incorrectly, but some commands do - % complicated argument parsing or otherwise get confused, so we - % undefine them. - % - % We can't do anything about stray @-signs, unfortunately; - % they'll produce `undefined control sequence' errors. - \ignoremorecommands - % - % Set the current font to be \nullfont, a TeX primitive, and define - % all the font commands to also use \nullfont. We don't use - % dummy.tfm, as suggested in the TeXbook, because not all sites - % might have that installed. Therefore, math mode will still - % produce output, but that should be an extremely small amount of - % stuff compared to the main input. - % - \nullfont - \let\tenrm = \nullfont \let\tenit = \nullfont \let\tensl = \nullfont - \let\tenbf = \nullfont \let\tentt = \nullfont \let\smallcaps = \nullfont - \let\tensf = \nullfont - % Similarly for index fonts (mostly for their use in - % smallexample) - \let\indrm = \nullfont \let\indit = \nullfont \let\indsl = \nullfont - \let\indbf = \nullfont \let\indtt = \nullfont \let\indsc = \nullfont - \let\indsf = \nullfont - % - % Don't complain when characters are missing from the fonts. - \tracinglostchars = 0 - % - % Don't bother to do space factor calculations. - \frenchspacing - % - % Don't report underfull hboxes. - \hbadness = 10000 - % - % Do minimal line-breaking. - \pretolerance = 10000 - % - % Do not execute instructions in @tex - \def\tex{\doignore{tex}}% - % Do not execute macro definitions. - % `c' is a comment character, so the word `macro' will get cut off. - \def\macro{\doignore{ma}}% -} - -% @set VAR sets the variable VAR to an empty value. -% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE. -% -% Since we want to separate VAR from REST-OF-LINE (which might be -% empty), we can't just use \parsearg; we have to insert a space of our -% own to delimit the rest of the line, and then take it out again if we -% didn't need it. Make sure the catcode of space is correct to avoid -% losing inside @example, for instance. -% -\def\set{\begingroup\catcode` =10 - \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR. - \parsearg\setxxx} -\def\setxxx#1{\setyyy#1 \endsetyyy} -\def\setyyy#1 #2\endsetyyy{% - \def\temp{#2}% - \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty - \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted. - \fi - \endgroup -} -% Can't use \xdef to pre-expand #2 and save some time, since \temp or -% \next or other control sequences that we've defined might get us into -% an infinite loop. Consider `@set foo @cite{bar}'. -\def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}} - -% @clear VAR clears (i.e., unsets) the variable VAR. -% -\def\clear{\parsearg\clearxxx} -\def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax} - -% @value{foo} gets the text saved in variable foo. -% -{ - \catcode`\_ = \active - % - % We might end up with active _ or - characters in the argument if - % we're called from @code, as @code{@value{foo-bar_}}. So \let any - % such active characters to their normal equivalents. - \gdef\value{\begingroup - \catcode`\-=12 \catcode`\_=12 - \indexbreaks \let_\normalunderscore - \valuexxx} -} -\def\valuexxx#1{\expandablevalue{#1}\endgroup} - -% We have this subroutine so that we can handle at least some @value's -% properly in indexes (we \let\value to this in \indexdummies). Ones -% whose names contain - or _ still won't work, but we can't do anything -% about that. The command has to be fully expandable, since the result -% winds up in the index file. This means that if the variable's value -% contains other Texinfo commands, it's almost certain it will fail -% (although perhaps we could fix that with sufficient work to do a -% one-level expansion on the result, instead of complete). -% -\def\expandablevalue#1{% - \expandafter\ifx\csname SET#1\endcsname\relax - {[No value for ``#1'']}% - \else - \csname SET#1\endcsname - \fi -} - -% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined -% with @set. -% -\def\ifset{\parsearg\ifsetxxx} -\def\ifsetxxx #1{% - \expandafter\ifx\csname SET#1\endcsname\relax - \expandafter\ifsetfail - \else - \expandafter\ifsetsucceed - \fi -} -\def\ifsetsucceed{\conditionalsucceed{ifset}} -\def\ifsetfail{\nestedignore{ifset}} -\defineunmatchedend{ifset} - -% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been -% defined with @set, or has been undefined with @clear. -% -\def\ifclear{\parsearg\ifclearxxx} -\def\ifclearxxx #1{% - \expandafter\ifx\csname SET#1\endcsname\relax - \expandafter\ifclearsucceed - \else - \expandafter\ifclearfail - \fi -} -\def\ifclearsucceed{\conditionalsucceed{ifclear}} -\def\ifclearfail{\nestedignore{ifclear}} -\defineunmatchedend{ifclear} - -% @iftex, @ifnothtml, @ifnotinfo always succeed; we read the text -% following, through the first @end iftex (etc.). Make `@end iftex' -% (etc.) valid only after an @iftex. -% -\def\iftex{\conditionalsucceed{iftex}} -\def\ifnothtml{\conditionalsucceed{ifnothtml}} -\def\ifnotinfo{\conditionalsucceed{ifnotinfo}} -\defineunmatchedend{iftex} -\defineunmatchedend{ifnothtml} -\defineunmatchedend{ifnotinfo} - -% We can't just want to start a group at @iftex (for example) and end it -% at @end iftex, since then @set commands inside the conditional have no -% effect (they'd get reverted at the end of the group). So we must -% define \Eiftex to redefine itself to be its previous value. (We can't -% just define it to fail again with an ``unmatched end'' error, since -% the @ifset might be nested.) -% -\def\conditionalsucceed#1{% - \edef\temp{% - % Remember the current value of \E#1. - \let\nece{prevE#1} = \nece{E#1}% - % - % At the `@end #1', redefine \E#1 to be its previous value. - \def\nece{E#1}{\let\nece{E#1} = \nece{prevE#1}}% - }% - \temp -} - -% We need to expand lots of \csname's, but we don't want to expand the -% control sequences after we've constructed them. -% -\def\nece#1{\expandafter\noexpand\csname#1\endcsname} - -% @asis just yields its argument. Used with @table, for example. -% -\def\asis#1{#1} - -% @math means output in math mode. -% We don't use $'s directly in the definition of \math because control -% sequences like \math are expanded when the toc file is written. Then, -% we read the toc file back, the $'s will be normal characters (as they -% should be, according to the definition of Texinfo). So we must use a -% control sequence to switch into and out of math mode. -% -% This isn't quite enough for @math to work properly in indices, but it -% seems unlikely it will ever be needed there. -% -\let\implicitmath = $ -\def\math#1{\implicitmath #1\implicitmath} - -% @bullet and @minus need the same treatment as @math, just above. -\def\bullet{\implicitmath\ptexbullet\implicitmath} -\def\minus{\implicitmath-\implicitmath} - -% @refill is a no-op. -\let\refill=\relax - -% If working on a large document in chapters, it is convenient to -% be able to disable indexing, cross-referencing, and contents, for test runs. -% This is done with @novalidate (before @setfilename). -% -\newif\iflinks \linkstrue % by default we want the aux files. -\let\novalidate = \linksfalse - -% @setfilename is done at the beginning of every texinfo file. -% So open here the files we need to have open while reading the input. -% This makes it possible to make a .fmt file for texinfo. -\def\setfilename{% - \iflinks - \readauxfile - \fi % \openindices needs to do some work in any case. - \openindices - \fixbackslash % Turn off hack to swallow `\input texinfo'. - \global\let\setfilename=\comment % Ignore extra @setfilename cmds. - % - % If texinfo.cnf is present on the system, read it. - % Useful for site-wide @afourpaper, etc. - % Just to be on the safe side, close the input stream before the \input. - \openin 1 texinfo.cnf - \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi - \closein1 - \temp - % - \comment % Ignore the actual filename. -} - -% Called from \setfilename. -% -\def\openindices{% - \newindex{cp}% - \newcodeindex{fn}% - \newcodeindex{vr}% - \newcodeindex{tp}% - \newcodeindex{ky}% - \newcodeindex{pg}% -} - -% @bye. -\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend} - - -\message{fonts,} -% Font-change commands. - -% Texinfo sort of supports the sans serif font style, which plain TeX does not. -% So we set up a \sf analogous to plain's \rm, etc. -\newfam\sffam -\def\sf{\fam=\sffam \tensf} -\let\li = \sf % Sometimes we call it \li, not \sf. - -% We don't need math for this one. -\def\ttsl{\tenttsl} - -% Use Computer Modern fonts at \magstephalf (11pt). -\newcount\mainmagstep -\mainmagstep=\magstephalf - -% Set the font macro #1 to the font named #2, adding on the -% specified font prefix (normally `cm'). -% #3 is the font's design size, #4 is a scale factor -\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4} - -% Use cm as the default font prefix. -% To specify the font prefix, you must define \fontprefix -% before you read in texinfo.tex. -\ifx\fontprefix\undefined -\def\fontprefix{cm} -\fi -% Support font families that don't use the same naming scheme as CM. -\def\rmshape{r} -\def\rmbshape{bx} %where the normal face is bold -\def\bfshape{b} -\def\bxshape{bx} -\def\ttshape{tt} -\def\ttbshape{tt} -\def\ttslshape{sltt} -\def\itshape{ti} -\def\itbshape{bxti} -\def\slshape{sl} -\def\slbshape{bxsl} -\def\sfshape{ss} -\def\sfbshape{ss} -\def\scshape{csc} -\def\scbshape{csc} - -\ifx\bigger\relax -\let\mainmagstep=\magstep1 -\setfont\textrm\rmshape{12}{1000} -\setfont\texttt\ttshape{12}{1000} -\else -\setfont\textrm\rmshape{10}{\mainmagstep} -\setfont\texttt\ttshape{10}{\mainmagstep} -\fi -% Instead of cmb10, you many want to use cmbx10. -% cmbx10 is a prettier font on its own, but cmb10 -% looks better when embedded in a line with cmr10. -\setfont\textbf\bfshape{10}{\mainmagstep} -\setfont\textit\itshape{10}{\mainmagstep} -\setfont\textsl\slshape{10}{\mainmagstep} -\setfont\textsf\sfshape{10}{\mainmagstep} -\setfont\textsc\scshape{10}{\mainmagstep} -\setfont\textttsl\ttslshape{10}{\mainmagstep} -\font\texti=cmmi10 scaled \mainmagstep -\font\textsy=cmsy10 scaled \mainmagstep - -% A few fonts for @defun, etc. -\setfont\defbf\bxshape{10}{\magstep1} %was 1314 -\setfont\deftt\ttshape{10}{\magstep1} -\def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf} - -% Fonts for indices and small examples (9pt). -% We actually use the slanted font rather than the italic, -% because texinfo normally uses the slanted fonts for that. -% Do not make many font distinctions in general in the index, since they -% aren't very useful. -\setfont\ninett\ttshape{9}{1000} -\setfont\ninettsl\ttslshape{10}{900} -\setfont\indrm\rmshape{9}{1000} -\setfont\indit\itshape{9}{1000} -\setfont\indsl\slshape{9}{1000} -\let\indtt=\ninett -\let\indttsl=\ninettsl -\let\indsf=\indrm -\let\indbf=\indrm -\setfont\indsc\scshape{10}{900} -\font\indi=cmmi9 -\font\indsy=cmsy9 - -% Fonts for title page: -\setfont\titlerm\rmbshape{12}{\magstep3} -\setfont\titleit\itbshape{10}{\magstep4} -\setfont\titlesl\slbshape{10}{\magstep4} -\setfont\titlett\ttbshape{12}{\magstep3} -\setfont\titlettsl\ttslshape{10}{\magstep4} -\setfont\titlesf\sfbshape{17}{\magstep1} -\let\titlebf=\titlerm -\setfont\titlesc\scbshape{10}{\magstep4} -\font\titlei=cmmi12 scaled \magstep3 -\font\titlesy=cmsy10 scaled \magstep4 -\def\authorrm{\secrm} - -% Chapter (and unnumbered) fonts (17.28pt). -\setfont\chaprm\rmbshape{12}{\magstep2} -\setfont\chapit\itbshape{10}{\magstep3} -\setfont\chapsl\slbshape{10}{\magstep3} -\setfont\chaptt\ttbshape{12}{\magstep2} -\setfont\chapttsl\ttslshape{10}{\magstep3} -\setfont\chapsf\sfbshape{17}{1000} -\let\chapbf=\chaprm -\setfont\chapsc\scbshape{10}{\magstep3} -\font\chapi=cmmi12 scaled \magstep2 -\font\chapsy=cmsy10 scaled \magstep3 - -% Section fonts (14.4pt). -\setfont\secrm\rmbshape{12}{\magstep1} -\setfont\secit\itbshape{10}{\magstep2} -\setfont\secsl\slbshape{10}{\magstep2} -\setfont\sectt\ttbshape{12}{\magstep1} -\setfont\secttsl\ttslshape{10}{\magstep2} -\setfont\secsf\sfbshape{12}{\magstep1} -\let\secbf\secrm -\setfont\secsc\scbshape{10}{\magstep2} -\font\seci=cmmi12 scaled \magstep1 -\font\secsy=cmsy10 scaled \magstep2 - -% \setfont\ssecrm\bxshape{10}{\magstep1} % This size an font looked bad. -% \setfont\ssecit\itshape{10}{\magstep1} % The letters were too crowded. -% \setfont\ssecsl\slshape{10}{\magstep1} -% \setfont\ssectt\ttshape{10}{\magstep1} -% \setfont\ssecsf\sfshape{10}{\magstep1} - -%\setfont\ssecrm\bfshape{10}{1315} % Note the use of cmb rather than cmbx. -%\setfont\ssecit\itshape{10}{1315} % Also, the size is a little larger than -%\setfont\ssecsl\slshape{10}{1315} % being scaled magstep1. -%\setfont\ssectt\ttshape{10}{1315} -%\setfont\ssecsf\sfshape{10}{1315} - -%\let\ssecbf=\ssecrm - -% Subsection fonts (13.15pt). -\setfont\ssecrm\rmbshape{12}{\magstephalf} -\setfont\ssecit\itbshape{10}{1315} -\setfont\ssecsl\slbshape{10}{1315} -\setfont\ssectt\ttbshape{12}{\magstephalf} -\setfont\ssecttsl\ttslshape{10}{1315} -\setfont\ssecsf\sfbshape{12}{\magstephalf} -\let\ssecbf\ssecrm -\setfont\ssecsc\scbshape{10}{\magstep1} -\font\sseci=cmmi12 scaled \magstephalf -\font\ssecsy=cmsy10 scaled 1315 -% The smallcaps and symbol fonts should actually be scaled \magstep1.5, -% but that is not a standard magnification. - -% In order for the font changes to affect most math symbols and letters, -% we have to define the \textfont of the standard families. Since -% texinfo doesn't allow for producing subscripts and superscripts, we -% don't bother to reset \scriptfont and \scriptscriptfont (which would -% also require loading a lot more fonts). -% -\def\resetmathfonts{% - \textfont0 = \tenrm \textfont1 = \teni \textfont2 = \tensy - \textfont\itfam = \tenit \textfont\slfam = \tensl \textfont\bffam = \tenbf - \textfont\ttfam = \tentt \textfont\sffam = \tensf -} - - -% The font-changing commands redefine the meanings of \tenSTYLE, instead -% of just \STYLE. We do this so that font changes will continue to work -% in math mode, where it is the current \fam that is relevant in most -% cases, not the current font. Plain TeX does \def\bf{\fam=\bffam -% \tenbf}, for example. By redefining \tenbf, we obviate the need to -% redefine \bf itself. -\def\textfonts{% - \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl - \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc - \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl - \resetmathfonts} -\def\titlefonts{% - \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl - \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc - \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy - \let\tenttsl=\titlettsl - \resetmathfonts \setleading{25pt}} -\def\titlefont#1{{\titlefonts\rm #1}} -\def\chapfonts{% - \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl - \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc - \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl - \resetmathfonts \setleading{19pt}} -\def\secfonts{% - \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl - \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc - \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl - \resetmathfonts \setleading{16pt}} -\def\subsecfonts{% - \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl - \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc - \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl - \resetmathfonts \setleading{15pt}} -\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf? -\def\indexfonts{% - \let\tenrm=\indrm \let\tenit=\indit \let\tensl=\indsl - \let\tenbf=\indbf \let\tentt=\indtt \let\smallcaps=\indsc - \let\tensf=\indsf \let\teni=\indi \let\tensy=\indsy \let\tenttsl=\indttsl - \resetmathfonts \setleading{12pt}} - -% Set up the default fonts, so we can use them for creating boxes. -% -\textfonts - -% Define these so they can be easily changed for other fonts. -\def\angleleft{$\langle$} -\def\angleright{$\rangle$} - -% Count depth in font-changes, for error checks -\newcount\fontdepth \fontdepth=0 - -% Fonts for short table of contents. -\setfont\shortcontrm\rmshape{12}{1000} -\setfont\shortcontbf\bxshape{12}{1000} -\setfont\shortcontsl\slshape{12}{1000} - -%% Add scribe-like font environments, plus @l for inline lisp (usually sans -%% serif) and @ii for TeX italic - -% \smartitalic{ARG} outputs arg in italics, followed by an italic correction -% unless the following character is such as not to need one. -\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else\/\fi\fi\fi} -\def\smartslanted#1{{\sl #1}\futurelet\next\smartitalicx} -\def\smartitalic#1{{\it #1}\futurelet\next\smartitalicx} - -\let\i=\smartitalic -\let\var=\smartslanted -\let\dfn=\smartslanted -\let\emph=\smartitalic -\let\cite=\smartslanted - -\def\b#1{{\bf #1}} -\let\strong=\b - -% We can't just use \exhyphenpenalty, because that only has effect at -% the end of a paragraph. Restore normal hyphenation at the end of the -% group within which \nohyphenation is presumably called. -% -\def\nohyphenation{\hyphenchar\font = -1 \aftergroup\restorehyphenation} -\def\restorehyphenation{\hyphenchar\font = `- } - -\def\t#1{% - {\tt \rawbackslash \frenchspacing #1}% - \null -} -\let\ttfont=\t -\def\samp#1{`\tclose{#1}'\null} -\setfont\smallrm\rmshape{8}{1000} -\font\smallsy=cmsy9 -\def\key#1{{\smallrm\textfont2=\smallsy \leavevmode\hbox{% - \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{% - \vbox{\hrule\kern-0.4pt - \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}% - \kern-0.4pt\hrule}% - \kern-.06em\raise0.4pt\hbox{\angleright}}}} -% The old definition, with no lozenge: -%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null} -\def\ctrl #1{{\tt \rawbackslash \hat}#1} - -% @file, @option are the same as @samp. -\let\file=\samp -\let\option=\samp - -% @code is a modification of @t, -% which makes spaces the same size as normal in the surrounding text. -\def\tclose#1{% - {% - % Change normal interword space to be same as for the current font. - \spaceskip = \fontdimen2\font - % - % Switch to typewriter. - \tt - % - % But `\ ' produces the large typewriter interword space. - \def\ {{\spaceskip = 0pt{} }}% - % - % Turn off hyphenation. - \nohyphenation - % - \rawbackslash - \frenchspacing - #1% - }% - \null -} - -% We *must* turn on hyphenation at `-' and `_' in \code. -% Otherwise, it is too hard to avoid overfull hboxes -% in the Emacs manual, the Library manual, etc. - -% Unfortunately, TeX uses one parameter (\hyphenchar) to control -% both hyphenation at - and hyphenation within words. -% We must therefore turn them both off (\tclose does that) -% and arrange explicitly to hyphenate at a dash. -% -- rms. -{ - \catcode`\-=\active - \catcode`\_=\active - % - \global\def\code{\begingroup - \catcode`\-=\active \let-\codedash - \catcode`\_=\active \let_\codeunder - \codex - } - % - % If we end up with any active - characters when handling the index, - % just treat them as a normal -. - \global\def\indexbreaks{\catcode`\-=\active \let-\realdash} -} - -\def\realdash{-} -\def\codedash{-\discretionary{}{}{}} -\def\codeunder{\ifusingtt{\normalunderscore\discretionary{}{}{}}{\_}} -\def\codex #1{\tclose{#1}\endgroup} - -%\let\exp=\tclose %Was temporary - -% @kbd is like @code, except that if the argument is just one @key command, -% then @kbd has no effect. - -% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always), -% `example' (@kbd uses ttsl only inside of @example and friends), -% or `code' (@kbd uses normal tty font always). -\def\kbdinputstyle{\parsearg\kbdinputstylexxx} -\def\kbdinputstylexxx#1{% - \def\arg{#1}% - \ifx\arg\worddistinct - \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}% - \else\ifx\arg\wordexample - \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}% - \else\ifx\arg\wordcode - \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}% - \fi\fi\fi -} -\def\worddistinct{distinct} -\def\wordexample{example} -\def\wordcode{code} - -% Default is kbdinputdistinct. (Too much of a hassle to call the macro, -% the catcodes are wrong for parsearg to work.) -\gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl} - -\def\xkey{\key} -\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}% -\ifx\one\xkey\ifx\threex\three \key{#2}% -\else{\tclose{\kbdfont\look}}\fi -\else{\tclose{\kbdfont\look}}\fi} - -% For @url, @env, @command quotes seem unnecessary, so use \code. -\let\url=\code -\let\env=\code -\let\command=\code - -% @uref (abbreviation for `urlref') takes an optional second argument -% specifying the text to display. First (mandatory) arg is the url. -% Perhaps eventually put in a hypertex \special here. -% -\def\uref#1{\urefxxx #1,,\finish} -\def\urefxxx#1,#2,#3\finish{% - \setbox0 = \hbox{\ignorespaces #2}% - \ifdim\wd0 > 0pt - \unhbox0\ (\code{#1})% - \else - \code{#1}% - \fi -} - -% rms does not like the angle brackets --karl, 17may97. -% So now @email is just like @uref. -%\def\email#1{\angleleft{\tt #1}\angleright} -\let\email=\uref - -% Check if we are currently using a typewriter font. Since all the -% Computer Modern typewriter fonts have zero interword stretch (and -% shrink), and it is reasonable to expect all typewriter fonts to have -% this property, we can check that font parameter. -% -\def\ifmonospace{\ifdim\fontdimen3\font=0pt } - -% Typeset a dimension, e.g., `in' or `pt'. The only reason for the -% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt. -% -\def\dmn#1{\thinspace #1} - -\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par} - -% @l was never documented to mean ``switch to the Lisp font'', -% and it is not used as such in any manual I can find. We need it for -% Polish suppressed-l. --karl, 22sep96. -%\def\l#1{{\li #1}\null} - -% Explicit font changes: @r, @sc, undocumented @ii. -\def\r#1{{\rm #1}} % roman font -\def\sc#1{{\smallcaps#1}} % smallcaps font -\def\ii#1{{\it #1}} % italic font - -% @acronym downcases the argument and prints in smallcaps. -\def\acronym#1{{\smallcaps \lowercase{#1}}} - -% @pounds{} is a sterling sign. -\def\pounds{{\it\$}} - - -\message{page headings,} - -\newskip\titlepagetopglue \titlepagetopglue = 1.5in -\newskip\titlepagebottomglue \titlepagebottomglue = 2pc - -% First the title page. Must do @settitle before @titlepage. -\newif\ifseenauthor -\newif\iffinishedtitlepage - -% Do an implicit @contents or @shortcontents after @end titlepage if the -% user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage. -% -\newif\ifsetcontentsaftertitlepage - \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue -\newif\ifsetshortcontentsaftertitlepage - \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue - -\def\shorttitlepage{\parsearg\shorttitlepagezzz} -\def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}% - \endgroup\page\hbox{}\page} - -\def\titlepage{\begingroup \parindent=0pt \textfonts - \let\subtitlerm=\tenrm - \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}% - % - \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines}% - % - % Leave some space at the very top of the page. - \vglue\titlepagetopglue - % - % Now you can print the title using @title. - \def\title{\parsearg\titlezzz}% - \def\titlezzz##1{\leftline{\titlefonts\rm ##1} - % print a rule at the page bottom also. - \finishedtitlepagefalse - \vskip4pt \hrule height 4pt width \hsize \vskip4pt}% - % No rule at page bottom unless we print one at the top with @title. - \finishedtitlepagetrue - % - % Now you can put text using @subtitle. - \def\subtitle{\parsearg\subtitlezzz}% - \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}% - % - % @author should come last, but may come many times. - \def\author{\parsearg\authorzzz}% - \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi - {\authorfont \leftline{##1}}}% - % - % Most title ``pages'' are actually two pages long, with space - % at the top of the second. We don't want the ragged left on the second. - \let\oldpage = \page - \def\page{% - \iffinishedtitlepage\else - \finishtitlepage - \fi - \oldpage - \let\page = \oldpage - \hbox{}}% -% \def\page{\oldpage \hbox{}} -} - -\def\Etitlepage{% - \iffinishedtitlepage\else - \finishtitlepage - \fi - % It is important to do the page break before ending the group, - % because the headline and footline are only empty inside the group. - % If we use the new definition of \page, we always get a blank page - % after the title page, which we certainly don't want. - \oldpage - \endgroup - % - % If they want short, they certainly want long too. - \ifsetshortcontentsaftertitlepage - \shortcontents - \contents - \global\let\shortcontents = \relax - \global\let\contents = \relax - \fi - % - \ifsetcontentsaftertitlepage - \contents - \global\let\contents = \relax - \global\let\shortcontents = \relax - \fi - % - \HEADINGSon -} - -\def\finishtitlepage{% - \vskip4pt \hrule height 2pt width \hsize - \vskip\titlepagebottomglue - \finishedtitlepagetrue -} - -%%% Set up page headings and footings. - -\let\thispage=\folio - -\newtoks\evenheadline % headline on even pages -\newtoks\oddheadline % headline on odd pages -\newtoks\evenfootline % footline on even pages -\newtoks\oddfootline % footline on odd pages - -% Now make Tex use those variables -\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline - \else \the\evenheadline \fi}} -\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline - \else \the\evenfootline \fi}\HEADINGShook} -\let\HEADINGShook=\relax - -% Commands to set those variables. -% For example, this is what @headings on does -% @evenheading @thistitle|@thispage|@thischapter -% @oddheading @thischapter|@thispage|@thistitle -% @evenfooting @thisfile|| -% @oddfooting ||@thisfile - -\def\evenheading{\parsearg\evenheadingxxx} -\def\oddheading{\parsearg\oddheadingxxx} -\def\everyheading{\parsearg\everyheadingxxx} - -\def\evenfooting{\parsearg\evenfootingxxx} -\def\oddfooting{\parsearg\oddfootingxxx} -\def\everyfooting{\parsearg\everyfootingxxx} - -{\catcode`\@=0 % - -\gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish} -\gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{% -\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}} - -\gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish} -\gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{% -\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}} - -\gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}% - -\gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish} -\gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{% -\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}} - -\gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish} -\gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{% - \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}% - % - % Leave some space for the footline. Hopefully ok to assume - % @evenfooting will not be used by itself. - \global\advance\pageheight by -\baselineskip - \global\advance\vsize by -\baselineskip -} - -\gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}} -% -}% unbind the catcode of @. - -% @headings double turns headings on for double-sided printing. -% @headings single turns headings on for single-sided printing. -% @headings off turns them off. -% @headings on same as @headings double, retained for compatibility. -% @headings after turns on double-sided headings after this page. -% @headings doubleafter turns on double-sided headings after this page. -% @headings singleafter turns on single-sided headings after this page. -% By default, they are off at the start of a document, -% and turned `on' after @end titlepage. - -\def\headings #1 {\csname HEADINGS#1\endcsname} - -\def\HEADINGSoff{ -\global\evenheadline={\hfil} \global\evenfootline={\hfil} -\global\oddheadline={\hfil} \global\oddfootline={\hfil}} -\HEADINGSoff -% When we turn headings on, set the page number to 1. -% For double-sided printing, put current file name in lower left corner, -% chapter name on inside top of right hand pages, document -% title on inside top of left hand pages, and page numbers on outside top -% edge of all pages. -\def\HEADINGSdouble{ -\global\pageno=1 -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\folio\hfil\thistitle}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chapoddpage -} -\let\contentsalignmacro = \chappager - -% For single-sided printing, chapter title goes across top left of page, -% page number on top right. -\def\HEADINGSsingle{ -\global\pageno=1 -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\thischapter\hfil\folio}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chappager -} -\def\HEADINGSon{\HEADINGSdouble} - -\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex} -\let\HEADINGSdoubleafter=\HEADINGSafter -\def\HEADINGSdoublex{% -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\folio\hfil\thistitle}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chapoddpage -} - -\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex} -\def\HEADINGSsinglex{% -\global\evenfootline={\hfil} -\global\oddfootline={\hfil} -\global\evenheadline={\line{\thischapter\hfil\folio}} -\global\oddheadline={\line{\thischapter\hfil\folio}} -\global\let\contentsalignmacro = \chappager -} - -% Subroutines used in generating headings -% Produces Day Month Year style of output. -\def\today{\number\day\space -\ifcase\month\or -January\or February\or March\or April\or May\or June\or -July\or August\or September\or October\or November\or December\fi -\space\number\year} - -% Use this if you want the Month Day, Year style of output. -%\def\today{\ifcase\month\or -%January\or February\or March\or April\or May\or June\or -%July\or August\or September\or October\or November\or December\fi -%\space\number\day, \number\year} - -% @settitle line... specifies the title of the document, for headings -% It generates no output of its own - -\def\thistitle{No Title} -\def\settitle{\parsearg\settitlezzz} -\def\settitlezzz #1{\gdef\thistitle{#1}} - - -\message{tables,} -% Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x). - -% default indentation of table text -\newdimen\tableindent \tableindent=.8in -% default indentation of @itemize and @enumerate text -\newdimen\itemindent \itemindent=.3in -% margin between end of table item and start of table text. -\newdimen\itemmargin \itemmargin=.1in - -% used internally for \itemindent minus \itemmargin -\newdimen\itemmax - -% Note @table, @vtable, and @vtable define @item, @itemx, etc., with -% these defs. -% They also define \itemindex -% to index the item name in whatever manner is desired (perhaps none). - -\newif\ifitemxneedsnegativevskip - -\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi} - -\def\internalBitem{\smallbreak \parsearg\itemzzz} -\def\internalBitemx{\itemxpar \parsearg\itemzzz} - -\def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz} -\def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz} - -\def\internalBkitem{\smallbreak \parsearg\kitemzzz} -\def\internalBkitemx{\itemxpar \parsearg\kitemzzz} - -\def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}% - \itemzzz {#1}} - -\def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}% - \itemzzz {#1}} - -\def\itemzzz #1{\begingroup % - \advance\hsize by -\rightskip - \advance\hsize by -\tableindent - \setbox0=\hbox{\itemfont{#1}}% - \itemindex{#1}% - \nobreak % This prevents a break before @itemx. - % - % If the item text does not fit in the space we have, put it on a line - % by itself, and do not allow a page break either before or after that - % line. We do not start a paragraph here because then if the next - % command is, e.g., @kindex, the whatsit would get put into the - % horizontal list on a line by itself, resulting in extra blank space. - \ifdim \wd0>\itemmax - % - % Make this a paragraph so we get the \parskip glue and wrapping, - % but leave it ragged-right. - \begingroup - \advance\leftskip by-\tableindent - \advance\hsize by\tableindent - \advance\rightskip by0pt plus1fil - \leavevmode\unhbox0\par - \endgroup - % - % We're going to be starting a paragraph, but we don't want the - % \parskip glue -- logically it's part of the @item we just started. - \nobreak \vskip-\parskip - % - % Stop a page break at the \parskip glue coming up. Unfortunately - % we can't prevent a possible page break at the following - % \baselineskip glue. - \nobreak - \endgroup - \itemxneedsnegativevskipfalse - \else - % The item text fits into the space. Start a paragraph, so that the - % following text (if any) will end up on the same line. - \noindent - % Do this with kerns and \unhbox so that if there is a footnote in - % the item text, it can migrate to the main vertical list and - % eventually be printed. - \nobreak\kern-\tableindent - \dimen0 = \itemmax \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0 - \unhbox0 - \nobreak\kern\dimen0 - \endgroup - \itemxneedsnegativevskiptrue - \fi -} - -\def\item{\errmessage{@item while not in a table}} -\def\itemx{\errmessage{@itemx while not in a table}} -\def\kitem{\errmessage{@kitem while not in a table}} -\def\kitemx{\errmessage{@kitemx while not in a table}} -\def\xitem{\errmessage{@xitem while not in a table}} -\def\xitemx{\errmessage{@xitemx while not in a table}} - -% Contains a kludge to get @end[description] to work. -\def\description{\tablez{\dontindex}{1}{}{}{}{}} - -% @table, @ftable, @vtable. -\def\table{\begingroup\inENV\obeylines\obeyspaces\tablex} -{\obeylines\obeyspaces% -\gdef\tablex #1^^M{% -\tabley\dontindex#1 \endtabley}} - -\def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex} -{\obeylines\obeyspaces% -\gdef\ftablex #1^^M{% -\tabley\fnitemindex#1 \endtabley -\def\Eftable{\endgraf\afterenvbreak\endgroup}% -\let\Etable=\relax}} - -\def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex} -{\obeylines\obeyspaces% -\gdef\vtablex #1^^M{% -\tabley\vritemindex#1 \endtabley -\def\Evtable{\endgraf\afterenvbreak\endgroup}% -\let\Etable=\relax}} - -\def\dontindex #1{} -\def\fnitemindex #1{\doind {fn}{\code{#1}}}% -\def\vritemindex #1{\doind {vr}{\code{#1}}}% - -{\obeyspaces % -\gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup% -\tablez{#1}{#2}{#3}{#4}{#5}{#6}}} - -\def\tablez #1#2#3#4#5#6{% -\aboveenvbreak % -\begingroup % -\def\Edescription{\Etable}% Necessary kludge. -\let\itemindex=#1% -\ifnum 0#3>0 \advance \leftskip by #3\mil \fi % -\ifnum 0#4>0 \tableindent=#4\mil \fi % -\ifnum 0#5>0 \advance \rightskip by #5\mil \fi % -\def\itemfont{#2}% -\itemmax=\tableindent % -\advance \itemmax by -\itemmargin % -\advance \leftskip by \tableindent % -\exdentamount=\tableindent -\parindent = 0pt -\parskip = \smallskipamount -\ifdim \parskip=0pt \parskip=2pt \fi% -\def\Etable{\endgraf\afterenvbreak\endgroup}% -\let\item = \internalBitem % -\let\itemx = \internalBitemx % -\let\kitem = \internalBkitem % -\let\kitemx = \internalBkitemx % -\let\xitem = \internalBxitem % -\let\xitemx = \internalBxitemx % -} - -% This is the counter used by @enumerate, which is really @itemize - -\newcount \itemno - -\def\itemize{\parsearg\itemizezzz} - -\def\itemizezzz #1{% - \begingroup % ended by the @end itemize - \itemizey {#1}{\Eitemize} -} - -\def\itemizey #1#2{% -\aboveenvbreak % -\itemmax=\itemindent % -\advance \itemmax by -\itemmargin % -\advance \leftskip by \itemindent % -\exdentamount=\itemindent -\parindent = 0pt % -\parskip = \smallskipamount % -\ifdim \parskip=0pt \parskip=2pt \fi% -\def#2{\endgraf\afterenvbreak\endgroup}% -\def\itemcontents{#1}% -\let\item=\itemizeitem} - -% Set sfcode to normal for the chars that usually have another value. -% These are `.?!:;,' -\def\frenchspacing{\sfcode46=1000 \sfcode63=1000 \sfcode33=1000 - \sfcode58=1000 \sfcode59=1000 \sfcode44=1000 } - -% \splitoff TOKENS\endmark defines \first to be the first token in -% TOKENS, and \rest to be the remainder. -% -\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}% - -% Allow an optional argument of an uppercase letter, lowercase letter, -% or number, to specify the first label in the enumerated list. No -% argument is the same as `1'. -% -\def\enumerate{\parsearg\enumeratezzz} -\def\enumeratezzz #1{\enumeratey #1 \endenumeratey} -\def\enumeratey #1 #2\endenumeratey{% - \begingroup % ended by the @end enumerate - % - % If we were given no argument, pretend we were given `1'. - \def\thearg{#1}% - \ifx\thearg\empty \def\thearg{1}\fi - % - % Detect if the argument is a single token. If so, it might be a - % letter. Otherwise, the only valid thing it can be is a number. - % (We will always have one token, because of the test we just made. - % This is a good thing, since \splitoff doesn't work given nothing at - % all -- the first parameter is undelimited.) - \expandafter\splitoff\thearg\endmark - \ifx\rest\empty - % Only one token in the argument. It could still be anything. - % A ``lowercase letter'' is one whose \lccode is nonzero. - % An ``uppercase letter'' is one whose \lccode is both nonzero, and - % not equal to itself. - % Otherwise, we assume it's a number. - % - % We need the \relax at the end of the \ifnum lines to stop TeX from - % continuing to look for a . - % - \ifnum\lccode\expandafter`\thearg=0\relax - \numericenumerate % a number (we hope) - \else - % It's a letter. - \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax - \lowercaseenumerate % lowercase letter - \else - \uppercaseenumerate % uppercase letter - \fi - \fi - \else - % Multiple tokens in the argument. We hope it's a number. - \numericenumerate - \fi -} - -% An @enumerate whose labels are integers. The starting integer is -% given in \thearg. -% -\def\numericenumerate{% - \itemno = \thearg - \startenumeration{\the\itemno}% -} - -% The starting (lowercase) letter is in \thearg. -\def\lowercaseenumerate{% - \itemno = \expandafter`\thearg - \startenumeration{% - % Be sure we're not beyond the end of the alphabet. - \ifnum\itemno=0 - \errmessage{No more lowercase letters in @enumerate; get a bigger - alphabet}% - \fi - \char\lccode\itemno - }% -} - -% The starting (uppercase) letter is in \thearg. -\def\uppercaseenumerate{% - \itemno = \expandafter`\thearg - \startenumeration{% - % Be sure we're not beyond the end of the alphabet. - \ifnum\itemno=0 - \errmessage{No more uppercase letters in @enumerate; get a bigger - alphabet} - \fi - \char\uccode\itemno - }% -} - -% Call itemizey, adding a period to the first argument and supplying the -% common last two arguments. Also subtract one from the initial value in -% \itemno, since @item increments \itemno. -% -\def\startenumeration#1{% - \advance\itemno by -1 - \itemizey{#1.}\Eenumerate\flushcr -} - -% @alphaenumerate and @capsenumerate are abbreviations for giving an arg -% to @enumerate. -% -\def\alphaenumerate{\enumerate{a}} -\def\capsenumerate{\enumerate{A}} -\def\Ealphaenumerate{\Eenumerate} -\def\Ecapsenumerate{\Eenumerate} - -% Definition of @item while inside @itemize. - -\def\itemizeitem{% -\advance\itemno by 1 -{\let\par=\endgraf \smallbreak}% -\ifhmode \errmessage{In hmode at itemizeitem}\fi -{\parskip=0in \hskip 0pt -\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}% -\vadjust{\penalty 1200}}% -\flushcr} - -% @multitable macros -% Amy Hendrickson, 8/18/94, 3/6/96 -% -% @multitable ... @end multitable will make as many columns as desired. -% Contents of each column will wrap at width given in preamble. Width -% can be specified either with sample text given in a template line, -% or in percent of \hsize, the current width of text on page. - -% Table can continue over pages but will only break between lines. - -% To make preamble: -% -% Either define widths of columns in terms of percent of \hsize: -% @multitable @columnfractions .25 .3 .45 -% @item ... -% -% Numbers following @columnfractions are the percent of the total -% current hsize to be used for each column. You may use as many -% columns as desired. - - -% Or use a template: -% @multitable {Column 1 template} {Column 2 template} {Column 3 template} -% @item ... -% using the widest term desired in each column. -% -% For those who want to use more than one line's worth of words in -% the preamble, break the line within one argument and it -% will parse correctly, i.e., -% -% @multitable {Column 1 template} {Column 2 template} {Column 3 -% template} -% Not: -% @multitable {Column 1 template} {Column 2 template} -% {Column 3 template} - -% Each new table line starts with @item, each subsequent new column -% starts with @tab. Empty columns may be produced by supplying @tab's -% with nothing between them for as many times as empty columns are needed, -% ie, @tab@tab@tab will produce two empty columns. - -% @item, @tab, @multitable or @end multitable do not need to be on their -% own lines, but it will not hurt if they are. - -% Sample multitable: - -% @multitable {Column 1 template} {Column 2 template} {Column 3 template} -% @item first col stuff @tab second col stuff @tab third col -% @item -% first col stuff -% @tab -% second col stuff -% @tab -% third col -% @item first col stuff @tab second col stuff -% @tab Many paragraphs of text may be used in any column. -% -% They will wrap at the width determined by the template. -% @item@tab@tab This will be in third column. -% @end multitable - -% Default dimensions may be reset by user. -% @multitableparskip is vertical space between paragraphs in table. -% @multitableparindent is paragraph indent in table. -% @multitablecolmargin is horizontal space to be left between columns. -% @multitablelinespace is space to leave between table items, baseline -% to baseline. -% 0pt means it depends on current normal line spacing. -% -\newskip\multitableparskip -\newskip\multitableparindent -\newdimen\multitablecolspace -\newskip\multitablelinespace -\multitableparskip=0pt -\multitableparindent=6pt -\multitablecolspace=12pt -\multitablelinespace=0pt - -% Macros used to set up halign preamble: -% -\let\endsetuptable\relax -\def\xendsetuptable{\endsetuptable} -\let\columnfractions\relax -\def\xcolumnfractions{\columnfractions} -\newif\ifsetpercent - -% #1 is the part of the @columnfraction before the decimal point, which -% is presumably either 0 or the empty string (but we don't check, we -% just throw it away). #2 is the decimal part, which we use as the -% percent of \hsize for this column. -\def\pickupwholefraction#1.#2 {% - \global\advance\colcount by 1 - \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}% - \setuptable -} - -\newcount\colcount -\def\setuptable#1{% - \def\firstarg{#1}% - \ifx\firstarg\xendsetuptable - \let\go = \relax - \else - \ifx\firstarg\xcolumnfractions - \global\setpercenttrue - \else - \ifsetpercent - \let\go\pickupwholefraction - \else - \global\advance\colcount by 1 - \setbox0=\hbox{#1\unskip }% Add a normal word space as a separator; - % typically that is always in the input, anyway. - \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}% - \fi - \fi - \ifx\go\pickupwholefraction - % Put the argument back for the \pickupwholefraction call, so - % we'll always have a period there to be parsed. - \def\go{\pickupwholefraction#1}% - \else - \let\go = \setuptable - \fi% - \fi - \go -} - -% multitable syntax -\def\tab{&\hskip1sp\relax} % 2/2/96 - % tiny skip here makes sure this column space is - % maintained, even if it is never used. - -% @multitable ... @end multitable definitions: -% -\def\multitable{\parsearg\dotable} -\def\dotable#1{\bgroup - \vskip\parskip - \let\item\crcr - \tolerance=9500 - \hbadness=9500 - \setmultitablespacing - \parskip=\multitableparskip - \parindent=\multitableparindent - \overfullrule=0pt - \global\colcount=0 - \def\Emultitable{\global\setpercentfalse\cr\egroup\egroup}% - % - % To parse everything between @multitable and @item: - \setuptable#1 \endsetuptable - % - % \everycr will reset column counter, \colcount, at the end of - % each line. Every column entry will cause \colcount to advance by one. - % The table preamble - % looks at the current \colcount to find the correct column width. - \everycr{\noalign{% - % - % \filbreak%% keeps underfull box messages off when table breaks over pages. - % Maybe so, but it also creates really weird page breaks when the table - % breaks over pages. Wouldn't \vfil be better? Wait until the problem - % manifests itself, so it can be fixed for real --karl. - \global\colcount=0\relax}}% - % - % This preamble sets up a generic column definition, which will - % be used as many times as user calls for columns. - % \vtop will set a single line and will also let text wrap and - % continue for many paragraphs if desired. - \halign\bgroup&\global\advance\colcount by 1\relax - \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname - % - % In order to keep entries from bumping into each other - % we will add a \leftskip of \multitablecolspace to all columns after - % the first one. - % - % If a template has been used, we will add \multitablecolspace - % to the width of each template entry. - % - % If the user has set preamble in terms of percent of \hsize we will - % use that dimension as the width of the column, and the \leftskip - % will keep entries from bumping into each other. Table will start at - % left margin and final column will justify at right margin. - % - % Make sure we don't inherit \rightskip from the outer environment. - \rightskip=0pt - \ifnum\colcount=1 - % The first column will be indented with the surrounding text. - \advance\hsize by\leftskip - \else - \ifsetpercent \else - % If user has not set preamble in terms of percent of \hsize - % we will advance \hsize by \multitablecolspace. - \advance\hsize by \multitablecolspace - \fi - % In either case we will make \leftskip=\multitablecolspace: - \leftskip=\multitablecolspace - \fi - % Ignoring space at the beginning and end avoids an occasional spurious - % blank line, when TeX decides to break the line at the space before the - % box from the multistrut, so the strut ends up on a line by itself. - % For example: - % @multitable @columnfractions .11 .89 - % @item @code{#} - % @tab Legal holiday which is valid in major parts of the whole country. - % Is automatically provided with highlighting sequences respectively marking - % characters. - \noindent\ignorespaces##\unskip\multistrut}\cr -} - -\def\setmultitablespacing{% test to see if user has set \multitablelinespace. -% If so, do nothing. If not, give it an appropriate dimension based on -% current baselineskip. -\ifdim\multitablelinespace=0pt -%% strut to put in table in case some entry doesn't have descenders, -%% to keep lines equally spaced -\let\multistrut = \strut -%% Test to see if parskip is larger than space between lines of -%% table. If not, do nothing. -%% If so, set to same dimension as multitablelinespace. -\else -\gdef\multistrut{\vrule height\multitablelinespace depth\dp0 -width0pt\relax} \fi -\ifdim\multitableparskip>\multitablelinespace -\global\multitableparskip=\multitablelinespace -\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller - %% than skip between lines in the table. -\fi% -\ifdim\multitableparskip=0pt -\global\multitableparskip=\multitablelinespace -\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller - %% than skip between lines in the table. -\fi} - - -\message{indexing,} -% Index generation facilities - -% Define \newwrite to be identical to plain tex's \newwrite -% except not \outer, so it can be used within \newindex. -{\catcode`\@=11 -\gdef\newwrite{\alloc@7\write\chardef\sixt@@n}} - -% \newindex {foo} defines an index named foo. -% It automatically defines \fooindex such that -% \fooindex ...rest of line... puts an entry in the index foo. -% It also defines \fooindfile to be the number of the output channel for -% the file that accumulates this index. The file's extension is foo. -% The name of an index should be no more than 2 characters long -% for the sake of vms. -% -\def\newindex#1{% - \iflinks - \expandafter\newwrite \csname#1indfile\endcsname - \openout \csname#1indfile\endcsname \jobname.#1 % Open the file - \fi - \expandafter\xdef\csname#1index\endcsname{% % Define @#1index - \noexpand\doindex{#1}} -} - -% @defindex foo == \newindex{foo} - -\def\defindex{\parsearg\newindex} - -% Define @defcodeindex, like @defindex except put all entries in @code. - -\def\newcodeindex#1{% - \iflinks - \expandafter\newwrite \csname#1indfile\endcsname - \openout \csname#1indfile\endcsname \jobname.#1 - \fi - \expandafter\xdef\csname#1index\endcsname{% - \noexpand\docodeindex{#1}} -} - -\def\defcodeindex{\parsearg\newcodeindex} - -% @synindex foo bar makes index foo feed into index bar. -% Do this instead of @defindex foo if you don't want it as a separate index. -% The \closeout helps reduce unnecessary open files; the limit on the -% Acorn RISC OS is a mere 16 files. -\def\synindex#1 #2 {% - \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname - \expandafter\closeout\csname#1indfile\endcsname - \expandafter\let\csname#1indfile\endcsname=\synindexfoo - \expandafter\xdef\csname#1index\endcsname{% define \xxxindex - \noexpand\doindex{#2}}% -} - -% @syncodeindex foo bar similar, but put all entries made for index foo -% inside @code. -\def\syncodeindex#1 #2 {% - \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname - \expandafter\closeout\csname#1indfile\endcsname - \expandafter\let\csname#1indfile\endcsname=\synindexfoo - \expandafter\xdef\csname#1index\endcsname{% define \xxxindex - \noexpand\docodeindex{#2}}% -} - -% Define \doindex, the driver for all \fooindex macros. -% Argument #1 is generated by the calling \fooindex macro, -% and it is "foo", the name of the index. - -% \doindex just uses \parsearg; it calls \doind for the actual work. -% This is because \doind is more useful to call from other macros. - -% There is also \dosubind {index}{topic}{subtopic} -% which makes an entry in a two-level index such as the operation index. - -\def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer} -\def\singleindexer #1{\doind{\indexname}{#1}} - -% like the previous two, but they put @code around the argument. -\def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer} -\def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}} - -\def\indexdummies{% -\def\ { }% -% Take care of the plain tex accent commands. -\def\"{\realbackslash "}% -\def\`{\realbackslash `}% -\def\'{\realbackslash '}% -\def\^{\realbackslash ^}% -\def\~{\realbackslash ~}% -\def\={\realbackslash =}% -\def\b{\realbackslash b}% -\def\c{\realbackslash c}% -\def\d{\realbackslash d}% -\def\u{\realbackslash u}% -\def\v{\realbackslash v}% -\def\H{\realbackslash H}% -% Take care of the plain tex special European modified letters. -\def\oe{\realbackslash oe}% -\def\ae{\realbackslash ae}% -\def\aa{\realbackslash aa}% -\def\OE{\realbackslash OE}% -\def\AE{\realbackslash AE}% -\def\AA{\realbackslash AA}% -\def\o{\realbackslash o}% -\def\O{\realbackslash O}% -\def\l{\realbackslash l}% -\def\L{\realbackslash L}% -\def\ss{\realbackslash ss}% -% Take care of texinfo commands likely to appear in an index entry. -% (Must be a way to avoid doing expansion at all, and thus not have to -% laboriously list every single command here.) -\def\@{@}% will be @@ when we switch to @ as escape char. -% Need these in case \tex is in effect and \{ is a \delimiter again. -% But can't use \lbracecmd and \rbracecmd because texindex assumes -% braces and backslashes are used only as delimiters. -\let\{ = \mylbrace -\let\} = \myrbrace -\def\_{{\realbackslash _}}% -\def\w{\realbackslash w }% -\def\bf{\realbackslash bf }% -%\def\rm{\realbackslash rm }% -\def\sl{\realbackslash sl }% -\def\sf{\realbackslash sf}% -\def\tt{\realbackslash tt}% -\def\gtr{\realbackslash gtr}% -\def\less{\realbackslash less}% -\def\hat{\realbackslash hat}% -\def\TeX{\realbackslash TeX}% -\def\dots{\realbackslash dots }% -\def\result{\realbackslash result}% -\def\equiv{\realbackslash equiv}% -\def\expansion{\realbackslash expansion}% -\def\print{\realbackslash print}% -\def\error{\realbackslash error}% -\def\point{\realbackslash point}% -\def\copyright{\realbackslash copyright}% -\def\tclose##1{\realbackslash tclose {##1}}% -\def\code##1{\realbackslash code {##1}}% -\def\uref##1{\realbackslash uref {##1}}% -\def\url##1{\realbackslash url {##1}}% -\def\env##1{\realbackslash env {##1}}% -\def\command##1{\realbackslash command {##1}}% -\def\option##1{\realbackslash option {##1}}% -\def\dotless##1{\realbackslash dotless {##1}}% -\def\samp##1{\realbackslash samp {##1}}% -\def\,##1{\realbackslash ,{##1}}% -\def\t##1{\realbackslash t {##1}}% -\def\r##1{\realbackslash r {##1}}% -\def\i##1{\realbackslash i {##1}}% -\def\b##1{\realbackslash b {##1}}% -\def\sc##1{\realbackslash sc {##1}}% -\def\cite##1{\realbackslash cite {##1}}% -\def\key##1{\realbackslash key {##1}}% -\def\file##1{\realbackslash file {##1}}% -\def\var##1{\realbackslash var {##1}}% -\def\kbd##1{\realbackslash kbd {##1}}% -\def\dfn##1{\realbackslash dfn {##1}}% -\def\emph##1{\realbackslash emph {##1}}% -\def\acronym##1{\realbackslash acronym {##1}}% -% -% Handle some cases of @value -- where the variable name does not -% contain - or _, and the value does not contain any -% (non-fully-expandable) commands. -\let\value = \expandablevalue -% -\unsepspaces -} - -% If an index command is used in an @example environment, any spaces -% therein should become regular spaces in the raw index file, not the -% expansion of \tie (\\leavevmode \penalty \@M \ ). -{\obeyspaces - \gdef\unsepspaces{\obeyspaces\let =\space}} - -% \indexnofonts no-ops all font-change commands. -% This is used when outputting the strings to sort the index by. -\def\indexdummyfont#1{#1} -\def\indexdummytex{TeX} -\def\indexdummydots{...} - -\def\indexnofonts{% -% Just ignore accents. -\let\,=\indexdummyfont -\let\"=\indexdummyfont -\let\`=\indexdummyfont -\let\'=\indexdummyfont -\let\^=\indexdummyfont -\let\~=\indexdummyfont -\let\==\indexdummyfont -\let\b=\indexdummyfont -\let\c=\indexdummyfont -\let\d=\indexdummyfont -\let\u=\indexdummyfont -\let\v=\indexdummyfont -\let\H=\indexdummyfont -\let\dotless=\indexdummyfont -% Take care of the plain tex special European modified letters. -\def\oe{oe}% -\def\ae{ae}% -\def\aa{aa}% -\def\OE{OE}% -\def\AE{AE}% -\def\AA{AA}% -\def\o{o}% -\def\O{O}% -\def\l{l}% -\def\L{L}% -\def\ss{ss}% -\let\w=\indexdummyfont -\let\t=\indexdummyfont -\let\r=\indexdummyfont -\let\i=\indexdummyfont -\let\b=\indexdummyfont -\let\emph=\indexdummyfont -\let\strong=\indexdummyfont -\let\cite=\indexdummyfont -\let\sc=\indexdummyfont -%Don't no-op \tt, since it isn't a user-level command -% and is used in the definitions of the active chars like <, >, |... -%\let\tt=\indexdummyfont -\let\tclose=\indexdummyfont -\let\code=\indexdummyfont -\let\url=\indexdummyfont -\let\uref=\indexdummyfont -\let\env=\indexdummyfont -\let\command=\indexdummyfont -\let\option=\indexdummyfont -\let\file=\indexdummyfont -\let\samp=\indexdummyfont -\let\kbd=\indexdummyfont -\let\key=\indexdummyfont -\let\var=\indexdummyfont -\let\TeX=\indexdummytex -\let\dots=\indexdummydots -\def\@{@}% -} - -% To define \realbackslash, we must make \ not be an escape. -% We must first make another character (@) an escape -% so we do not become unable to do a definition. - -{\catcode`\@=0 \catcode`\\=\other - @gdef@realbackslash{\}} - -\let\indexbackslash=0 %overridden during \printindex. -\let\SETmarginindex=\relax % put index entries in margin (undocumented)? - -% For \ifx comparisons. -\def\emptymacro{\empty} - -% Most index entries go through here, but \dosubind is the general case. -% -\def\doind#1#2{\dosubind{#1}{#2}\empty} - -% Workhorse for all \fooindexes. -% #1 is name of index, #2 is stuff to put there, #3 is subentry -- -% \empty if called from \doind, as we usually are. The main exception -% is with defuns, which call us directly. -% -\def\dosubind#1#2#3{% - % Put the index entry in the margin if desired. - \ifx\SETmarginindex\relax\else - \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}% - \fi - {% - \count255=\lastpenalty - {% - \indexdummies % Must do this here, since \bf, etc expand at this stage - \escapechar=`\\ - {% - \let\folio = 0% We will expand all macros now EXCEPT \folio. - \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now - % so it will be output as is; and it will print as backslash. - % - \def\thirdarg{#3}% - % - % If third arg is present, precede it with space in sort key. - \ifx\thirdarg\emptymacro - \let\subentry = \empty - \else - \def\subentry{ #3}% - \fi - % - % First process the index-string with all font commands turned off - % to get the string to sort by. - {\indexnofonts \xdef\indexsorttmp{#2\subentry}}% - % - % Now produce the complete index entry, with both the sort key and the - % original text, including any font commands. - \toks0 = {#2}% - \edef\temp{% - \write\csname#1indfile\endcsname{% - \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}% - }% - % - % If third (subentry) arg is present, add it to the index string. - \ifx\thirdarg\emptymacro \else - \toks0 = {#3}% - \edef\temp{\temp{\the\toks0}}% - \fi - % - % If a skip is the last thing on the list now, preserve it - % by backing up by \lastskip, doing the \write, then inserting - % the skip again. Otherwise, the whatsit generated by the - % \write will make \lastskip zero. The result is that sequences - % like this: - % @end defun - % @tindex whatever - % @defun ... - % will have extra space inserted, because the \medbreak in the - % start of the @defun won't see the skip inserted by the @end of - % the previous defun. - % - % But don't do any of this if we're not in vertical mode. We - % don't want to do a \vskip and prematurely end a paragraph. - % - % Avoid page breaks due to these extra skips, too. - % - \iflinks - \ifvmode - \skip0 = \lastskip - \ifdim\lastskip = 0pt \else \nobreak\vskip-\lastskip \fi - \fi - % - \temp % do the write - % - % - \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi - \fi - }% - }% - \penalty\count255 - }% -} - -% The index entry written in the file actually looks like -% \entry {sortstring}{page}{topic} -% or -% \entry {sortstring}{page}{topic}{subtopic} -% The texindex program reads in these files and writes files -% containing these kinds of lines: -% \initial {c} -% before the first topic whose initial is c -% \entry {topic}{pagelist} -% for a topic that is used without subtopics -% \primary {topic} -% for the beginning of a topic that is used with subtopics -% \secondary {subtopic}{pagelist} -% for each subtopic. - -% Define the user-accessible indexing commands -% @findex, @vindex, @kindex, @cindex. - -\def\findex {\fnindex} -\def\kindex {\kyindex} -\def\cindex {\cpindex} -\def\vindex {\vrindex} -\def\tindex {\tpindex} -\def\pindex {\pgindex} - -\def\cindexsub {\begingroup\obeylines\cindexsub} -{\obeylines % -\gdef\cindexsub "#1" #2^^M{\endgroup % -\dosubind{cp}{#2}{#1}}} - -% Define the macros used in formatting output of the sorted index material. - -% @printindex causes a particular index (the ??s file) to get printed. -% It does not print any chapter heading (usually an @unnumbered). -% -\def\printindex{\parsearg\doprintindex} -\def\doprintindex#1{\begingroup - \dobreak \chapheadingskip{10000}% - % - \indexfonts \rm - \tolerance = 9500 - \indexbreaks - % - % See if the index file exists and is nonempty. - % Change catcode of @ here so that if the index file contains - % \initial {@} - % as its first line, TeX doesn't complain about mismatched braces - % (because it thinks @} is a control sequence). - \catcode`\@ = 11 - \openin 1 \jobname.#1s - \ifeof 1 - % \enddoublecolumns gets confused if there is no text in the index, - % and it loses the chapter title and the aux file entries for the - % index. The easiest way to prevent this problem is to make sure - % there is some text. - (Index is nonexistent) - \else - % - % If the index file exists but is empty, then \openin leaves \ifeof - % false. We have to make TeX try to read something from the file, so - % it can discover if there is anything in it. - \read 1 to \temp - \ifeof 1 - (Index is empty) - \else - % Index files are almost Texinfo source, but we use \ as the escape - % character. It would be better to use @, but that's too big a change - % to make right now. - \def\indexbackslash{\rawbackslashxx}% - \catcode`\\ = 0 - \escapechar = `\\ - \begindoublecolumns - \input \jobname.#1s - \enddoublecolumns - \fi - \fi - \closein 1 -\endgroup} - -% These macros are used by the sorted index file itself. -% Change them to control the appearance of the index. - -\def\initial#1{{% - % Some minor font changes for the special characters. - \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt - % - % Remove any glue we may have, we'll be inserting our own. - \removelastskip - % - % We like breaks before the index initials, so insert a bonus. - \penalty -300 - % - % Typeset the initial. Making this add up to a whole number of - % baselineskips increases the chance of the dots lining up from column - % to column. It still won't often be perfect, because of the stretch - % we need before each entry, but it's better. - % - % No shrink because it confuses \balancecolumns. - \vskip 1.67\baselineskip plus .5\baselineskip - \leftline{\secbf #1}% - \vskip .33\baselineskip plus .1\baselineskip - % - % Do our best not to break after the initial. - \nobreak -}} - -% This typesets a paragraph consisting of #1, dot leaders, and then #2 -% flush to the right margin. It is used for index and table of contents -% entries. The paragraph is indented by \leftskip. -% -\def\entry#1#2{\begingroup - % - % Start a new paragraph if necessary, so our assignments below can't - % affect previous text. - \par - % - % Do not fill out the last line with white space. - \parfillskip = 0in - % - % No extra space above this paragraph. - \parskip = 0in - % - % Do not prefer a separate line ending with a hyphen to fewer lines. - \finalhyphendemerits = 0 - % - % \hangindent is only relevant when the entry text and page number - % don't both fit on one line. In that case, bob suggests starting the - % dots pretty far over on the line. Unfortunately, a large - % indentation looks wrong when the entry text itself is broken across - % lines. So we use a small indentation and put up with long leaders. - % - % \hangafter is reset to 1 (which is the value we want) at the start - % of each paragraph, so we need not do anything with that. - \hangindent = 2em - % - % When the entry text needs to be broken, just fill out the first line - % with blank space. - \rightskip = 0pt plus1fil - % - % A bit of stretch before each entry for the benefit of balancing columns. - \vskip 0pt plus1pt - % - % Start a ``paragraph'' for the index entry so the line breaking - % parameters we've set above will have an effect. - \noindent - % - % Insert the text of the index entry. TeX will do line-breaking on it. - #1% - % The following is kludged to not output a line of dots in the index if - % there are no page numbers. The next person who breaks this will be - % cursed by a Unix daemon. - \def\tempa{{\rm }}% - \def\tempb{#2}% - \edef\tempc{\tempa}% - \edef\tempd{\tempb}% - \ifx\tempc\tempd\ \else% - % - % If we must, put the page number on a line of its own, and fill out - % this line with blank space. (The \hfil is overwhelmed with the - % fill leaders glue in \indexdotfill if the page number does fit.) - \hfil\penalty50 - \null\nobreak\indexdotfill % Have leaders before the page number. - % - % The `\ ' here is removed by the implicit \unskip that TeX does as - % part of (the primitive) \par. Without it, a spurious underfull - % \hbox ensues. - \ #2% The page number ends the paragraph. - \fi% - \par -\endgroup} - -% Like \dotfill except takes at least 1 em. -\def\indexdotfill{\cleaders - \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill} - -\def\primary #1{\line{#1\hfil}} - -\newskip\secondaryindent \secondaryindent=0.5cm - -\def\secondary #1#2{ -{\parfillskip=0in \parskip=0in -\hangindent =1in \hangafter=1 -\noindent\hskip\secondaryindent\hbox{#1}\indexdotfill #2\par -}} - -% Define two-column mode, which we use to typeset indexes. -% Adapted from the TeXbook, page 416, which is to say, -% the manmac.tex format used to print the TeXbook itself. -\catcode`\@=11 - -\newbox\partialpage -\newdimen\doublecolumnhsize - -\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns - % Grab any single-column material above us. - \output = {\global\setbox\partialpage = \vbox{% - % - % Here is a possibility not foreseen in manmac: if we accumulate a - % whole lot of material, we might end up calling this \output - % routine twice in a row (see the doublecol-lose test, which is - % essentially a couple of indexes with @setchapternewpage off). In - % that case, we must prevent the second \partialpage from - % simply overwriting the first, causing us to lose the page. - % This will preserve it until a real output routine can ship it - % out. Generally, \partialpage will be empty when this runs and - % this will be a no-op. - \unvbox\partialpage - % - % Unvbox the main output page. - \unvbox255 - \kern-\topskip \kern\baselineskip - }}% - \eject % run that output routine to set \partialpage - % - % Use the double-column output routine for subsequent pages. - \output = {\doublecolumnout}% - % - % Change the page size parameters. We could do this once outside this - % routine, in each of @smallbook, @afourpaper, and the default 8.5x11 - % format, but then we repeat the same computation. Repeating a couple - % of assignments once per index is clearly meaningless for the - % execution time, so we may as well do it in one place. - % - % First we halve the line length, less a little for the gutter between - % the columns. We compute the gutter based on the line length, so it - % changes automatically with the paper format. The magic constant - % below is chosen so that the gutter has the same value (well, +-<1pt) - % as it did when we hard-coded it. - % - % We put the result in a separate register, \doublecolumhsize, so we - % can restore it in \pagesofar, after \hsize itself has (potentially) - % been clobbered. - % - \doublecolumnhsize = \hsize - \advance\doublecolumnhsize by -.04154\hsize - \divide\doublecolumnhsize by 2 - \hsize = \doublecolumnhsize - % - % Double the \vsize as well. (We don't need a separate register here, - % since nobody clobbers \vsize.) - \advance\vsize by -\ht\partialpage - \vsize = 2\vsize -} - -% The double-column output routine for all double-column pages except -% the last. -% -\def\doublecolumnout{% - \splittopskip=\topskip \splitmaxdepth=\maxdepth - % Get the available space for the double columns -- the normal - % (undoubled) page height minus any material left over from the - % previous page. - \dimen@ = \vsize - \divide\dimen@ by 2 - % - % box0 will be the left-hand column, box2 the right. - \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@ - \onepageout\pagesofar - \unvbox255 - \penalty\outputpenalty -} -\def\pagesofar{% - % Re-output the contents of the output page -- any previous material, - % followed by the two boxes we just split, in box0 and box2. - \advance\vsize by \ht\partialpage - \unvbox\partialpage - % - \hsize = \doublecolumnhsize - \wd0=\hsize \wd2=\hsize - \hbox to\pagewidth{\box0\hfil\box2}% -} -\def\enddoublecolumns{% - \output = {% - % Split the last of the double-column material. Leave it on the - % current page, no automatic page break. - \balancecolumns - % - % If we end up splitting too much material for the current page, - % though, there will be another page break right after this \output - % invocation ends. Having called \balancecolumns once, we do not - % want to call it again. Therefore, reset \output to its normal - % definition right away. (We hope \balancecolumns will never be - % called on to balance too much material, but if it is, this makes - % the output somewhat more palatable.) - \global\output = {\onepageout{\pagecontents\PAGE}}% - }% - \eject - \endgroup % started in \begindoublecolumns - % - % \pagegoal was set to the doubled \vsize above, since we restarted - % the current page. We're now back to normal single-column - % typesetting, so reset \pagegoal to the normal \vsize (after the - % \endgroup where \vsize got restored). - \pagegoal = \vsize -} -\def\balancecolumns{% - % Called at the end of the double column material. - \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120. - \dimen@ = \ht0 - \advance\dimen@ by \topskip - \advance\dimen@ by-\baselineskip - \divide\dimen@ by 2 % target to split to - %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}% - \splittopskip = \topskip - % Loop until we get a decent breakpoint. - {% - \vbadness = 10000 - \loop - \global\setbox3 = \copy0 - \global\setbox1 = \vsplit3 to \dimen@ - \ifdim\ht3>\dimen@ - \global\advance\dimen@ by 1pt - \repeat - }% - %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}% - \setbox0=\vbox to\dimen@{\unvbox1}% - \setbox2=\vbox to\dimen@{\unvbox3}% - % - \pagesofar -} -\catcode`\@ = \other - - -\message{sectioning,} -% Define chapters, sections, etc. - -\newcount\chapno -\newcount\secno \secno=0 -\newcount\subsecno \subsecno=0 -\newcount\subsubsecno \subsubsecno=0 - -% This counter is funny since it counts through charcodes of letters A, B, ... -\newcount\appendixno \appendixno = `\@ -\def\appendixletter{\char\the\appendixno} - -% Each @chapter defines this as the name of the chapter. -% page headings and footings can use it. @section does likewise. -\def\thischapter{} -\def\thissection{} - -\newcount\absseclevel % used to calculate proper heading level -\newcount\secbase\secbase=0 % @raise/lowersections modify this count - -% @raisesections: treat @section as chapter, @subsection as section, etc. -\def\raisesections{\global\advance\secbase by -1} -\let\up=\raisesections % original BFox name - -% @lowersections: treat @chapter as section, @section as subsection, etc. -\def\lowersections{\global\advance\secbase by 1} -\let\down=\lowersections % original BFox name - -% Choose a numbered-heading macro -% #1 is heading level if unmodified by @raisesections or @lowersections -% #2 is text for heading -\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1 -\ifcase\absseclevel - \chapterzzz{#2} -\or - \seczzz{#2} -\or - \numberedsubseczzz{#2} -\or - \numberedsubsubseczzz{#2} -\else - \ifnum \absseclevel<0 - \chapterzzz{#2} - \else - \numberedsubsubseczzz{#2} - \fi -\fi -} - -% like \numhead, but chooses appendix heading levels -\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1 -\ifcase\absseclevel - \appendixzzz{#2} -\or - \appendixsectionzzz{#2} -\or - \appendixsubseczzz{#2} -\or - \appendixsubsubseczzz{#2} -\else - \ifnum \absseclevel<0 - \appendixzzz{#2} - \else - \appendixsubsubseczzz{#2} - \fi -\fi -} - -% like \numhead, but chooses numberless heading levels -\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1 -\ifcase\absseclevel - \unnumberedzzz{#2} -\or - \unnumberedseczzz{#2} -\or - \unnumberedsubseczzz{#2} -\or - \unnumberedsubsubseczzz{#2} -\else - \ifnum \absseclevel<0 - \unnumberedzzz{#2} - \else - \unnumberedsubsubseczzz{#2} - \fi -\fi -} - -% @chapter, @appendix, @unnumbered. -\def\thischaptername{No Chapter Title} -\outer\def\chapter{\parsearg\chapteryyy} -\def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz -\def\chapterzzz #1{% -\secno=0 \subsecno=0 \subsubsecno=0 -\global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}% -\chapmacro {#1}{\the\chapno}% -\gdef\thissection{#1}% -\gdef\thischaptername{#1}% -% We don't substitute the actual chapter name into \thischapter -% because we don't want its macros evaluated now. -\xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}% - {\the\chapno}}}% -\temp -\donoderef -\global\let\section = \numberedsec -\global\let\subsection = \numberedsubsec -\global\let\subsubsection = \numberedsubsubsec -} - -\outer\def\appendix{\parsearg\appendixyyy} -\def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz -\def\appendixzzz #1{% -\secno=0 \subsecno=0 \subsubsecno=0 -\global\advance \appendixno by 1 -\message{\putwordAppendix\space \appendixletter}% -\chapmacro {#1}{\putwordAppendix{} \appendixletter}% -\gdef\thissection{#1}% -\gdef\thischaptername{#1}% -\xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}% - {\putwordAppendix{} \appendixletter}}}% -\temp -\appendixnoderef -\global\let\section = \appendixsec -\global\let\subsection = \appendixsubsec -\global\let\subsubsection = \appendixsubsubsec -} - -% @centerchap is like @unnumbered, but the heading is centered. -\outer\def\centerchap{\parsearg\centerchapyyy} -\def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}} - -% @top is like @unnumbered. -\outer\def\top{\parsearg\unnumberedyyy} - -\outer\def\unnumbered{\parsearg\unnumberedyyy} -\def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz -\def\unnumberedzzz #1{% -\secno=0 \subsecno=0 \subsubsecno=0 -% -% This used to be simply \message{#1}, but TeX fully expands the -% argument to \message. Therefore, if #1 contained @-commands, TeX -% expanded them. For example, in `@unnumbered The @cite{Book}', TeX -% expanded @cite (which turns out to cause errors because \cite is meant -% to be executed, not expanded). -% -% Anyway, we don't want the fully-expanded definition of @cite to appear -% as a result of the \message, we just want `@cite' itself. We use -% \the to achieve this: TeX expands \the only once, -% simply yielding the contents of . (We also do this for -% the toc entries.) -\toks0 = {#1}\message{(\the\toks0)}% -% -\unnumbchapmacro {#1}% -\gdef\thischapter{#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbchapentry{\the\toks0}}}% -\temp -\unnumbnoderef -\global\let\section = \unnumberedsec -\global\let\subsection = \unnumberedsubsec -\global\let\subsubsection = \unnumberedsubsubsec -} - -% Sections. -\outer\def\numberedsec{\parsearg\secyyy} -\def\secyyy #1{\numhead1{#1}} % normally calls seczzz -\def\seczzz #1{% -\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 % -\gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}% - {\the\chapno}{\the\secno}}}% -\temp -\donoderef -\nobreak -} - -\outer\def\appendixsection{\parsearg\appendixsecyyy} -\outer\def\appendixsec{\parsearg\appendixsecyyy} -\def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz -\def\appendixsectionzzz #1{% -\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 % -\gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}% - {\appendixletter}{\the\secno}}}% -\temp -\appendixnoderef -\nobreak -} - -\outer\def\unnumberedsec{\parsearg\unnumberedsecyyy} -\def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz -\def\unnumberedseczzz #1{% -\plainsecheading {#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsecentry{\the\toks0}}}% -\temp -\unnumbnoderef -\nobreak -} - -% Subsections. -\outer\def\numberedsubsec{\parsearg\numberedsubsecyyy} -\def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz -\def\numberedsubseczzz #1{% -\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 % -\subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}% - {\the\chapno}{\the\secno}{\the\subsecno}}}% -\temp -\donoderef -\nobreak -} - -\outer\def\appendixsubsec{\parsearg\appendixsubsecyyy} -\def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz -\def\appendixsubseczzz #1{% -\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 % -\subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}% - {\appendixletter}{\the\secno}{\the\subsecno}}}% -\temp -\appendixnoderef -\nobreak -} - -\outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy} -\def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz -\def\unnumberedsubseczzz #1{% -\plainsubsecheading {#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsecentry% - {\the\toks0}}}% -\temp -\unnumbnoderef -\nobreak -} - -% Subsubsections. -\outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy} -\def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz -\def\numberedsubsubseczzz #1{% -\gdef\thissection{#1}\global\advance \subsubsecno by 1 % -\subsubsecheading {#1} - {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}% - {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}% -\temp -\donoderef -\nobreak -} - -\outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy} -\def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz -\def\appendixsubsubseczzz #1{% -\gdef\thissection{#1}\global\advance \subsubsecno by 1 % -\subsubsecheading {#1} - {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}% - {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}% -\temp -\appendixnoderef -\nobreak -} - -\outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy} -\def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz -\def\unnumberedsubsubseczzz #1{% -\plainsubsubsecheading {#1}\gdef\thissection{#1}% -\toks0 = {#1}% -\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsubsecentry% - {\the\toks0}}}% -\temp -\unnumbnoderef -\nobreak -} - -% These are variants which are not "outer", so they can appear in @ifinfo. -% Actually, they should now be obsolete; ordinary section commands should work. -\def\infotop{\parsearg\unnumberedzzz} -\def\infounnumbered{\parsearg\unnumberedzzz} -\def\infounnumberedsec{\parsearg\unnumberedseczzz} -\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz} -\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz} - -\def\infoappendix{\parsearg\appendixzzz} -\def\infoappendixsec{\parsearg\appendixseczzz} -\def\infoappendixsubsec{\parsearg\appendixsubseczzz} -\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz} - -\def\infochapter{\parsearg\chapterzzz} -\def\infosection{\parsearg\sectionzzz} -\def\infosubsection{\parsearg\subsectionzzz} -\def\infosubsubsection{\parsearg\subsubsectionzzz} - -% These macros control what the section commands do, according -% to what kind of chapter we are in (ordinary, appendix, or unnumbered). -% Define them by default for a numbered chapter. -\global\let\section = \numberedsec -\global\let\subsection = \numberedsubsec -\global\let\subsubsection = \numberedsubsubsec - -% Define @majorheading, @heading and @subheading - -% NOTE on use of \vbox for chapter headings, section headings, and such: -% 1) We use \vbox rather than the earlier \line to permit -% overlong headings to fold. -% 2) \hyphenpenalty is set to 10000 because hyphenation in a -% heading is obnoxious; this forbids it. -% 3) Likewise, headings look best if no \parindent is used, and -% if justification is not attempted. Hence \raggedright. - - -\def\majorheading{\parsearg\majorheadingzzz} -\def\majorheadingzzz #1{% -{\advance\chapheadingskip by 10pt \chapbreak }% -{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\raggedright - \rm #1\hfill}}\bigskip \par\penalty 200} - -\def\chapheading{\parsearg\chapheadingzzz} -\def\chapheadingzzz #1{\chapbreak % -{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\raggedright - \rm #1\hfill}}\bigskip \par\penalty 200} - -% @heading, @subheading, @subsubheading. -\def\heading{\parsearg\plainsecheading} -\def\subheading{\parsearg\plainsubsecheading} -\def\subsubheading{\parsearg\plainsubsubsecheading} - -% These macros generate a chapter, section, etc. heading only -% (including whitespace, linebreaking, etc. around it), -% given all the information in convenient, parsed form. - -%%% Args are the skip and penalty (usually negative) -\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi} - -\def\setchapterstyle #1 {\csname CHAPF#1\endcsname} - -%%% Define plain chapter starts, and page on/off switching for it -% Parameter controlling skip before chapter headings (if needed) - -\newskip\chapheadingskip - -\def\chapbreak{\dobreak \chapheadingskip {-4000}} -\def\chappager{\par\vfill\supereject} -\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi} - -\def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname} - -\def\CHAPPAGoff{% -\global\let\contentsalignmacro = \chappager -\global\let\pchapsepmacro=\chapbreak -\global\let\pagealignmacro=\chappager} - -\def\CHAPPAGon{% -\global\let\contentsalignmacro = \chappager -\global\let\pchapsepmacro=\chappager -\global\let\pagealignmacro=\chappager -\global\def\HEADINGSon{\HEADINGSsingle}} - -\def\CHAPPAGodd{ -\global\let\contentsalignmacro = \chapoddpage -\global\let\pchapsepmacro=\chapoddpage -\global\let\pagealignmacro=\chapoddpage -\global\def\HEADINGSon{\HEADINGSdouble}} - -\CHAPPAGon - -\def\CHAPFplain{ -\global\let\chapmacro=\chfplain -\global\let\unnumbchapmacro=\unnchfplain -\global\let\centerchapmacro=\centerchfplain} - -% Plain chapter opening. -% #1 is the text, #2 the chapter number or empty if unnumbered. -\def\chfplain#1#2{% - \pchapsepmacro - {% - \chapfonts \rm - \def\chapnum{#2}% - \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}% - \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright - \hangindent = \wd0 \centerparametersmaybe - \unhbox0 #1\par}% - }% - \nobreak\bigskip % no page break after a chapter title - \nobreak -} - -% Plain opening for unnumbered. -\def\unnchfplain#1{\chfplain{#1}{}} - -% @centerchap -- centered and unnumbered. -\let\centerparametersmaybe = \relax -\def\centerchfplain#1{{% - \def\centerparametersmaybe{% - \advance\rightskip by 3\rightskip - \leftskip = \rightskip - \parfillskip = 0pt - }% - \chfplain{#1}{}% -}} - -\CHAPFplain % The default - -\def\unnchfopen #1{% -\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt\raggedright - \rm #1\hfill}}\bigskip \par\nobreak -} - -\def\chfopen #1#2{\chapoddpage {\chapfonts -\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}% -\par\penalty 5000 % -} - -\def\centerchfopen #1{% -\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000 - \parindent=0pt - \hfill {\rm #1}\hfill}}\bigskip \par\nobreak -} - -\def\CHAPFopen{ -\global\let\chapmacro=\chfopen -\global\let\unnumbchapmacro=\unnchfopen -\global\let\centerchapmacro=\centerchfopen} - - -% Section titles. -\newskip\secheadingskip -\def\secheadingbreak{\dobreak \secheadingskip {-1000}} -\def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}} -\def\plainsecheading#1{\sectionheading{sec}{}{#1}} - -% Subsection titles. -\newskip \subsecheadingskip -\def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}} -\def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}} -\def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}} - -% Subsubsection titles. -\let\subsubsecheadingskip = \subsecheadingskip -\let\subsubsecheadingbreak = \subsecheadingbreak -\def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}} -\def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}} - - -% Print any size section title. -% -% #1 is the section type (sec/subsec/subsubsec), #2 is the section -% number (maybe empty), #3 the text. -\def\sectionheading#1#2#3{% - {% - \expandafter\advance\csname #1headingskip\endcsname by \parskip - \csname #1headingbreak\endcsname - }% - {% - % Switch to the right set of fonts. - \csname #1fonts\endcsname \rm - % - % Only insert the separating space if we have a section number. - \def\secnum{#2}% - \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}% - % - \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright - \hangindent = \wd0 % zero if no section number - \unhbox0 #3}% - }% - \ifdim\parskip<10pt \nobreak\kern10pt\nobreak\kern-\parskip\fi \nobreak -} - - -\message{toc,} -\newwrite\tocfile - -% Write an entry to the toc file, opening it if necessary. -% Called from @chapter, etc. We supply {\folio} at the end of the -% argument, which will end up as the last argument to the \...entry macro. -% -% We open the .toc file here instead of at @setfilename or any other -% given time so that @contents can be put in the document anywhere. -% -\newif\iftocfileopened -\def\writetocentry#1{% - \iftocfileopened\else - \immediate\openout\tocfile = \jobname.toc - \global\tocfileopenedtrue - \fi - \iflinks \write\tocfile{#1{\folio}}\fi -} - -\newskip\contentsrightmargin \contentsrightmargin=1in -\newcount\savepageno -\newcount\lastnegativepageno \lastnegativepageno = -1 - -% Finish up the main text and prepare to read what we've written -% to \tocfile. -% -\def\startcontents#1{% - % If @setchapternewpage on, and @headings double, the contents should - % start on an odd page, unlike chapters. Thus, we maintain - % \contentsalignmacro in parallel with \pagealignmacro. - % From: Torbjorn Granlund - \contentsalignmacro - \immediate\closeout\tocfile - % - % Don't need to put `Contents' or `Short Contents' in the headline. - % It is abundantly clear what they are. - \unnumbchapmacro{#1}\def\thischapter{}% - \savepageno = \pageno - \begingroup % Set up to handle contents files properly. - \catcode`\\=0 \catcode`\{=1 \catcode`\}=2 \catcode`\@=11 - % We can't do this, because then an actual ^ in a section - % title fails, e.g., @chapter ^ -- exponentiation. --karl, 9jul97. - %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi - \raggedbottom % Worry more about breakpoints than the bottom. - \advance\hsize by -\contentsrightmargin % Don't use the full line length. - % - % Roman numerals for page numbers. - \ifnum \pageno>0 \pageno = \lastnegativepageno \fi -} - - -% Normal (long) toc. -\def\contents{% - \startcontents{\putwordTableofContents}% - \openin 1 \jobname.toc - \ifeof 1 \else - \closein 1 - \input \jobname.toc - \fi - \vfill \eject - \endgroup - \lastnegativepageno = \pageno - \pageno = \savepageno -} - -% And just the chapters. -\def\summarycontents{% - \startcontents{\putwordShortContents}% - % - \let\chapentry = \shortchapentry - \let\unnumbchapentry = \shortunnumberedentry - % We want a true roman here for the page numbers. - \secfonts - \let\rm=\shortcontrm \let\bf=\shortcontbf \let\sl=\shortcontsl - \rm - \hyphenpenalty = 10000 - \advance\baselineskip by 1pt % Open it up a little. - \def\secentry ##1##2##3##4{} - \def\unnumbsecentry ##1##2{} - \def\subsecentry ##1##2##3##4##5{} - \def\unnumbsubsecentry ##1##2{} - \def\subsubsecentry ##1##2##3##4##5##6{} - \def\unnumbsubsubsecentry ##1##2{} - \openin 1 \jobname.toc - \ifeof 1 \else - \closein 1 - \input \jobname.toc - \fi - \vfill \eject - \endgroup - \lastnegativepageno = \pageno - \pageno = \savepageno -} -\let\shortcontents = \summarycontents - -% These macros generate individual entries in the table of contents. -% The first argument is the chapter or section name. -% The last argument is the page number. -% The arguments in between are the chapter number, section number, ... - -% Chapter-level things, for both the long and short contents. -\def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}} - -% See comments in \dochapentry re vbox and related settings -\def\shortchapentry#1#2#3{% - \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno{#3}}% -} - -% Typeset the label for a chapter or appendix for the short contents. -% The arg is, e.g. `Appendix A' for an appendix, or `3' for a chapter. -% We could simplify the code here by writing out an \appendixentry -% command in the toc file for appendices, instead of using \chapentry -% for both, but it doesn't seem worth it. -\setbox0 = \hbox{\shortcontrm \putwordAppendix } -\newdimen\shortappendixwidth \shortappendixwidth = \wd0 - -\def\shortchaplabel#1{% - % We typeset #1 in a box of constant width, regardless of the text of - % #1, so the chapter titles will come out aligned. - \setbox0 = \hbox{#1}% - \dimen0 = \ifdim\wd0 > \shortappendixwidth \shortappendixwidth \else 0pt \fi - % - % This space should be plenty, since a single number is .5em, and the - % widest letter (M) is 1em, at least in the Computer Modern fonts. - % (This space doesn't include the extra space that gets added after - % the label; that gets put in by \shortchapentry above.) - \advance\dimen0 by 1.1em - \hbox to \dimen0{#1\hfil}% -} - -\def\unnumbchapentry#1#2{\dochapentry{#1}{#2}} -\def\shortunnumberedentry#1#2{\tocentry{#1}{\doshortpageno{#2}}} - -% Sections. -\def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}} -\def\unnumbsecentry#1#2{\dosecentry{#1}{#2}} - -% Subsections. -\def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}} -\def\unnumbsubsecentry#1#2{\dosubsecentry{#1}{#2}} - -% And subsubsections. -\def\subsubsecentry#1#2#3#4#5#6{% - \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}} -\def\unnumbsubsubsecentry#1#2{\dosubsubsecentry{#1}{#2}} - -% This parameter controls the indentation of the various levels. -\newdimen\tocindent \tocindent = 3pc - -% Now for the actual typesetting. In all these, #1 is the text and #2 is the -% page number. -% -% If the toc has to be broken over pages, we want it to be at chapters -% if at all possible; hence the \penalty. -\def\dochapentry#1#2{% - \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip - \begingroup - \chapentryfonts - \tocentry{#1}{\dopageno{#2}}% - \endgroup - \nobreak\vskip .25\baselineskip plus.1\baselineskip -} - -\def\dosecentry#1#2{\begingroup - \secentryfonts \leftskip=\tocindent - \tocentry{#1}{\dopageno{#2}}% -\endgroup} - -\def\dosubsecentry#1#2{\begingroup - \subsecentryfonts \leftskip=2\tocindent - \tocentry{#1}{\dopageno{#2}}% -\endgroup} - -\def\dosubsubsecentry#1#2{\begingroup - \subsubsecentryfonts \leftskip=3\tocindent - \tocentry{#1}{\dopageno{#2}}% -\endgroup} - -% Final typesetting of a toc entry; we use the same \entry macro as for -% the index entries, but we want to suppress hyphenation here. (We -% can't do that in the \entry macro, since index entries might consist -% of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.) -\def\tocentry#1#2{\begingroup - \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks - % Do not use \turnoffactive in these arguments. Since the toc is - % typeset in cmr, so characters such as _ would come out wrong; we - % have to do the usual translation tricks. - \entry{#1}{#2}% -\endgroup} - -% Space between chapter (or whatever) number and the title. -\def\labelspace{\hskip1em \relax} - -\def\dopageno#1{{\rm #1}} -\def\doshortpageno#1{{\rm #1}} - -\def\chapentryfonts{\secfonts \rm} -\def\secentryfonts{\textfonts} -\let\subsecentryfonts = \textfonts -\let\subsubsecentryfonts = \textfonts - - -\message{environments,} - -% Since these characters are used in examples, it should be an even number of -% \tt widths. Each \tt character is 1en, so two makes it 1em. -% Furthermore, these definitions must come after we define our fonts. -\newbox\dblarrowbox \newbox\longdblarrowbox -\newbox\pushcharbox \newbox\bullbox -\newbox\equivbox \newbox\errorbox - -%{\tentt -%\global\setbox\dblarrowbox = \hbox to 1em{\hfil$\Rightarrow$\hfil} -%\global\setbox\longdblarrowbox = \hbox to 1em{\hfil$\mapsto$\hfil} -%\global\setbox\pushcharbox = \hbox to 1em{\hfil$\dashv$\hfil} -%\global\setbox\equivbox = \hbox to 1em{\hfil$\ptexequiv$\hfil} -% Adapted from the manmac format (p.420 of TeXbook) -%\global\setbox\bullbox = \hbox to 1em{\kern.15em\vrule height .75ex width .85ex -% depth .1ex\hfil} -%} - -% @point{}, @result{}, @expansion{}, @print{}, @equiv{}. -\def\point{$\star$} -\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}} -\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}} -\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}} -\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}} - -% Adapted from the TeXbook's \boxit. -{\tentt \global\dimen0 = 3em}% Width of the box. -\dimen2 = .55pt % Thickness of rules -% The text. (`r' is open on the right, `e' somewhat less so on the left.) -\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt} - -\global\setbox\errorbox=\hbox to \dimen0{\hfil - \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right. - \advance\hsize by -2\dimen2 % Rules. - \vbox{ - \hrule height\dimen2 - \hbox{\vrule width\dimen2 \kern3pt % Space to left of text. - \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below. - \kern3pt\vrule width\dimen2}% Space to right. - \hrule height\dimen2} - \hfil} - -% The @error{} command. -\def\error{\leavevmode\lower.7ex\copy\errorbox} - -% @tex ... @end tex escapes into raw Tex temporarily. -% One exception: @ is still an escape character, so that @end tex works. -% But \@ or @@ will get a plain tex @ character. - -\def\tex{\begingroup - \catcode `\\=0 \catcode `\{=1 \catcode `\}=2 - \catcode `\$=3 \catcode `\&=4 \catcode `\#=6 - \catcode `\^=7 \catcode `\_=8 \catcode `\~=13 \let~=\tie - \catcode `\%=14 - \catcode 43=12 % plus - \catcode`\"=12 - \catcode`\==12 - \catcode`\|=12 - \catcode`\<=12 - \catcode`\>=12 - \escapechar=`\\ - % - \let\b=\ptexb - \let\bullet=\ptexbullet - \let\c=\ptexc - \let\,=\ptexcomma - \let\.=\ptexdot - \let\dots=\ptexdots - \let\equiv=\ptexequiv - \let\!=\ptexexclam - \let\i=\ptexi - \let\{=\ptexlbrace - \let\+=\tabalign - \let\}=\ptexrbrace - \let\*=\ptexstar - \let\t=\ptext - % - \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}% - \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}% - \def\@{@}% -\let\Etex=\endgroup} - -% Define @lisp ... @endlisp. -% @lisp does a \begingroup so it can rebind things, -% including the definition of @endlisp (which normally is erroneous). - -% Amount to narrow the margins by for @lisp. -\newskip\lispnarrowing \lispnarrowing=0.4in - -% This is the definition that ^^M gets inside @lisp, @example, and other -% such environments. \null is better than a space, since it doesn't -% have any width. -\def\lisppar{\null\endgraf} - -% Make each space character in the input produce a normal interword -% space in the output. Don't allow a line break at this space, as this -% is used only in environments like @example, where each line of input -% should produce a line of output anyway. -% -{\obeyspaces % -\gdef\sepspaces{\obeyspaces\let =\tie}} - -% Define \obeyedspace to be our active space, whatever it is. This is -% for use in \parsearg. -{\sepspaces% -\global\let\obeyedspace= } - -% This space is always present above and below environments. -\newskip\envskipamount \envskipamount = 0pt - -% Make spacing and below environment symmetrical. We use \parskip here -% to help in doing that, since in @example-like environments \parskip -% is reset to zero; thus the \afterenvbreak inserts no space -- but the -% start of the next paragraph will insert \parskip -% -\def\aboveenvbreak{{\advance\envskipamount by \parskip -\endgraf \ifdim\lastskip<\envskipamount -\removelastskip \penalty-50 \vskip\envskipamount \fi}} - -\let\afterenvbreak = \aboveenvbreak - -% \nonarrowing is a flag. If "set", @lisp etc don't narrow margins. -\let\nonarrowing=\relax - -% @cartouche ... @end cartouche: draw rectangle w/rounded corners around -% environment contents. -\font\circle=lcircle10 -\newdimen\circthick -\newdimen\cartouter\newdimen\cartinner -\newskip\normbskip\newskip\normpskip\newskip\normlskip -\circthick=\fontdimen8\circle -% -\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth -\def\ctr{{\hskip 6pt\circle\char'010}} -\def\cbl{{\circle\char'012\hskip -6pt}} -\def\cbr{{\hskip 6pt\circle\char'011}} -\def\carttop{\hbox to \cartouter{\hskip\lskip - \ctl\leaders\hrule height\circthick\hfil\ctr - \hskip\rskip}} -\def\cartbot{\hbox to \cartouter{\hskip\lskip - \cbl\leaders\hrule height\circthick\hfil\cbr - \hskip\rskip}} -% -\newskip\lskip\newskip\rskip - -\long\def\cartouche{% -\begingroup - \lskip=\leftskip \rskip=\rightskip - \leftskip=0pt\rightskip=0pt %we want these *outside*. - \cartinner=\hsize \advance\cartinner by-\lskip - \advance\cartinner by-\rskip - \cartouter=\hsize - \advance\cartouter by 18.4pt % allow for 3pt kerns on either -% side, and for 6pt waste from -% each corner char, and rule thickness - \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip - % Flag to tell @lisp, etc., not to narrow margin. - \let\nonarrowing=\comment - \vbox\bgroup - \baselineskip=0pt\parskip=0pt\lineskip=0pt - \carttop - \hbox\bgroup - \hskip\lskip - \vrule\kern3pt - \vbox\bgroup - \hsize=\cartinner - \kern3pt - \begingroup - \baselineskip=\normbskip - \lineskip=\normlskip - \parskip=\normpskip - \vskip -\parskip -\def\Ecartouche{% - \endgroup - \kern3pt - \egroup - \kern3pt\vrule - \hskip\rskip - \egroup - \cartbot - \egroup -\endgroup -}} - - -% This macro is called at the beginning of all the @example variants, -% inside a group. -\def\nonfillstart{% - \aboveenvbreak - \inENV % This group ends at the end of the body - \hfuzz = 12pt % Don't be fussy - \sepspaces % Make spaces be word-separators rather than space tokens. - \singlespace - \let\par = \lisppar % don't ignore blank lines - \obeylines % each line of input is a line of output - \parskip = 0pt - \parindent = 0pt - \emergencystretch = 0pt % don't try to avoid overfull boxes - % @cartouche defines \nonarrowing to inhibit narrowing - % at next level down. - \ifx\nonarrowing\relax - \advance \leftskip by \lispnarrowing - \exdentamount=\lispnarrowing - \let\exdent=\nofillexdent - \let\nonarrowing=\relax - \fi -} - -% Define the \E... control sequence only if we are inside the particular -% environment, so the error checking in \end will work. -% -% To end an @example-like environment, we first end the paragraph (via -% \afterenvbreak's vertical glue), and then the group. That way we keep -% the zero \parskip that the environments set -- \parskip glue will be -% inserted at the beginning of the next paragraph in the document, after -% the environment. -% -\def\nonfillfinish{\afterenvbreak\endgroup} - -% @lisp: indented, narrowed, typewriter font. -\def\lisp{\begingroup - \nonfillstart - \let\Elisp = \nonfillfinish - \tt - \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special. - \gobble % eat return -} - -% @example: Same as @lisp. -\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp} - -% @small... is usually equivalent to the non-small (@smallbook -% redefines). We must call \example (or whatever) last in the -% definition, since it reads the return following the @example (or -% whatever) command. -% -% This actually allows (for example) @end display inside an -% @smalldisplay. Too bad, but makeinfo will catch the error anyway. -% -\def\smalldisplay{\begingroup\def\Esmalldisplay{\nonfillfinish\endgroup}\display} -\def\smallexample{\begingroup\def\Esmallexample{\nonfillfinish\endgroup}\lisp} -\def\smallformat{\begingroup\def\Esmallformat{\nonfillfinish\endgroup}\format} -\def\smalllisp{\begingroup\def\Esmalllisp{\nonfillfinish\endgroup}\lisp} - -% Real @smallexample and @smalllisp (when @smallbook): use smaller fonts. -% Originally contributed by Pavel@xerox. -\def\smalllispx{\begingroup - \def\Esmalllisp{\nonfillfinish\endgroup}% - \def\Esmallexample{\nonfillfinish\endgroup}% - \indexfonts - \lisp -} - -% @display: same as @lisp except keep current font. -% -\def\display{\begingroup - \nonfillstart - \let\Edisplay = \nonfillfinish - \gobble -} - -% @smalldisplay (when @smallbook): @display plus smaller fonts. -% -\def\smalldisplayx{\begingroup - \def\Esmalldisplay{\nonfillfinish\endgroup}% - \indexfonts \rm - \display -} - -% @format: same as @display except don't narrow margins. -% -\def\format{\begingroup - \let\nonarrowing = t - \nonfillstart - \let\Eformat = \nonfillfinish - \gobble -} - -% @smallformat (when @smallbook): @format plus smaller fonts. -% -\def\smallformatx{\begingroup - \def\Esmallformat{\nonfillfinish\endgroup}% - \indexfonts \rm - \format -} - -% @flushleft (same as @format). -% -\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format} - -% @flushright. -% -\def\flushright{\begingroup - \let\nonarrowing = t - \nonfillstart - \let\Eflushright = \nonfillfinish - \advance\leftskip by 0pt plus 1fill - \gobble -} - -% @quotation does normal linebreaking (hence we can't use \nonfillstart) -% and narrows the margins. -% -\def\quotation{% - \begingroup\inENV %This group ends at the end of the @quotation body - {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip - \singlespace - \parindent=0pt - % We have retained a nonzero parskip for the environment, since we're - % doing normal filling. So to avoid extra space below the environment... - \def\Equotation{\parskip = 0pt \nonfillfinish}% - % - % @cartouche defines \nonarrowing to inhibit narrowing at next level down. - \ifx\nonarrowing\relax - \advance\leftskip by \lispnarrowing - \advance\rightskip by \lispnarrowing - \exdentamount = \lispnarrowing - \let\nonarrowing = \relax - \fi -} - - -\message{defuns,} -% Define formatter for defuns -% First, allow user to change definition object font (\df) internally -\def\setdeffont #1 {\csname DEF#1\endcsname} - -\newskip\defbodyindent \defbodyindent=.4in -\newskip\defargsindent \defargsindent=50pt -\newskip\deftypemargin \deftypemargin=12pt -\newskip\deflastargmargin \deflastargmargin=18pt - -\newcount\parencount -% define \functionparens, which makes ( and ) and & do special things. -% \functionparens affects the group it is contained in. -\def\activeparens{% -\catcode`\(=\active \catcode`\)=\active \catcode`\&=\active -\catcode`\[=\active \catcode`\]=\active} - -% Make control sequences which act like normal parenthesis chars. -\let\lparen = ( \let\rparen = ) - -{\activeparens % Now, smart parens don't turn on until &foo (see \amprm) - -% Be sure that we always have a definition for `(', etc. For example, -% if the fn name has parens in it, \boldbrax will not be in effect yet, -% so TeX would otherwise complain about undefined control sequence. -\global\let(=\lparen \global\let)=\rparen -\global\let[=\lbrack \global\let]=\rbrack - -\gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 } -\gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb} -% This is used to turn on special parens -% but make & act ordinary (given that it's active). -\gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr} - -% Definitions of (, ) and & used in args for functions. -% This is the definition of ( outside of all parentheses. -\gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested - \global\advance\parencount by 1 -} -% -% This is the definition of ( when already inside a level of parens. -\gdef\opnested{\char`\(\global\advance\parencount by 1 } -% -\gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0. - % also in that case restore the outer-level definition of (. - \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi - \global\advance \parencount by -1 } -% If we encounter &foo, then turn on ()-hacking afterwards -\gdef\amprm#1 {{\rm\}\let(=\oprm \let)=\clrm\ } -% -\gdef\normalparens{\boldbrax\let&=\ampnr} -} % End of definition inside \activeparens -%% These parens (in \boldbrax) actually are a little bolder than the -%% contained text. This is especially needed for [ and ] -\def\opnr{{\sf\char`\(}\global\advance\parencount by 1 } -\def\clnr{{\sf\char`\)}\global\advance\parencount by -1 } -\def\ampnr{\&} -\def\lbrb{{\bf\char`\[}} -\def\rbrb{{\bf\char`\]}} - -% First, defname, which formats the header line itself. -% #1 should be the function name. -% #2 should be the type of definition, such as "Function". - -\def\defname #1#2{% -% Get the values of \leftskip and \rightskip as they were -% outside the @def... -\dimen2=\leftskip -\advance\dimen2 by -\defbodyindent -\noindent -\setbox0=\hbox{\hskip \deflastargmargin{\rm #2}\hskip \deftypemargin}% -\dimen0=\hsize \advance \dimen0 by -\wd0 % compute size for first line -\dimen1=\hsize \advance \dimen1 by -\defargsindent %size for continuations -\parshape 2 0in \dimen0 \defargsindent \dimen1 -% Now output arg 2 ("Function" or some such) -% ending at \deftypemargin from the right margin, -% but stuck inside a box of width 0 so it does not interfere with linebreaking -{% Adjust \hsize to exclude the ambient margins, -% so that \rightline will obey them. -\advance \hsize by -\dimen2 -\rlap{\rightline{{\rm #2}\hskip -1.25pc }}}% -% Make all lines underfull and no complaints: -\tolerance=10000 \hbadness=10000 -\advance\leftskip by -\defbodyindent -\exdentamount=\defbodyindent -{\df #1}\enskip % Generate function name -} - -% Actually process the body of a definition -% #1 should be the terminating control sequence, such as \Edefun. -% #2 should be the "another name" control sequence, such as \defunx. -% #3 should be the control sequence that actually processes the header, -% such as \defunheader. - -\def\defparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2{\begingroup\obeylines\activeparens\spacesplit#3}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup % -\catcode 61=\active % 61 is `=' -\obeylines\activeparens\spacesplit#3} - -% #1 is the \E... control sequence to end the definition (which we define). -% #2 is the \...x control sequence for consecutive fns (which we define). -% #3 is the control sequence to call to resume processing. -% #4, delimited by the space, is the class name. -% -\def\defmethparsebody#1#2#3#4 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\activeparens\spacesplit{#3{#4}}} - -% @deftypemethod has an extra argument that nothing else does. Sigh. -% #1 is the \E... control sequence to end the definition (which we define). -% #2 is the \...x control sequence for consecutive fns (which we define). -% #3 is the control sequence to call to resume processing. -% #4, delimited by the space, is the class name. -% #5 is the method's return type. -% -\def\deftypemethparsebody#1#2#3#4 #5 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 ##2 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}{##2}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\activeparens\spacesplit{#3{#4}{#5}}} - -\def\defopparsebody #1#2#3#4#5 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 ##2 {\def#4{##1}% -\begingroup\obeylines\activeparens\spacesplit{#3{##2}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\activeparens\spacesplit{#3{#5}}} - -% These parsing functions are similar to the preceding ones -% except that they do not make parens into active characters. -% These are used for "variables" since they have no arguments. - -\def\defvarparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2{\begingroup\obeylines\spacesplit#3}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup % -\catcode 61=\active % -\obeylines\spacesplit#3} - -% This is used for \def{tp,vr}parsebody. It could probably be used for -% some of the others, too, with some judicious conditionals. -% -\def\parsebodycommon#1#2#3{% - \begingroup\inENV % - \medbreak % - % Define the end token that this defining construct specifies - % so that it will exit this group. - \def#1{\endgraf\endgroup\medbreak}% - \def#2##1 {\begingroup\obeylines\spacesplit{#3{##1}}}% - \parindent=0in - \advance\leftskip by \defbodyindent - \exdentamount=\defbodyindent - \begingroup\obeylines -} - -\def\defvrparsebody#1#2#3#4 {% - \parsebodycommon{#1}{#2}{#3}% - \spacesplit{#3{#4}}% -} - -% This loses on `@deftp {Data Type} {struct termios}' -- it thinks the -% type is just `struct', because we lose the braces in `{struct -% termios}' when \spacesplit reads its undelimited argument. Sigh. -% \let\deftpparsebody=\defvrparsebody -% -% So, to get around this, we put \empty in with the type name. That -% way, TeX won't find exactly `{...}' as an undelimited argument, and -% won't strip off the braces. -% -\def\deftpparsebody #1#2#3#4 {% - \parsebodycommon{#1}{#2}{#3}% - \spacesplit{\parsetpheaderline{#3{#4}}}\empty -} - -% Fine, but then we have to eventually remove the \empty *and* the -% braces (if any). That's what this does. -% -\def\removeemptybraces\empty#1\relax{#1} - -% After \spacesplit has done its work, this is called -- #1 is the final -% thing to call, #2 the type name (which starts with \empty), and #3 -% (which might be empty) the arguments. -% -\def\parsetpheaderline#1#2#3{% - #1{\removeemptybraces#2\relax}{#3}% -}% - -\def\defopvarparsebody #1#2#3#4#5 {\begingroup\inENV % -\medbreak % -% Define the end token that this defining construct specifies -% so that it will exit this group. -\def#1{\endgraf\endgroup\medbreak}% -\def#2##1 ##2 {\def#4{##1}% -\begingroup\obeylines\spacesplit{#3{##2}}}% -\parindent=0in -\advance\leftskip by \defbodyindent -\exdentamount=\defbodyindent -\begingroup\obeylines\spacesplit{#3{#5}}} - -% Split up #2 at the first space token. -% call #1 with two arguments: -% the first is all of #2 before the space token, -% the second is all of #2 after that space token. -% If #2 contains no space token, all of it is passed as the first arg -% and the second is passed as empty. - -{\obeylines -\gdef\spacesplit#1#2^^M{\endgroup\spacesplitfoo{#1}#2 \relax\spacesplitfoo}% -\long\gdef\spacesplitfoo#1#2 #3#4\spacesplitfoo{% -\ifx\relax #3% -#1{#2}{}\else #1{#2}{#3#4}\fi}} - -% So much for the things common to all kinds of definitions. - -% Define @defun. - -% First, define the processing that is wanted for arguments of \defun -% Use this to expand the args and terminate the paragraph they make up - -\def\defunargs #1{\functionparens \sl -% Expand, preventing hyphenation at `-' chars. -% Note that groups don't affect changes in \hyphenchar. -\hyphenchar\tensl=0 -#1% -\hyphenchar\tensl=45 -\ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi% -\interlinepenalty=10000 -\advance\rightskip by 0pt plus 1fil -\endgraf\nobreak\vskip -\parskip\nobreak -} - -\def\deftypefunargs #1{% -% Expand, preventing hyphenation at `-' chars. -% Note that groups don't affect changes in \hyphenchar. -% Use \boldbraxnoamp, not \functionparens, so that & is not special. -\boldbraxnoamp -\tclose{#1}% avoid \code because of side effects on active chars -\interlinepenalty=10000 -\advance\rightskip by 0pt plus 1fil -\endgraf\nobreak\vskip -\parskip\nobreak -} - -% Do complete processing of one @defun or @defunx line already parsed. - -% @deffn Command forward-char nchars - -\def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader} - -\def\deffnheader #1#2#3{\doind {fn}{\code{#2}}% -\begingroup\defname {#2}{#1}\defunargs{#3}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defun == @deffn Function - -\def\defun{\defparsebody\Edefun\defunx\defunheader} - -\def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index -\begingroup\defname {#1}{Function}% -\defunargs {#2}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @deftypefun int foobar (int @var{foo}, float @var{bar}) - -\def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader} - -% #1 is the data type. #2 is the name and args. -\def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax} -% #1 is the data type, #2 the name, #3 the args. -\def\deftypefunheaderx #1#2 #3\relax{% -\doind {fn}{\code{#2}}% Make entry in function index -\begingroup\defname {\defheaderxcond#1\relax$$$#2}{Function}% -\deftypefunargs {#3}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar}) - -\def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader} - -% \defheaderxcond#1\relax$$$ -% puts #1 in @code, followed by a space, but does nothing if #1 is null. -\def\defheaderxcond#1#2$$${\ifx#1\relax\else\code{#1#2} \fi} - -% #1 is the classification. #2 is the data type. #3 is the name and args. -\def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax} -% #1 is the classification, #2 the data type, #3 the name, #4 the args. -\def\deftypefnheaderx #1#2#3 #4\relax{% -\doind {fn}{\code{#3}}% Make entry in function index -\begingroup -\normalparens % notably, turn off `&' magic, which prevents -% at least some C++ text from working -\defname {\defheaderxcond#2\relax$$$#3}{#1}% -\deftypefunargs {#4}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defmac == @deffn Macro - -\def\defmac{\defparsebody\Edefmac\defmacx\defmacheader} - -\def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index -\begingroup\defname {#1}{Macro}% -\defunargs {#2}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% @defspec == @deffn Special Form - -\def\defspec{\defparsebody\Edefspec\defspecx\defspecheader} - -\def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index -\begingroup\defname {#1}{Special Form}% -\defunargs {#2}\endgroup % -\catcode 61=\other % Turn off change made in \defparsebody -} - -% This definition is run if you use @defunx -% anywhere other than immediately after a @defun or @defunx. - -\def\deffnx #1 {\errmessage{@deffnx in invalid context}} -\def\defunx #1 {\errmessage{@defunx in invalid context}} -\def\defmacx #1 {\errmessage{@defmacx in invalid context}} -\def\defspecx #1 {\errmessage{@defspecx in invalid context}} -\def\deftypefnx #1 {\errmessage{@deftypefnx in invalid context}} -\def\deftypemethodx #1 {\errmessage{@deftypemethodx in invalid context}} -\def\deftypefunx #1 {\errmessage{@deftypefunx in invalid context}} - -% @defmethod, and so on - -% @defop CATEGORY CLASS OPERATION ARG... - -\def\defop #1 {\def\defoptype{#1}% -\defopparsebody\Edefop\defopx\defopheader\defoptype} - -\def\defopheader #1#2#3{% -\dosubind {fn}{\code{#2}}{\putwordon\ #1}% Make entry in function index -\begingroup\defname {#2}{\defoptype{} on #1}% -\defunargs {#3}\endgroup % -} - -% @deftypemethod CLASS RETURN-TYPE METHOD ARG... -% -\def\deftypemethod{% - \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader} -% -% #1 is the class name, #2 the data type, #3 the method name, #4 the args. -\def\deftypemethodheader#1#2#3#4{% - \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index - \begingroup - \defname{\defheaderxcond#2\relax$$$#3}{\putwordMethodon\ \code{#1}}% - \deftypefunargs{#4}% - \endgroup -} - -% @defmethod == @defop Method -% -\def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader} -% -% #1 is the class name, #2 the method name, #3 the args. -\def\defmethodheader#1#2#3{% - \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index - \begingroup - \defname{#2}{\putwordMethodon\ \code{#1}}% - \defunargs{#3}% - \endgroup -} - -% @defcv {Class Option} foo-class foo-flag - -\def\defcv #1 {\def\defcvtype{#1}% -\defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype} - -\def\defcvarheader #1#2#3{% -\dosubind {vr}{\code{#2}}{of #1}% Make entry in var index -\begingroup\defname {#2}{\defcvtype{} of #1}% -\defvarargs {#3}\endgroup % -} - -% @defivar == @defcv {Instance Variable} - -\def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader} - -\def\defivarheader #1#2#3{% -\dosubind {vr}{\code{#2}}{of #1}% Make entry in var index -\begingroup\defname {#2}{Instance Variable of #1}% -\defvarargs {#3}\endgroup % -} - -% These definitions are run if you use @defmethodx, etc., -% anywhere other than immediately after a @defmethod, etc. - -\def\defopx #1 {\errmessage{@defopx in invalid context}} -\def\defmethodx #1 {\errmessage{@defmethodx in invalid context}} -\def\defcvx #1 {\errmessage{@defcvx in invalid context}} -\def\defivarx #1 {\errmessage{@defivarx in invalid context}} - -% Now @defvar - -% First, define the processing that is wanted for arguments of @defvar. -% This is actually simple: just print them in roman. -% This must expand the args and terminate the paragraph they make up -\def\defvarargs #1{\normalparens #1% -\interlinepenalty=10000 -\endgraf\nobreak\vskip -\parskip\nobreak} - -% @defvr Counter foo-count - -\def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader} - -\def\defvrheader #1#2#3{\doind {vr}{\code{#2}}% -\begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup} - -% @defvar == @defvr Variable - -\def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader} - -\def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index -\begingroup\defname {#1}{Variable}% -\defvarargs {#2}\endgroup % -} - -% @defopt == @defvr {User Option} - -\def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader} - -\def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index -\begingroup\defname {#1}{User Option}% -\defvarargs {#2}\endgroup % -} - -% @deftypevar int foobar - -\def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader} - -% #1 is the data type. #2 is the name, perhaps followed by text that -% is actually part of the data type, which should not be put into the index. -\def\deftypevarheader #1#2{% -\dovarind#2 \relax% Make entry in variables index -\begingroup\defname {\defheaderxcond#1\relax$$$#2}{Variable}% -\interlinepenalty=10000 -\endgraf\nobreak\vskip -\parskip\nobreak -\endgroup} -\def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}} - -% @deftypevr {Global Flag} int enable - -\def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader} - -\def\deftypevrheader #1#2#3{\dovarind#3 \relax% -\begingroup\defname {\defheaderxcond#2\relax$$$#3}{#1} -\interlinepenalty=10000 -\endgraf\nobreak\vskip -\parskip\nobreak -\endgroup} - -% This definition is run if you use @defvarx -% anywhere other than immediately after a @defvar or @defvarx. - -\def\defvrx #1 {\errmessage{@defvrx in invalid context}} -\def\defvarx #1 {\errmessage{@defvarx in invalid context}} -\def\defoptx #1 {\errmessage{@defoptx in invalid context}} -\def\deftypevarx #1 {\errmessage{@deftypevarx in invalid context}} -\def\deftypevrx #1 {\errmessage{@deftypevrx in invalid context}} - -% Now define @deftp -% Args are printed in bold, a slight difference from @defvar. - -\def\deftpargs #1{\bf \defvarargs{#1}} - -% @deftp Class window height width ... - -\def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader} - -\def\deftpheader #1#2#3{\doind {tp}{\code{#2}}% -\begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup} - -% This definition is run if you use @deftpx, etc -% anywhere other than immediately after a @deftp, etc. - -\def\deftpx #1 {\errmessage{@deftpx in invalid context}} - - -\message{macros,} -% @macro. - -% To do this right we need a feature of e-TeX, \scantokens, -% which we arrange to emulate with a temporary file in ordinary TeX. -\ifx\eTeXversion\undefined - \newwrite\macscribble - \def\scanmacro#1{% - \begingroup \newlinechar`\^^M - \immediate\openout\macscribble=\jobname.tmp - \immediate\write\macscribble{#1}% - \immediate\closeout\macscribble - \let\xeatspaces\eatspaces - \input \jobname.tmp - \endgroup -} -\else -\def\scanmacro#1{% -\begingroup \newlinechar`\^^M -\let\xeatspaces\eatspaces\scantokens{#1}\endgroup} -\fi - -\newcount\paramno % Count of parameters -\newtoks\macname % Macro name -\newif\ifrecursive % Is it recursive? - -% Utility routines. -% Thisdoes \let #1 = #2, except with \csnames. -\def\cslet#1#2{% -\expandafter\expandafter -\expandafter\let -\expandafter\expandafter -\csname#1\endcsname -\csname#2\endcsname} - -% Trim leading and trailing spaces off a string. -% Concepts from aro-bend problem 15 (see CTAN). -{\catcode`\@=11 -\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }} -\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@} -\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @} -\def\unbrace#1{#1} -\unbrace{\gdef\trim@@@ #1 } #2@{#1} -} - -% Trim a single trailing ^^M off a string. -{\catcode`\^^M=12\catcode`\Q=3% -\gdef\eatcr #1{\eatcra #1Q^^MQ}% -\gdef\eatcra#1^^MQ{\eatcrb#1Q}% -\gdef\eatcrb#1Q#2Q{#1}% -} - -% Macro bodies are absorbed as an argument in a context where -% all characters are catcode 10, 11 or 12, except \ which is active -% (as in normal texinfo). It is necessary to change the definition of \. - -% It's necessary to have hard CRs when the macro is executed. This is -% done by making ^^M (\endlinechar) catcode 12 when reading the macro -% body, and then making it the \newlinechar in \scanmacro. - -\def\macrobodyctxt{% - \catcode`\~=12 - \catcode`\^=12 - \catcode`\_=12 - \catcode`\|=12 - \catcode`\<=12 - \catcode`\>=12 - \catcode`\+=12 - \catcode`\{=12 - \catcode`\}=12 - \catcode`\@=12 - \catcode`\^^M=12 - \usembodybackslash} - -\def\macroargctxt{% - \catcode`\~=12 - \catcode`\^=12 - \catcode`\_=12 - \catcode`\|=12 - \catcode`\<=12 - \catcode`\>=12 - \catcode`\+=12 - \catcode`\@=12 - \catcode`\\=12} - -% \mbodybackslash is the definition of \ in @macro bodies. -% It maps \foo\ => \csname macarg.foo\endcsname => #N -% where N is the macro parameter number. -% We define \csname macarg.\endcsname to be \realbackslash, so -% \\ in macro replacement text gets you a backslash. - -{\catcode`@=0 @catcode`@\=@active - @gdef@usembodybackslash{@let\=@mbodybackslash} - @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname} -} -\expandafter\def\csname macarg.\endcsname{\realbackslash} - -\def\macro{\recursivefalse\parsearg\macroxxx} -\def\rmacro{\recursivetrue\parsearg\macroxxx} - -\def\macroxxx#1{% - \getargs{#1}% now \macname is the macname and \argl the arglist - \ifx\argl\empty % no arguments - \paramno=0% - \else - \expandafter\parsemargdef \argl;% - \fi - \expandafter\ifx \csname macsave.\the\macname\endcsname \relax - \cslet{macsave.\the\macname}{\the\macname}% - \else - \message{Warning: redefining \the\macname}% - \fi - \begingroup \macrobodyctxt - \ifrecursive \expandafter\parsermacbody - \else \expandafter\parsemacbody - \fi} - -\def\unmacro{\parsearg\unmacroxxx} -\def\unmacroxxx#1{% - \expandafter\ifx \csname macsave.\the\macname\endcsname \relax - \errmessage{Macro \the\macname\ not defined.}% - \else - \cslet{#1}{macsave.#1}% - \expandafter\let \csname macsave.\the\macname\endcsname \undefined - \fi -} - -% This makes use of the obscure feature that if the last token of a -% is #, then the preceding argument is delimited by -% an opening brace, and that opening brace is not consumed. -\def\getargs#1{\getargsxxx#1{}} -\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs} -\def\getmacname #1 #2\relax{\macname={#1}} -\def\getmacargs#1{\def\argl{#1}} - -% Parse the optional {params} list. Set up \paramno and \paramlist -% so \defmacro knows what to do. Define \macarg.blah for each blah -% in the params list, to be ##N where N is the position in that list. -% That gets used by \mbodybackslash (above). - -% We need to get `macro parameter char #' into several definitions. -% The technique used is stolen from LaTeX: let \hash be something -% unexpandable, insert that wherever you need a #, and then redefine -% it to # just before using the token list produced. -% -% The same technique is used to protect \eatspaces till just before -% the macro is used. - -\def\parsemargdef#1;{\paramno=0\def\paramlist{}% - \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,} -\def\parsemargdefxxx#1,{% - \if#1;\let\next=\relax - \else \let\next=\parsemargdefxxx - \advance\paramno by 1% - \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname - {\xeatspaces{\hash\the\paramno}}% - \edef\paramlist{\paramlist\hash\the\paramno,}% - \fi\next} - -% These two commands read recursive and nonrecursive macro bodies. -% (They're different since rec and nonrec macros end differently.) - -\long\def\parsemacbody#1@end macro% -{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}% -\long\def\parsermacbody#1@end rmacro% -{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}% - -% This defines the macro itself. There are six cases: recursive and -% nonrecursive macros of zero, one, and many arguments. -% Much magic with \expandafter here. -% \xdef is used so that macro definitions will survive the file -% they're defined in; @include reads the file inside a group. -\def\defmacro{% - \let\hash=##% convert placeholders to macro parameter chars - \ifrecursive - \ifcase\paramno - % 0 - \expandafter\xdef\csname\the\macname\endcsname{% - \noexpand\scanmacro{\temp}}% - \or % 1 - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\braceorline\csname\the\macname xxx\endcsname}% - \expandafter\xdef\csname\the\macname xxx\endcsname##1{% - \egroup\noexpand\scanmacro{\temp}}% - \else % many - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\csname\the\macname xx\endcsname} - \expandafter\xdef\csname\the\macname xx\endcsname##1{% - \csname\the\macname xxx\endcsname ##1,}% - \expandafter\expandafter - \expandafter\xdef - \expandafter\expandafter - \csname\the\macname xxx\endcsname - \paramlist{\egroup\noexpand\scanmacro{\temp}}% - \fi - \else - \ifcase\paramno - % 0 - \expandafter\xdef\csname\the\macname\endcsname{% - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \or % 1 - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\braceorline\csname\the\macname xxx\endcsname}% - \expandafter\xdef\csname\the\macname xxx\endcsname##1{% - \egroup - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \else % many - \expandafter\xdef\csname\the\macname\endcsname{% - \bgroup\noexpand\macroargctxt - \noexpand\csname\the\macname xx\endcsname} - \expandafter\xdef\csname\the\macname xx\endcsname##1{% - \csname\the\macname xxx\endcsname ##1,}% - \expandafter\expandafter - \expandafter\xdef - \expandafter\expandafter - \csname\the\macname xxx\endcsname - \paramlist{% - \egroup - \noexpand\norecurse{\the\macname}% - \noexpand\scanmacro{\temp}\egroup}% - \fi - \fi} - -\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}} - -% \braceorline decides whether the next nonwhitespace character is a -% {. If so it reads up to the closing }, if not, it reads the whole -% line. Whatever was read is then fed to the next control sequence -% as an argument (by \parsebrace or \parsearg) -\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx} -\def\braceorlinexxx{% - \ifx\nchar\bgroup\else - \expandafter\parsearg - \fi \next} - - -\message{cross references,} -\newwrite\auxfile - -\newif\ifhavexrefs % True if xref values are known. -\newif\ifwarnedxrefs % True if we warned once that they aren't known. - -% @inforef is relatively simple. -\def\inforef #1{\inforefzzz #1,,,,**} -\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}}, - node \samp{\ignorespaces#1{}}} - -% @node's job is to define \lastnode. -\def\node{\ENVcheck\parsearg\nodezzz} -\def\nodezzz#1{\nodexxx [#1,]} -\def\nodexxx[#1,#2]{\gdef\lastnode{#1}} -\let\nwnode=\node -\let\lastnode=\relax - -% The sectioning commands (@chapter, etc.) call these. -\def\donoderef{% - \ifx\lastnode\relax\else - \expandafter\expandafter\expandafter\setref{\lastnode}% - {Ysectionnumberandtype}% - \global\let\lastnode=\relax - \fi -} -\def\unnumbnoderef{% - \ifx\lastnode\relax\else - \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}% - \global\let\lastnode=\relax - \fi -} -\def\appendixnoderef{% - \ifx\lastnode\relax\else - \expandafter\expandafter\expandafter\setref{\lastnode}% - {Yappendixletterandtype}% - \global\let\lastnode=\relax - \fi -} - - -% @anchor{NAME} -- define xref target at arbitrary point. -% -\def\anchor#1{\setref{#1}{Ynothing}} - - -% \setref{NAME}{SNT} defines a cross-reference point NAME, namely -% NAME-title, NAME-pg, and NAME-SNT. Called from \foonoderef. We have -% to set \indexdummies so commands such as @code in a section title -% aren't expanded. It would be nicer not to expand the titles in the -% first place, but there's so many layers that that is hard to do. -% -\def\setref#1#2{{% - \indexdummies - \dosetq{#1-title}{Ytitle}% - \dosetq{#1-pg}{Ypagenumber}% - \dosetq{#1-snt}{#2} -}} - -% @xref, @pxref, and @ref generate cross-references. For \xrefX, #1 is -% the node name, #2 the name of the Info cross-reference, #3 the printed -% node name, #4 the name of the Info file, #5 the name of the printed -% manual. All but the node name can be omitted. -% -\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]} -\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]} -\def\ref#1{\xrefX[#1,,,,,,,]} -\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup - \def\printedmanual{\ignorespaces #5}% - \def\printednodename{\ignorespaces #3}% - \setbox1=\hbox{\printedmanual}% - \setbox0=\hbox{\printednodename}% - \ifdim \wd0 = 0pt - % No printed node name was explicitly given. - \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax - % Use the node name inside the square brackets. - \def\printednodename{\ignorespaces #1}% - \else - % Use the actual chapter/section title appear inside - % the square brackets. Use the real section title if we have it. - \ifdim \wd1 > 0pt - % It is in another manual, so we don't have it. - \def\printednodename{\ignorespaces #1}% - \else - \ifhavexrefs - % We know the real title if we have the xref values. - \def\printednodename{\refx{#1-title}{}}% - \else - % Otherwise just copy the Info node name. - \def\printednodename{\ignorespaces #1}% - \fi% - \fi - \fi - \fi - % - % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not - % insert empty discretionaries after hyphens, which means that it will - % not find a line break at a hyphen in a node names. Since some manuals - % are best written with fairly long node names, containing hyphens, this - % is a loss. Therefore, we give the text of the node name again, so it - % is as if TeX is seeing it for the first time. - \ifdim \wd1 > 0pt - \putwordsection{} ``\printednodename'' in \cite{\printedmanual}% - \else - % _ (for example) has to be the character _ for the purposes of the - % control sequence corresponding to the node, but it has to expand - % into the usual \leavevmode...\vrule stuff for purposes of - % printing. So we \turnoffactive for the \refx-snt, back on for the - % printing, back off for the \refx-pg. - {\normalturnoffactive - % Only output a following space if the -snt ref is nonempty; for - % @unnumbered and @anchor, it won't be. - \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}% - \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi - }% - % [mynode], - [\printednodename],\space - % page 3 - \turnoffactive \putwordpage\tie\refx{#1-pg}{}% - \fi -\endgroup} - -% \dosetq is the interface for calls from other macros - -% Use \normalturnoffactive so that punctuation chars such as underscore -% and backslash work in node names. (\turnoffactive doesn't do \.) -\def\dosetq#1#2{% - {\let\folio=0 - \normalturnoffactive - \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}% - \iflinks - \next - \fi - }% -} - -% \internalsetq {foo}{page} expands into -% CHARACTERS 'xrdef {foo}{...expansion of \Ypage...} -% When the aux file is read, ' is the escape character - -\def\internalsetq #1#2{'xrdef {#1}{\csname #2\endcsname}} - -% Things to be expanded by \internalsetq - -\def\Ypagenumber{\folio} - -\def\Ytitle{\thissection} - -\def\Ynothing{} - -\def\Ysectionnumberandtype{% -\ifnum\secno=0 \putwordChapter\xreftie\the\chapno % -\else \ifnum \subsecno=0 \putwordSection\xreftie\the\chapno.\the\secno % -\else \ifnum \subsubsecno=0 % -\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno % -\else % -\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno % -\fi \fi \fi } - -\def\Yappendixletterandtype{% -\ifnum\secno=0 \putwordAppendix\xreftie'char\the\appendixno{}% -\else \ifnum \subsecno=0 \putwordSection\xreftie'char\the\appendixno.\the\secno % -\else \ifnum \subsubsecno=0 % -\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno % -\else % -\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno % -\fi \fi \fi } - -\gdef\xreftie{'tie} - -% Use TeX 3.0's \inputlineno to get the line number, for better error -% messages, but if we're using an old version of TeX, don't do anything. -% -\ifx\inputlineno\thisisundefined - \let\linenumber = \empty % Non-3.0. -\else - \def\linenumber{\the\inputlineno:\space} -\fi - -% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME. -% If its value is nonempty, SUFFIX is output afterward. - -\def\refx#1#2{% - \expandafter\ifx\csname X#1\endcsname\relax - % If not defined, say something at least. - \angleleft un\-de\-fined\angleright - \iflinks - \ifhavexrefs - \message{\linenumber Undefined cross reference `#1'.}% - \else - \ifwarnedxrefs\else - \global\warnedxrefstrue - \message{Cross reference values unknown; you must run TeX again.}% - \fi - \fi - \fi - \else - % It's defined, so just use it. - \csname X#1\endcsname - \fi - #2% Output the suffix in any case. -} - -% This is the macro invoked by entries in the aux file. -% -\def\xrdef#1{\begingroup - % Reenable \ as an escape while reading the second argument. - \catcode`\\ = 0 - \afterassignment\endgroup - \expandafter\gdef\csname X#1\endcsname -} - -% Read the last existing aux file, if any. No error if none exists. -\def\readauxfile{\begingroup - \catcode`\^^@=\other - \catcode`\^^A=\other - \catcode`\^^B=\other - \catcode`\^^C=\other - \catcode`\^^D=\other - \catcode`\^^E=\other - \catcode`\^^F=\other - \catcode`\^^G=\other - \catcode`\^^H=\other - \catcode`\^^K=\other - \catcode`\^^L=\other - \catcode`\^^N=\other - \catcode`\^^P=\other - \catcode`\^^Q=\other - \catcode`\^^R=\other - \catcode`\^^S=\other - \catcode`\^^T=\other - \catcode`\^^U=\other - \catcode`\^^V=\other - \catcode`\^^W=\other - \catcode`\^^X=\other - \catcode`\^^Z=\other - \catcode`\^^[=\other - \catcode`\^^\=\other - \catcode`\^^]=\other - \catcode`\^^^=\other - \catcode`\^^_=\other - \catcode`\@=\other - \catcode`\^=\other - % It was suggested to define this as 7, which would allow ^^e4 etc. - % in xref tags, i.e., node names. But since ^^e4 notation isn't - % supported in the main text, it doesn't seem desirable. Furthermore, - % that is not enough: for node names that actually contain a ^ - % character, we would end up writing a line like this: 'xrdef {'hat - % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first - % argument, and \hat is not an expandable control sequence. It could - % all be worked out, but why? Either we support ^^ or we don't. - % - % The other change necessary for this was to define \auxhat: - % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter - % and then to call \auxhat in \setq. - % - \catcode`\~=\other - \catcode`\[=\other - \catcode`\]=\other - \catcode`\"=\other - \catcode`\_=\other - \catcode`\|=\other - \catcode`\<=\other - \catcode`\>=\other - \catcode`\$=\other - \catcode`\#=\other - \catcode`\&=\other - \catcode`+=\other % avoid \+ for paranoia even though we've turned it off - % Make the characters 128-255 be printing characters - {% - \count 1=128 - \def\loop{% - \catcode\count 1=\other - \advance\count 1 by 1 - \ifnum \count 1<256 \loop \fi - }% - }% - % The aux file uses ' as the escape (for now). - % Turn off \ as an escape so we do not lose on - % entries which were dumped with control sequences in their names. - % For example, 'xrdef {$\leq $-fun}{page ...} made by @defun ^^ - % Reference to such entries still does not work the way one would wish, - % but at least they do not bomb out when the aux file is read in. - \catcode`\{=1 - \catcode`\}=2 - \catcode`\%=\other - \catcode`\'=0 - \catcode`\\=\other - % - \openin 1 \jobname.aux - \ifeof 1 \else - \closein 1 - \input \jobname.aux - \global\havexrefstrue - \global\warnedobstrue - \fi - % Open the new aux file. TeX will close it automatically at exit. - \openout\auxfile=\jobname.aux -\endgroup} - - -% Footnotes. - -\newcount \footnoteno - -% The trailing space in the following definition for supereject is -% vital for proper filling; pages come out unaligned when you do a -% pagealignmacro call if that space before the closing brace is -% removed. (Generally, numeric constants should always be followed by a -% space to prevent strange expansion errors.) -\def\supereject{\par\penalty -20000\footnoteno =0 } - -% @footnotestyle is meaningful for info output only. -\let\footnotestyle=\comment - -\let\ptexfootnote=\footnote - -{\catcode `\@=11 -% -% Auto-number footnotes. Otherwise like plain. -\gdef\footnote{% - \global\advance\footnoteno by \@ne - \edef\thisfootno{$^{\the\footnoteno}$}% - % - % In case the footnote comes at the end of a sentence, preserve the - % extra spacing after we do the footnote number. - \let\@sf\empty - \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi - % - % Remove inadvertent blank space before typesetting the footnote number. - \unskip - \thisfootno\@sf - \footnotezzz -}% - -% Don't bother with the trickery in plain.tex to not require the -% footnote text as a parameter. Our footnotes don't need to be so general. -% -% Oh yes, they do; otherwise, @ifset and anything else that uses -% \parseargline fail inside footnotes because the tokens are fixed when -% the footnote is read. --karl, 16nov96. -% -\long\gdef\footnotezzz{\insert\footins\bgroup - % We want to typeset this text as a normal paragraph, even if the - % footnote reference occurs in (for example) a display environment. - % So reset some parameters. - \interlinepenalty\interfootnotelinepenalty - \splittopskip\ht\strutbox % top baseline for broken footnotes - \splitmaxdepth\dp\strutbox - \floatingpenalty\@MM - \leftskip\z@skip - \rightskip\z@skip - \spaceskip\z@skip - \xspaceskip\z@skip - \parindent\defaultparindent - % - % Hang the footnote text off the number. - \hang - \textindent{\thisfootno}% - % - % Don't crash into the line above the footnote text. Since this - % expands into a box, it must come within the paragraph, lest it - % provide a place where TeX can split the footnote. - \footstrut - \futurelet\next\fo@t -} -\def\fo@t{\ifcat\bgroup\noexpand\next \let\next\f@@t - \else\let\next\f@t\fi \next} -\def\f@@t{\bgroup\aftergroup\@foot\let\next} -\def\f@t#1{#1\@foot} -\def\@foot{\strut\egroup} - -}%end \catcode `\@=11 - -% Set the baselineskip to #1, and the lineskip and strut size -% correspondingly. There is no deep meaning behind these magic numbers -% used as factors; they just match (closely enough) what Knuth defined. -% -\def\lineskipfactor{.08333} -\def\strutheightpercent{.70833} -\def\strutdepthpercent {.29167} -% -\def\setleading#1{% - \normalbaselineskip = #1\relax - \normallineskip = \lineskipfactor\normalbaselineskip - \normalbaselines - \setbox\strutbox =\hbox{% - \vrule width0pt height\strutheightpercent\baselineskip - depth \strutdepthpercent \baselineskip - }% -} - -% @| inserts a changebar to the left of the current line. It should -% surround any changed text. This approach does *not* work if the -% change spans more than two lines of output. To handle that, we would -% have adopt a much more difficult approach (putting marks into the main -% vertical list for the beginning and end of each change). -% -\def\|{% - % \vadjust can only be used in horizontal mode. - \leavevmode - % - % Append this vertical mode material after the current line in the output. - \vadjust{% - % We want to insert a rule with the height and depth of the current - % leading; that is exactly what \strutbox is supposed to record. - \vskip-\baselineskip - % - % \vadjust-items are inserted at the left edge of the type. So - % the \llap here moves out into the left-hand margin. - \llap{% - % - % For a thicker or thinner bar, change the `1pt'. - \vrule height\baselineskip width1pt - % - % This is the space between the bar and the text. - \hskip 12pt - }% - }% -} - -% For a final copy, take out the rectangles -% that mark overfull boxes (in case you have decided -% that the text looks ok even though it passes the margin). -% -\def\finalout{\overfullrule=0pt} - -% @image. We use the macros from epsf.tex to support this. -% If epsf.tex is not installed and @image is used, we complain. -% -% Check for and read epsf.tex up front. If we read it only at @image -% time, we might be inside a group, and then its definitions would get -% undone and the next image would fail. -\openin 1 = epsf.tex -\ifeof 1 \else - \closein 1 - % Do not bother showing banner with post-v2.7 epsf.tex (available in - % doc/epsf.tex until it shows up on ctan). - \def\epsfannounce{\toks0 = }% - \input epsf.tex -\fi -% -\newif\ifwarnednoepsf -\newhelp\noepsfhelp{epsf.tex must be installed for images to - work. It is also included in the Texinfo distribution, or you can get - it from ftp://ftp.tug.org/tex/epsf.tex.} -% -% Only complain once about lack of epsf.tex. -\def\image#1{% - \ifx\epsfbox\undefined - \ifwarnednoepsf \else - \errhelp = \noepsfhelp - \errmessage{epsf.tex not found, images will be ignored}% - \global\warnednoepsftrue - \fi - \else - \imagexxx #1,,,\finish - \fi -} -% -% Arguments to @image: -% #1 is (mandatory) image filename; we tack on .eps extension. -% #2 is (optional) width, #3 is (optional) height. -% #4 is just the usual extra ignored arg for parsing this stuff. -\def\imagexxx#1,#2,#3,#4\finish{% - % \epsfbox itself resets \epsf?size at each figure. - \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi - \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi - % If the image is by itself, center it. - \ifvmode - \nobreak\medskip - \nobreak - \centerline{\epsfbox{#1.eps}}% - \bigbreak - \else - \epsfbox{#1.eps}% - \fi -} - - -\message{paper sizes,} -% And other related parameters. - -\newdimen\defaultparindent \defaultparindent = 15pt - -\chapheadingskip = 15pt plus 4pt minus 2pt -\secheadingskip = 12pt plus 3pt minus 2pt -\subsecheadingskip = 9pt plus 2pt minus 2pt - -% Prevent underfull vbox error messages. -\vbadness = 10000 - -% Don't be so finicky about underfull hboxes, either. -\hbadness = 2000 - -% Following George Bush, just get rid of widows and orphans. -\widowpenalty=10000 -\clubpenalty=10000 - -% Use TeX 3.0's \emergencystretch to help line breaking, but if we're -% using an old version of TeX, don't do anything. We want the amount of -% stretch added to depend on the line length, hence the dependence on -% \hsize. This makes it come to about 9pt for the 8.5x11 format. We -% call this whenever the paper size is set. -% -\def\setemergencystretch{% - \ifx\emergencystretch\thisisundefined - % Allow us to assign to \emergencystretch anyway. - \def\emergencystretch{\dimen0}% - \else - \emergencystretch = \hsize - \divide\emergencystretch by 45 - \fi -} - -% Parameters in order: 1) textheight; 2) textwidth; 3) voffset; -% 4) hoffset; 5) binding offset; 6) topskip. Then whoever calls us can -% set \parskip and call \setleading for \baselineskip. -% -\def\internalpagesizes#1#2#3#4#5#6{% - \voffset = #3\relax - \topskip = #6\relax - \splittopskip = \topskip - % - \vsize = #1\relax - \advance\vsize by \topskip - \outervsize = \vsize - \advance\outervsize by 2\topandbottommargin - \pageheight = \vsize - % - \hsize = #2\relax - \outerhsize = \hsize - \advance\outerhsize by 0.5in - \pagewidth = \hsize - % - \normaloffset = #4\relax - \bindingoffset = #5\relax - % - \parindent = \defaultparindent - \setemergencystretch -} - -% @letterpaper (the default). -\def\letterpaper{{\globaldefs = 1 - \parskip = 3pt plus 2pt minus 1pt - \setleading{13.2pt}% - % - % If page is nothing but text, make it come out even. - \internalpagesizes{46\baselineskip}{6in}{\voffset}{.25in}{\bindingoffset}{36pt}% -}} - -% Use @smallbook to reset parameters for 7x9.5 (or so) format. -\def\smallbook{{\globaldefs = 1 - \parskip = 2pt plus 1pt - \setleading{12pt}% - % - \internalpagesizes{7.5in}{5.in}{\voffset}{.25in}{\bindingoffset}{16pt}% - % - \lispnarrowing = 0.3in - \tolerance = 700 - \hfuzz = 1pt - \contentsrightmargin = 0pt - \deftypemargin = 0pt - \defbodyindent = .5cm - % - \let\smalldisplay = \smalldisplayx - \let\smallexample = \smalllispx - \let\smallformat = \smallformatx - \let\smalllisp = \smalllispx -}} - -% Use @afourpaper to print on European A4 paper. -\def\afourpaper{{\globaldefs = 1 - \setleading{12pt}% - \parskip = 3pt plus 2pt minus 1pt - % - \internalpagesizes{53\baselineskip}{160mm}{\voffset}{4mm}{\bindingoffset}{44pt}% - % - \tolerance = 700 - \hfuzz = 1pt -}} - -% A specific text layout, 24x15cm overall, intended for A4 paper. Top margin -% 29mm, hence bottom margin 28mm, nominal side margin 3cm. -\def\afourlatex{{\globaldefs = 1 - \setleading{13.6pt}% - % - \afourpaper - \internalpagesizes{237mm}{150mm}{3.6mm}{3.6mm}{3mm}{7mm}% - % - \globaldefs = 0 -}} - -% Use @afourwide to print on European A4 paper in wide format. -\def\afourwide{% - \afourpaper - \internalpagesizes{9.5in}{6.5in}{\hoffset}{\normaloffset}{\bindingoffset}{7mm}% - % - \globaldefs = 0 -} - -% @pagesizes TEXTHEIGHT[,TEXTWIDTH] -% Perhaps we should allow setting the margins, \topskip, \parskip, -% and/or leading, also. Or perhaps we should compute them somehow. -% -\def\pagesizes{\parsearg\pagesizesxxx} -\def\pagesizesxxx#1{\pagesizesyyy #1,,\finish} -\def\pagesizesyyy#1,#2,#3\finish{{% - \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi - \globaldefs = 1 - % - \parskip = 3pt plus 2pt minus 1pt - \setleading{13.2pt}% - % - \internalpagesizes{#1}{\hsize}{\voffset}{\normaloffset}{\bindingoffset}{44pt}% -}} - -% Set default to letter. -% -\letterpaper - -\message{and turning on texinfo input format.} - -% Define macros to output various characters with catcode for normal text. -\catcode`\"=\other -\catcode`\~=\other -\catcode`\^=\other -\catcode`\_=\other -\catcode`\|=\other -\catcode`\<=\other -\catcode`\>=\other -\catcode`\+=\other -\def\normaldoublequote{"} -\def\normaltilde{~} -\def\normalcaret{^} -\def\normalunderscore{_} -\def\normalverticalbar{|} -\def\normalless{<} -\def\normalgreater{>} -\def\normalplus{+} - -% This macro is used to make a character print one way in ttfont -% where it can probably just be output, and another way in other fonts, -% where something hairier probably needs to be done. -% -% #1 is what to print if we are indeed using \tt; #2 is what to print -% otherwise. Since all the Computer Modern typewriter fonts have zero -% interword stretch (and shrink), and it is reasonable to expect all -% typewriter fonts to have this, we can check that font parameter. -% -\def\ifusingtt#1#2{\ifdim \fontdimen3\the\font=0pt #1\else #2\fi} - -% Turn off all special characters except @ -% (and those which the user can use as if they were ordinary). -% Most of these we simply print from the \tt font, but for some, we can -% use math or other variants that look better in normal text. - -\catcode`\"=\active -\def\activedoublequote{{\tt\char34}} -\let"=\activedoublequote -\catcode`\~=\active -\def~{{\tt\char126}} -\chardef\hat=`\^ -\catcode`\^=\active -\def^{{\tt \hat}} - -\catcode`\_=\active -\def_{\ifusingtt\normalunderscore\_} -% Subroutine for the previous macro. -\def\_{\leavevmode \kern.06em \vbox{\hrule width.3em height.1ex}} - -\catcode`\|=\active -\def|{{\tt\char124}} -\chardef \less=`\< -\catcode`\<=\active -\def<{{\tt \less}} -\chardef \gtr=`\> -\catcode`\>=\active -\def>{{\tt \gtr}} -\catcode`\+=\active -\def+{{\tt \char 43}} -%\catcode 27=\active -%\def^^[{$\diamondsuit$} - -% Set up an active definition for =, but don't enable it most of the time. -{\catcode`\==\active -\global\def={{\tt \char 61}}} - -\catcode`+=\active -\catcode`\_=\active - -% If a .fmt file is being used, characters that might appear in a file -% name cannot be active until we have parsed the command line. -% So turn them off again, and have \everyjob (or @setfilename) turn them on. -% \otherifyactive is called near the end of this file. -\def\otherifyactive{\catcode`+=\other \catcode`\_=\other} - -\catcode`\@=0 - -% \rawbackslashxx output one backslash character in current font -\global\chardef\rawbackslashxx=`\\ -%{\catcode`\\=\other -%@gdef@rawbackslashxx{\}} - -% \rawbackslash redefines \ as input to do \rawbackslashxx. -{\catcode`\\=\active -@gdef@rawbackslash{@let\=@rawbackslashxx }} - -% \normalbackslash outputs one backslash in fixed width font. -\def\normalbackslash{{\tt\rawbackslashxx}} - -% Say @foo, not \foo, in error messages. -\escapechar=`\@ - -% \catcode 17=0 % Define control-q -\catcode`\\=\active - -% Used sometimes to turn off (effectively) the active characters -% even after parsing them. -@def@turnoffactive{@let"=@normaldoublequote -@let\=@realbackslash -@let~=@normaltilde -@let^=@normalcaret -@let_=@normalunderscore -@let|=@normalverticalbar -@let<=@normalless -@let>=@normalgreater -@let+=@normalplus} - -@def@normalturnoffactive{@let"=@normaldoublequote -@let\=@normalbackslash -@let~=@normaltilde -@let^=@normalcaret -@let_=@normalunderscore -@let|=@normalverticalbar -@let<=@normalless -@let>=@normalgreater -@let+=@normalplus} - -% Make _ and + \other characters, temporarily. -% This is canceled by @fixbackslash. -@otherifyactive - -% If a .fmt file is being used, we don't want the `\input texinfo' to show up. -% That is what \eatinput is for; after that, the `\' should revert to printing -% a backslash. -% -@gdef@eatinput input texinfo{@fixbackslash} -@global@let\ = @eatinput - -% On the other hand, perhaps the file did not have a `\input texinfo'. Then -% the first `\{ in the file would cause an error. This macro tries to fix -% that, assuming it is called before the first `\' could plausibly occur. -% Also back turn on active characters that might appear in the input -% file name, in case not using a pre-dumped format. -% -@gdef@fixbackslash{@ifx\@eatinput @let\ = @normalbackslash @fi - @catcode`+=@active @catcode`@_=@active} - -% These look ok in all fonts, so just make them not special. The @rm below -% makes sure that the current font starts out as the newly loaded cmr10 -@catcode`@$=@other @catcode`@%=@other @catcode`@&=@other @catcode`@#=@other - -@textfonts -@rm - -@c Local variables: -@c eval: (add-hook 'write-file-hooks 'time-stamp) -@c page-delimiter: "^\\\\message" -@c time-stamp-start: "def\\\\texinfoversion{" -@c time-stamp-format: "%:y-%02m-%02d" -@c time-stamp-end: "}" -@c End: diff --git a/lsh/src/nettle/twofish.c b/lsh/src/nettle/twofish.c deleted file mode 100644 index 2a341e8..0000000 --- a/lsh/src/nettle/twofish.c +++ /dev/null @@ -1,459 +0,0 @@ -/* twofish.c - * - * The twofish block cipher. - */ - -/* twofish - An implementation of the twofish cipher. - * Copyright (C) 1999 Ruud de Rooij - * - * Modifications for lsh, integrated testing - * Copyright (C) 1999 J.H.M. Dassen (Ray) - * - * Integrated with the nettle library, - * Copyright (C) 2001 Niels Möller - */ - -/* nettle, low-level cryptographics library - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle Library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -#include "twofish.h" - -#include "macros.h" - -#include -#include - -/* Bitwise rotations on 32-bit words. These are defined as macros that - * evaluate their argument twice, so do not apply to any expressions with - * side effects. - */ - -#define rol1(x) (((x) << 1) | (((x) & 0x80000000) >> 31)) -#define rol8(x) (((x) << 8) | (((x) & 0xFF000000) >> 24)) -#define rol9(x) (((x) << 9) | (((x) & 0xFF800000) >> 23)) -#define ror1(x) (((x) >> 1) | (((x) & 0x00000001) << 31)) - -/* ------------------------------------------------------------------------- */ - -/* The permutations q0 and q1. These are fixed permutations on 8-bit values. - * The permutations have been computed using the program generate_q - * which is distributed along with this file. - */ - -static const uint8_t q0[] = { 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, - 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, - 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, - 0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, - 0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23, - 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82, - 0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, - 0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61, - 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B, - 0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, - 0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66, - 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7, - 0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, - 0xEA, 0x77, 0x39, 0xAF, 0x33, 0xC9, 0x62, 0x71, - 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8, - 0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, - 0xA1, 0x1D, 0xAA, 0xED, 0x06, 0x70, 0xB2, 0xD2, - 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90, - 0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, - 0x9E, 0x9C, 0x52, 0x1B, 0x5F, 0x93, 0x0A, 0xEF, - 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B, - 0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, - 0x2A, 0xCE, 0xCB, 0x2F, 0xFC, 0x97, 0x05, 0x7A, - 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A, - 0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, - 0xB8, 0xDA, 0xB0, 0x17, 0x55, 0x1F, 0x8A, 0x7D, - 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72, - 0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, - 0x6E, 0x50, 0xDE, 0x68, 0x65, 0xBC, 0xDB, 0xF8, - 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4, - 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, - 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0, }; - -static const uint8_t q1[] = { 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, - 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, - 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, - 0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, - 0x5E, 0xBA, 0xAE, 0x5B, 0x8A, 0x00, 0xBC, 0x9D, - 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5, - 0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, - 0xB2, 0x73, 0x4C, 0x54, 0x92, 0x74, 0x36, 0x51, - 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96, - 0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, - 0x13, 0x95, 0x9C, 0xC7, 0x24, 0x46, 0x3B, 0x70, - 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8, - 0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, - 0x03, 0x6F, 0x08, 0xBF, 0x40, 0xE7, 0x2B, 0xE2, - 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9, - 0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, - 0x66, 0x94, 0xA1, 0x1D, 0x3D, 0xF0, 0xDE, 0xB3, - 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E, - 0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, - 0x81, 0x88, 0xEE, 0x21, 0xC4, 0x1A, 0xEB, 0xD9, - 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01, - 0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, - 0x4F, 0xF2, 0x65, 0x8E, 0x78, 0x5C, 0x58, 0x19, - 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64, - 0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, - 0xCE, 0xE9, 0x68, 0x44, 0xE0, 0x4D, 0x43, 0x69, - 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E, - 0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, - 0x22, 0xC9, 0xC0, 0x9B, 0x89, 0xD4, 0xED, 0xAB, - 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9, - 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, - 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91, }; - -/* ------------------------------------------------------------------------- */ - -/* uint8_t gf_multiply(uint8_t p, uint8_t a, uint8_t b) - * - * Multiplication in GF(2^8). - * - * This function multiplies a times b in the Galois Field GF(2^8) with - * primitive polynomial p. - * The representation of the polynomials a, b, and p uses bits with - * values 2^i to represent the terms x^i. The polynomial p contains an - * implicit term x^8. - * - * Note that addition and subtraction in GF(2^8) is simply the XOR - * operation. - */ - -static uint8_t -gf_multiply(uint8_t p, uint8_t a, uint8_t b) -{ - uint32_t shift = b; - uint8_t result = 0; - while (a) - { - if (a & 1) result ^= shift; - a = a >> 1; - shift = shift << 1; - if (shift & 0x100) shift ^= p; - } - return result; -} - -/* ------------------------------------------------------------------------- */ - -/* The matrix RS as specified in section 4.3 the twofish paper. */ - -static const uint8_t rs_matrix[4][8] = { - { 0x01, 0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E }, - { 0xA4, 0x56, 0x82, 0xF3, 0x1E, 0xC6, 0x68, 0xE5 }, - { 0x02, 0xA1, 0xFC, 0xC1, 0x47, 0xAE, 0x3D, 0x19 }, - { 0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E, 0x03 } }; - -/* uint32_t compute_s(uint32_t m1, uint32_t m2); - * - * Computes the value RS * M, where M is a byte vector composed of the - * bytes of m1 and m2. Arithmetic is done in GF(2^8) with primitive - * polynomial x^8 + x^6 + x^3 + x^2 + 1. - * - * This function is used to compute the sub-keys S which are in turn used - * to generate the S-boxes. - */ - -static uint32_t -compute_s(uint32_t m1, uint32_t m2) -{ - uint32_t s = 0; - int i; - for (i = 0; i < 4; i++) - s |= (( gf_multiply(0x4D, m1, rs_matrix[i][0]) - ^ gf_multiply(0x4D, m1 >> 8, rs_matrix[i][1]) - ^ gf_multiply(0x4D, m1 >> 16, rs_matrix[i][2]) - ^ gf_multiply(0x4D, m1 >> 24, rs_matrix[i][3]) - ^ gf_multiply(0x4D, m2, rs_matrix[i][4]) - ^ gf_multiply(0x4D, m2 >> 8, rs_matrix[i][5]) - ^ gf_multiply(0x4D, m2 >> 16, rs_matrix[i][6]) - ^ gf_multiply(0x4D, m2 >> 24, rs_matrix[i][7])) << (i*8)); - return s; -} - -/* ------------------------------------------------------------------------- */ - -/* This table describes which q S-boxes are used for each byte in each stage - * of the function h, cf. figure 2 of the twofish paper. - */ - -static const uint8_t * q_table[4][5] = { { q1, q1, q0, q0, q1 }, - { q0, q1, q1, q0, q0 }, - { q0, q0, q0, q1, q1 }, - { q1, q0, q1, q1, q0 } }; - -/* The matrix MDS as specified in section 4.3.2 of the twofish paper. */ - -static const uint8_t mds_matrix[4][4] = { { 0x01, 0xEF, 0x5B, 0x5B }, - { 0x5B, 0xEF, 0xEF, 0x01 }, - { 0xEF, 0x5B, 0x01, 0xEF }, - { 0xEF, 0x01, 0xEF, 0x5B } }; - -/* uint32_t h_uint8_t(int k, int i, uint8_t x, uint8_t l0, uint8_t l1, uint8_t l2, uint8_t l3); - * - * Perform the h function (section 4.3.2) on one byte. It consists of - * repeated applications of the q permutation, followed by a XOR with - * part of a sub-key. Finally, the value is multiplied by one column of - * the MDS matrix. To obtain the result for a full word, the results of - * h for the individual bytes are XORed. - * - * k is the key size (/ 64 bits), i is the byte number (0 = LSB), x is the - * actual byte to apply the function to; l0, l1, l2, and l3 are the - * appropriate bytes from the subkey. Note that only l0..l(k-1) are used. - */ - -static uint32_t -h_byte(int k, int i, uint8_t x, uint8_t l0, uint8_t l1, uint8_t l2, uint8_t l3) -{ - uint8_t y = q_table[i][4][l0 ^ - q_table[i][3][l1 ^ - q_table[i][2][k == 2 ? x : l2 ^ - q_table[i][1][k == 3 ? x : l3 ^ q_table[i][0][x]]]]]; - - return ( ((uint32_t)gf_multiply(0x69, mds_matrix[0][i], y)) - | ((uint32_t)gf_multiply(0x69, mds_matrix[1][i], y) << 8) - | ((uint32_t)gf_multiply(0x69, mds_matrix[2][i], y) << 16) - | ((uint32_t)gf_multiply(0x69, mds_matrix[3][i], y) << 24) ); -} - -/* uint32_t h(int k, uint8_t x, uint32_t l0, uint32_t l1, uint32_t l2, uint32_t l3); - * - * Perform the function h on a word. See the description of h_byte() above. - */ - -static uint32_t -h(int k, uint8_t x, uint32_t l0, uint32_t l1, uint32_t l2, uint32_t l3) -{ - return ( h_byte(k, 0, x, l0, l1, l2, l3) - ^ h_byte(k, 1, x, l0 >> 8, l1 >> 8, l2 >> 8, l3 >> 8) - ^ h_byte(k, 2, x, l0 >> 16, l1 >> 16, l2 >> 16, l3 >> 16) - ^ h_byte(k, 3, x, l0 >> 24, l1 >> 24, l2 >> 24, l3 >> 24) ); -} - - -/* ------------------------------------------------------------------------- */ - -/* API */ - -/* Structure which contains the tables containing the subkeys and the - * key-dependent s-boxes. - */ - - -/* Set up internal tables required for twofish encryption and decryption. - * - * The key size is specified in bytes. Key sizes up to 32 bytes are - * supported. Larger key sizes are silently truncated. - */ - -void -twofish_set_key(struct twofish_ctx *context, - unsigned keysize, const uint8_t *key) -{ - uint8_t key_copy[32]; - uint32_t m[8], s[4], t; - int i, j, k; - - /* Extend key as necessary */ - - assert(keysize <= 32); - - /* We do a little more copying than necessary, but that doesn't - * really matter. */ - memset(key_copy, 0, 32); - memcpy(key_copy, key, keysize); - - for (i = 0; i<8; i++) - m[i] = LE_READ_UINT32(key_copy + i*4); - - if (keysize <= 16) - k = 2; - else if (keysize <= 24) - k = 3; - else - k = 4; - - /* Compute sub-keys */ - - for (i = 0; i < 20; i++) - { - t = h(k, 2*i+1, m[1], m[3], m[5], m[7]); - t = rol8(t); - t += (context->keys[2*i] = - t + h(k, 2*i, m[0], m[2], m[4], m[6])); - t = rol9(t); - context->keys[2*i+1] = t; - } - - /* Compute key-dependent S-boxes */ - - for (i = 0; i < k; i++) - s[k-1-i] = compute_s(m[2*i], m[2*i+1]); - - for (i = 0; i < 4; i++) - for (j = 0; j < 256; j++) - context->s_box[i][j] = h_byte(k, i, j, - s[0] >> (i*8), - s[1] >> (i*8), - s[2] >> (i*8), - s[3] >> (i*8)); -} - -/* Encrypt blocks of 16 bytes of data with the twofish algorithm. - * - * Before this function can be used, twofish_set_key() must be used in order to - * set up various tables required for the encryption algorithm. - * - * This function always encrypts 16 bytes of plaintext to 16 bytes of - * ciphertext. The memory areas of the plaintext and the ciphertext can - * overlap. - */ - -void -twofish_encrypt(struct twofish_ctx *context, - unsigned length, - uint8_t *ciphertext, - const uint8_t *plaintext) -{ - uint32_t * keys = context->keys; - uint32_t (*s_box)[256] = context->s_box; - - assert( !(length % TWOFISH_BLOCK_SIZE) ); - for ( ; length; length -= TWOFISH_BLOCK_SIZE) - { - uint32_t words[4]; - uint32_t r0, r1, r2, r3, t0, t1; - int i; - - for (i = 0; i<4; i++, plaintext += 4) - words[i] = LE_READ_UINT32(plaintext); - - r0 = words[0] ^ keys[0]; - r1 = words[1] ^ keys[1]; - r2 = words[2] ^ keys[2]; - r3 = words[3] ^ keys[3]; - - for (i = 0; i < 8; i++) { - t1 = ( s_box[1][r1 & 0xFF] - ^ s_box[2][(r1 >> 8) & 0xFF] - ^ s_box[3][(r1 >> 16) & 0xFF] - ^ s_box[0][(r1 >> 24) & 0xFF]); - t0 = ( s_box[0][r0 & 0xFF] - ^ s_box[1][(r0 >> 8) & 0xFF] - ^ s_box[2][(r0 >> 16) & 0xFF] - ^ s_box[3][(r0 >> 24) & 0xFF]) + t1; - r3 = (t1 + t0 + keys[4*i+9]) ^ rol1(r3); - r2 = (t0 + keys[4*i+8]) ^ r2; - r2 = ror1(r2); - - t1 = ( s_box[1][r3 & 0xFF] - ^ s_box[2][(r3 >> 8) & 0xFF] - ^ s_box[3][(r3 >> 16) & 0xFF] - ^ s_box[0][(r3 >> 24) & 0xFF]); - t0 = ( s_box[0][r2 & 0xFF] - ^ s_box[1][(r2 >> 8) & 0xFF] - ^ s_box[2][(r2 >> 16) & 0xFF] - ^ s_box[3][(r2 >> 24) & 0xFF]) + t1; - r1 = (t1 + t0 + keys[4*i+11]) ^ rol1(r1); - r0 = (t0 + keys[4*i+10]) ^ r0; - r0 = ror1(r0); - } - - words[0] = r2 ^ keys[4]; - words[1] = r3 ^ keys[5]; - words[2] = r0 ^ keys[6]; - words[3] = r1 ^ keys[7]; - - for (i = 0; i<4; i++, ciphertext += 4) - LE_WRITE_UINT32(ciphertext, words[i]); - } -} - -/* Decrypt blocks of 16 bytes of data with the twofish algorithm. - * - * Before this function can be used, twofish_set_key() must be used in order to - * set up various tables required for the decryption algorithm. - * - * This function always decrypts 16 bytes of ciphertext to 16 bytes of - * plaintext. The memory areas of the plaintext and the ciphertext can - * overlap. - */ - -void -twofish_decrypt(struct twofish_ctx *context, - unsigned length, - uint8_t *plaintext, - const uint8_t *ciphertext) - -{ - uint32_t *keys = context->keys; - uint32_t (*s_box)[256] = context->s_box; - - assert( !(length % TWOFISH_BLOCK_SIZE) ); - for ( ; length; length -= TWOFISH_BLOCK_SIZE) - { - uint32_t words[4]; - uint32_t r0, r1, r2, r3, t0, t1; - int i; - - for (i = 0; i<4; i++, ciphertext += 4) - words[i] = LE_READ_UINT32(ciphertext); - - r0 = words[2] ^ keys[6]; - r1 = words[3] ^ keys[7]; - r2 = words[0] ^ keys[4]; - r3 = words[1] ^ keys[5]; - - for (i = 0; i < 8; i++) { - t1 = ( s_box[1][r3 & 0xFF] - ^ s_box[2][(r3 >> 8) & 0xFF] - ^ s_box[3][(r3 >> 16) & 0xFF] - ^ s_box[0][(r3 >> 24) & 0xFF]); - t0 = ( s_box[0][r2 & 0xFF] - ^ s_box[1][(r2 >> 8) & 0xFF] - ^ s_box[2][(r2 >> 16) & 0xFF] - ^ s_box[3][(r2 >> 24) & 0xFF]) + t1; - r1 = (t1 + t0 + keys[39-4*i]) ^ r1; - r1 = ror1(r1); - r0 = (t0 + keys[38-4*i]) ^ rol1(r0); - - t1 = ( s_box[1][r1 & 0xFF] - ^ s_box[2][(r1 >> 8) & 0xFF] - ^ s_box[3][(r1 >> 16) & 0xFF] - ^ s_box[0][(r1 >> 24) & 0xFF]); - t0 = ( s_box[0][r0 & 0xFF] - ^ s_box[1][(r0 >> 8) & 0xFF] - ^ s_box[2][(r0 >> 16) & 0xFF] - ^ s_box[3][(r0 >> 24) & 0xFF]) + t1; - r3 = (t1 + t0 + keys[37-4*i]) ^ r3; - r3 = ror1(r3); - r2 = (t0 + keys[36-4*i]) ^ rol1(r2); - } - - words[0] = r0 ^ keys[0]; - words[1] = r1 ^ keys[1]; - words[2] = r2 ^ keys[2]; - words[3] = r3 ^ keys[3]; - - for (i = 0; i<4; i++, plaintext += 4) - LE_WRITE_UINT32(plaintext, words[i]); - } -} diff --git a/lsh/src/nettle/twofish.h b/lsh/src/nettle/twofish.h deleted file mode 100644 index a33554c..0000000 --- a/lsh/src/nettle/twofish.h +++ /dev/null @@ -1,65 +0,0 @@ -/* twofish.h - * - * The twofish block cipher. - */ - -/* nettle, low-level cryptographics library - * - * Copyright (C) 2001 Niels Möller - * - * The nettle library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The nettle library 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the nettle library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* - * Twofish is a 128-bit block cipher that accepts a variable-length - * key up to 256 bits, designed by Bruce Schneier and others. See - * http://www.counterpane.com/twofish.html for details. - */ - -#ifndef NETTLE_TWOFISH_H_INCLUDED -#define NETTLE_TWOFISH_H_INCLUDED - -#include - -#define TWOFISH_BLOCK_SIZE 16 - -/* Variable key size between 128 and 256 bits. But the only valid - * values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */ -#define TWOFISH_MIN_KEY_SIZE 16 -#define TWOFISH_MAX_KEY_SIZE 32 - -#define TWOFISH_KEY_SIZE 32 - -struct twofish_ctx -{ - uint32_t keys[40]; - uint32_t s_box[4][256]; -}; - -void -twofish_set_key(struct twofish_ctx *ctx, - unsigned length, const uint8_t *key); - -void -twofish_encrypt(struct twofish_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); -void -twofish_decrypt(struct twofish_ctx *ctx, - unsigned length, uint8_t *dst, - const uint8_t *src); - -#endif /* NETTLE_TWOFISH_H_INCLUDED */ diff --git a/lsh/src/packet_types.h b/lsh/src/packet_types.h deleted file mode 100755 index 2e5b6d7..0000000 --- a/lsh/src/packet_types.h +++ /dev/null @@ -1,262 +0,0 @@ -/* Automatically generated by invert-defs Tue May 30 20:51:01 CEST 2000. - * Do not edit. */ - -{ -"Unknown", -"DISCONNECT", -"IGNORE", -"UNIMPLEMENTED", -"DEBUG", -"SERVICE_REQUEST", -"SERVICE_ACCEPT", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"KEXINIT", -"NEWKEYS", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"KEXDH_INIT|KEXSRP_INIT|KEX_DH_MOD_GROUPS", -"KEXDH_REPLY|KEXSRP_REPLY|KEX_DH_MOD_INIT", -"KEXSRP_PROOF|KEX_DH_MOD_REPLY", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"USERAUTH_REQUEST", -"USERAUTH_FAILURE", -"USERAUTH_SUCCESS", -"USERAUTH_BANNER", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"USERAUTH_PK_OK|USERAUTH_PASSWD_CHANGEREQ", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"GLOBAL_REQUEST", -"REQUEST_SUCCESS", -"REQUEST_FAILURE", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"CHANNEL_OPEN", -"CHANNEL_OPEN_CONFIRMATION", -"CHANNEL_OPEN_FAILURE", -"CHANNEL_WINDOW_ADJUST", -"CHANNEL_DATA", -"CHANNEL_EXTENDED_DATA", -"CHANNEL_EOF", -"CHANNEL_CLOSE", -"CHANNEL_REQUEST", -"CHANNEL_SUCCESS", -"CHANNEL_FAILURE", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -"Unknown", -} - diff --git a/lsh/src/pad.c b/lsh/src/pad.c deleted file mode 100755 index 36fed76..0000000 --- a/lsh/src/pad.c +++ /dev/null @@ -1,97 +0,0 @@ -/* pad.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include -#include - -#include "pad.h" - -#include "format.h" -#include "xalloc.h" - -#include "pad.c.x" - -/* GABA: - (class - (name packet_pad) - (super abstract_write_pipe) - (vars - (connection object ssh_connection) - (random object randomness))) -*/ - -static void -do_pad(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(packet_pad, closure, w); - struct ssh_connection *connection = closure->connection; - - struct lsh_string *new; - - UINT32 new_size; - UINT8 padding; - - UINT8 *data; - UINT32 block_size; - - block_size = connection->send_crypto - ? connection->send_crypto->block_size : 8; - - /* new_size is (packet->length + 9) rounded up to a multiple of - * block_size */ - new_size = block_size - * (1 + (8 + packet->length) / block_size); - - padding = new_size - packet->length - 5; - assert(padding >= 4); - - new = ssh_format("%i%c%lr", packet->length + padding + 1, - padding, packet->length + padding, &data); - - assert(new->length == new_size); - - memcpy(data, packet->data, packet->length); - RANDOM(closure->random, padding, data + packet->length); - - lsh_string_free(packet); - - A_WRITE(closure->super.next, new); -} - -struct abstract_write * -make_packet_pad(struct abstract_write *next, - struct ssh_connection *connection, - struct randomness *random) -{ - NEW(packet_pad, closure); - - closure->super.super.write = do_pad; - closure->super.next = next; - closure->connection = connection; - closure->random = random; - - return &closure->super.super; -} diff --git a/lsh/src/pad.c.x b/lsh/src/pad.c.x deleted file mode 100755 index 47b3c63..0000000 Binary files a/lsh/src/pad.c.x and /dev/null differ diff --git a/lsh/src/pad.h b/lsh/src/pad.h deleted file mode 100755 index 9173fcd..0000000 --- a/lsh/src/pad.h +++ /dev/null @@ -1,42 +0,0 @@ -/* pad.h - * - * Processor for padding and formatting ssh-packets - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_PAD_H_INCLUDED -#define LSH_PAD_H_INCLUDED - -#include "abstract_crypto.h" -#include "abstract_io.h" -#include "connection.h" -#include "randomness.h" - -/* Input to the processor is a packet with the payload. Output is a - * packet containing a formatted ssh packet (with correct byte order, - * etc). */ - -struct abstract_write *make_packet_pad(struct abstract_write *continuation, - struct ssh_connection *connection, - struct randomness *random); - -#endif /* LSH_PAD_H_INCLUDED */ diff --git a/lsh/src/parse.c b/lsh/src/parse.c deleted file mode 100755 index a297f08..0000000 --- a/lsh/src/parse.c +++ /dev/null @@ -1,375 +0,0 @@ -/* parse.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "parse.h" - -#include "format.h" -#include "list.h" -#include "werror.h" -#include "xalloc.h" - -#include "parse_macros.h" - -#include -#include - -void -simple_buffer_init(struct simple_buffer *buffer, - UINT32 capacity, const UINT8 *data) -{ - buffer->capacity = capacity; - buffer->pos = 0; - buffer->data = data; -} - -int -parse_uint32(struct simple_buffer *buffer, UINT32 *result) -{ - if (LEFT < 4) - return 0; - - *result = READ_UINT32(HERE); - ADVANCE(4); - return 1; -} - -int -parse_string(struct simple_buffer *buffer, - UINT32 *length, const UINT8 **start) -{ - UINT32 l; - - if (!parse_uint32(buffer, &l)) - return 0; - - if (LEFT < l) - return 0; - - *length = l; - *start = HERE; - ADVANCE(l); - return 1; -} - -int -parse_octets(struct simple_buffer *buffer, - UINT32 length, UINT8 *start) -{ - if (LEFT < length) - return 0; - memcpy(start, HERE, length); - ADVANCE(length); - return 1; -} - -struct lsh_string * -parse_string_copy(struct simple_buffer *buffer) -{ - UINT32 length; - const UINT8 *start; - - if (!parse_string(buffer, &length, &start)) - return NULL; - - return ssh_format("%ls", length, start); -} - -/* Initializes subbuffer to parse a string from buffer */ -int -parse_sub_buffer(struct simple_buffer *buffer, - struct simple_buffer *subbuffer) -{ - UINT32 length; - const UINT8 *data; - - if (!parse_string(buffer, &length, &data)) - return 0; - - simple_buffer_init(subbuffer, length, data); - return 1; -} - -int -parse_uint8(struct simple_buffer *buffer, unsigned *result) -{ - if (!LEFT) - return 0; - - *result = HERE[0]; - ADVANCE(1); - return 1; -} - -int -parse_utf8(struct simple_buffer *buffer, UINT32 *result) -{ - UINT32 first; - int length; - int i; - - if (!LEFT) - return -1; - - first = HERE[0]; - - if (first < 0x80) - { - *result = first; - ADVANCE(1); - return 1; - } - - switch(first & 0xF0) - { - default: - return 0; - case 0xC0: - case 0xD0: - length = 2; - *result = first & 0x1F; - break; - case 0xE0: - length = 3; - *result = first & 0x0F; - break; - case 0xF0: - switch(first & 0x0E) - { - case 0: case 2: case 4: case 6: - length = 4; - *result = first & 0x07; - break; - case 8: case 0xA: - length = 5; - *result = first & 0x03; - break; - case 0xC: - length = 6; - *result = first & 0x01; - break; - default: - fatal("Internal error!\n"); - } - break; - } - for(i = 1; i (limit + 1))) - return 0; - - bignum_parse_s(result, length, digits); - - return 1; -} - -int -parse_atom(struct simple_buffer *buffer, int *result) -{ - UINT32 length; - const UINT8 *start; - - if ( (!parse_string(buffer, &length, &start)) - || length > 64) - return 0; - - *result = lookup_atom(length, start); - - return 1; -} - -/* NOTE: This functions record the fact that it has read to the end of - * the buffer by setting the position to *beyond* the end of the - * buffer. */ -static int -parse_next_atom(struct simple_buffer *buffer, int *result) -{ - UINT32 i; - - assert (buffer->pos <=buffer->capacity); - - for(i = 0; i < LEFT; i++) - { - if (HERE[i] == ',') - break; - if (i == 64) - /* Atoms can be no larger than 64 characters */ - return 0; - } - - /* NOTE: ssh-2.0.13, server string "SSH-1.99-2.0.13 - * (non-commercial)", sends USERAUTH_FAILURE messages with strings - * like "publickey,password,". It's not entirely clear to me if that - * is allowed for the spec, but it seems safe and straightforward to - * treat empty atoms as any other unknown atom. */ - if (!i) - { - verbose("parse_next_atom: Received an empty atom.\n"); - /* Treat empty atoms as unknown */ - *result = 0; - } - else - *result = lookup_atom(i, HERE); - - ADVANCE(i+1); /* If the atom was terminated at the end of the - * buffer, rather than by a comma, this points beyond - * the end of the buffer */ - return 1; -} - -struct int_list * -parse_atoms(struct simple_buffer *buffer, unsigned limit) -{ - unsigned count; - unsigned i; - struct int_list *res; - - assert(limit); - - if (!LEFT) - return make_int_list(0, -1); - - /* Count commas (no commas means one atom) */ - for (i = buffer->pos, count = 1; i < buffer->capacity; i++) - if (buffer->data[i] == ',') - { - if (count >= limit) - return NULL; - count++; - } - - res = alloc_int_list(count); - - for (i = 0; i < count; i++) - { - if (!parse_next_atom(buffer, LIST(res)+i)) - { - KILL(res); - return NULL; - } - } - - return res; -} - -struct int_list * -parse_atom_list(struct simple_buffer *buffer, unsigned limit) -{ - struct simple_buffer sub_buffer; - - if (!parse_sub_buffer(buffer, &sub_buffer)) - return NULL; - - return parse_atoms(&sub_buffer, limit); -} - -/* Used by client_x11.c, for parsing xauth */ -int -parse_uint16(struct simple_buffer *buffer, UINT32 *result) -{ - if (LEFT < 2) - return 0; - - *result = READ_UINT16(HERE); - ADVANCE(2); - return 1; -} - -int -parse_string16(struct simple_buffer *buffer, - UINT32 *length, const UINT8 **start) -{ - UINT32 l; - - if (!parse_uint16(buffer, &l)) - return 0; - - if (LEFT < l) - return 0; - - *length = l; - *start = HERE; - ADVANCE(l); - return 1; -} - -void -parse_rest(struct simple_buffer *buffer, - UINT32 *length, const UINT8 **start) -{ - *length = LEFT; - *start = HERE; - - ADVANCE(*length); -} - -struct lsh_string * -parse_rest_copy(struct simple_buffer *buffer) -{ - UINT32 length = LEFT; - struct lsh_string *s = ssh_format("%ls", length, HERE); - - ADVANCE(length); - assert(!LEFT); - - return s; -} - -/* Returns success (i.e. 1) iff there is no data left */ -int -parse_eod(struct simple_buffer *buffer) -{ - return !LEFT; -} diff --git a/lsh/src/parse.h b/lsh/src/parse.h deleted file mode 100755 index 5c54e51..0000000 --- a/lsh/src/parse.h +++ /dev/null @@ -1,116 +0,0 @@ -/* parse.h - * - * Parses the data formats used in ssh packets. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_PARSE_H_INCLUDED -#define LSH_PARSE_H_INCLUDED - -#include "atoms.h" -#include "bignum.h" - - -/* Simple buffer - * NOTE: All instances are allocated on the stack. - * No object header is needed. */ - -struct simple_buffer -{ - UINT32 capacity; - UINT32 pos; - const UINT8 *data; -}; - -void -simple_buffer_init(struct simple_buffer *buffer, - UINT32 capacity, const UINT8 *data); - -/* Returns 1 on success, 0 on failure */ -int -parse_uint32(struct simple_buffer *buffer, UINT32 *result); - -/* Only records length and start pointer */ -int -parse_string(struct simple_buffer *buffer, - UINT32 *length, const UINT8 **start); - -/* Copies a given number of octets, without any length header */ -int -parse_octets(struct simple_buffer *buffer, - UINT32 length, UINT8 *start); - -/* Copies a substring */ -struct lsh_string * -parse_string_copy(struct simple_buffer *buffer); - -/* Initializes subbuffer to parse a string from buffer */ -int -parse_sub_buffer(struct simple_buffer *buffer, - struct simple_buffer *subbuffer); - -int -parse_uint8(struct simple_buffer *buffer, unsigned *result); - -/* Returns 1 on success, 0 on error, and -1 at end of buffer */ -int -parse_utf8(struct simple_buffer *buffer, UINT32 *result); - -int parse_boolean(struct simple_buffer *buffer, int *result); - -int -parse_bignum(struct simple_buffer *buffer, mpz_t result, UINT32 limit); - -int -parse_atom(struct simple_buffer *buffer, int *result); - -/* Reads a list of zero or more atoms. The buffer should hold the list - * body; the length field should already be stripped off (usually by - * parse_sub_buffer()). */ -struct int_list * -parse_atoms(struct simple_buffer *buffer, unsigned limit); - -/* Creates a list of integers. The 0 atom means an unknown atom was - * read. Returns a NULL pointer on error. */ -struct int_list * -parse_atom_list(struct simple_buffer *buffer, unsigned limit); - -int -parse_uint16(struct simple_buffer *buffer, UINT32 *result); - -int -parse_string16(struct simple_buffer *buffer, - UINT32 *length, const UINT8 **start); - -void -parse_rest(struct simple_buffer *buffer, - UINT32 *length, const UINT8 **start); - -/* Copies the rest of the buffer into a string. */ -struct lsh_string * -parse_rest_copy(struct simple_buffer *buffer); - -/* Returns success (i.e. 1) iff there is no data left */ -int -parse_eod(struct simple_buffer *buffer); - -#endif /* LSH_PARSE_H_INCLUDED */ diff --git a/lsh/src/parse_macros.h b/lsh/src/parse_macros.h deleted file mode 100755 index 91865d1..0000000 --- a/lsh/src/parse_macros.h +++ /dev/null @@ -1,19 +0,0 @@ -/* parse_macros.h - * - * Utility macros for managing a struct simple_buffer *buffer. - * - * $Id$ */ - -#ifndef LSH_PARSE_MACROS_H_INCLUDED -#define LSH_PARSE_MACROS_H_INCLUDED - -#ifndef BUFFER -#define BUFFER buffer -#endif - -#define LEFT (BUFFER->capacity - BUFFER->pos) -#define HERE (BUFFER->data + BUFFER->pos) -#define ADVANCE(n) (BUFFER->pos += (n)) -#define GET() (BUFFER->data[BUFFER->pos++]) - -#endif /* LSH_PARSE_MACROS_H_INCLUDED */ diff --git a/lsh/src/pkcs5-test.c b/lsh/src/pkcs5-test.c deleted file mode 100755 index 6d4f38f..0000000 --- a/lsh/src/pkcs5-test.c +++ /dev/null @@ -1,91 +0,0 @@ -/* pkcs5-test.c - * - */ - -#include "crypto.h" - -/* FIXME: In which include file can getopt be found? Solaris man page - * says stdlib.h, linux's says unistd.h. */ -#include -#include - -#include -#include - -static void -usage(void) -{ - fprintf(stderr, "pkcs5-test [-i iterations] [-s salt] [-l key length] password"); - exit(1); -} - -static void -print_hex(unsigned length, const char *data) -{ - static const char digits[16] = "0123456789ABCDEF"; - unsigned i; - - for (i = 0; i 10000000)) - usage(); - break; - case 's': - salt = optarg; - break; - case 'l': - length = atoi(optarg); - if ( (length < 1) || (length > 5000) ) - usage(); - break; - case '?': - usage(); - default: - abort(); - } - } - - if (optind != (argc - 1)) - usage(); - - password = argv[optind]; - - key = alloca(length); - - pkcs5_derive_key(make_hmac_algorithm(&sha1_algorithm), - strlen(password), password, - strlen(salt), salt, - iterations, - length, key); - - printf("Key:"); - print_hex(length, key); - printf("\n"); - - return 0; -} - diff --git a/lsh/src/pkcs5.c b/lsh/src/pkcs5.c deleted file mode 100755 index fde04b5..0000000 --- a/lsh/src/pkcs5.c +++ /dev/null @@ -1,127 +0,0 @@ -/* pkcs5.c - * - * PKCS#5 "PBKDF2" style key derivation. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "memxor.h" -#include "xalloc.h" - -#include -#include - -/* NOTE: The PKCS#5 v2 spec doesn't recommend or specify any - * particular value of the iteration count. - * - * To get a feeling for reasonable ranges, I've done some benchmarking - * on my system, an old SparcStation 4 with a bogomips rating of about - * 110. For testing, I'm using SHA1-HMAC with the password = "gazonk", - * salt = "pepper", and I generate a 32 octet key, suitable for - * triple-DES CBC. - * - * Measured timings: - * - * Iterations Elapsed time (seconds) - * 1 0.02 - * 10 0.02 - * 100 0.06 - * 1000 0.35 - * 10 000 3.27 - * 100 000 33.36 - * 1000 000 330.84 - * - * What is reasonable? - * - * With 1000 iterations, key derivation is still doable (and probably - * almost bearable) on slow machines. A real slow i386 could be 50 - * times slower than my machine, and 1000 iterations might take 20 - * seconds. - * - * On the other hand, the key derivation involved in a small - * dictionary attack trying 10000 passwords would take about an hour - * on my machine. And perhaps only a few minutes on a modern office - * machine. - * - * Based on this, it seems that something between 1000 and 10000 is a - * reasonable number of iterations (today, May 2000). */ - -void -pkcs5_derive_key(struct mac_algorithm *prf, - UINT32 password_length, const UINT8 *password, - UINT32 salt_length, const UINT8 *salt, - UINT32 iterations, - UINT32 key_length, UINT8 *key) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - struct mac_instance *m = MAKE_MAC(prf, password_length, password); - UINT32 left = key_length; - - /* Set up the block counter buffer. This will never have more than - * the last few bits set (using sha1, 8 bits = 5100 bytes of key) so - * we only change the last byte. */ - - UINT8 block_count[4] = { 0, 0, 0, 1 }; - - UINT8 *digest = alloca(prf->hash_size); - UINT8 *buffer = alloca(prf->hash_size); - - assert(iterations); - assert(key_length <= 255 * prf->hash_size); - - for (;; block_count[3]++) - { - UINT32 i; - assert(block_count[3]); - - /* First iterate */ - HASH_UPDATE(m, salt_length, salt); - HASH_UPDATE(m, 4, block_count); - HASH_DIGEST(m, buffer); - - for (i = 1; i < iterations; i++) - { - HASH_UPDATE(m, prf->hash_size, buffer); - HASH_DIGEST(m, digest); - memxor(buffer, digest, prf->hash_size); - } - - if (left <= prf->hash_size) - { - memcpy(key, buffer, left); - break; - } - else - { - memcpy(key, buffer, prf->hash_size); - key += prf->hash_size; - left -= prf->hash_size; - } - } - KILL(m); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} diff --git a/lsh/src/prime_table.c b/lsh/src/prime_table.c deleted file mode 100755 index b2365de..0000000 --- a/lsh/src/prime_table.c +++ /dev/null @@ -1,88 +0,0 @@ -/* $Id$ - * - * Generates a table of small odd primes. - */ - -#include -#include - -void fill_table(unsigned long *primes, unsigned long *squares, int length); -void write_table(char *program, - unsigned long *primes, unsigned long *squares, int length); - -int -main(int argc, char **argv) -{ - int length; - unsigned long *table; - - if ( (argc != 2) || ((length = atoi(argv[1])) < 1)) - { - fprintf(stderr, "Usage: %s tablesize\n", argv[0]); - exit(1); - } - - table = (unsigned long *) malloc(2 * length * sizeof(*table)); - fill_table(table, table + length, length); - write_table(argv[0], table, table + length, length); - return 0; -} - -void -fill_table(unsigned long *primes, unsigned long *squares, int length) -{ - int i; - int j; - unsigned long n; - - primes[0] = 2; squares[0] = 4; - i = 1; - n = 3; - while (i < length) - { - for (j=0; (j < i) && (squares[j] <= n); j++) - { - if (n % primes[j] == 0) - /* n is no prime */ - goto outer; - } - primes[i] = n; squares[i] = n*n; - i++; - outer: - n += 2; - } -} - - -void -write_table(char *program, unsigned long *primes, - unsigned long *squares, int length) -{ - int i; - - printf("/* Automatically generated by\n" - " * %s %d\n" - " * Do not edit.\n" - " */\n\n", program, length); - printf("#define NUMBER_OF_PRIMES %d\n\n", length); - - printf("const unsigned long primes[NUMBER_OF_PRIMES] = {"); - for (i=0; i -#include - -struct command chained_connection; -#define CHAINED_CONNECTION (&chained_connection.super) - -#include "proxy.c.x" - -/* GABA: - (class - (name exc_chain_connections_handler) - (super exception_handler) - (vars - (connection object ssh_connection))) -*/ - -static void -do_exc_chain_connections_handler(struct exception_handler *c, - const struct exception *e) -{ - CAST(exc_chain_connections_handler, self, c); - switch (e->type) - { - case EXC_FINISH_READ: - case EXC_FINISH_IO: - { - struct ssh_connection *chain = self->connection->chain; - if (chain) - { - self->connection->chain->chain = NULL; - self->connection->chain = NULL; /* prevent raising this exception again */ - - /* FIXME: is it possible to pass the same exception to two handlers? - * - * It should be. /nisse - */ - - EXCEPTION_RAISE(chain->e, e); - } - } - } - EXCEPTION_RAISE(c->parent, e); -} - -static struct exception_handler * -make_exc_chain_connections_handler(struct ssh_connection *connection, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_chain_connections_handler, self); - - self->super.parent = parent; - self->super.raise = do_exc_chain_connections_handler; - self->super.context = context; - - self->connection = connection; - - return &self->super; -} - -/* GABA: - (class - (name chain_connections_continuation) - (super command_continuation) - (vars - (connection object ssh_connection) - (up object command_continuation))) - */ - -static void -do_chain_connections_continuation(struct command_continuation *s, - struct lsh_object *x) -{ - CAST(chain_connections_continuation, self, s); - CAST(ssh_connection, chained, x); - - self->connection->chain = chained; - chained->chain = self->connection; - - /* FIXME: this a little bit kludgy here */ - self->connection->e = - make_exc_chain_connections_handler(self->connection, - self->connection->e, - HANDLER_CONTEXT); - chained->e = - make_exc_chain_connections_handler(chained, - chained->e, - HANDLER_CONTEXT); - - COMMAND_RETURN(self->up, x); -} - -static struct command_continuation * -make_chain_connections_continuation(struct ssh_connection *connection, - struct command_continuation *c) -{ - NEW(chain_connections_continuation, self); - - self->super.c = do_chain_connections_continuation; - self->connection = connection; - self->up = c; - return &self->super; -} - -/* GABA: - (class - (name chain_connections_client) - (super command_frame) - (vars - (client_addr object listen_value) - (client_callback object command))) -*/ - -static void -do_chain_connections_client(struct command_continuation *s, - struct lsh_object *x) -{ - CAST(chain_connections_client, closure, s); - CAST(ssh_connection, server_connection, x); - - COMMAND_CALL(closure->client_callback, - &closure->client_addr->super, - make_chain_connections_continuation(server_connection, closure->super.up), - closure->super.e); -} - -static struct command_continuation * -make_chain_connections_client(struct command *client_callback, - struct listen_value *client_addr, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(chain_connections_client, self); - - self->super.super.c = do_chain_connections_client; - self->super.up = c; - self->super.e = e; - self->client_callback = client_callback; - self->client_addr = client_addr; - - return &self->super.super; -} - -DEFINE_COMMAND3(chain_connections) - (struct lsh_object *a1, - struct lsh_object *a2, - struct lsh_object *a3, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST_SUBTYPE(command, server_callback, a1); - CAST_SUBTYPE(command, client_callback, a2); - CAST(listen_value, client_addr, a3); - - COMMAND_CALL(server_callback, &client_addr->super, - make_chain_connections_client(client_callback, client_addr, c, e), - e); -} - - -/* (proxy_connection_service user connection) -> connection */ -/* GABA: - (class - (name proxy_connection_service) - (super command) - (vars - ; hooks called on the client side (the server connection) - (server_hooks object object_list) - ; hooks called on the server side (the client connection) - (client_hooks object object_list))) -*/ - -DEFINE_COMMAND(chained_connection) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(ssh_connection, connection, a); - COMMAND_RETURN(c, connection->chain); -} - -/* GABA: - (expr - (name make_call_hooks) - (params - (server_hooks object object_list) - (client_hooks object object_list)) - (expr - (lambda (connection) - (progn - client_hooks - (chained_connection (progn server_hooks connection)))))) - */ - -static void -do_login(struct command *s, - struct lsh_object *x UNUSED, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(proxy_connection_service, self, s); - - COMMAND_RETURN(c, make_call_hooks(self->server_hooks, self->client_hooks)); -} - -struct command * -make_proxy_connection_service(struct object_list *server_hooks, - struct object_list *client_hooks) -{ - NEW(proxy_connection_service, self); - - self->super.call = do_login; - self->server_hooks = server_hooks; - self->client_hooks = client_hooks; - return &self->super; -} - -/* GABA: - (class - (name proxy_accept_service_handler) - (super packet_handler) - (vars - (name . int) - (service object command) - (c object command_continuation) - (e object exception_handler))) -*/ - -static void -do_proxy_accept_service(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(proxy_accept_service_handler, closure, c); - - struct simple_buffer buffer; - UINT32 msg_number; - int name; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_SERVICE_ACCEPT) - && ( -#if DATAFELLOWS_WORKAROUNDS - (connection->peer_flags & PEER_SERVICE_ACCEPT_KLUDGE) -#else - 0 -#endif - || (parse_atom(&buffer, &name) - && (name == closure->name))) - && parse_eod(&buffer)) - { - struct lsh_string *new_packet; - - connection->dispatch[SSH_MSG_SERVICE_ACCEPT] = &connection_fail_handler; -#if DATAFELLOWS_WORKAROUNDS - if ((connection->chain->peer_flags & PEER_SERVICE_ACCEPT_KLUDGE) == - (connection->peer_flags & PEER_SERVICE_ACCEPT_KLUDGE)) - new_packet = packet; - else - { - if (connection->chain->peer_flags & PEER_SERVICE_ACCEPT_KLUDGE) - new_packet = ssh_format("%c", SSH_MSG_SERVICE_ACCEPT); - else - new_packet = ssh_format("%c%a", SSH_MSG_SERVICE_ACCEPT, closure->name); - } -#else - new_packet = packet; -#endif - - C_WRITE(connection->chain, new_packet); - COMMAND_CALL(closure->service, - connection->chain, - closure->c, closure->e); - } - else - PROTOCOL_ERROR(closure->e, "Invalid SSH_MSG_SERVICE_ACCEPT message"); -} - -static struct packet_handler * -make_proxy_accept_service_handler(UINT32 name, - struct command *service, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(proxy_accept_service_handler, self); - - self->super.handler = do_proxy_accept_service; - self->name = name; - self->service = service; - self->c = c; - self->e = e; - return &self->super; -} - -/* GABA: - (class - (name proxy_service_handler) - (super packet_handler) - (vars - (services object alist) - (c object command_continuation) - (e object exception_handler))) -*/ - -static void -do_proxy_service_request(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(proxy_service_handler, self, c); - - struct simple_buffer buffer; - unsigned msg_number; - int name; - - simple_buffer_init(&buffer, packet->length, packet->data); - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_SERVICE_REQUEST) - && parse_atom(&buffer, &name) - && parse_eod(&buffer)) - { - if (name) - { - CAST_SUBTYPE(command, service, ALIST_GET(self->services, name)); - if (service) - { - /* Don't accept any further service requests */ - connection->dispatch[SSH_MSG_SERVICE_REQUEST] - = &connection_fail_handler; - - connection->chain->dispatch[SSH_MSG_SERVICE_ACCEPT] - = make_proxy_accept_service_handler(name, service, self->c, self->e); - - C_WRITE(connection->chain, packet); - - return; - } - } - - EXCEPTION_RAISE(connection->e, - make_protocol_exception(SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, NULL)); - } - else - PROTOCOL_ERROR(connection->e, "Invalid SERVICE_REQUEST message"); -} - -static struct packet_handler * -make_proxy_service_handler(struct alist *services, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(proxy_service_handler, self); - - self->super.handler = do_proxy_service_request; - self->services = services; - self->c = c; - self->e = e; - return &self->super; -} - -/* GABA: - (class - (name proxy_offer_service) - (super command) - (vars - (services object alist))) -*/ - -static void -do_proxy_offer_service(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(proxy_offer_service, self, s); - CAST(ssh_connection, connection, x); - - connection->dispatch[SSH_MSG_SERVICE_REQUEST] - = make_proxy_service_handler(self->services, c, e); - -#if 0 - /* currently servers may not ask for services in clients */ - connection->chain->dispatch[SSH_MSG_SERVICE_REQUEST] - = make_proxy_service_request(self->server_services, c, e); -#endif -} - -struct command * -make_proxy_offer_service(struct alist *services) -{ - NEW(proxy_offer_service, self); - - self->super.call = do_proxy_offer_service; - self->services = services; - return &self->super; -} - diff --git a/lsh/src/proxy.c.x b/lsh/src/proxy.c.x deleted file mode 100755 index 6ef3d7f..0000000 Binary files a/lsh/src/proxy.c.x and /dev/null differ diff --git a/lsh/src/proxy.h b/lsh/src/proxy.h deleted file mode 100755 index 1f93f94..0000000 --- a/lsh/src/proxy.h +++ /dev/null @@ -1,49 +0,0 @@ -/* proxy.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_PROXY_H_INCLUDED -#define LSH_PROXY_H_INCLUDED - -#include "alist.h" -#include "command.h" - -extern struct command_3 chain_connections; -#define CHAIN_CONNECTIONS (&chain_connections.super.super) - -struct command * -make_proxy_connection_service(struct object_list *server_hooks, - struct object_list *client_hooks); - - -struct command * -make_proxy_offer_service(struct alist *services); - -struct channel_open * -make_proxy_open_direct_tcpip(void); - -struct channel_open * -make_proxy_open_forwarded_tcpip(void); - - - -#endif /* LSH_PROXY_H_INCLUDED */ diff --git a/lsh/src/proxy_agentforward.c b/lsh/src/proxy_agentforward.c deleted file mode 100755 index 9fb1dae..0000000 --- a/lsh/src/proxy_agentforward.c +++ /dev/null @@ -1,76 +0,0 @@ -/* proxy_agentforward.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "proxy_agentforward.h" - -#include "channel_commands.h" -#include "format.h" -#include "gateway_channel.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#define WINDOW_SIZE 10000 - -static void -do_proxy_open_auth_agent(struct channel_open *s UNUSED, - struct ssh_connection *connection, - struct channel_open_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - if (parse_eod(args)) - { - struct gateway_channel *server - = make_gateway_channel(NULL); - - /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's - * send_window_size and send_max_packet. */ - struct command *o - = make_gateway_channel_open_command(info, - ssh_format(""), - NULL); - - werror("auth-agent open request\n"); - COMMAND_CALL(o, - connection->chain, - make_gateway_channel_open_continuation(c, NULL, server), - e); - - } - else - { - PROTOCOL_ERROR(e, "Trailing garbage in open message"); - } -} - -struct channel_open * -make_proxy_open_auth_agent(void) -{ - NEW(channel_open, self); - - self->handler = do_proxy_open_auth_agent; - return self; -} - diff --git a/lsh/src/proxy_agentforward.h b/lsh/src/proxy_agentforward.h deleted file mode 100755 index db05bfc..0000000 --- a/lsh/src/proxy_agentforward.h +++ /dev/null @@ -1,30 +0,0 @@ -/* proxy_agentforward.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_PROXY_AGENTFORWARD_H_INCLUDED -#define LSH_PROXY_AGENTFORWARD_H_INCLUDED - -struct channel_open * -make_proxy_open_auth_agent(void); - -#endif diff --git a/lsh/src/proxy_session.c b/lsh/src/proxy_session.c deleted file mode 100755 index b870f56..0000000 --- a/lsh/src/proxy_session.c +++ /dev/null @@ -1,96 +0,0 @@ -/* proxy_session.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "proxy_session.h" - -#include "channel_commands.h" -#include "format.h" -#include "gateway_channel.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include "proxy_session.c.x" - -#define WINDOW_SIZE 10000 - - -/* GABA: - (class - (name proxy_open_session) - (super channel_open) - (vars - ; requests to accept from server -> client - (server_requests object alist) - ; requests to accept from client -> server - (client_requests object alist))) - -*/ - -static void -do_proxy_open_session(struct channel_open *s, - struct ssh_connection *connection, - struct channel_open_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(proxy_open_session, closure, s); - - debug("server.c: do_proxy_open_session\n"); - - if (parse_eod(args)) - { - struct gateway_channel *server - = make_gateway_channel(closure->server_requests); - - /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's - * send_window_size and send_max_packet. */ - struct command *o = - make_gateway_channel_open_command(info, - ssh_format(""), - closure->client_requests); - - COMMAND_CALL(o, - connection->chain, - make_gateway_channel_open_continuation(c, NULL, server), - e); - - } - else - { - PROTOCOL_ERROR(e, "Trailing garbage in open message"); - } -} - -struct channel_open * -make_proxy_open_session(struct alist *server_requests, - struct alist *client_requests) -{ - NEW(proxy_open_session, self); - - self->super.handler = do_proxy_open_session; - self->server_requests = server_requests; - self->client_requests = client_requests; - return &self->super; -} diff --git a/lsh/src/proxy_session.c.x b/lsh/src/proxy_session.c.x deleted file mode 100755 index 2cbcadd..0000000 Binary files a/lsh/src/proxy_session.c.x and /dev/null differ diff --git a/lsh/src/proxy_session.h b/lsh/src/proxy_session.h deleted file mode 100755 index 423bacf..0000000 --- a/lsh/src/proxy_session.h +++ /dev/null @@ -1,34 +0,0 @@ -/* proxy_session.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_PROXY_SESSION_H_INCLUDED -#define LSH_PROXY_SESSION_H_INCLUDED - -#include "alist.h" -#include "channel.h" - -struct channel_open * -make_proxy_open_session(struct alist *server_requests, - struct alist *client_requests); - -#endif /* LSH_PROXY_SESSION_H_INCLUDED */ diff --git a/lsh/src/proxy_tcpforward.c b/lsh/src/proxy_tcpforward.c deleted file mode 100755 index 5c0300e..0000000 --- a/lsh/src/proxy_tcpforward.c +++ /dev/null @@ -1,144 +0,0 @@ -/* proxy_tcpforward.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "proxy_tcpforward.h" - -#include "gateway_channel.h" -#include "xalloc.h" -#include "ssh.h" -#include "werror.h" -#include "channel_commands.h" -#include "format.h" - -#define WINDOW_SIZE 10000 - -static void -do_proxy_open_direct_tcpip(struct channel_open *s UNUSED, - struct ssh_connection *connection, - struct channel_open_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - struct lsh_string *host = NULL, *orig_host = NULL; - UINT32 port, orig_port; - - debug("server.c: do_proxy_open_direct_tcpip\n"); - - if ((host = parse_string_copy(args)) && - parse_uint32(args, &port) && - (orig_host = parse_string_copy(args)) && - parse_uint32(args, &orig_port) && - parse_eod(args)) - { - struct gateway_channel *server - = make_gateway_channel(NULL); - - /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's - * send_window_size and send_max_packet. */ - - struct command *o - = make_gateway_channel_open_command(info, - ssh_format("%S%i%S%i", - host, port, - orig_host, orig_port), NULL); - - werror("direct-tcpip open request: host to connect=%S:%i, originator=%S:%i", - host, port, orig_host, orig_port); - COMMAND_CALL(o, - connection->chain, - make_gateway_channel_open_continuation(c, NULL, server), - e); - - } - else - { - PROTOCOL_ERROR(e, "Trailing garbage in open message"); - } - lsh_string_free(host); - lsh_string_free(orig_host); -} - -struct channel_open * -make_proxy_open_direct_tcpip(void) -{ - NEW(channel_open, self); - - self->handler = do_proxy_open_direct_tcpip; - return self; -} - -static void -do_proxy_open_forwarded_tcpip(struct channel_open *s UNUSED, - struct ssh_connection *connection, - struct channel_open_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - struct lsh_string *host = NULL, *orig_host = NULL; - UINT32 port, orig_port; - - debug("server.c: do_proxy_open_forwarded_tcpip\n"); - - if ((host = parse_string_copy(args)) && - parse_uint32(args, &port) && - (orig_host = parse_string_copy(args)) && - parse_uint32(args, &orig_port) && - parse_eod(args)) - { - struct gateway_channel *server - = make_gateway_channel(NULL); - - /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's - * send_window_size and send_max_packet. */ - struct command *o - = make_gateway_channel_open_command(info, - ssh_format("%S%i%S%i", - host, port, - orig_host, orig_port), NULL); - - werror("direct-tcpip open request: address where connection was accepted=%S:%i, originator=%S:%i", - host, port, orig_host, orig_port); - COMMAND_CALL(o, - connection->chain, - make_gateway_channel_open_continuation(c, NULL, server), - e); - - } - else - { - PROTOCOL_ERROR(e, "Trailing garbage in open message"); - } - lsh_string_free(host); - lsh_string_free(orig_host); -} - -struct channel_open * -make_proxy_open_forwarded_tcpip(void) -{ - NEW(channel_open, self); - - self->handler = do_proxy_open_forwarded_tcpip; - return self; -} diff --git a/lsh/src/proxy_tcpforward.h b/lsh/src/proxy_tcpforward.h deleted file mode 100755 index f38c477..0000000 --- a/lsh/src/proxy_tcpforward.h +++ /dev/null @@ -1,33 +0,0 @@ -/* proxy_tcpforward.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_PROXY_TCPFORWARD_H_INCLUDED -#define LSH_PROXY_TCPFORWARD_H_INCLUDED - -struct channel_open * -make_proxy_open_direct_tcpip(void); - -struct channel_open * -make_proxy_open_forwarded_tcpip(void); - -#endif diff --git a/lsh/src/proxy_userauth.c b/lsh/src/proxy_userauth.c deleted file mode 100755 index b0a72f8..0000000 --- a/lsh/src/proxy_userauth.c +++ /dev/null @@ -1,352 +0,0 @@ -/* proxy_userauth.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "proxy_userauth.h" - -#include "client_userauth.h" -#include "format.h" -#include "proxy.h" -#include "server_userauth.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "proxy_userauth.h.x" -#undef GABA_DEFINE - -#include "proxy_userauth.c.x" - -/* authenticated user is returned in this class */ -static struct proxy_user * -make_proxy_user(struct lsh_string *name) -{ - NEW(proxy_user, self); - self->name = name; - return self; -} - -/* GABA: - (class - (name proxy_userauth) - (vars - (proxy_auth method void "struct ssh_connection *" - "struct lsh_string *username" - "UINT32 service" - "struct simple_buffer *args"))) -*/ - -#define PROXY_AUTH(u, c, n, s, a) ((u)->proxy_auth(u, c, n, s, a)) - -static void -do_forward_password_userauth(struct proxy_userauth *ignored UNUSED, - struct ssh_connection *connection, - struct lsh_string *username, - UINT32 service, - struct simple_buffer *args) -{ - struct lsh_string *password; - int change_password; - - if (parse_boolean(args, &change_password) && - (password = parse_string_copy(args)) && - parse_eod(args)) - { - /* FIXME: Should we really pass the last argument free=1 ? */ - C_WRITE(connection->chain, format_userauth_password(username, service, password, 1)); - } -} - -struct proxy_userauth proxy_password_auth = -{ STATIC_HEADER, do_forward_password_userauth }; - -/* GABA: - (class - (name proxy_userauth_success) - (super packet_handler) - (vars - (name string) - (c object command_continuation))) -*/ - -static void -do_forward_success(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(proxy_userauth_success, self, c); - - struct simple_buffer buffer; - unsigned msg_number; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_SUCCESS) - && parse_eod(&buffer)) - { - struct lsh_string *name = self->name; - self->name = NULL; - C_WRITE(connection->chain, lsh_string_dup(packet)); - COMMAND_RETURN(self->c, make_proxy_user(name)); - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_USERAUTH_SUCCESS message."); -} - - -static struct packet_handler * -make_forward_success(struct lsh_string *name, - struct command_continuation *c) -{ - NEW(proxy_userauth_success, self); - self->super.handler = do_forward_success; - self->name = name; - self->c = c; - return &self->super; -} - -/* GABA: - (class - (name proxy_userauth_failure) - (super packet_handler) - (vars - (e object exception_handler))) -*/ - -/* Arbitrary limit on list length */ -#define USERAUTH_MAX_METHODS 47 - -static void -do_forward_failure(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(proxy_userauth_failure, closure, c); - struct simple_buffer buffer; - unsigned msg_number; - struct int_list *methods = NULL; - int partial_success; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_FAILURE) - && ( (methods = parse_atom_list(&buffer, USERAUTH_MAX_METHODS)) ) - && parse_boolean(&buffer, &partial_success) - && parse_eod(&buffer)) - { - static const struct exception userauth_failed - = STATIC_EXCEPTION(EXC_USERAUTH, - "Server authentication error."); - - verbose("Authentication failure"); - - EXCEPTION_RAISE(closure->e, &userauth_failed); - - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_USERAUTH_FAILURE message."); -} - -static struct packet_handler * -make_forward_failure(struct exception_handler *e) -{ - NEW(proxy_userauth_failure, self); - self->super.handler = do_forward_failure; - self->e = e; - return &self->super; -} - -/* GABA: - (class - (name proxy_userauth_handler) - (super packet_handler) - (vars - ; What to do after successful authentication - (c object command_continuation) - ; or failed. - (e object exception_handler) - - ; Maps authentication methods to userath objects - (methods object alist) - - ; Maps services to commands - (services object alist))) -*/ - -static void -do_handle_userauth(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(proxy_userauth_handler, closure, c); - struct simple_buffer buffer; - - unsigned msg_number; - struct lsh_string *user; - int requested_service; - int method; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_REQUEST) - && ( (user = parse_string_copy(&buffer)) ) - && parse_atom(&buffer, &requested_service) - && parse_atom(&buffer, &method)) - { - CAST_SUBTYPE(proxy_userauth, auth, ALIST_GET(closure->methods, method)); - CAST_SUBTYPE(command, service, - ALIST_GET(closure->services, requested_service)); - - connection_lock(connection); - - if (auth && service) - { - connection->chain->dispatch[SSH_MSG_USERAUTH_FAILURE] = - make_forward_failure(closure->e); - -#if 0 - connection->chain->dispatch[SSH_MSG_USERAUTH_SUCCESS] = - make_forward_success(user, make_delay_continuation(service, closure->c)); -#endif - connection->chain->dispatch[SSH_MSG_USERAUTH_SUCCESS] = - make_forward_success(user, closure->c); - - PROXY_AUTH(auth, connection, user, requested_service, &buffer); - } - else - { - static const struct exception userauth_failed - = STATIC_EXCEPTION(EXC_USERAUTH, - "Unknown auth method or service."); - - EXCEPTION_RAISE(closure->e, &userauth_failed); - } - } - else - PROTOCOL_ERROR(connection->e, "Invalid USERAUTH message."); -} - -static struct packet_handler * -make_proxy_userauth_handler(struct alist *methods, - struct alist *services, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(proxy_userauth_handler, auth); - - auth->super.handler = do_handle_userauth; - auth->methods = methods; - auth->services = services; - auth->c = c; - auth->e = e; - - return &auth->super; -} - -/* chained into the returning of the authenticated user, ignores all - authentication messages */ -/* GABA: - (class - (name proxy_userauth_continuation) - (super command_frame) - (vars - (connection object ssh_connection))) -*/ - -static void -do_proxy_userauth_continuation(struct command_continuation *c, - struct lsh_object *x) -{ - CAST(proxy_userauth_continuation, self, c); - CAST(proxy_user, user, x); - int i; - - assert(user); - /* self->connection->user = user; */ - - connection_unlock(self->connection); - - /* Ignore any further userauth messages. */ - for (i = SSH_FIRST_USERAUTH_GENERIC; i < SSH_FIRST_CONNECTION_GENERIC; i++) - self->connection->dispatch[i] = &connection_ignore_handler; - - COMMAND_RETURN(self->super.up, self->connection); - - /* FIXME: Possibly call connection_handle_pending. */ -} - -static struct command_continuation * -make_proxy_userauth_continuation(struct ssh_connection *connection, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(proxy_userauth_continuation, self); - - self->super.super.c = do_proxy_userauth_continuation; - self->super.up = c; - self->super.e = e; - self->connection = connection; - return &self->super.super; -} - -#define AUTH_ATTEMPTS 20 - -/* Install an SSH_MSG_USERAUTH_REQUEST handler */ -static void -do_userauth_proxy(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(userauth_service, self, s); - CAST(ssh_connection, connection, x); - - connection->dispatch[SSH_MSG_USERAUTH_REQUEST] = - make_proxy_userauth_handler(self->methods, - self->services, - make_proxy_userauth_continuation - (connection, c, e), - make_exc_userauth_handler(connection, - self->advertised_methods, - AUTH_ATTEMPTS, e, - HANDLER_CONTEXT)); -} - -struct command * -make_proxy_userauth(struct int_list *allowed_methods, - struct alist *methods, - struct alist *services) -{ - NEW(userauth_service, self); - - self->super.call = do_userauth_proxy; - self->advertised_methods = allowed_methods; - self->methods = methods; - self->services = services; - return &self->super; -} diff --git a/lsh/src/proxy_userauth.c.x b/lsh/src/proxy_userauth.c.x deleted file mode 100755 index fd66636..0000000 Binary files a/lsh/src/proxy_userauth.c.x and /dev/null differ diff --git a/lsh/src/proxy_userauth.h b/lsh/src/proxy_userauth.h deleted file mode 100755 index 2bbfa1b..0000000 --- a/lsh/src/proxy_userauth.h +++ /dev/null @@ -1,51 +0,0 @@ -/* proxy_userauth.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_PROXY_USERAUTH_H_INCLUDED -#define LSH_PROXY_USERAUTH_H_INCLUDED - -#include "xalloc.h" -#include "alist.h" -#include "list.h" -#include "userauth.h" - -#define GABA_DECLARE -#include "proxy_userauth.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name proxy_user) - (vars - (name string))) -*/ - -struct proxy_userauth; - -extern struct proxy_userauth proxy_password_auth; - -struct command *make_proxy_userauth(struct int_list *allowed_methods, - struct alist *methods, - struct alist *services); - -#endif /* LSH_PROXY_USERAUTH_H_INCLUDED */ diff --git a/lsh/src/proxy_userauth.h.x b/lsh/src/proxy_userauth.h.x deleted file mode 100755 index 172f42a..0000000 Binary files a/lsh/src/proxy_userauth.h.x and /dev/null differ diff --git a/lsh/src/proxy_x11forward.c b/lsh/src/proxy_x11forward.c deleted file mode 100755 index ffa06b3..0000000 --- a/lsh/src/proxy_x11forward.c +++ /dev/null @@ -1,95 +0,0 @@ -/* proxy_x11forward.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "proxy_x11forward.h" - -#include "gateway_channel.h" -#include "xalloc.h" -#include "ssh.h" -#include "werror.h" -#include "channel_commands.h" -#include "format.h" - -#define WINDOW_SIZE 10000 - -static void -do_proxy_open_x11(struct channel_open *s UNUSED, - struct ssh_connection *connection, - struct channel_open_info *info, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - struct lsh_string *host = NULL; - UINT32 port = 0; - - if ((host = parse_string_copy(args)) && -#if DATAFELLOWS_WORKAROUNDS - ((connection->peer_flags & PEER_X11_OPEN_KLUDGE) || - parse_uint32(args, &port)) && -#else - parse_uint32(args, &port) && -#endif - parse_eod(args)) - { - struct gateway_channel *server - = make_gateway_channel(NULL); - - struct command *o; - - /* NOTE: The origin's rec_window_size and rec_max_packet becomes the target's - * send_window_size and send_max_packet. */ - if (connection->chain->peer_flags & PEER_X11_OPEN_KLUDGE) - o = make_gateway_channel_open_command(info, - ssh_format("%S", - host), - NULL); - else - /* FIXME: maybe parse the sent string to get the port value */ - o = make_gateway_channel_open_command(info, - ssh_format("%S%i", - host, port), - NULL); - if (port) - werror("x11 open request: host=%S:%i\n", host, port); - else - werror("datafellows compatible x11 open request: %S\n", host); - COMMAND_CALL(o, - connection->chain, - make_gateway_channel_open_continuation(c, NULL, server), - e); - - } - else - PROTOCOL_ERROR(e, "Trailing garbage in open message"); -} - -struct channel_open * -make_proxy_open_x11(void) -{ - NEW(channel_open, self); - - self->handler = do_proxy_open_x11; - return self; -} - diff --git a/lsh/src/proxy_x11forward.h b/lsh/src/proxy_x11forward.h deleted file mode 100755 index 351f8e1..0000000 --- a/lsh/src/proxy_x11forward.h +++ /dev/null @@ -1,30 +0,0 @@ -/* proxy_x11forward.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_PROXY_X11FORWARD_H_INCLUDED -#define LSH_PROXY_X11FORWARD_H_INCLUDED - -struct channel_open * -make_proxy_open_x11(void); - -#endif diff --git a/lsh/src/publickey_crypto.c b/lsh/src/publickey_crypto.c deleted file mode 100755 index a3dac3e..0000000 --- a/lsh/src/publickey_crypto.c +++ /dev/null @@ -1,260 +0,0 @@ -/* publickey_crypto.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "publickey_crypto.h" - -#include "atoms.h" -#include "bignum.h" -#include "connection.h" -#include "crypto.h" -#include "format.h" -#include "parse.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "publickey_crypto.h.x" -#undef GABA_DEFINE - -#include "publickey_crypto.c.x" - -struct keypair * -make_keypair(UINT32 type, - struct lsh_string *public, - struct signer *private) -{ - NEW(keypair, self); - - self->type = type; - self->public = public; - self->private = private; - return self; -} - -/* Groups */ -/* GABA: - (class - (name group_zn) - (super abstract_group) - (vars - (modulo bignum))) -*/ - -static int -zn_range(struct abstract_group *c, mpz_t x) -{ - CAST(group_zn, closure, c); - - return ( (mpz_sgn(x) == 1) && (mpz_cmp(x, closure->modulo) < 0) ); -} - -#if 0 -static int -zn_member(struct abstract_group *c, mpz_t x) -{ - if (zn_range(c, x)) - { - CAST(group_zn, closure, c); - mpz_t t; - int res; - - mpz_init(t); - - mpz_powm(t, x, closure->order, closure->modulo); - res = !mpz_cmp_ui(t, 1); - - mpz_clear(t); - - return res; - } - return 0; -} -#endif - -static void -zn_invert(struct abstract_group *c, mpz_t res, mpz_t x) -{ - CAST(group_zn, closure, c); - - /* NOTE: In gmp-2, mpz_invert sometimes generates negative inverses. */ - if (!mpz_invert(res, x, closure->modulo)) - fatal("zn_invert: element is non-invertible\n"); - - mpz_fdiv_r(res, res, closure->modulo); -} - -static void -zn_combine(struct abstract_group *c, mpz_t res, mpz_t a, mpz_t b) -{ - CAST(group_zn, closure, c); - - mpz_mul(res, a, b); - mpz_fdiv_r(res, res, closure->modulo); -} - -static void -zn_power(struct abstract_group *c, mpz_t res, mpz_t g, mpz_t e) -{ - CAST(group_zn, closure, c); - - mpz_powm(res, g, e, closure->modulo); -} - -static void -zn_small_power(struct abstract_group *c, mpz_t res, mpz_t g, UINT32 e) -{ - CAST(group_zn, closure, c); - - mpz_powm_ui(res, g, e, closure->modulo); -} - -/* Assumes p is a prime number */ -struct abstract_group * -make_group_zn(mpz_t p, mpz_t g, mpz_t order) -{ - NEW(group_zn, res); - - res->super.range = zn_range; - res->super.invert = zn_invert; - res->super.combine = zn_combine; - res->super.power = zn_power; /* Pretty Mutation! Magical Recall! */ - res->super.small_power = zn_small_power; - res->super.add = NULL; - res->super.subtract = NULL; - - mpz_init_set(res->modulo, p); - mpz_init_set(res->super.generator, g); - mpz_init_set(res->super.order, order); - - return &res->super; -} - -static int -zn_ring_add(struct abstract_group *s, - mpz_t res, mpz_t a, mpz_t b) -{ - CAST(group_zn, self, s); - mpz_add(res, a, b); - mpz_fdiv_r(res, res, self->modulo); - - return mpz_sgn(res); -} - -static int -zn_ring_subtract(struct abstract_group *s, - mpz_t res, mpz_t a, mpz_t b) -{ - CAST(group_zn, self, s); - mpz_sub(res, a, b); - mpz_fdiv_r(res, res, self->modulo); - - return mpz_sgn(res); -} - -/* Assumes p is a prime number, and g a primitive root. */ -struct abstract_group * -make_ring_zn(mpz_t p, mpz_t g) -{ - NEW(group_zn, res); - - res->super.range = zn_range; - res->super.invert = zn_invert; - res->super.combine = zn_combine; - res->super.power = zn_power; - res->super.small_power = zn_small_power; - res->super.add = zn_ring_add; - res->super.subtract = zn_ring_subtract; - - mpz_init_set(res->modulo, p); - mpz_init_set(res->super.generator, g); - mpz_init_set(res->super.order, p); - mpz_sub_ui(res->super.order, res->super.order, 1); - - return &res->super; -} - -struct abstract_group * -make_ssh_group1(void) -{ - struct abstract_group *G; - mpz_t p; - mpz_t g; - mpz_t order; - - /* Prime and generator as defined in - * draft-ietf-secsh-transport-07.txt. */ - - mpz_init_set_str(p, - "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" - "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" - "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" - "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" - "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" - "FFFFFFFFFFFFFFFF", 16); - - mpz_init_set(order, p); - mpz_sub_ui(order, order, 1); - mpz_fdiv_q_2exp(order, order, 1); - mpz_init_set_ui(g, 2); - - G = make_group_zn(p, g, order); - - mpz_clear(p); - mpz_clear(g); - mpz_clear(order); - - return G; -} - -struct abstract_group * -make_ssh_ring_srp_1(void) -{ - struct abstract_group *G; - mpz_t p; - mpz_t g; - - /* Same prime as in draft-ietf-secsh-transport-07.txt, but a - * different generator. */ - mpz_init_set_str(p, - "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" - "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" - "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" - "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" - "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" - "FFFFFFFFFFFFFFFF", 16); - - /* 5 is a primitive root */ - mpz_init_set_ui(g, 5); - - G = make_ring_zn(p, g); - - mpz_clear(p); - mpz_clear(g); - - return G; -} diff --git a/lsh/src/publickey_crypto.c.x b/lsh/src/publickey_crypto.c.x deleted file mode 100755 index 1101073..0000000 Binary files a/lsh/src/publickey_crypto.c.x and /dev/null differ diff --git a/lsh/src/publickey_crypto.h b/lsh/src/publickey_crypto.h deleted file mode 100755 index 74753bc..0000000 --- a/lsh/src/publickey_crypto.h +++ /dev/null @@ -1,205 +0,0 @@ -/* publickey_crypto.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_PUBLICKEY_CRYPTO_H_INCLUDED -#define LSH_PUBLICKEY_CRYPTO_H_INCLUDED - -#include "abstract_crypto.h" -#include "parse.h" - -#define GABA_DECLARE -#include "publickey_crypto.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name keypair) - (vars - ; Atom identifying algorithm type. Needed mostly to know when to invoke the - ; ssh2 ssh-dss bug-compatibility kludge. - (type . int) - (public string) - (private object signer))) -*/ - -struct keypair * -make_keypair(UINT32 type, - struct lsh_string *public, - struct signer *private); - - -/* Groups. For now, assume that all group elements are represented by - * bignums. */ -/* GABA: - (class - (name abstract_group) - (vars - (order bignum) - (generator bignum) - - ; Checks if a bignum is in the correct range for being a group element. - (range method int "mpz_t x") - - ;; (member method int "mpz_t x") - - (invert method void "mpz_t res" "mpz_t x") - (combine method void "mpz_t res" "mpz_t a" "mpz_t b") - - ; This provides operations G x G -> G that is unrelated to the - ; group operation above. It is needed by SRP. For the group Z/n, - ; it can simply be ring addition and subtraction. - - ; The operations may fail (for instance if the result is - ; zero, which is not a member of the multiplicative group). In - ; that case, the method returns zero. - - (add method int "mpz_t res" "mpz_t a" "mpz_t b") - (subtract method int "mpz_t res" "mpz_t a" "mpz_t b") - - ; FIXME: Doesn't handle negative exponents - (power method void "mpz_t res" "mpz_t g" "mpz_t e") - (small_power method void "mpz_t res" "mpz_t g" "UINT32 e"))) */ - -#define GROUP_RANGE(group, x) ((group)->range((group), (x))) -#define GROUP_INVERT(group, res, x) ((group)->invert((group), (res), (x))) -#define GROUP_COMBINE(group, res, a, b) \ -((group)->combine((group), (res), (a), (b))) -#define GROUP_POWER(group, res, g, e) \ -((group)->power((group), (res), (g), (e))) -#define GROUP_SMALL_POWER(group, res, g, e) \ -((group)->small_power((group), (res), (g), (e))) -#define GROUP_ADD(group, res, a, b) \ -((group)->add((group), (res), (a), (b))) -#define GROUP_SUBTRACT(group, res, a, b) \ -((group)->subtract((group), (res), (a), (b))) - -struct abstract_group * -make_group_zn(mpz_t p, mpz_t g, mpz_t order); - -struct abstract_group * -make_ring_zn(mpz_t p, mpz_t g); - -/* NOTE: The object system is not powerful enough for a proper ring - * class, as we would like - * - * abstract_ring inherits abstract_group, - * group_zn inherits abstract_group - * ring_zn inherits abstract_ring, group_zn - * - * and we don't have multiple inheritance. - */ - - -struct abstract_group * -make_ssh_group1(void); - -struct abstract_group * -make_ssh_ring_srp_1(void); - -/* DH key exchange, with authentication */ -/* GABA: - (class - (name dh_method) - (vars - (G object abstract_group) - (H object hash_algorithm) - (random object randomness))) -*/ - -/* State common for both DH keyechange and SRP, for both client and - * server. */ -/* GABA: - (struct - (name dh_instance) - (vars - (method object dh_method) - (e bignum) ; Client value - (f bignum) ; Server value - - (secret bignum) ; This side's secret exponent - - ; Currently, K doesn't include any length header. - (K string) - (hash object hash_instance) - (exchange_hash string))) -*/ - - -/* Creates client message */ -struct lsh_string * -dh_make_client_msg(struct dh_instance *self); - -/* Receives client message */ -int -dh_process_client_msg(struct dh_instance *self, - struct lsh_string *packet); - -/* Includes more data to the exchange hash. */ -void -dh_hash_update(struct dh_instance *self, - struct lsh_string *s, int free); - -/* Generates server's secret exponent */ -void -dh_make_server_secret(struct dh_instance *self); - -/* Creates server message */ -struct lsh_string * -dh_make_server_msg(struct dh_instance *self, - struct lsh_string *server_key, - int hostkey_algorithm, - struct signer *s); - -/* Decodes server message, but does not verify its signature. */ -struct lsh_string * -dh_process_server_msg(struct dh_instance *self, - struct lsh_string **signature, - struct lsh_string *packet); - -/* Verifies server's signature */ -int -dh_verify_server_msg(struct dh_instance *self, - struct verifier *v); - -void -dh_generate_secret(struct dh_method *self, - mpz_t r, mpz_t v); - -void -dh_hash_digest(struct dh_instance *self); - -struct dh_method * -make_dh(struct abstract_group *G, struct hash_algorithm *H, - struct randomness *r); - -struct dh_method * -make_dh1(struct randomness *r); - -void -init_dh_instance(struct dh_method *m, - struct dh_instance *self, - struct ssh_connection *c); - -#endif /* LSH_PUBLICKEY_CRYPTO_H_INCLUDED */ diff --git a/lsh/src/publickey_crypto.h.x b/lsh/src/publickey_crypto.h.x deleted file mode 100755 index 0e8c203..0000000 Binary files a/lsh/src/publickey_crypto.h.x and /dev/null differ diff --git a/lsh/src/queue.c b/lsh/src/queue.c deleted file mode 100755 index b070b98..0000000 --- a/lsh/src/queue.c +++ /dev/null @@ -1,392 +0,0 @@ -/* queue.c - * - * $Id$ - * - * Generic doubly linked list. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "queue.h" - -#include "list.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Prototypes */ -static void do_object_queue_mark(struct lsh_queue *q, - void (*mark)(struct lsh_object *o)); -static void do_object_queue_free(struct lsh_queue *q); -static void do_string_queue_free(struct lsh_queue *q); - -#define GABA_DEFINE -#include "queue.h.x" -#undef GABA_DEFINE - -/* Short cuts */ -#define next np_links[LSH_QUEUE_NEXT] -#define prev np_links[LSH_QUEUE_PREV] - -#define head ht_links[LSH_QUEUE_HEAD] -#define tail ht_links[LSH_QUEUE_TAIL] -#define tailprev ht_links[LSH_QUEUE_TAILPREV] - -#define EMPTYP(q) ((q)->tailprev == (struct lsh_queue_node *) &(q)->head) - -/* #define EMPTYP(q) (!(q)->length) */ - -#if DEBUG_ALLOC -static void sanity_check_queue(struct lsh_queue *q) -{ - struct lsh_queue_node *n; - -#if 0 - UINT32 count; -#endif - -#if 0 - debug("sanity_check_queue: q = %xi\n", (UINT32) q); -#endif - -#if 0 - if (EMPTYP(q) != EMPTYP_1(q)) - fatal("inconsistent emptyness!\n"); - - count = 0; -#endif - - if (q->tail) - fatal("sanity_check_queue: q->tail not NULL!\n"); - - n = q->head; - - if (n->prev != (struct lsh_queue_node *) &q->head) - fatal("sanity_check_queue: head->prev != &q->head !\n"); - - while (n->next) - { -#if 0 - debug(" n = %xi\n", (UINT32) n); -#endif - if (n->prev->next != n) - fatal("n->prev->next != n !\n"); - - n = n->next; -#if 0 - count++; -#endif - } - if (n != (struct lsh_queue_node *) &(q->tail)) - fatal("n != n &t->tail!\n"); - -#if 0 - if (count != (q->length + 1)) - fatal("incorrect length!\n"); -#endif - -} -#else -#define sanity_check_queue(x) -#endif - -void lsh_queue_init(struct lsh_queue *q) -{ - q->head = (struct lsh_queue_node *) &(q->tail); - q->tail = NULL; - q->tailprev = (struct lsh_queue_node *) &(q->head); - sanity_check_queue(q); -} - -int lsh_queue_is_empty(struct lsh_queue *q) -{ - sanity_check_queue(q); - return EMPTYP(q); -} - -void lsh_queue_add_head(struct lsh_queue *q, struct lsh_queue_node *n) -{ - sanity_check_queue(q); - n->next = q->head; - n->prev = (struct lsh_queue_node *) &(q->head); - n->prev->next = n; - n->next->prev = n; - - sanity_check_queue(q); -} - -void lsh_queue_add_tail(struct lsh_queue *q, struct lsh_queue_node *n) -{ - sanity_check_queue(q); - n->next = (struct lsh_queue_node *) &(q->tail); - n->prev = q->tailprev; - n->prev->next = n; - n->next->prev = n; - - sanity_check_queue(q); -} - -void lsh_queue_remove(struct lsh_queue_node *n) -{ - assert(n->next); - assert(n->prev); - n->next->prev = n->prev; - n->prev->next = n->next; -} - -struct lsh_queue_node *lsh_queue_remove_head(struct lsh_queue *q) -{ - struct lsh_queue_node *n = q->head; - - sanity_check_queue(q); - assert(!EMPTYP(q)); - lsh_queue_remove(n); - sanity_check_queue(q); - - return n; -} - -struct lsh_queue_node *lsh_queue_remove_tail(struct lsh_queue *q) -{ - struct lsh_queue_node *n = q->tailprev; - - sanity_check_queue(q); - assert(!EMPTYP(q)); - lsh_queue_remove(n); - sanity_check_queue(q); - - return n; -} - -struct lsh_queue_node *lsh_queue_peek_head(struct lsh_queue *q) -{ - return EMPTYP(q) ? NULL : q->head; -} - -struct lsh_queue_node *lsh_queue_peek_tail(struct lsh_queue *q) -{ - return EMPTYP(q) ? NULL : q->tailprev; -} - - -/* object_queue */ -static struct object_queue_node * -make_object_queue_node(struct lsh_object *o) -{ - struct object_queue_node *n; - - NEW_SPACE(n); - n->o = o; - - return n; -} - -void object_queue_init(struct object_queue *q) -{ - lsh_queue_init(&q->q); - q->length = 0; -} - -int object_queue_is_empty(struct object_queue *q) -{ - assert(EMPTYP(&q->q) == !q->length); - - return !q->length; -} - -void object_queue_add_head(struct object_queue *q, struct lsh_object *o) -{ - lsh_queue_add_head(&q->q, &make_object_queue_node(o)->header); - q->length++; -} - -void object_queue_add_tail(struct object_queue *q, struct lsh_object *o) -{ - lsh_queue_add_tail(&q->q, &make_object_queue_node(o)->header); - q->length++; -} - -static struct lsh_object * -object_queue_get_contents(struct lsh_queue_node *l) -{ - struct object_queue_node *n = (struct object_queue_node *) l; - - struct lsh_object *res = n->o; - lsh_space_free(n); - - return res; -} - -static struct lsh_object * -object_queue_peek(struct lsh_queue_node *n) -{ - return ( (struct object_queue_node *) n)->o; -} - -struct lsh_object *object_queue_remove_head(struct object_queue *q) -{ - q->length--; - return object_queue_get_contents(lsh_queue_remove_head(&q->q)); -} - -struct lsh_object *object_queue_remove_tail(struct object_queue *q) -{ - q->length--; - return object_queue_get_contents(lsh_queue_remove_tail(&q->q)); -} - -struct lsh_object *object_queue_peek_head(struct object_queue *q) -{ - return EMPTYP(&q->q) ? NULL : object_queue_peek(q->q.head); -} - -struct lsh_object *object_queue_peek_tail(struct object_queue *q) -{ - return EMPTYP(&q->q) ? NULL : object_queue_peek(q->q.tailprev); -} - -struct object_list *queue_to_list(struct object_queue *q) -{ - struct object_list *l = alloc_object_list(q->length); - UINT32 i = 0; - - FOR_OBJECT_QUEUE(q, n) - { - LIST(l)[i++] = n; - } - assert(i == q->length); - - return l; -} - -struct object_list *queue_to_list_and_kill(struct object_queue *q) -{ - struct object_list *l = queue_to_list(q); - object_queue_kill(q); - - return l; -} - -/* For gc */ -static void do_object_queue_mark(struct lsh_queue *q, - void (*mark)(struct lsh_object *o)) -{ - FOR_QUEUE(q, struct object_queue_node *, n) - mark(n->o); -} - -static void do_object_queue_free(struct lsh_queue *q) -{ - FOR_QUEUE(q, struct object_queue_node *, n) - lsh_space_free(n); -} - -void object_queue_kill(struct object_queue *q) -{ - do_object_queue_free(&q->q); -} - - -/* String queues */ - -static struct string_queue_node * -make_string_queue_node(struct lsh_string *s) -{ - struct string_queue_node *n; - - NEW_SPACE(n); - n->s = s; - - return n; -} - -void string_queue_init(struct string_queue *q) -{ - lsh_queue_init(&q->q); - q->length = 0; -} - -int string_queue_is_empty(struct string_queue *q) -{ - assert(EMPTYP(&q->q) == !q->length); - - return !q->length; -} - -void string_queue_add_head(struct string_queue *q, struct lsh_string *s) -{ - lsh_queue_add_head(&q->q, &make_string_queue_node(s)->header); - q->length++; -} - -void string_queue_add_tail(struct string_queue *q, struct lsh_string *s) -{ - lsh_queue_add_tail(&q->q, &make_string_queue_node(s)->header); - q->length++; -} - -static struct lsh_string * -string_queue_get_contents(struct lsh_queue_node *l) -{ - struct string_queue_node *n = (struct string_queue_node *) l; - - struct lsh_string *res = n->s; - lsh_space_free(n); - - return res; -} - -static struct lsh_string * -string_queue_peek(struct lsh_queue_node *n) -{ - return ( (struct string_queue_node *) n)->s; -} - -struct lsh_string *string_queue_remove_head(struct string_queue *q) -{ - q->length--; - return string_queue_get_contents(lsh_queue_remove_head(&q->q)); -} - -struct lsh_string *string_queue_remove_tail(struct string_queue *q) -{ - q->length--; - return string_queue_get_contents(lsh_queue_remove_tail(&q->q)); -} - -struct lsh_string *string_queue_peek_head(struct string_queue *q) -{ - return EMPTYP(&q->q) ? NULL : string_queue_peek(q->q.head); -} - -struct lsh_string *string_queue_peek_tail(struct string_queue *q) -{ - return EMPTYP(&q->q) ? NULL : string_queue_peek(q->q.tailprev); -} - -static void do_string_queue_free(struct lsh_queue *q) -{ - FOR_QUEUE(q, struct string_queue_node *, n) - { - lsh_string_free(n->s); - lsh_space_free(n); - } -} - diff --git a/lsh/src/queue.h b/lsh/src/queue.h deleted file mode 100755 index 11d9641..0000000 --- a/lsh/src/queue.h +++ /dev/null @@ -1,154 +0,0 @@ -/* queue.h - * - * $Id$ - * - * Generic doubly linked list. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_QUEUE_H_INCLUDED -#define LSH_QUEUE_H_INCLUDED - -#include "lsh.h" - -/* Layout taken from AmigaOS lists... The first node uses a prev - * pointer that points to the queue's HEAD. The last node uses a next - * pointer that points to the queue's TAIL field. The TAIL field is - * always NULL; TAILPREV points to the last node in the queue. */ -struct lsh_queue_node -{ - struct lsh_queue_node *np_links[2]; -}; -#define LSH_QUEUE_NEXT 0 -#define LSH_QUEUE_PREV 1 - -struct lsh_queue -{ - struct lsh_queue_node *ht_links[3]; -}; -#define LSH_QUEUE_HEAD 0 -#define LSH_QUEUE_TAIL 1 -#define LSH_QUEUE_TAILPREV 2 - -/* This macro must be used at the start of a block, to make the - * declarations legal. It is allowed to free n inside the loop. */ - -#define FOR_QUEUE(q, type, n) \ - struct lsh_queue_node *n##_this, *n##_next; \ - type n; \ - for ( n##_this = (q)->ht_links[LSH_QUEUE_HEAD]; \ - ( n = (type) n##_this, \ - (n##_next = n##_this->np_links[LSH_QUEUE_NEXT])); \ - n##_this = n##_next) - -void lsh_queue_init(struct lsh_queue *q); -int lsh_queue_is_empty(struct lsh_queue *q); -void lsh_queue_add_head(struct lsh_queue *q, struct lsh_queue_node *n); -void lsh_queue_add_tail(struct lsh_queue *q, struct lsh_queue_node *n); -void lsh_queue_remove(struct lsh_queue_node *n); -struct lsh_queue_node *lsh_queue_remove_head(struct lsh_queue *q); -struct lsh_queue_node *lsh_queue_remove_tail(struct lsh_queue *q); - -struct lsh_queue_node *lsh_queue_peek_head(struct lsh_queue *q); -struct lsh_queue_node *lsh_queue_peek_tail(struct lsh_queue *q); - -#define GABA_DECLARE -#include "queue.h.x" -#undef GABA_DECLARE - -/* Object queue */ -struct object_queue_node -{ - struct lsh_queue_node header; - struct lsh_object *o; -}; - -/* GABA: - (struct - (name object_queue) - (vars - (length . UINT32) - (q indirect-special "struct lsh_queue" - do_object_queue_mark do_object_queue_free))) -*/ - -void object_queue_init(struct object_queue *q); -int object_queue_is_empty(struct object_queue *q); - -void object_queue_add_head(struct object_queue *q, struct lsh_object *o); -void object_queue_add_tail(struct object_queue *q, struct lsh_object *o); -struct lsh_object *object_queue_remove_head(struct object_queue *q); -struct lsh_object *object_queue_remove_tail(struct object_queue *q); - -struct lsh_object *object_queue_peek_head(struct object_queue *q); -struct lsh_object *object_queue_peek_tail(struct object_queue *q); - -/* For explicitly allocated object queues, which are not included in a - * garbage collected object. */ -void object_queue_kill(struct object_queue *q); - -#define KILL_OBJECT_QUEUE(q) object_queue_kill((q)) - -struct object_list *queue_to_list(struct object_queue *q); -struct object_list *queue_to_list_and_kill(struct object_queue *q); - -#define FOR_OBJECT_QUEUE(oq, n) \ - struct lsh_queue_node *n##_this, *n##_next; \ - struct lsh_object *n; \ - for ( n##_this = (oq)->q.ht_links[LSH_QUEUE_HEAD]; \ - ( n = ((struct object_queue_node *) n##_this)->o, \ - (n##_next = n##_this->np_links[LSH_QUEUE_NEXT])); \ - n##_this = n##_next) - -/* NOTE: You should probably use break or perhaps continue after - * removing the current node. */ -/* FIXME: This name is rather ugly. */ - -#define FOR_OBJECT_QUEUE_REMOVE(q, n) \ -do { (q)->length--; lsh_queue_remove(n##_this); } while(0) - -/* String queue */ -struct string_queue_node -{ - struct lsh_queue_node header; - struct lsh_string *s; -}; - -/* GABA: - (struct - (name string_queue) - (vars - (length . UINT32) - (q indirect-special "struct lsh_queue" - #f do_string_queue_free))) -*/ - -void string_queue_init(struct string_queue *q); -int string_queue_is_empty(struct string_queue *q); - -void string_queue_add_head(struct string_queue *q, struct lsh_string *o); -void string_queue_add_tail(struct string_queue *q, struct lsh_string *o); -struct lsh_string *string_queue_remove_head(struct string_queue *q); -struct lsh_string *string_queue_remove_tail(struct string_queue *q); - -struct lsh_string *string_queue_peek_head(struct string_queue *q); -struct lsh_string *string_queue_peek_tail(struct string_queue *q); - -#endif /* LSH_QUEUE_H_INCLUDED */ diff --git a/lsh/src/queue.h.x b/lsh/src/queue.h.x deleted file mode 100755 index 3a284ea..0000000 Binary files a/lsh/src/queue.h.x and /dev/null differ diff --git a/lsh/src/randomness.c b/lsh/src/randomness.c deleted file mode 100755 index 0af2ab5..0000000 --- a/lsh/src/randomness.c +++ /dev/null @@ -1,379 +0,0 @@ -/* randomness.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, 2000, Niels Möller - * - * 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 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 should 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 - */ - -#include "randomness.h" - -#include "werror.h" - -#include "crypto.h" -#include "exception.h" -#include "xalloc.h" - -#include "nettle/arcfour.h" - -#include - -#include -#include -#include -#include -#if HAVE_UNISTD_H -#include -#endif - -#include - -#define GABA_DEFINE -#include "randomness.h.x" -#undef GABA_DEFINE - -#include "randomness.c.x" - -#ifdef MACOS -#include -#ifdef __powerc -// The timebase is available through mfspr on 601, mftb on later chips. -// Motorola recommends that an 601 implementation map mftb to mfspr -// through an exception, but I haven't tested to see if MacOS actually -// does this. We only sample the lower 32 bits of the timer (i.e. a -// few minutes of resolution) -static unsigned long GetPPCTimer(); -static asm unsigned long GetPPCTimer() -{ - mftb r3 // Available on 603 and later. -} -#endif -#endif - -/* Random */ -/* GABA: - (class - (name poor_random) - (super randomness) - (vars - (hash object hash_instance) - (pos . UINT32) - (buffer space UINT8))) -*/ - -static void -do_poor_random(struct randomness *r, UINT32 length, UINT8 *dst) -{ - CAST(poor_random, self, r); - - while(length) - { - UINT32 available = self->hash->hash_size - self->pos; - UINT32 to_copy; - - if (!available) - { - time_t now = time(NULL); /* To avoid cycles */ - -#if MACOS -#ifdef __powerc - unsigned long tick = GetPPCTimer(); -#else - unsigned long tick = (pid_t)TickCount(); -#endif - Point mouseLoc; - HASH_UPDATE(self->hash, sizeof(unsigned long), (UINT8 *) &tick); - GetMouse(&mouseLoc); - HASH_UPDATE(self->hash, sizeof(mouseLoc), (UINT8 *) &mouseLoc); -#endif - HASH_UPDATE(self->hash, sizeof(now), (UINT8 *) &now); - HASH_UPDATE(self->hash, self->hash->hash_size, - self->buffer); - HASH_DIGEST(self->hash, self->buffer); - - available = self->hash->hash_size; - self->pos = 0; - } - to_copy = MIN(available, length); - - memcpy(dst, self->buffer + self->pos, to_copy); - length -= to_copy; - dst += to_copy; - self->pos += to_copy; - } -} - -struct randomness * -make_poor_random(struct hash_algorithm *hash, - struct lsh_string *init) -{ - NEW(poor_random, self); - time_t now = time(NULL); -#ifndef MACOS - pid_t pid = getpid(); -#else -#ifdef __powerc - pid_t pid = GetPPCTimer(); -#else - pid_t pid = (pid_t)TickCount(); -#endif - Point mouseLoc; -#endif - - self->super.random = do_poor_random; - self->super.quality = 0; - - self->hash = MAKE_HASH(hash); - self->buffer = lsh_space_alloc(hash->hash_size); - - HASH_UPDATE(self->hash, sizeof(now), (UINT8 *) &now); - HASH_UPDATE(self->hash, sizeof(pid), (UINT8 *) &pid); -#ifdef MACOS - GetMouse(&mouseLoc); - HASH_UPDATE(self->hash, sizeof(mouseLoc), (UINT8 *) &mouseLoc); -#endif - - if (init) - { - HASH_UPDATE(self->hash, init->length, init->data); - lsh_string_free(init); - } - HASH_DIGEST(self->hash, self->buffer); - - self->pos = 0; - - return &self->super; -} - -struct randomness *make_bad_random() -{ - return make_poor_random(&sha1_algorithm, NULL); -} - -/* GABA: - (class - (name device_random) - (super randomness) - (vars - (fd . int))) -*/ - -static void -do_device_random(struct randomness *r, UINT32 length, UINT8 *dst) -{ - CAST(device_random, self, r); - - while(length) - { - int n = read(self->fd, dst, length); - - if (!n) - fatal("do_device_random: EOF on random source.\n"); - - if (n<0) - switch(errno) - { - case EINTR: - break; - default: - fatal("Read from random device failed (errno = %i): %z\n", - errno, STRERROR(errno)); - } - else - { - length -= n; - dst += n; - } - } -} - -/* NOTE: In most cases, blocking while waiting for more entropy to - * arrive is not acceptable. So use /dev/urandom, not /dev/random. The - * alternative is to read a smaller seed from /dev/random at startup, - * and use an internal pseudorandom generator. That - * would be friendlier to other applications, but would not buy as - * more security, as /dev/urandom should degenerate to a fairly strong - * pseudorandom generator when it runs out of entropy. */ - -struct randomness * -make_device_random(const char *device) -{ - int fd = open(device, O_RDONLY); - - if (fd < 0) - { - werror("make_device_random: Failed to open '%z' (errno = %i): %z\n", - device, errno, STRERROR(errno)); - return NULL; - } - else - { - NEW(device_random, self); - - self->super.random = do_device_random; - - /* The quality depends on the used device. */ - self->super.quality = 2; - self->fd = fd; - - return &self->super; - } -} - -/* GABA: - (class - (name arcfour_random) - (super randomness_with_poll) - (vars - (e object exception_handler) - - ; The pool that is used to create the output bytes - (pool . "struct arcfour_ctx") - - ; Accumulate randomness here before it is added to the main - ; pool - (staging_area object hash_instance) - (staging_count . unsigned))) -*/ - -#define STAGE_THRESHOLD 100 - -static void -do_arcfour_random(struct randomness *r, UINT32 length, UINT8 *dst) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(arcfour_random, self, r); - - self->staging_count += RANDOM_POLL_FAST(self->super.poller, self->staging_area); - - if (self->staging_count > STAGE_THRESHOLD) - { - /* Pour the collected randomness into the pool */ - UINT8 *buf = alloca(self->staging_area->hash_size); - - verbose("do_arcfour_random: Pouring staging area into pool.\n"); - - /* Get some data out of the pool, in order to keep any entropy - * there. */ - arcfour_stream(&self->pool, self->staging_area->hash_size, buf); - - HASH_UPDATE(self->staging_area, self->staging_area->hash_size, buf); - - HASH_DIGEST(self->staging_area, buf); - arcfour_set_key(&self->pool, self->staging_area->hash_size, buf); - - self->staging_count = 0; - } - - arcfour_stream(&self->pool, length, dst); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static void -do_arcfour_random_slow(struct randomness *r, UINT32 length, UINT8 *dst) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(arcfour_random, self, r); - - unsigned count = RANDOM_POLL_SLOW(self->super.poller, self->staging_area); - - debug("arcfour_random: entropy estimate for initialization: %i bits.\n", - count); - - if (count < STAGE_THRESHOLD) - { - const struct exception low_entropy = - STATIC_EXCEPTION(EXC_RANDOMNESS_LOW_ENTROPY, - "Could not get enough entropy from the environment."); - EXCEPTION_RAISE(self->e, &low_entropy); - } - else - self->super.super.quality = 1; - - { - /* Initialize the pool. */ - UINT8 *buf = alloca(self->staging_area->hash_size); - - verbose("do_arcfour_random_slow: Initalizing randomness pool.\n"); - HASH_DIGEST(self->staging_area, buf); - arcfour_set_key(&self->pool, self->staging_area->hash_size, buf); - - self->staging_count = 0; - } - - self->super.super.random = do_arcfour_random; - - arcfour_stream(&self->pool, length, dst); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -struct randomness_with_poll * -make_arcfour_random(struct random_poll *poller, - struct hash_algorithm *hash, - struct exception_handler *e) -{ - NEW(arcfour_random, self); - self->super.super.random = do_arcfour_random_slow; - self->super.super.quality = 0; - - self->super.poller = poller; - self->e = e; - - self->staging_area = MAKE_HASH(hash); - self->staging_count = 0; - - return &self->super; -} - -#if 0 -struct randomness * -make_reasonably_random(void) -{ - struct randomness *r = make_device_random("/dev/urandom"); - - if (r) - r->quality = 1; - else - { - werror("Warning: Falling back to an insecure pseudorandom generator.\n"); - r = make_poor_random(&sha1_algorithm, NULL); - } - return r; -} -#endif - -struct randomness_with_poll * -make_default_random(struct reap *reaper, - struct exception_handler *e) -{ - struct random_poll *poller = make_unix_random(reaper); - - /* FIXME: Move away from using rc4. */ - return make_arcfour_random(poller, &sha1_algorithm, e); -} - diff --git a/lsh/src/randomness.c.x b/lsh/src/randomness.c.x deleted file mode 100755 index b90e830..0000000 Binary files a/lsh/src/randomness.c.x and /dev/null differ diff --git a/lsh/src/randomness.h b/lsh/src/randomness.h deleted file mode 100755 index 43f7a54..0000000 --- a/lsh/src/randomness.h +++ /dev/null @@ -1,97 +0,0 @@ -/* randomness.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_RANDOMNESS_H_INCLUDED -#define LSH_RANDOMNESS_H_INCLUDED - -#include "abstract_crypto.h" - -#include "exception.h" - -#define GABA_DECLARE -#include "randomness.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name randomness) - (vars - (quality . int) - (random method void "UINT32 length" "UINT8 *dst"))) -*/ - -#define RANDOM(r, length, dst) ((r)->random((r), length, dst)) - -/* A class polling the environment for randomness. Following Peter - * Gutmann's ideas, there are two methods for a slow more thorough - * poll done at startup, and a faster poll performed from time to time - * as a generator is used. */ - -/* GABA: - (class - (name random_poll) - (vars - ; Both functions return an entropy estimate, and adds the - ; randomness to the given hash instance. - (slow method unsigned "struct hash_instance *") - (fast method unsigned "struct hash_instance *") - (background method void))) -*/ - -#define RANDOM_POLL_SLOW(p, h) ((p)->slow((p), (h))) -#define RANDOM_POLL_FAST(p, h) ((p)->fast((p), (h))) -#define RANDOM_POLL_BACKGROUND(p) ((p)->background((p))) - -/* GABA: - (class - (name randomness_with_poll) - (super randomness) - (vars - ; Object that gets randomness from the environment - (poller object random_poll))) -*/ - -/* Consumes the init string (which may be NULL). */ -struct randomness *make_poor_random(struct hash_algorithm *hash, - struct lsh_string *init); - -struct randomness *make_bad_random(void); - -struct randomness *make_device_random(const char *device); -struct randomness *make_reasonably_random(void); - -struct randomness_with_poll * -make_arcfour_random(struct random_poll *poller, - struct hash_algorithm *hash, - struct exception_handler *e); - -struct randomness_with_poll * -make_default_random(struct reap *reaper, - struct exception_handler *e); - -struct random_poll * -make_unix_random(struct reap *reaper); - -#endif /* LSH_RANDOMNESS_H_INCLUDED */ diff --git a/lsh/src/randomness.h.x b/lsh/src/randomness.h.x deleted file mode 100755 index 6268ec7..0000000 Binary files a/lsh/src/randomness.h.x and /dev/null differ diff --git a/lsh/src/read_base64.c b/lsh/src/read_base64.c deleted file mode 100755 index ec0c17b..0000000 --- a/lsh/src/read_base64.c +++ /dev/null @@ -1,133 +0,0 @@ -/* read_base64.c - * - * A read handler for reading an entire file as a string. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "read_file.h" - -#include "digits.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "read_base64.c.x" - -/* GABA: - (class - (name read_base64) - (super read_handler) - (vars - (c object abstract_write) - (state . "struct base64_state") - - (buffer string) - (pos . UINT32))) -*/ - -/* We can use any non-digit as terminator for base_64_decode */ -#define TERMINATOR 0 - -static UINT32 -do_read_base64(struct read_handler **h, - UINT32 available, - UINT8 *data) -{ - CAST(read_base64, self, *h); - - if (!self->buffer) - { - /* Ignore any extra data. */ - werror("do_read_base64: buffer == NULL, ignoring extra data.\n"); - return available; - } - - if (!available) - { - /* EOF reached */ - if (base64_decode(&self->state, TERMINATOR) - == BASE64_END) - { - self->buffer->length = self->pos; - A_WRITE(self->c, self->buffer); - } - else - { - A_WRITE(self->c, NULL); - lsh_string_free(self->buffer); - } - - self->buffer = NULL; - - *h = NULL; - return 0; - } - else - { - UINT32 i; - for (i = 0; i < available; ) - { - int digit = base64_decode(&self->state, data[i++]); - switch (digit) - { - case BASE64_INVALID: - case BASE64_END: - A_WRITE(self->c, NULL); - *h = NULL; - return available; - - case BASE64_SPACE: - case BASE64_PARTIAL: - break; - - default: - self->buffer->data[self->pos++] = digit; - if (self->pos == self->buffer->length) - { - A_WRITE(self->c, self->buffer); - self->buffer = NULL; - *h = NULL; - return i; - } - } - } - return available; - } -} - -struct read_handler * -make_read_base64(struct abstract_write *c, - UINT32 max_size) -{ - NEW(read_base64, self); - assert(max_size); - - self->super.handler = do_read_base64; - self->c = c; - base64_init(&self->state, TERMINATOR); - - self->buffer = lsh_string_alloc(max_size); - self->pos = 0; - - return &self->super; -} diff --git a/lsh/src/read_base64.c.x b/lsh/src/read_base64.c.x deleted file mode 100755 index e9b045c..0000000 Binary files a/lsh/src/read_base64.c.x and /dev/null differ diff --git a/lsh/src/read_data.c b/lsh/src/read_data.c deleted file mode 100755 index c97e73b..0000000 --- a/lsh/src/read_data.c +++ /dev/null @@ -1,85 +0,0 @@ -/* read_data.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "read_data.h" - -#include "io.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "read_data.c.x" - -/* GABA: - (class - (name read_data) - (super io_consuming_read) - (vars - ; For flow control. - - ; FIXME: Perhaps the information that is needed for flow - ; control should be abstracted out from the channel struct? - - (channel object ssh_channel))) -*/ - -static UINT32 -do_read_data_query(struct io_consuming_read *s) -{ - CAST(read_data, self, s); - - assert(self->channel->sources); - - if (self->channel->flags & - (CHANNEL_RECEIVED_CLOSE | CHANNEL_SENT_CLOSE | CHANNEL_SENT_EOF)) - { - werror("read_data: Receiving data on closed channel. Ignoring.\n"); - return 0; - } - - return MIN(self->channel->send_max_packet, - self->channel->send_window_size); -} - - -struct io_callback * -make_read_data(struct ssh_channel *channel, - struct abstract_write *write) -{ - NEW(read_data, self); - - init_consuming_read(&self->super, write); - - self->super.query = do_read_data_query; - self->super.consumer = write; - - self->channel = channel; - - channel->sources++; - - return &self->super.super; -} - diff --git a/lsh/src/read_data.c.x b/lsh/src/read_data.c.x deleted file mode 100755 index d7a6817..0000000 Binary files a/lsh/src/read_data.c.x and /dev/null differ diff --git a/lsh/src/read_data.h b/lsh/src/read_data.h deleted file mode 100755 index a757a25..0000000 --- a/lsh/src/read_data.h +++ /dev/null @@ -1,35 +0,0 @@ -/* read_data.h - * - * A read handler for application data. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_READ_DATA_H_INCLUDED -#define LSH_READ_DATA_H_INCLUDED - -#include "channel.h" - -struct io_callback * -make_read_data(struct ssh_channel *channel, - struct abstract_write *write); - -#endif /* LSH_READ_DATA_H_INCLUDED */ diff --git a/lsh/src/read_file.c b/lsh/src/read_file.c deleted file mode 100755 index 1f232c6..0000000 --- a/lsh/src/read_file.c +++ /dev/null @@ -1,111 +0,0 @@ -/* read_file.c - * - * A read handler for reading an entire file as a string. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "read_file.h" - -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include "read_file.c.x" - -/* GABA: - (class - (name read_file) - (super read_handler) - (vars - (c object abstract_write) - (buffer string) - (pos . UINT32))) -*/ - -static UINT32 -do_read_file(struct read_handler **h, - UINT32 available, - UINT8 *data) -{ - CAST(read_file, self, *h); - - if (!self->buffer) - { - /* Ignore any extra data. */ - werror("do_read_file: buffer == NULL, ignoring extra data.\n"); - return available; - } - - if (!available) - { - /* EOF reached */ - self->buffer->length = self->pos; - - A_WRITE(self->c, self->buffer); - self->buffer = NULL; - - *h = NULL; - return 0; - } - else - { - UINT32 left = self->buffer->length - self->pos; - if (available >= left) - { - memcpy(self->buffer->data + self->pos, data, left); - A_WRITE(self->c, self->buffer); - self->buffer = NULL; - -#if 0 - if (available > left) - A_WRITE(self->c, NULL); -#endif - *h = NULL; - return available; - } - else - { - memcpy(self->buffer->data + self->pos, data, available); - self->pos += available; - return available; - } - } -} - -struct read_handler * -make_read_file(struct abstract_write *c, - UINT32 max_size) -{ - NEW(read_file, self); - assert(max_size); - - self->super.handler = do_read_file; - self->c = c; - self->buffer = lsh_string_alloc(max_size); - self->pos = 0; - - return &self->super; -} - - diff --git a/lsh/src/read_file.c.x b/lsh/src/read_file.c.x deleted file mode 100755 index ecdacca..0000000 Binary files a/lsh/src/read_file.c.x and /dev/null differ diff --git a/lsh/src/read_file.h b/lsh/src/read_file.h deleted file mode 100755 index 746888d..0000000 --- a/lsh/src/read_file.h +++ /dev/null @@ -1,39 +0,0 @@ -/* read_file.h - * - * A read handler for reading an entire file as a string. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_READ_FILE_H_INCLUDED -#define LSH_READ_FILE_H_INCLUDED - -#include "abstract_io.h" - -struct read_handler * -make_read_file(struct abstract_write *c, - UINT32 max_size); - -struct read_handler * -make_read_base64(struct abstract_write *c, - UINT32 max_size); - -#endif /* LSH_READ_FILE_H_INCLUDED */ diff --git a/lsh/src/read_line.c b/lsh/src/read_line.c deleted file mode 100755 index 52cce50..0000000 --- a/lsh/src/read_line.c +++ /dev/null @@ -1,135 +0,0 @@ -/* read_line.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include -#include - -#include "read_line.h" - -#include "werror.h" -#include "xalloc.h" - -#define GABA_DEFINE -#include "read_line.h.x" -#undef GABA_DEFINE - -#include "read_line.c.x" - -/* GABA: - (class - (name read_line) - (super read_handler) - (vars - (handler object line_handler) - (e object exception_handler) - - ; Line buffer - (pos . UINT32) - (buffer array UINT8 MAX_LINE))) -*/ - -static UINT32 -do_read_line(struct read_handler **h, - UINT32 available, - UINT8 *data /*, struct exception_handler *e */) -{ - CAST(read_line, self, *h); - - UINT8 *eol; - UINT32 consumed; - UINT32 tail; - UINT32 length; - - if (!available) - { - /* FIXME: Should we use some other exception type for this? */ - EXCEPTION_RAISE(self->e, - make_protocol_exception(0, "Unexpected EOF")); - *h = NULL; - return 0; - } - - eol = memchr(data, 0x0a, available); - - if (!eol) - { - /* No newline character yet */ - if (available + self->pos >= 255) - { - /* Too long line */ - EXCEPTION_RAISE(self->e, - make_protocol_exception(0, "Line too long.")); - } - else - { - memcpy(self->buffer + self->pos, data, available); - self->pos += available; - } - return available; - } - - tail = eol - data; /* Excludes the newline character */ - consumed = tail + 1; /* Includes newline character */ - - if ( (self->pos + consumed) > 255) - { - /* Too long line */ - EXCEPTION_RAISE(self->e, - make_protocol_exception(0, "Line too long.")); - } - - /* Ok, now we have a line. Copy it into the buffer. */ - memcpy(self->buffer + self->pos, data, tail); - length = self->pos + tail; - - /* Exclude carriage return character, if any */ - if (length && (data[length-1] == 0xd)) - length--; - - /* NOTE: This call can modify both self->handler and *h. */ - PROCESS_LINE(self->handler, h, length, self->buffer, self->e); - - /* Reset */ - self->pos = 0; - - return consumed; -} - -struct read_handler *make_read_line(struct line_handler *handler, - struct exception_handler *e) -{ - NEW(read_line, closure); - assert(e); - - closure->super.handler = do_read_line; - closure->pos = 0; - - closure->handler = handler; - closure->e = e; - - return &closure->super; -} - - diff --git a/lsh/src/read_line.c.x b/lsh/src/read_line.c.x deleted file mode 100755 index 7ac773a..0000000 Binary files a/lsh/src/read_line.c.x and /dev/null differ diff --git a/lsh/src/read_line.h b/lsh/src/read_line.h deleted file mode 100755 index 493f9eb..0000000 --- a/lsh/src/read_line.h +++ /dev/null @@ -1,54 +0,0 @@ -/* read_line.h - * - * Read-handler processing a line at a time. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_READ_HANDLER_H_INCLUDED -#define LSH_READ_HANDLER_H_INCLUDED - -#include "abstract_io.h" - -#define GABA_DECLARE -#include "read_line.h.x" -#undef GABA_DECLARE - -/* This limit follows the ssh specification */ -#define MAX_LINE 255 - -/* May store a new handler into *h. */ -/* GABA: - (class - (name line_handler) - (vars - (handler indirect-method void "struct read_handler **r" - "UINT32 length" "UINT8 *line" - "struct exception_handler *e"))) -*/ - -#define PROCESS_LINE(h, r, length, line, e) \ -((h)->handler(&(h), (r), (length), (line), (e))) - -struct read_handler *make_read_line(struct line_handler *handler, - struct exception_handler *e); - -#endif /* LSH_READ_HANDLER_H_INCLUDED */ diff --git a/lsh/src/read_line.h.x b/lsh/src/read_line.h.x deleted file mode 100755 index 9e5854a..0000000 Binary files a/lsh/src/read_line.h.x and /dev/null differ diff --git a/lsh/src/read_packet.c b/lsh/src/read_packet.c deleted file mode 100755 index 8471354..0000000 --- a/lsh/src/read_packet.c +++ /dev/null @@ -1,396 +0,0 @@ -/* read_packet.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include -#include -#include - -#include "read_packet.h" - -#include "crypto.h" -#include "format.h" -#include "io.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#define WAIT_START 0 -#define WAIT_HEADER 1 -#define WAIT_CONTENTS 2 -#define WAIT_MAC 3 - -#include "read_packet.c.x" - - -/* GABA: - (class - (name read_packet) - (super read_handler) - (vars - (state . int) - - ; Attached to read packets - (sequence_number . UINT32) - - ; Buffer index, used for all the buffers - (pos . UINT32) - - ; NOTE: This buffer should hold one block, and must be - ; reallocated when the crypto algorithms is changed. - (block_buffer string) - - ; Must point to an area large enough to hold a mac - (mac_buffer string) - - ; Holds the packet payload - (packet_buffer string) - - ; Position in the buffer after the first, - ; already decrypted, block. - (crypt_pos . "UINT8 *") - - (handler object abstract_write) - (connection object ssh_connection))) -*/ - -static struct lsh_string * -lsh_string_realloc(struct lsh_string *s, UINT32 length) -{ - if (!s) - return lsh_string_alloc(length); - - if (s->length < length) - { - lsh_string_free(s); - return lsh_string_alloc(length); - } - else - return s; -} - - -#define READ(n, dst) do { \ - memcpy((dst)->data + closure->pos, data, (n)); \ - closure->pos += (n); \ - data += (n); \ - total += (n); \ - available -= (n); \ -} while (0) - -static UINT32 -do_read_packet(struct read_handler **h, - UINT32 available, - UINT8 *data /*, struct exception_handler *e */) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(read_packet, closure, *h); - UINT32 total = 0; - - if (!available) - { - debug("read_packet: EOF in state %i\n", closure->state); - EXCEPTION_RAISE(closure->connection->e, - make_protocol_exception(0, "Unexpected EOF")); - *h = NULL; - return 0; - } - - for (;;) - switch(closure->state) - { - case WAIT_START: - { - UINT32 block_size = closure->connection->rec_crypto - ? closure->connection->rec_crypto->block_size : 8; - - closure->block_buffer - = lsh_string_realloc(closure->block_buffer, - block_size); - - if (closure->connection->rec_mac) - closure->mac_buffer = lsh_string_realloc - (closure->mac_buffer, - closure->connection->rec_mac->hash_size); - - /* FALL THROUGH */ - } - /* do_header: */ - closure->state = WAIT_HEADER; - closure->pos = 0; - /* FALL THROUGH */ - - case WAIT_HEADER: - { - UINT32 block_size = closure->connection->rec_crypto - ? closure->connection->rec_crypto->block_size : 8; - UINT32 left; - - left = block_size - closure->pos; - assert(left); - - if (available < left) - { - READ(available, closure->block_buffer); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - else - { - /* We have read a complete block */ - UINT32 length; - - READ(left, closure->block_buffer); - - if (closure->connection->rec_crypto) - CRYPT(closure->connection->rec_crypto, - block_size, - closure->block_buffer->data, - closure->block_buffer->data); - - length = READ_UINT32(closure->block_buffer->data); - - /* NOTE: We don't implement a limit at _exactly_ - * rec_max_packet, as we don't include the length field - * and MAC in the comparison below. */ - if (length > (closure->connection->rec_max_packet + SSH_MAX_PACKET_FUZZ)) - { - static const struct protocol_exception too_large = - STATIC_PROTOCOL_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR, - "Packet too large"); - - werror("read_packet: Receiving too large packet.\n" - " %i octets, limit is %i\n", - length, closure->connection->rec_max_packet); - - EXCEPTION_RAISE(closure->connection->e, &too_large.super); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - - if ( (length < 12) - || (length < (block_size - 4)) - || ( (length + 4) % block_size)) - { - static const struct protocol_exception invalid = - STATIC_PROTOCOL_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR, - "Invalid packet length"); - - werror("read_packet: Bad packet length %i\n", - length); - EXCEPTION_RAISE(closure->connection->e, &invalid.super); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - - /* Process this block before the length field is lost. */ - if (closure->connection->rec_mac) - { - UINT8 s[4]; - WRITE_UINT32(s, closure->sequence_number); - - HASH_UPDATE(closure->connection->rec_mac, 4, s); - HASH_UPDATE(closure->connection->rec_mac, - block_size, - closure->block_buffer->data); - } - - /* Allocate full packet */ - { - unsigned done = block_size - 4; - - assert(!closure->packet_buffer); - - closure->packet_buffer - = ssh_format("%ls%lr", - done, - closure->block_buffer->data + 4, - length - done, - &closure->crypt_pos); - - /* The sequence number is needed by the handler for - * unimplemented message types. */ - closure->packet_buffer->sequence_number - = closure->sequence_number++; - - closure->pos = done; - - if (done == length) - { - /* A complete ssh packet fitted in the first - * encryption block. */ - debug("read_packet.c: " - "Going directly to the WAIT_MAC state\n"); - - goto do_mac; - } - else - goto do_contents; - } - } - } - fatal("read_packet: Supposedly not happening???\n"); - - do_contents: - closure->state = WAIT_CONTENTS; - - case WAIT_CONTENTS: - { - UINT32 left = closure->packet_buffer->length - closure->pos; - - assert(left); - - if (available < left) - { - READ(available, closure->packet_buffer); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - else - { - /* Read a complete packet */ - READ(left, closure->packet_buffer); - - left = ( (closure->packet_buffer->length + closure->packet_buffer->data) - - closure->crypt_pos ); - - if (closure->connection->rec_crypto) - CRYPT(closure->connection->rec_crypto, - left, - closure->crypt_pos, - closure->crypt_pos); - - if (closure->connection->rec_mac) - HASH_UPDATE(closure->connection->rec_mac, - left, - closure->crypt_pos); - - goto do_mac; - } - } - fatal("read_packet: Supposedly not happening???\n"); - - do_mac: - closure->state = WAIT_MAC; - closure->pos = 0; - - case WAIT_MAC: - - if (closure->connection->rec_mac) - { - UINT32 left = (closure->connection->rec_mac->mac_size - - closure->pos); - - assert(left); - - if (available < left) - { - READ(available, closure->mac_buffer); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - else - { - /* Read a complete MAC */ - - UINT8 *mac; - - READ(left, closure->mac_buffer); - - mac = alloca(closure->connection->rec_mac->mac_size); - HASH_DIGEST(closure->connection->rec_mac, mac); - - if (memcmp(mac, - closure->mac_buffer->data, - closure->connection->rec_mac->mac_size)) - { - static const struct protocol_exception mac_error = - STATIC_PROTOCOL_EXCEPTION(SSH_DISCONNECT_MAC_ERROR, - "MAC error"); - - EXCEPTION_RAISE(closure->connection->e, &mac_error.super); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - } - } - - /* MAC was ok, send packet on */ - { - struct lsh_string *packet = closure->packet_buffer; - - closure->packet_buffer = NULL; - closure->state = WAIT_START; - - A_WRITE(closure->handler, packet); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return total; - } - default: - fatal("Internal error\n"); - } -} - -struct read_handler * -make_read_packet(struct abstract_write *handler, - struct ssh_connection *connection) -{ - NEW(read_packet, closure); - - closure->super.handler = do_read_packet; - - closure->connection = connection; - closure->handler = handler; - - closure->state = WAIT_START; - closure->sequence_number = 0; - - closure->block_buffer = NULL; - closure->mac_buffer = NULL; - closure->packet_buffer = NULL; - - return &closure->super; -} diff --git a/lsh/src/read_packet.c.x b/lsh/src/read_packet.c.x deleted file mode 100755 index 3638413..0000000 Binary files a/lsh/src/read_packet.c.x and /dev/null differ diff --git a/lsh/src/read_packet.h b/lsh/src/read_packet.h deleted file mode 100755 index f80a19f..0000000 --- a/lsh/src/read_packet.h +++ /dev/null @@ -1,36 +0,0 @@ -/* read_packet.h - * - * Read-handler to read a packet at a time. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_READ_PACKET_H_INCLUDED -#define LSH_READ_PACKET_H_INCLUDED - -#include "abstract_io.h" -#include "abstract_crypto.h" -#include "connection.h" - -struct read_handler *make_read_packet(struct abstract_write *handler, - struct ssh_connection *connection); - -#endif /* LSH_READ_PACKET_H_INCLUDED */ diff --git a/lsh/src/reaper.c b/lsh/src/reaper.c deleted file mode 100755 index d5a7a44..0000000 --- a/lsh/src/reaper.c +++ /dev/null @@ -1,195 +0,0 @@ -/* reaper.c - * - * Handle child processes. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "reaper.h" - -#include "alist.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include -#include -#include -#include - -#define GABA_DEFINE -#include "reaper.h.x" -#undef GABA_DEFINE - -#include "reaper.c.x" - -static volatile sig_atomic_t halloween; - -static void child_handler(int signum) -{ - assert(signum == SIGCHLD); - - halloween = 1; -} - -/* GABA: - (class - (name reaper) - (super reap) - (vars - ; Mapping of from pids to exit-callbacks. - ; NOTE: This assumes that a pid_t fits in an int. - (children object alist))) -*/ - -static void -do_reap(struct reap *c, - pid_t pid, struct exit_callback *callback) -{ - CAST(reaper, closure, c); - - ALIST_SET(closure->children, pid, &callback->super); -} - -/* GABA: - (class - (name reaper_callback) - (super lsh_callback) - (vars - (reaper object reaper))) -*/ - -static void -do_reaper_callback(struct lsh_callback *s) -{ - CAST(reaper_callback, self, s); - struct reaper *r = self->reaper; - - pid_t pid; - int status; - - while( (pid = waitpid(-1, &status, WNOHANG)) ) - { - if (pid > 0) - { - int signaled; - int value; - int core; - struct exit_callback *callback; - - if (WIFEXITED(status)) - { - verbose("Child %i died with exit code %i.\n", - pid, WEXITSTATUS(status)); - signaled = 0; - core = 0; - value = WEXITSTATUS(status); - } - else if (WIFSIGNALED(status)) - { - verbose("Child %i killed by signal %i.\n", - pid, WTERMSIG(status)); - signaled = 1; - core = !!WCOREDUMP(status); - value = WTERMSIG(status); - } - else - fatal("Child died, but neither WIFEXITED or WIFSIGNALED is true.\n"); - - { - CAST_SUBTYPE(exit_callback, c, ALIST_GET(r->children, pid)); - callback = c; - } - - if (callback) - { - ALIST_SET(r->children, pid, NULL); - EXIT_CALLBACK(callback, signaled, core, value); - } - else - { - if (WIFSIGNALED(status)) - werror("Unregistered child %i killed by signal %i.\n", - pid, value); - else - werror("Unregistered child %i died with exit status %i.\n", - pid, value); - } - } - else switch(errno) - { - case EINTR: - werror("reaper.c: waitpid returned EINTR.\n"); - break; - case ECHILD: - /* No more child processes */ - return; - default: - fatal("reaper.c: waitpid failed (errno = %i), %z\n", - errno, STRERROR(errno)); - } - } -} - -static struct lsh_callback * -make_reaper_callback(struct reaper *reaper) -{ - NEW(reaper_callback, self); - self->super.f = do_reaper_callback; - self->reaper = reaper; - - return &self->super; -} - -static void -reaper_install_handler(struct reaper *reaper, - struct io_backend *b) -{ - struct sigaction chld; - memset(&chld, 0, sizeof(chld)); - - chld.sa_handler = child_handler; - sigemptyset(&chld.sa_mask); - chld.sa_flags = SA_NOCLDSTOP; - - halloween = 0; - - if (sigaction(SIGCHLD, &chld, NULL) < 0) - fatal("Failed to install handler for SIGCHLD.\n"); - - io_signal_handler(b, &halloween, make_reaper_callback(reaper)); -} - -struct reap * -make_reaper(struct io_backend *b) -{ - NEW(reaper, self); - - self->super.reap = do_reap; - self->children = make_linked_alist(0, -1); - - reaper_install_handler(self, b); - - return &self->super; -} diff --git a/lsh/src/reaper.c.x b/lsh/src/reaper.c.x deleted file mode 100755 index fcac2ea..0000000 Binary files a/lsh/src/reaper.c.x and /dev/null differ diff --git a/lsh/src/reaper.h b/lsh/src/reaper.h deleted file mode 100755 index e17c3c4..0000000 --- a/lsh/src/reaper.h +++ /dev/null @@ -1,57 +0,0 @@ -/* reaper.h - * - * Handle child processes. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_REAPER_H_INCLUDED -#define LSH_REAPER_H_INCLUDED - -#include "io.h" - -#define GABA_DECLARE -#include "reaper.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name exit_callback) - (vars - (exit method void "int signaled" "int core" "int value"))) -*/ - -#define EXIT_CALLBACK(e, s, c, v) ((e)->exit((e), (s), (c), (v))) - -/* GABA: - (class - (name reap) - (vars - ; Use callback == NULL to cancel a previous callback. - (reap method void "pid_t pid" "struct exit_callback *callback"))) -*/ - -#define REAP(r, p, c) ((r)->reap((r), (p), (c))) - -struct reap *make_reaper(struct io_backend *b); - -#endif /* LSH_REAPER_H_INCLUDED */ diff --git a/lsh/src/reaper.h.x b/lsh/src/reaper.h.x deleted file mode 100755 index 98cbfeb..0000000 Binary files a/lsh/src/reaper.h.x and /dev/null differ diff --git a/lsh/src/resource.c b/lsh/src/resource.c deleted file mode 100755 index 462c39c..0000000 --- a/lsh/src/resource.c +++ /dev/null @@ -1,199 +0,0 @@ -/* resource.c - * - * External resources associated with a connection, for instance - * processes and ports. Used to kill or release the resource in - * question when the connection dies. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "resource.h" - -#include "gc.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Prototypes */ - -void dont_free_live_resource(int alive); - -#define GABA_DEFINE -#include "resource.h.x" -#undef GABA_DEFINE - -/* Forward declarations */ - -struct resource_node; - -void do_mark_resources(struct resource_node **q, - void (*mark)(struct lsh_object *o)); - -void do_free_resources(struct resource_node **q); - -#include "resource.c.x" - - -/* Sanity check */ - -/* NOTE: This happens normally during gc_final. Under all other - * circumstances, it's a serious error. */ -void -dont_free_live_resource(int alive) -{ - if (alive) - { -#if DEBUG_ALLOC - if (gc_final_p) - verbose("dont_free_live_resource: " - "final collection of a live resource!\n"); - else -#endif - fatal("dont_free_live_resource: " - "garbage collecting a live resource!\n"); -} -} - -/* For resources that are only marked as dead, and taken care of - * later. */ -static void -do_resource_kill(struct resource *self) -{ self->alive = 0; } - -void -init_resource(struct resource *self, - void (*k)(struct resource *)) -{ - self->alive = 1; - self->kill = k ? k : do_resource_kill; -} - -/* The behaviour of a resource list is somewhat similar to - * a weak list. Nodes that are dead are unlinked automatically, - * so that they can be garbage collected. */ - -struct resource_node -{ - struct resource_node *next; - struct resource *resource; -}; - -/* GABA: - (class - (name concrete_resource_list) - (super resource_list) - (vars - (q indirect-special "struct resource_node *" - do_mark_resources do_free_resources))) -*/ - -/* Loop over the resources, mark the living and unlink the dead. */ -void -do_mark_resources(struct resource_node **q, - void (*mark)(struct lsh_object *o)) -{ - struct resource_node *n; - - while ( (n = *q) ) - { - if (n->resource->alive) - { - mark(&n->resource->super); - q = &n->next; - } - else - { - *q = n->next; - lsh_space_free(n); - } - } -} - -/* Free the list. */ -void -do_free_resources(struct resource_node **q) -{ - struct resource_node *n; - - for (n = *q; n; ) - { - struct resource_node *old = n; - n = n->next; - lsh_space_free(old); - } -} - - -static void -do_remember_resource(struct resource_list *s, - struct resource *resource) -{ - CAST(concrete_resource_list, self, s); - struct resource_node *n; - - if (!self->super.super.alive) - { - werror("do_remember_resource: resource list is already dead.\n"); - KILL_RESOURCE(resource); - return; - } - - NEW_SPACE(n); - - n->resource = resource; - n->next = self->q; - self->q = n; -} - -static void -do_kill_all(struct resource *s) -{ - CAST(concrete_resource_list, self, s); - struct resource_node *n; - - for (n = self->q; n; ) - { - CAST_SUBTYPE(resource, r, n->resource); - struct resource_node *old = n; - - KILL_RESOURCE(r); - n = n->next; - - lsh_space_free(old); - } - self->q = NULL; - self->super.super.alive = 0; -} - -struct resource_list * -empty_resource_list(void) -{ - NEW(concrete_resource_list, self); - init_resource(&self->super.super, do_kill_all); - - trace("empty_resource_list: created %xi\n", self); - self->super.remember = do_remember_resource; - - self->q = NULL; - - return &self->super; -} diff --git a/lsh/src/resource.c.x b/lsh/src/resource.c.x deleted file mode 100755 index 1b9c63e..0000000 Binary files a/lsh/src/resource.c.x and /dev/null differ diff --git a/lsh/src/resource.h b/lsh/src/resource.h deleted file mode 100755 index f9025bc..0000000 --- a/lsh/src/resource.h +++ /dev/null @@ -1,70 +0,0 @@ -/* resource.h - * - * External resources associated with a connection, for instance - * processes and ports. Used to kill or release the resource in - * question when the connection dies. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_RESOURCE_H_INCLUDED -#define LSH_RESOURCE_H_INCLUDED - -#include "lsh.h" - -#define GABA_DECLARE -#include "resource.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name resource) - (vars - ; Hack to check liveness before the resource gets gc:ed. - ; Live resources should never be forgotten. - (alive special int #f dont_free_live_resource) - - (kill method void))) -*/ - -#define KILL_RESOURCE(r) ((r)->kill((r))) - -void -init_resource(struct resource *self, - void (*k)(struct resource *)); - -/* For the resource list. */ - -/* GABA: - (class - (name resource_list) - (super resource) - (vars - (remember method void "struct resource *r"))) -*/ - -#define REMEMBER_RESOURCE(l, r) ((l)->remember((l), (r))) -#define KILL_RESOURCE_LIST(l) KILL_RESOURCE(&(l)->super) - -/* Allocates an empty list. */ -struct resource_list *empty_resource_list(void); - -#endif /* LSH_RESOURCE_H_INCLUDED */ diff --git a/lsh/src/resource.h.x b/lsh/src/resource.h.x deleted file mode 100755 index 39fd256..0000000 Binary files a/lsh/src/resource.h.x and /dev/null differ diff --git a/lsh/src/rijndael.c b/lsh/src/rijndael.c deleted file mode 100755 index 3a75f24..0000000 --- a/lsh/src/rijndael.c +++ /dev/null @@ -1,101 +0,0 @@ -/* rijndael.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999, 2000 Niels Möller, Rafael R. Sevilla - * - * 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 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 should 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 - */ -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/aes.h" - -#include - -#include "rijndael.c.x" - -/* Rijndael */ - -/* GABA: - (class - (name rijndael_instance) - (super crypto_instance) - (vars - (ctx . "struct aes_ctx"))) -*/ - -static void -do_rijndael_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(rijndael_instance, self, s); - - aes_encrypt(&self->ctx, length, dst, src); -} - -static void -do_rijndael_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(rijndael_instance, self, s); - - aes_decrypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_rijndael_instance(struct crypto_algorithm *algorithm, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(rijndael_instance, self); - - self->super.block_size = AES_BLOCK_SIZE; - self->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_rijndael_encrypt - : do_rijndael_decrypt); - - aes_set_key(&self->ctx, algorithm->key_size, key); - - return(&self->super); -} - -struct crypto_algorithm * -make_rijndael_algorithm(UINT32 key_size) -{ - NEW(crypto_algorithm, algorithm); - - assert(key_size <= AES_MAX_KEY_SIZE); - assert(key_size >= AES_MIN_KEY_SIZE); - - algorithm->block_size = AES_BLOCK_SIZE; - algorithm->key_size = key_size; - algorithm->iv_size = 0; - algorithm->make_crypt = make_rijndael_instance; - - return algorithm; -} - -struct crypto_algorithm rijndael128_algorithm = -{ STATIC_HEADER, AES_BLOCK_SIZE, 16, 0, make_rijndael_instance}; - -struct crypto_algorithm rijndael192_algorithm = -{ STATIC_HEADER, AES_BLOCK_SIZE, 24, 0, make_rijndael_instance}; - -struct crypto_algorithm rijndael256_algorithm = -{ STATIC_HEADER, AES_BLOCK_SIZE, 32, 0, make_rijndael_instance}; diff --git a/lsh/src/rijndael.c.x b/lsh/src/rijndael.c.x deleted file mode 100755 index 80f942d..0000000 Binary files a/lsh/src/rijndael.c.x and /dev/null differ diff --git a/lsh/src/rsa.c b/lsh/src/rsa.c deleted file mode 100755 index a61254f..0000000 --- a/lsh/src/rsa.c +++ /dev/null @@ -1,695 +0,0 @@ -/* rsa.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "rsa.h" - -#include "atoms.h" -#include "crypto.h" -#include "format.h" -#include "parse.h" -#include "sexp.h" -/* #include "ssh.h" */ -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#define GABA_DEFINE -#include "rsa.h.x" -#undef GABA_DEFINE - -#include "rsa.c.x" - -#define SA(x) sexp_a(ATOM_##x) - -#define RSA_CRT 1 - -/* GABA: - (class - (name rsa_verifier) - (super verifier) - (vars - (params object rsa_algorithm) - (size . unsigned) - (n bignum) - (e bignum))) -*/ - -/* GABA: - (class - (name rsa_signer) - (super signer) - (vars - (verifier object rsa_verifier) - - ; Secret exponent - (d bignum) - - ; The two factors - (p bignum) - (q bignum) - - ; d % (p-1), i.e. a e = 1 (mod p) - (a bignum) - - ; d % (q-1), i.e. b e = 1 (mod q) - (b bignum) - - ; modular inverse of q , i.e. c q = 1 (mod p) - (c bignum))) -*/ - - -/* Utility functions */ - -static void -pkcs1_encode(mpz_t m, - struct rsa_algorithm *params, - UINT32 length, - UINT32 msg_length, - const UINT8 *msg) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - UINT8 *em = alloca(length); - unsigned i = length; - - struct hash_instance *h = MAKE_HASH(params->hash); - HASH_UPDATE(h, msg_length, msg); - - assert(i >= h->hash_size); - i -= h->hash_size; - - HASH_DIGEST(h, em + i); - KILL(h); - - assert(i >= params->prefix_length); - i -= params->prefix_length; - - memcpy(em + i, params->prefix, params->prefix_length); - - assert(i); - em[--i] = 0; - - assert(i >= 9); - em[0] = 1; - memset(em + 1, 0xff, i - 1); - - bignum_parse_u(m, length, em); - - debug("pkcs1_encode: m = %xn\n", m); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static int -rsa_check_size(struct rsa_verifier *key) -{ - /* Size in octets */ - key->size = (mpz_sizeinbase(key->n, 2) + 7) / 8; - - /* For PKCS#1 to make sense, the size of the modulo, in octets, must - * be at least 1 + the length of the DER-encoded Digest Info. - * - * And a DigestInfo is 34 octets for md5, and 35 octets for sha1. - * 46 octets is 368 bits. */ - return (key->size >= 46); -} - -static struct sexp * -encode_rsa_sig_val(mpz_t s) -{ - return sexp_un(s); -} - -static int -decode_rsa_sig_val(struct sexp *e, mpz_t s, unsigned limit) -{ - return sexp2bignum_u(e, s, limit); -} - -static int -spki_init_rsa_verifier(struct rsa_verifier *key, - struct sexp_iterator *i) -{ - return (sexp_get_un(i, ATOM_N, key->n, RSA_MAX_SIZE) - && sexp_get_un(i, ATOM_E, key->e, RSA_MAX_SIZE) - && rsa_check_size(key)); -} - - -/* Signature verification */ -static int -rsa_pkcs1_verify(struct rsa_verifier *self, - UINT32 length, - const UINT8 *msg, - mpz_t signature) -{ - int res; - mpz_t m; - mpz_t s; - - if (mpz_cmp(signature, self->n) >= 0) - return 0; - - mpz_init(m); - mpz_init(s); - - debug("rsa_pkcs1_verify: n = %xn\n" - " e = %xn\n" - " s = %xn\n", - self->n, self->e, signature); - - mpz_powm(s, signature, self->e, self->n); - - debug("rsa_pkcs1_verify: m = %xn\n", s); - - pkcs1_encode(m, self->params, self->size - 1, - length, msg); - - res = !mpz_cmp(m, s); - mpz_clear(m); mpz_clear(s); - - return res; -} - -static int -do_rsa_verify(struct verifier *v, - int algorithm, - UINT32 length, - const UINT8 *msg, - UINT32 signature_length, - const UINT8 *signature_data) -{ - CAST(rsa_verifier, self, v); - mpz_t s; - int res = 0; - - trace("do_rsa_verify: Verifying %a signature\n", algorithm); - - mpz_init(s); - - switch(algorithm) - { -#if 0 - case ATOM_RSA_PKCS1_SHA1: - case ATOM_RSA_PKCS1_SHA1_LOCAL: - - if (signature_length > self->size) - goto fail; - - bignum_parse_u(s, signature_length, signature_data); - break; - - case ATOM_SPKI: -#endif - case ATOM_SSH_RSA: - { - struct simple_buffer buffer; - UINT32 length; - const UINT8 *digits; - int atom; - - simple_buffer_init(&buffer, signature_length, signature_data); - - if (!(parse_atom(&buffer, &atom) - && (atom == ATOM_SSH_RSA) - && parse_string(&buffer, &length, &digits) - && (length <= self->size) - && parse_eod(&buffer) )) - goto fail; - - bignum_parse_u(s, length, digits); - - break; - } - - /* It doesn't matter here which flavour of SPKI is used. */ - case ATOM_SPKI_SIGN_RSA: - case ATOM_SPKI_SIGN_DSS: - { - struct simple_buffer buffer; - struct sexp *e; - - simple_buffer_init(&buffer, signature_length, signature_data); - - if (! ( (e = sexp_parse_canonical(&buffer)) - && parse_eod(&buffer) - && decode_rsa_sig_val(e, s, self->size)) ) - goto fail; - - break; - } - - default: - fatal("do_rsa_verify: Internal error!\n"); - } - - res = rsa_pkcs1_verify(self, length, msg, s); - - fail: - mpz_clear(s); - - return res; -} - -static int -do_rsa_verify_spki(struct verifier *v, - UINT32 length, - const UINT8 *msg, - struct sexp *e) -{ - CAST(rsa_verifier, self, v); - mpz_t s; - int res; - - mpz_init(s); - - res = (decode_rsa_sig_val(e, s, self->size) - && rsa_pkcs1_verify(self, length, msg, s)); - - mpz_clear(s); - - return res; -} - -static struct lsh_string * -do_rsa_public_key(struct verifier *s) -{ - CAST(rsa_verifier, self, s); - - return ssh_format("%a%n%n", ATOM_SSH_RSA, - self->e, self->n); -} - -static struct sexp * -do_rsa_public_spki_key(struct verifier *s) -{ - CAST(rsa_verifier, self, s); - - return sexp_l(3, sexp_a(self->params->name), - sexp_l(2, SA(N), sexp_un(self->n), -1), - sexp_l(2, SA(E), sexp_un(self->e), -1), - -1); -} - -/* NOTE: To initialize an rsa verifier, one must - * - * 1. Call this function. - * 2. Initialize the modulo n and exponent e. - * 3. Call rsa_check_size. - */ -static void -init_rsa_verifier(struct rsa_verifier *self, struct rsa_algorithm *params) -{ - self->params = params; - - /* FIXME: The allocator could do this kind of initialization - * automatically. */ - mpz_init(self->n); - mpz_init(self->e); - - self->size = 0; - - self->super.verify = do_rsa_verify; - self->super.verify_spki = do_rsa_verify_spki; - self->super.public_key = do_rsa_public_key; - self->super.public_spki_key = do_rsa_public_spki_key; -} - -static struct rsa_verifier * -make_rsa_verifier_internal(struct rsa_algorithm *params, - struct sexp_iterator *i) -{ - NEW(rsa_verifier, res); - init_rsa_verifier(res, params); - - assert(SEXP_LEFT(i) >= 2); - - if (spki_init_rsa_verifier(res, i)) - { - return res; - } - else - { - KILL(res); - return NULL; - } -} - -/* Alternative constructor using a key of type ssh-rsa, when the atom - * "ssh-rsa" is already read from the buffer. */ -struct verifier * -parse_ssh_rsa_public(struct simple_buffer *buffer) -{ - NEW(rsa_verifier, res); - init_rsa_verifier(res, &rsa_sha1_algorithm); - - if (parse_bignum(buffer, res->e, RSA_MAX_SIZE) - && (mpz_sgn(res->e) == 1) - && parse_bignum(buffer, res->n, RSA_MAX_SIZE) - && (mpz_sgn(res->n) == 1) - && (mpz_cmp(res->e, res->n) < 0) - && parse_eod(buffer) - && rsa_check_size(res)) - return &res->super; - - else - { - KILL(res); - return NULL; - } -} - -/* Signature creation */ - -/* Compute x, the d:th root of m. Calling it with x == m is allowed. */ -static void -rsa_compute_root(struct rsa_signer *self, mpz_t x, mpz_t m) -{ - debug("rsa_compute_root: n = %xn\n" - " e = %xn\n" - " m = %xn\n", - self->verifier->n, self->verifier->e, m); - -#if RSA_CRT - { - mpz_t xp; /* modulo p */ - mpz_t xq; /* modulo q */ - - mpz_init(xp); mpz_init(xq); - -#if 0 - debug("rsa_compute_root: p = %xn\n" - " q = %xn\n", - self->p, self->q); - - debug("rsa_compute_root: d = %xn\n" - " a = %xn\n" - " b = %xn\n" - " c = %xn\n", - self->d, self->a, self->b, self->c); -#endif - - /* Compute xq = m^d % q = (m%q)^b % q */ - mpz_fdiv_r(xq, m, self->q); - mpz_powm(xq, xq, self->b, self->q); - -#if 0 - debug("rsa_compute_root: xq = %xn\n", xq); -#endif - - /* Compute xp = m^d % p = (m%p)^a % p */ - mpz_fdiv_r(xp, m, self->p); - mpz_powm(xp, xp, self->a, self->p); - -#if 0 - debug("rsa_compute_root: xp = %xn\n", xp); -#endif - - /* Set xp' = (xp - xq) c % p. */ - mpz_sub(xp, xp, xq); - mpz_mul(xp, xp, self->c); - mpz_fdiv_r(xp, xp, self->p); - -#if 0 - debug("rsa_compute_root: xp' = %xn\n", xp); -#endif - - /* Finally, compute x = xq + q xp' - * - * To prove that this works, note that - * - * xp = x + i p, - * xq = x + j q, - * c q = 1 + k p - * - * for some integers i, j and k. Now, for some integer l, - * - * xp' = (xp - xq) c + l p - * = (x + i p - (x + j q)) c + l p - * = (i p - j q) c + l p - * = (i + l) p - j (c q) - * = (i + l) p - j (1 + kp) - * = (i + l - j k) p - j - * - * which shows that xp' = -j (mod p). We get - * - * xq + q xp' = x + j q + (i + l - j k) p q - j q - * = x + (i + l - j k) p q - * - * so that - * - * xq + q xp' = x (mod pq) - * - * We also get 0 <= xq + q xp' < p q, because - * - * 0 <= xq < q and 0 <= * xp' < p. - */ - mpz_mul(x, self->q, xp); - mpz_add(x, x, xq); - - mpz_clear(xp); mpz_clear(xq); - } -#else /* !RSA_CRT */ - mpz_powm(x, m, self->d, self->verifier->n); -#endif /* !RSA_CRT */ - debug("rsa_compute_root: x = %xn\n", x); -} - -static struct lsh_string * -do_rsa_sign(struct signer *s, - int algorithm, - UINT32 msg_length, - const UINT8 *msg) -{ - CAST(rsa_signer, self, s); - struct lsh_string *res; - mpz_t m; - - trace("do_rsa_sign: Signing according to %a\n", algorithm); - - mpz_init(m); - pkcs1_encode(m, self->verifier->params, self->verifier->size - 1, - msg_length, msg); - - rsa_compute_root(self, m, m); - - switch (algorithm) - { - case ATOM_SSH_RSA: - /* Uses the encoding: - * - * string ssh-rsa - * string signature-blob - */ - - res = ssh_format("%a%un", ATOM_SSH_RSA, m); - break; -#if 0 - case ATOM_RSA_PKCS1_SHA1: - case ATOM_RSA_PKCS1_SHA1_LOCAL: - /* Uses the encoding: - * - * string rsa-pkcs1 - * string signature-blob - */ - - res = ssh_format("%a%un", ATOM_RSA_PKCS1_SHA1, m); - break; -#endif - /* It doesn't matter here which flavour of SPKI is used. */ - case ATOM_SPKI_SIGN_RSA: - case ATOM_SPKI_SIGN_DSS: - - res = sexp_format(encode_rsa_sig_val(m), SEXP_CANONICAL, 0); - break; - default: - fatal("do_rsa_sign: Internal error!\n"); - } - mpz_clear(m); - return res; -} - -static struct sexp * -do_rsa_sign_spki(struct signer *s, - /* struct sexp *hash, struct sexp *principal, */ - UINT32 msg_length, - const UINT8 *msg) -{ - CAST(rsa_signer, self, s); - mpz_t m; - struct sexp *signature; - - mpz_init(m); - pkcs1_encode(m, self->verifier->params, self->verifier->size - 1, - msg_length, msg); - - rsa_compute_root(self, m, m); - - signature = encode_rsa_sig_val(m); - - mpz_clear(m); - return signature; -} - -static struct verifier * -do_rsa_get_verifier(struct signer *s) -{ - CAST(rsa_signer, self, s); - return &self->verifier->super; -} - - -static struct verifier * -make_rsa_verifier(struct signature_algorithm *s, - struct sexp_iterator *i) -{ - CAST(rsa_algorithm, self, s); - - return ( (SEXP_LEFT(i) == 2) - ? &make_rsa_verifier_internal(self, i)->super - : NULL); -} - - -static struct signer * -make_rsa_signer(struct signature_algorithm *s, - struct sexp_iterator *i) -{ - CAST(rsa_algorithm, params, s); - NEW(rsa_signer, res); - - if ( (SEXP_LEFT(i) == 8) - && ( (res->verifier = make_rsa_verifier_internal(params, i)) ) - && sexp_get_un(i, ATOM_D, res->d, RSA_MAX_SIZE) - && sexp_get_un(i, ATOM_P, res->p, RSA_MAX_SIZE) - && sexp_get_un(i, ATOM_Q, res->q, RSA_MAX_SIZE) - && sexp_get_un(i, ATOM_A, res->a, RSA_MAX_SIZE) - && sexp_get_un(i, ATOM_B, res->b, RSA_MAX_SIZE) - && sexp_get_un(i, ATOM_C, res->c, RSA_MAX_SIZE) ) - { - res->super.sign = do_rsa_sign; - res->super.sign_spki = do_rsa_sign_spki; - res->super.get_verifier = do_rsa_get_verifier; - - return &res->super; - } - else - { - KILL(res); - return NULL; - } -} - - -struct signature_algorithm * -make_rsa_algorithm(struct hash_algorithm *hash, - int name, - UINT32 prefix_length, - const UINT8 *prefix) -{ - NEW(rsa_algorithm, self); - self->super.make_signer = make_rsa_signer; - self->super.make_verifier = make_rsa_verifier; - self->hash = hash; - self->name = name; - - self->prefix_length = prefix_length; - self->prefix = prefix; - - return &self->super; -} - -#define STATIC_RSA_ALGORITHM(a, n, l, id) \ -{ { STATIC_HEADER, make_rsa_signer, make_rsa_verifier }, \ - (a), (n), (l), (id) } - -/* From pkcs-1v2 - * - * md5 OBJECT IDENTIFIER ::= - * {iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 5} - * - * The parameters part of the algorithm identifier is NULL: - * - * md5Identifier ::= AlgorithmIdentifier {md5, NULL} - */ - -static const UINT8 md5_prefix[] = -{ - /* 18 octets prefic 16 octets hash, 34 total. */ - 0x30, 32, /* SEQUENCE */ - 0x30, 12, /* SEQUENCE */ - 0x06, 8, /* OBJECT IDENTIFIER */ - 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, - 0x05, 0, /* NULL */ - 0x04, 16 /* OCTET STRING */ - /* Here comes the raw hash value */ -}; - -struct rsa_algorithm rsa_md5_algorithm = -STATIC_RSA_ALGORITHM(&md5_algorithm, ATOM_RSA_PKCS1_MD5, 18, md5_prefix); - -/* From pkcs-1v2 - * - * id-sha1 OBJECT IDENTIFIER ::= - * {iso(1) identified-organization(3) oiw(14) secsig(3) - * algorithms(2) 26} - * - * The default hash function is SHA-1: - * sha1Identifier ::= AlgorithmIdentifier {id-sha1, NULL} - */ - -static const UINT8 sha1_prefix[] = -{ - /* 15 octets prefix, 20 octets hash, total 35 */ - 0x30, 33, /* SEQUENCE */ - 0x30, 9, /* SEQUENCE */ - 0x06, 5, /* OBJECT IDENTIFIER */ - 0x2b, 0x0e, 0x03, 0x02, 0x1a, - 0x05, 0, /* NULL */ - 0x04, 20 /* OCTET STRING */ - /* Here comes the raw hash value */ -}; - -struct rsa_algorithm rsa_sha1_algorithm = -STATIC_RSA_ALGORITHM(&sha1_algorithm, ATOM_RSA_PKCS1_SHA1, 15, sha1_prefix); - -struct verifier * -make_ssh_rsa_verifier(UINT32 public_length, - const UINT8 *public) -{ - struct simple_buffer buffer; - int atom; - - simple_buffer_init(&buffer, public_length, public); - - return ( (parse_atom(&buffer, &atom) - && (atom == ATOM_SSH_RSA)) - ? parse_ssh_rsa_public(&buffer) - : NULL); -} diff --git a/lsh/src/rsa.c.x b/lsh/src/rsa.c.x deleted file mode 100755 index ec039c9..0000000 Binary files a/lsh/src/rsa.c.x and /dev/null differ diff --git a/lsh/src/rsa.h b/lsh/src/rsa.h deleted file mode 100755 index 9261279..0000000 --- a/lsh/src/rsa.h +++ /dev/null @@ -1,76 +0,0 @@ -/* rsa.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_RSA_H_INCLUDED -#define LSH_RSA_H_INCLUDED - -#include "bignum.h" -#include "publickey_crypto.h" - -#define GABA_DECLARE -#include "rsa.h.x" -#undef GABA_DECLARE - -/* We don't allow keys larger than 5000 bits (i.e. 625 octets). Note - * that allowing really large keys opens for Denial-of-service - * attacks. */ - -#define RSA_MAX_SIZE 625 - -/* GABA: - (class - (name rsa_algorithm) - (super signature_algorithm) - (vars - (hash object hash_algorithm) - ; SPKI name for the algorithm - (name . int) - ; The complete prefix for a DigestInfo, including the algorithm - ; identifier for the hash function. A DigestInfo is formed by - ; cetenating this prefix with the raw hash value. - (prefix_length . UINT32) - (prefix . "const UINT8 *"))) -*/ - -struct signature_algorithm * -make_rsa_algorithm(struct hash_algorithm *hash, - int name, - UINT32 prefix_length, - const UINT8 *prefix); - -extern struct rsa_algorithm rsa_md5_algorithm; -extern struct rsa_algorithm rsa_sha1_algorithm; - -/* Non spki keys */ -struct verifier * -parse_ssh_rsa_public(struct simple_buffer *buffer); - -struct verifier * -make_ssh_rsa_verifier(UINT32 public_length, - const UINT8 *public); - -struct sexp * -rsa_generate_key(mpz_t e, struct randomness *r, UINT32 bits); - -#endif /* LSH_RSA_H_INCLUDED */ diff --git a/lsh/src/rsa.h.x b/lsh/src/rsa.h.x deleted file mode 100755 index 8495c32..0000000 Binary files a/lsh/src/rsa.h.x and /dev/null differ diff --git a/lsh/src/rsa_keygen.c b/lsh/src/rsa_keygen.c deleted file mode 100755 index 335548c..0000000 --- a/lsh/src/rsa_keygen.c +++ /dev/null @@ -1,129 +0,0 @@ -/* rsa_keygen.c - * - * Generate rsa key pairs.. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "rsa.h" - -#include "sexp.h" -#include "werror.h" - -#define SA(x) sexp_a(ATOM_##x) - -/* Takes the public exponent e as argument. */ -struct sexp * -rsa_generate_key(mpz_t e, struct randomness *r, UINT32 bits) -{ - struct sexp *key = NULL; - - mpz_t n; - mpz_t d; - mpz_t p; mpz_t q; - mpz_t a; mpz_t b; mpz_t c; - mpz_t phi; - mpz_t tmp; - - mpz_init(n); mpz_init(d); mpz_init(p), mpz_init(q); - mpz_init(a); mpz_init(b); mpz_init(c); - - mpz_init(phi); mpz_init(tmp); - - /* Generate primes */ - bignum_random_prime(p, r, bits/2); - bignum_random_prime(q, r, (bits+1)/2); - - debug("p = %xn\nq = %xn\n", p, q); - - /* Compute modulo */ - mpz_mul(n, p, q); - - debug("n = %xn\n", n); - - /* Compute phi */ - mpz_sub_ui(phi, p, 1); - mpz_sub_ui(tmp, q, 1); - mpz_mul(phi, phi, tmp); - - debug("phi = %xn\ne = %xn\n", phi, e); - - /* Compute d such that e d = 1 (mod phi) */ - /* NOTE: In gmp-2, mpz_invert sometimes generates negative inverses. */ - if (!mpz_invert(d, e, phi)) - { - debug("rsa_generate_key: e not invertible.\n"); - goto done; - } - - if (mpz_sgn(d) < 0) - mpz_fdiv_r(d, d, phi); - - debug("d = %xn\n", d); - - /* Compute extra values that are needed for the CRT optimization */ - - /* a = d % (p-1) */ - mpz_sub_ui(tmp, p, 1); - mpz_fdiv_r(a, d, tmp); - - debug("a = %xn\n", a); - - mpz_sub_ui(tmp, q, 1); - mpz_fdiv_r(b, d, tmp); - - debug("b = %xn\n", b); - - /* NOTE: In gmp-2, mpz_invert sometimes generates negative inverses. */ - if (!mpz_invert(c, q, p)) - { - werror("rsa_generate_key: q not invertible."); - goto done; - } - - if (mpz_sgn(c) < 0) - mpz_fdiv_r(c, c, p); - - debug("a = %xn\n", c); - - /* FIXME: Add sanity checking */ - - key = sexp_l(2, SA(PRIVATE_KEY), - sexp_l(9, SA(RSA_PKCS1_SHA1), - sexp_l(2, SA(N), sexp_un(n), -1), - sexp_l(2, SA(E), sexp_un(e), -1), - sexp_l(2, SA(D), sexp_un(d), -1), - sexp_l(2, SA(P), sexp_un(p), -1), - sexp_l(2, SA(Q), sexp_un(q), -1), - sexp_l(2, SA(A), sexp_un(a), -1), - sexp_l(2, SA(B), sexp_un(b), -1), - sexp_l(2, SA(C), sexp_un(c), -1), -1), -1); - - done: - mpz_clear(n); mpz_clear(d); mpz_clear(p), mpz_clear(q); - mpz_clear(a); mpz_clear(b); mpz_clear(c); - - mpz_clear(phi); mpz_clear(tmp); - - return key; -} - diff --git a/lsh/src/rsync/Makefile.am b/lsh/src/rsync/Makefile.am deleted file mode 100755 index 4ca59cc..0000000 Binary files a/lsh/src/rsync/Makefile.am and /dev/null differ diff --git a/lsh/src/rsync/Makefile.in b/lsh/src/rsync/Makefile.in deleted file mode 100755 index bf69283..0000000 --- a/lsh/src/rsync/Makefile.in +++ /dev/null @@ -1,279 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# Process this file with automake to produce Makefile.in - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = ../.. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -noinst_LIBRARIES = librsync.a -noinst_HEADERS = rsync.h - -librsync_a_SOURCES = generate.c receive.c checksum.c send.c -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../../config.h -CONFIG_CLEAN_FILES = -LIBRARIES = $(noinst_LIBRARIES) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I../.. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -librsync_a_LIBADD = -librsync_a_OBJECTS = generate.o receive.o checksum.o send.o -AR = ar -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -HEADERS = $(noinst_HEADERS) - -DIST_COMMON = README Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = $(librsync_a_SOURCES) -OBJECTS = $(librsync_a_OBJECTS) - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps src/rsync/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - - -mostlyclean-noinstLIBRARIES: - -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) - -distclean-noinstLIBRARIES: - -maintainer-clean-noinstLIBRARIES: - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -librsync.a: $(librsync_a_OBJECTS) $(librsync_a_DEPENDENCIES) - -rm -f librsync.a - $(AR) cru librsync.a $(librsync_a_OBJECTS) $(librsync_a_LIBADD) - $(RANLIB) librsync.a - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = src/rsync - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -checksum.o: checksum.c rsync.h ../../src/lsh_types.h ../../config.h \ - ../../src/nettle/md5.h -generate.o: generate.c rsync.h ../../src/lsh_types.h ../../config.h \ - ../../src/nettle/md5.h -receive.o: receive.c rsync.h ../../src/lsh_types.h ../../config.h \ - ../../src/nettle/md5.h -send.o: send.c rsync.h ../../src/lsh_types.h ../../config.h \ - ../../src/nettle/md5.h - -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile $(LIBRARIES) $(HEADERS) -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \ - mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \ - mostlyclean-am - -clean: clean-am - -distclean-am: distclean-noinstLIBRARIES distclean-compile \ - distclean-tags distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-noinstLIBRARIES \ - maintainer-clean-compile maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ -clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ -check-am installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/rsync/README b/lsh/src/rsync/README deleted file mode 100755 index f88269e..0000000 Binary files a/lsh/src/rsync/README and /dev/null differ diff --git a/lsh/src/rsync/checksum.c b/lsh/src/rsync/checksum.c deleted file mode 100755 index fe8bdec..0000000 --- a/lsh/src/rsync/checksum.c +++ /dev/null @@ -1,99 +0,0 @@ -/* checksum.c - * - * Calculate rsync specific checksums. - * - * $Id$ - */ - -#include "rsync.h" - -/* NOTE: We do calculations module 2^16. We don't need to care about - * overflow, as calculation with unsigned C variables is arithmetic - * module 2^n for some n >= 16. */ - -#define CHAR_OFFSET 0 - -/* Update a checksum of a prefix of a block - * - * For input x_i, i = 0, ..., l-1, we calculate (modulo 2^16) - * - * a_k = \sum_0^k x_i, - * b_k = \sum_0^k (l-i) x_i - * - * But in fact, we don't calculate all b_k, only the final - * value b_{l-1}, and we have the identity (by changing order of summation) - * - * b_{l-1} = \sum_0^{l-1} (l-i) x_i = \sum_0^{l-1} a_i - * - * So we keep track of the numbers c_k = \sum_0^k a_k rather than b_k. */ - -void -rsync_update_1(unsigned *ap, unsigned *cp, - UINT32 length, UINT8 *data) -{ - unsigned a = *ap; - unsigned c = *cp; - UINT32 i; - - for (i = 0; i -#include - -static void -rsync_init_block(struct rsync_generate_state *s) -{ - s->a_sum = 0; - s->c_sum = 0; - md5_init(&s->block_sum); -} - -static void -rsync_end_block(struct rsync_generate_state *s, - uint8_t *dst) -{ - WRITE_UINT16(dst, s->a_sum); - WRITE_UINT16(dst + 2, s->c_sum); - md5_final(&s->block_sum); - md5_digest(&s->block_sum, MD5_DIGEST_SIZE, dst + 4); -} - -static void -rsync_output_block(struct rsync_generate_state *s) -{ - assert(!s->buf_length); - - if (s->avail_out < RSYNC_ENTRY_SIZE) - { - rsync_end_block(s, s->buf); - s->buf_length = RSYNC_ENTRY_SIZE; - s->buf_pos = 0; - } - else - { - rsync_end_block(s, s->next_out); - s->avail_out -= RSYNC_ENTRY_SIZE; - s->next_out += RSYNC_ENTRY_SIZE; - } - rsync_init_block(s); -} - -/* Update checksums. */ - -static void -rsync_update(struct rsync_generate_state *s, - uint32_t length) -{ - assert(length <= s->avail_in); - - md5_update(&s->block_sum, length, s->next_in); - rsync_update_1(&s->a_sum, &s->c_sum, length, s->next_in); - - s->offset += length; - s->next_in += length; - s->avail_in -= length; -} - -#define OUT(c) (*s->next_out++ = (c), --s->avail_out) - -#define DONE (s->offset == s->total_length) - -enum rsync_result_t -rsync_generate(struct rsync_generate_state *s) -{ - /* Have we made any progress? */ - int progress = 0; - - for (;;) - { - if (s->avail_out && s->buf_length) - { - /* Output previously prepared data */ - unsigned left = s->buf_length - s->buf_pos; - - if (s->avail_out >= left) - { - memcpy(s->next_out, s->buf + s->buf_pos, left); - s->next_out += left; - s->avail_out -= left; - s->buf_length = 0; - progress = 1; - } else { - memcpy(s->next_out, s->buf + s->buf_pos, s->avail_out); - s->next_out += s->avail_out; - s->buf_pos += s->avail_out; - s->avail_out = 0; - - return DONE ? RSYNC_DONE : RSYNC_PROGRESS; - } - } - if (!s->avail_out && s->buf_length) - /* We have buffered data, but no output space */ - return progress ? RSYNC_PROGRESS : RSYNC_BUF_ERROR; - - /* Here, the internal buffer should be flushed. */ - assert(!s->buf_length); - - if (DONE) - return s->avail_in ? RSYNC_INPUT_ERROR : RSYNC_DONE; - - /* Now we have some output space. */ - - assert(s->left); - - if (!s->avail_in) - return progress ? RSYNC_PROGRESS : RSYNC_BUF_ERROR; - - /* And also some input to process. */ - - if (s->avail_in < s->left) - { - s->left -= s->avail_in; - rsync_update(s, s->avail_in); - return RSYNC_PROGRESS; - } - else - { - rsync_update(s, s->left); - rsync_output_block(s); - if ( (s->offset + s->block_size) > s->total_length) - { - /* Next block is the final one, and shorter than one block */ - s->left = s->total_length - s->offset; - } - else - s->left = s->block_size; - - progress = 1; - } - } -} - -enum rsync_result_t -rsync_generate_init(struct rsync_generate_state *s, - uint32_t block_size, - uint32_t size) -{ - /* Number of blocks */ - unsigned count = (size + block_size - 1) / block_size; - unsigned tail = size % block_size; - - s->block_size = block_size; - s->total_length = size; - s->offset = 0; - - /* md5_init(&s->full_sum); */ - - WRITE_UINT32(s->buf, count); - WRITE_UINT32(s->buf + 4, block_size); - WRITE_UINT32(s->buf + 8, tail); - - s->buf_length = RSYNC_HEADER_SIZE; - s->buf_pos = 0; - - s->left = block_size; - - return 1; -} - - - diff --git a/lsh/src/rsync/receive.c b/lsh/src/rsync/receive.c deleted file mode 100755 index cb4a135..0000000 --- a/lsh/src/rsync/receive.c +++ /dev/null @@ -1,152 +0,0 @@ -/* receive.c - * - * The receive end of the rsync algorithm. - * - * $Id$ */ - -#include "rsync.h" - -#include -#include - -/* Hash the data after it is copied to the output buffer. */ -static void -rsync_update(struct rsync_receive_state *s, - UINT32 length) -{ - md5_update(&s->sum_md5, length, s->next_out); - s->next_out += length; - s->avail_out -= length; -} - -#define GET() (assert(s->avail_in), s->avail_in--, *s->next_in++) - -enum rsync_result_t -rsync_receive(struct rsync_receive_state *s) -{ - int progress = 0; - - for (;;) - /* FIXME: Cast to enum rsync_receive_mode, for better type checking? */ - switch (s->state) - { - do_token: - /* Here, i is octets read */ - s->token = 0; - s->i = 0; - s->state = RSYNC_READ_TOKEN; - case RSYNC_READ_TOKEN: - if (!s->avail_in) - return progress ? RSYNC_PROGRESS : RSYNC_BUF_ERROR; - - s->token = (s->token << 8) | GET(); - s->i++; - - progress = 1; - - if (s->i == 4) - { - if (!s->token) - goto do_checksum; - - else if (! (s->token & 0x80000000)) - { - s->i = s->token; - goto do_literal; - } - else - { - /* Index is one's complement */ - s->token = ~s->token; - goto do_lookup; - } - } - break; - - do_literal: - /* Here, i is the number of octets to read. */ - s->state = RSYNC_READ_LITERAL; - case RSYNC_READ_LITERAL: - { - UINT32 avail = MIN(s->avail_in, s->avail_out); - if (!avail) - return progress ? RSYNC_PROGRESS : RSYNC_BUF_ERROR; - - if (avail < s->i) - { - memcpy(s->next_out, s->next_in, avail); - rsync_update(s, avail); - s->next_in += avail; - s->avail_in -= avail; - s->i -= avail; - } - else - { - memcpy(s->next_out, s->next_in, s->i); - rsync_update(s, s->i); - s->next_in += s->i; - s->avail_in -= s->i; - goto do_token; - } - } - break; - - do_lookup: - s->state = RSYNC_READ_LOOKUP; - s->i = 0; - case RSYNC_READ_LOOKUP: - { - UINT32 done; - - if (!s->avail_out) - return progress ? RSYNC_PROGRESS : RSYNC_BUF_ERROR; - - switch (s->lookup(s->opaque, s->next_out, s->avail_out, - s->token, s->i, &done)) - { - case 1: - rsync_update(s, done); - goto do_token; - case 0: - rsync_update(s, done); - s->i += done; - break; - case -1: - return RSYNC_INPUT_ERROR; - default: - abort(); - } - } - break; - - do_checksum: - /* i is number of octets read */ - s->i = 0; - md5_final(&s->sum_md5); - md5_digest(&s->sum_md5, MD5_DIGEST_SIZE, s->buf); - s->state = RSYNC_READ_CHECKSUM; - case RSYNC_READ_CHECKSUM: - if (!s->avail_in) - return progress ? RSYNC_PROGRESS : RSYNC_BUF_ERROR; - - if (GET() != s->buf[s->i++]) - return RSYNC_INPUT_ERROR; - - if (s->i == RSYNC_SUM_SIZE) - { - s->state = RSYNC_READ_INVALID; - return RSYNC_DONE; - } - break; - - default: - abort(); - } -} - -void -rsync_receive_init(struct rsync_receive_state *s) -{ - s->state = RSYNC_READ_TOKEN; - s->i = 0; -} diff --git a/lsh/src/rsync/rsync.h b/lsh/src/rsync/rsync.h deleted file mode 100755 index 6d097e4..0000000 --- a/lsh/src/rsync/rsync.h +++ /dev/null @@ -1,273 +0,0 @@ -/* rsync.h - * - * $Id$ - */ - -/* - Copyright (C) Andrew Tridgell 1996 - Copyright (C) Paul Mackerras 1996 - - 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 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 should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* Hacked by Niels Möller */ -#ifndef RSYNC_H_INCLUDED -#define RSYNC_H_INCLUDED - -#if LSH -# include "lsh_types.h" -#else -# if HAVE_CONFIG_H -# include "config.h" -# endif -#endif - -#include - -#include - -#include - -/* FIXME: replace with proper autoconf check */ -#define OFF_T size_t - -#define RSYNC_SUM_SIZE MD5_DIGEST_SIZE - -/* Size of block count, block size, tail */ -#define RSYNC_HEADER_SIZE 12 - -/* Size of weak sum, md5 sum */ -#define RSYNC_ENTRY_SIZE 20 - -#define RSYNC_TOKEN_SIZE 4 - -/* Initial checksum calculations (by the receiver) */ - -/* NOTE: Unlike zlib, we want to know the file size before we start. - * This could be relaxed, but requires some modifications to the - * protocol. */ -struct rsync_generate_state -{ - /* Public fields */ - uint8_t *next_in; - uint32_t avail_in; - uint8_t *next_out; - uint32_t avail_out; - - uint32_t block_size; - uint32_t total_length; - uint32_t offset; /* Current offset in input file. */ - - /* Weak check sum */ - unsigned a_sum; - unsigned c_sum; - - struct md5_ctx block_sum; - - /* Internal state */ - uint8_t buf[RSYNC_ENTRY_SIZE]; - uint8_t buf_length; /* Zero means no buffered data. */ - uint8_t buf_pos; - - uint32_t left; /* Amount left of current block */ -}; - -/* Return values */ -enum rsync_result_t -{ - /* Things are working fine */ - RSYNC_PROGRESS, - - /* All data is flushed to the output */ - RSYNC_DONE, - - /* No progress possible */ - RSYNC_BUF_ERROR, - - /* Invalid input */ - RSYNC_INPUT_ERROR, - - /* Out of memory (can happen only for rsync_read_table and rsync_send_init) */ - RSYNC_MEMORY -}; - -enum rsync_result_t -rsync_generate(struct rsync_generate_state *state); - -enum rsync_result_t -rsync_generate_init(struct rsync_generate_state *state, - uint32_t block_size, - uint32_t size); - - -/* Receiving a file. */ - -/* The receiver calls this function to copy at most LENGTH octets of - * local data to the output buffer. - * - * OPAQUE is state private to the lookup function. DST and LENGTH give - * the location of the destination buffer. INDEX is the block to read, - * and OFFSET is a location within that block. - * - * The function should return - * - * -1 on failure (and it has to check INDEX and OFFSET for validity). - * 0 if copying succeeds, but not all of the block was copied. - * 1 if copying succeeds, and the final octet of the data was copied. - * - * On success, the function should set *DONE to the amount of data copied. - */ - -typedef int (*rsync_lookup_read_t)(void *opaque, - uint8_t *dst, uint32_t length, - uint32_t index, uint32_t offset, uint32_t *done); - -struct rsync_receive_state -{ - /* Public fields */ - uint8_t *next_in; - uint32_t avail_in; - uint8_t *next_out; - uint32_t avail_out; - - uint32_t block_size; - /* uint32_t offset; */ /* Current offset in output file. */ - - rsync_lookup_read_t lookup; - void *opaque; - - struct md5_ctx sum_md5; /* Sum of all the output data */ - - /* Private state */ - - enum { - /* Reading a partial token */ - RSYNC_READ_TOKEN, - - /* Reading a literal */ - RSYNC_READ_LITERAL, - - /* Copying a local block */ - RSYNC_READ_LOOKUP, - - /* Reading final md5 sum */ - RSYNC_READ_CHECKSUM, - - /* Results in error */ - RSYNC_READ_INVALID - } state; - - uint32_t token; - uint32_t i; - - uint8_t buf[RSYNC_SUM_SIZE]; -}; - -enum rsync_result_t -rsync_receive(struct rsync_receive_state *state); - -void -rsync_receive_init(struct rsync_receive_state *state); - -/* Sending files */ - -struct rsync_table; -struct rsync_node; - -struct rsync_read_table_state -{ - /* Public fields */ - struct rsync_table *table; - - /* Limits */ - uint32_t max_count; - uint32_t max_block_size; - - uint32_t count; /* Block count */ - uint32_t block_size; - uint32_t remainder; - - /* Private state */ - uint8_t buf[RSYNC_ENTRY_SIZE]; - unsigned pos; -}; - -enum rsync_result_t -rsync_read_table(struct rsync_read_table_state *state, - uint32_t length, uint8_t *input); - -/* For reading the list of checksums. */ -struct rsync_send_state -{ - /* Public fields */ - uint8_t *next_in; - uint32_t avail_in; - uint8_t *next_out; - uint32_t avail_out; - - struct rsync_table *table; - - /* Internal state */ - - enum { RSYNC_SEND_READING, RSYNC_SEND_WRITING } state; - - /* Non-zero if the final EOF-token has been buffered for output. */ - int final; - - /* The next block that we expect */ - struct rsync_node *guess; - - /* The input and output buffer. */ - - uint32_t buf_size; - /* The allocated size includes space for header and trailer, - * besides the input buffer of BUD_SIZE octets. */ - uint8_t *buf; - - /* In writing mode, we copy the data from I to OUT_END */ - uint32_t i; - uint32_t out_end; - - /* Size of buffer (relevant in primarily in read mode). - * It does not include the buffer header. */ - - uint32_t size; - - unsigned sum_a; - unsigned sum_b; - - struct md5_ctx sum_md5; /* Sum of all the input data */ - -}; - -enum rsync_result_t -rsync_send_init(struct rsync_send_state *state, - struct rsync_table *table); - -enum rsync_result_t -rsync_send(struct rsync_send_state *state, int flush); - -void rsync_send_free(struct rsync_send_state *state); - -void -rsync_update_1(unsigned *ap, unsigned *cp, - uint32_t length, uint8_t *data); - -struct rsync_node * -rsync_search(unsigned *ap, unsigned *bp, unsigned block_size, - uint32_t length, uint8_t *start, uint8_t *end, - uint32_t *found, struct rsync_node **hash); - -#endif /* RSYNC_H_INCLUDED */ diff --git a/lsh/src/rsync/send.c b/lsh/src/rsync/send.c deleted file mode 100755 index 07cc1c5..0000000 --- a/lsh/src/rsync/send.c +++ /dev/null @@ -1,577 +0,0 @@ -/* send.c - * - * The sending end of the rsync algorithm. - * - * $Id$ */ - -#include "rsync.h" - -#include -#include - -#define HASH_SIZE 0x10000 -#define HASH_SUM(a, b) (((a) ^ (b)) & 0xffff) -#define COMBINE_SUM(a, b) ((a) | ((b) << 16)) - -struct rsync_node -{ - struct rsync_node *next; - uint32_t index; - uint32_t length; - - uint32_t sum_weak; /* a | b << 16*/ - - uint8_t sum_md5[MD5_DIGEST_SIZE]; -}; - -struct rsync_table -{ - struct rsync_node *hash[HASH_SIZE]; - uint32_t alloc_size; - uint32_t size; - uint32_t block_size; - - struct rsync_node all_nodes[1]; -}; - -static struct rsync_table * -make_rsync_table(uint32_t count, uint32_t block_size) -{ - unsigned i; - - struct rsync_table *table = - malloc(sizeof(struct rsync_table) - sizeof(struct rsync_node) - + count * sizeof(struct rsync_node)); - - if (!table) - return NULL; - - for (i = 0; ihash[i] = NULL; - - table->alloc_size = count; - table->size = 0; - - table->block_size = block_size; - - return table; -} - -static struct rsync_node * -rsync_add_entry(struct rsync_table *table, - uint8_t *input) -{ - struct rsync_node *node; - unsigned a, b; - unsigned h; - - assert(table->size < table->alloc_size); - node = table->all_nodes + table->size; - - node->index = table->size++; - - /* NOTE: Length field is left uninitialized for now */ - - a = READ_UINT16(input); - b = READ_UINT16(input + 2); - - node->sum_weak = COMBINE_SUM(a, b); - memcpy(node->sum_md5, input + 4, RSYNC_SUM_SIZE); - - h = HASH_SUM(a, b); - node->next = table->hash[h]; - table->hash[h] = node; - - return node; -} - -static struct rsync_node * -rsync_lookup_1(struct rsync_node *n, uint32_t weak) -{ - while (n && (n->sum_weak != weak)) - n = n->next; - - return n; -} - -static struct rsync_node * -rsync_lookup_2(struct rsync_node *n, uint32_t weak, - const uint8_t *digest) -{ - /* FIXME: This could be speeded up slightly if the hash lists were - * kept sorted on weak_sum. */ - while (n && ( (n->sum_weak != weak) - || memcmp(n->sum_md5, digest, RSYNC_SUM_SIZE))) - n = n->next; - - return n; -} - -static struct rsync_node * -rsync_lookup_block(struct rsync_send_state *s, - uint32_t start, uint32_t size) - -{ - struct rsync_node *n; - - assert(size); - - if (size == s->table->block_size) - { - n = s->table->hash[HASH_SUM(s->sum_a, s->sum_b)]; - if (n) - { - /* The first block might match. */ - uint32_t weak = COMBINE_SUM(s->sum_a, s->sum_b); - struct md5_ctx m; - uint8_t digest[MD5_DIGEST_SIZE]; - - /* First check our guess. */ - if (s->guess && (s->guess->sum_weak == weak)) - { - md5_init(&m); - md5_update(&m, s->table->block_size, s->buf + start); - md5_final(&m); - md5_digest(&m, MD5_DIGEST_SIZE, digest); - - if (!memcmp(s->guess->sum_md5, digest, RSYNC_SUM_SIZE)) - { - /* Correct guess! */ - n = s->guess; - } - else - n = rsync_lookup_2(n, weak, digest); - } - else - { - n = rsync_lookup_1(n, weak); - if (n) - { - md5_init(&m); - md5_update(&m, s->table->block_size, s->buf + start); - md5_final(&m); - md5_digest(&m, MD5_DIGEST_SIZE, digest); - - n = rsync_lookup_2(n, weak, digest); - } - } - } - if (n) - { - /* Guess for the next block. */ - s->guess = n + 1; - - /* Does it make sense? */ - if ( (s->guess == (s->table->all_nodes + s->table->alloc_size)) - || (s->guess->length < s->table->block_size) ) - s->guess = NULL; - } - } - else - { - /* A smaller block. It could only match the final block. */ - s->guess = NULL; - n = s->table->all_nodes + s->table->alloc_size - 1; - if (size == n->length) - { - uint32_t weak = COMBINE_SUM(s->sum_a, s->sum_b); - - if (weak == n->sum_weak) - { - struct md5_ctx m; - uint8_t digest[MD5_DIGEST_SIZE]; - - md5_init(&m); - md5_update(&m, size, s->buf + start); - md5_final(&m); - md5_digest(&m, MD5_DIGEST_SIZE, digest); - - if (!memcmp(n->sum_md5, digest, RSYNC_SUM_SIZE)) - return n; - } - } - } - return NULL; -} - - -enum rsync_result_t -rsync_read_table(struct rsync_read_table_state *s, - uint32_t length, uint8_t *input) -{ - while (length) - if (!s->table) - { - uint32_t left = RSYNC_HEADER_SIZE - s->pos; - if (length < left) - { - memcpy(s->buf + s->pos, input, length); - s->pos += length; - return RSYNC_PROGRESS; - } - else - { - uint32_t block_size; - - memcpy(s->buf + s->pos, input, left); - input += left; - length -= left; - s->pos = 0; - - s->count = READ_UINT32(s->buf); - block_size = READ_UINT32(s->buf + 4); - s->remainder = READ_UINT32(s->buf + 8); - - if ( (s->count > s->max_count) - || (s->block_size > s->max_block_size) - || (s->remainder >= s->block_size)) - return RSYNC_INPUT_ERROR; - - s->table = make_rsync_table(s->count, block_size); - - return (s->table) ? RSYNC_PROGRESS : RSYNC_MEMORY; - } - } - else - { - struct rsync_node *node; - - if (s->pos) - { - /* Do partial entries */ - uint32_t left = RSYNC_ENTRY_SIZE - s->pos; - if (length < left) - { - memcpy(s->buf + s->pos, input, length); - s->pos += length; - return RSYNC_PROGRESS; - } - else - { - memcpy(s->buf + s->pos, input, left); - input += left; - length -= left; - s->pos = 0; - - node = rsync_add_entry(s->table, s->buf); - } - } - else if (length < RSYNC_ENTRY_SIZE) - { - /* New partial block */ - memcpy(s->buf, input, length); - s->pos = length; - return RSYNC_PROGRESS; - } - else - { - node = rsync_add_entry(s->table, input); - length -= RSYNC_ENTRY_SIZE; - input += RSYNC_ENTRY_SIZE; - } - - node->length = s->block_size; - - if (s->table->size == s->table->alloc_size) - { - if (s->remainder) - node->length = s->remainder; - - return length ? RSYNC_INPUT_ERROR : RSYNC_DONE; - } - } - return RSYNC_PROGRESS; -} - -/* While searching, we have to keep a buffer of previous block of - * data. Our buffer BUF consists of SIZE octets starting after the header space. - * - * We may have less than one block of data available, in that case we - * must collect more data before we can start searching. If we collect - * more than buf_size (usually twice the block size), we output a - * literal. */ - -#define BUFFER_HEADER RSYNC_TOKEN_SIZE -#define BUFFER_TRAILER (RSYNC_TOKEN_SIZE + RSYNC_SUM_SIZE) - -enum rsync_result_t -rsync_send_init(struct rsync_send_state *s, - struct rsync_table *table) -{ - assert(table->block_size <= 0xffffffffU/2); - - /* The buffer must be at least twice the block size. */ - s->buf_size = table->block_size * 3; - s->table = table; - - s->buf = malloc(s->buf_size + BUFFER_HEADER + BUFFER_TRAILER); - - if (!s->buf) - return RSYNC_MEMORY; - - s->size = 0; - - s->sum_a = s->sum_b = 0; - - md5_init(&s->sum_md5); - - s->state = RSYNC_SEND_READING; - s->final = 0; - - return RSYNC_PROGRESS; -} - -static void -rsync_send_eof(struct rsync_send_state *s) -{ - /* FIXME: Try matching the final block. */ - uint32_t end = 0; - - /* If buffer is non-empty, add a literal. */ - if (s->size) - { - WRITE_UINT32(s->buf, s->size); - end = s->size + 4; - } - - /* Write EOF marker */ - WRITE_UINT32(s->buf + end, 0); - - end += 4; - - /* And final hash of the entire file */ - md5_final(&s->sum_md5); - md5_digest(&s->sum_md5, MD5_DIGEST_SIZE, s->buf + end); - - end += RSYNC_SUM_SIZE; - - s->size = 0; - s->i = 0; - s->out_end = end; - s->final = 1; - s->state = RSYNC_SEND_WRITING; -} - -/* The start of the input buffer */ -#define BUF (s->buf + BUFFER_HEADER) - -/* Copy from input buffer, and update md5 sum. */ -static void -rsync_send_copy_in(struct rsync_send_state *s, - uint32_t length) -{ - assert(length <= s->avail_in); - - md5_update(&s->sum_md5, length, s->next_in); - memcpy(BUF + s->size, s->next_in, length); - s->next_in += length; - s->avail_in -= length; - s->size += length; -} - -static void -rsync_send_read(struct rsync_send_state *s, uint32_t left) -{ - /* The current hash does not include a complete block. We need more data. */ - struct rsync_node *n; - uint32_t avail = MIN(left, s->avail_in); - - assert(avail); - - /* Update weak sum */ - rsync_update_1(&s->sum_a, &s->sum_b, avail, s->next_in); - rsync_send_copy_in(s, avail); - - if (s->size < s->table->block_size) - return; - - /* We have a complete block. Check if we have a match already. */ - n = rsync_lookup_block(s, 0, s->size); - - if (n) - { - /* We have a match! */ - uint32_t token = ~(n - s->table->all_nodes); - - WRITE_UINT32(s->buf, token); - - s->size = 0; - s->i = 0; - s->out_end = RSYNC_TOKEN_SIZE; - s->state = RSYNC_SEND_WRITING; - } -} - -static void -rsync_send_search(struct rsync_send_state *s) -{ - uint32_t avail; - uint32_t done; - struct rsync_node *n; - - assert(s->size >= s->table->block_size); - assert(s->size < s->buf_size); - - avail = MIN(s->avail_in, s->buf_size - s->size); - - n = rsync_search(&s->sum_a, &s->sum_b, s->table->block_size, - avail, - BUF + s->size - s->table->block_size, - s->next_in, - &done, s->table->hash); - - /* done should be non-zero */ - assert(done); - - if (n) - { - /* The block - * - * BUF[size + done - block_size...size] + next_in[0...done] - * - * might match */ - - uint32_t weak = COMBINE_SUM(s->sum_a, s->sum_b); - - n = rsync_lookup_1(n, weak); - - if (n) - { - struct md5_ctx m; - uint8_t digest[MD5_DIGEST_SIZE]; - uint32_t start = s->size + done - s->table->block_size; - - assert(start); - - /* NOTE: Don't bother examining our guess. */ - - md5_init(&m); - md5_update(&m, - s->table->block_size - done, - BUF + start); - md5_update(&m, done, s->next_in); - md5_final(&m); - md5_digest(&m, MD5_DIGEST_SIZE, digest); - - n = rsync_lookup_2(n, weak, digest); - - if (n) - { - /* Match found! */ - - /* Token is one-complement of the index */ - uint32_t token = ~(n - s->table->all_nodes); - - /* Hash input before we discard it */ - md5_update(&s->sum_md5, done, s->next_in); - s->next_in += done; - s->avail_in -= done; - - /* Length of literal */ - WRITE_UINT32(s->buf, start); - - /* Block reference, written after the literal data. */ - WRITE_UINT32(BUF + start, token); - - s->size = 0; - s->i = 0; - s->out_end = start + (2 * RSYNC_TOKEN_SIZE); - s->state = RSYNC_SEND_WRITING; - - return; - } - } - } - - /* No match so far. Copy the data up to the apparent match, or all - * available if there were no apparent match. */ - rsync_send_copy_in(s, done); -} - -static void -rsync_send_flush(struct rsync_send_state *s) -{ - /* Entire buffer filled, but no match. Make a literal - * out of all but the last block in the buffer */ - - uint32_t length = s->size - s->table->block_size; - WRITE_UINT32(s->buf, length); - - s->size = s->table->block_size; - s->i = 0; - s->out_end = length + RSYNC_TOKEN_SIZE; - s->state = RSYNC_SEND_WRITING; -} - -static int -rsync_send_write(struct rsync_send_state *s) -{ - /* Trassmits octets between I and OUT_END */ - - uint32_t left = s->out_end - s->i; - if (left <= s->avail_out) - { - memcpy(s->next_out, s->buf + s->i, left); - s->next_out += left; - s->avail_out -= left; - s->state = RSYNC_SEND_READING; - - return 1; - } - else - { - memcpy(s->next_out, s->buf + s->i, s->avail_out); - s->next_out += s->avail_out; - s->i += s->avail_out; - s->avail_out = 0; - - return 0; - } -} - -enum rsync_result_t -rsync_send(struct rsync_send_state *s, int flush) -{ - enum rsync_result_t result = RSYNC_BUF_ERROR; - - for (;;) - { - switch (s->state) - { - case RSYNC_SEND_READING: - assert(!s->final); - assert(s->size <= s->buf_size); - - if (!s->avail_in) - { - if (!flush) - return result; - - rsync_send_eof(s); - continue; - } - - if (s->size == s->buf_size) - rsync_send_flush(s); - else - { - result = RSYNC_PROGRESS; - - if (s->size < s->table->block_size) - rsync_send_read(s, s->table->block_size - s->size); - else - rsync_send_search(s); - } - break; - - case RSYNC_SEND_WRITING: - if (!s->avail_out) - return result; - - if (rsync_send_write(s) && s->final) - return RSYNC_DONE; - else - result = RSYNC_PROGRESS; - } - } -} diff --git a/lsh/src/scm/Makefile.am b/lsh/src/scm/Makefile.am deleted file mode 100755 index c4fda0c..0000000 --- a/lsh/src/scm/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -## Automatically generated by make_am, Wed Aug 29 23:52:09 CEST 2001 -## Process this file with automake to produce Makefile.in - - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = compiler.scm gaba.scm make-char-classes.scm \ - guile-compat.scm scsh-compat.scm Makefile.am.in diff --git a/lsh/src/scm/Makefile.am.in b/lsh/src/scm/Makefile.am.in deleted file mode 100755 index 74a7fe0..0000000 Binary files a/lsh/src/scm/Makefile.am.in and /dev/null differ diff --git a/lsh/src/scm/Makefile.in b/lsh/src/scm/Makefile.in deleted file mode 100755 index 3c4e877..0000000 --- a/lsh/src/scm/Makefile.in +++ /dev/null @@ -1,180 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = ../.. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = compiler.scm gaba.scm make-char-classes.scm guile-compat.scm scsh-compat.scm Makefile.am.in - -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../../config.h -CONFIG_CLEAN_FILES = -DIST_COMMON = Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -all: all-redirect -.SUFFIXES: -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps src/scm/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -tags: TAGS -TAGS: - - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = src/scm - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: tags distdir info-am info dvi-am dvi check check-am \ -installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/scm/compiler.scm b/lsh/src/scm/compiler.scm deleted file mode 100755 index 1ded8cd..0000000 Binary files a/lsh/src/scm/compiler.scm and /dev/null differ diff --git a/lsh/src/scm/gaba.scm b/lsh/src/scm/gaba.scm deleted file mode 100755 index 014bac5..0000000 Binary files a/lsh/src/scm/gaba.scm and /dev/null differ diff --git a/lsh/src/scm/guile-compat.scm b/lsh/src/scm/guile-compat.scm deleted file mode 100755 index 832903f..0000000 Binary files a/lsh/src/scm/guile-compat.scm and /dev/null differ diff --git a/lsh/src/scm/make-char-classes.scm b/lsh/src/scm/make-char-classes.scm deleted file mode 100755 index a582c8e..0000000 Binary files a/lsh/src/scm/make-char-classes.scm and /dev/null differ diff --git a/lsh/src/scm/scsh-compat.scm b/lsh/src/scm/scsh-compat.scm deleted file mode 100755 index 99d8779..0000000 Binary files a/lsh/src/scm/scsh-compat.scm and /dev/null differ diff --git a/lsh/src/serpent.c b/lsh/src/serpent.c deleted file mode 100755 index 8ff293a..0000000 --- a/lsh/src/serpent.c +++ /dev/null @@ -1,101 +0,0 @@ -/* serpent.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999, 2000 Niels Möller, Rafael R. Sevilla - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/serpent.h" - -#include - -#include "serpent.c.x" - -/* Serpent */ -/* GABA: - (class - (name serpent_instance) - (super crypto_instance) - (vars - (ctx . "struct serpent_ctx"))) -*/ - -static void -do_serpent_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(serpent_instance, self, s); - - serpent_encrypt(&self->ctx, length, dst, src); -} - -static void -do_serpent_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(serpent_instance, self, s); - - serpent_decrypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_serpent_instance(struct crypto_algorithm *algorithm, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(serpent_instance, self); - - self->super.block_size = SERPENT_BLOCK_SIZE; - self->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_serpent_encrypt - : do_serpent_decrypt); - - serpent_set_key(&self->ctx, algorithm->key_size, key); - - return(&self->super); -} - -struct crypto_algorithm * -make_serpent_algorithm(UINT32 key_size) -{ - NEW(crypto_algorithm, algorithm); - - assert(key_size >= SERPENT_MIN_KEY_SIZE); - assert(key_size <= SERPENT_MAX_KEY_SIZE); - - algorithm->block_size = SERPENT_BLOCK_SIZE; - algorithm->key_size = key_size; - algorithm->iv_size = 0; - algorithm->make_crypt = make_serpent_instance; - - return algorithm; -} - -struct crypto_algorithm serpent128_algorithm = -{ STATIC_HEADER, SERPENT_BLOCK_SIZE, 16, 0, make_serpent_instance}; - -struct crypto_algorithm serpent192_algorithm = -{ STATIC_HEADER, SERPENT_BLOCK_SIZE, 24, 0, make_serpent_instance}; - -struct crypto_algorithm serpent256_algorithm = -{ STATIC_HEADER, SERPENT_BLOCK_SIZE, 32, 0, make_serpent_instance}; diff --git a/lsh/src/serpent.c.x b/lsh/src/serpent.c.x deleted file mode 100755 index 367fc5d..0000000 Binary files a/lsh/src/serpent.c.x and /dev/null differ diff --git a/lsh/src/server.c b/lsh/src/server.c deleted file mode 100755 index f447181..0000000 --- a/lsh/src/server.c +++ /dev/null @@ -1,170 +0,0 @@ -/* server.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "server.h" - -#include "abstract_io.h" -#include "channel.h" -#include "compress.h" -#include "connection.h" -#include "debug.h" -#include "disconnect.h" -#include "format.h" -#include "keyexchange.h" -#include "read_line.h" -#include "read_packet.h" -#include "reaper.h" -#include "ssh.h" -#include "unpad.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - - -#include "server.c.x" - - -static struct lsh_string * -format_service_accept(int name) -{ - return ssh_format("%c%a", SSH_MSG_SERVICE_ACCEPT, name); -} - -#if DATAFELLOWS_WORKAROUNDS -static struct lsh_string * -format_service_accept_kludge(void) -{ - return ssh_format("%c", SSH_MSG_SERVICE_ACCEPT); -} -#endif /* DATAFELLOWS_WORKAROUNDS */ - - -/* GABA: - (class - (name service_handler) - (super packet_handler) - (vars - (services object alist) - (c object command_continuation) - (e object exception_handler))) -*/ - -static void -do_service_request(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(service_handler, closure, c); - - struct simple_buffer buffer; - unsigned msg_number; - int name; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_SERVICE_REQUEST) - && parse_atom(&buffer, &name) - && parse_eod(&buffer)) - { - if (name) - { - CAST_SUBTYPE(command, service, ALIST_GET(closure->services, name)); - if (service) - { - /* Don't accept any further service requests */ - connection->dispatch[SSH_MSG_SERVICE_REQUEST] - = &connection_fail_handler; - - /* Start service */ -#if DATAFELLOWS_WORKAROUNDS - if (connection->peer_flags & PEER_SERVICE_ACCEPT_KLUDGE) - C_WRITE(connection, format_service_accept_kludge()); - else -#endif /* DATAFELLOWS_WORKAROUNDS */ - C_WRITE(connection, format_service_accept(name)); - - COMMAND_CALL(service, connection, - closure->c, closure->e); - return; - } - } - EXCEPTION_RAISE(connection->e, - make_protocol_exception(SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, NULL)); - - } - else - PROTOCOL_ERROR(connection->e, "Invalid SERVICE_REQUEST message"); -} - -static struct packet_handler * -make_service_request_handler(struct alist *services, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(service_handler, self); - - self->super.handler = do_service_request; - self->services = services; - self->c = c; - self->e = e; - - return &self->super; -} - - -/* GABA: - (class - (name offer_service) - (super command) - (vars - (services object alist))) -*/ - -static void -do_offer_service(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(offer_service, self, s); - CAST(ssh_connection, connection, x); - - connection->dispatch[SSH_MSG_SERVICE_REQUEST] - = make_service_request_handler(self->services, c, e); -} - -struct command *make_offer_service(struct alist *services) -{ - NEW(offer_service, self); - - self->super.call = do_offer_service; - self->services = services; - - return &self->super; -} - - diff --git a/lsh/src/server.c.x b/lsh/src/server.c.x deleted file mode 100755 index 0a70fad..0000000 Binary files a/lsh/src/server.c.x and /dev/null differ diff --git a/lsh/src/server.h b/lsh/src/server.h deleted file mode 100755 index 3e6e742..0000000 --- a/lsh/src/server.h +++ /dev/null @@ -1,32 +0,0 @@ -/* server.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SERVER_H_INCLUDED -#define LSH_SERVER_H_INCLUDED - -#include "command.h" -#include "alist.h" - -struct command *make_offer_service(struct alist *services); - -#endif /* LSH_SERVER_H_INCLUDED */ diff --git a/lsh/src/server_authorization.c b/lsh/src/server_authorization.c deleted file mode 100755 index 32c35f4..0000000 --- a/lsh/src/server_authorization.c +++ /dev/null @@ -1,116 +0,0 @@ -/* server_authorization.c - * - * user authorization database - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should 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 - */ - -#include "server_authorization.h" - -#include "dsa.h" -#include "format.h" -#include "rsa.h" -#include "server_userauth.h" -#include "sexp.h" -#include "spki.h" -#include "xalloc.h" - -#include - -#include "server_authorization.c.x" - -/* For now a key is authorized if a file named as the hash of the - SPKI pubkey exists */ - -/* GABA: - (class - (name authorization_db) - (super lookup_verifier) - (vars - (index_name string) - ;; (signalgo object signature_algorithm) - (hashalgo object hash_algorithm))) -*/ - -static struct verifier * -do_key_lookup(struct lookup_verifier *c, - int method, - struct lsh_user *keyholder, - struct lsh_string *key) -{ - CAST(authorization_db, closure, c); - struct lsh_string *filename; - - struct verifier *v = NULL; - - assert(keyholder); - - switch (method) - { - default: - return NULL; - - /* FIXME: SPKI support. */ - - case ATOM_SSH_DSS: - /* FIXME: Perhaps this is the right place to choose to apply the - * PEER_SSH_DSS_KLUDGE? */ - - v = make_ssh_dss_verifier(key->length, key->data); - break; - - case ATOM_SSH_RSA: - v = make_ssh_rsa_verifier(key->length, key->data); - break; - } - - if (!v) - return NULL; - - /* FIXME: Proper spki acl reading should go here. */ - - filename = ssh_format(".lsh/%lS/%lxfS", - closure->index_name, - hash_string(closure->hashalgo, - sexp_format(spki_make_public_key(v), - SEXP_CANONICAL, 0), - 1)); - - if (USER_FILE_EXISTS(keyholder, filename, 1)) - return v; - - return NULL; -} - -struct lookup_verifier * -make_authorization_db(struct lsh_string *index_name, - /* struct signature_algorithm *s, */ - struct hash_algorithm *h) -{ - NEW(authorization_db, res); - - res->super.lookup = do_key_lookup; - res->index_name = index_name; - /* res->signalgo = s; */ - res->hashalgo = h; - - return &res->super; -} diff --git a/lsh/src/server_authorization.c.x b/lsh/src/server_authorization.c.x deleted file mode 100755 index 214aafe..0000000 Binary files a/lsh/src/server_authorization.c.x and /dev/null differ diff --git a/lsh/src/server_authorization.h b/lsh/src/server_authorization.h deleted file mode 100755 index 206580c..0000000 --- a/lsh/src/server_authorization.h +++ /dev/null @@ -1,37 +0,0 @@ -/* server_authorization.c - * - * user authorization database - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should 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 - */ - -#ifndef LSH_SERVER_AUTHORIZATION_H_INCLUDED -#define LSH_SERVER_AUTHORIZATION_H_INCLUDED - -#include "lookup_verifier.h" -#include "publickey_crypto.h" - -struct lookup_verifier * -make_authorization_db(struct lsh_string *index_name, - /* struct signature_algorithm *s, */ - struct hash_algorithm *h); - -#endif /* LSH_SERVER_AUTHORIZATION_H_INCLUDED */ diff --git a/lsh/src/server_keyexchange.c b/lsh/src/server_keyexchange.c deleted file mode 100755 index 5b6f9ae..0000000 --- a/lsh/src/server_keyexchange.c +++ /dev/null @@ -1,378 +0,0 @@ -/* server_keyexchange.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "server_keyexchange.h" - -#include "atoms.h" -#include "command.h" -#include "debug.h" -#include "dsa.h" -#include "format.h" -#include "sexp_commands.h" -#include "srp.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "server_keyexchange.c.x" - -/* GABA: - (class - (name dh_server_exchange) - (super keyexchange_algorithm) - (vars - (dh object dh_method))) -*/ - -/* Handler for the kex_dh_reply message */ -/* GABA: - (class - (name dh_server) - (super packet_handler) - (vars - (dh struct dh_instance) - (hostkey_algorithm . int) - (server_key string) - (signer object signer) - (algorithms object object_list))) -*/ - -static void -do_handle_dh_init(struct packet_handler *c, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(dh_server, closure, c); - int res; - - trace("handle_dh_init\n"); - - res = dh_process_client_msg(&closure->dh, packet); - - if (!res) - { - disconnect_kex_failed(connection, "Bad dh-init\r\n"); - return; - } - - /* Send server's message, to complete key exchange */ - C_WRITE(connection, - dh_make_server_msg(&closure->dh, - closure->server_key, - closure->hostkey_algorithm, - closure->signer)); - - connection->dispatch[SSH_MSG_KEXDH_INIT] = &connection_fail_handler; - - keyexchange_finish(connection, closure->algorithms, - closure->dh.method->H, - closure->dh.exchange_hash, - closure->dh.K); - - /* For gc */ - closure->dh.K = NULL; - closure->dh.exchange_hash = NULL; - - /* Try to purge information about the key exchange */ - KILL(closure); -} - -static void -do_init_server_dh(struct keyexchange_algorithm *c, - struct ssh_connection *connection, - int hostkey_algorithm, - struct lsh_object *extra, - struct object_list *algorithms) -{ - CAST(dh_server_exchange, closure, c); - CAST_SUBTYPE(alist, keys, extra); - CAST(keypair, key, ALIST_GET(keys, - hostkey_algorithm)); - - if (!key) - { - werror("Keypair for for selected signature-algorithm not found!\n"); - disconnect_kex_failed(connection, "Configuration error"); - return; - } - else - { - NEW(dh_server, dh); - - /* Initialize */ - dh->super.handler = do_handle_dh_init; - init_dh_instance(closure->dh, &dh->dh, connection); - - dh->server_key = lsh_string_dup(key->public); - dh->signer = key->private; - -#if DATAFELLOWS_WORKAROUNDS - if ( (hostkey_algorithm == ATOM_SSH_DSS) - && (connection->peer_flags & PEER_SSH_DSS_KLUDGE)) - { - hostkey_algorithm = ATOM_SSH_DSS_KLUDGE_LOCAL; - } - else -#endif - dh->hostkey_algorithm = hostkey_algorithm; - - dh->algorithms = algorithms; - - /* Generate server's secret exponent */ - dh_make_server_secret(&dh->dh); - - /* Install handler */ - connection->dispatch[SSH_MSG_KEXDH_INIT] = &dh->super; - } -} - - -struct keyexchange_algorithm * -make_dh_server(struct dh_method *dh) -{ - NEW(dh_server_exchange, self); - - self->super.init = do_init_server_dh; - self->dh = dh; - - return &self->super; -} - - -#if WITH_SRP -/* SRP key exchange */ - -/* GABA: - (class - (name srp_server_instance) - (vars - (dh struct dh_instance) - (algorithms object object_list) - (db object user_db) - (user object lsh_user) - (entry object srp_entry))) -*/ - -/* GABA: - (class - (name srp_server_handler) - (super packet_handler) - (vars - (srp object srp_server_instance))) -*/ - -static void -do_srp_server_proof_handler(struct packet_handler *s, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(srp_server_handler, self, s); - - struct lsh_string *response = srp_process_client_proof(&self->srp->dh, packet); - - connection->dispatch[SSH_MSG_KEXSRP_PROOF] = &connection_fail_handler; - - if (response) - { - C_WRITE(connection, response); - - /* Remember that a user was authenticated. */ - connection->user = self->srp->user; - connection->flags |= CONNECTION_SRP; - - keyexchange_finish(connection, self->srp->algorithms, - self->srp->dh.method->H, - self->srp->dh.exchange_hash, - self->srp->dh.K); - /* For gc */ - self->srp->dh.K = NULL; - self->srp->dh.exchange_hash = NULL; - } - else - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_KEXSRP_PROOF message"); - - /* Try to purge information about the key exchange */ - KILL(self->srp); - KILL(self); -} - -static struct packet_handler * -make_srp_server_proof_handler(struct srp_server_instance *srp) -{ - NEW(srp_server_handler, self); - self->super.handler = do_srp_server_proof_handler; - self->srp = srp; - - return &self->super; -} - -static void -do_exc_srp(struct exception_handler *e, - const struct exception *x) -{ - /* FIXME: Filter the error messages. E.g. "No more sexps" doesn't - * make much sense to the client. */ - EXCEPTION_RAISE(e->parent, - make_protocol_exception(SSH_DISCONNECT_KEY_EXCHANGE_FAILED, - x->msg)); -} - -/* Invoked after that we have read an sexp that represents a user's verifier */ -/* GABA: - (class - (name srp_init_continuation) - (super command_continuation) - (vars - (srp object srp_server_instance) - (connection object ssh_connection))) -*/ - -static void -do_srp_init_continuation(struct command_continuation *s, - struct lsh_object *a) -{ - CAST(srp_init_continuation, self, s); - CAST_SUBTYPE(sexp, e, a); - - self->srp->entry = make_srp_entry(self->srp->user->name, e); - - if (!self->srp->entry) - { - disconnect_kex_failed(self->connection, "Invalid SRP verifier"); - return; - } - - C_WRITE(self->connection, srp_make_reply_msg(&self->srp->dh, self->srp->entry)); - self->connection->dispatch[SSH_MSG_KEXSRP_PROOF] = make_srp_server_proof_handler(self->srp); -} - -static struct command_continuation * -make_server_srp_continuation(struct srp_server_instance *srp, - struct ssh_connection *connection) -{ - NEW(srp_init_continuation, self); - self->super.c = do_srp_init_continuation; - self->srp = srp; - self->connection = connection; - - return &self->super; -} - -#define MAX_SRP_SIZE 2000 - -static void -do_handle_srp_init(struct packet_handler *s, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(srp_server_handler, self, s); - struct lsh_string *name = srp_process_init_msg(&self->srp->dh, packet); - struct exception_handler *e; - - connection->dispatch[SSH_MSG_KEXSRP_INIT] = &connection_fail_handler; - - if (!name) - { - PROTOCOL_ERROR(connection->e, "Invalid SSH_MSG_KEXSRP_INIT message"); - return; - } - - self->srp->user = USER_LOOKUP(self->srp->db, name, 1); - if (!self->srp->user) - { - EXCEPTION_RAISE(connection->e, - make_protocol_exception(SSH_DISCONNECT_ILLEGAL_USER_NAME, NULL)); - return; - } - - /* Try opening the user's ~/.lsh/srp-verifier */ - e = make_exception_handler(do_exc_srp, connection->e, HANDLER_CONTEXT); - - USER_READ_FILE(self->srp->user, "srp-verifier", 1, - make_apply(make_read_sexp_command(SEXP_CANONICAL, 0, MAX_SRP_SIZE), - make_server_srp_continuation(self->srp, connection), - e), - e); -} - -static struct packet_handler * -make_srp_init_handler(struct srp_server_instance *srp) -{ - NEW(srp_server_handler, self); - self->super.handler = do_handle_srp_init; - self->srp = srp; - - return &self->super; -} - -/* GABA: - (class - (name srp_server_exchange) - (super keyexchange_algorithm) - (vars - (dh object dh_method) - (db object user_db))) -*/ - -static void -do_init_server_srp(struct keyexchange_algorithm *s, - struct ssh_connection *connection, - int hostkey_algorithm UNUSED, - struct lsh_object *extra UNUSED, - struct object_list *algorithms) -{ - CAST(srp_server_exchange, self, s); - - NEW(srp_server_instance, srp); - - /* Initialize */ - init_dh_instance(self->dh, &srp->dh, connection); - - srp->algorithms = algorithms; - srp->db = self->db; - srp->user = NULL; - srp->entry = NULL; - - /* Install handler */ - connection->dispatch[SSH_MSG_KEXSRP_INIT] = make_srp_init_handler(srp); -} - -struct keyexchange_algorithm * -make_srp_server(struct dh_method *dh, - struct user_db *db) -{ - NEW(srp_server_exchange, self); - - assert(dh->G->add); - assert(dh->G->subtract); - - self->super.init = do_init_server_srp; - self->dh = dh; - self->db = db; - - return &self->super; -} - -#endif /* WITH_SRP */ diff --git a/lsh/src/server_keyexchange.c.x b/lsh/src/server_keyexchange.c.x deleted file mode 100755 index b4350f9..0000000 Binary files a/lsh/src/server_keyexchange.c.x and /dev/null differ diff --git a/lsh/src/server_keyexchange.h b/lsh/src/server_keyexchange.h deleted file mode 100755 index c01dbbf..0000000 --- a/lsh/src/server_keyexchange.h +++ /dev/null @@ -1,41 +0,0 @@ -/* server_keyexchange.h - * - * Server specific key exchange handling - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SERVER_KEYEXCHANGE_H_INCLUDED -#define LSH_SERVER_KEYEXCHANGE_H_INCLUDED - -#include "keyexchange.h" -#include "publickey_crypto.h" -#include "server_userauth.h" - -/* This function consumes the server key */ -struct keyexchange_algorithm * -make_dh_server(struct dh_method *dh); - -struct keyexchange_algorithm * -make_srp_server(struct dh_method *dh, - struct user_db *db); - -#endif /* LSH_SERVER_KEYEXCHANGE_H_INCLUDED */ diff --git a/lsh/src/server_password.c b/lsh/src/server_password.c deleted file mode 100755 index aa005e5..0000000 --- a/lsh/src/server_password.c +++ /dev/null @@ -1,128 +0,0 @@ -/* server_password.c - * - * System dependant password related functions. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "charset.h" -#include "format.h" -#include "parse.h" -#include "ssh.h" -#include "server_userauth.h" -#include "werror.h" -#include "xalloc.h" - -#include "server_password.c.x" - -/* GABA: - (class - (name userauth_password) - (super userauth) - (vars - (db object user_db))) -*/ - -static void -do_authenticate(struct userauth *s, - struct ssh_connection *connection UNUSED, - struct lsh_string *username, - UINT32 service UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(userauth_password, self, s); - - int change_passwd; - - username = utf8_to_local(username, 1, 1); - if (!username) - { - PROTOCOL_ERROR(e, "Invalid utf8 in username."); - return; - } - - if (parse_boolean(args, &change_passwd)) - { - struct lsh_string *password = NULL; - - if (change_passwd) - { - static const struct exception passwd_change_not_implemented - = STATIC_EXCEPTION(EXC_USERAUTH, - "Password change not implemented."); - - lsh_string_free(username); - EXCEPTION_RAISE(e, &passwd_change_not_implemented); - - return; - } - if ( (password = parse_string_copy(args)) - && parse_eod(args)) - { - struct lsh_user *user; - - password = utf8_to_local(password, 1, 1); - - if (!password) - { - lsh_string_free(username); - PROTOCOL_ERROR(e, "Invalid utf8 in password."); - return; - } - - user = USER_LOOKUP(self->db, username, 1); - - if (!user) - { - static const struct exception no_such_user - = STATIC_EXCEPTION(EXC_USERAUTH, "No such user"); - - lsh_string_free(password); - EXCEPTION_RAISE(e, &no_such_user); - return; - } - - USER_VERIFY_PASSWORD(user, password, c, e); - return; - } - if (password) - lsh_string_free(password); - } - - /* Request was invalid */ - lsh_string_free(username); - - PROTOCOL_ERROR(e, "Invalid password USERAUTH message."); -} - -struct userauth * -make_userauth_password(struct user_db *db) -{ - NEW(userauth_password, self); - self->super.authenticate = do_authenticate; - self->db = db; - - return &self->super; -} - diff --git a/lsh/src/server_password.c.x b/lsh/src/server_password.c.x deleted file mode 100755 index 308c1c5..0000000 Binary files a/lsh/src/server_password.c.x and /dev/null differ diff --git a/lsh/src/server_pty.c b/lsh/src/server_pty.c deleted file mode 100755 index c9996ab..0000000 --- a/lsh/src/server_pty.c +++ /dev/null @@ -1,355 +0,0 @@ -/* server_pty.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, Niels Möller, Balázs Scheidler - * - * 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 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 should 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. - */ - -#include "server_pty.h" - -#include "channel.h" -#include "connection.h" -#include "format.h" -#include "parse.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include -#include -#include -#include -#include -#include /* FIXME: for snprintf, maybe use a custom snprintf? Bazsi */ - -#if HAVE_STROPTS_H -# include /* isastream() */ -#endif - -#if HAVE_PTY_H -# include /* openpty() */ -#endif - - -#define GABA_DEFINE -#include "server_pty.h.x" -#undef GABA_DEFINE - -static void -do_kill_pty_info(struct resource *r) -{ - CAST(pty_info, closure, r); - - if (closure->super.alive) - { - closure->super.alive = 0; - if ( (closure->master >= 0) && (close(closure->master) < 0) ) - werror("do_kill_pty_info: closing master failed (errno = %i): %z\n", - errno, STRERROR(errno)); - - if ( (closure->slave >= 0) && (close(closure->slave) < 0) ) - werror("do_kill_pty_info: closing slave failed (errno = %i): %z\n", - errno, STRERROR(errno)); - } -} - -struct pty_info * -make_pty_info(void) -{ - NEW(pty_info, pty); - - init_resource(&pty->super, do_kill_pty_info); - pty->tty_name = NULL; - pty->master = pty->slave = -1; - return pty; -} - -/* FIXME: Maybe this name should be configurable? */ -#ifndef TTY_GROUP -#define TTY_GROUP "tty" -#endif - -#ifndef ACCESSPERMS -#define ACCESSPERMS 07777 -#endif - -/* Sets the permissions on the slave pty suitably for use by USER. - * This function is derived from the grantpt function in - * sysdeps/unix/grantpt.c in glibc-2.1. */ - -static int -pty_check_permissions(const char *name, uid_t user) -{ - struct stat st; - struct group *grp; - gid_t tty_gid; - - if (stat(name, &st) < 0) - return 0; - - /* Make sure that the user owns the device. */ - if ( (st.st_uid != user) - && (chown(name, user, st.st_gid) < 0) ) - return 0; - - /* Points to static area */ - grp = getgrnam(TTY_GROUP); - - if (grp) - tty_gid = grp->gr_gid; - else - { - /* If no tty group is found, use the server's gid */ - werror("lshd: server_pty.c: No tty group found.\n"); - tty_gid = getgid(); - } - - if ( (st.st_gid != tty_gid) - && (chown(name, user, tty_gid) < 0)) - return 0; - - /* Make sure the permission mode is set to readable and writable - * by the owner, and writable by the group. */ - - if ( ((st.st_mode & ACCESSPERMS) != (S_IRUSR | S_IWUSR | S_IWGRP)) - && (chmod(name, S_IRUSR | S_IWUSR | S_IWGRP) < 0) ) - return 0; - - /* Everything is fine */ - return 1; -} - -#if HAVE_UNIX98_PTYS - -/* Returns the name of the slave tty, as a string with an extra - * terminating NUL. */ - -static struct lsh_string * -pty_grantpt_uid(int master, uid_t user) -{ - uid_t me = getuid(); - if (me == user) - { - /* Use standard grantpt call */ - if (grantpt(master) < 0) - return NULL; - - return make_string(ptsname(master)); - } - else - { /* Set up permissions for user */ - - /* Pointer to static area */ - char *name = ptsname(master); - return (pty_check_permissions(name, user) - ? make_string(name) - : NULL); - - } -} -#endif /* HAVE_UNIX98_PTYS */ - -int -pty_allocate(struct pty_info *pty, - uid_t user -#if !HAVE_UNIX98_PTYS - UNUSED -#endif - ) -{ -#if HAVE_UNIX98_PTYS - struct lsh_string *name = NULL; - if ((pty->master = open("/dev/ptmx", O_RDWR | O_NOCTTY)) < 0) - { - werror("pty_allocate: Opening /dev/ptmx failed (errno = %i): %z\n", - errno, STRERROR(errno)); - return 0; - } - - if (! (name = pty_grantpt_uid(pty->master, user))) - goto close_master; - - if (unlockpt(pty->master) < 0) - goto close_master; - - pty->slave = open(name->data, O_RDWR | O_NOCTTY); - if (pty->slave == -1) - goto close_master; - -# ifdef HAVE_STROPTS_H - if (isastream(pty->slave)) - { - if (ioctl(pty->slave, I_PUSH, "ptem") < 0 - || ioctl(pty->slave, I_PUSH, "ldterm") < 0) - goto close_slave; - } -# endif /* HAVE_STROPTS_H */ - - pty->tty_name = name; - return 1; - -close_slave: - close (pty->slave); pty->slave = -1; -close_master: - close (pty->master); pty->master = -1; - - if (name) - lsh_string_free(name); - return 0; - -#elif PTY_BSD_SCHEME - -#define PTY_BSD_SCHEME_MASTER "/dev/pty%c%c" -#define PTY_BSD_SCHEME_SLAVE "/dev/tty%c%c" - char first[] = PTY_BSD_SCHEME_FIRST_CHARS; - char second[] = PTY_BSD_SCHEME_SECOND_CHARS; - char master[MAX_TTY_NAME], slave[MAX_TTY_NAME]; - unsigned int i, j; - int saved_errno; - -#define CONST_STRLEN(s) (sizeof((s)) - sizeof("")) - - for (i = 0; i < CONST_STRLEN(first); i++) - { - for (j = 0; j < CONST_STRLEN(second); j++) - { - snprintf(master, sizeof(master), - PTY_BSD_SCHEME_MASTER, first[i], second[j]); - - pty->master = open(master, O_RDWR | O_NOCTTY); - if (pty->master != -1) - { - /* master succesfully opened */ - snprintf(slave, sizeof(slave), - PTY_BSD_SCHEME_SLAVE, first[i], second[j]); - - pty->slave = open(slave, O_RDWR | O_NOCTTY); - if (pty->slave == -1) - { - saved_errno = errno; - close(pty->master); pty->master = -1; - errno = saved_errno; - return 0; - } - /* NOTE: As there is no locking, setting the permissions - * properly does not guarantee that nobody else has the - * pty open, and can snoop the traffic on it. But it - * should be a little better than nothing. */ - - /* FIXME: Should we do something about the master - * permissions as well? */ - if (pty_check_permissions(slave, user)) - { - pty->tty_name = make_string(slave); - return 1; - } - saved_errno = errno; - close(pty->master); pty->master = -1; - close(pty->slave); pty->slave = -1; - return 0; - } - } - } - return 0; -#elif HAVE_OPENPTY - /* FIXME: openpty may not work properly, when called with the - * wrong uid. */ -#error The openpty scheme is not currently supported. - return (openpty(&pty->master, &pty->slave, NULL, NULL, NULL) == 0) - && pty_check_permissions(ptsname..., user); - -#else /* !HAVE_OPENPTY */ - /* No pty:s */ - return 0; -#endif -} - -/* NOTE: This function also makes the current process a process group - * leader. */ -int -tty_setctty(struct pty_info *pty) -{ - debug("tty_setctty\n"); - if (setsid() < 0) - { - werror("tty_setctty: setsid failed, already process group leader?\n" - " (errno = %i): %z\n", errno, STRERROR(errno)); - return 0; - } -#if HAVE_UNIX98_PTYS - { - int fd; - - /* Open the slave, to make it our controlling tty */ - - /* FIXME: According to carson@tla.org, there's a cleaner POSIX way - * to make a tty the process's controlling tty, but I haven't - * found out how. */ - - debug("setctty: Attempting open\n"); - fd = open(pty->tty_name->data, O_RDWR); - if (fd < 0) - { - werror("tty_setctty: open(\"%z\") failed,\n" - " (errno = %i): %z\n", - pty->tty_name->data, errno, STRERROR(errno)); - return 0; - } - close(fd); - - return 1; - } -#elif PTY_BSD_SCHEME - { - /* Is this really needed? setsid should unregister the - * controlling tty */ -#if 0 - int oldtty; - - oldtty = open("/dev/tty", O_RDWR | O_NOCTTY); - if (oldtty >= 0) - { - ioctl(oldtty, TIOCNOTTY, NULL); - close(oldtty); - oldtty = open("/dev/tty", O_RDWR | O_NOCTTY); - if (oldtty >= 0) - { - werror("pty_setctty: Error disconnecting from controlling tty.\n"); - close(oldtty); - return 0; - } - } -#endif - - if (ioctl(pty->slave, TIOCSCTTY, NULL) == -1) - { - werror("tty_setctty: Failed to set the controlling tty.\n" - " (errno = %i): %z\n", errno, STRERROR(errno)); - return 0; - } - - return 1; - } -#else /* !PTY_BSD_SCHEME */ -#error Dont know how to register a controlling tty -#endif -} diff --git a/lsh/src/server_pty.h b/lsh/src/server_pty.h deleted file mode 100755 index a734814..0000000 --- a/lsh/src/server_pty.h +++ /dev/null @@ -1,65 +0,0 @@ -/* server_pty.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, Niels Möller, Balázs Scheidler - * - * 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 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 should 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 - */ - -#ifndef LSH_SERVER_PTY_H_INCLUDED -#define LSH_SERVER_PTY_H_INCLUDED - -#include "lsh.h" - -#include "resource.h" - -#include -#include - -#define MAX_TTY_NAME 32 - -#define GABA_DECLARE -#include "server_pty.h.x" -#undef GABA_DECLARE - - -/* GABA: - (class - (name pty_info) - (super resource) - (vars - (master . int) - (slave . int) - - ; Name of slave tty. - ; Needed for SysV pty-handling (where opening the tty - ; makes it the controlling terminal). Perhaps handy also for - ; writing accurate utmp-entries. - ; This string should be NUL-terminated - (tty_name string))) -*/ - -struct pty_info *make_pty_info(void); -int pty_allocate(struct pty_info *pty, uid_t user); - -/* NOTE: This function also makes the current process a process group - * leader. */ -int tty_setctty(struct pty_info *pty); - - -#endif /* LSH_SERVER_PTY_H_INCLUDED */ diff --git a/lsh/src/server_pty.h.x b/lsh/src/server_pty.h.x deleted file mode 100755 index 974c614..0000000 Binary files a/lsh/src/server_pty.h.x and /dev/null differ diff --git a/lsh/src/server_publickey.c b/lsh/src/server_publickey.c deleted file mode 100755 index 07c292e..0000000 --- a/lsh/src/server_publickey.c +++ /dev/null @@ -1,216 +0,0 @@ -/* server_publickey.c - * - * Publickey authentication method - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should 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 - */ - -#include "charset.h" -#include "connection.h" -#include "dsa.h" -#include "format.h" -#include "lookup_verifier.h" -#include "parse.h" -#include "publickey_crypto.h" -#include "server_userauth.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#include "server_publickey.c.x" - -/* GABA: - (class - (name userauth_publickey) - (super userauth) - (vars - (db object user_db) - (verifiers object alist))) -*/ - -static struct lsh_string * -format_userauth_pk_ok(int algorithm, struct lsh_string *keyblob) -{ - return ssh_format("%c%a%S", SSH_MSG_USERAUTH_PK_OK, - algorithm, keyblob); -} - -static void -do_authenticate(struct userauth *s, - struct ssh_connection *connection, - struct lsh_string *username, - UINT32 service UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(userauth_publickey, self, s); - - struct lsh_string *keyblob = NULL; - struct lookup_verifier *lookup; - struct verifier *v; - const UINT8 *signature_blob; - UINT32 signature_length; - UINT32 signature_start = 0; - int algorithm; - int check_key; - - username = utf8_to_local(username, 1, 1); - if (!username) - { - PROTOCOL_ERROR(e, "Invalid utf8 in username."); - return; - } - - if (parse_boolean(args, &check_key) && - parse_atom(args, &algorithm) && - (keyblob = parse_string_copy(args)) && - (check_key - ? ((signature_start = args->pos) - , (parse_string(args, &signature_length, &signature_blob)) - && parse_eod(args)) - : parse_eod(args))) - { - struct lsh_user *user; - - { - CAST_SUBTYPE(lookup_verifier, l, - ALIST_GET(self->verifiers, algorithm)); - lookup = l; - } - - if (!lookup) - { - static const struct exception unsupported_publickey_algorithm - = STATIC_EXCEPTION(EXC_USERAUTH, - "Unsupported public key algorithm."); - - verbose("Unknown publickey algorithm %a\n", algorithm); - EXCEPTION_RAISE(e, &unsupported_publickey_algorithm); - - fail: - lsh_string_free(keyblob); - lsh_string_free(username); - return; - } - - user = USER_LOOKUP(self->db, username, 0); - - if (!user) - { - static const struct exception unknown_user - = STATIC_EXCEPTION(EXC_USERAUTH, - "Unknown user."); - - EXCEPTION_RAISE(e, &unknown_user); - goto fail; - } - - v = LOOKUP_VERIFIER(lookup, algorithm, user, keyblob); - - if (!v) - { - static const struct exception unauthorized_key - = STATIC_EXCEPTION(EXC_USERAUTH, - "Unauthorized public key."); - - EXCEPTION_RAISE(e, &unauthorized_key); - goto fail; - } - - if (!check_key) - { - assert(v); - EXCEPTION_RAISE(e, make_userauth_special_exception - (format_userauth_pk_ok(algorithm, keyblob), - NULL)); - goto fail; - } - else - { - struct lsh_string *signed_data; - - assert(v); - -#if DATAFELLOWS_WORKAROUNDS - if ( (algorithm == ATOM_SSH_DSS) - && (connection->peer_flags & PEER_SSH_DSS_KLUDGE)) - algorithm = ATOM_SSH_DSS_KLUDGE_LOCAL; - - if (connection->peer_flags & PEER_USERAUTH_REQUEST_KLUDGE) - { - signed_data = ssh_format("%lS%c%S%a%a%c%a%S", - connection->session_id, - SSH_MSG_USERAUTH_REQUEST, - username, - ATOM_SSH_USERAUTH, - ATOM_PUBLICKEY, - 1, - algorithm, - keyblob); - } - else -#endif /* DATAFELLOWS_WORKAROUNDS */ - /* The signature is on the session id, followed by the - * userauth request up to the actual signature. To avoid collisions, - * the length field for the session id is included. */ - signed_data = ssh_format("%S%ls", connection->session_id, - signature_start, args->data); - - lsh_string_free(keyblob); - if (VERIFY(v, algorithm, - signed_data->length, signed_data->data, - signature_length, signature_blob)) - { - werror("publickey authentication for user %S succeeded.\n", username); - COMMAND_RETURN(c, user); - } - else - { - static const struct exception bad_sign - = STATIC_EXCEPTION(EXC_USERAUTH, "Bad signature in userauth request"); - - EXCEPTION_RAISE(e, &bad_sign); - } - lsh_string_free(username); - lsh_string_free(signed_data); - return; - } - } - else - { - werror("Badly formatted publickey authentication request\n"); - PROTOCOL_ERROR(e, "Invalid publickey authentication request"); - } -} - -struct userauth * -make_userauth_publickey(struct user_db *db, - struct alist *verifiers) -{ - NEW(userauth_publickey, self); - - self->super.authenticate = do_authenticate; - self->db = db; - self->verifiers = verifiers; - return &self->super; -} diff --git a/lsh/src/server_publickey.c.x b/lsh/src/server_publickey.c.x deleted file mode 100755 index df5e7c0..0000000 Binary files a/lsh/src/server_publickey.c.x and /dev/null differ diff --git a/lsh/src/server_session.c b/lsh/src/server_session.c deleted file mode 100755 index 91096c1..0000000 --- a/lsh/src/server_session.c +++ /dev/null @@ -1,1065 +0,0 @@ -/* server_session.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "server_session.h" - -#include "channel_commands.h" -#include "format.h" -#include "read_data.h" -#include "reaper.h" -#include "server_pty.h" -#include "ssh.h" -#include "tcpforward.h" -#include "translate_signal.h" -#include "tty.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* For debug */ - -#include -#if HAVE_UNISTD_H -#include -#endif - -#include -#include - -#include - -#include "server_session.c.x" - - -/* Session */ -/* GABA: - (class - (name server_session) - (super ssh_channel) - (vars - ; User information - ;; (user object lsh_user) - - (initial_window . UINT32) - - ; Resource to kill when the channel is closed. - (process object lsh_process) - - ; pty - (pty object pty_info) - ; value of the TERM environment variable - (term string) - - ; Child process's stdio - (in object lsh_fd) - (out object lsh_fd) - - ; err may be NULL, if there's no separate stderr channel. - ; This happens if we use a pty, and the bash workaround is used. - (err object lsh_fd))) -*/ - -/* Receive channel data */ -static void -do_receive(struct ssh_channel *c, - int type, struct lsh_string *data) -{ - CAST(server_session, closure, c); - - switch(type) - { - case CHANNEL_DATA: - A_WRITE(&closure->in->write_buffer->super, data); - break; - case CHANNEL_STDERR_DATA: - werror("Ignoring unexpected stderr data.\n"); - lsh_string_free(data); - break; - default: - fatal("Internal error!\n"); - } -} - -/* We may send more data */ -static void -do_send_adjust(struct ssh_channel *s, - UINT32 i UNUSED) -{ - CAST(server_session, session, s); - - /* FIXME: Perhaps it's better to just check the read pointers, and - * not bother with the alive-flags? */ - if (session->out->super.alive) - { - assert(session->out->read); - - session->out->want_read = 1; - } - - if (session->err && session->err->super.alive) - { - assert(session->err->read); - - session->err->want_read = 1; - } -} - -/* FIXME: Perhaps unify with client_session.c:do_client_session_eof */ -static void -do_eof(struct ssh_channel *channel) -{ - CAST(server_session, session, channel); - - trace("server_session.c: do_eof\n"); - - write_buffer_close(session->in->write_buffer); -} - -struct ssh_channel * -make_server_session(UINT32 initial_window, - struct alist *request_types) -{ - NEW(server_session, self); - - init_channel(&self->super); - - self->initial_window = initial_window; - - /* We don't want to receive any data before we have forked some - * process to receive it. */ - self->super.rec_window_size = 0; - - /* FIXME: Make maximum packet size configurable. */ - self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ; - self->super.request_types = request_types; - - /* Note: We don't need a close handler; the channels resource list - * is taken care of automatically. */ - - self->process = NULL; - - self->in = NULL; - self->out = NULL; - self->err = NULL; - - return &self->super; -} - - -/* GABA: - (class - (name open_session) - (super channel_open) - (vars - (session_requests object alist))) -*/ - -#define WINDOW_SIZE 10000 - -static void -do_open_session(struct channel_open *s, - struct ssh_connection *connection UNUSED, - struct channel_open_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(open_session, self, s); - - debug("server.c: do_open_session\n"); - - assert(connection->user); - - if (parse_eod(args)) - { - COMMAND_RETURN(c, - make_server_session(WINDOW_SIZE, self->session_requests)); - } - else - { - PROTOCOL_ERROR(e, "trailing garbage in open message"); - } -} - -struct channel_open * -make_open_session(struct alist *session_requests) -{ - NEW(open_session, closure); - - closure->super.handler = do_open_session; - closure->session_requests = session_requests; - - return &closure->super; -} - - -struct lsh_string * -format_exit_signal(struct ssh_channel *channel, - int core, int signal) -{ - struct lsh_string *msg = ssh_format("Process killed by %lz.\n", - STRSIGNAL(signal)); - - return format_channel_request(ATOM_EXIT_SIGNAL, - channel, - 0, - "%a%c%fS%z", - signal_local_to_network(signal), - core, - msg, ""); -} - -struct lsh_string * -format_exit(struct ssh_channel *channel, int value) -{ - return format_channel_request(ATOM_EXIT_STATUS, - channel, - 0, - "%i", value); -} - -/* GABA: - (class - (name exit_shell) - (super exit_callback) - (vars - (session object server_session))) -*/ - -static void -do_exit_shell(struct exit_callback *c, int signaled, - int core, int value) -{ - CAST(exit_shell, closure, c); - struct server_session *session = closure->session; - struct ssh_channel *channel = &session->super; - - trace("server_session.c: do_exit_shell\n"); - - /* NOTE: We don't close the child's stdio here. */ - - if (!(channel->flags & CHANNEL_SENT_CLOSE)) - { - verbose("server_session.c: Sending %a message on channel %i\n", - signaled ? ATOM_EXIT_SIGNAL : ATOM_EXIT_STATUS, - channel->channel_number); - - C_WRITE(channel->connection, - (signaled - ? format_exit_signal(channel, core, value) - : format_exit(channel, value)) ); - - /* We want to close the channel as soon as all stdout and stderr - * data has been sent. In particular, we don't wait for EOF from - * the client, most clients never sends that. */ - - channel->flags |= (CHANNEL_NO_WAIT_FOR_EOF | CHANNEL_CLOSE_AT_EOF); - - if (channel->flags & CHANNEL_SENT_EOF) - { - /* We have sent EOF already, so initiate close */ - channel_close(channel); - } - } -} - -static struct exit_callback * -make_exit_shell(struct server_session *session) -{ - NEW(exit_shell, self); - - self->super.exit = do_exit_shell; - self->session = session; - - return &self->super; -} - -/* GABA: - (class - (name shell_request) - (super channel_request) - (vars - (backend object io_backend))) -*/ - -static int -make_pipes(int *in, int *out, int *err) -{ - int saved_errno; - - if (lsh_make_pipe(in)) - { - if (lsh_make_pipe(out)) - { - if (lsh_make_pipe(err)) - { - return 1; - } - saved_errno = errno; - close(out[0]); - close(out[1]); - } - else - saved_errno = errno; - close(in[0]); - close(in[1]); - } - else - saved_errno = errno; - - errno = saved_errno; - return 0; -} - -#define BASH_WORKAROUND 1 - -#if WITH_PTY_SUPPORT -static int make_pty(struct pty_info *pty, int *in, int *out, int *err) -{ - int saved_errno = 0; - - debug("make_pty... "); - if (pty) - debug("exists: \n" - " alive = %i\n" - " master = %i\n" - " slave = %i\n" - "... ", - pty->super.alive, pty->master, pty->slave); - debug("\n"); - - if (pty) - { - assert(pty->super.alive); - - debug("make_pty: Using allocated pty.\n"); - in[0] = pty->slave; - in[1] = pty->master; - - /* Ownership of the fd:s passes on to some file objects. */ - pty->super.alive = 0; - - /* FIXME: It seems unnecessary to dup the fd:s here. But perhaps - * having equal in and out fds may confuse the cleanup code, so - * we leave it for now. */ - if ((out[0] = dup(pty->master)) != -1) - { - if ((out[1] = dup(pty->slave)) != -1) - { -#if BASH_WORKAROUND - /* Don't use a separate stderr channel; just dup the - * stdout pty to stderr. */ - if ((err[1] = dup(pty->slave)) != -1) - { - err[0] = -1; - return 1; - } -#else /* !BASH_WORKAROUND */ - if (lsh_make_pipe(err)) - { - /* Success! */ - return 1; - } -#endif /* !BASH_WORKAROUND */ - saved_errno = errno; - - } - else - saved_errno = errno; - close(out[0]); - } - else - saved_errno = errno; - close(in[0]); - close(in[1]); - - werror("make_pty: duping pty filedescriptors failed (errno = %i): %z\n", - errno, STRERROR(errno)); - } - errno = saved_errno; - return 0; -} -#else /* !WITH_PTY_SUPPORT */ -static int make_pty(struct pty_info *pty UNUSED, - int *in UNUSED, int *out UNUSED, int *err UNUSED) -{ return 0; } -#endif /* !WITH_PTY_SUPPORT */ - -/* Returns -1 on failure, 0 for child and +1 for parent */ -static int -spawn_process(struct server_session *session, - struct lsh_user *user, - struct address_info *peer, - struct io_backend *backend) -{ - int in[2]; - int out[2]; - int err[2]; - - int using_pty = 0; - - if (session->process) - /* Already spawned a shell or command */ - return -1; - - /* {in|out|err}[0] is for reading, - * {in|out|err}[1] for writing. */ - - if (make_pty(session->pty, in, out, err)) - using_pty = 1; - - else if (!make_pipes(in, out, err)) - return -1; - - { - struct lsh_process *child; - - if (USER_FORK(user, &child, - make_exit_shell(session), - peer, using_pty ? session->pty->tty_name : NULL)) - { - if (child) - { /* Parent */ - struct ssh_channel *channel = &session->super; - trace("spawn_process: Parent process\n"); - - session->process = child; - - /* Close the child's fd:s */ - close(in[0]); - close(out[1]); - close(err[1]); - - { - /* Exception handlers */ - struct exception_handler *io_exception_handler - = make_channel_io_exception_handler(channel, - "lshd: Child stdio: ", - &default_exception_handler, - HANDLER_CONTEXT); - - /* Close callback for stderr and stdout */ - struct lsh_callback *read_close_callback - = make_channel_read_close_callback(channel); - - session->in - = io_write(make_lsh_fd(backend, in[1], "child stdin", - io_exception_handler), - SSH_MAX_PACKET, NULL); - - /* Flow control */ - session->in->write_buffer->report = &session->super.super; - - /* FIXME: Should we really use the same exception handler, - * which will close the channel on read errors, or is it - * better to just send EOF on read errors? */ - session->out - = io_read(make_lsh_fd(backend, out[0], "child stdout", - io_exception_handler), - make_channel_read_data(channel), - read_close_callback); - session->err - = ( (err[0] != -1) - ? io_read(make_lsh_fd(backend, err[0], "child stderr", - io_exception_handler), - make_channel_read_stderr(channel), - read_close_callback) - : NULL); - } - - channel->receive = do_receive; - channel->send_adjust = do_send_adjust; - channel->eof = do_eof; - - /* Make sure that the process and it's stdio is - * cleaned up if the channel or connection dies. */ - REMEMBER_RESOURCE - (channel->resources, &child->super); - - /* FIXME: How to do this properly if in and out may use the - * same fd? */ - REMEMBER_RESOURCE - (channel->resources, &session->in->super); - REMEMBER_RESOURCE - (channel->resources, &session->out->super); - if (session->err) - REMEMBER_RESOURCE - (channel->resources, &session->err->super); - - /* Don't close channel immediately at EOF, as we want to - * get a chance to send exit-status or exit-signal. */ - session->super.flags &= ~CHANNEL_CLOSE_AT_EOF; - return 1; - } - else - { /* Child */ - trace("spawn_process: Child process\n"); - assert(getuid() == user->uid); - -#if 0 - /* Debug timing problems */ - if (sleep(5)) - { - trace("server_session.c: sleep interrupted\n"); - - sleep(5); - } -#endif - if (!USER_CHDIR_HOME(user)) - { - werror("Could not change to home (or root) directory!\n"); - _exit(EXIT_FAILURE); - } - -#if WITH_PTY_SUPPORT - if (using_pty) - { - debug("lshd: server.c: Setting controlling tty...\n"); - if (!tty_setctty(session->pty)) - { - debug("lshd: server.c: " - "Setting controlling tty... Failed!\n"); - werror("lshd: Can't set controlling tty for child!\n"); - _exit(EXIT_FAILURE); - } - else - debug("lshd: server.c: Setting controlling tty... Ok.\n"); - } -#endif /* WITH_PTY_SUPPORT */ - - /* Close all descriptors but those used for - * communicationg with parent. We rely on the - * close-on-exec flag for all fd:s handled by the - * backend. */ - - if (dup2(in[0], STDIN_FILENO) < 0) - { - werror("Can't dup stdin!\n"); - _exit(EXIT_FAILURE); - } - close(in[0]); - close(in[1]); - - if (dup2(out[1], STDOUT_FILENO) < 0) - { - werror("Can't dup stdout!\n"); - _exit(EXIT_FAILURE); - } - close(out[0]); - close(out[1]); - - if (!dup_error_stream()) - { - werror("server_session: Failed to dup old stderr. Bye.\n"); - set_error_ignore(); - } - - if (dup2(err[1], STDERR_FILENO) < 0) - { - werror("Can't dup stderr!\n"); - _exit(EXIT_FAILURE); - } - close(err[0]); - close(err[1]); - - return 0; - } - } - /* fork failed */ - /* Close and return channel_failure */ - - close(err[0]); - close(err[1]); - close(out[0]); - close(out[1]); - close(in[0]); - close(in[1]); - } - return -1; -} - -static void -do_spawn_shell(struct channel_request *s, - struct ssh_channel *channel, - struct channel_request_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(shell_request, closure, s); - CAST(server_session, session, channel); - -static struct exception shell_request_failed = -STATIC_EXCEPTION(EXC_CHANNEL_REQUEST, "Shell request failed"); - - if (!parse_eod(args)) - { - PROTOCOL_ERROR(e, "Invalid shell CHANNEL_REQUEST message."); - return; - } - - if (session->process) - /* Already spawned a shell or command */ - goto fail; - - switch (spawn_process(session, channel->connection->user, - channel->connection->peer, - closure->backend)) - { - case 1: /* Parent */ - /* NOTE: The return value is not used. */ - COMMAND_RETURN(c, channel); - channel_start_receive(channel, session->initial_window); - return; - case 0: - { /* Child */ -#define MAX_ENV 1 - /* No args, and the USER_EXEC method fills in argv[0]. */ - const char *argv[] = { NULL, NULL }; - - struct env_value env[MAX_ENV]; - int env_length = 0; - - debug("do_spawn_shell: Child process\n"); - assert(getuid() == channel->connection->user->uid); - - if (session->term) - { - env[env_length].name ="TERM"; - env[env_length].value = session->term; - env_length++; - } - assert(env_length <= MAX_ENV); -#undef MAX_ENV - -#if 1 - USER_EXEC(channel->connection->user, 1, argv, env_length, env); - - /* exec failed! */ - verbose("server_session: exec failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - -#else -# define GREETING "Hello world!\n" - if (write(STDOUT_FILENO, GREETING, strlen(GREETING)) < 0) - _exit(errno); - kill(getuid(), SIGSTOP); - if (write(STDOUT_FILENO, shell, strlen(shell)) < 0) - _exit(125); - _exit(126); -# undef GREETING -#endif - } - case -1: - /* fork failed */ - - break; - default: - fatal("Internal error!"); - } - fail: - EXCEPTION_RAISE(e, &shell_request_failed); -} - -struct channel_request * -make_shell_handler(struct io_backend *backend) -{ - NEW(shell_request, closure); - - closure->super.handler = do_spawn_shell; - closure->backend = backend; - - return &closure->super; -} - - -static void -do_spawn_exec(struct channel_request *s, - struct ssh_channel *channel, - struct channel_request_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(shell_request, closure, s); - CAST(server_session, session, channel); - -static struct exception exec_request_failed = -STATIC_EXCEPTION(EXC_CHANNEL_REQUEST, "Exec request failed"); - - UINT32 command_len; - const UINT8 *command; - - if (!(parse_string(args, &command_len, &command) - && parse_eod(args))) - { - PROTOCOL_ERROR(e, "Invalid exec CHANNEL_REQUEST message."); - return; - } - - if (/* Already spawned a shell or command */ - session->process - /* Command can't contain NUL characters. */ - || memchr(command, '\0', command_len)) - - EXCEPTION_RAISE(e, &exec_request_failed); - else - { - struct lsh_string *command_line = ssh_format("%ls", command_len, command); - - switch (spawn_process(session, channel->connection->user, - channel->connection->peer, - closure->backend)) - { - case 1: /* Parent */ - lsh_string_free(command_line); - - /* NOTE: The return value is not used. */ - COMMAND_RETURN(c, channel); - channel_start_receive(channel, session->initial_window); - return; - case 0: - { /* Child */ -#define MAX_ENV 1 - struct env_value env[MAX_ENV]; - int env_length = 0; - - /* No args, and the USER_EXEC method fills in argv[0]. */ - - /* NOTE: I'd like to use an array initializer, but that's - * not ANSI-C, and at least HPUX' compiler can't handle - * it. */ - - const char *argv[4]; - argv[0] = NULL; - argv[1] = "-c"; - argv[2] = lsh_get_cstring(command_line); - argv[3] = NULL; - - debug("do_spawn_shell: Child process\n"); - - assert(getuid() == channel->connection->user->uid); - assert(argv[2]); - - if (session->term) - { - env[env_length].name ="TERM"; - env[env_length].value = session->term; - env_length++; - } - assert(env_length <= MAX_ENV); -#undef MAX_ENV - - USER_EXEC(channel->connection->user, 0, argv, env_length, env); - - /* exec failed! */ - verbose("server_session: exec failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - case -1: - /* fork failed */ - lsh_string_free(command_line); - EXCEPTION_RAISE(e, &exec_request_failed); - - break; - default: - fatal("Internal error!"); - } - } -} - -struct channel_request * -make_exec_handler(struct io_backend *backend) -{ - NEW(shell_request, closure); - - closure->super.handler = do_spawn_exec; - closure->backend = backend; - - return &closure->super; -} - -/* For simplicity, represent a subsystem simply as a name of the - * executable. */ - -/* GABA: - (class - (name subsystem_request) - (super shell_request) - (vars - ;(subsystems object alist) - ; A list { name, program, name, program, NULL } - (subsystems . "const char **"))) -*/ - -/* ;; GABA: - (class - (name sybsystem_info) - (vars - (name "const char *"))) -*/ - -static const char * -lookup_subsystem(struct subsystem_request *self, - UINT32 length, const UINT8 *name) -{ - unsigned i; - if (memchr(name, 0, length)) - return NULL; - - for (i = 0; self->subsystems[i]; i+=2) - { - assert(self->subsystems[i+1]); - if ((length == strlen(self->subsystems[i])) - && !memcmp(name, self->subsystems[i], length)) - return self->subsystems[i + 1]; - } - return NULL; -} - -static void -do_spawn_subsystem(struct channel_request *s, - struct ssh_channel *channel, - struct channel_request_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(subsystem_request, self, s); - CAST(server_session, session, channel); - - static struct exception subsystem_request_failed = - STATIC_EXCEPTION(EXC_CHANNEL_REQUEST, "Subsystem request failed"); - - const UINT8 *name; - UINT32 name_length; - - const char *program; - - if (! (parse_string(args, &name_length, &name) && parse_eod(args))) - { - PROTOCOL_ERROR(e, "Invalid subsystem CHANNEL_REQUEST message."); - return; - } - - program = lookup_subsystem(self, name_length, name); - - if (!session->process && program) - { - /* Don't use any pty */ - if (session->pty) - { - KILL_RESOURCE(&session->pty->super); - session->pty = NULL; - } - - switch (spawn_process(session, channel->connection->user, - channel->connection->peer, - self->super.backend)) - { - case 1: /* Parent */ - /* NOTE: The return value is not used. */ - COMMAND_RETURN(c, channel); - channel_start_receive(channel, session->initial_window); - return; - - case 0: /* Child */ - { - /* No args, and the USER_EXEC method fills in argv[0]. */ - const char *argv[] = { NULL, NULL }; - - debug("do_spawn_subsystem: Child process\n"); - - USER_EXEC(channel->connection->user, 1, argv, 0, NULL); - - werror("server_session: subsystem exec failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - case -1: /* Error */ - break; - - default: - fatal("Internal error!"); - } - } - EXCEPTION_RAISE(e, &subsystem_request_failed); -} - -struct channel_request * -make_subsystem_handler(struct io_backend *backend, - const char **subsystems) -{ - NEW(subsystem_request, self); - - self->super.super.handler = do_spawn_subsystem; - self->super.backend = backend; - self->subsystems = subsystems; - - return &self->super.super; -} - - -#if WITH_PTY_SUPPORT - -/* pty_handler */ -static void -do_alloc_pty(struct channel_request *c UNUSED, - struct ssh_channel *channel, - struct channel_request_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *s, - struct exception_handler *e) -{ - struct terminal_dimensions dims; - const UINT8 *mode; - UINT32 mode_length; - struct lsh_string *term = NULL; - - static struct exception pty_request_failed = - STATIC_EXCEPTION(EXC_CHANNEL_REQUEST, "pty request failed"); - - CAST(server_session, session, channel); - - verbose("Client requesting a tty...\n"); - - if ((term = parse_string_copy(args)) - && parse_uint32(args, &dims.char_width) - && parse_uint32(args, &dims.char_height) - && parse_uint32(args, &dims.pixel_width) - && parse_uint32(args, &dims.pixel_height) - && parse_string(args, &mode_length, &mode) - && parse_eod(args)) - { - /* The client may only request a tty once. */ - if (session->pty) - { - lsh_string_free(term); - EXCEPTION_RAISE(e, &pty_request_failed); - } - else - { - struct pty_info *pty = make_pty_info(); - - if (pty_allocate(pty, channel->connection->user->uid)) - { - struct termios ios; - - if (tty_getattr(pty->slave, &ios)) - { - assert(pty->super.alive); - session->pty = pty; - - /* Don't set TERM if the value is empty. */ - if (!term->length) - { - lsh_string_free(term); - term = NULL; - } - - session->term = term; - tty_decode_term_mode(&ios, mode_length, mode); - - if (tty_setattr(pty->slave, &ios) && - tty_setwinsize(pty->slave, &dims)) - { - REMEMBER_RESOURCE(channel->resources, &pty->super); - - verbose(" granted.\n"); - COMMAND_RETURN(s, NULL); - - return; - } - } - } - - /* Close fd:s and mark the pty-struct as dead */ - KILL_RESOURCE(&pty->super); - KILL(pty); - } - verbose("Pty allocation failed.\n"); - lsh_string_free(term); - EXCEPTION_RAISE(e, &pty_request_failed); - } - else - { - werror("Invalid pty request.\n"); - lsh_string_free(term); - - PROTOCOL_ERROR(e, "Invalid pty request."); - } -} - -struct channel_request -pty_request_handler = -{ STATIC_HEADER, do_alloc_pty }; - -static void -do_window_change_request(struct channel_request *c UNUSED, - struct ssh_channel *channel, - struct channel_request_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *s, - struct exception_handler *e) -{ - struct terminal_dimensions dims; - CAST(server_session, session, channel); - - verbose("Receiving window-change request...\n"); - - if (parse_uint32(args, &dims.char_width) - && parse_uint32(args, &dims.char_height) - && parse_uint32(args, &dims.pixel_width) - && parse_uint32(args, &dims.pixel_height) - && parse_eod(args)) - { - static const struct exception winch_request_failed = - STATIC_EXCEPTION(EXC_CHANNEL_REQUEST, "window-change request failed: No pty"); - - if (!(session->pty && session->pty->super.alive)) - EXCEPTION_RAISE(e, &winch_request_failed); - - else if (!tty_setwinsize(session->pty->slave, &dims)) - EXCEPTION_RAISE(e, &winch_request_failed); - - else - { - if (!SIGNAL_PROCESS(session->process, SIGWINCH)) - werror("Sending SIGWINCH signal failed.\n"); - - COMMAND_RETURN(s, NULL); - } - } - else - PROTOCOL_ERROR(e, "Invalid window-change request."); -} - -struct channel_request -window_change_request_handler = -{ STATIC_HEADER, do_window_change_request }; - -#endif /* WITH_PTY_SUPPORT */ diff --git a/lsh/src/server_session.c.x b/lsh/src/server_session.c.x deleted file mode 100755 index 3687ed2..0000000 Binary files a/lsh/src/server_session.c.x and /dev/null differ diff --git a/lsh/src/server_session.h b/lsh/src/server_session.h deleted file mode 100755 index b2ab8c3..0000000 --- a/lsh/src/server_session.h +++ /dev/null @@ -1,61 +0,0 @@ -/* server_session.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef LSH_SERVER_SESSION_H_INCLUDED -#define LSH_SERVER_SESSION_H_INCLUDED - -#include "channel.h" -#include "io.h" -#include "server_userauth.h" - -#include -#include - -struct ssh_channel * -make_server_session(UINT32 initial_window, - struct alist *request_types); - -struct channel_open * -make_open_session(struct alist *session_requests); - -struct channel_request * -make_shell_handler(struct io_backend *backend); - -struct channel_request * -make_exec_handler(struct io_backend *backend); - -struct channel_request * -make_subsystem_handler(struct io_backend *backend, - const char **subsystems); - -struct lsh_string * -format_exit_signal(struct ssh_channel *channel, - int core, int signal); -struct lsh_string * -format_exit(struct ssh_channel *channel, int value); - -extern struct channel_request -pty_request_handler; - -#endif /* LSH_SERVER_SESSION_H_INCLUDED */ diff --git a/lsh/src/server_userauth.c b/lsh/src/server_userauth.c deleted file mode 100755 index cf62504..0000000 --- a/lsh/src/server_userauth.c +++ /dev/null @@ -1,410 +0,0 @@ -/* server_userauth.c - * - * Server side user authentication. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999 Niels Möller - * - * 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 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 should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "server_userauth.h" - -#include "charset.h" -#include "connection.h" -#include "format.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - - -#define GABA_DEFINE -#include "server_userauth.h.x" -#undef GABA_DEFINE - -#include "server_userauth.c.x" - -struct lsh_string * -format_userauth_failure(struct int_list *methods, - int partial) -{ - return ssh_format("%c%A%c", SSH_MSG_USERAUTH_FAILURE, methods, partial); -} - -struct lsh_string * -format_userauth_success(void) -{ - return ssh_format("%c", SSH_MSG_USERAUTH_SUCCESS); -} - - -/* Max number of attempts */ -#define AUTH_ATTEMPTS 20 - -/* FIXME: There are no timeouts for authentications. The callouts in - * io.c could be used for timeouts, but it's not clear how the timeout - * handler can close the right connection. Using the right exception - * handler could work. */ - -/* NOTE: Here we assume that services and authentication methods are - * orthogonal. I.e. every supported authentication method is accepted - * for every supported service. */ - -/* GABA: - (class - (name userauth_handler) - (super packet_handler) - (vars - ; What to do after successful authentication. - (c object command_continuation) - - ; Handler to use when starting a new service. - (service_e object exception_handler) - - ; Handler to use when invoking an authentication method. - (auth_e object exception_handler) - - ; Maps authentication methods to userauth objects - (methods object alist) - - ; Maps services to commands - (services object alist))) -*/ - -/* FIXME: This code doesn't handle authentication methods where the - * result (continuation or exception) is not invoked immediately. - * There are two problems: - * - * 1. Requests are not necessarily replied to in order. That is bad, - * but can probably be fixed fairly easily the same way that it is - * done for GLOBAL_REQUEST messages. - * - * 2. Packets that are received after a sucessful USERAUTH_REQUEST - * message, but before it is processed and replied to, must somehow be - * queued until we know that the user is authenticated for some - * service to receive them. - * - * I think the right thing to do is to serialize userauth requests - * completely: if a request can't be replied to immediately, put the - * entire connection on hold until the reply is ready. - * - * This code now uses serialization, using connection_lock and - * connection_unlock. However, the implementation of serialization - * is rather stupid. And will crash if a userauth method returns to - * the main loop while the connection is still locked. */ - -/* GABA: - (class - (name userauth_continuation) - (super command_continuation) - (vars - (up object command_continuation) - (connection object ssh_connection))) -*/ - -static void -do_userauth_continuation(struct command_continuation *s, - struct lsh_object *a) -{ - CAST(userauth_continuation, self, s); - CAST_SUBTYPE(lsh_user, user, a); - - unsigned i; - - /* Access granted. */ - - assert(user); - self->connection->user = user; - - /* Unlock connection */ - connection_unlock(self->connection); - - C_WRITE(self->connection, format_userauth_success()); - - /* Ignore any further userauth messages. */ - for (i = SSH_FIRST_USERAUTH_GENERIC; i < SSH_FIRST_CONNECTION_GENERIC; i++) - self->connection->dispatch[i] = &connection_ignore_handler; - - COMMAND_RETURN(self->up, self->connection); - - /* NOTE: It would be better to use a callout, so that we return back - * to the backend loop before starting to process new packets. It's - * not obvious that calling connection_handle_pending here is - * safe. - * - * connection_handle_pending(self->connection); - */ -} - -static struct command_continuation * -make_userauth_continuation(struct ssh_connection *connection, - struct command_continuation *c) -{ - NEW(userauth_continuation, self); - self->super.c = do_userauth_continuation; - self->up = c; - - self->connection = connection; - - return &self->super; -} - -/* FIXME: Perhaps this should use a two-dimensional lookup, and call - * an authentication object depending on both service and method? */ - -/* NOTE: This implementation does not use any partial successes. As - * soon as one authentication request is successful, the - * entire authentication process succeeds. */ -static void -do_handle_userauth(struct packet_handler *s, - struct ssh_connection *connection, - struct lsh_string *packet) -{ - CAST(userauth_handler, self, s); - struct simple_buffer buffer; - - unsigned msg_number; - struct lsh_string *user; - int requested_service; - int method; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_USERAUTH_REQUEST) - && ( (user = parse_string_copy(&buffer)) ) - && parse_atom(&buffer, &requested_service) - && parse_atom(&buffer, &method)) - { - CAST_SUBTYPE(userauth, auth, ALIST_GET(self->methods, method)); - CAST_SUBTYPE(command, service, - ALIST_GET(self->services, requested_service)); - - /* Serialize handling of userauth requests */ - connection_lock(connection); - - if (!(auth && service)) - { - static const struct exception userauth_failed - = STATIC_EXCEPTION(EXC_USERAUTH, - "Unknown auth method or service."); - - EXCEPTION_RAISE(self->auth_e, &userauth_failed); - return; - } - - /* FIXME: Do the user_db lookup here? */ - AUTHENTICATE(auth, connection, user, requested_service, &buffer, - make_userauth_continuation(connection, - make_apply(service, self->c, self->service_e)), - self->auth_e); - } - else - PROTOCOL_ERROR(connection->e, "Invalid USERAUTH message."); -} - -static struct packet_handler * -make_userauth_handler(struct alist *methods, - struct alist *services, - struct command_continuation *c, - struct exception_handler *service_e, - struct exception_handler *auth_e) -{ - NEW(userauth_handler, auth); - - auth->super.handler = do_handle_userauth; - auth->methods = methods; - auth->services = services; - auth->c = c; - auth->service_e = service_e; - auth->auth_e = auth_e; - - return &auth->super; -} - - -/* GABA: - (class - (name exc_userauth_handler) - (super exception_handler) - (vars - (connection object ssh_connection) - - ; Methods advertised in failure messages - (advertised_methods object int_list) - - ; Allowed number of failures before disconnecting - (attempts . unsigned))) -*/ - -static void -do_exc_userauth_handler(struct exception_handler *s, - const struct exception *x) -{ - CAST(exc_userauth_handler, self, s); - - switch(x->type) - { - default: - EXCEPTION_RAISE(self->super.parent, x); - break; - - case EXC_PROTOCOL: - /* Protocol errors should be handled by the connection's - * exception handler, not our parent's. */ - EXCEPTION_RAISE(self->connection->e, x); - break; - - case EXC_USERAUTH: - { - /* Unlock connection */ - connection_unlock(self->connection); - - if (self->attempts) - { - self->attempts--; - C_WRITE(self->connection, - format_userauth_failure(self->advertised_methods, 0)); - } - else - { - EXCEPTION_RAISE(self->connection->e, - make_protocol_exception(SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, - "Access denied")); - } - - /* FIXME: Possibly call connection_handle_pending. */ - break; - } - case EXC_USERAUTH_SPECIAL: - { - CAST_SUBTYPE(userauth_special_exception, e, x); - - /* Unlock connection */ - connection_unlock(self->connection); - - /* NOTE: We can't NULL e->reply, since the exception is supposed to be constant. - * So we have to dup it, to make the gc happy. */ - C_WRITE(self->connection, lsh_string_dup(e->reply)); - - /* FIXME: Possibly call connection_handle_pending. */ - break; - } - } -} - -struct exception_handler * -make_exc_userauth_handler(struct ssh_connection *connection, - struct int_list *advertised_methods, - unsigned attempts, - struct exception_handler *parent, - const char *context) -{ - NEW(exc_userauth_handler, self); - self->super.raise = do_exc_userauth_handler; - self->super.parent = parent; - self->super.context = context; - - self->connection = connection; - self->advertised_methods = advertised_methods; - self->attempts = attempts; - - return &self->super; -} - - -static void -do_userauth(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(userauth_service, self, s); - CAST(ssh_connection, connection, x); - - if (connection->user) - { - werror("do_userauth: Dropping previous authentication for user '%pS'.\n", - connection->user->name); - connection->user = NULL; - } - - connection->dispatch[SSH_MSG_USERAUTH_REQUEST] = - make_userauth_handler(self->methods, self->services, - c, e, - make_exc_userauth_handler(connection, - self->advertised_methods, - AUTH_ATTEMPTS, e, - HANDLER_CONTEXT)); -} - -struct command * -make_userauth_service(struct int_list *advertised_methods, - struct alist *methods, - struct alist *services) -{ - NEW(userauth_service, self); - - self->super.call = do_userauth; - self->advertised_methods = advertised_methods; - self->methods = methods; - self->services = services; - - return &self->super; -} - - -/* None service (which works like external-keyexchange) */ -static void -do_none_authenticate(struct userauth *s UNUSED, - struct ssh_connection *connection UNUSED, - struct lsh_string *username, - UINT32 service UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - username = utf8_to_local(username, 1, 1); - if (!username) - { - PROTOCOL_ERROR(e, "Invalid utf8 in username."); - return; - } - - if (parse_eod(args)) - { - static const struct exception wrong_user - = STATIC_EXCEPTION(EXC_USERAUTH, - "User needs to authenticate properly"); - - if (connection->user - && lsh_string_eq(username, connection->user->name)) - COMMAND_RETURN(c, connection->user); - else - EXCEPTION_RAISE(e, &wrong_user); - } - else - PROTOCOL_ERROR(e, "Invalid none USERAUTH message."); - - lsh_string_free(username); -} - -struct userauth server_userauth_none = - { STATIC_HEADER, do_none_authenticate }; diff --git a/lsh/src/server_userauth.c.x b/lsh/src/server_userauth.c.x deleted file mode 100755 index 6187327..0000000 Binary files a/lsh/src/server_userauth.c.x and /dev/null differ diff --git a/lsh/src/server_userauth.h b/lsh/src/server_userauth.h deleted file mode 100755 index 7a14635..0000000 --- a/lsh/src/server_userauth.h +++ /dev/null @@ -1,119 +0,0 @@ -/* server_userauth.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SERVER_USERAUTH_H_INCLUDED -#define LSH_SERVER_USERAUTH_H_INCLUDED - -#include "alist.h" -#include "command.h" -#include "connection.h" -#include "io.h" -#include "parse.h" -#include "userauth.h" - -/* For uid_t and gid_t */ - -#if HAVE_UNISTD_H -#include -#endif - -#define GABA_DECLARE -#include "server_userauth.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name user_db) - (vars - ;; FIXME: Do we really need the FREE parameter? - (lookup method "struct lsh_user *" - "struct lsh_string *name" "int free"))) -*/ - -#define USER_LOOKUP(db, n, f) ((db)->lookup((db), (n), (f))) - -struct user_db * -make_unix_user_db(struct io_backend *backend, struct reap *reaper, - const char *pw_helper, const char *login_shell, - int allow_root); - -/* GABA: - (class - (name userauth) - (vars - (authenticate method void - "struct ssh_connection *connection" - ; The name is consumed by this function - "struct lsh_string *username" - "UINT32 service" - "struct simple_buffer *args" - "struct command_continuation *c" - "struct exception_handler *e"))) -*/ - -#define AUTHENTICATE(s, n, u, v, a, c, e) \ -((s)->authenticate((s), (n), (u), (v), (a), (c), (e))) - -/* NOTE: This class struct is used also by proxy_userauth.c. */ - -/* GABA: - (class - (name userauth_service) - (super command) - (vars - (advertised_methods object int_list) - (methods object alist) - (services object alist))) -*/ - -struct lsh_string * -format_userauth_failure(struct int_list *methods, - int partial); -struct lsh_string * -format_userauth_success(void); - -/* authentication methods */ - -extern struct userauth server_userauth_none; - -struct userauth * -make_userauth_password(struct user_db *db); - -struct userauth * -make_userauth_publickey(struct user_db *db, - struct alist *verifiers); - -struct command * -make_userauth_service(struct int_list *advertised_methods, - struct alist *methods, - struct alist *services); - -struct exception_handler * -make_exc_userauth_handler(struct ssh_connection *connection, - struct int_list *advertised_methods, - unsigned attempts, - struct exception_handler *parent, - const char *context); - -#endif /* LSH_SERVER_USERAUTH_H_INCLUDED */ diff --git a/lsh/src/server_userauth.h.x b/lsh/src/server_userauth.h.x deleted file mode 100755 index e5bf69b..0000000 Binary files a/lsh/src/server_userauth.h.x and /dev/null differ diff --git a/lsh/src/sexp-conv.c b/lsh/src/sexp-conv.c deleted file mode 100755 index c2815be..0000000 --- a/lsh/src/sexp-conv.c +++ /dev/null @@ -1,438 +0,0 @@ -/* sexp-conv.c - * - * Reads a sexp in given form from, and writes it in given form. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#if macintosh -#include "lshprefix.h" -#include "lsh_context.h" -#endif - -#include "algorithms.h" -#include "alist.h" -#include "atoms.h" -#include "crypto.h" -#include "io.h" -#include "lsh.h" -#include "lsh_argp.h" -#include "sexp_commands.h" -#include "spki_commands.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#include "sexp-conv.c.x" - -/* Global, for simplicity */ -int exit_code = EXIT_SUCCESS; - -/* GABA: - (expr - (name make_sexp_conv) - (params - (read object command) - (select object command) - (transform object command) - (print object command) - (dest object abstract_write)) - (expr - (lambda (in) - (print dest (transform (select (read in))))))) -*/ - - -static void -do_exc_sexp_conv_handler(struct exception_handler *self, - const struct exception *x) -{ - /* CAST(exc_sexp_conv_handler, self, s); */ - - switch (x->type) - { - case EXC_SEXP_SYNTAX: - werror("Invalid SEXP input.\n"); - exit_code = EXIT_FAILURE; - /* Fall through */ - case EXC_SEXP_EOF: - /* Normal termination */ - EXCEPTION_RAISE(self->parent, &finish_read_exception); - break; - case EXC_IO_WRITE: - case EXC_IO_READ: - { - CAST(io_exception, e, x); - exit_code = EXIT_FAILURE; - werror("sexp-conv: %z, (errno = %i)\n", x->msg, e->error); - break; - } - default: - exit_code = EXIT_FAILURE; - EXCEPTION_RAISE(self->parent, x); - return; - } -} - -enum sexp_select_ops { OP_CAR, OP_CDR, OP_RETURN_CAR }; - -/* GABA: - (class - (name sexp_select_command) - (super command) - (vars - (ops object int_list))) -*/ - -static void -do_sexp_select(struct command *s, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(sexp_select_command, self, s); - CAST_SUBTYPE(sexp, expr, x); - struct sexp_iterator *i; - unsigned j; - - static const struct exception non_list = - STATIC_EXCEPTION(EXC_SEXP_SYNTAX, - "Attemt to select in a non-list expression."); - - static const struct exception list_exhausted = - STATIC_EXCEPTION(EXC_SEXP_SYNTAX, - "List exhausted while selecting."); - - if (sexp_atomp(expr)) - { - EXCEPTION_RAISE(e, &non_list); - return; - } - - i = SEXP_ITER(expr); - - for (j = 0; j < LIST_LENGTH(self->ops); j++) - switch (LIST(self->ops)[j]) - { - case OP_RETURN_CAR: - { - struct sexp *expr = SEXP_GET(i); - if (!expr) - EXCEPTION_RAISE(e, &list_exhausted); - else - COMMAND_RETURN(c, expr); - - return; - } - case OP_CAR: - { - struct sexp *expr = SEXP_GET(i); - if (!expr) - { - EXCEPTION_RAISE(e, &list_exhausted); - return; - } - - if (sexp_atomp(expr)) - { - EXCEPTION_RAISE(e, &non_list); - return; - } - i = SEXP_ITER(expr); - - break; - } - case OP_CDR: - SEXP_NEXT(i); - if (!SEXP_LEFT(i)) - { - EXCEPTION_RAISE(e, &list_exhausted); - return; - } - break; - } - - fatal("do_sexp_select: Internal error!\n"); -} - -static struct command * -make_sexp_select_command(const char *arg) -{ - unsigned len = strlen(arg); - - /* Check syntax */ - if ( (len >= 3) - && (arg[0] == 'c') - && (arg[1] == 'a') - && (arg[len-1] == 'r')) - { - struct int_list *ops = alloc_int_list(len - 2); - unsigned i; - - for (i = 0; i < len - 3; i++) - switch(arg[len - i - 2]) - { - case 'a': - LIST(ops)[i] = OP_CAR; - break; - case 'd': - LIST(ops)[i] = OP_CDR; - break; - default: - KILL(ops); - return NULL; - } - - LIST(ops)[i++] = OP_RETURN_CAR; - assert (i == LIST_LENGTH(ops)); - - { - NEW(sexp_select_command, self); - self->super.call = do_sexp_select; - self->ops = ops; - - return &self->super; - } - } - else - return NULL; -} - -/* Option parsing */ - -const char *argp_program_version -= "sexp-conv-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -#define OPT_HASH 0x200 -#define OPT_SPKI_HASH 0x201 -#define OPT_RAW_HASH 0x202 -#define OPT_ONCE 0x203 -#define OPT_SELECT 0x204 - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "spki-hash", OPT_SPKI_HASH, NULL, 0, "Output an SPKI hash for the object.", 0 }, - { "raw-hash", OPT_RAW_HASH, NULL, 0, "Output the hash for the canonical " - "representation of the object, in hexadecimal.", 0 }, - { "hash", OPT_HASH, "Algorithm", 0, "Hash algorithm (default sha1).", 0 }, - { "select", OPT_SELECT, "Operator", 0, "Select a subexpression " - "(e.g \"caddr\") for processing.", 0 }, - { "once", OPT_ONCE, NULL, 0, "Process at most one s-expression.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -#define MODE_VANILLA 0 -#define MODE_RAW_HASH 1 -#define MODE_SPKI_HASH 2 - -/* GABA: -(class - (name sexp_conv_options) - (vars - (input . sexp_argp_state) - (output . sexp_argp_state) - (once . int) - (mode . int) - (algorithms object alist) - (hash . int) - (select object command) - (transform object command) - (print object command) -)) -*/ - -static struct sexp_conv_options *make_options(void) -{ - NEW(sexp_conv_options, self); - self->input = SEXP_TRANSPORT; - self->output = SEXP_ADVANCED; - self->once = 0; - self->mode = MODE_VANILLA; - self->select = &command_I; - self->transform = &command_I; - self->algorithms = make_alist(2, - ATOM_MD5, &md5_algorithm, - ATOM_SHA1, &sha1_algorithm, - -1); - self->hash = ATOM_SHA1; - - return self; -} - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_input_argp, 0, NULL, 0 }, - { &sexp_output_argp, 0, NULL, 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(sexp_conv_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->input; - state->child_inputs[1] = &self->output; - state->child_inputs[2] = NULL; - break; - case ARGP_KEY_END: - { - switch(self->mode) - { - default: - fatal("Internal error!"); - case MODE_VANILLA: - self->transform = &command_I; - self->print = &make_sexp_print_command(self->output)->super; - break; - case MODE_SPKI_HASH: - { - CAST_SUBTYPE(hash_algorithm, a, - ALIST_GET(self->algorithms, self->hash)); - self->transform = make_spki_hash(self->hash, a); - self->print = &make_sexp_print_command(self->output)->super; - break; - } - case MODE_RAW_HASH: - { - CAST_SUBTYPE(hash_algorithm, a, - ALIST_GET(self->algorithms, self->hash)); - self->transform = &command_I; - self->print = make_sexp_print_raw_hash(a); - break; - } - } - break; - } - case OPT_HASH: - { - int hash = lookup_hash(self->algorithms, arg, NULL, 0); - if (hash) - self->hash = hash; - else - argp_error(state, "Unknown hash algorithm '%s'.", arg); - break; - } - case OPT_SPKI_HASH: - self->mode = MODE_SPKI_HASH; - break; - case OPT_RAW_HASH: - self->mode = MODE_RAW_HASH; - break; - case OPT_SELECT: - { - struct command *sel = make_sexp_select_command(arg); - if (sel) - self->select = sel; - else - argp_error(state, "Unsupported select operator '%s' (the supported " - "ones are ca[ad]*r).", arg); - break; - } - case OPT_ONCE: - self->once = 1; - break; - } - - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - "Conversion: sexp-conv [options] OUTPUT\n" - "Fingerprinting: sexp-conv --raw-hash [ --hash=ALGORITHM ] input, - !options->once, - MAX_SEXP_SIZE), - options->select, - options->transform, - options->print, - &(io_write(make_lsh_fd(backend, - STDOUT_FILENO, - "stdout", - e), - SEXP_BUFFER_SIZE, - NULL) - ->write_buffer->super))); - - struct lsh_fd *in = make_lsh_fd(backend, STDIN_FILENO, "stdin", e); - - /* Fixing the exception handler creates a circularity */ - e->parent = make_exc_finish_read_handler(in, - &default_exception_handler, - HANDLER_CONTEXT); - - COMMAND_CALL(work, in, - &discard_continuation, e); - } - io_run(backend); - - return exit_code; -} diff --git a/lsh/src/sexp-conv.c.x b/lsh/src/sexp-conv.c.x deleted file mode 100755 index 05d6c22..0000000 Binary files a/lsh/src/sexp-conv.c.x and /dev/null differ diff --git a/lsh/src/sexp.c b/lsh/src/sexp.c deleted file mode 100755 index 1c83c7f..0000000 --- a/lsh/src/sexp.c +++ /dev/null @@ -1,937 +0,0 @@ -/* sexp.c - * - * An implementation of Ron Rivest's S-expressions, used in spki. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "sexp.h" - -#include "format.h" -#include "queue.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#define GABA_DEFINE -#include "sexp.h.x" -#undef GABA_DEFINE - -/* Defines int sexp_char_classes[0x100] */ -#define CHAR_CLASSES_TABLE sexp_char_classes -#include "sexp_table.h" -#undef CHAR_CLASSES_TABLE - -#include "sexp.c.x" - -/* GABA: - (class - (name sexp_string) - (super sexp) - (vars - (display const string) - (contents const string))) -*/ - -/* For advanced format */ -static struct lsh_string * -do_format_simple_string(const struct lsh_string *s, - int style, - unsigned indent) -{ - int quote_friendly = ( (~CHAR_control & ~CHAR_international) - | CHAR_escapable); - - switch(style) - { - case SEXP_TRANSPORT: - fatal("Internal error!\n"); - case SEXP_CANONICAL: - return ssh_format("%dS", s); - case SEXP_INTERNATIONAL: - quote_friendly |= CHAR_international; - /* Fall through */ - case SEXP_ADVANCED: - { - int c; - unsigned i; - - if (!s->length) - return ssh_format("\"\""); - - /* Compute the set of all character classes represented in the string */ - for (c = 0, i = 0; i < s->length; i++) - c |= sexp_char_classes[s->data[i]]; - - if (! ( (sexp_char_classes[s->data[0]] & CHAR_digit) - || (c & ~(CHAR_alpha | CHAR_digit | CHAR_punctuation)))) - /* Output token, without any quoting at all */ - return lsh_string_dup(s); - - if (! (c & ~quote_friendly)) - { - /* Count the number of characters needing escape */ - unsigned length = s->length; - unsigned i; - struct lsh_string *res; - UINT8 *dst; - - for (i = 0; ilength; i++) - if (sexp_char_classes[s->data[i]] & CHAR_escapable) - length++; - - res = ssh_format("\"%lr\"", length, &dst); - for (i=0; ilength; i++) - if (sexp_char_classes[s->data[i]] & CHAR_escapable) - { - *dst++ = '\\'; - switch(s->data[i]) - { - case '\b': - *dst++ = 'b'; - break; - case '\t': - *dst++ = 't'; - break; - case '\v': - *dst++ = 'v'; - break; - case '\n': - *dst++ = 'n'; - break; - case '\f': - *dst++ = 'f'; - break; - case '\r': - *dst++ = 'r'; - break; - case '\"': - *dst++ = '\"'; - break; - case '\\': - *dst++ = '\\'; - break; - default: - fatal("Internal error!\n"); - } - } - else - *dst++ = s->data[i]; - - assert(dst == (res->data + 1 + length)); - - return res; - } - /* Base 64 string */ - return encode_base64(s, "||", 1, indent + 1, 0); - } - default: - fatal("do_format_sexp_string: Unknown output style.\n"); - } -} - -static struct lsh_string * -do_format_sexp_string(struct sexp *s, - int style, unsigned indent) -{ - CAST(sexp_string, self, s); - - switch(style) - { - case SEXP_TRANSPORT: - fatal("Internal error!\n"); - case SEXP_ADVANCED: - case SEXP_INTERNATIONAL: - case SEXP_CANONICAL: - return (self->display) - ? ssh_format("[%lfS]%lfS", - do_format_simple_string(self->display, style, indent + 1), - do_format_simple_string(self->contents, style, indent)) - : do_format_simple_string(self->contents, style, indent); - - default: - fatal("do_format_sexp_string: Unknown output style.\n"); - } -} - -/* Consumes its args (display may be NULL) */ -struct sexp * -sexp_s(struct lsh_string *d, struct lsh_string *c) -{ - NEW(sexp_string, s); - assert(c); - - s->super.format = do_format_sexp_string; - s->super.iter = NULL; - - s->display = d; - s->contents = c; - - return &s->super; -} - -const struct lsh_string * -sexp_contents(const struct sexp *e) -{ - CAST(sexp_string, self, e); - return self->contents; -} - -const struct lsh_string * -sexp_display(const struct sexp *e) -{ - CAST(sexp_string, self, e); - return self->display; -} - -/* The nil expression. */ - -static struct sexp * -do_nil_get(struct sexp_iterator *c UNUSED) -{ - return NULL; -} - -static struct sexp * -do_nil_assoc(struct sexp_iterator *s UNUSED, UINT32 length UNUSED, - const UINT8 *name UNUSED, struct sexp_iterator **i UNUSED) -{ - return NULL; -} - -static unsigned -do_nil_left(struct sexp_iterator *c UNUSED) -{ - return 0; -} - -static void -do_nil_next(struct sexp_iterator *c UNUSED) -{} - -static struct sexp_iterator * -make_iter_nil(struct sexp *e UNUSED) -{ - static struct sexp_iterator nil_iterator = - { STATIC_HEADER, do_nil_get, do_nil_assoc, do_nil_left, do_nil_next }; - return &nil_iterator; -} - -static struct lsh_string * -do_format_nil(struct sexp *ignored UNUSED, int style UNUSED, - unsigned indent UNUSED) -{ - return ssh_format("()"); -} - -struct sexp sexp_nil = -{ STATIC_HEADER, make_iter_nil, do_format_nil }; - -#define SEXP_NIL (&sexp_nil) - -/* For assoc */ -struct sexp_iterator * -sexp_check_type_l(struct sexp *e, UINT32 length, - const UINT8 *name) -{ - if (!sexp_atomp(e)) - { - struct sexp_iterator *i = SEXP_ITER(e); - - if (sexp_eq(SEXP_GET(i), length, name)) - { - SEXP_NEXT(i); - return i; - } - else - KILL(i); - } - return NULL; -} - -/* Returns 1 if the type matches. - * - * FIXME: Do we relly need this interface, that allows res == NULL? */ -int -sexp_check_type(struct sexp *e, int type, struct sexp_iterator **res) -{ - struct sexp_iterator *i = - sexp_check_type_l(e, get_atom_length(type), get_atom_name(type)); - - if (i) - { - if (res) - *res = i; - else - KILL(i); - return 1; - } - return 0; -} - -static int -is_short(struct lsh_string *s) -{ - return ( (s->length < 15) - && !memchr(s->data, '\n', s->length) ); -} - -/* GABA: - (class - (name sexp_vector) - (super sexp) - (vars - ; FIXME: With better var-array support, this - ; could use an embedded var-array instead. - (elements object object_list))) -*/ - -/* GABA: - (class - (name sexp_iter_vector) - (super sexp_iterator) - (vars - (l object object_list) - (i . unsigned))) -*/ - -static struct sexp * -do_vector_get(struct sexp_iterator *c) -{ - CAST(sexp_iter_vector, i, c); - if (i->i < LIST_LENGTH(i->l)) - { - CAST_SUBTYPE(sexp, res, LIST(i->l)[i->i]); - return res; - } - return NULL; -} - -static struct sexp * -do_vector_assoc(struct sexp_iterator *s, UINT32 length, - const UINT8 *name, struct sexp_iterator **i) -{ - CAST(sexp_iter_vector, self, s); - unsigned j; - - for (j = self->i; j < LIST_LENGTH(self->l); j++) - { - CAST_SUBTYPE(sexp, e, LIST(self->l)[j]); - struct sexp_iterator *inner = sexp_check_type_l(e, length, name); - - if (inner) - { - if (i) - *i = inner; - - return e; - } - } - return NULL; -} - -static unsigned -do_vector_left(struct sexp_iterator *s) -{ - CAST(sexp_iter_vector, i, s); - return LIST_LENGTH(i->l) - i->i; -} - -static void -do_vector_next(struct sexp_iterator *c) -{ - CAST(sexp_iter_vector, i, c); - if (i->i < LIST_LENGTH(i->l)) - i->i++; -} - -static struct sexp_iterator * -make_iter_vector(struct sexp *s) -{ - CAST(sexp_vector, v, s); - NEW(sexp_iter_vector, iter); - - iter->super.get = do_vector_get; - iter->super.assoc = do_vector_assoc; - iter->super.left = do_vector_left; - iter->super.next = do_vector_next; - - iter->l = v->elements; - iter->i = 0; - - return &iter->super; -} - -static struct lsh_string * -do_format_sexp_vector(struct sexp *e, - int style, unsigned indent) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - CAST(sexp_vector, v, e); - - struct lsh_string *res; - UINT8 *dst; - - CAST_SUBTYPE(sexp, car, LIST(v->elements)[0]); - - assert(LIST_LENGTH(v->elements)); - - indent++; - - if (LIST_LENGTH(v->elements) == 1) - { - CAST_SUBTYPE(sexp, car, LIST(v->elements)[0]); - - return ssh_format("(%lfS)", sexp_format(car, style, indent)); - } - - switch(style) - { - case SEXP_TRANSPORT: - fatal("Internal error!\n"); - case SEXP_ADVANCED: - case SEXP_INTERNATIONAL: - { - struct lsh_string **elements; - - unsigned i; - UINT32 size; - - /* align_after means formatting like - * - * (tag a - * b) - */ - unsigned align_after = 0; - - struct lsh_string *tag = sexp_format(car, style, indent); - - if (is_short(tag)) - { - indent += tag->length + 1; - align_after = 1; - } - - /* NOTE: The first element is never used. */ - elements = alloca(LIST_LENGTH(v->elements) - * sizeof(struct lsh_string *) ); - - for (i = 1, size = 0; ielements); i++) - { - CAST_SUBTYPE(sexp, o, LIST(v->elements)[i]); - - elements[i] = sexp_format(o, style, indent); - size += elements[i]->length; - } - - /* Count a single character separator between each element. */ - size += LIST_LENGTH(v->elements) - 1; - - /* Count extra indentation */ - size += indent * (LIST_LENGTH(v->elements) + !align_after - 2); - - res = ssh_format("(%lS%lr)", tag, size, &dst); - - for (i = 1; ielements); i++) - { - if (i <= align_after) - *dst++ = ' '; - else - { - *dst++ = '\n'; - memset(dst, ' ', indent); - dst += indent; - } - memcpy(dst, elements[i]->data, elements[i]->length); - dst += elements[i]->length; - - lsh_string_free(elements[i]); - } - - break; - } - case SEXP_CANONICAL: - { - struct lsh_string **elements - = alloca(LIST_LENGTH(v->elements) - * sizeof(struct lsh_string *) ); - - unsigned i; - UINT32 size; - - for (i = 0, size = 0; ielements); i++) - { - CAST_SUBTYPE(sexp, o, LIST(v->elements)[i]); - - elements[i] = sexp_format(o, style, indent + 1); - size += elements[i]->length; - } - - res = ssh_format("(%lr)", size, &dst); - - for (i = 0; ielements); i++) - { - memcpy(dst, elements[i]->data, elements[i]->length); - dst += elements[i]->length; - - lsh_string_free(elements[i]); - } - - break; - } - default: - fatal("do_format_sexp_vector: Unknown output style.\n"); - } - - assert( (dst + 1) == (res->data + res->length)); - -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return res; - -} - -struct sexp * -sexp_v(struct object_list *l) -{ - if (LIST_LENGTH(l)) - { - NEW(sexp_vector, v); - - v->super.format = do_format_sexp_vector; - v->super.iter = make_iter_vector; - - v->elements = l; - - return &v->super; - } - else - return SEXP_NIL; -} - -struct sexp * -sexp_l(unsigned n, ...) -{ - va_list args; - - va_start(args, n); - - if (!n) - { - assert(va_arg(args, int) == -1); - va_end(args); - return SEXP_NIL; - } - else - { - struct sexp *v = sexp_v(make_object_listv(n, args)); - - va_end(args); - - return v; - } -} - -struct sexp * -sexp_a(const int a) -{ - return sexp_s(NULL, ssh_format("%la", a)); -} - -struct sexp * -sexp_z(const char *s) -{ - return sexp_s(NULL, ssh_format("%lz", s)); -} - -/* mpz->sexp */ -struct sexp * -sexp_un(const mpz_t n) -{ - struct lsh_string *s; - UINT32 l = bignum_format_u_length(n); - - s = lsh_string_alloc(l); - l -= bignum_format_u(n, s->data); - - assert(!l); - - return sexp_s(NULL, s); -} - -/* Small unsigned int -> sexp */ -struct sexp * -sexp_uint32(UINT32 n) -{ - /* FIXME: Eliminate redundant leading zeroes. */ - struct lsh_string *digits = lsh_string_alloc(4); - WRITE_UINT32(digits->data, n); - return sexp_s(NULL, digits); -} - -struct lsh_string * -sexp_format(struct sexp *e, int style, unsigned indent) -{ - switch(style) - { - case SEXP_TRANSPORT: - return encode_base64(sexp_format(e, SEXP_CANONICAL, 0), "{}", 1, indent, 1); - case SEXP_CANONICAL: - case SEXP_ADVANCED: - case SEXP_INTERNATIONAL: - /* NOTE: Check for NULL here? I don't think so. */ - return SEXP_FORMAT(e, style, indent); - default: - fatal("sexp_format: Unknown output style.\n"); - } -} - -static void -encode_base64_group(UINT32 n, UINT8 *dest) -{ - static const UINT8 digits[64] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" - "ghijklmnopqrstuvwxyz0123456789+/"; - unsigned i; - - for (i = 0; i<4; i++) - { - dest[3 - i] = digits[n & 0x3f]; - n >>= 6; - } -} - -/* In pretty-print mode, print 40 characters or 10 groups on each - * line. */ -#define GROUPS_PER_LINE 10 - -struct lsh_string * -encode_base64(const struct lsh_string *s, - const char *delimiters, - int break_lines, - unsigned indent, - int free) -{ - UINT32 full_groups = (s->length) / 3; - unsigned last = (s->length) % 3; - - /* We never fold after the last full group, so we don't fold strings - * with full_groups <= GROUPS_PER_LINE. */ - unsigned linebreaks = ( (break_lines && full_groups) - ? (full_groups - 1) / GROUPS_PER_LINE - : 0); - unsigned length = (full_groups + !!last) * 4 + (indent + 1) * linebreaks; - - const UINT8 *src = s->data; - UINT8 *dst; - - struct lsh_string *res - = (delimiters - ? ssh_format("%c%lr%c", delimiters[0], length, &dst, delimiters[1]) - : ssh_format("%lr", length, &dst)); - - if (full_groups) - { - unsigned i; - - /* Loop over all but the last group. */ - for (i=0; idata + res->length)); - - if (free) - lsh_string_free(s); - - return res; -} - -int -sexp_nullp(const struct sexp *e) -{ - return (e == SEXP_NIL); -} - -int -sexp_atomp(const struct sexp *e) -{ - return !e->iter; -} - -/* Checks that the sexp is a simple string (i.e. no display part) */ -const struct lsh_string * -sexp2string(struct sexp *e) -{ - return ( (e && sexp_atomp(e) && !sexp_display(e)) - ? sexp_contents(e) : NULL); -} - - -int -sexp2atom(struct sexp *e) -{ - const struct lsh_string *s = sexp2string(e); - return s ? lookup_atom(s->length, s->data) : 0; -} - -/* If limit is nonzero, at most that number of octets are allowed. */ -int -sexp2bignum_u(struct sexp *e, mpz_t n, UINT32 limit) -{ - const struct lsh_string *s = sexp2string(e); - - if (s) - { - if (limit && (s->length > limit)) - return 0; - - bignum_parse_u(n, s->length, s->data); - return 1; - } - else - return 0; -} - -int -sexp2uint32(struct sexp *e, UINT32 *n) -{ - const struct lsh_string *digits = sexp2string(e); - - if (!digits) - return 0; - - switch(digits->length) - { - case 0: - return 0; - case 1: - *n = digits->data[0]; - return 1; - case 2: - *n = READ_UINT16(digits->data); - return 1; - case 3: - *n = READ_UINT24(digits->data); - return 1; - case 4: - *n = READ_UINT32(digits->data); - return 1; - default: - { - UINT32 i; - UINT32 left; - - for (i = 0, left = digits->length; - left > 4; - i++, left--) - if (digits->data[i]) - return 0; - - *n = READ_UINT32(digits->data + i); - return 1; - } - } -} - -int -sexp_eq(struct sexp *e, UINT32 length, const UINT8 *name) -{ - const struct lsh_string *c = sexp2string(e); - - return c && lsh_string_eq_l(c, length, name); -} - -/* FIXME: sexp_atom_eq compares an sexp to a given atom, while - * sexp_atoms_eq compares two atomic sexps. - * - * This naming seems a little confusing. */ -int -sexp_atom_eq(struct sexp *e, int atom) -{ - return sexp_eq(e, get_atom_length(atom), get_atom_name(atom)); -} - -/* Assumes that both expressions are atoms */ -int -sexp_atoms_eq(struct sexp *a, struct sexp *b) -{ - const struct lsh_string *ac = sexp_contents(a); - const struct lsh_string *ad = sexp_display(a); - const struct lsh_string *bc = sexp_contents(b); - const struct lsh_string *bd = sexp_display(b); - - return lsh_string_eq(ac, bc) - && (ad ? (bd && lsh_string_eq(ad, bd)) - : !bd); -} - -struct sexp * -sexp_assq(struct sexp_iterator *i, int atom) -{ - struct sexp_iterator *inner; - if (SEXP_ASSOC(i, get_atom_length(atom), get_atom_name(atom), &inner) - && (SEXP_LEFT(inner) == 1)) - { - struct sexp *value = SEXP_GET(inner); - assert(value); - - KILL(inner); - return value; - } - else - return NULL; -} - -int -sexp_get_un(struct sexp_iterator *i, int atom, mpz_t n, UINT32 limit) -{ - return sexp2bignum_u(sexp_assq(i, atom), n, limit); -} - -/* Command line options */ -struct sexp_format -{ - char *name; - int id; -}; - -static const struct sexp_format -sexp_formats[] = -{ - { "transport", SEXP_TRANSPORT }, - { "canonical", SEXP_CANONICAL }, - { "advanced", SEXP_ADVANCED }, - { "international", SEXP_INTERNATIONAL }, - { NULL, 0 } -}; - -static int -lookup_sexp_format(const char *name) -{ - int i; - - for (i = 0; sexp_formats[i].name; i++) - { - if (strcmp(sexp_formats[i].name, name) == 0) - return sexp_formats[i].id; - } - return -1; -} - -static const struct argp_option -sexp_input_options[] = -{ - { NULL, 0, NULL, 0, "Valid sexp-formats are transport, canonical, " - "advanced and international.", 0 }, - { "input-format", 'i', "format", 0, - "Variant of the s-expression syntax to accept.", 0}, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_option -sexp_output_options[] = -{ - { NULL, 0, NULL, 0, "Valid sexp-formats are transport, canonical, " - "advanced and international.", 0 }, - { "output-format", 'f', "format", 0, - "Variant of the s-expression syntax to generate.", 0}, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static error_t -sexp_argp_parser(int key, char *arg, struct argp_state *state) -{ - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case 'f': - case 'i': - { - int format = lookup_sexp_format(arg); - if (format < 0) - argp_error(state, "Unknown s-expression format '%s'", arg); - else - *(sexp_argp_state *) (state->input) = format; - - break; - } - } - return 0; -} - -const struct argp -sexp_input_argp = -{ - sexp_input_options, - sexp_argp_parser, - NULL, NULL, NULL, NULL, NULL -}; - -const struct argp -sexp_output_argp = -{ - sexp_output_options, - sexp_argp_parser, - NULL, NULL, NULL, NULL, NULL -}; diff --git a/lsh/src/sexp.c.x b/lsh/src/sexp.c.x deleted file mode 100755 index 61af988..0000000 Binary files a/lsh/src/sexp.c.x and /dev/null differ diff --git a/lsh/src/sexp.h b/lsh/src/sexp.h deleted file mode 100755 index 44bad8b..0000000 --- a/lsh/src/sexp.h +++ /dev/null @@ -1,199 +0,0 @@ -/* sexp.h - * - * An implementation of Ron Rivest's S-expressions, used in spki. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SEXP_H_INCLUDED -#define LSH_SEXP_H_INCLUDED - -#include "bignum.h" -#include "command.h" -#include "list.h" -#include "lsh_argp.h" -#include "parse.h" - -#include "sexp_table.h" - - -#define GABA_DECLARE -#include "sexp.h.x" -#undef GABA_DECLARE - -/* FIXME: Do some constification. Strings inside sexpressions should - * always be const. */ - -/* GABA: - (class - (name sexp) - (vars - ; NULL for non-lists - (iter method "struct sexp_iterator *") - (format method "struct lsh_string *" "int style" "unsigned indent"))) -*/ - -#define SEXP_FORMAT(e, s, i) ((e)->format((e), (s), (i))) -#define SEXP_ITER(e) ((e)->iter((e))) - -/* Iterator abstraction idea taken from Ron's code */ -/* FIXME: It would make a lot of sense to use (meta)class methods for - * iterators. */ -/* GABA: - (class - (name sexp_iterator) - (vars - (get method "struct sexp *") - (assoc method "struct sexp *" - "UINT32 length" "const UINT8 *name" - "struct sexp_iterator **i") - (left method unsigned) - (next method void))) -*/ - -#define SEXP_GET(i) ((i)->get((i))) -#define SEXP_ASSOC(s, l, n, i) ((s)->assoc((s), (l), (n), (i))) -#define SEXP_LEFT(i) ((i)->left((i))) -#define SEXP_NEXT(i) ((i)->next((i))) - -/* Syntax styles */ - -#define SEXP_CANONICAL 0 -#define SEXP_TRANSPORT 1 -#define SEXP_ADVANCED 2 - -/* Like advanced, but allow international characters in quoted strings. */ -#define SEXP_INTERNATIONAL 3 - -struct lsh_string *sexp_format(struct sexp *e, int style, unsigned indent); - -struct lsh_string * -encode_base64(const struct lsh_string *s, - const char *delimiters, - int break_lines, - unsigned indent, int free); - -/* Creating sexps */ - -/* Consumes its args (display may be NULL) */ -struct sexp *sexp_s(struct lsh_string *d, struct lsh_string *c); - -/* atom->sexp */ -struct sexp *sexp_a(const int a); - -/* cstring->sexp */ -struct sexp *sexp_z(const char *s); - -/* mpz->sexp */ -struct sexp *sexp_un(const mpz_t n); -struct sexp *sexp_sn(const mpz_t n); - -/* Small unsigned int -> sexp */ -struct sexp *sexp_uint32(UINT32 n); - -/* list */ -struct sexp *sexp_l(unsigned n, ...); - -/* vector */ -struct sexp *sexp_v(struct object_list *l); - -int sexp_nullp(const struct sexp *e); -int sexp_atomp(const struct sexp *e); - -/* Checks that the sexp is a simple string (i.e. no display part). - * e == NULL is allowed. */ -const struct lsh_string *sexp2string(struct sexp *e); - -/* Returns an ATOM_FOO constant if e is a simple sexp string - * corresponding to an atom. Or zero if that is not the case. */ -int sexp2atom(struct sexp *e); - -int -sexp2bignum_u(struct sexp *e, mpz_t n, UINT32 limit); - -int -sexp2uint32(struct sexp *e, UINT32 *n); - -const struct lsh_string *sexp_contents(const struct sexp *e); -const struct lsh_string *sexp_display(const struct sexp *e); -int sexp_atom(const struct sexp *e); -int sexp_bignum_u(const struct sexp *e, mpz_t n); -int sexp_bignum_s(const struct sexp *e, mpz_t n); - -/* Utility functions for parsing spki objects. */ - -int -sexp_eq(struct sexp *e, UINT32 length, const UINT8 *name); - -int -sexp_atom_eq(struct sexp *e, int atom); - -int -sexp_atoms_eq(struct sexp *a, struct sexp *b); - -struct sexp * -sexp_assq(struct sexp_iterator *i, int atom); - -struct sexp_iterator * -sexp_check_type_l(struct sexp *e, UINT32 length, - const UINT8 *name); - -int -sexp_check_type(struct sexp *e, int type, struct sexp_iterator **res); - - -int sexp_get_un(struct sexp_iterator *i, int atom, mpz_t n, UINT32 limit); - -extern int sexp_char_classes[]; - - -/* Simple sexp parser */ - -struct sexp * -sexp_parse_canonical(struct simple_buffer *buffer); - -struct sexp * -sexp_parse_transport(struct simple_buffer *buffer); - -struct sexp * -sexp_parse(int style, struct simple_buffer *buffer); - -struct sexp * -string_to_sexp(int style, const struct lsh_string *src, int free); - - -#if 0 -/* Streamed parser */ - -struct read_handler * -make_read_sexp(int style, int goon, - struct command_continuation *c, - struct exception_handler *e); -#endif - -extern const struct argp sexp_input_argp; -extern const struct argp sexp_output_argp; - -typedef int sexp_argp_state; - -#endif /* LSH_SEXP_H_INCLUDED */ - - diff --git a/lsh/src/sexp.h.x b/lsh/src/sexp.h.x deleted file mode 100755 index 15caae1..0000000 Binary files a/lsh/src/sexp.h.x and /dev/null differ diff --git a/lsh/src/sexp_chars.in b/lsh/src/sexp_chars.in deleted file mode 100755 index 557152c..0000000 Binary files a/lsh/src/sexp_chars.in and /dev/null differ diff --git a/lsh/src/sexp_commands.c b/lsh/src/sexp_commands.c deleted file mode 100755 index 75aa3d8..0000000 --- a/lsh/src/sexp_commands.c +++ /dev/null @@ -1,272 +0,0 @@ -/* sexp_commands.c - * - * Reading and writing of s-expressions. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "sexp_commands.h" - -#include "format.h" -#include "io.h" -#include "read_file.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Forward declarations */ -static struct catch_command catch_sexp_exceptions; -#define CATCH_SEXP (&catch_sexp_exceptions.super.super) - -static struct read_sexp_command read_sexp; -#define READ_SEXP (&read_sexp.super.super) - -#define GABA_DEFINE -#include "sexp_commands.h.x" -#undef GABA_DEFINE - -#include "sexp_commands.c.x" - -/* (write out sexp) - * - * Prints the sexp to tha abstract_write OUT. Returns the sexp. */ - -static void -do_sexp_print(struct command_2 *s, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(sexp_print_command, self, s); - CAST_SUBTYPE(abstract_write, dest, a1); - CAST_SUBTYPE(sexp, o, a2); - - A_WRITE(dest, sexp_format(o, self->format, 0)); - if (self->format != SEXP_CANONICAL) - A_WRITE(dest, ssh_format("\n")); - - COMMAND_RETURN(c, o); -} - -struct command_2 * -make_sexp_print_command(int format) -{ - NEW(sexp_print_command, self); - self->super.super.call = do_command_2; - self->super.invoke = do_sexp_print; - self->format = format; - - return &self->super; -} - -struct command * -make_sexp_print_to(int format, struct abstract_write *dest) -{ - return - make_command_2_invoke(make_sexp_print_command(format), - &dest->super); -} - -DEFINE_COMMAND3(sexp_print_raw_hash) - (struct lsh_object *a1, - struct lsh_object *a2, - struct lsh_object *a3, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(hash_algorithm, algorithm, a1); - CAST_SUBTYPE(abstract_write, dest, a2); - CAST_SUBTYPE(sexp, o, a3); - - struct lsh_string *canonical = sexp_format(o, SEXP_CANONICAL, 0); - struct hash_instance *hash = MAKE_HASH(algorithm); - struct lsh_string *digest = lsh_string_alloc(hash->hash_size); - - HASH_UPDATE(hash, canonical->length, canonical->data); - HASH_DIGEST(hash, digest->data); - - lsh_string_free(canonical); - KILL(hash); - - A_WRITE(dest, ssh_format("%lxfS\n", digest)); - - COMMAND_RETURN(c, o); -} - -struct command * -make_sexp_print_raw_hash(struct hash_algorithm *algorithm) -{ - return make_command_3_invoke(&sexp_print_raw_hash, - &algorithm->super); -} - -/* GABA: - (class - (name sexp_parser) - (super abstract_write) - (vars - (style . int) - (c object command_continuation) - (e object exception_handler))) -*/ - -static const struct exception -sexp_syntax_exception = STATIC_EXCEPTION(EXC_SEXP_SYNTAX, - "Sexp syntax error"); - -static const struct exception -sexp_eof_exception = STATIC_EXCEPTION(EXC_SEXP_EOF, "All sexps read"); - -static void -do_sexp_parse_once(struct abstract_write *s, struct lsh_string *input) -{ - CAST(sexp_parser, self, s); - struct simple_buffer buffer; - struct sexp *expr; - - assert(input); - - simple_buffer_init(&buffer, input->length, input->data); - - expr = sexp_parse(self->style, &buffer); - if (!expr) - EXCEPTION_RAISE(self->e, &sexp_syntax_exception); - else - COMMAND_RETURN(self->c, expr); - - lsh_string_free(input); -} - -static void -do_sexp_parse_many(struct abstract_write *s, struct lsh_string *input) -{ - CAST(sexp_parser, self, s); - struct simple_buffer buffer; - const struct exception *e = &sexp_eof_exception; - - assert(input); - - simple_buffer_init(&buffer, input->length, input->data); - - while (!parse_eod(&buffer)) - { - struct sexp *expr = sexp_parse(self->style, &buffer); - if (!expr) - { - e = &sexp_syntax_exception; - break; - } - else - COMMAND_RETURN(self->c, expr); - } - - EXCEPTION_RAISE(self->e, e); - lsh_string_free(input); -} - -static struct abstract_write * -make_sexp_parser(int style, int goon, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(sexp_parser, self); - self->super.write = goon ? do_sexp_parse_many : do_sexp_parse_once; - self->style = style; - self->c = c; - self->e = e; - - return &self->super; -} - -#define SEXP_BUFFER_SIZE 1024 - -void -do_read_sexp(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(read_sexp_command, self, s); - CAST(lsh_fd, fd, a); - - trace("do_read_sexp\n"); - - assert(fd); - - io_read(fd, - make_buffered_read - (SEXP_BUFFER_SIZE, - make_read_file - (make_sexp_parser(self->format, - self->goon, - c, e), - self->max_size)), - NULL); -} - -struct command * -make_read_sexp_command(int format, int goon, UINT32 max_size) -{ - NEW(read_sexp_command, self); - - trace("make_read_sexp_command\n"); - - self->super.call = do_read_sexp; - self->format = format; - self->goon = goon; - self->max_size = max_size; - - return &self->super; -} - -static struct catch_command catch_sexp_exceptions -= STATIC_CATCH_COMMAND(EXC_ALL, EXC_SEXP_EOF, 1); - -/* Arbitrary limit on file size. */ -/*#define MAX_SEXP_SIZE 10000*/ -#define MAX_SEXP_SIZE 65536 - -static struct read_sexp_command read_sexp -= STATIC_READ_SEXP(SEXP_TRANSPORT, 1, MAX_SEXP_SIZE); - -/* GABA: - (expr - (name for_sexp) - (params - (handler object command)) - (expr - (lambda (proc) - (catch_sexp handler - (lambda (file) - (proc (read_sexp file))))))) -*/ - -DEFINE_COMMAND(for_sexp_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command, handler, a); - COMMAND_RETURN(c, for_sexp(handler)); -} diff --git a/lsh/src/sexp_commands.c.x b/lsh/src/sexp_commands.c.x deleted file mode 100755 index ced0d51..0000000 Binary files a/lsh/src/sexp_commands.c.x and /dev/null differ diff --git a/lsh/src/sexp_commands.h b/lsh/src/sexp_commands.h deleted file mode 100755 index 8e23b21..0000000 --- a/lsh/src/sexp_commands.h +++ /dev/null @@ -1,87 +0,0 @@ -/* sexp_commands.h - * - * Reading and writing of s-expressions. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef SEXP_COMMANDS_H_INCLUDED -#define SEXP_COMMANDS_H_INCLUDED - -#include "abstract_crypto.h" -#include "abstract_io.h" -#include "command.h" -#include "sexp.h" - -#define GABA_DECLARE -#include "sexp_commands.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name sexp_print_command) - (super command_2) - (vars - (format . int))) -*/ - -#define STATIC_PRINT_SEXP(format) \ -{{ STATIC_HEADER, do_command_2}, format } - -struct command_2 * -make_sexp_print_command(int format); - -struct command * -make_sexp_print_to(int format, struct abstract_write *dest); - -struct command * -make_sexp_print_raw_hash(struct hash_algorithm *algorithm); - -struct command * -make_sexp_print_raw_hash_to(struct hash_algorithm *algorithm, - struct abstract_write *dest); - -/* GABA: - (class - (name read_sexp_command) - (super command) - (vars - (format . int) - (goon . int) - (max_size . UINT32))) -*/ - -void -do_read_sexp(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e); - -#define STATIC_READ_SEXP(format, goon, max_size) \ -{ STATIC_COMMAND(do_read_sexp), format, goon, max_size } - -struct command * -make_read_sexp_command(int format, int goon, UINT32 max_size); - -extern struct command for_sexp_command; -#define FOR_SEXP (&for_sexp_command.super) - -#endif /* SEXP_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/sexp_commands.h.x b/lsh/src/sexp_commands.h.x deleted file mode 100755 index fb4f6b7..0000000 Binary files a/lsh/src/sexp_commands.h.x and /dev/null differ diff --git a/lsh/src/sexp_parser.c b/lsh/src/sexp_parser.c deleted file mode 100755 index adc74c3..0000000 --- a/lsh/src/sexp_parser.c +++ /dev/null @@ -1,335 +0,0 @@ -/* sexp_parser.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, Ron Rivest, Niels Möller - * - * 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 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 should 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 parser reads an sexp from a buffer in memory, and supports - * *only* the canonical syntax. */ - -#include "sexp.h" - -#include "digits.h" -#include "format.h" -#include "parse_macros.h" -#include "queue.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -/* Automatically generated files. */ -#include "sexp_table.h" - -/* Returns the length of the segment of characters of a class */ -static UINT32 -sexp_scan_class(struct simple_buffer *buffer, int class) -{ - UINT32 i; - - for (i=0; i MAX_DIGITS) - { - werror("sexp: Decimal number too long (%i digits, max is 8).\n", - length); - return 0; - } - for (i = 0, *value = 0; isuper); - } - werror("sexp: Unexpected EOF (missing ')')\n"); - - object_queue_kill(&p); - return NULL; -} - -struct sexp * -sexp_parse_canonical(struct simple_buffer *buffer) -{ - if (!LEFT) - { - werror("sexp: Unexpected EOF.\n"); - return NULL; - } - - switch(*HERE) - { - case '(': - ADVANCE(1); - return sexp_parse_list_canonical(buffer); - case '[': - ADVANCE(1); - return sexp_parse_display_canonical(buffer); - default: - { - struct lsh_string *s = sexp_parse_string_canonical(buffer); - return s ? sexp_s(NULL, s) : NULL; - } - } -} - - -static void -skip_space(struct simple_buffer *buffer) -{ - while (LEFT) - { - UINT32 length = sexp_scan_class(buffer, CHAR_space); - ADVANCE(length); - - if (LEFT && (*HERE == ';')) - while (LEFT && (*HERE != '\n')) - ADVANCE(1); - - else if (!length) - /* No comment, and no spaces skipped. Done. */ - return; - } -} - -/* NOTE: Implements the transport syntax. Also allows comments, - * starting with ';' and terminating at end of line. */ - -struct sexp * -sexp_parse_transport(struct simple_buffer *buffer) -{ - struct sexp *expr = NULL; - - skip_space(buffer); - - if (!LEFT) - { - werror("sexp: Unexpected EOF.\n"); - return NULL; - } - - if (*HERE != '{') - expr = sexp_parse_canonical(buffer); - - else - { - UINT32 length; - - ADVANCE(1); /* Skip '{', and search for '}'. */ - - for (length = 0; length < LEFT; length++) - if (HERE[length] == '}') - { - struct lsh_string *canonical = decode_base64(length, HERE); - struct simple_buffer inner; - - if (!canonical) - { - werror("sexp: Invalid transport encoding.\n"); - return NULL; - } - simple_buffer_init(&inner, canonical->length, canonical->data); - expr = sexp_parse_canonical(&inner); - - lsh_string_free(canonical); - ADVANCE(length + 1); - break; - } - } - if (expr) - /* It seems a little redundant to skip space *both* before and after - * parsing an expression, but it's the simplest way to make sure we allow - * space both at the beginning and at the end of a file. - */ - skip_space(buffer); - else - werror("sexp: Missing } in transport encoding.\n"); - - return expr; - } - -struct sexp * -sexp_parse(int style, struct simple_buffer *buffer) -{ - switch(style) - { - case SEXP_CANONICAL: - return sexp_parse_canonical(buffer); - case SEXP_ADVANCED: - case SEXP_INTERNATIONAL: - werror("sexp syntax %i not supported in parser. " - "Using transport syntax instead.\n", style); - /* Fall through */ - case SEXP_TRANSPORT: - return sexp_parse_transport(buffer); - default: - fatal("sexp_parse: Internal error, style %i not implemented.\n", style); - } -} - -struct sexp * -string_to_sexp(int style, const struct lsh_string *src, int free) -{ - struct simple_buffer buffer; - struct sexp *e; - - simple_buffer_init(&buffer, src->length, src->data); - - e = sexp_parse(style, &buffer); - - if (e && !parse_eod(&buffer)) - e = NULL; - - if (free) - lsh_string_free(src); - - return e; - } diff --git a/lsh/src/sexp_table.h b/lsh/src/sexp_table.h deleted file mode 100755 index 38b10f9..0000000 --- a/lsh/src/sexp_table.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifdef CHAR_CLASSES_TABLE -int CHAR_CLASSES_TABLE[] = -{ - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<12, 1L<<11, 1L<<11, 1L<<12, 1L<<12, 1L<<11, 1L<<14, 1L<<14, - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<15, 1L<<0, 1L<<13, 1L<<0, 1L<<0, 1L<<0, 1L<<0, 1L<<0, - 1L<<0, 1L<<0, 1L<<4, 1L<<3, 1L<<0, 1L<<4, 1L<<4, 1L<<3, - 1L<<9, 1L<<9, 1L<<9, 1L<<9, 1L<<9, 1L<<9, 1L<<9, 1L<<9, - 1L<<10, 1L<<10, 1L<<4, 1L<<0, 1L<<0, 1L<<2, 1L<<0, 1L<<0, - 1L<<0, 1L<<5, 1L<<5, 1L<<5, 1L<<5, 1L<<5, 1L<<5, 1L<<7, - 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, - 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, 1L<<7, - 1L<<7, 1L<<7, 1L<<7, 1L<<0, 1L<<13, 1L<<0, 1L<<0, 1L<<4, - 1L<<0, 1L<<6, 1L<<6, 1L<<6, 1L<<6, 1L<<6, 1L<<6, 1L<<8, - 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, - 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, 1L<<8, - 1L<<8, 1L<<8, 1L<<8, 1L<<0, 1L<<0, 1L<<0, 1L<<0, 1L<<14, - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, 1L<<14, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, - 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1, 1L<<1 -}; -#else /* !CHAR_CLASSES_TABLE */ -#define CHAR_international (1L<<1) -#define CHAR_token (1L<<2 | 1L<<3 | 1L<<4 | 1L<<5 | 1L<<6 | 1L<<7 | 1L<<8 | 1L<<9 | 1L<<10) -#define CHAR_token_start (1L<<2 | 1L<<3 | 1L<<4 | 1L<<5 | 1L<<6 | 1L<<7 | 1L<<8) -#define CHAR_punctuation (1L<<2 | 1L<<3 | 1L<<4) -#define CHAR_escapable (1L<<11 | 1L<<12 | 1L<<13) -#define CHAR_control (1L<<11 | 1L<<12 | 1L<<14) -#define CHAR_base64_space (1L<<2 | 1L<<11 | 1L<<15) -#define CHAR_base64 (1L<<2 | 1L<<3 | 1L<<5 | 1L<<6 | 1L<<7 | 1L<<8 | 1L<<9 | 1L<<10) -#define CHAR_hex (1L<<5 | 1L<<6 | 1L<<9 | 1L<<10) -#define CHAR_octal (1L<<9) -#define CHAR_digit (1L<<9 | 1L<<10) -#define CHAR_space (1L<<11 | 1L<<15) -#define CHAR_alpha (1L<<5 | 1L<<6 | 1L<<7 | 1L<<8) -#define CHAR_upper (1L<<5 | 1L<<7) -#define CHAR_lower (1L<<6 | 1L<<8) -#define CHAR_other 1 -#endif /* !CHAR_CLASSES_TABLE */ diff --git a/lsh/src/sftp/Makefile.am b/lsh/src/sftp/Makefile.am deleted file mode 100644 index 22daa66..0000000 --- a/lsh/src/sftp/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -SUBDIRS = . testsuite - -AUTOMAKE_OPTIONS = foreign - -bin_PROGRAMS = sftp-server -noinst_PROGRAMS = sftp-test-client dump-hex - -EXTRA_DIST = buffer.h client.h filemode.h idcache.h sftp.h werror.h xmalloc.h - -sftp_server_SOURCES = sftp-server.c buffer.c filemode.c idcache.c xmalloc.c - -sftp_test_client_SOURCES = sftp-test-client.c buffer.c xmalloc.c werror.c client.c - diff --git a/lsh/src/sftp/Makefile.in b/lsh/src/sftp/Makefile.in deleted file mode 100644 index 12f8c2a..0000000 --- a/lsh/src/sftp/Makefile.in +++ /dev/null @@ -1,479 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = . - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -VERSION = @VERSION@ - -SUBDIRS = . testsuite - -AUTOMAKE_OPTIONS = foreign - -bin_PROGRAMS = sftp-server -noinst_PROGRAMS = sftp-test-client dump-hex - -EXTRA_DIST = buffer.h client.h filemode.h idcache.h sftp.h werror.h xmalloc.h - -sftp_server_SOURCES = sftp-server.c buffer.c filemode.c idcache.c xmalloc.c - -sftp_test_client_SOURCES = sftp-test-client.c buffer.c xmalloc.c werror.c client.c -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs -CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = -PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -sftp_server_OBJECTS = sftp-server.o buffer.o filemode.o idcache.o \ -xmalloc.o -sftp_server_LDADD = $(LDADD) -sftp_server_DEPENDENCIES = -sftp_server_LDFLAGS = -sftp_test_client_OBJECTS = sftp-test-client.o buffer.o xmalloc.o \ -werror.o client.o -sftp_test_client_LDADD = $(LDADD) -sftp_test_client_DEPENDENCIES = -sftp_test_client_LDFLAGS = -dump_hex_SOURCES = dump-hex.c -dump_hex_OBJECTS = dump-hex.o -dump_hex_LDADD = $(LDADD) -dump_hex_DEPENDENCIES = -dump_hex_LDFLAGS = -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = ./stamp-h.in Makefile.am Makefile.in acconfig.h \ -aclocal.m4 config.h.in configure configure.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = $(sftp_server_SOURCES) $(sftp_test_client_SOURCES) dump-hex.c -OBJECTS = $(sftp_server_OBJECTS) $(sftp_test_client_OBJECTS) dump-hex.o - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -$(ACLOCAL_M4): configure.in - cd $(srcdir) && $(ACLOCAL) - -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) - -config.h: stamp-h - @if test ! -f $@; then \ - rm -f stamp-h; \ - $(MAKE) stamp-h; \ - else :; fi -stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=config.h \ - $(SHELL) ./config.status - @echo timestamp > stamp-h 2> /dev/null -$(srcdir)/config.h.in: $(srcdir)/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/stamp-h.in; \ - $(MAKE) $(srcdir)/stamp-h.in; \ - else :; fi -$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f config.h - -maintainer-clean-hdr: - -mostlyclean-binPROGRAMS: - -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) - -distclean-binPROGRAMS: - -maintainer-clean-binPROGRAMS: - -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ - $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - else :; fi; \ - done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - list='$(bin_PROGRAMS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - done - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -sftp-server: $(sftp_server_OBJECTS) $(sftp_server_DEPENDENCIES) - @rm -f sftp-server - $(LINK) $(sftp_server_LDFLAGS) $(sftp_server_OBJECTS) $(sftp_server_LDADD) $(LIBS) - -sftp-test-client: $(sftp_test_client_OBJECTS) $(sftp_test_client_DEPENDENCIES) - @rm -f sftp-test-client - $(LINK) $(sftp_test_client_LDFLAGS) $(sftp_test_client_OBJECTS) $(sftp_test_client_LDADD) $(LIBS) - -dump-hex: $(dump_hex_OBJECTS) $(dump_hex_DEPENDENCIES) - @rm -f dump-hex - $(LINK) $(dump_hex_LDFLAGS) $(dump_hex_OBJECTS) $(dump_hex_LDADD) $(LIBS) - -# This directory's subdirectories are mostly independent; you can cd -# into them and run `make' without going through this Makefile. -# To change the values of `make' variables: instead of editing Makefiles, -# (1) if the variable is set in `config.status', edit `config.status' -# (which will cause the Makefiles to be regenerated when you run `make'); -# (2) otherwise, pass the desired values on the `make' command line. - -@SET_MAKE@ - -all-recursive install-data-recursive install-exec-recursive \ -installdirs-recursive install-recursive uninstall-recursive \ -check-recursive installcheck-recursive info-recursive dvi-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -mostlyclean-recursive clean-recursive distclean-recursive \ -maintainer-clean-recursive: - @set fnord $(MAKEFLAGS); amf=$$2; \ - dot_seen=no; \ - rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ - rev="$$subdir $$rev"; \ - test "$$subdir" = "." && dot_seen=yes; \ - done; \ - test "$$dot_seen" = "no" && rev=". $$rev"; \ - target=`echo $@ | sed s/-recursive//`; \ - for subdir in $$rev; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ - done && test -z "$$fail" -tags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ - done - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \ - fi; \ - done; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - -rm -rf $(distdir) - GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz - mkdir $(distdir)/=build - mkdir $(distdir)/=inst - dc_install_base=`cd $(distdir)/=inst && pwd`; \ - cd $(distdir)/=build \ - && ../configure --srcdir=.. --prefix=$$dc_install_base \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) dist - -rm -rf $(distdir) - @banner="$(distdir).tar.gz is ready for distribution"; \ - dashes=`echo "$$banner" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - echo "$$dashes" -dist: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -dist-all: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -distdir: $(DISTFILES) - -rm -rf $(distdir) - mkdir $(distdir) - -chmod 777 $(distdir) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - for subdir in $(SUBDIRS); do \ - if test "$$subdir" = .; then :; else \ - test -d $(distdir)/$$subdir \ - || mkdir $(distdir)/$$subdir \ - || exit 1; \ - chmod 777 $(distdir)/$$subdir; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \ - || exit 1; \ - fi; \ - done -buffer.o: buffer.c buffer.h config.h xmalloc.h sftp.h -client.o: client.c client.h buffer.h config.h werror.h xmalloc.h sftp.h -dump-hex.o: dump-hex.c -filemode.o: filemode.c config.h filemode.h -idcache.o: idcache.c idcache.h xmalloc.h -sftp-server.o: sftp-server.c buffer.h config.h sftp.h filemode.h \ - idcache.h xmalloc.h -sftp-test-client.o: sftp-test-client.c buffer.h config.h sftp.h \ - xmalloc.h client.h -werror.o: werror.c werror.h buffer.h config.h -xmalloc.o: xmalloc.c xmalloc.h - -info-am: -info: info-recursive -dvi-am: -dvi: dvi-recursive -check-am: all-am -check: check-recursive -installcheck-am: -installcheck: installcheck-recursive -all-recursive-am: config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -install-exec-am: install-binPROGRAMS -install-exec: install-exec-recursive - -install-data-am: -install-data: install-data-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-recursive -uninstall-am: uninstall-binPROGRAMS -uninstall: uninstall-recursive -all-am: Makefile $(PROGRAMS) config.h -all-redirect: all-recursive-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: installdirs-recursive -installdirs-am: - $(mkinstalldirs) $(DESTDIR)$(bindir) - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-hdr mostlyclean-binPROGRAMS \ - mostlyclean-noinstPROGRAMS mostlyclean-compile \ - mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-recursive - -clean-am: clean-hdr clean-binPROGRAMS clean-noinstPROGRAMS \ - clean-compile clean-tags clean-generic mostlyclean-am - -clean: clean-recursive - -distclean-am: distclean-hdr distclean-binPROGRAMS \ - distclean-noinstPROGRAMS distclean-compile \ - distclean-tags distclean-generic clean-am - -distclean: distclean-recursive - -rm -f config.status - -maintainer-clean-am: maintainer-clean-hdr maintainer-clean-binPROGRAMS \ - maintainer-clean-noinstPROGRAMS \ - maintainer-clean-compile maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-recursive - -rm -f config.status - -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ -maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ -mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \ -clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile install-data-recursive \ -uninstall-data-recursive install-exec-recursive \ -uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \ -all-recursive check-recursive installcheck-recursive info-recursive \ -dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \ -maintainer-clean-recursive tags tags-recursive mostlyclean-tags \ -distclean-tags clean-tags maintainer-clean-tags distdir info-am info \ -dvi-am dvi check check-am installcheck-am installcheck all-recursive-am \ -install-exec-am install-exec install-data-am install-data install-am \ -install uninstall-am uninstall all-redirect all-am all installdirs-am \ -installdirs mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/sftp/acconfig.h b/lsh/src/sftp/acconfig.h deleted file mode 100644 index 2e9e2a6..0000000 --- a/lsh/src/sftp/acconfig.h +++ /dev/null @@ -1,2 +0,0 @@ -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE diff --git a/lsh/src/sftp/aclocal.m4 b/lsh/src/sftp/aclocal.m4 deleted file mode 100644 index 749952f..0000000 --- a/lsh/src/sftp/aclocal.m4 +++ /dev/null @@ -1,215 +0,0 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4 - -dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without -dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A -dnl PARTICULAR PURPOSE. - -# Do all the work for Automake. This macro actually does too much -- -# some checks are only needed if your package does certain things. -# But this isn't really a big deal. - -# serial 1 - -dnl Usage: -dnl AM_INIT_AUTOMAKE(package,version, [no-define]) - -AC_DEFUN(AM_INIT_AUTOMAKE, -[AC_REQUIRE([AC_PROG_INSTALL]) -PACKAGE=[$1] -AC_SUBST(PACKAGE) -VERSION=[$2] -AC_SUBST(VERSION) -dnl test to see if srcdir already configured -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) -fi -ifelse([$3],, -AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) -AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) -AC_REQUIRE([AM_SANITY_CHECK]) -AC_REQUIRE([AC_ARG_PROGRAM]) -dnl FIXME This is truly gross. -missing_dir=`cd $ac_aux_dir && pwd` -AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) -AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) -AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) -AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) -AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) -AC_REQUIRE([AC_PROG_MAKE_SET])]) - -# -# Check to make sure that the build environment is sane. -# - -AC_DEFUN(AM_SANITY_CHECK, -[AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "[$]*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "[$]*" != "X $srcdir/configure conftestfile" \ - && test "[$]*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi - - test "[$]2" = conftestfile - ) -then - # Ok. - : -else - AC_MSG_ERROR([newly created file is older than distributed files! -Check your system clock]) -fi -rm -f conftest* -AC_MSG_RESULT(yes)]) - -dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) -dnl The program must properly implement --version. -AC_DEFUN(AM_MISSING_PROG, -[AC_MSG_CHECKING(for working $2) -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if ($2 --version) < /dev/null > /dev/null 2>&1; then - $1=$2 - AC_MSG_RESULT(found) -else - $1="$3/missing $2" - AC_MSG_RESULT(missing) -fi -AC_SUBST($1)]) - -# Like AC_CONFIG_HEADER, but automatically create stamp file. - -AC_DEFUN(AM_CONFIG_HEADER, -[AC_PREREQ([2.12]) -AC_CONFIG_HEADER([$1]) -dnl When config.status generates a header, we must update the stamp-h file. -dnl This file resides in the same directory as the config header -dnl that is generated. We must strip everything past the first ":", -dnl and everything past the last "/". -AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl -ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>, -<>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>, -<>; do - case " <<$>>CONFIG_HEADERS " in - *" <<$>>am_file "*<<)>> - echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx - ;; - esac - am_indx=`expr "<<$>>am_indx" + 1` -done<<>>dnl>>) -changequote([,]))]) - - -# serial 1 - -# @defmac AC_PROG_CC_STDC -# @maindex PROG_CC_STDC -# @ovindex CC -# If the C compiler in not in ANSI C mode by default, try to add an option -# to output variable @code{CC} to make it so. This macro tries various -# options that select ANSI C on some system or another. It considers the -# compiler to be in ANSI C mode if it handles function prototypes correctly. -# -# If you use this macro, you should check after calling it whether the C -# compiler has been set to accept ANSI C; if not, the shell variable -# @code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source -# code in ANSI C, you can make an un-ANSIfied copy of it by using the -# program @code{ansi2knr}, which comes with Ghostscript. -# @end defmac - -AC_DEFUN(AM_PROG_CC_STDC, -[AC_REQUIRE([AC_PROG_CC]) -AC_BEFORE([$0], [AC_C_INLINE]) -AC_BEFORE([$0], [AC_C_CONST]) -dnl Force this before AC_PROG_CPP. Some cpp's, eg on HPUX, require -dnl a magic option to avoid problems with ANSI preprocessor commands -dnl like #elif. -dnl FIXME: can't do this because then AC_AIX won't work due to a -dnl circular dependency. -dnl AC_BEFORE([$0], [AC_PROG_CPP]) -AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C) -AC_CACHE_VAL(am_cv_prog_cc_stdc, -[am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - AC_TRY_COMPILE( -[#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -], [ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; -], -[am_cv_prog_cc_stdc="$ac_arg"; break]) -done -CC="$ac_save_CC" -]) -if test -z "$am_cv_prog_cc_stdc"; then - AC_MSG_RESULT([none needed]) -else - AC_MSG_RESULT($am_cv_prog_cc_stdc) -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac -]) - diff --git a/lsh/src/sftp/buffer.c b/lsh/src/sftp/buffer.c deleted file mode 100644 index 6397fc2..0000000 --- a/lsh/src/sftp/buffer.c +++ /dev/null @@ -1,605 +0,0 @@ -/* buffer.c - * - * $Id$ - * - * Buffering for sftp. - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 */ - -#include "buffer.h" - -#include "xmalloc.h" -#include "sftp.h" - -#include -#include -#include - -#define FATAL(x) do { fputs("sftp-server: " x "\n", stderr); exit(EXIT_FAILURE); } while (0) - -#include - -/* Reads a 32-bit integer, in network byte order */ -#define READ_UINT32(p) \ -( (((UINT32) (p)[0]) << 24) \ - | (((UINT32) (p)[1]) << 16) \ - | (((UINT32) (p)[2]) << 8) \ - | ((UINT32) (p)[3])) - -#define WRITE_UINT32(p, i) \ -do { \ - (p)[0] = ((i) >> 24) & 0xff; \ - (p)[1] = ((i) >> 16) & 0xff; \ - (p)[2] = ((i) >> 8) & 0xff; \ - (p)[3] = (i) & 0xff; \ -} while(0) - -#define SFTP_MAX_STRINGS 2 - -struct sftp_input -{ - FILE *f; - UINT32 left; - - /* Strings that we own */ - UINT8 *strings[SFTP_MAX_STRINGS]; - unsigned used_strings; -}; - -struct sftp_output -{ - FILE *f; - - /* The message type is the first byte of a message, after the - * length. */ - UINT8 msg; - - /* The next word is either the id, or the version. */ - UINT32 first; - - /* The rest of the packet is variable length. */ - UINT8 *data; - UINT32 size; - UINT32 i; -}; - -/* Input */ - -static int -sftp_check_input(const struct sftp_input *i, UINT32 length) -{ - return (i->left >= length); -} - -int -sftp_get_data(struct sftp_input *i, UINT32 length, UINT8 *data) -{ - if (sftp_check_input(i, length)) - { - i->left -= length; - return (fread(data, 1, length, i->f) == length); - } - return 0; -} - -#define GET_DATA(i, buf) \ -(sftp_get_data((i), sizeof((buf)), (buf))) - -int -sftp_get_uint8(struct sftp_input *i, UINT8 *value) -{ - return sftp_get_data(i, 1, value); -} - -int -sftp_get_uint32(struct sftp_input *i, UINT32 *value) -{ - UINT8 buf[4]; - if (!GET_DATA(i, buf)) - return 0; - - *value = READ_UINT32(buf); - return 1; -} - -UINT8 * -sftp_get_string(struct sftp_input *i, UINT32 *length) -{ - UINT8 *data; - - if (!(sftp_get_uint32(i, length) && sftp_check_input(i, *length))) - return NULL; - - data = xmalloc(*length + 1); - - if (!sftp_get_data(i, *length, data)) - { - free(data); - return NULL; - } - - /* NUL-terminate, for convenience */ - data[*length] = '\0'; - - return data; -} - -void -sftp_free_string(UINT8 *s) -{ - free(s); -} - -UINT8 * -sftp_get_string_auto(struct sftp_input *i, UINT32 *length) -{ - UINT8 *data; - - assert(i->used_strings < SFTP_MAX_STRINGS); - - data = sftp_get_string(i, length); - - if (!data) - return NULL; - - /* Remember the string. */ - i->strings[i->used_strings++] = data; - return data; -} - -int -sftp_get_eod(struct sftp_input *i) -{ - return !i->left; -} - -/* Input */ -struct sftp_input * -sftp_make_input(FILE *f) -{ - struct sftp_input *i = xmalloc(sizeof(struct sftp_input)); - - i->f = f; - i->left = 0; - i->used_strings = 0; - - return i; -} - -void -sftp_input_clear_strings(struct sftp_input *i) -{ - unsigned k; - - for (k = 0; k < i->used_strings; k++) - sftp_free_string(i->strings[k]); - - i->used_strings = 0; -} - -/* Returns 1 of all was well, 0 on error, and -1 on EOF */ -int -sftp_read_packet(struct sftp_input *i) -{ - UINT8 buf[4]; - int done; - - if (i->left) - return 0; - - /* First, deallocate the strings. */ - sftp_input_clear_strings(i); - - done = fread(buf, 1, sizeof(buf), i->f); - - switch (done) - { - case 0: - return feof(i->f) ? -1 : 0; - case 4: - i->left = READ_UINT32(buf); - return 1; - default: - return 0; - } -} - -/* Output */ - -static void -sftp_check_output(struct sftp_output *o, UINT32 length) -{ - UINT32 needed = o->i + length; - if (!o->data || (needed > o->size)) - { - UINT32 size = 2 * needed + 40; - o->data = xrealloc(o->data, size); - - o->size = size; - } -} - -void -sftp_put_data(struct sftp_output *o, UINT32 length, const UINT8 *data) -{ - sftp_check_output(o, length); - - memcpy(o->data + o->i, data, length); - o->i += length; -} - -#define PUT_DATA(o, buf) \ -(sftp_put_data((o), sizeof((buf)), (buf))) - -void -sftp_put_uint8(struct sftp_output *o, UINT8 value) -{ - sftp_check_output(o, 1); - - o->data[o->i++] = value; -} - -void -sftp_put_uint32(struct sftp_output *o, UINT32 value) -{ - UINT8 buf[4]; - - WRITE_UINT32(buf, value); - PUT_DATA(o, buf); -} - -void -sftp_put_string(struct sftp_output *o, UINT32 length, const UINT8 *data) -{ - sftp_put_uint32(o, length); - sftp_put_data(o, length, data); -} - -UINT32 -sftp_put_reserve_length(struct sftp_output *o) -{ - UINT32 index; - sftp_check_output(o, 4); - - index = o->i; - o->i += 4; - - return index; -} - -void -sftp_put_length(struct sftp_output *o, - UINT32 index, - UINT32 length) -{ - assert( (index + 4) < o->i); - WRITE_UINT32(o->data + index, length); -} - -void -sftp_put_final_length(struct sftp_output *o, - UINT32 index) -{ - sftp_put_length(o, index, o->i - index - 4); -} - -void -sftp_put_reset(struct sftp_output *o, - UINT32 index) -{ - assert(index < o->i); - o->i = index; -} - -UINT32 -sftp_put_printf(struct sftp_output *o, const char *format, ...) -{ - /* Initial buffer space */ - int needed; - int length; - - for (needed = 100;; needed *= 2) - { - va_list args; - - va_start(args, format); - - sftp_check_output(o, needed); - length = vsnprintf(o->data + o->i, needed, format, args); - - va_end(args); - - if ( (length >= 0) && (length < needed)) - break; - } - o->i += length; - - return length; -} - -/* If SIZE > 0 it is the desired field length, and - * smaller output is padded with blanks. */ -UINT32 -sftp_put_strftime(struct sftp_output *o, UINT32 size, const char *format, - const struct tm *tm) -{ - /* Initial buffer space */ - size_t needed; - size_t length; - - for (needed = size ? size : 100;; needed *= 2) - { - sftp_check_output(o, needed); - length = strftime(o->data + o->i, needed, format, tm); - - if ( (length > 0) && (length < needed)) - break; - } - - while (length < size) - o->data[o->i + length++] = ' '; - - o->i += length; - - return length; -} - - -/* 64-bit stuff */ -#if SIZEOF_OFF_T > 4 -#define READ_UINT64(p) \ -( (((UINT64) (p)[0]) << 56) \ - | (((UINT64) (p)[1]) << 48) \ - | (((UINT64) (p)[2]) << 40) \ - | (((UINT64) (p)[3]) << 32) \ - | (((UINT64) (p)[4]) << 24) \ - | (((UINT64) (p)[5]) << 16) \ - | (((UINT64) (p)[6]) << 8) \ - | ((UINT64) (p)[7])) - - -int -sftp_get_uint64(struct sftp_input *i, off_t *value) -{ - UINT8 buf[8]; - if (!GET_DATA(i, buf)) - return 0; - - *value = READ_UINT64(buf); - return 1; -} - -#define WRITE_UINT64(p, i) \ -do { \ - (p)[0] = ((i) >> 56) & 0xff; \ - (p)[1] = ((i) >> 48) & 0xff; \ - (p)[2] = ((i) >> 40) & 0xff; \ - (p)[3] = ((i) >> 32) & 0xff; \ - (p)[4] = ((i) >> 24) & 0xff; \ - (p)[5] = ((i) >> 16) & 0xff; \ - (p)[6] = ((i) >> 8) & 0xff; \ - (p)[7] = (i) & 0xff; \ -} while(0) - -void -sftp_put_uint64(struct sftp_output *o, off_t value) -{ - UINT8 buf[8]; - - WRITE_UINT64(buf, value); - PUT_DATA(o, buf); -} - -#else /* SIZEOF_OFF_T <= 4 */ - -/* Fail for too large numbers. */ -int -sftp_get_uint64(struct sftp_input *i, off_t *value) -{ - UINT32 high; - UINT32 low; - - if (sftp_get_uint32(i, &high) - && !high - && sftp_get_uint32(i, &low)) - { - *value = low; - return 1; - } - else - return 0; -} - -void -sftp_put_uint64(struct sftp_output *o, off_t value) -{ - sftp_put_uint32(o, 0); - sftp_put_uint32(o, value); -} - -#endif /* SIZEOF_OFF_T <= 4 */ - -/* The first part of the buffer is always - * - * uint32 length - * uint8 msg - * uint32 id/version - */ - -struct sftp_output * -sftp_make_output(FILE *f) -{ - struct sftp_output *o = xmalloc(sizeof(struct sftp_output)); - - o->f = f; - o->data = NULL; - o->size = 0; - o->i = 0; - - return o; -} - -void -sftp_set_msg(struct sftp_output *o, UINT8 msg) -{ - o->msg = msg; -} - -void -sftp_set_id(struct sftp_output *o, UINT32 id) -{ - o->first = id; -} - -int -sftp_write_packet(struct sftp_output *o) -{ - UINT32 length = o->i + 5; - UINT8 buf[9]; - - WRITE_UINT32(buf, length); - buf[4] = o->msg; - WRITE_UINT32(buf + 5, o->first); - - if (fwrite(buf, 1, 9, o->f) != 9) - return 0; - if (fwrite(o->data, 1, o->i, o->f) != o->i) - return 0; - - o->i = 0; - - /* FIXME: Flushing after each packet is sub-optimal. */ - if (fflush(o->f)) - return 0; - - return 1; -} - -/* General functions */ - -void -sftp_clear_attrib(struct sftp_attrib *a) -{ - a->flags = 0; - a->size = 0; - a->uid = 0; - a->gid = 0; - a->permissions = 0; - a->atime = 0; - a->mtime = 0; -}; - -int -sftp_skip_extension(struct sftp_input *i) -{ - UINT32 length; - UINT8 *data; - unsigned j; - - /* Skip name and value*/ - for (j = 0; j<2; j++) - { - if (!(data = sftp_get_string(i, &length))) - return 0; - } - sftp_input_clear_strings(i); - - return 1; -} - -int -sftp_get_attrib(struct sftp_input *i, struct sftp_attrib *a) -{ - sftp_clear_attrib(a); - - if (!sftp_get_uint32(i, &a->flags)) - return 0; - - if (a->flags & SSH_FILEXFER_ATTR_SIZE) - { - if (!sftp_get_uint64(i, &a->size)) - return 0; - } - - if (a->flags & SSH_FILEXFER_ATTR_UIDGID) - { - if (!sftp_get_uint32(i, &a->uid)) - return 0; - - if (!sftp_get_uint32(i, &a->gid)) - return 0; - } - - if (a->flags & SSH_FILEXFER_ATTR_PERMISSIONS) - { - if (!sftp_get_uint32(i, &a->permissions)) - return 0; - } - - if (a->flags & SSH_FILEXFER_ATTR_ACMODTIME) - { - if (!sftp_get_uint32(i, &a->atime)) - return 0; - - if (!sftp_get_uint32(i, &a->mtime)) - return 0; - } - - if (a->flags & SSH_FILEXFER_ATTR_EXTENDED) - { - UINT32 count; - UINT32 n; - - if (!sftp_get_uint32(i, &count)) - return 0; - - /* Just skip the extensions */ - for (n = 0; n < count; n++) - if (!sftp_skip_extension(i)) - return 0; - } - return 1; -} - -void -sftp_put_attrib(struct sftp_output *o, const struct sftp_attrib *a) -{ - assert(!(a->flags & SSH_FILEXFER_ATTR_EXTENDED)); - - sftp_put_uint32(o, a->flags); - - if (a->flags & SSH_FILEXFER_ATTR_SIZE) - sftp_put_uint64(o, a->size); - - if (a->flags & SSH_FILEXFER_ATTR_UIDGID) - { - sftp_put_uint32(o, a->uid); - sftp_put_uint32(o, a->gid); - } - - if (a->flags & SSH_FILEXFER_ATTR_PERMISSIONS) - sftp_put_uint32(o, a->permissions); - - if (a->flags & SSH_FILEXFER_ATTR_ACMODTIME) - { - sftp_put_uint32(o, a->atime); - sftp_put_uint32(o, a->mtime); - } -} diff --git a/lsh/src/sftp/buffer.h b/lsh/src/sftp/buffer.h deleted file mode 100644 index 2b63e15..0000000 --- a/lsh/src/sftp/buffer.h +++ /dev/null @@ -1,201 +0,0 @@ -/* buffer.h - * - * Buffering for sftp. - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 */ - -#ifndef SFTP_BUFFER_H_INCLUDED -#define SFTP_BUFFER_H_INCLUDED - -/* Basic configuration */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* For off_t */ -#include - -#if SIZEOF_SHORT >= 4 -# define UINT32 unsigned short -#elif SIZEOF_INT >= 4 -# define UINT32 unsigned int -#elif SIZEOF_LONG >= 4 -# define UINT32 unsigned long -#else -# error No suitable type found to use for UINT32 -#endif /* UINT32 */ - -#if SIZEOF_SHORT >= 2 -# define UINT16 unsigned short -#elif SIZEOF_INT >= 2 -# define UINT16 unsigned int -#else -# error No suitable type found to use for UINT16 -#endif /* UINT16 */ - -#define UINT8 unsigned char - -#if __GNUC__ && HAVE_GCC_ATTRIBUTE -# define NORETURN __attribute__ ((__noreturn__)) -# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) -# define UNUSED __attribute__ ((__unused__)) -#else -# define NORETURN -# define PRINTF_STYLE(f, a) -# define UNUSED -#endif - - -/* Abstract input and output functions */ -#include - -struct sftp_input; -struct sftp_output; - -/* Input */ - -/* Returns 1 of all was well, 0 on error, and -1 on EOF */ -int -sftp_read_packet(struct sftp_input *i); - -int -sftp_get_data(struct sftp_input *i, UINT32 length, UINT8 *data); - -int -sftp_get_uint8(struct sftp_input *i, UINT8 *value); - -int -sftp_get_uint32(struct sftp_input *i, UINT32 *value); - -int -sftp_get_uint64(struct sftp_input *i, off_t *value); - -/* Allocates storage. Caller must deallocate using - * sftp_free_string. */ -UINT8 * -sftp_get_string(struct sftp_input *i, UINT32 *length); - -void -sftp_free_string(UINT8 *s); - -/* Like sftp_get_string, but the data is deallocated automatically by - * sftp_read_packet and sftp_input_clear_strings. */ -UINT8 * -sftp_get_string_auto(struct sftp_input *i, UINT32 *length); - -void -sftp_input_clear_strings(struct sftp_input *i); - -int -sftp_get_eod(struct sftp_input *i); - -/* Output */ - -void -sftp_set_msg(struct sftp_output *o, UINT8 msg); - -void -sftp_set_id(struct sftp_output *o, UINT32 id); - -int -sftp_write_packet(struct sftp_output *o); - -void -sftp_put_data(struct sftp_output *o, UINT32 length, const UINT8 *data); - -void -sftp_put_uint8(struct sftp_output *o, UINT8 value); - -void -sftp_put_uint32(struct sftp_output *o, UINT32 value); - -void -sftp_put_uint64(struct sftp_output *o, off_t value); - -void -sftp_put_string(struct sftp_output *o, UINT32 length, const UINT8 *data); - -/* Returns index. */ -UINT32 -sftp_put_reserve_length(struct sftp_output *o); - -void -sftp_put_final_length(struct sftp_output *o, - UINT32 index); - -void -sftp_put_length(struct sftp_output *o, - UINT32 index, - UINT32 length); - -void -sftp_put_reset(struct sftp_output *o, - UINT32 index); - -UINT32 -sftp_put_printf(struct sftp_output *o, const char *format, ...) - PRINTF_STYLE(2,3); - -UINT32 -sftp_put_strftime(struct sftp_output *o, UINT32 size, - const char *format, - const struct tm *tm); - - -/* Constructed types. */ - -struct sftp_attrib -{ - UINT32 flags; - off_t size; - UINT32 uid; - UINT32 gid; - UINT32 permissions; - - /* NOTE: The representations of times is about to change. */ - UINT32 atime; - UINT32 mtime; -}; - -void -sftp_clear_attrib(struct sftp_attrib *a); - -int -sftp_get_attrib(struct sftp_input *i, struct sftp_attrib *a); - -void -sftp_put_attrib(struct sftp_output *o, const struct sftp_attrib *a); - -int -sftp_skip_extension(struct sftp_input *i); - - -/* Simple input and output objects based on FILE * */ -#include - -struct sftp_input * -sftp_make_input(FILE *f); - -struct sftp_output * -sftp_make_output(FILE *f); - - -#endif /* SFTP_BUFFER_H_INCLUDED */ diff --git a/lsh/src/sftp/client.c b/lsh/src/sftp/client.c deleted file mode 100644 index 5619dd8..0000000 --- a/lsh/src/sftp/client.c +++ /dev/null @@ -1,154 +0,0 @@ -/* client.c - * - * Utility functions for the client side of the protocol. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 */ - -#include "client.h" - -#include "buffer.h" -#include "werror.h" -#include "xmalloc.h" - -#include "sftp.h" - -#include - -/* We never have several pending calls at once. */ -static UINT32 -sftp_client_new_id(void) -{ return 17; } - -static struct client_handle * -client_get_handle(struct sftp_input *i) -{ - UINT32 length; - UINT8 *data; - struct client_handle *handle; - - data = sftp_get_string(i, &length); - if (!data) - fatal("Protocol error, client_get_handle"); - - handle = xmalloc(sizeof(*handle)); - handle->length = length; - handle->data = data; - - return handle; -} - -static UINT8 -client_get_msg(struct client_ctx *ctx, UINT32 expected) -{ - UINT8 msg; - UINT32 id; - - if (sftp_get_uint8(ctx->i, &msg) - && sftp_get_uint32(ctx->i, &id) - && (expected == id)) - return msg; - - else - fatal("Protocol error, client_get_msg"); -} - -static UINT32 -client_get_status(struct client_ctx *ctx, UINT32 id) -{ - UINT32 status; - - if ( (client_get_msg(ctx, id) == SSH_FXP_STATUS) - && sftp_get_uint32(ctx->i, &status)) - return status; - - else - fatal("Protocol error, client_get_status"); -} - -static void -client_put_handle(struct client_ctx *ctx, struct client_handle *handle) -{ - sftp_put_string(ctx->o, handle->length, handle->data); -} - -/* Creates a file handle */ - struct client_handle * -sftp_open(struct client_ctx *ctx, - const char *name, - UINT32 flags, - const struct sftp_attrib *a) -{ - UINT8 msg; - UINT32 id = sftp_client_new_id(); - - /* Send a OPEN message */ - sftp_set_msg(ctx->o, SSH_FXP_OPEN); - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, strlen(name), name ); - sftp_put_uint32(ctx->o, flags); - sftp_put_attrib(ctx->o, a); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - msg = client_get_msg(ctx, id); - - switch (msg) - { - case SSH_FXP_HANDLE: - return client_get_handle(ctx->i); - case SSH_FXP_STATUS: - if (!sftp_get_uint32(ctx->i, &ctx->status)) - fatal("Protocol error, sftp_open"); - return NULL; - default: - fatal("Unexpected message from server."); - } -} - -/* Destroys a file or directory handle */ -int -sftp_close(struct client_ctx *ctx, - struct client_handle *handle) -{ - UINT32 id = sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_CLOSE); /* Send a close message */ - sftp_set_id(ctx->o, id); - client_put_handle(ctx, handle); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - /* None of these may fail */ - ctx->status = client_get_status(ctx, id); - - return (ctx->status == SSH_FX_OK); -} - - diff --git a/lsh/src/sftp/client.h b/lsh/src/sftp/client.h deleted file mode 100644 index b62c6f5..0000000 --- a/lsh/src/sftp/client.h +++ /dev/null @@ -1,60 +0,0 @@ -/* client.h - * - * Utility functions for the client side of the protocol. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 */ - -#ifndef SFTP_CLIENT_H_INCLUDED -#define SFTP_CLIENT_H_INCLUDED - -#include "buffer.h" - -struct client_ctx -{ - struct sftp_input *i; - struct sftp_output *o; - - /* Status from latest message. */ - UINT32 status; -}; - -/* Handles are strings, choosen by the server. */ -struct client_handle -{ - UINT32 length; - UINT8 *data; -}; - -/* Creates a file handle */ -struct client_handle * -sftp_open(struct client_ctx *ctx, - const char *name, - UINT32 flags, - const struct sftp_attrib *a); - -/* Destroys a file or directory handle */ -int -sftp_close(struct client_ctx *ctx, - struct client_handle *handle); - - -#endif /* SFTP_CLIENT_H_INCLUDED */ diff --git a/lsh/src/sftp/config.h.in b/lsh/src/sftp/config.h.in deleted file mode 100644 index 3068776..0000000 --- a/lsh/src/sftp/config.h.in +++ /dev/null @@ -1,67 +0,0 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ -/* Define if the compiler understands __attribute__ */ -#undef HAVE_GCC_ATTRIBUTE - -/* Define if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define if you have the `pread' function. */ -#undef HAVE_PREAD - -/* Define if you have the `pwrite' function. */ -#undef HAVE_PWRITE - -/* Define if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define if you have the header file. */ -#undef HAVE_STRING_H - -/* Define if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Name of package */ -#undef PACKAGE - -/* The size of a `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of a `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of a `off_t', as computed by sizeof. */ -#undef SIZEOF_OFF_T - -/* The size of a `short', as computed by sizeof. */ -#undef SIZEOF_SHORT - -/* Define if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Define if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Version number of package */ -#undef VERSION - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define to `int' if doesn't define. */ -#undef gid_t - -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ -#undef inline - -/* Define to `unsigned' if does not define. */ -#undef size_t - -/* Define to `int' if doesn't define. */ -#undef uid_t diff --git a/lsh/src/sftp/configure b/lsh/src/sftp/configure deleted file mode 100644 index 3fdd013..0000000 --- a/lsh/src/sftp/configure +++ /dev/null @@ -1,4778 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by Autoconf 2.50. -# -# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -# Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -exec 6>&1 - -# -# Initializations. -# -ac_default_prefix=/usr/local -cross_compiling=no -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - -# Avoid depending upon Character Ranges. -ac_cr_az='abcdefghijklmnopqrstuvwxyz' -ac_cr_AZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -ac_cr_09='0123456789' -ac_cr_alnum=$ac_cr_az$ac_cr_AZ$ac_cr_09 - -# Sed expression to map a string onto a valid sh and CPP variable names. -ac_tr_sh="sed y%*+%pp%;s%[^_$ac_cr_alnum]%_%g" -ac_tr_cpp="sed y%*$ac_cr_az%P$ac_cr_AZ%;s%[^_$ac_cr_alnum]%_%g" - -ac_unique_file="sftp-server.c" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#include -#include -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#else -# if HAVE_STRINGS_H -# include -# endif -#endif -#if HAVE_INTTYPES_H -# include -#endif -#if HAVE_UNISTD_H -# include -#endif" - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -# Identity of this package. -PACKAGE_NAME= -PACKAGE_TARNAME= -PACKAGE_VERSION= -PACKAGE_STRING= -PACKAGE_BUGREPORT= - -ac_prev= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_option in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - eval "enable_$ac_feature=no" ;; - - -enable-* | --enable-*) - ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "enable_$ac_feature='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package| sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "with_$ac_package='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/-/_/g'` - eval "with_$ac_package=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$ac_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` - eval "$ac_envvar='$ac_optarg'" - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$ac_cr_alnum]" >/dev/null && - echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -# Be sure to have absolute paths. -for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ - localstatedir libdir includedir oldincludedir infodir mandir \ - exec_prefix prefix -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* ) ;; - NONE ) ;; - *) { echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: should be removed in autoconf 3.0. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo "$ac_prog" | sed 's%[\\/][^\\/][^\\/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "$as_me: error: cannot find sources in $ac_confdir or .." >&2 - { (exit 1); exit 1; }; } - else - { echo "$as_me: error: cannot find sources in $srcdir" >&2 - { (exit 1); exit 1; }; } - fi -fi -srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` -ac_env_build_alias_set=${build_alias+set} -ac_env_build_alias_value=$build_alias -ac_cv_env_build_alias_set=${build_alias+set} -ac_cv_env_build_alias_value=$build_alias -ac_env_host_alias_set=${host_alias+set} -ac_env_host_alias_value=$host_alias -ac_cv_env_host_alias_set=${host_alias+set} -ac_cv_env_host_alias_value=$host_alias -ac_env_target_alias_set=${target_alias+set} -ac_env_target_alias_value=$target_alias -ac_cv_env_target_alias_set=${target_alias+set} -ac_cv_env_target_alias_value=$target_alias -ac_env_CC_set=${CC+set} -ac_env_CC_value=$CC -ac_cv_env_CC_set=${CC+set} -ac_cv_env_CC_value=$CC -ac_env_CFLAGS_set=${CFLAGS+set} -ac_env_CFLAGS_value=$CFLAGS -ac_cv_env_CFLAGS_set=${CFLAGS+set} -ac_cv_env_CFLAGS_value=$CFLAGS -ac_env_LDFLAGS_set=${LDFLAGS+set} -ac_env_LDFLAGS_value=$LDFLAGS -ac_cv_env_LDFLAGS_set=${LDFLAGS+set} -ac_cv_env_LDFLAGS_value=$LDFLAGS -ac_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_env_CPPFLAGS_value=$CPPFLAGS -ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat < if you have libraries in a - nonstandard directory - CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have - headers in a nonstandard directory - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -EOF -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - ac_popdir=`pwd` - for ac_subdir in : $ac_subdirs_all; do test "x$ac_subdir" = x: && continue - cd $ac_subdir - # A "../" for each directory in /$ac_subdir. - ac_dots=`echo $ac_subdir | - sed 's,^\./,,;s,[^/]$,&/,;s,[^/]*/,../,g'` - - case $srcdir in - .) # No --srcdir option. We are building in place. - ac_sub_srcdir=$srcdir ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_sub_srcdir=$srcdir/$ac_subdir ;; - *) # Relative path. - ac_sub_srcdir=$ac_dots$srcdir/$ac_subdir ;; - esac - - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_sub_srcdir/configure.gnu; then - echo - $SHELL $ac_sub_srcdir/configure.gnu --help=recursive - elif test -f $ac_sub_srcdir/configure; then - echo - $SHELL $ac_sub_srcdir/configure --help=recursive - elif test -f $ac_sub_srcdir/configure.ac || - test -f $ac_sub_srcdir/configure.in; then - echo - $ac_configure --help - else - echo "$as_me: WARNING: no configuration information is in $ac_subdir" >&2 - fi - cd $ac_popdir - done -fi - -test -n "$ac_init_help" && exit 0 -if $ac_init_version; then - cat <<\EOF - -Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -EOF - exit 0 -fi -exec 5>config.log -cat >&5 </dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -hostinfo = `(hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -PATH = $PATH - -_ASUNAME -} >&5 - -cat >&5 <\?\"\']*) - ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` - ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" - ac_sep=" " ;; - *) ac_configure_args="$ac_configure_args$ac_sep$ac_arg" - ac_sep=" " ;; - esac - # Get rid of the leading space. -done - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - echo >&5 - echo "## ----------------- ##" >&5 - echo "## Cache variables. ##" >&5 - echo "## ----------------- ##" >&5 - echo >&5 - # The following way of writing the cache mishandles newlines in values, -{ - (set) 2>&1 | - case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in - *ac_space=\ *) - sed -n \ - "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" - ;; - *) - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} >&5 - sed "/^$/d" confdefs.h >conftest.log - if test -s conftest.log; then - echo >&5 - echo "## ------------ ##" >&5 - echo "## confdefs.h. ##" >&5 - echo "## ------------ ##" >&5 - echo >&5 - cat conftest.log >&5 - fi - (echo; echo) >&5 - test "$ac_signal" != 0 && - echo "$as_me: caught signal $ac_signal" >&5 - echo "$as_me: exit $exit_status" >&5 - rm -rf conftest* confdefs* core core.* *.core conf$$* $ac_clean_files && - exit $exit_status - ' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_status=$?; ac_signal='$ac_signal'; { (exit $ac_status); exit $ac_status; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo >confdefs.h - -# Let the site file select an alternate cache file if it wants to. -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - { echo "$as_me:841: loading site script $ac_site_file" >&5 -echo "$as_me: loading site script $ac_site_file" >&6;} - cat "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { echo "$as_me:852: loading cache $cache_file" >&5 -echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . $cache_file;; - *) . ./$cache_file;; - esac - fi -else - { echo "$as_me:860: creating cache $cache_file" >&5 -echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_suggest_removing_cache=false -for ac_var in `(set) 2>&1 | - sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val="\$ac_cv_env_${ac_var}_value" - eval ac_new_val="\$ac_env_${ac_var}_value" - case $ac_old_set,$ac_new_set in - set,) - { echo "$as_me:876: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,set) - { echo "$as_me:880: WARNING: \`$ac_var' was not set in the previous run" >&5 -echo "$as_me: WARNING: \`$ac_var' was not set in the previous run" >&2;} - ac_suggest_removing_cache=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - { echo "$as_me:886: WARNING: \`$ac_var' has changed since the previous run:" >&5 -echo "$as_me: WARNING: \`$ac_var' has changed since the previous run:" >&2;} - { echo "$as_me:888: WARNING: former value: $ac_old_val" >&5 -echo "$as_me: WARNING: former value: $ac_old_val" >&2;} - { echo "$as_me:890: WARNING: current value: $ac_new_val" >&5 -echo "$as_me: WARNING: current value: $ac_new_val" >&2;} - ac_suggest_removing_cache=: - fi;; - esac -done -if $ac_suggest_removing_cache; then - { echo "$as_me:897: WARNING: changes in the environment can compromise the build" >&5 -echo "$as_me: WARNING: changes in the environment can compromise the build" >&2;} - { echo "$as_me:899: WARNING: consider removing $cache_file and starting over" >&5 -echo "$as_me: WARNING: consider removing $cache_file and starting over" >&2;} -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac -echo "#! $SHELL" >conftest.sh -echo "exit 0" >>conftest.sh -chmod +x conftest.sh -if { (echo "$as_me:918: PATH=\".;.\"; conftest.sh") >&5 - (PATH=".;."; conftest.sh) 2>&5 - ac_status=$? - echo "$as_me:921: \$? = $ac_status" >&5 - (exit $ac_status); }; then - ac_path_separator=';' -else - ac_path_separator=: -fi -PATH_SEPARATOR="$ac_path_separator" -rm -f conftest.sh - -ac_aux_dir= -for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do - if test -f $ac_dir/install-sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f $ac_dir/install.sh; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f $ac_dir/shtool; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - { { echo "$as_me:947: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 -echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} - { (exit 1); exit 1; }; } -fi -ac_config_guess="$SHELL $ac_aux_dir/config.guess" -ac_config_sub="$SHELL $ac_aux_dir/config.sub" -ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# ./install, which can be erroneously created by make from ./install.sh. -echo "$as_me:967: checking for a BSD compatible install" >&5 -echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6 -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_save_IFS=$IFS; IFS=$ac_path_separator - for ac_dir in $PATH; do - IFS=$ac_save_IFS - # Account for people who put trailing slashes in PATH elements. - case $ac_dir/ in - / | ./ | .// | /cC/* \ - | /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* \ - | /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - if $as_executable_p "$ac_dir/$ac_prog"; then - if test $ac_prog = install && - grep dspmsg "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$ac_dir/$ac_prog" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - ac_cv_path_install="$ac_dir/$ac_prog -c" - break 2 - fi - fi - done - ;; - esac - done - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. We don't cache a - # path for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the path is relative. - INSTALL=$ac_install_sh - fi -fi -echo "$as_me:1016: result: $INSTALL" >&5 -echo "${ECHO_T}$INSTALL" >&6 - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -echo "$as_me:1027: checking whether build environment is sane" >&5 -echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6 -# Just in case -sleep 1 -echo timestamp > conftestfile -# Do `set' in a subshell so we don't clobber the current shell's -# arguments. Must try -L first in case configure is actually a -# symlink; some systems play weird games with the mod time of symlinks -# (eg FreeBSD returns the mod time of the symlink's containing -# directory). -if ( - set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t $srcdir/configure conftestfile` - fi - if test "$*" != "X $srcdir/configure conftestfile" \ - && test "$*" != "X conftestfile $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - { { echo "$as_me:1050: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&5 -echo "$as_me: error: ls -t appears to fail. Make sure there is not a broken -alias in your environment" >&2;} - { (exit 1); exit 1; }; } - fi - - test "$2" = conftestfile - ) -then - # Ok. - : -else - { { echo "$as_me:1063: error: newly created file is older than distributed files! -Check your system clock" >&5 -echo "$as_me: error: newly created file is older than distributed files! -Check your system clock" >&2;} - { (exit 1); exit 1; }; } -fi -rm -f conftest* -echo "$as_me:1070: result: yes" >&5 -echo "${ECHO_T}yes" >&6 -if test "$program_transform_name" = s,x,x,; then - program_transform_name= -else - # Double any \ or $. echo might interpret backslashes. - cat <<\EOF >conftest.sed -s,\\,\\\\,g; s,\$,$$,g -EOF - program_transform_name=`echo $program_transform_name | sed -f conftest.sed` - rm -f conftest.sed -fi -test "$program_prefix" != NONE && - program_transform_name="s,^,${program_prefix},;$program_transform_name" -# Use a double $ so make ignores it. -test "$program_suffix" != NONE && - program_transform_name="s,\$\$,${program_suffix},;$program_transform_name" - -# sed with no file args requires a program. -test -z "$program_transform_name" && program_transform_name="s,x,x," - -echo "$as_me:1091: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1111: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1115: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -PACKAGE=lsh-sftp - -VERSION=1.0 - -if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then - { { echo "$as_me:1125: error: source directory already configured; run \"make distclean\" there first" >&5 -echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;} - { (exit 1); exit 1; }; } -fi - -cat >>confdefs.h <>confdefs.h <&5 -echo $ECHO_N "checking for working aclocal... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (aclocal --version) < /dev/null > /dev/null 2>&1; then - ACLOCAL=aclocal - echo "$as_me:1146: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - ACLOCAL="$missing_dir/missing aclocal" - echo "$as_me:1150: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1154: checking for working autoconf" >&5 -echo $ECHO_N "checking for working autoconf... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoconf --version) < /dev/null > /dev/null 2>&1; then - AUTOCONF=autoconf - echo "$as_me:1161: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOCONF="$missing_dir/missing autoconf" - echo "$as_me:1165: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1169: checking for working automake" >&5 -echo $ECHO_N "checking for working automake... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (automake --version) < /dev/null > /dev/null 2>&1; then - AUTOMAKE=automake - echo "$as_me:1176: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOMAKE="$missing_dir/missing automake" - echo "$as_me:1180: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1184: checking for working autoheader" >&5 -echo $ECHO_N "checking for working autoheader... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (autoheader --version) < /dev/null > /dev/null 2>&1; then - AUTOHEADER=autoheader - echo "$as_me:1191: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - AUTOHEADER="$missing_dir/missing autoheader" - echo "$as_me:1195: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -echo "$as_me:1199: checking for working makeinfo" >&5 -echo $ECHO_N "checking for working makeinfo... $ECHO_C" >&6 -# Run test in a subshell; some versions of sh will print an error if -# an executable is not found, even if stderr is redirected. -# Redirect stdin to placate older versions of autoconf. Sigh. -if (makeinfo --version) < /dev/null > /dev/null 2>&1; then - MAKEINFO=makeinfo - echo "$as_me:1206: result: found" >&5 -echo "${ECHO_T}found" >&6 -else - MAKEINFO="$missing_dir/missing makeinfo" - echo "$as_me:1210: result: missing" >&5 -echo "${ECHO_T}missing" >&6 -fi - -ac_config_headers="$ac_config_headers config.h" - -ac_config_commands="$ac_config_commands default-1" - -CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -echo "$as_me:1228: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}gcc" -echo "$as_me:1243: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1251: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1254: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo "$as_me:1263: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="gcc" -echo "$as_me:1278: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1286: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1289: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -echo "$as_me:1302: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="${ac_tool_prefix}cc" -echo "$as_me:1317: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1325: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1328: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1337: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="cc" -echo "$as_me:1352: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1360: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1363: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:1376: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue -fi -ac_cv_prog_CC="cc" -echo "$as_me:1396: found $ac_dir/$ac_word" >&5 -break -done - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - set dummy "$ac_dir/$ac_word" ${1+"$@"} - shift - ac_cv_prog_CC="$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1418: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1421: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:1432: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_CC="$ac_tool_prefix$ac_prog" -echo "$as_me:1447: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:1455: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:1458: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:1471: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_CC="$ac_prog" -echo "$as_me:1486: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:1494: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:1497: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CC" && break -done - - CC=$ac_ct_CC -fi - -fi - -test -z "$CC" && { { echo "$as_me:1509: error: no acceptable cc found in \$PATH" >&5 -echo "$as_me: error: no acceptable cc found in \$PATH" >&2;} - { (exit 1); exit 1; }; } - -cat >conftest.$ac_ext <<_ACEOF -#line 1514 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.exe" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compiler, and finding out an intuition -# of exeext. -echo "$as_me:1530: checking for C compiler default output" >&5 -echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6 -ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` -if { (eval echo "$as_me:1533: \"$ac_link_default\"") >&5 - (eval $ac_link_default) 2>&5 - ac_status=$? - echo "$as_me:1536: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `ls a.exe conftest.exe a.* conftest conftest.* 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - a.out ) # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1553: error: C compiler cannot create executables" >&5 -echo "$as_me: error: C compiler cannot create executables" >&2;} - { (exit 77); exit 77; }; } -fi - -ac_exeext=$ac_cv_exeext -echo "$as_me:1559: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6 - -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1564: checking whether the C compiler works" >&5 -echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (eval echo "$as_me:1570: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1573: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { echo "$as_me:1580: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&5 -echo "$as_me: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'." >&2;} - { (exit 1); exit 1; }; } - fi - fi -fi -echo "$as_me:1588: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - -rm -f a.out a.exe conftest$ac_cv_exeext -ac_clean_files=$ac_clean_files_save -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:1595: checking whether we are cross compiling" >&5 -echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 -echo "$as_me:1597: result: $cross_compiling" >&5 -echo "${ECHO_T}$cross_compiling" >&6 - -echo "$as_me:1600: checking for executable suffix" >&5 -echo $ECHO_N "checking for executable suffix... $ECHO_C" >&6 -if { (eval echo "$as_me:1602: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:1605: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in `(ls conftest.exe; ls conftest; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - { { echo "$as_me:1621: error: cannot compute EXEEXT: cannot compile and link" >&5 -echo "$as_me: error: cannot compute EXEEXT: cannot compile and link" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest$ac_cv_exeext -echo "$as_me:1627: result: $ac_cv_exeext" >&5 -echo "${ECHO_T}$ac_cv_exeext" >&6 - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -echo "$as_me:1633: checking for object suffix" >&5 -echo $ECHO_N "checking for object suffix... $ECHO_C" >&6 -if test "${ac_cv_objext+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1639 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (eval echo "$as_me:1651: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1654: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -{ { echo "$as_me:1666: error: cannot compute OBJEXT: cannot compile" >&5 -echo "$as_me: error: cannot compute OBJEXT: cannot compile" >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -echo "$as_me:1673: result: $ac_cv_objext" >&5 -echo "${ECHO_T}$ac_cv_objext" >&6 -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -echo "$as_me:1677: checking whether we are using the GNU C compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 -if test "${ac_cv_c_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1683 "configure" -#include "confdefs.h" - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1698: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1701: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1704: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1707: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_compiler_gnu=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:1719: result: $ac_cv_c_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 -GCC=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" -echo "$as_me:1725: checking whether $CC accepts -g" >&5 -echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 1731 "configure" -#include "confdefs.h" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1743: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1746: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1749: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1752: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_g=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_prog_cc_g=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:1762: result: $ac_cv_prog_cc_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -# Some people use a C++ compiler to compile C. Since we use `exit', -# in C++ we need to declare it. In case someone uses the same compiler -# for both compiling C and C++ we need to have the C++ compiler decide -# the declaration of exit, since it's the most demanding environment. -cat >conftest.$ac_ext <<_ACEOF -#ifndef __cplusplus - choke me -#endif -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1789: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1792: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1795: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1798: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - for ac_declaration in \ - ''\ - '#include ' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -#line 1810 "configure" -#include "confdefs.h" -#include -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1823: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1826: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1829: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1832: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -continue -fi -rm -f conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -#line 1842 "configure" -#include "confdefs.h" -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:1854: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:1857: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:1860: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:1863: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -echo '#ifdef __cplusplus' >>confdefs.h -echo $ac_declaration >>confdefs.h -echo '#endif' >>confdefs.h - -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:1887: checking whether ${MAKE-make} sets \${MAKE}" >&5 -echo $ECHO_N "checking whether ${MAKE-make} sets \${MAKE}... $ECHO_C" >&6 -set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,./+-,__p_,'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.make <<\EOF -all: - @echo 'ac_maketemp="${MAKE}"' -EOF -# GNU make sometimes prints "make[1]: Entering...", which would confuse us. -eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=` -if test -n "$ac_maketemp"; then - eval ac_cv_prog_make_${ac_make}_set=yes -else - eval ac_cv_prog_make_${ac_make}_set=no -fi -rm -f conftest.make -fi -if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then - echo "$as_me:1907: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - SET_MAKE= -else - echo "$as_me:1911: result: no" >&5 -echo "${ECHO_T}no" >&6 - SET_MAKE="MAKE=${MAKE-make}" -fi - -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -echo "$as_me:1919: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" -echo "$as_me:1934: found $ac_dir/$ac_word" >&5 -break -done - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - echo "$as_me:1942: result: $RANLIB" >&5 -echo "${ECHO_T}$RANLIB" >&6 -else - echo "$as_me:1945: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -echo "$as_me:1954: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else - ac_save_IFS=$IFS; IFS=$ac_path_separator -ac_dummy="$PATH" -for ac_dir in $ac_dummy; do - IFS=$ac_save_IFS - test -z "$ac_dir" && ac_dir=. - $as_executable_p "$ac_dir/$ac_word" || continue -ac_cv_prog_ac_ct_RANLIB="ranlib" -echo "$as_me:1969: found $ac_dir/$ac_word" >&5 -break -done - - test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":" -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - echo "$as_me:1978: result: $ac_ct_RANLIB" >&5 -echo "${ECHO_T}$ac_ct_RANLIB" >&6 -else - echo "$as_me:1981: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - RANLIB=$ac_ct_RANLIB -else - RANLIB="$ac_cv_prog_RANLIB" -fi - -echo "$as_me:1990: checking for ${CC-cc} option to accept ANSI C" >&5 -echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6 -if test "${am_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - am_cv_prog_cc_stdc=no -ac_save_CC="$CC" -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - cat >conftest.$ac_ext <<_ACEOF -#line 2007 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; - -int -main () -{ - -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2049: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2052: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2055: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2058: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - am_cv_prog_cc_stdc="$ac_arg"; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -CC="$ac_save_CC" - -fi - -if test -z "$am_cv_prog_cc_stdc"; then - echo "$as_me:2072: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 -else - echo "$as_me:2075: result: $am_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$am_cv_prog_cc_stdc" >&6 -fi -case "x$am_cv_prog_cc_stdc" in - x|xno) ;; - *) CC="$CC $am_cv_prog_cc_stdc" ;; -esac - -if test "x$am_cv_prog_cc_stdc" = xno ; then - { { echo "$as_me:2084: error: the C compiler doesn't handle ANSI-C" >&5 -echo "$as_me: error: the C compiler doesn't handle ANSI-C" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -echo "$as_me:2094: checking how to run the C preprocessor" >&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - # break 2 since there is a loop in there. - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2116 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2121: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2127: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2150 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2154: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2160: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break 2 -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:2197: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -#line 2207 "configure" -#include "confdefs.h" -#include - Syntax error -_ACEOF -if { (eval echo "$as_me:2212: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2218: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -#line 2241 "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:2245: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2251: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:2279: error: C preprocessor \"$CPP\" fails sanity check" >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -echo "$as_me:2290: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2296 "configure" -#include "confdefs.h" -#include -#include -#include -#include - -_ACEOF -if { (eval echo "$as_me:2304: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2310: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_header_stdc=no -fi -rm -f conftest.err conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2332 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -#line 2350 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -#line 2371 "configure" -#include "confdefs.h" -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:2397: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:2400: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:2402: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2405: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_stdc=no -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -fi -echo "$as_me:2418: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\EOF -#define STDC_HEADERS 1 -EOF - -fi - -echo "$as_me:2428: checking for $CC option to accept ANSI C" >&5 -echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_prog_cc_stdc=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -#line 2436 "configure" -#include "confdefs.h" -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (eval echo "$as_me:2485: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2488: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2491: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2494: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_stdc=$ac_arg -break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext -done -rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC - -fi - -case "x$ac_cv_prog_cc_stdc" in - x|xno) - echo "$as_me:2511: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 ;; - *) - echo "$as_me:2514: result: $ac_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 - CC="$CC $ac_cv_prog_cc_stdc" ;; -esac - -echo "$as_me:2519: checking for an ANSI C-conforming const" >&5 -echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6 -if test "${ac_cv_c_const+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2525 "configure" -#include "confdefs.h" - -int -main () -{ -/* FIXME: Include the comments suggested by Paul. */ -#ifndef __cplusplus - /* Ultrix mips cc rejects this. */ - typedef int charset[2]; - const charset x; - /* SunOS 4.1.1 cc rejects this. */ - char const *const *ccp; - char **p; - /* NEC SVR4.0.2 mips cc rejects this. */ - struct point {int x, y;}; - static struct point const zero = {0,0}; - /* AIX XL C 1.02.0.0 rejects this. - It does not let you subtract one const X* pointer from another in - an arm of an if-expression whose if-part is not a constant - expression */ - const char *g = "string"; - ccp = &g + (g ? g-g : 0); - /* HPUX 7.0 cc rejects these. */ - ++ccp; - p = (char**) ccp; - ccp = (char const *const *) p; - { /* SCO 3.2v4 cc rejects this. */ - char *t; - char const *s = 0 ? (char *) 0 : (char const *) 0; - - *t++ = 0; - } - { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ - int x[] = {25, 17}; - const int *foo = &x[0]; - ++foo; - } - { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ - typedef const int *iptr; - iptr p = 0; - ++p; - } - { /* AIX XL C 1.02.0.0 rejects this saying - "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; }; - struct s *b; b->j = 5; - } - { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ - const int foo = 10; - } -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2583: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2586: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2589: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2592: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_const=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_c_const=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2602: result: $ac_cv_c_const" >&5 -echo "${ECHO_T}$ac_cv_c_const" >&6 -if test $ac_cv_c_const = no; then - -cat >>confdefs.h <<\EOF -#define const -EOF - -fi - -echo "$as_me:2612: checking for inline" >&5 -echo $ECHO_N "checking for inline... $ECHO_C" >&6 -if test "${ac_cv_c_inline+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_c_inline=no -for ac_kw in inline __inline__ __inline; do - cat >conftest.$ac_ext <<_ACEOF -#line 2620 "configure" -#include "confdefs.h" -#ifndef __cplusplus -static $ac_kw int static_foo () {return 0; } -$ac_kw int foo () {return 0; } -#endif - -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2629: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2632: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2635: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2638: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_inline=$ac_kw; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done - -fi -echo "$as_me:2649: result: $ac_cv_c_inline" >&5 -echo "${ECHO_T}$ac_cv_c_inline" >&6 -case $ac_cv_c_inline in - inline | yes) ;; - no) -cat >>confdefs.h <<\EOF -#define inline -EOF - ;; - *) cat >>confdefs.h <&5 -echo $ECHO_N "checking for uid_t in sys/types.h... $ECHO_C" >&6 -if test "${ac_cv_type_uid_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2670 "configure" -#include "confdefs.h" -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - egrep "uid_t" >/dev/null 2>&1; then - ac_cv_type_uid_t=yes -else - ac_cv_type_uid_t=no -fi -rm -f conftest* - -fi -echo "$as_me:2684: result: $ac_cv_type_uid_t" >&5 -echo "${ECHO_T}$ac_cv_type_uid_t" >&6 -if test $ac_cv_type_uid_t = no; then - -cat >>confdefs.h <<\EOF -#define uid_t int -EOF - -cat >>confdefs.h <<\EOF -#define gid_t int -EOF - -fi - -for ac_header in stdlib.h string.h memory.h strings.h inttypes.h unistd.h -do -ac_ac_Header=`echo "ac_cv_header_$ac_header" | $ac_tr_sh` -echo "$as_me:2701: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2707 "configure" -#include "confdefs.h" -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:2711: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - egrep -v '^ *\+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:2717: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - eval "$ac_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - eval "$ac_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_ext -fi -echo "$as_me:2736: result: `eval echo '${'$ac_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_Header'}'`" >&6 -if test `eval echo '${'$ac_ac_Header'}'` = yes; then - cat >>confdefs.h <&5 -echo $ECHO_N "checking for size_t... $ECHO_C" >&6 -if test "${ac_cv_type_size_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2752 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((size_t *) 0) - return 0; -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2767: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2770: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2773: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2776: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_size_t=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_size_t=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2786: result: $ac_cv_type_size_t" >&5 -echo "${ECHO_T}$ac_cv_type_size_t" >&6 -if test $ac_cv_type_size_t = yes; then - : -else - -cat >>confdefs.h <&5 -echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6 -if test "${ac_cv_header_time+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2804 "configure" -#include "confdefs.h" -#include -#include -#include - -int -main () -{ -struct tm *tp; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2819: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2822: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2825: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2828: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_time=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_header_time=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2838: result: $ac_cv_header_time" >&5 -echo "${ECHO_T}$ac_cv_header_time" >&6 -if test $ac_cv_header_time = yes; then - -cat >>confdefs.h <<\EOF -#define TIME_WITH_SYS_TIME 1 -EOF - -fi - -echo "$as_me:2848: checking for short" >&5 -echo $ECHO_N "checking for short... $ECHO_C" >&6 -if test "${ac_cv_type_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 2854 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((short *) 0) - return 0; -if (sizeof (short)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2869: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2872: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2875: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2878: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_short=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_short=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:2888: result: $ac_cv_type_short" >&5 -echo "${ECHO_T}$ac_cv_type_short" >&6 - -echo "$as_me:2891: checking size of short" >&5 -echo $ECHO_N "checking size of short... $ECHO_C" >&6 -if test "${ac_cv_sizeof_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_short" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 2900 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2912: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2915: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2918: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2921: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 2926 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2938: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2941: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2944: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2947: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 2963 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:2975: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:2978: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:2981: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:2984: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3000 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (short)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3012: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3015: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3018: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3021: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_short=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3034: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3039 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (short))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3055: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3058: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3060: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3063: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_short=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_short=0 -fi -fi -echo "$as_me:3079: result: $ac_cv_sizeof_short" >&5 -echo "${ECHO_T}$ac_cv_sizeof_short" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for int... $ECHO_C" >&6 -if test "${ac_cv_type_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3091 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((int *) 0) - return 0; -if (sizeof (int)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3106: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3109: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3112: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3115: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_int=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_int=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3125: result: $ac_cv_type_int" >&5 -echo "${ECHO_T}$ac_cv_type_int" >&6 - -echo "$as_me:3128: checking size of int" >&5 -echo $ECHO_N "checking size of int... $ECHO_C" >&6 -if test "${ac_cv_sizeof_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_int" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 3137 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3149: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3152: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3155: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3158: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3163 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3175: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3178: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3181: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3184: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3200 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3212: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3215: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3218: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3221: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3237 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (int)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3249: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3252: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3255: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3258: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_int=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3271: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3276 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (int))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3292: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3295: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3297: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3300: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_int=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_int=0 -fi -fi -echo "$as_me:3316: result: $ac_cv_sizeof_int" >&5 -echo "${ECHO_T}$ac_cv_sizeof_int" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for long... $ECHO_C" >&6 -if test "${ac_cv_type_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3328 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -if ((long *) 0) - return 0; -if (sizeof (long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3343: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3346: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3349: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3352: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_long=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3362: result: $ac_cv_type_long" >&5 -echo "${ECHO_T}$ac_cv_type_long" >&6 - -echo "$as_me:3365: checking size of long" >&5 -echo $ECHO_N "checking size of long... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 3374 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3386: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3389: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3392: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3395: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3400 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3412: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3415: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3418: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3421: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3437 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3449: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3452: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3455: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3458: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3474 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -int _array_ [1 - 2 * !((sizeof (long)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3486: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3489: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3492: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3495: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_long=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3508: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3513 "configure" -#include "confdefs.h" -$ac_includes_default -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (long))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3529: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3532: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3534: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3537: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long=0 -fi -fi -echo "$as_me:3553: result: $ac_cv_sizeof_long" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for off_t... $ECHO_C" >&6 -if test "${ac_cv_type_off_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3565 "configure" -#include "confdefs.h" -#include - #include - -int -main () -{ -if ((off_t *) 0) - return 0; -if (sizeof (off_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3582: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3585: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3588: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3591: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_off_t=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_type_off_t=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3601: result: $ac_cv_type_off_t" >&5 -echo "${ECHO_T}$ac_cv_type_off_t" >&6 - -echo "$as_me:3604: checking size of off_t" >&5 -echo $ECHO_N "checking size of off_t... $ECHO_C" >&6 -if test "${ac_cv_sizeof_off_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_off_t" = yes; then - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -#line 3613 "configure" -#include "confdefs.h" -#include - #include - -int -main () -{ -int _array_ [1 - 2 * !((sizeof (off_t)) >= 0)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3627: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3630: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3633: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3636: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3641 "configure" -#include "confdefs.h" -#include - #include - -int -main () -{ -int _array_ [1 - 2 * !((sizeof (off_t)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3655: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3658: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3661: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3664: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -#line 3680 "configure" -#include "confdefs.h" -#include - #include - -int -main () -{ -int _array_ [1 - 2 * !((sizeof (off_t)) >= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3694: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3697: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3700: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3703: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.$ac_objext conftest.$ac_ext - done -fi -rm -f conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -#line 3719 "configure" -#include "confdefs.h" -#include - #include - -int -main () -{ -int _array_ [1 - 2 * !((sizeof (off_t)) <= $ac_mid)] - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3733: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3736: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3739: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3742: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_lo=`expr $ac_mid + 1` -fi -rm -f conftest.$ac_objext conftest.$ac_ext -done -ac_cv_sizeof_off_t=$ac_lo -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:3755: error: cannot run test program while cross compiling" >&5 -echo "$as_me: error: cannot run test program while cross compiling" >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -#line 3760 "configure" -#include "confdefs.h" -#include - #include - -int -main () -{ -FILE *f = fopen ("conftest.val", "w"); -if (!f) - exit (1); -fprintf (f, "%d", (sizeof (off_t))); -fclose (f); - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:3778: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3781: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:3783: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3786: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_off_t=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -fi -rm -f core core.* *.core conftest$ac_exeext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_off_t=0 -fi -fi -echo "$as_me:3802: result: $ac_cv_sizeof_off_t" >&5 -echo "${ECHO_T}$ac_cv_sizeof_off_t" >&6 -cat >>confdefs.h <&5 -echo $ECHO_N "checking for __attribute__... $ECHO_C" >&6 -if test "${lsh_cv_c_attribute+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3814 "configure" -#include "confdefs.h" - -#include - -int -main () -{ - -static void foo(void) __attribute__ ((noreturn)); - -static void __attribute__ ((noreturn)) -foo(void) -{ - exit(1); -} - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:3836: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:3839: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:3842: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3845: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - lsh_cv_c_attribute=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -lsh_cv_c_attribute=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:3855: result: $lsh_cv_c_attribute" >&5 -echo "${ECHO_T}$lsh_cv_c_attribute" >&6 - -if test "x$lsh_cv_c_attribute" = "xyes"; then - cat >>confdefs.h <<\EOF -#define HAVE_GCC_ATTRIBUTE 1 -EOF - -fi - -for ac_func in pread pwrite -do -ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` -echo "$as_me:3868: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$ac_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -#line 3874 "configure" -#include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -char (*f) (); - -int -main () -{ -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -f = $ac_func; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:3905: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:3908: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:3911: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:3914: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$ac_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -eval "$ac_ac_var=no" -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:3924: result: `eval echo '${'$ac_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$ac_ac_var'}'`" >&6 -if test `eval echo '${'$ac_ac_var'}'` = yes; then - cat >>confdefs.h <confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overriden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -{ - (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n \ - "s/^\\([_$ac_cr_alnum]*_cv_[_$ac_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} | - sed ' - t clear - : clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - : end' >>confcache -if cmp -s $cache_file confcache; then :; else - if test -w $cache_file; then - test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" - cat confcache >$cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/; -s/:*\${srcdir}:*/:/; -s/:*@srcdir@:*/:/; -s/^\([^=]*=[ ]*\):*/\1/; -s/:*$//; -s/^[^=]*=[ ]*$//; -}' -fi - -DEFS=-DHAVE_CONFIG_H - -: ${CONFIG_STATUS=./config.status} -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ echo "$as_me:4022: creating $CONFIG_STATUS" >&5 -echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF -#! $SHELL -# Generated automatically by configure. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -SHELL=\${CONFIG_SHELL-$SHELL} -ac_cs_invocation="\$0 \$@" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi - -# Name of the executable. -as_me=`echo "$0" |sed 's,.*[\\/],,'` - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -as_executable_p="test -f" - -# Support unset when possible. -if (FOO=FOO; unset FOO) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - -# NLS nuisances. -$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } -$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } -$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } -$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } -$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } -$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } -$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } -$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } - -exec 6>&1 - -_ACEOF - -# Files that config.status was made for. -if test -n "$ac_config_files"; then - echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_headers"; then - echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_links"; then - echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_commands"; then - echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS -fi - -cat >>$CONFIG_STATUS <<\EOF - -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTIONS] [FILE]... - - -h, --help print this help, then exit - -V, --version print version number, then exit - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to ." -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -# If no file are specified by the user, then we need to provide default -# value. By we need to know if files were specified by the user. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "x$1" : 'x\([^=]*\)='` - ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` - shift - set dummy "$ac_option" "$ac_optarg" ${1+"$@"} - shift - ;; - -*);; - *) # This is not an option, so the user has probably given explicit - # arguments. - ac_need_defaults=false;; - esac - - case $1 in - # Handling of the options. -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF - --version | --vers* | -V ) - echo "$ac_cs_version"; exit 0 ;; - --he | --h) - # Conflict between --help and --header - { { echo "$as_me:4198: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - echo "$ac_cs_usage"; exit 0 ;; - --debug | --d* | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - shift - CONFIG_FILES="$CONFIG_FILES $1" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - shift - CONFIG_HEADERS="$CONFIG_HEADERS $1" - ac_need_defaults=false;; - - # Handling of arguments. - 'Makefile' ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; - 'testsuite/Makefile' ) CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;; - 'default-1' ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; - 'config.h' ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - - # This is an error. - -*) { { echo "$as_me:4223: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; } ;; - *) { { echo "$as_me:4228: error: invalid argument: $1" >&5 -echo "$as_me: error: invalid argument: $1" >&2;} - { (exit 1); exit 1; }; };; - esac - shift -done - -exec 5>>config.log -cat >&5 << _ACEOF - -## ----------------------- ## -## Running config.status. ## -## ----------------------- ## - -This file was extended by $as_me 2.50, executed with - > $ac_cs_invocation -on `(hostname || uname -n) 2>/dev/null | sed 1q` - -_ACEOF -EOF - -cat >>$CONFIG_STATUS <<\EOF -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Create a temporary directory, and hook for its removal unless debugging. -$debug || -{ - trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 - trap '{ (exit $?); exit $?; }' 1 2 13 15 -} - -# Create a (secure) tmp directory for tmp files. -: ${TMPDIR=/tmp} -{ - tmp=`(umask 077 && mktemp -d -q "$TMPDIR/csXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=$TMPDIR/cs$$-$RANDOM - (umask 077 && mkdir $tmp) -} || -{ - echo "$me: cannot create a temporary directory in $TMPDIR" >&2 - { (exit 1); exit 1; } -} - -EOF - -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <\$tmp/subs.sed <<\\CEOF -s,@SHELL@,$SHELL,;t t -s,@exec_prefix@,$exec_prefix,;t t -s,@prefix@,$prefix,;t t -s,@program_transform_name@,$program_transform_name,;t t -s,@bindir@,$bindir,;t t -s,@sbindir@,$sbindir,;t t -s,@libexecdir@,$libexecdir,;t t -s,@datadir@,$datadir,;t t -s,@sysconfdir@,$sysconfdir,;t t -s,@sharedstatedir@,$sharedstatedir,;t t -s,@localstatedir@,$localstatedir,;t t -s,@libdir@,$libdir,;t t -s,@includedir@,$includedir,;t t -s,@oldincludedir@,$oldincludedir,;t t -s,@infodir@,$infodir,;t t -s,@mandir@,$mandir,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t -s,@ECHO_C@,$ECHO_C,;t t -s,@ECHO_N@,$ECHO_N,;t t -s,@ECHO_T@,$ECHO_T,;t t -s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t -s,@DEFS@,$DEFS,;t t -s,@LIBS@,$LIBS,;t t -s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t -s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t -s,@INSTALL_DATA@,$INSTALL_DATA,;t t -s,@PACKAGE@,$PACKAGE,;t t -s,@VERSION@,$VERSION,;t t -s,@ACLOCAL@,$ACLOCAL,;t t -s,@AUTOCONF@,$AUTOCONF,;t t -s,@AUTOMAKE@,$AUTOMAKE,;t t -s,@AUTOHEADER@,$AUTOHEADER,;t t -s,@MAKEINFO@,$MAKEINFO,;t t -s,@SET_MAKE@,$SET_MAKE,;t t -s,@CC@,$CC,;t t -s,@CFLAGS@,$CFLAGS,;t t -s,@LDFLAGS@,$LDFLAGS,;t t -s,@CPPFLAGS@,$CPPFLAGS,;t t -s,@ac_ct_CC@,$ac_ct_CC,;t t -s,@EXEEXT@,$EXEEXT,;t t -s,@OBJEXT@,$OBJEXT,;t t -s,@RANLIB@,$RANLIB,;t t -s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t -s,@CPP@,$CPP,;t t -CEOF - -EOF - - cat >>$CONFIG_STATUS <<\EOF - # Split the substitutions into bite-sized pieces for seds with - # small command number limits, like on Digital OSF/1 and HP-UX. - ac_max_sed_lines=48 - ac_sed_frag=1 # Number of current file. - ac_beg=1 # First line for current file. - ac_end=$ac_max_sed_lines # Line after last line for current file. - ac_more_lines=: - ac_sed_cmds= - while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - else - sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - fi - if test ! -s $tmp/subs.frag; then - ac_more_lines=false - else - # The purpose of the label and of the branching condition is to - # speed up the sed processing (if there are no `@' at all, there - # is no need to browse any of the substitutions). - # These are the two extra sed commands mentioned above. - (echo ':t - /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" - else - ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" - fi - ac_sed_frag=`expr $ac_sed_frag + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_lines` - fi - done - if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat - fi -fi # test -n "$CONFIG_FILES" - -EOF -cat >>$CONFIG_STATUS <<\EOF -for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - ac_dir_suffix="/`echo $ac_dir|sed 's,^\./,,'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo "$ac_dir_suffix" | sed 's,/[^/]*,../,g'` - else - ac_dir_suffix= ac_dots= - fi - - case $srcdir in - .) ac_srcdir=. - if test -z "$ac_dots"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_dots | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_dots$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_dots$srcdir ;; - esac - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_dots$INSTALL ;; - esac - - if test x"$ac_file" != x-; then - { echo "$as_me:4465: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - configure_input="Generated automatically from `echo $ac_file_in | - sed 's,.*/,,'` by configure." - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:4483: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:4496: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } -EOF -cat >>$CONFIG_STATUS <>$CONFIG_STATUS <<\EOF -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s,@configure_input@,$configure_input,;t t -s,@srcdir@,$ac_srcdir,;t t -s,@top_srcdir@,$ac_top_srcdir,;t t -s,@INSTALL@,$ac_INSTALL,;t t -" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out - rm -f $tmp/stdin - if test x"$ac_file" != x-; then - mv $tmp/out $ac_file - else - cat $tmp/out - rm -f $tmp/out - fi - -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_HEADER section. -# - -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' -ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t' - -for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - test x"$ac_file" != x- && { echo "$as_me:4557: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:4568: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo $f;; - *) # Relative - if test -f "$f"; then - # Build tree - echo $f - elif test -f "$srcdir/$f"; then - # Source tree - echo $srcdir/$f - else - # /dev/null tree - { { echo "$as_me:4581: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } - # Remove the trailing spaces. - sed 's/[ ]*$//' $ac_file_inputs >$tmp/in - -EOF - -# Transform confdefs.h into two sed scripts, `conftest.defines' and -# `conftest.undefs', that substitutes the proper values into -# config.h.in to produce config.h. The first handles `#define' -# templates, and the second `#undef' templates. -# And first: Protect against being on the right side of a sed subst in -# config.status. Protect against being in an unquoted here document -# in config.status. -rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. -# Putting comments in sed scripts is not portable. -# -# `end' is used to avoid that the second main sed command (meant for -# 0-ary CPP macros) applies to n-ary macro definitions. -# See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\EOF -s/[\\&,]/\\&/g -s,[\\$`],\\&,g -t clear -: clear -s,^[ ]*#[ ]*define[ ][ ]*\(\([^ (][^ (]*\)([^)]*)\)[ ]*\(.*\)$,${ac_dA}\2${ac_dB}\1${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end -EOF -# If some macros were called several times there might be several times -# the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. -uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs -rm -f confdef2sed.sed - -# This sed command replaces #undef with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\EOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -EOF - -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if egrep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.defines >/dev/null -do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/defines.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail - rm -f conftest.defines - mv conftest.tail conftest.defines -done -rm -f conftest.defines -echo ' fi # egrep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/undefs.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs - -cat >>$CONFIG_STATUS <<\EOF - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated automatically by config.status. */ - if test x"$ac_file" = x-; then - echo "/* Generated automatically by configure. */" >$tmp/config.h - else - echo "/* $ac_file. Generated automatically by configure. */" >$tmp/config.h - fi - cat $tmp/in >>$tmp/config.h - rm -f $tmp/in - if test x"$ac_file" != x-; then - if cmp -s $ac_file $tmp/config.h 2>/dev/null; then - { echo "$as_me:4698: $ac_file is unchanged" >&5 -echo "$as_me: $ac_file is unchanged" >&6;} - else - ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - { case "$ac_dir" in - [\\/]* | ?:[\\/]* ) as_incr_dir=;; - *) as_incr_dir=.;; -esac -as_dummy="$ac_dir" -for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do - case $as_mkdir_dir in - # Skip DOS drivespec - ?:) as_incr_dir=$as_mkdir_dir ;; - *) - as_incr_dir=$as_incr_dir/$as_mkdir_dir - test -d "$as_incr_dir" || mkdir "$as_incr_dir" - ;; - esac -done; } - - fi - rm -f $ac_file - mv $tmp/config.h $ac_file - fi - else - cat $tmp/config.h - rm -f $tmp/config.h - fi -done -EOF -cat >>$CONFIG_STATUS <<\EOF - -# -# CONFIG_COMMANDS section. -# -for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue - ac_dest=`echo "$ac_file" | sed 's,:.*,,'` - ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'` - - case $ac_dest in - default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;; - esac -done -EOF - -cat >>$CONFIG_STATUS <<\EOF - -{ (exit 0); exit 0; } -EOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - exec 5>/dev/null - $SHELL $CONFIG_STATUS || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi - diff --git a/lsh/src/sftp/configure.in b/lsh/src/sftp/configure.in deleted file mode 100644 index 39001cc..0000000 --- a/lsh/src/sftp/configure.in +++ /dev/null @@ -1,74 +0,0 @@ -dnl -*- mode: shell-script; sh-indentation: 2; -*- -dnl $Id$ - -dnl Process this file with autoconf to produce a configure script. - -AC_INIT(sftp-server.c) - -AM_INIT_AUTOMAKE(lsh-sftp, 1.0) - -AM_CONFIG_HEADER(config.h) - -CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" - -dnl Checks for programs. -AC_PROG_CC -AC_PROG_MAKE_SET -AC_PROG_RANLIB -AM_PROG_CC_STDC - -if test "x$am_cv_prog_cc_stdc" = xno ; then - AC_ERROR([the C compiler doesn't handle ANSI-C]) -fi - -dnl Checks for header files. -AC_HEADER_STDC - -dnl Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE -AC_TYPE_UID_T -AC_TYPE_SIZE_T -AC_HEADER_TIME - -AC_CHECK_SIZEOF(short, 2) -AC_CHECK_SIZEOF(int, 4) -AC_CHECK_SIZEOF(long, 4) -AC_CHECK_SIZEOF(off_t, 8, -[#include - #include ]) - -dnl Check for gcc's __attribute__ construction -AC_CACHE_CHECK(for __attribute__, - lsh_cv_c_attribute, -[ AC_TRY_COMPILE([ -#include -], -[ -static void foo(void) __attribute__ ((noreturn)); - -static void __attribute__ ((noreturn)) -foo(void) -{ - exit(1); -} -], -lsh_cv_c_attribute=yes, -lsh_cv_c_attribute=no)]) - -if test "x$lsh_cv_c_attribute" = "xyes"; then - AC_DEFINE(HAVE_GCC_ATTRIBUTE) -fi - -dnl Checks for library functions. -AC_CHECK_FUNCS(pread pwrite) - -# Set these flags *last*, or else the test programs won't compile -if test x$GCC = xyes ; then - CFLAGS="$CFLAGS -ggdb3 -Wall -W \ - -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \ - -Waggregate-return \ - -Wpointer-arith -Wbad-function-cast -Wnested-externs -Wcast-align" -fi - -AC_OUTPUT([Makefile testsuite/Makefile]) diff --git a/lsh/src/sftp/dump-hex.c b/lsh/src/sftp/dump-hex.c deleted file mode 100644 index db68a8a..0000000 --- a/lsh/src/sftp/dump-hex.c +++ /dev/null @@ -1,212 +0,0 @@ -/* dump-hex.c - * - * This program copies data from stdin to stdout, and also - * writes a hex dump to stderr. - */ - -#include -#include -#include -#include - -#include -#include - -static void -usage(void) -{ - fprintf(stderr, - "Usage: dump-hex\n" - " or dump-hex LABEL\n" - " or dump-hex --help\n\n" - "Copies data from stdin to stdout,\n" - "and also writes a hex dump to stderr.\n"); -} - -static int is_help_option(const char *arg) -{ - return !strcmp(arg, "-?") || !strcasecmp(arg, "--help"); -} - -/* Blocks for at least one character, but no longer. Returns number of - * characters, just like read. */ -static int -do_read(int fd, char *data, int length) -{ - int res; - do - res = read(fd, data, length); - while ( (res < 0) && (errno == EINTR) ); - - return res; -}; - -/* Writes all data, unless some error occurs. */ -static int -do_write(int fd, const char *data, int length) -{ - int done; - for (done = 0; done < length; ) - { - int res = write(fd, data + done, length - done); - if (res < 0) - { - if (errno != EINTR) - return -1; - } - else - { - done += res; - } - } - return done; -} - -#define LINE 16 - -static int -output_line(int fd, const char *label, - unsigned pos, const char *data, unsigned length) -{ - /* The format used: - * - * LABEL ADDRESS DATA ASCII - * foobar: 000000B0 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff xxxxxxxxxxxxxxxx - * - * 0 1 2 3 4 5 6 7 - * 0123456789012345678901234567890123456789012345678901234567890123456789012 - * - * Lines are 72 characters + the size of the label + newline. - */ - - const char hex_digit[16] = "0123456789abcdef"; - - unsigned label_length = strlen(label); - char *line = alloca(label_length + 80); - unsigned i = 0; - - unsigned offset = pos % LINE; - unsigned address = pos - offset; - - if (label_length) - { - /* Non-empty-label */ - memcpy(line, label, label_length); - i = label_length; - line[i++] = ':'; - line[i++] = ' '; - } - - /* Write the address field. */ - { - unsigned k; - unsigned buffer; - - for (k = 8, buffer = address; k-- > 0; buffer >>= 4) - line[i+k] = hex_digit[buffer & 0xf]; - - i += 8; - } - line[i++] = ' '; - - /* Skip to the start of the data */ - memset(line + i, ' ', 3 * offset); - i += 3 * offset; - - /* Write the hex data */ - { - unsigned k; - for (k = 0; k> 4]; - line[i++] = hex_digit[c & 0xf]; - line[i++] = ' '; - } - } - - /* Skip to ascii part */ - { - /* (LINE - (length + offset)) * 3 + offset - * = (LINE - length) * 3 - offset * 2 - */ - unsigned skip = 3* (LINE - length) - 2 * offset; - memset(line + i, ' ', skip); - i += skip; - } - - /* Output ascii */ - { - unsigned k; - for (k = 0; k -#endif - -#include -#include - -#include "filemode.h" - -#if !S_IRUSR -# if S_IREAD -# define S_IRUSR S_IREAD -# else -# define S_IRUSR 00400 -# endif -#endif - -#if !S_IWUSR -# if S_IWRITE -# define S_IWUSR S_IWRITE -# else -# define S_IWUSR 00200 -# endif -#endif - -#if !S_IXUSR -# if S_IEXEC -# define S_IXUSR S_IEXEC -# else -# define S_IXUSR 00100 -# endif -#endif - -#ifdef STAT_MACROS_BROKEN -# undef S_ISBLK -# undef S_ISCHR -# undef S_ISDIR -# undef S_ISFIFO -# undef S_ISLNK -# undef S_ISMPB -# undef S_ISMPC -# undef S_ISNWK -# undef S_ISREG -# undef S_ISSOCK -#endif /* STAT_MACROS_BROKEN. */ - -#if !defined(S_ISBLK) && defined(S_IFBLK) -# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#endif -#if !defined(S_ISCHR) && defined(S_IFCHR) -# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#endif -#if !defined(S_ISDIR) && defined(S_IFDIR) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif -#if !defined(S_ISREG) && defined(S_IFREG) -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -#if !defined(S_ISFIFO) && defined(S_IFIFO) -# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#endif -#if !defined(S_ISLNK) && defined(S_IFLNK) -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#endif -#if !defined(S_ISSOCK) && defined(S_IFSOCK) -# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) -#endif -#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */ -# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) -# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) -#endif -#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ -# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) -#endif - -/* Look at read, write, and execute bits in BITS and set - flags in CHARS accordingly. */ - -static void -rwx (short unsigned int bits, char *chars) -{ - chars[0] = (bits & S_IRUSR) ? 'r' : '-'; - chars[1] = (bits & S_IWUSR) ? 'w' : '-'; - chars[2] = (bits & S_IXUSR) ? 'x' : '-'; -} - -/* Set the 's' and 't' flags in file attributes string CHARS, - according to the file mode BITS. */ - -static void -setst (short unsigned int bits, char *chars) -{ -#ifdef S_ISUID - if (bits & S_ISUID) - { - if (chars[3] != 'x') - /* Set-uid, but not executable by owner. */ - chars[3] = 'S'; - else - chars[3] = 's'; - } -#endif -#ifdef S_ISGID - if (bits & S_ISGID) - { - if (chars[6] != 'x') - /* Set-gid, but not executable by group. */ - chars[6] = 'S'; - else - chars[6] = 's'; - } -#endif -#ifdef S_ISVTX - if (bits & S_ISVTX) - { - if (chars[9] != 'x') - /* Sticky, but not executable by others. */ - chars[9] = 'T'; - else - chars[9] = 't'; - } -#endif -} - -/* Return a character indicating the type of file described by - file mode BITS: - 'd' for directories - 'b' for block special files - 'c' for character special files - 'm' for multiplexor files - 'M' for an off-line (regular) file - 'l' for symbolic links - 's' for sockets - 'p' for fifos - '-' for regular files - '?' for any other file type. */ - -static char -ftypelet (long int bits) -{ -#ifdef S_ISBLK - if (S_ISBLK (bits)) - return 'b'; -#endif - if (S_ISCHR (bits)) - return 'c'; - if (S_ISDIR (bits)) - return 'd'; - if (S_ISREG (bits)) - return '-'; -#ifdef S_ISFIFO - if (S_ISFIFO (bits)) - return 'p'; -#endif -#ifdef S_ISLNK - if (S_ISLNK (bits)) - return 'l'; -#endif -#ifdef S_ISSOCK - if (S_ISSOCK (bits)) - return 's'; -#endif -#ifdef S_ISMPC - if (S_ISMPC (bits)) - return 'm'; -#endif -#ifdef S_ISNWK - if (S_ISNWK (bits)) - return 'n'; -#endif - - /* The following two tests are for Cray DMF (Data Migration - Facility), which is a HSM file system. A migrated file has a - `st_dm_mode' that is different from the normal `st_mode', so any - tests for migrated files should use the former. */ - -#ifdef S_ISOFD - if (S_ISOFD (bits)) - /* off line, with data */ - return 'M'; -#endif -#ifdef S_ISOFL - /* off line, with no data */ - if (S_ISOFL (bits)) - return 'M'; -#endif - return '?'; -} - -/* Like filemodestring, but only the relevant part of the `struct stat' - is given as an argument. */ - -void -mode_string (short unsigned int mode, char *str) -{ - str[0] = ftypelet ((long) mode); - rwx ((mode & 0700) << 0, &str[1]); - rwx ((mode & 0070) << 3, &str[4]); - rwx ((mode & 0007) << 6, &str[7]); - setst (mode, str); -} - -/* filemodestring - fill in string STR with an ls-style ASCII - representation of the st_mode field of file stats block STATP. - 10 characters are stored in STR; no terminating null is added. - The characters stored in STR are: - - 0 File type. 'd' for directory, 'c' for character - special, 'b' for block special, 'm' for multiplex, - 'l' for symbolic link, 's' for socket, 'p' for fifo, - '-' for regular, '?' for any other file type - - 1 'r' if the owner may read, '-' otherwise. - - 2 'w' if the owner may write, '-' otherwise. - - 3 'x' if the owner may execute, 's' if the file is - set-user-id, '-' otherwise. - 'S' if the file is set-user-id, but the execute - bit isn't set. - - 4 'r' if group members may read, '-' otherwise. - - 5 'w' if group members may write, '-' otherwise. - - 6 'x' if group members may execute, 's' if the file is - set-group-id, '-' otherwise. - 'S' if it is set-group-id but not executable. - - 7 'r' if any user may read, '-' otherwise. - - 8 'w' if any user may write, '-' otherwise. - - 9 'x' if any user may execute, 't' if the file is "sticky" - (will be retained in swap space after execution), '-' - otherwise. - 'T' if the file is sticky but not executable. */ - -void -filemodestring (struct stat *statp, char *str) -{ - mode_string (statp->st_mode, str); -} diff --git a/lsh/src/sftp/filemode.h b/lsh/src/sftp/filemode.h deleted file mode 100644 index 273b387..0000000 --- a/lsh/src/sftp/filemode.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PARAMS -# if defined PROTOTYPES || (defined __STDC__ && __STDC__) -# define PARAMS(Args) Args -# else -# define PARAMS(Args) () -# endif -#endif - -#include -#include - -#define MODE_STRING_LENGTH 10 -void mode_string PARAMS ((short unsigned int mode, char *str)); -void filemodestring PARAMS ((struct stat *statp, char *str)); diff --git a/lsh/src/sftp/idcache.c b/lsh/src/sftp/idcache.c deleted file mode 100644 index 1532559..0000000 --- a/lsh/src/sftp/idcache.c +++ /dev/null @@ -1,88 +0,0 @@ -/* idcache.c -- map user and group IDs, cached for speed - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 */ - -#include "idcache.h" - -#include "xmalloc.h" - -/* For cached user and group info */ -struct sftp_user_info -{ - int id; - const char *name; - struct sftp_user_info *next; -}; - - -#if 1 -int -sftp_cache_assoc(struct sftp_user_info **cache, - int id, - const char **name) -{ - struct sftp_user_info *p; - for (p = *cache ; p; p = p->next) - if (p->id == id) - { - *name = p->name; - return 1; - } - return 0; -} - -#else - -int -sftp_cache_assoc(struct sftp_user_info **cache, - int id, - const char **name) -{ - struct sftp_user_info **p; - struct sftp_user_info *p; - - for (pp = cache; (p = *pp); pp = &(p->next)) - if (p->id == id) - { - /* Reorder, putting the found element first. */ - *pp = p->next; - p->next = *cache; - *cache = p; - - *name = p->name; - return 1; - } - return 0; -} -#endif - -const char * -sftp_cache_push(struct sftp_user_info **cache, - int id, const char *name) -{ - struct sftp_user_info *p = xmalloc(sizeof(struct sftp_user_info)); - p->id = id; - p->name = name; - p->next = *cache; - *cache = p; - - return name; -} diff --git a/lsh/src/sftp/idcache.h b/lsh/src/sftp/idcache.h deleted file mode 100644 index 75c32d2..0000000 --- a/lsh/src/sftp/idcache.h +++ /dev/null @@ -1,37 +0,0 @@ -/* idcache.h - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 */ - -#ifndef SFTP_IDCACHE_H_INCLUDED -#define SFTP_IDCACHE_H_INCLUDED - -struct sftp_user_info; - -int -sftp_cache_assoc(struct sftp_user_info **cache, - int id, - const char **name); - -const char * -sftp_cache_push(struct sftp_user_info **cache, - int id, const char *name); - -#endif /* SFTP_IDCACHE_H_INCLUDED */ diff --git a/lsh/src/sftp/sftp-server.c b/lsh/src/sftp/sftp-server.c deleted file mode 100644 index 59d52e4..0000000 --- a/lsh/src/sftp/sftp-server.c +++ /dev/null @@ -1,1257 +0,0 @@ -/* sftp-server.c - * - * $Id$ - * - * The server side of the sftp subsystem. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Markus Friedl, Niels Möller, Pontus Sköld - * - * Also includes parts from GNU fileutils, Copyright by Free Software - * Foundation, Inc. - * - * 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 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 should 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 */ - -/* Some of this code is written by Markus Friedl, and licensed as follows, - * - * Copyright (c) 2000 Markus Friedl. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "buffer.h" -#include "sftp.h" - -#include "filemode.h" -#include "idcache.h" -#include "xmalloc.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#define SFTP_VERSION 3 - -#define FATAL(x) do { fputs("sftp-server: " x "\n", stderr); exit(EXIT_FAILURE); } while (0) - -#define WITH_DEBUG 1 - -#if WITH_DEBUG -static int debug_flag = 0; - -static void -debug(const char *format, ...) PRINTF_STYLE(1,2); - -static void -debug(const char *format, ...) -{ - if (debug_flag) - { - va_list args; - - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - } -} -# define DEBUG(x) debug x -#else /* !WITH_DEBUG */ -# define DEBUG(x) -#endif /* !WITH_DEBUG */ - -#define SFTP_MAX_HANDLES 200 - -/* We need to keep the name of directories around, in order to stat - * entries. */ -struct sftp_dir -{ - DIR *dir; - char *name; -}; - -/* And we need the position, so we know if we need to seek. - * Not all fd:s have an internal file position */ -struct sftp_file -{ - int fd; - off_t position; -}; - -struct sftp_handle -{ - enum sftp_handle_type - { HANDLE_UNUSED = 0, HANDLE_TYPE_FILE, HANDLE_TYPE_DIRECTORY } type; - - union - { - struct sftp_file file; - struct sftp_dir dir; - } u; -}; - -#define HANDLE_TYPE(ctx, handle) ((ctx)->handles[handle].type) - -#define HANDLE_DIR(ctx, handle) ((ctx)->handles[handle].u.dir) -#define HANDLE_FILE(ctx, handle) ((ctx)->handles[handle].u.file) - -struct sftp_ctx -{ - struct sftp_input *i; - struct sftp_output *o; - struct sftp_user_info *user_cache; - struct sftp_user_info *group_cache; - - struct sftp_handle handles[SFTP_MAX_HANDLES]; -}; - -static void -sftp_init(struct sftp_ctx *ctx, FILE *in, FILE *out) -{ - unsigned i; - - ctx->i = sftp_make_input(in); - ctx->o = sftp_make_output(out); - - ctx->user_cache = NULL; - ctx->group_cache = NULL; - - for (i = 0; i < SFTP_MAX_HANDLES; i++) - ctx->handles[i].type = HANDLE_UNUSED; -} - -static const char * -sftp_get_user(struct sftp_ctx *ctx, uid_t id) -{ - const char *name; - - if (sftp_cache_assoc(&ctx->user_cache, id, &name)) - return name; - - else - { - struct passwd *pwd = getpwuid(id); - name = pwd ? xstrdup(pwd->pw_name) : NULL; - sftp_cache_push(&ctx->user_cache, id, name); - return name; - } -} - -static const char * -sftp_get_group(struct sftp_ctx *ctx, gid_t id) -{ - const char *name; - - if (sftp_cache_assoc(&ctx->group_cache, id, &name)) - return name; - - else - { - struct group *grp = getgrgid(id); - name = grp ? xstrdup(grp->gr_name) : NULL; - sftp_cache_push(&ctx->group_cache, id, name); - return name; - } -} - -static void -sftp_attrib_from_stat(struct stat *st, struct sftp_attrib* a) -{ - a->permissions=st->st_mode; - a->uid=st->st_uid; - a->gid=st->st_gid; - a->atime=st->st_atime; - a->mtime=st->st_mtime; - a->size=st->st_size; - a->flags= ( SSH_FILEXFER_ATTR_SIZE || - SSH_FILEXFER_ATTR_UIDGID || - SSH_FILEXFER_ATTR_PERMISSIONS || - SSH_FILEXFER_ATTR_ACMODTIME - ); -} - -static void -sftp_put_longname_mode(struct sftp_output *o, struct stat *st) -{ - /* A 10 character modestring and a space */ - UINT8 modes[MODE_STRING_LENGTH]; - - filemodestring(st, modes); - - sftp_put_data(o, sizeof(modes), modes); -} - -static void -sftp_put_longname(struct sftp_ctx *ctx, - struct stat *st, const UINT8 *fname) -{ - /* NOTE: The current spec doesn't mandate utf8. */ - - /* Where to store the length. */ - UINT32 length_index = sftp_put_reserve_length(ctx->o); - const char *user_name; - const char *group_name; - time_t now, when; - struct tm *when_local; - const char *time_format; - - sftp_put_longname_mode(ctx->o, st); - sftp_put_printf(ctx->o, " %3u ", (unsigned) st->st_nlink); - - user_name = sftp_get_user(ctx, st->st_uid); - if (user_name) - sftp_put_printf(ctx->o, "%-8.8s ", user_name); - else - sftp_put_printf(ctx->o, "%-8u ", (unsigned int) st->st_uid); - - group_name = sftp_get_group(ctx, st->st_gid); - if (group_name) - sftp_put_printf(ctx->o, "%-8.8s ", group_name); - else - sftp_put_printf(ctx->o, "%-8u ", (unsigned) st->st_gid); - - /* FIXME: How to deal with long long sizes? */ - sftp_put_printf(ctx->o, "%8lu ", (unsigned long) st->st_size); - - now = time(NULL); - when = st->st_mtime; - - when_local = localtime( &st->st_mtime ); - - if ( (now > when + 6L * 30L * 24L * 60L * 60L) /* Old. */ - || (now < when - 60L * 60L) ) /* In the future. */ - /* The file is fairly old or in the future. - POSIX says the cutoff is 6 months old; - approximate this by 6*30 days. - Allow a 1 hour slop factor for what is considered "the future", - to allow for NFS server/client clock disagreement. - Show the year instead of the time of day. */ - time_format = "%b %e %Y"; - else - time_format = "%b %e %H:%M"; - - sftp_put_strftime(ctx->o, 12, time_format, when_local); - - sftp_put_printf(ctx->o, " %s", fname); - - sftp_put_final_length(ctx->o, length_index); -} - -static void -sftp_put_filename(struct sftp_ctx *ctx, - struct stat *st, - const char *name) -{ - struct sftp_attrib a; - - sftp_attrib_from_stat( st, &a); - sftp_put_string(ctx->o, strlen(name), name); - sftp_put_longname(ctx, st, name); - sftp_put_attrib(ctx->o, &a); -} - -/* FIXME: We need to distinguish invalid messages from invalid file - names. */ -static const UINT8 * -sftp_get_name(struct sftp_input *i) -{ - UINT8 *name; - UINT32 length; - - name = sftp_get_string_auto(i, &length); - if (!length) - name = "."; - - else if (memchr(name, 0, length)) - name = NULL; - - DEBUG (("sftp_get_name: %s\n", name ? (char *) name : "")); - - return name; -} - -static int -sftp_handle_used(struct sftp_ctx *ctx, UINT32 handle) -{ - return (handle < SFTP_MAX_HANDLES) - && (ctx->handles[handle].type != HANDLE_UNUSED); -} - -static int -sftp_new_handle(struct sftp_ctx *ctx, - enum sftp_handle_type type, - UINT32 *handle) -{ - UINT32 i; - - assert(type != HANDLE_UNUSED); - - /* FIXME: This linear search is suboptimal */ - for (i = 0; ii, &length) - && (length == 4) - && sftp_get_uint32(ctx->i, &value) - && sftp_handle_used(ctx, value)) - { - *handle = value; - return 1; - } - return 0; -} - -static int -sftp_get_handle_dir(struct sftp_ctx *ctx, struct sftp_dir **value) -{ - UINT32 handle; - - if (sftp_get_handle(ctx, &handle) - && (HANDLE_TYPE(ctx, handle) == HANDLE_TYPE_DIRECTORY)) - { - *value = &HANDLE_DIR(ctx, handle); - return 1; - } - else - return 0; -} - -static int -sftp_get_handle_file(struct sftp_ctx *ctx, struct sftp_file **f) -{ - UINT32 handle; - - if (sftp_get_handle(ctx, &handle) - && (HANDLE_TYPE(ctx, handle) == HANDLE_TYPE_FILE)) - { - *f = &HANDLE_FILE(ctx, handle); - return 1; - } - else - return 0; -} - -static int -sftp_get_handle_fd(struct sftp_ctx *ctx, int *fd) -{ - struct sftp_file *f; - - if (sftp_get_handle_file(ctx, &f)) - { - *fd = f->fd; - return 1; - } - else - return 0; -} - -static void -sftp_put_handle(struct sftp_ctx *ctx, UINT32 handle) -{ - sftp_put_uint32(ctx->o, 4); - sftp_put_uint32(ctx->o, handle); -} - -static int -sftp_send_handle(struct sftp_ctx *ctx, UINT32 handle) -{ - sftp_set_msg(ctx->o, SSH_FXP_HANDLE); - sftp_put_handle(ctx, handle); - return 1; -} - -/* NOTE: The status message should be expanded with a human-readable - * message and a language tag. */ -static int -sftp_send_status(struct sftp_ctx *ctx, UINT32 status) -{ - DEBUG (("sftp_send_status: %d\n", status)); - - sftp_set_msg(ctx->o, SSH_FXP_STATUS); - sftp_put_uint32(ctx->o, status); - return 1; -} - -static int -sftp_send_errno(struct sftp_ctx *ctx, int e) -{ - UINT32 status; - - DEBUG (("sftp_send_errno: %d, %s\n", e, strerror(e))); - switch(e) - { - case ENOENT: - status = SSH_FX_NO_SUCH_FILE; - break; - case EACCES: - status = SSH_FX_PERMISSION_DENIED; - break; - default: - status = SSH_FX_FAILURE; - break; - } - return sftp_send_status(ctx, status); -} - -static int -sftp_bad_message(struct sftp_ctx *ctx) -{ - sftp_send_status(ctx, SSH_FX_BAD_MESSAGE); - return 0; -} - -typedef int sftp_process_func(struct sftp_ctx *ctx); - -static int -sftp_process_unsupported(struct sftp_ctx *ctx) -{ - return sftp_bad_message(ctx); -} - -static int -sftp_process_opendir(struct sftp_ctx *ctx) -{ - const UINT8 *name; - DIR* dir; - UINT32 handle; - - DEBUG (("sftp_process_opendir\n")); - - if ( ! (name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - /* FIXME: Perhaps we should have a sftp_mangle_fname? If not, we - have to handle an empty filename here */ - - dir=opendir(name); - - if (!dir) - return sftp_send_errno(ctx, errno); - - /* Open successful */ - - if (!sftp_new_handle(ctx, HANDLE_TYPE_DIRECTORY, &handle)) - return sftp_send_status(ctx, SSH_FX_FAILURE); - - HANDLE_DIR(ctx, handle).dir = dir; - HANDLE_DIR(ctx, handle).name = strdup(name); - - return sftp_send_handle(ctx, handle); -} - -/* FIXME: Creative use of dirfd and fchdir would be more robust. */ -static int -sftp_lstat_in_dir(const char *dir, const char *file, - struct stat *sb) -{ - unsigned dir_length = strlen(dir); - unsigned file_length = strlen(file); - char *s = alloca(dir_length + file_length + 2); - - memcpy(s, dir, dir_length); - s[dir_length] = '/'; - memcpy(s + dir_length + 1, file, file_length); - s[dir_length + file_length + 1] = '\0'; - - return lstat(s, sb); -} - -static int -sftp_process_readdir(struct sftp_ctx *ctx) -{ - struct sftp_dir *dir; - struct dirent* entry; - struct stat st; - - if (!sftp_get_handle_dir(ctx, &dir)) - return sftp_bad_message(ctx); - - entry=readdir(dir->dir); - - if (!entry) - return (errno ? sftp_send_errno(ctx, errno) - : sftp_send_status(ctx, SSH_FX_EOF)); - - if (sftp_lstat_in_dir(dir->name, entry->d_name, &st) ) - /* FIXME: Would it be better to just skip this entry, or send an - * SSH_FXP_NAME with no file attributes? */ - return sftp_send_errno(ctx, errno); - - /* FIXME: we don't have to, but maybe we should be nice and pass - * several at once? It might improve performance quite a lot (or it - * might not) */ - - /* Use count == 1 for now. */ - sftp_put_uint32(ctx->o, 1); - - sftp_put_filename(ctx, &st, entry->d_name); - - sftp_set_msg(ctx->o, SSH_FXP_NAME ); - return 1; -} - -static int -sftp_process_stat(struct sftp_ctx *ctx) -{ - struct stat st; - struct sftp_attrib a; - - const UINT8 *name; - - if ( ! (name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - if (stat(name, &st ) < 0) - return sftp_send_errno(ctx, errno); - - sftp_attrib_from_stat( &st, &a); - - sftp_set_msg( ctx->o, SSH_FXP_ATTRS ); - sftp_put_attrib( ctx->o, &a); - - return 1; -} - -static int -sftp_process_lstat(struct sftp_ctx *ctx) -{ - struct stat st; - struct sftp_attrib a; - - const UINT8 *name; - - if ( !(name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - if (lstat(name, &st) < 0) - return sftp_send_errno(ctx, errno); - - sftp_attrib_from_stat( &st, &a ); - sftp_set_msg( ctx->o, SSH_FXP_ATTRS ); - - sftp_put_attrib( ctx->o, &a); - - return 1; -} - -/* FIXME: Implement fstat for directories as well. */ -static int -sftp_process_fstat(struct sftp_ctx *ctx) -{ - struct stat st; - struct sftp_attrib a; - int fd; - - if (!sftp_get_handle_fd(ctx, &fd) ) - return sftp_bad_message(ctx); - - - if (fstat(fd, &st ) < 0 ) - return sftp_send_errno(ctx, errno); - - sftp_attrib_from_stat(&st,&a); - sftp_set_msg( ctx->o, SSH_FXP_ATTRS ); - - sftp_put_attrib( ctx->o, &a); - return 1; -} - -static int -sftp_process_fsetstat(struct sftp_ctx *ctx) -{ - struct sftp_attrib a; - int fd; - - if (sftp_get_handle_fd(ctx, &fd) && - sftp_get_attrib(ctx->i, &a)) - { - /* FIXME: What is the right order for doing this? */ - - if ( a.flags & SSH_FILEXFER_ATTR_UIDGID ) - if (fchown(fd, a.uid, a.gid ) < 0 ) - return sftp_send_errno(ctx, errno); - - if ( a.flags & SSH_FILEXFER_ATTR_SIZE ) - if( ftruncate(fd, a.size ) < 0) - return sftp_send_errno(ctx, errno); - - if ( a.flags & SSH_FILEXFER_ATTR_PERMISSIONS ) - if( fchmod(fd, a.permissions ) < 0 ) - return sftp_send_errno(ctx, errno); - - if ( a.flags & (SSH_FILEXFER_ATTR_EXTENDED | SSH_FILEXFER_ATTR_ACMODTIME )) - /* FIXME: how do we? */ - return sftp_send_status(ctx, SSH_FX_OP_UNSUPPORTED ); - - return sftp_send_status(ctx, SSH_FX_OK); - } - else - return sftp_bad_message(ctx); -} - -static int -sftp_process_setstat(struct sftp_ctx *ctx) -{ - struct sftp_attrib a; - - const UINT8 *name; - - if ( !((name = sftp_get_name(ctx->i)) - && sftp_get_attrib(ctx->i, &a) )) - return sftp_bad_message(ctx); - else - { - if ( a.flags & SSH_FILEXFER_ATTR_UIDGID ) - if ( chown(name, a.uid, a.gid ) ) - return sftp_send_errno(ctx, errno); - - if ( a.flags & SSH_FILEXFER_ATTR_SIZE ) - if( truncate(name, a.size ) ) - return sftp_send_errno(ctx, errno); - - if ( a.flags & SSH_FILEXFER_ATTR_PERMISSIONS ) - if( chmod(name, a.permissions ) ) - return sftp_send_errno(ctx, errno); - - if ( a.flags & (SSH_FILEXFER_ATTR_EXTENDED | SSH_FILEXFER_ATTR_ACMODTIME)) - /* FIXME: how do we? */ - return sftp_send_status(ctx, SSH_FX_OP_UNSUPPORTED ); - - return sftp_send_status(ctx, SSH_FX_OK); - } -} - -static int -sftp_process_remove(struct sftp_ctx *ctx) -{ - const UINT8 *name; - - if ( ! (name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - if (unlink(name) < 0) - return sftp_send_errno(ctx, errno); - else - return sftp_send_status(ctx, SSH_FX_OK); -} - -/* NOTE: This request ought to include the desired attributes. */ -static int -sftp_process_mkdir(struct sftp_ctx *ctx) -{ - const UINT8 *name; - - if (! (name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - /* FIXME: default permissions ? */ - if(mkdir(name, 0755) < 0 ) - return sftp_send_errno(ctx, errno); - else - return sftp_send_status(ctx, SSH_FX_OK); -} - -static int -sftp_process_rmdir(struct sftp_ctx *ctx) -{ - const UINT8 *name; - - if (! (name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - if(rmdir(name) < 0) - return sftp_send_errno(ctx, errno); - else - return sftp_send_status(ctx, SSH_FX_OK); -} - -static int -sftp_process_realpath(struct sftp_ctx *ctx) -{ - const UINT8 *name; - UINT8 *resolved; - struct stat st; - int path_max; - - if (! (name = sftp_get_name(ctx->i))) - return sftp_bad_message(ctx); - - /* Code below from the manpage for realpath on my debian system */ - -#ifdef PATH_MAX - path_max = PATH_MAX; -#else - path_max = pathconf (name, _PC_PATH_MAX); - if (path_max <= 0) - path_max = 4096; -#endif - - resolved = realpath(name, alloca(path_max)); - - if (!resolved) - return sftp_send_errno(ctx, errno); - - sftp_put_uint32(ctx->o, 1); /* Count */ - - /* FIXME: The draft says we should return "just one name and dummy - * attributes", but I figure we might as well pass the real attributes, - * if we can get them. */ - - if (lstat(resolved, &st ) < 0) - { - /* Return dummy attributes. */ - sftp_put_string(ctx->o, strlen(resolved), resolved); - - /* Leave the "long name" field empty. */ - sftp_put_uint32(ctx->o, 0); - - /* ATTRS data, containing only a zer flags field. */ - sftp_put_uint32(ctx->o, 0); - } - else - sftp_put_filename(ctx, &st, resolved); - - sftp_set_msg( ctx->o, SSH_FXP_NAME ); - return 1; -} - -static int -sftp_process_rename(struct sftp_ctx *ctx) -{ - const UINT8 *src; - const UINT8 *dst; - - if (! ( (src = sftp_get_name(ctx->i)) - && (dst = sftp_get_name(ctx->i))) ) - return sftp_bad_message(ctx); - - if (rename(src, dst) < 0) - return sftp_send_errno(ctx, errno); - else - return sftp_send_status(ctx, SSH_FX_OK); -} - - -static int -sftp_process_open(struct sftp_ctx *ctx) -{ - const UINT8 *name; - UINT32 pflags; - struct sftp_attrib a; - - if (!((name = sftp_get_name(ctx->i)) - && sftp_get_uint32(ctx->i, &pflags) - && sftp_get_attrib(ctx->i, &a))) - return sftp_bad_message(ctx); - else - { - int fd; - int mode; - struct stat sb; - UINT32 handle; - - switch (pflags & (SSH_FXF_READ | SSH_FXF_WRITE)) - { - case 0: - sftp_send_status(ctx, SSH_FX_FAILURE); - return 1; - case SSH_FXF_READ: - mode = O_RDONLY; - break; - case SSH_FXF_WRITE: - mode = O_WRONLY; - break; - case SSH_FXF_READ | SSH_FXF_WRITE: - mode = O_RDWR; - break; - default: - abort(); - } - if (pflags & SSH_FXF_APPEND) - mode |= O_APPEND; - - if (pflags & SSH_FXF_CREAT) - mode |= O_CREAT; - else if (pflags & SSH_FXF_EXCL) - /* We can't have EXCL without CREAT. */ - sftp_send_status(ctx, SSH_FX_FAILURE); - - if (pflags & SSH_FXF_TRUNC) - mode |= O_TRUNC; - if (pflags & SSH_FXF_EXCL) - mode |= O_EXCL; - - /* Look at the atributes. For now, we care only about the - * permission bits. */ - if (a.flags & SSH_FILEXFER_ATTR_PERMISSIONS) - { - /* Use the client's permission bits with no umask filtering */ - mode_t old = umask(0); - fd = open(name, mode, a.permissions); - umask(old); - } - else - /* Default flags, filtered through our umask */ - fd = open(name, mode, 0666); - - if (fd < 0) - return sftp_send_errno(ctx, errno); - -#if 0 - if (a.flags & SSH_FILEXFER_ATTR_UIDGID) - if ( fchown(fd, a.uid, a.gid) ) - return sftp_send_errno(ctx, errno); -#endif - - if (fstat(fd, &sb) < 0) - { - close(fd); - return sftp_send_errno(ctx, errno); - } - - if (S_ISDIR(sb.st_mode)) - { - close(fd); - return sftp_send_status(ctx, SSH_FX_NO_SUCH_FILE); - } - - if (!sftp_new_handle(ctx, HANDLE_TYPE_FILE, &handle)) - return sftp_send_status(ctx, SSH_FX_FAILURE); - - DEBUG (("sftp_process_open: handle = %d, fd = %d\n", handle, fd)); - - HANDLE_FILE(ctx, handle).fd = fd; - HANDLE_FILE(ctx, handle).position = 0; - - sftp_send_handle(ctx, handle); - return 1; - } -} - - -static int -sftp_process_close(struct sftp_ctx *ctx) -{ - UINT32 handle; - - if (sftp_get_handle(ctx, &handle) ) - { - switch (HANDLE_TYPE(ctx, handle)) - { - case HANDLE_TYPE_FILE: - if (close(HANDLE_FILE(ctx, handle).fd) < 0) - /* FIXME: Should we do something on error ? */ - return sftp_send_errno(ctx, errno); - - break; - - case HANDLE_TYPE_DIRECTORY: - if (closedir(HANDLE_DIR(ctx, handle).dir) < 0) - /* FIXME: Should we do something on error ? */ - return sftp_send_errno(ctx, errno); - - free(HANDLE_DIR(ctx, handle).name); - - break; - - default: - abort(); - } - - HANDLE_TYPE(ctx, handle) = HANDLE_UNUSED; - return sftp_send_status(ctx, SSH_FX_OK); - } - else - return sftp_bad_message(ctx); - - /* FIXME: Should we separate cases bad message and illegal handle - * and return failure for one and bad_message for the other? - */ -} - -#define SFTP_MAX_SIZE 32768 - -static ssize_t -sftp_read(struct sftp_file *f, void *buf, size_t count, off_t offset) -{ - ssize_t done; - - if (offset != f->position) - { -#if HAVE_PREAD - do - done = pread(f->fd, buf, count, offset); - while ( (done < 0) && (errno == EINTR) ); - - return done; -#else /* !HAVE_PREAD */ - - if (lseek(f->fd, offset, SEEK_SET) == (off_t) -1) - return -1; - - f->position = offset; -#endif /* !HAVE_PREAD */ - } - - do /* Plain read */ - done = read(f->fd, buf, count); - while ( (done < 0) && (errno == EINTR) ); - - if (done > 0) - f->position += done; - - return done; -} - -#define BUFFER_SIZE 4096 - -static int -sftp_process_read(struct sftp_ctx *ctx) -{ - struct sftp_file *f; - off_t offset; - UINT32 length; - - if ( !(sftp_get_handle_file(ctx, &f) && - sftp_get_uint64(ctx->i, &offset) && - sftp_get_uint32(ctx->i, &length))) - return sftp_bad_message(ctx); - - /* FIXME: Should we separate cases bad message - and illegal handle and return failure - for one and bad_message for the other? - */ - - /* Check so we are to read at all */ - if (length) - { - size_t done = 0; - int res; - UINT32 index; - - DEBUG (("sftp_process_read: fd = %d\n", f->fd)); - - /* FIXME: Should we really sanity check the length? */ - if (length > SFTP_MAX_SIZE) - length = SFTP_MAX_SIZE; - - index = sftp_put_reserve_length(ctx->o); - - while (length) - { - UINT8 buf[BUFFER_SIZE]; - - res = sftp_read(f, buf, sizeof(buf), offset); - - DEBUG (("sftp_process_read: read => %d\n", res)); - if (res < 0) - { - sftp_put_reset(ctx->o, index); - return sftp_send_errno(ctx, errno); - } - else if (res > 0) - { - sftp_put_data(ctx->o, res, buf); - done += res; - offset += res; - length -= res; - } - else - break; - } - - DEBUG (("sftp_process_read: After read loop, done = %d, left = %d\n", - done, length)); - if (!done) - { - sftp_put_reset(ctx->o, index); - return sftp_send_status( ctx, SSH_FX_EOF ); - } - else - { - sftp_put_final_length(ctx->o, index); - sftp_set_msg( ctx->o, SSH_FXP_DATA ); - return 1; - } - } - /* An empty string */ - sftp_put_uint32(ctx->o, 0); - sftp_set_msg( ctx->o, SSH_FXP_DATA ); - return 1; -} - -static ssize_t -sftp_write(struct sftp_file *f, const void *buf, size_t count, off_t offset) -{ - ssize_t done; - - if (offset != f->position) - { -#if HAVE_PWRITE - do - done = pwrite(f->fd, buf, count, offset); - while ( (done < 0) && (errno == EINTR) ); - - return done; -#else /* !HAVE_PWRITE */ - - if (lseek(f->fd, offset, SEEK_SET) == (off_t) -1) - return -1; - - f->position = offset; -#endif /* !HAVE_PWRITE */ - } - - do /* Plain write */ - done = write(f->fd, buf, count); - while ( (done < 0) && (errno == EINTR) ); - - if (done > 0) - f->position += done; - - return done; -} - -static int -sftp_process_write(struct sftp_ctx *ctx) -{ - struct sftp_file *f; - off_t offset; - size_t done; - - UINT8 *data; - UINT32 length; - - if ( !(sftp_get_handle_file(ctx, &f) - && sftp_get_uint64(ctx->i, &offset) - && (data = sftp_get_string_auto(ctx->i, &length)))) - return sftp_bad_message(ctx); - - /* FIXME: Should we separate cases bad message - and illegal handle and return failure - for one and bad_message for the other? - */ - - /* FIXME: 64-bit support works differently on solaris at least */ - - /* Nothing happens if length is 0 - hence we need no special test */ - - for (done = 0; length; ) - { - int res = sftp_write(f, data + done, length, offset); - - if (res <= 0) - return sftp_send_errno(ctx, errno); - - else if (res > 0) - { - done += res; - offset += res; - length -= res; - } - } - return sftp_send_status(ctx, SSH_FX_OK); -} - - -static void -sftp_process(sftp_process_func **dispatch, - struct sftp_ctx *ctx) -{ - UINT8 msg; - UINT32 id; - - int ok; - - switch (sftp_read_packet(ctx->i)) - { - case 1: - break; - case 0: - exit(EXIT_FAILURE); - case -1: /* EOF */ - exit(EXIT_SUCCESS); - } - - /* All packets start with a msg byte and a 32-bit id. */ - if (!sftp_get_uint8(ctx->i, &msg)) - FATAL("Invalid packet."); - - if (!sftp_get_uint32(ctx->i, &id)) - FATAL("Invalid packet."); - - /* Every reply starts with the id, so copy it through */ - sftp_set_id(ctx->o, id); - - /* Calls FATAL on protocol errors. */ - ok = dispatch[msg](ctx); - - /* Every handler should result in at least one message */ - if (!sftp_write_packet(ctx->o)) - exit(EXIT_FAILURE); - - if (!ok) - exit(EXIT_FAILURE); -} - -/* The handshake packets are special, because they don't include any - * request id. */ -static int -sftp_handshake(struct sftp_ctx *ctx) -{ - UINT8 msg; - UINT32 version; - - DEBUG (("sftp_handshake\n")); - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - DEBUG (("sftp_handshake, read packet\n")); - - if (sftp_get_uint8(ctx->i, &msg) - && (msg == SSH_FXP_INIT) - && sftp_get_uint32(ctx->i, &version)) - { - DEBUG (("sftp_handshake, got version packet\n")); - - while (!sftp_get_eod(ctx->i)) - if (!sftp_skip_extension(ctx->i)) - return 0; - - if (version < SFTP_VERSION) - return 0; - - /* The VERSION message puts the version number where - * the id is usually located. */ - - sftp_set_msg(ctx->o, SSH_FXP_VERSION); - sftp_set_id(ctx->o, SFTP_VERSION); - - return sftp_write_packet(ctx->o); - } - return 0; -} - -static int -parse_options(int argc, char **argv) -{ - int i; - - for (i = 1; i -#include -#include - -#include -#include -#include - -#include - -#define SFTP_XFER_BLOCKSIZE 16384 -#define SFTP_VERSION 3 - -#define FATAL(x) do { fputs("sftp-test-client: " x "\n", stderr); exit(EXIT_FAILURE); } while (0) -#define _FATAL(x) do { fputs("sftp-test-client: " x "\n", stderr); _exit(EXIT_FAILURE); } while (0) - - - - -static UINT32 -sftp_client_new_id(void) -{ - /* Return a new (monotonically increasing) every time */ - static UINT32 curid=0; - return curid++; -} - -static int -sftp_client_get_id(struct sftp_input *i, UINT32 expected) -{ - UINT32 id; - return (sftp_get_uint32(i, &id) - && (id == expected)); -} - -static void -fork_server(char *name, - struct client_ctx *ctx) -{ - /* [0] for reading, [1] for writing */ - int stdin_pipe[2]; - int stdout_pipe[2]; - - if (pipe(stdin_pipe) < 0) - FATAL("Creating stdin_pipe failed."); - - if (pipe(stdout_pipe) < 0) - FATAL("Creating stdout_pipe failed."); - - switch(fork()) - { - case -1: - FATAL("fork failed."); - default: /* Parent */ - { - FILE *i; - FILE *o; - - close(stdin_pipe[0]); - close(stdout_pipe[1]); - - i = fdopen(stdout_pipe[0], "r"); - if (!i) - FATAL("fdopen stdout_pipe failed."); - - o = fdopen(stdin_pipe[1], "w"); - if (!o) - FATAL("fdopen stdin_pipe failed."); - - ctx->i = sftp_make_input(i); - ctx->o = sftp_make_output(o); - - return; - } - case 0: /* Child */ - if (dup2(stdin_pipe[0], STDIN_FILENO) < 0) - _FATAL("dup2 for stdin failed."); - if (dup2(stdout_pipe[1], STDOUT_FILENO) < 0) - _FATAL("dup2 for stdout failed."); - - close(stdin_pipe[0]); - close(stdin_pipe[1]); - close(stdout_pipe[0]); - close(stdout_pipe[1]); - - execl(name, name, NULL); - - _FATAL("execl failed."); - } -} - -/* The handshake packets are special, because they don't include any - * request id. */ -static int -client_handshake(struct client_ctx *ctx) -{ - UINT8 msg; - UINT32 version; - - sftp_set_msg(ctx->o, SSH_FXP_INIT); - sftp_set_id(ctx->o, SFTP_VERSION); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - return (sftp_get_uint8(ctx->i, &msg) - && (msg == SSH_FXP_VERSION) - && sftp_get_uint32(ctx->i, &version) - && (version == SFTP_VERSION) - && sftp_get_eod(ctx->i)); -} - -static int -do_ls(struct client_ctx *ctx, const char *name) -{ - UINT32 id; - UINT32 status; - UINT8* handle; - UINT32 hlength; - - UINT8 msg; - int lsloop=1; - int failure=0; - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_OPENDIR); /* Send a OPENDIR message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, strlen(name), name); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - /* None of these may fail */ - if ( !(sftp_get_uint8(ctx->i, &msg) - && (msg==SSH_FXP_HANDLE) - && sftp_client_get_id(ctx->i, id) - && (handle=sftp_get_string(ctx->i, &hlength)) )) - return 0; - - /* OK, we now have a successfull call and a handle to a directory. */ - - while ( lsloop ) - { - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_READDIR); - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if( !(sftp_get_uint8(ctx->i, &msg) - && sftp_client_get_id(ctx->i, id))) - return 0; - - if ( msg == SSH_FXP_NAME ) - { - UINT32 count; - struct sftp_attrib a; - - sftp_get_uint32(ctx->i, &count ); - - while ( count-- ) - { - UINT8* fname; - UINT32 fnamel; - - UINT8* lname; - UINT32 lnamel; - - sftp_input_clear_strings(ctx->i); - - if (! ( (fname=sftp_get_string_auto(ctx->i, &fnamel)) - && (lname=sftp_get_string_auto(ctx->i, &lnamel)) - && sftp_get_attrib(ctx->i, &a))) - return 0; - - printf("%s\n", lname); - } - } - else - if ( msg == SSH_FXP_STATUS ) - { - sftp_get_uint32(ctx->i, &status); - lsloop=0; /* End of loop - EOF or failue */ - - if ( status != SSH_FX_EOF) - failure=1; - } - } - - /* Time to close */ - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_CLOSE); /* Send a close message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle); - - sftp_free_string(handle); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - return (sftp_get_uint8(ctx->i, &msg) - && (msg==SSH_FXP_STATUS) - && sftp_client_get_id(ctx->i, id) - && sftp_get_uint32(ctx->i, &status) - && (status == SSH_FX_OK) - && !failure); -} - -static UINT8 * -do_open(struct client_ctx *ctx, - const char *name, - UINT32 flags, - const struct sftp_attrib *a, - UINT32 *handle_length) -{ - UINT8 msg; - UINT32 id = sftp_client_new_id(); - - /* Send a OPEN message */ - sftp_set_msg(ctx->o, SSH_FXP_OPEN); - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, strlen(name), name ); - sftp_put_uint32(ctx->o, flags); - sftp_put_attrib(ctx->o, a); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - /* None of these may fail */ - return (sftp_get_uint8(ctx->i, &msg) - && (msg==SSH_FXP_HANDLE) - && sftp_client_get_id(ctx->i, id)) - ? sftp_get_string(ctx->i, handle_length) - : NULL; -} - -static int -do_close(struct client_ctx *ctx, - UINT32 handle_length, - const UINT8 *handle) -{ - UINT8 msg; - UINT32 status; - - UINT32 id = sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_CLOSE); /* Send a close message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, handle_length, handle); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - /* None of these may fail */ - return (sftp_get_uint8(ctx->i, &msg) - && (msg==SSH_FXP_STATUS) - && sftp_client_get_id(ctx->i, id) - && sftp_get_uint32(ctx->i, &status) - && (status == SSH_FX_OK)); -} - -static int -do_get(struct client_ctx *ctx, - const char *name, - int dst) -{ - UINT32 id; - UINT8* handle; - UINT32 handle_length; - UINT32 status; - - off_t curpos=0; - - struct sftp_attrib a; - - UINT8 msg; - int getloop=1; - int ok = 1; - - sftp_clear_attrib(&a); /* Don't pass any information on how to open */ - - if (! (handle = do_open(ctx, name, SSH_FXF_READ, &a, &handle_length))) - return 0; - - /* OK, we now have a successfull call and file handle */ - - id=sftp_client_new_id(); - - while ( getloop ) - { - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_READ); /* Send a read request */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, handle_length, handle); - sftp_put_uint64(ctx->o, curpos); - sftp_put_uint32(ctx->o, SFTP_XFER_BLOCKSIZE); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if( !(sftp_get_uint8(ctx->i, &msg) - && sftp_client_get_id(ctx->i, id))) - return 0; - - switch (msg) - { - case SSH_FXP_DATA: - { - UINT8 *data; - UINT32 length; - - data = sftp_get_string_auto(ctx->i, &length); - curpos += length; - - while (length) - { - int res; - do - res = write(dst, data, length); - while ( (res < 0) && (errno = EINTR) ); - if (res < 0) - { - getloop=0; - ok=0; - break; - } - data +=res; - length -= res; - } - break; - } - case SSH_FXP_STATUS: - { - sftp_get_uint32(ctx->i, &status); - getloop=0; /* End of loop - EOF or failue */ - - if ( status != SSH_FX_EOF) - ok=0; - - break; - } - default: - return 0; - } - } - - /* Time to close */ - - if (!do_close(ctx, handle_length, handle)) - ok = 0; - - sftp_free_string(handle); - - return ok; -} - -#if 0 -static int -do_get(struct client_ctx *ctx, - const char *lname, - const char *rname, - int cont, - off_t contat) -{ - UINT32 id; - UINT32 status; - UINT8* handle; - UINT32 hlength; - - off_t curpos=0; - UINT32 rdatal; - UINT8* rdata; - - struct sftp_attrib a; - - UINT8 msg; - int getloop=1; - int failure=0; - int fd=-1; - - id=sftp_client_new_id(); - - sftp_clear_attrib(&a); /* Don't pass any information on how to open */ - - sftp_set_msg(ctx->o, SSH_FXP_OPEN); /* Send a OPEN message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, strlen(rname), rname ); - sftp_put_uint32(ctx->o, SSH_FXF_READ ); /* Read mode only */ - sftp_put_attrib(ctx->o, &a); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( !(sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_HANDLE && - sftp_client_get_id(ctx->i, id) && - (handle=sftp_get_string(ctx->i, &hlength)) - )) - return 0; - - /* OK, we now have a successfull call and file handle */ - - id=sftp_client_new_id(); - sftp_set_msg(ctx->o, SSH_FXP_FSTAT); /* Send a FSTAT message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle ); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( !(sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_ATTRS && - sftp_client_get_id(ctx->i, id) && - sftp_get_attrib(ctx->i, &a) - )) - { - getloop=0; /* fstat failed - skip the loop */ - failure=1; /* failure (but we still need to close the file */ - } - else - { - int openmode=0666; /* Default mode for open if server doesn't say - otherwise */ - - if ( a.flags & SSH_FILEXFER_ATTR_PERMISSIONS ) - openmode=a.permissions & 0777; - - if ( (fd=open( lname, O_CREAT | O_WRONLY, openmode )) < 0 ) - { - getloop=0; /* Couldn't open local file - skip loop */ - failure=1; - } - - if ( !cont ) /* Continue an old transfer */ - curpos=0; - else - { - if ( contat ) /* Position to continue at given? */ - curpos=contat; - else - { - struct stat st; - - if ( ! fstat(fd, &st ) ) /* Stat local file */ - { - /* Failed (Fixme; is it plausible that the fstat fails but the - rest works?) */ - failure=1; - getloop=0; - } - else - curpos=st.st_size; /* Continue at end of local file */ - } - } - - } - - while ( getloop ) - { - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_READ); /* Send a read request */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle); - sftp_put_uint64(ctx->o, curpos); - sftp_put_uint32(ctx->o, SFTP_XFER_BLOCKSIZE); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - - if( !(sftp_get_uint8(ctx->i, &msg) && - sftp_client_get_id(ctx->i, id) - )) - return 0; - - if ( msg == SSH_FXP_DATA ) - { - rdata=sftp_get_string_auto(ctx->i, &rdatal); - /* Fixme; display this somehow */ - - if ( ( -1 == lseek(fd,curpos, SEEK_SET) ) || - ( -1 == write(fd,rdata,rdatal) ) ) - { - getloop=0; - failure=1; - } - else - curpos+=rdatal; - - } - else - if ( msg == SSH_FXP_STATUS ) - { - sftp_get_uint32(ctx->i, &status); - getloop=0; /* End of loop - EOF or failue */ - - if ( status != SSH_FX_EOF) - failure=1; - } - } - - /* Time to close */ - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_CLOSE); /* Send a close message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle); - - sftp_free_string(handle); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( fd >= 0 && close(fd) ) - failure=1; - - if ( !( - sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_STATUS && - sftp_client_get_id(ctx->i, id) && - sftp_get_uint32(ctx->i, &status) && - status == SSH_FX_OK && - !failure - )) - return 0; - - return 1; - -} -#endif - -static int -do_put(struct client_ctx *ctx, - const char *name, - int fd) -{ - UINT32 id; - UINT32 status; - UINT8* handle; - UINT32 handle_length; - off_t curpos=0; - - struct sftp_attrib a; - - UINT8 msg; - int putloop=1; - int ok = 1; - - sftp_clear_attrib(&a); - - a.flags = 0; - - if (! (handle = do_open(ctx, name, SSH_FXF_CREAT | SSH_FXF_WRITE, &a, - &handle_length))) - return 0; - - /* OK, we now have a successfull call and file handle */ - - while ( putloop ) - { - UINT8 buf[SFTP_XFER_BLOCKSIZE]; - int res; - - do - res = read(fd, buf, sizeof(buf)); - while ( (res < 0) && (errno == EINTR) ); - - if (res < 0) - { - putloop=0; - ok = 0; - break; - } - - if ( !res ) - putloop=0; - else - { - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_WRITE); /* Send a read request */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, handle_length, handle); - sftp_put_uint64(ctx->o, curpos); - sftp_put_string(ctx->o, res, buf); - - if (!sftp_write_packet(ctx->o)) - return 0; - - curpos += res; - - if (!sftp_read_packet(ctx->i)) - return 0; - - if( !(sftp_get_uint8(ctx->i, &msg) - && sftp_client_get_id(ctx->i, id))) - return 0; - - if ( msg == SSH_FXP_STATUS ) - { - sftp_get_uint32(ctx->i, &status); - putloop=0; /* End of loop - EOF or failue */ - - if ( status != SSH_FX_OK ) - ok = 0; - } - } - } - - /* Time to close */ - - if (!do_close(ctx, handle_length, handle)) - ok = 0; - - sftp_free_string(handle); - - return ok; -} - -#if 0 -static int -do_put(struct client_ctx *ctx, - const char *lname, - const char *rname, - int cont, - off_t contat) -{ - UINT32 id; - UINT32 status; - UINT8* handle; - UINT32 hlength; - off_t curpos=0; - UINT8* wdata; - ssize_t rbytes; - - struct stat st; - struct sftp_attrib a; - - UINT8 msg; - int putloop=1; - int failure=0; - int fd=-1; - - sftp_clear_attrib(&a); - - if ( ((fd=open( lname, O_RDONLY)) < 0) || - fstat(fd, &st) ) - return 0; /* Open or stat failed */ - - wdata=xmalloc(SFTP_XFER_BLOCKSIZE); - - a.flags= ( SSH_FILEXFER_ATTR_PERMISSIONS | - SSH_FILEXFER_ATTR_UIDGID ); /* Fixme; what should we pass? */ - - a.permissions=st.st_mode & 0777; /* Fixme; Macro for 0777? */ - a.uid=st.st_uid; - a.gid=st.st_gid; - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_OPEN); /* Send a OPEN message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, strlen(rname), rname ); - sftp_put_uint32(ctx->o, SSH_FXF_CREAT | SSH_FXF_WRITE ); - sftp_put_attrib(ctx->o, &a); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( !( - sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_HANDLE && - sftp_client_get_id(ctx->i, id) && - (handle=sftp_get_string(ctx->i, &hlength)) - )) - return 0; - - /* OK, we now have a successfull call and file handle */ - - id=sftp_client_new_id(); - sftp_set_msg(ctx->o, SSH_FXP_FSTAT); /* Send a FSTAT message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle ); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( !( - sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_ATTRS && - sftp_client_get_id(ctx->i, id) && - sftp_get_attrib(ctx->i, &a) - )) - { - putloop=0; /* fstat failed - skip the loop */ - failure=1; /* failure (but we still need to close the file) */ - } - - - if ( !cont ) /* Continue an old transfer? */ - curpos=0; - else - { - if ( contat ) /* Position to continue at given? */ - curpos=contat; - else - { - if ( a.flags & SSH_FILEXFER_ATTR_SIZE ) - curpos=a.size; - /* Continue at end of remote file */ - } - } - - while ( putloop ) - { - if ( - (-1 == ( lseek(fd, curpos ,SEEK_SET) ) ) || - (-1 == (rbytes=read(fd, wdata, SFTP_XFER_BLOCKSIZE )) ) - ) - { - putloop=0; - failure=1; - break; - } - - if ( !rbytes ) - putloop=0; - else - { - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_WRITE); /* Send a read request */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle); - sftp_put_uint64(ctx->o, curpos); - sftp_put_string(ctx->o, rbytes, wdata); - - if (!sftp_write_packet(ctx->o)) - return 0; - - curpos+=rbytes; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - - if( !( - sftp_get_uint8(ctx->i, &msg) && - sftp_client_get_id(ctx->i, id) - )) - return 0; - - if ( msg == SSH_FXP_STATUS ) - { - sftp_get_uint32(ctx->i, &status); - putloop=0; /* End of loop - EOF or failue */ - - if ( status != SSH_FX_OK ) - failure=1; - } - } - } - /* Time to close */ - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_CLOSE); /* Send a close message */ - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, hlength, handle); - - sftp_free_string(handle); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( fd >= 0 && close(fd) ) - failure=1; - - free(wdata); - - if ( !( - sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_STATUS && - sftp_client_get_id(ctx->i, id) && - sftp_get_uint32(ctx->i, &status) && - status == SSH_FX_OK && - !failure - )) - return 0; - - return 1; - -} -#endif - -static int -do_stat(struct client_ctx *ctx, const char *name) -{ - UINT32 id; - UINT8 msg; - struct sftp_attrib a; - - id=sftp_client_new_id(); - - sftp_set_msg(ctx->o, SSH_FXP_STAT); - sftp_set_id(ctx->o, id); - sftp_put_string(ctx->o, strlen(name), name); - - if (!sftp_write_packet(ctx->o)) - return 0; - - if (sftp_read_packet(ctx->i) <= 0) - return 0; - - if ( !(sftp_get_uint8(ctx->i, &msg) && /* None of these may fail */ - msg==SSH_FXP_ATTRS && - sftp_client_get_id(ctx->i, id) && - sftp_get_attrib(ctx->i, &a) - )) - return 0; - - /* Fixme; return this somehow */ - printf("Stat succeeded\n"); - - return 1; -} - -const char *werror_program_name = "sftp-test-client"; - -int -main(int argc, char **argv) -{ - struct client_ctx ctx; - int i; - - if (argc < 2) - FATAL("Too few args."); - - fork_server(argv[1], &ctx); - - if (!client_handshake(&ctx)) - FATAL("Handshake failed."); - - for (i = 2; i < argc; i += 2) - { - int res; - switch (argv[i][0]) - { - case 'l': /* ls */ - /* Depends on argv[argc] == NULL */ - res = do_ls(&ctx, argv[i+1]); - break; - case 'g': /* get */ - res = do_get(&ctx, argv[i+1], STDOUT_FILENO); - break; - case 'p': - res = do_put(&ctx, argv[i+1], STDIN_FILENO); - break; - case 's': - res = do_stat(&ctx, argv[i+1]); - break; - default: - FATAL("Bad arg"); - } - if (!res) - exit(EXIT_FAILURE); - } - - return EXIT_SUCCESS; -} diff --git a/lsh/src/sftp/sftp.h b/lsh/src/sftp/sftp.h deleted file mode 100644 index 4e9da4c..0000000 --- a/lsh/src/sftp/sftp.h +++ /dev/null @@ -1,70 +0,0 @@ -/* sftp.h - */ - -#ifndef SFTP_SFTP_H_INCLUDED -#define SFTP_SFTP_H_INCLUDED - -/* Messages */ -enum sftp_msg_type { - SSH_FXP_INIT = 1, /* 0x01 */ - SSH_FXP_VERSION = 2, /* 0x02 */ - SSH_FXP_OPEN = 3, /* 0x03 */ - SSH_FXP_CLOSE = 4, /* 0x04 */ - SSH_FXP_READ = 5, /* 0x05 */ - SSH_FXP_WRITE = 6, /* 0x06 */ - SSH_FXP_LSTAT = 7, /* 0x07 */ - SSH_FXP_FSTAT = 8, /* 0x08 */ - SSH_FXP_SETSTAT = 9, /* 0x09 */ - SSH_FXP_FSETSTAT = 10, /* 0x0a */ - SSH_FXP_OPENDIR = 11, /* 0x0b */ - SSH_FXP_READDIR = 12, /* 0x0c */ - SSH_FXP_REMOVE = 13, /* 0x0d */ - SSH_FXP_MKDIR = 14, /* 0x0e */ - SSH_FXP_RMDIR = 15, /* 0x0f */ - SSH_FXP_REALPATH = 16, /* 0x10 */ - SSH_FXP_STAT = 17, /* 0x11 */ - SSH_FXP_RENAME = 18, /* 0x12 */ - SSH_FXP_STATUS = 101, /* 0x65 */ - SSH_FXP_HANDLE = 102, /* 0x66 */ - SSH_FXP_DATA = 103, /* 0x67 */ - SSH_FXP_NAME = 104, /* 0x68 */ - SSH_FXP_ATTRS = 105, /* 0x69 */ - SSH_FXP_EXTENDED = 200, /* 0xc8 */ - SSH_FXP_EXTENDED_REPLY = 201, /* 0xc9 */ -}; - -/* Attribute flags */ -enum sftp_attr_flag { - SSH_FILEXFER_ATTR_SIZE = 0x00000001, - SSH_FILEXFER_ATTR_UIDGID = 0x00000002, - SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004, - SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008, - SSH_FILEXFER_ATTR_EXTENDED = 0x80000000, -}; - -/* Open flags */ -enum sftp_open_flag { - SSH_FXF_READ = 0x00000001, - SSH_FXF_WRITE = 0x00000002, - SSH_FXF_APPEND = 0x00000004, - SSH_FXF_CREAT = 0x00000008, - SSH_FXF_TRUNC = 0x00000010, - SSH_FXF_EXCL = 0x00000020, -}; - -/* Status codes */ -enum sftp_status { - SSH_FX_OK = 0, - SSH_FX_EOF = 1, - SSH_FX_NO_SUCH_FILE = 2, - SSH_FX_PERMISSION_DENIED = 3, - SSH_FX_FAILURE = 4, - SSH_FX_BAD_MESSAGE = 5, -#if 0 - SSH_FX_NO_CONNECTION = 6, - SSH_FX_CONNECTION_LOST = 7, -#endif - SSH_FX_OP_UNSUPPORTED = 8, -}; - -#endif /* SFTP_SFTP_H_INCLUDED */ diff --git a/lsh/src/sftp/stamp-h.in b/lsh/src/sftp/stamp-h.in deleted file mode 100644 index 9788f70..0000000 --- a/lsh/src/sftp/stamp-h.in +++ /dev/null @@ -1 +0,0 @@ -timestamp diff --git a/lsh/src/sftp/testsuite/Makefile.am b/lsh/src/sftp/testsuite/Makefile.am deleted file mode 100644 index 8f4faef..0000000 --- a/lsh/src/sftp/testsuite/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -TS_SH = connect-test get-1-test ls-1-test ls-2-test put-1-test - -EXTRA_DIST = common.sh run-tests \ - setup-env teardown-env \ - $(TS_SH) - -# I thought srcdir was exported automatically? -check: - srcdir="$(srcdir)" $(srcdir)/run-tests $(TS_SH) diff --git a/lsh/src/sftp/testsuite/Makefile.in b/lsh/src/sftp/testsuite/Makefile.in deleted file mode 100644 index 87a381b..0000000 --- a/lsh/src/sftp/testsuite/Makefile.in +++ /dev/null @@ -1,175 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = .. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -VERSION = @VERSION@ - -TS_SH = connect-test get-1-test ls-1-test ls-2-test put-1-test - -EXTRA_DIST = common.sh run-tests setup-env teardown-env $(TS_SH) - -mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs -CONFIG_HEADER = ../config.h -CONFIG_CLEAN_FILES = -DIST_COMMON = Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -all: all-redirect -.SUFFIXES: -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps testsuite/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -tags: TAGS -TAGS: - - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = testsuite - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: tags distdir info-am info dvi-am dvi check check-am \ -installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -# I thought srcdir was exported automatically? -check: - srcdir="$(srcdir)" $(srcdir)/run-tests $(TS_SH) - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/sftp/testsuite/common.sh b/lsh/src/sftp/testsuite/common.sh deleted file mode 100644 index af49f5c..0000000 --- a/lsh/src/sftp/testsuite/common.sh +++ /dev/null @@ -1,21 +0,0 @@ -# Common stuff for all test scripts. - -set -e - -TESTHOME=home -export TESTHOME - -# We need an absolute path. -PROGRAMDIR=`cd .. && pwd` -export PROGRAMDIR - -if [ -n "$SFTP_DEBUG" ] ; then - SERVER=debug-server -else - SERVER=sftp-server -fi - -client () { - (cd $TESTHOME && "$PROGRAMDIR"/sftp-test-client "$PROGRAMDIR"/"$SERVER" "$@") -} - diff --git a/lsh/src/sftp/testsuite/connect-test b/lsh/src/sftp/testsuite/connect-test deleted file mode 100644 index 0b69278..0000000 --- a/lsh/src/sftp/testsuite/connect-test +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -client diff --git a/lsh/src/sftp/testsuite/get-1-test b/lsh/src/sftp/testsuite/get-1-test deleted file mode 100644 index c64e788..0000000 --- a/lsh/src/sftp/testsuite/get-1-test +++ /dev/null @@ -1,11 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -client get "x1" | grep -q foo - - diff --git a/lsh/src/sftp/testsuite/ls-1-test b/lsh/src/sftp/testsuite/ls-1-test deleted file mode 100644 index d9ce63d..0000000 --- a/lsh/src/sftp/testsuite/ls-1-test +++ /dev/null @@ -1,11 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -# Match the d directory -client ls "" | grep -q '^d.* d$' - diff --git a/lsh/src/sftp/testsuite/ls-2-test b/lsh/src/sftp/testsuite/ls-2-test deleted file mode 100644 index baca3aa..0000000 --- a/lsh/src/sftp/testsuite/ls-2-test +++ /dev/null @@ -1,11 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -# Match the d directory -client ls "d" | grep -q ' x3$' - diff --git a/lsh/src/sftp/testsuite/put-1-test b/lsh/src/sftp/testsuite/put-1-test deleted file mode 100644 index 435f273..0000000 --- a/lsh/src/sftp/testsuite/put-1-test +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -rm -f "$TESTHOME/d/new" -echo data | client put "d/new" && \ - [ -r "$TESTHOME/d/new" ] && grep -q data "$TESTHOME/d/new" - - - diff --git a/lsh/src/sftp/testsuite/run-tests b/lsh/src/sftp/testsuite/run-tests deleted file mode 100644 index 46f454c..0000000 --- a/lsh/src/sftp/testsuite/run-tests +++ /dev/null @@ -1,50 +0,0 @@ -#! /bin/bash - -failed=0 -all=0 - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -env_program () { - if [ -x "$srcdir/$1" ] ; then - if "$srcdir/$1"; then : ; else - echo FAIL: $1 - exit 1 - fi - fi -} - -test_program () { - if "$srcdir/$1" ; then - echo PASS: ${1%-test} - else - echo FAIL: ${1%-test} - failed=`expr $failed + 1` - fi - all=`expr $all + 1` -} - -env_program setup-env - -if [ $# -eq 0 ] ; then - for f in `cd $srcdir && echo *-test`; do test_program "$f"; done -else - for f in "$@" ; do test_program "$f"; done -fi - -if [ $failed -eq 0 ] ; then - banner="All $all tests passed" -else - banner="$failed of $all tests failed" -fi -dashes=`echo "$banner" | sed s/./=/g` -echo "$dashes" -echo "$banner" -echo "$dashes" - -env_program teardown-env - -[ "$failed" -eq 0 ] - diff --git a/lsh/src/sftp/testsuite/setup-env b/lsh/src/sftp/testsuite/setup-env deleted file mode 100644 index 29e83bd..0000000 --- a/lsh/src/sftp/testsuite/setup-env +++ /dev/null @@ -1,21 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -# Clean up first. -rm -rf $TESTHOME - -# Create a directory to play with -mkdir $TESTHOME -cd $TESTHOME - -# Create some files -echo foo >x1 -echo bar >x2 - -mkdir d -echo gazonk >d/x3 diff --git a/lsh/src/sftp/testsuite/teardown-env b/lsh/src/sftp/testsuite/teardown-env deleted file mode 100644 index bb736fd..0000000 --- a/lsh/src/sftp/testsuite/teardown-env +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh - -if [ -z "$srcdir" ] ; then - srcdir=. -fi - -. $srcdir/common.sh - -rm -rf $TESTHOME diff --git a/lsh/src/sftp/werror.c b/lsh/src/sftp/werror.c deleted file mode 100644 index af69c57..0000000 --- a/lsh/src/sftp/werror.c +++ /dev/null @@ -1,40 +0,0 @@ -/* werror.c - * - * Simple diagnostics routines. - * - * $id$ - */ - -#include "werror.h" - -#include -#include -#include - -void -werror(const char *format, ...) -{ - va_list args; - - va_start(args, format); - - fprintf(stderr, "%s: ", werror_program_name); - vfprintf(stderr, format, args); - - va_end(args); -} - -void -fatal(const char *format, ...) -{ - va_list args; - - va_start(args, format); - - fprintf(stderr, "%s: ", werror_program_name); - vfprintf(stderr, format, args); - - va_end(args); - - exit(EXIT_FAILURE); -} diff --git a/lsh/src/sftp/werror.h b/lsh/src/sftp/werror.h deleted file mode 100644 index 892aa3e..0000000 --- a/lsh/src/sftp/werror.h +++ /dev/null @@ -1,20 +0,0 @@ -/* werror.h - * - * Simple diagnostics routines. - * - * $id$ - */ - -#ifndef SFTP_WERROR_H_INCLUDED -#define SFTP_WERROR_H_INCLUDED - -/* For types and config stuff */ -#include "buffer.h" - -extern const char *werror_program_name; - -void werror(const char *format, ...) PRINTF_STYLE(1,2); -void fatal(const char *format, ...) PRINTF_STYLE(1,2) NORETURN; - -#endif /* SFTP_WERROR_H_INCLUDED */ - diff --git a/lsh/src/sftp/xmalloc.c b/lsh/src/sftp/xmalloc.c deleted file mode 100644 index 8315786..0000000 --- a/lsh/src/sftp/xmalloc.c +++ /dev/null @@ -1,41 +0,0 @@ -/* xmalloc.c - */ - -#include "xmalloc.h" - -#include - -void * -xmalloc(size_t size) -{ - void *p = malloc(size); - if (!p) - { - fprintf(stderr, "Virtual memory exhausted\n"); - abort(); - } - return p; -} - -char * -xstrdup(const char *s) -{ - size_t length = strlen(s); - char *p = xmalloc(length + 1); - memcpy(p, s, length); - p[length] = '\0'; - - return p; -} - -void * -xrealloc(void *old, size_t size) -{ - void *p = realloc(old, size); - if (!p) - { - fprintf(stderr, "Virtual memory exhausted\n"); - abort(); - } - return p; -} diff --git a/lsh/src/sftp/xmalloc.h b/lsh/src/sftp/xmalloc.h deleted file mode 100644 index b6e6150..0000000 --- a/lsh/src/sftp/xmalloc.h +++ /dev/null @@ -1,18 +0,0 @@ -/* xmalloc.h - */ - -#ifndef SFTP_XMALLOC_H_INCLUDED -#define SFTP_XMALLOC_H_INCLUDED - -#include - -void * -xmalloc(size_t size); - -char * -xstrdup(const char *s); - -void * -xrealloc(void *old, size_t size); - -#endif /* SFTP_XMALLOC_H_INCLUDED */ diff --git a/lsh/src/sha.c b/lsh/src/sha.c deleted file mode 100755 index 1523e93..0000000 --- a/lsh/src/sha.c +++ /dev/null @@ -1,86 +0,0 @@ -/* sha.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "xalloc.h" - -#include "nettle/sha1.h" - -#include "sha.c.x" - - -/* SHA1 hash */ -/* GABA: - (class - (name sha_instance) - (super hash_instance) - (vars - (ctx . "struct sha1_ctx"))) -*/ - -static void -do_sha_update(struct hash_instance *s, - UINT32 length, const UINT8 *data) -{ - CAST(sha_instance, self, s); - - sha1_update(&self->ctx, length, data); -} - -static void -do_sha_digest(struct hash_instance *s, - UINT8 *dst) -{ - CAST(sha_instance, self, s); - - sha1_final(&self->ctx); - sha1_digest(&self->ctx, SHA1_DIGEST_SIZE, dst); - sha1_init(&self->ctx); -} - -static struct hash_instance * -do_sha_copy(struct hash_instance *s) -{ - return &CLONE(sha_instance, s)->super; -} - -static struct hash_instance * -make_sha_instance(struct hash_algorithm *ignored UNUSED) -{ - NEW(sha_instance, res); - - res->super.hash_size = SHA1_DIGEST_SIZE; - res->super.update = do_sha_update; - res->super.digest = do_sha_digest; - res->super.copy = do_sha_copy; - - sha1_init(&res->ctx); - - return &res->super; -} - -struct hash_algorithm sha1_algorithm = -{ STATIC_HEADER, - SHA1_DATA_SIZE, SHA1_DIGEST_SIZE, make_sha_instance }; - diff --git a/lsh/src/sha.c.x b/lsh/src/sha.c.x deleted file mode 100755 index 66b0973..0000000 Binary files a/lsh/src/sha.c.x and /dev/null differ diff --git a/lsh/src/spki.c b/lsh/src/spki.c deleted file mode 100755 index 61067ee..0000000 --- a/lsh/src/spki.c +++ /dev/null @@ -1,905 +0,0 @@ -/* spki.c - * - * An implementation of SPKI certificate checking - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "spki.h" - -#include "atoms.h" -#include "crypto.h" -#include "format.h" -#include "io.h" -#include "list.h" -#include "parse.h" -#include "publickey_crypto.h" -#include "sexp.h" -#include "werror.h" -#include "xalloc.h" -#include "alist.h" - -#include -#include - -#define GABA_DEFINE -#include "spki.h.x" -#undef GABA_DEFINE - -#include "spki.c.x" - -#define SA(x) sexp_a(ATOM_##x) - -struct exception * -make_spki_exception(UINT32 type, const char *msg, struct sexp *expr) -{ - NEW(spki_exception, self); - assert(type & EXC_SPKI); - - self->super.type = type; - self->super.msg = msg; - self->expr = expr; - - return &self->super; -} - -/* FIXME: This should create different tags for hostnames that are not - * dns fqdn:s. */ - -struct sexp * -make_ssh_hostkey_tag(struct address_info *host) -{ - UINT32 left = host->ip->length; - UINT8 *s = host->ip->data; - - struct lsh_string *reversed = lsh_string_alloc(left); - - /* First, transform "foo.lysator.liu.se" into "se.liu.lysator.foo" */ - while (left) - { - UINT8 *p = memchr(s, '.', left); - if (!p) - { - memcpy(reversed->data, s, left); - break; - } - else - { - UINT32 segment = p - s; - left -= segment; - - memcpy(reversed->data + left, s, segment); - reversed->data[--left] = '.'; - s = p+1; - } - } - - return sexp_l(2, sexp_z("ssh-hostkey"), - sexp_s(NULL, reversed), - -1); -} - - -struct verifier * -spki_make_verifier(struct alist *algorithms, - struct sexp *e) -{ - /* Syntax: ( *) */ - struct signature_algorithm *algorithm; - struct verifier *v; - int algorithm_name; - struct sexp_iterator *i; - - algorithm_name = spki_get_type(e, &i); - - { - CAST_SUBTYPE(signature_algorithm, a, - ALIST_GET(algorithms, algorithm_name)); - algorithm = a; - } - - if (!algorithm) - { - werror("spki_make_verifier: Unsupported algorithm %a.\n", algorithm_name); - return NULL; - } - - v = MAKE_VERIFIER(algorithm, i); - KILL(i); - - if (!v) - { - werror("spki_make_verifier: Invalid public-key data.\n"); - return NULL; - } - - return v; -} - - -/* Returns the algorithm type, or zero on error. */ -struct signer * -spki_make_signer(struct alist *algorithms, - struct sexp *e, - int *type) -{ - /* Syntax: ( *) */ - struct signature_algorithm *algorithm; - struct signer *s; - int algorithm_name; - struct sexp_iterator *i; - - algorithm_name = spki_get_type(e, &i); - - if (!algorithm_name) - return NULL; - - { - CAST_SUBTYPE(signature_algorithm, a, - ALIST_GET(algorithms, algorithm_name)); - algorithm = a; - } - - if (!algorithm) - { - werror("spki_make_signer: Unsupported algorithm %a.\n", algorithm_name); - return NULL; - } - - s = MAKE_SIGNER(algorithm, i); - KILL(i); - - if (!s) - { - werror("spki_make_signer: Invalid public-key data.\n"); - return NULL; - } - - if (type) - *type = algorithm_name; - - return s; -} - -struct sexp * -spki_make_public_key(struct verifier *verifier) -{ - return sexp_l(2, SA(PUBLIC_KEY), - PUBLIC_SPKI_KEY(verifier), -1); -} - -/* Returns 0 or an atom */ -int -spki_get_type(struct sexp *e, struct sexp_iterator **res) -{ - struct sexp_iterator *i; - int type; - - if (sexp_atomp(e) || sexp_nullp(e)) - return 0; - - i = SEXP_ITER(e); - - type = sexp2atom(SEXP_GET(i)); - if (type && res) - { - SEXP_NEXT(i); - *res = i; - } - else - KILL(i); - - return type; -} - -struct sexp * -spki_hash_data(struct hash_algorithm *algorithm, - int algorithm_name, - UINT32 length, UINT8 *data) -{ - struct hash_instance *hash = MAKE_HASH(algorithm); - struct lsh_string *out = lsh_string_alloc(hash->hash_size); - - HASH_UPDATE(hash, length, data); - HASH_DIGEST(hash, out->data); - - return sexp_l(3, - SA(HASH), - sexp_a(algorithm_name), - sexp_s(NULL, out), -1); -} - - -/* 5-tuples */ - -struct spki_subject * -make_spki_subject(struct sexp *key, - struct verifier *verifier, - struct lsh_string *sha1, - struct lsh_string *md5) -{ - NEW(spki_subject, self); - self->key = key; - self->verifier = verifier; - self->sha1 = sha1; - self->md5 = md5; - - return self; -} - -static int -subject_match_hash(struct spki_subject *self, - int method, - const struct lsh_string *h1) -{ - struct lsh_string *h2; - - switch (method) - { - case ATOM_SHA1: - if (self->sha1) - h2 = self->sha1; -#if 0 - else if (self->key) - h2 = self->sha1 - = hash_string(&sha1_algorithm, - sexp_format(self->key, SEXP_CANONICAL, 0), 1); -#endif - else - return 0; - break; - - case ATOM_MD5: - if (self->md5) - h2 = self->md5; -#if 0 - else if (self->key) - h2 = self->md5 - = hash_string(&md5_algorithm, - sexp_format(self->key, SEXP_CANONICAL, 0), 1); -#endif - else - return 0; - break; - - default: - return 0; - } - return lsh_string_eq(h1, h2); -} - -struct spki_5_tuple * -make_spki_5_tuple(struct spki_subject *issuer, - struct spki_subject *subject, - int propagate, - struct spki_tag *authorization, - int before_limit, time_t not_before, - int after_limit, time_t not_after) -{ - NEW(spki_5_tuple, self); - self->issuer = issuer; - self->subject = subject; - self->propagate = propagate; - self->authorization = authorization; - self->validity.before_limit = before_limit; - self->validity.not_before = not_before; - self->validity.after_limit = after_limit; - self->validity.not_after = not_after; - - return self; -} - - -/* Sets of authorizations, representing the (tag ...) expressions in - * acl:s and certificates. */ - -/* An authorization represented as a string (optionally with display - * type). */ - -/* GABA: - (class - (name spki_tag_atom) - (super spki_tag) - (vars - (resource object sexp))) -*/ - -static int -do_spki_tag_atom_match(struct spki_tag *s, - struct sexp *e) -{ - CAST(spki_tag_atom, self, s); - - assert(sexp_atomp(self->resource)); - - return sexp_atomp(e) - && sexp_atoms_eq(self->resource, e); -} - -static struct spki_tag * -make_spki_tag_atom(struct sexp *resource) -{ - NEW(spki_tag_atom, self); - - assert(sexp_atomp(resource)); - - self->super.type = SPKI_TAG_ATOM; - self->super.match = do_spki_tag_atom_match; - - self->resource = resource; - - return &self->super; -} - - -/* An authorization represented as a list. Includes all authorizations - * that for which a prefix matches the list. */ - -/* GABA: - (class - (name spki_tag_list) - (super spki_tag) - (vars - (list object object_list))) -*/ - -static int -do_spki_tag_list_match(struct spki_tag *s, - struct sexp *e) -{ - CAST(spki_tag_list, self, s); - unsigned i; - struct sexp_iterator *j; - - if (sexp_atomp(e)) - return 0; - - for (i = 0, j = SEXP_ITER(e); - ilist); - i++, SEXP_NEXT(j)) - { - CAST_SUBTYPE(spki_tag, tag, LIST(self->list)[i]); - struct sexp *o = SEXP_GET(j); - - if (! (o && SPKI_TAG_MATCH(tag, o))) - return 0; - } - - return 1; -} - -static struct spki_tag * -make_spki_tag_list(struct object_list *list) -{ - NEW(spki_tag_list, self); - - self->super.type = SPKI_TAG_LIST; - self->super.match = do_spki_tag_list_match; - - self->list = list; - - return &self->super; -} - -/* A (* set ...) construction */ - -/* GABA: - (class - (name spki_tag_set) - (super spki_tag) - (vars - (set object object_list))) -*/ - -static int -do_spki_tag_set_match(struct spki_tag *s, - struct sexp *e) -{ - CAST(spki_tag_set, self, s); - unsigned i; - - for (i = 0; iset); i++) - { - CAST_SUBTYPE(spki_tag, tag, LIST(self->set)[i]); - if (SPKI_TAG_MATCH(tag, e)) - return 1; - } - - return 0; -} - -static struct spki_tag * -make_spki_tag_set(struct object_list *set) -{ - NEW(spki_tag_set, self); - - self->super.type = SPKI_TAG_SET; - self->super.match = do_spki_tag_set_match; - - self->set = set; - - return &self->super; -} - -/* Authorizations represented as a string prefix. If display types are - * present, they must be equal. */ - -/* GABA: - (class - (name spki_tag_prefix) - (super spki_tag) - (vars - (prefix object sexp))) -*/ - -static int -do_spki_tag_prefix_match(struct spki_tag *s, - struct sexp *e) -{ - CAST(spki_tag_prefix, self, s); - const struct lsh_string *ed; - const struct lsh_string *pd; - - assert(sexp_atomp(self->prefix)); - - if (!sexp_atomp(e)) - return 0; - - ed = sexp_display(e); - pd = sexp_display(self->prefix); - - return (ed ? (pd && lsh_string_eq(ed, pd)) : !pd) - && lsh_string_prefixp(sexp_contents(self->prefix), - sexp_contents(e)); -} - -static struct spki_tag * -make_spki_tag_prefix(struct sexp *prefix) -{ - NEW(spki_tag_prefix, self); - - self->super.type = SPKI_TAG_PREFIX; - self->super.match = do_spki_tag_prefix_match; - - self->prefix = prefix; - - return &self->super; -} - - -static int -do_spki_tag_any_match(struct spki_tag *self UNUSED, - struct sexp *e UNUSED) -{ - return 1; -} - -/* FIXME: Make this const */ -struct spki_tag spki_tag_any = -{ STATIC_HEADER, SPKI_TAG_ANY, do_spki_tag_any_match }; - - -static struct object_list * -spki_sexp_to_tag_list(struct sexp_iterator *i, unsigned limit) -{ - unsigned left; - struct object_list *l; - unsigned j; - - left = SEXP_LEFT(i); - - if (!left) - { - werror("spki_sexp_to_tag_list: Empty list.\n"); - return NULL; - } - - l = alloc_object_list(left); - - for (j = 0; jsuper; - SEXP_NEXT(i); - } - assert(!SEXP_GET(i)); - - return l; -} - -struct spki_tag * -spki_sexp_to_tag(struct sexp *e, - /* Some limit on the recursion */ - unsigned limit) -{ - if (sexp_atomp(e)) - return make_spki_tag_atom(e); - else - { - struct sexp_iterator *i; - if (!limit) - { - werror("spki_sexp_to_tag: Nesting too deep.\n"); - return NULL; - } - - if (sexp_check_type(e, ATOM_STAR, &i)) - { - struct sexp *magic = SEXP_GET(i); - - if (!magic) - return &spki_tag_any; - - SEXP_NEXT(i); - - switch(sexp2atom(magic)) - { - case ATOM_SET: - { - struct object_list *l = spki_sexp_to_tag_list(i, limit - 1); - - return l ? make_spki_tag_set(l) : NULL; - } - case ATOM_PREFIX: - { - struct sexp *prefix = SEXP_GET(i); - - return (prefix && sexp_atomp(prefix)) - ? make_spki_tag_prefix(prefix) - : NULL; - } - default: - werror("spki_sexp_to_tag: Invalid (* ...) tag.\n"); - return NULL; - } - } - else - { - struct object_list *l = spki_sexp_to_tag_list(SEXP_ITER(e), limit - 1); - - return l ? make_spki_tag_list(l) : NULL; - } - } -} - -#define SPKI_NESTING_LIMIT 17 - -/* The iterator should point at the element after the tag of an expression - * - * (entry (public-key|hash|name ...) (propagate)? (tag ...) (valid ...)? ) - */ - -struct spki_5_tuple * -spki_acl_entry_to_5_tuple(struct spki_context *ctx, - struct sexp_iterator *i) -{ - struct spki_subject *subject; - struct sexp_iterator *j; - struct spki_tag *authorization; - - int propagate = 0; - - struct sexp *e = SEXP_GET(i); - - if (!e) - { - werror("spki_acl_entry_to_5_tuple: Invalid entry.\n"); - return NULL; - } - - subject = SPKI_LOOKUP(ctx, e, NULL); - if (!subject) - return NULL; - - SEXP_NEXT(i); - e = SEXP_GET(i); - if (!e) - return NULL; - - if (sexp_check_type(e, ATOM_PROPAGATE, &j)) - { - if (SEXP_GET(j)) - { - werror("spki_acl_entry_to_5_tuple: Invalid propagate-expression.\n"); - return NULL; - } - propagate = 1; - SEXP_NEXT(i); - e = SEXP_GET(i); - } - - if (sexp_check_type(e, ATOM_TAG, &j)) - { - struct sexp *tag = SEXP_GET(j); - SEXP_NEXT(j); - if (SEXP_GET(j)) - { - werror("spki_acl_entry_to_5_tuple: Invalid tag-expression.\n"); - return NULL; - } - - authorization = spki_sexp_to_tag(tag, SPKI_NESTING_LIMIT); - if (!authorization) - return NULL; - } - else - { - werror("spki_acl_entry_to_5_tuple: Invalid entry.\n"); - return NULL; - } - - SEXP_NEXT(i); - if (SEXP_GET(i)) - { - werror("spki_acl_entry_to_5_tuple: Garbage at end of entry.\n"); - return NULL; - } - - /* Create a 5-tuple with a NULL (i.e. self) issuer */ - return make_spki_5_tuple(NULL, subject, propagate, - authorization, 0, 0, 0, 0); -} - -/* Takes an spki_context and an ACL s-expression, and adds - * corresponding 5-tuples to the context. Returns 1 if all entries - * were correct, 0 on any error. However, it tries to gon on if some - * sub-expression is invalid. */ - -int -spki_add_acl(struct spki_context *ctx, - struct sexp *e) -{ - struct sexp_iterator *i; - int res = 1; - - if (!sexp_check_type(e, ATOM_ACL, &i)) - { - werror("spki_read_acls: Invalid acl\n"); - return 0; - } - - /* FIXME: Accept at least (version "0") */ - if (sexp_check_type(SEXP_GET(i), ATOM_VERSION, NULL)) - { - werror("spki_read_acls: Unsupported acl version\n"); - return 0; - } - - for (; (e = SEXP_GET(i)); SEXP_NEXT(i)) - { - struct sexp_iterator *j; - if (sexp_check_type(e, ATOM_ENTRY, &j)) - { - struct spki_5_tuple *acl = spki_acl_entry_to_5_tuple(ctx, j); - if (acl) - SPKI_ADD_TUPLE(ctx, acl); - else res = 0; - } - else - { - werror("spki_read_acls: Invalid entry, ignoring\n"); - res = 0; - } - } - - return res; -} - - -/* SPKI context */ - -/* GABA: - (class - (name spki_state) - (super spki_context) - (vars - ; Signature algorithms - (algorithms object alist) - ;; FIXME: Could have a alist of hash algorithms as well. - - ; We could use some kind of hash table instead - (keys struct object_queue) - - ; Five tuples. - (db struct object_queue))) -*/ - -static struct spki_subject * -spki_subject_by_hash(struct spki_state *self, - int algorithm, - const struct lsh_string *hash) -{ - FOR_OBJECT_QUEUE(&self->keys, n) - { - CAST(spki_subject, subject, n); - - if (subject_match_hash(subject, algorithm, hash)) - return subject; - } - return NULL; -} - -static struct spki_subject * -do_spki_lookup(struct spki_context *s, - struct sexp *e, - struct verifier *v) - -{ - CAST(spki_state, self, s); - struct sexp_iterator *i; - - switch (spki_get_type(e, &i)) - { - case ATOM_HASH: - { - /* Syntax: (hash ) */ - struct spki_subject *subject; - const struct lsh_string *hash; - - int method = sexp2atom(SEXP_GET(i)); - if (!method) - return NULL; - - SEXP_NEXT(i); - hash = sexp2string(SEXP_GET(i)); - - if (!hash) - return NULL; - - SEXP_NEXT(i); - if (SEXP_GET(i)) - return NULL; - - subject = spki_subject_by_hash(self, method, hash); - - if (!subject) - { - switch (method) - { - case ATOM_SHA1: - subject = make_spki_subject(NULL, NULL, lsh_string_dup(hash), NULL); - break; - case ATOM_MD5: - subject = make_spki_subject(NULL, NULL, NULL, lsh_string_dup(hash)); - break; - default: - return NULL; - } - - object_queue_add_tail(&self->keys, &subject->super); - } - - if (!subject->verifier && v) - subject->verifier = v; - - return subject; - } - case ATOM_PUBLIC_KEY: - { - /* Syntax: (public-key ( *) ) */ - struct spki_subject *subject; - struct lsh_string *sha1; - struct lsh_string *md5; - struct sexp *key = SEXP_GET(i); - - if (!key) - { - werror("do_spki_lookup: Invalid (public-key ...) expression.\n"); - return NULL; - } - - /* We first se if we can find the key by hash */ - { - struct lsh_string *canonical = sexp_format(e, SEXP_CANONICAL, 0); - sha1 = hash_string(&sha1_algorithm, canonical, 0); - md5 = hash_string(&md5_algorithm, canonical, 1); - } - - if ( ((subject = spki_subject_by_hash(self, ATOM_SHA1, sha1))) - || ((subject = spki_subject_by_hash(self, ATOM_MD5, md5))) ) - { - lsh_string_free(md5); - lsh_string_free(sha1); - - if (!subject->key) - { - assert(!subject->verifier); - subject->key = e; - - subject->verifier - = v ? v : spki_make_verifier(self->algorithms, key); - } - } - else - { - /* New subject */ - subject = make_spki_subject(e, - v ? v : spki_make_verifier(self->algorithms, key), - sha1, md5); - - object_queue_add_head(&self->keys, &subject->super); - } - - return subject; - } - case ATOM_SEQUENCE: - werror("do_spki_lookup: spki sequences not yet supported.\n"); - return NULL; - - case ATOM_NAME: - werror("do_spki_lookup: names not yet supported.\n"); - return NULL; - default: - werror("do_spki_lookup: Invalid expression.\n"); - return NULL; - } -} - -static void -do_spki_add_tuple(struct spki_context *s, - struct spki_5_tuple *tuple) -{ - CAST(spki_state, self, s); - - object_queue_add_tail(&self->db, &tuple->super); -} - -static int -do_spki_authorize(struct spki_context *s, - struct spki_subject *user, - struct sexp *access) -{ - CAST(spki_state, self, s); - - FOR_OBJECT_QUEUE(&self->db, n) - { - CAST(spki_5_tuple, tuple, n); - - /* FIXME: Handles ACL:s only. I.e. issuer == NULL. */ - if ( (user == tuple->subject) - && !tuple->issuer - && SPKI_TAG_MATCH(tuple->authorization, access)) - return 1; - } - return 0; -} - -struct spki_context * -make_spki_context(struct alist *algorithms) -{ - NEW(spki_state, self); - self->super.lookup = do_spki_lookup; - self->super.add_tuple = do_spki_add_tuple; - self->super.authorize = do_spki_authorize; - - self->algorithms = algorithms; - object_queue_init(&self->keys); - object_queue_init(&self->db); - - return &self->super; -} diff --git a/lsh/src/spki.c.x b/lsh/src/spki.c.x deleted file mode 100755 index 901377a..0000000 Binary files a/lsh/src/spki.c.x and /dev/null differ diff --git a/lsh/src/spki.h b/lsh/src/spki.h deleted file mode 100755 index 75d1db1..0000000 --- a/lsh/src/spki.h +++ /dev/null @@ -1,212 +0,0 @@ -/* spki.h - * - * An implementation of SPKI certificate checking - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Balázs Scheidler - * - * 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 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 should 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 - */ - -#ifndef LSH_SPKI_H_INCLUDED -#define LSH_SPKI_H_INCLUDED - -#include "alist.h" -#include "dsa.h" -#include "exception.h" -#include "publickey_crypto.h" - -#include - -/* Needed by spki.h.x */ -/* SPKI validity. No online validity tests supported. */ -struct spki_validity -{ - char before_limit; /* Nonzero if not_before was supplied */ - char after_limit; /* Nonzero if not_after was supplied */ - time_t not_before; - time_t not_after; -}; - -struct spki_5_tuple; - -#define GABA_DECLARE -#include "spki.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name spki_exception) - (super exception) - (vars - (expr object sexp))) -*/ - -struct exception * -make_spki_exception(UINT32 type, const char *msg, struct sexp *expr); - -int spki_get_type(struct sexp *e, struct sexp_iterator **res); - -struct sexp * -make_ssh_hostkey_tag(struct address_info *host); - -struct verifier * -spki_make_verifier(struct alist *algorithms, - struct sexp *e); - -struct signer * -spki_make_signer(struct alist *algorithms, - struct sexp *e, - int *type); - -struct sexp * -spki_make_public_key(struct verifier *verifier); - -struct sexp * -spki_hash_data(struct hash_algorithm *algorithm, - int algorithm_name, - UINT32 length, UINT8 *data); - -/* At a point in time, not all fields are known; fields may be added - * later, or computed as needed. This information is not automatically - * trusted in any way, except that any non-NULL attributes must be - * consistent with each other. */ - -/* GABA: - (class - (name spki_subject) - (vars - ; (public-key ...) expression. - (key object sexp) - - ; Verifier - (verifier object verifier) - (sha1 string) - (md5 string))) -*/ - -struct spki_subject * -make_spki_subject(struct sexp *key, - struct verifier *verifier, - struct lsh_string *sha1, - struct lsh_string *md5); - -/* Keeps track of spki_subjects and their keys. - * - * We try to make sure that subjects within one context can be - * compared pointer-wise. I.e. if we get several (public-key ...) and - * (hash ...) expressions representing the same principal, we merge - * them into a single spki_subject object. However, there is one case - * in which this fails: If we encounter several (hash ...) - * expressions with different hash algorithms, before we encounter the - * non-hashed (public-key ...) expression. */ - -/* GABA: - (class - (name spki_context) - (vars - ; Looks up a public-key or hash. - (lookup method (object spki_subject) - "struct sexp *e" - ; If non-NULL, use this verifier for - ; the subject. Useful for non-SPKI keys. - "struct verifier *v") - (add_tuple method void - "struct spki_5_tuple *tuple") - (authorize method int - "struct spki_subject *subject" - "struct sexp *access"))) - ;; (clone method (object spki_context)))) -*/ - -#define SPKI_LOOKUP(c, e, v) ((c)->lookup((c), (e), (v))) -#define SPKI_ADD_TUPLE(c, t) ((c)->add_tuple((c), ((t)))) -#define SPKI_AUTHORIZE(c, s, a) ((c)->authorize((c), (s), (a))) -#define SPKI_CLONE(c) ((c)->clone((c))) - -struct spki_context * -make_spki_context(struct alist *algorithms); - -/* 5-tuples */ - -#define SPKI_TAG_ATOM 1 -#define SPKI_TAG_LIST 2 -#define SPKI_TAG_SET 3 -#define SPKI_TAG_PREFIX 4 -#define SPKI_TAG_ANY 5 - -/* GABA: - (class - (name spki_tag) - (vars - ; Explicit type field is needed only for computing - ; intersections - (type . int) - ; Returns true iff the resources described by the tag - ; include the resource described by the sexp. - (match method int "struct sexp *"))) -*/ - -#define SPKI_TAG_TYPE(t) ((t)->type) -#define SPKI_TAG_MATCH(t, e) ((t)->match((t), (e))) - -/* The data in a 5-tuple is always trusted, to the extent a non-NULL - * issuer field implies that the tuple was derived from a certificate - * that was properly signed by that issuer. However, no trust in the - * issuer is assumed. */ - -/* GABA: - (class - (name spki_5_tuple) - (vars - ; Principal - (issuer object spki_subject) - ; Principal (n-to-k not yet supported) - (subject object spki_subject) - ; Non-zero to allow delegation - (propagate . int) - ; Authorization, (tag ...) expression - (authorization object spki_tag) - ; Validity period - (validity . "struct spki_validity"))) - -*/ - -struct spki_5_tuple * -make_spki_5_tuple(struct spki_subject *issuer, - struct spki_subject *subject, - int propagate, - struct spki_tag *authorization, - int before_limit, time_t not_before, - int after_limit, time_t not_after); - - -struct spki_tag * -spki_sexp_to_tag(struct sexp *e, - /* Some limit on the recursion */ - unsigned limit); - -struct spki_5_tuple * -spki_acl_entry_to_5_tuple(struct spki_context *ctx, - struct sexp_iterator *i); - -int -spki_add_acl(struct spki_context *ctx, - struct sexp *e); - -#endif /* LSH_SPKI_H_INCLUDED */ diff --git a/lsh/src/spki.h.x b/lsh/src/spki.h.x deleted file mode 100755 index a01d9ba..0000000 Binary files a/lsh/src/spki.h.x and /dev/null differ diff --git a/lsh/src/spki_commands.c b/lsh/src/spki_commands.c deleted file mode 100755 index 826bd69..0000000 --- a/lsh/src/spki_commands.c +++ /dev/null @@ -1,982 +0,0 @@ -/* spki_commands.c - * - * SPKI interface - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller - * - * 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 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 should 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 - */ - -#include "spki_commands.h" - -#include "atoms.h" -#include "crypto.h" -#include "format.h" -#include "queue.h" -#include "randomness.h" -#include "sexp_commands.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Forward declarations */ -struct command spki_add_acl_command; -#define SPKI_ADD_ACL (&spki_add_acl_command.super) - -struct command spki_return_hostkeys; -#define RETURN_HOSTKEYS (&spki_return_hostkeys.super) - -struct command spki_add_hostkey_command; -#define SPKI_ADD_HOSTKEY (&spki_add_hostkey_command.super) - -struct command spki_return_userkeys; -#define RETURN_USERKEYS (&spki_return_userkeys.super) - -struct command spki_add_userkey_command; -#define SPKI_ADD_USERKEY (&spki_add_userkey_command.super) - - -#include "spki_commands.c.x" - -#define SA(x) sexp_a(ATOM_##x) - -#define SPKI_ERROR(e, msg, expr) \ -EXCEPTION_RAISE((e), make_spki_exception(EXC_SPKI_TYPE, (msg), (expr))) - - -/* Various conversion functions */ - -DEFINE_COMMAND(spki_signer2verifier) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(signer, private, a); - COMMAND_RETURN(c, SIGNER_GET_VERIFIER(private)); -} - -DEFINE_COMMAND(spki_verifier2public) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(verifier, v, a); - COMMAND_RETURN(c, spki_make_public_key(v)); -} - -/* Create an SPKI hash from an s-expression. */ -/* GABA: - (class - (name spki_hash) - (super command) - (vars - (name . int) - (algorithm object hash_algorithm))) -*/ - -static void -do_spki_hash(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_hash, self, s); - CAST_SUBTYPE(sexp, o, a); - - struct lsh_string *tmp = hash_string(self->algorithm, - sexp_format(o, SEXP_CANONICAL, 0), - 1); - struct sexp *hash = spki_hash_data(self->algorithm, self->name, - tmp->length, tmp->data); - lsh_string_free(tmp); - - COMMAND_RETURN(c, hash); -} - -struct command * -make_spki_hash(int name, struct hash_algorithm *algorithm) -{ - NEW(spki_hash, self); - self->super.call = do_spki_hash; - self->name = name; - self->algorithm = algorithm; - - return &self->super; -} - -const struct spki_hash spki_hash_md5 = -{ STATIC_COMMAND(do_spki_hash), ATOM_MD5, &md5_algorithm }; - -const struct spki_hash spki_hash_sha1 = -{ STATIC_COMMAND(do_spki_hash), ATOM_SHA1, &sha1_algorithm }; - - -/* Reading keys */ - -/* Used for both sexp2keypair and sexp2signer. */ -/* FIXME: Use DEFINE_COMMAND2 instead? */ -/* GABA: - (class - (name spki_parse_key) - (super command) - (vars - (algorithms object alist))) -*/ - - -static void -do_spki_sexp2signer(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(spki_parse_key, self, s); - CAST_SUBTYPE(sexp, key, a); - - struct sexp_iterator *i; - - if (sexp_check_type(key, ATOM_PRIVATE_KEY, &i)) - { - struct sexp *expr = SEXP_GET(i); - struct signer *s; - - if (!expr) - SPKI_ERROR(e, "spki.c: Invalid key.", key); - - s = spki_make_signer(self->algorithms, expr, NULL); - - if (s) - /* Test key here? */ - COMMAND_RETURN(c, s); - else - SPKI_ERROR(e, "spki.c: Invalid key.", expr); - } - else - SPKI_ERROR(e, "spki.c: Expected private-key expression.", key); -} - -/* (parse algorithms sexp) -> signer */ -DEFINE_COMMAND(spki_sexp2signer_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(alist, algorithms, a); - NEW(spki_parse_key, self); - - self->super.call = do_spki_sexp2signer; - self->algorithms = algorithms; - COMMAND_RETURN(c, self); -} - - -static void -parse_private_key(struct alist *algorithms, - struct sexp_iterator *i, - struct command_continuation *c, - struct exception_handler *e) -{ - struct sexp *expr = SEXP_GET(i); - int algorithm_name; - struct signer *s; - struct verifier *v; - struct lsh_string *spki_public; - - if (!expr) - { - werror("parse_private_key: Invalid key.\n"); - SPKI_ERROR(e, "spki.c: Invalid key.", expr); - return; - } - - s = spki_make_signer(algorithms, expr, &algorithm_name); - - if (!s) - { - SPKI_ERROR(e, "spki.c: Invalid key.", expr); - return; - - } - - v = SIGNER_GET_VERIFIER(s); - spki_public = sexp_format(spki_make_public_key(SIGNER_GET_VERIFIER(s)), - SEXP_CANONICAL, 0); - - /* Test key here? */ - switch (algorithm_name) - { - case ATOM_DSA: - COMMAND_RETURN(c, make_keypair(ATOM_SSH_DSS, - PUBLIC_KEY(v), - s)); - COMMAND_RETURN(c, make_keypair(ATOM_SPKI_SIGN_DSS, - spki_public, s)); - break; - - case ATOM_RSA_PKCS1_SHA1: - COMMAND_RETURN(c, make_keypair(ATOM_SSH_RSA, - PUBLIC_KEY(v), - s)); - /* Fall through */ - - case ATOM_RSA_PKCS1_MD5: - COMMAND_RETURN(c, make_keypair(ATOM_SPKI_SIGN_RSA, - spki_public, s)); - break; - - default: - fatal("Internal error!\n"); -#if 0 - /* Get a corresponding public key. */ - COMMAND_RETURN(c, make_keypair - (ATOM_SPKI, - sexp_format(spki_make_public_key(SIGNER_GET_VERIFIER(s)), - SEXP_CANONICAL, 0), - s)); -#endif - - break; - } -} - -static void -do_spki_sexp2keypair(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(spki_parse_key, self, s); - CAST_SUBTYPE(sexp, key, a); - - struct sexp_iterator *i; - - switch (spki_get_type(key, &i)) - { - default: - SPKI_ERROR(e, "spki.c: Expected private-key expression.", key); - return; - case ATOM_PRIVATE_KEY: - parse_private_key(self->algorithms, i, c, e); - break; - } -} - - -/* (parse algorithms sexp) -> one or more keypairs */ -DEFINE_COMMAND(spki_sexp2keypair_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(alist, algorithms, a); - NEW(spki_parse_key, self); - - self->super.call = do_spki_sexp2keypair; - self->algorithms = algorithms; - COMMAND_RETURN(c, self); -} - -/* GABA: - (class - (name spki_command) - (super command) - (vars - (ctx object spki_context))) -*/ - -/* Reading of ACL:s - * ****************/ - -/* Adds an ACL s-expression to an SPKI-context. Returns the context. */ - -static void -do_spki_add_acl(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_command, self, s); - CAST_SUBTYPE(sexp, expr, a); - - trace("do_spki_add_acl\n"); - spki_add_acl(self->ctx, expr); - - COMMAND_RETURN(c, self->ctx); -} - -DEFINE_COMMAND(spki_add_acl_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(spki_context, ctx, a); - - NEW(spki_command, self); - self->super.call = do_spki_add_acl; - self->ctx = ctx; - - trace("spki_add_acl_command\n"); - - COMMAND_RETURN(c, self); -} - -DEFINE_COMMAND(spki_make_context_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(alist, algorithms, a); - trace("spki_make_context_command\n"); - - COMMAND_RETURN(c, make_spki_context(algorithms)); -} - -/* Reads a file of ACL:s, and returns an spki_context. */ - -/* GABA: - (expr - (name spki_read_acl) - (params - (algorithms object alist)) - (expr - (lambda (file) - (let ((ctx (spki_make_context - ;; Delay call, so that we really - ;; create one context for each file. - (prog1 algorithms file)))) - (for_sexp - (lambda (e) ctx) ; Return ctx - ;; Keep on reading until an SEXP_EOF or - ;; SEXP_SYNTAX exception is raised. - (spki_add_acl ctx) - file))))) -*/ - -struct command * -make_spki_read_acls(struct alist *algorithms) -{ - CAST_SUBTYPE(command, res, spki_read_acl(algorithms)); - - trace("make_spki_read_acl\n"); - return res; -} - - -/* Reading of host-keys - * ********************/ - -/* GABA: - (class - (name spki_read_hostkey_context) - (super command) - (vars - (keys object alist))) -*/ - -static void -do_spki_add_hostkey(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_read_hostkey_context, self, s); - CAST(keypair, key, a); - - trace("do_spki_add_hostkey\n"); - - if (ALIST_GET(self->keys, key->type)) - werror("Multiple host keys of type %a.\n", key->type); - else - ALIST_SET(self->keys, key->type, &key->super); - - COMMAND_RETURN(c, self->keys); -} - -/* Ignores its argument */ -DEFINE_COMMAND(spki_add_hostkey_command) - (struct command *s UNUSED, - struct lsh_object *a UNUSED, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - NEW(spki_read_hostkey_context, self); - - trace("spki_add_hostkey_command\n"); - - self->super.call = do_spki_add_hostkey; - self->keys = make_alist(0, -1); - - COMMAND_RETURN(c, self); -} - -DEFINE_COMMAND(spki_return_hostkeys) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_read_hostkey_context, self, a); - trace("spki_return_hostkeys\n"); - COMMAND_RETURN(c, self->keys); -} - -/* GABA: - (expr - (name spki_read_hostkeys) - (params - (algorithms object alist)) - (expr - (lambda (file) - (let ((add (spki_add_hostkey file))) - (for_sexp (lambda (e) - ;; Delay return until we actually get an exception - (return_hostkeys (prog1 add e))) - (lambda (key) - (add (sexp2keypair - algorithms key))) - file))))) -*/ - -DEFINE_COMMAND(spki_read_hostkeys_command) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(alist, algorithms, a); - CAST_SUBTYPE(command, res, spki_read_hostkeys(algorithms)); - - trace("spki_read_hostkeys_command\n"); - - COMMAND_RETURN(c, res); -} - -/* Reading of private user-keys - * ****************************/ - -/* GABA: - (class - (name spki_read_userkey_context) - (super command) - (vars - (keys struct object_queue))) -*/ - -static void -do_spki_add_userkey(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_read_userkey_context, self, s); - CAST(keypair, key, a); - - trace("do_spki_add_userkey\n"); - - object_queue_add_tail(&self->keys, &key->super); - - COMMAND_RETURN(c, s); -} - -/* Ignores its argument */ -DEFINE_COMMAND(spki_add_userkey_command) - (struct command *s UNUSED, - struct lsh_object *a UNUSED, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - NEW(spki_read_userkey_context, self); - - trace("spki_add_userkey_command\n"); - self->super.call = do_spki_add_userkey; - object_queue_init(&self->keys); - - COMMAND_RETURN(c, self); -} - -DEFINE_COMMAND(spki_return_userkeys) - (struct command *s UNUSED, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_read_userkey_context, self, a); - trace("spki_return_userkeys\n"); - - COMMAND_RETURN(c,queue_to_list(&self->keys)); -} - -/* GABA: - (expr - (name spki_read_userkeys) - (params - (algorithms object alist) - (decrypt object command)) - (expr - (lambda (file) - (let ((ctx (spki_add_userkey file))) - (for_sexp (lambda (e) - ;; Delay return until we actually get an exception - (return_userkeys (prog1 ctx e))) - (lambda (key) - (ctx (sexp2keypair - algorithms (decrypt key)))) - file))))) -*/ - -struct command * -make_spki_read_userkeys(struct alist *algorithms, - struct alist *signature_algorithms, - struct interact *tty) -{ - struct command *decrypt; - trace("make_spki_read_userkeys\n"); - - if (tty) - { - struct alist *mac = make_alist(0, -1); - struct alist *crypto = make_alist(0, -1); - - alist_select_l(mac, algorithms, - 2, ATOM_HMAC_SHA1, ATOM_HMAC_MD5, -1); - alist_select_l(crypto, algorithms, - 3, ATOM_3DES_CBC, ATOM_BLOWFISH_CBC, - ATOM_RIJNDAEL_CBC_LOCAL, -1); - decrypt = make_pkcs5_decrypt(mac, crypto, tty); - } - else - decrypt = &command_I; - - { - CAST_SUBTYPE(command, res, - spki_read_userkeys(signature_algorithms, - decrypt)); - - return res; - } -} - -/* Encryption of private data. - * For PKCS#5 (version 2) key derivation, we use - * - * (password-encrypted LABEL - * (Xpkcs5v2 hmac-sha1 (salt #...#) - * (iterations #...#)) - * ("3des-cbc" (iv #...#) (data #...#))) - * - * where the X:s will be removed when the format is more stable. - * - */ - -/* GABA: - (class - (name spki_password_encrypt) - (super command) - (vars - (label string) - (method object sexp) - (algorithm_name . int) - (algorithm object crypto_algorithm) - (r object randomness) - (key string))) -*/ - -static void -do_spki_encrypt(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(spki_password_encrypt, self, s); - CAST_SUBTYPE(sexp, expr, a); - - struct lsh_string *iv = NULL; - - if (self->algorithm->iv_size) - { - iv = lsh_string_alloc(self->algorithm->iv_size); - RANDOM(self->r, iv->length, iv->data); - } - - COMMAND_RETURN(c, - sexp_l(4, - SA(PASSWORD_ENCRYPTED), - sexp_s(NULL, lsh_string_dup(self->label)), - self->method, - sexp_l(3, - sexp_a(self->algorithm_name), - sexp_l(2, SA(IV), sexp_s(NULL, iv), -1), - sexp_l(2, SA(DATA), - sexp_s(NULL, crypt_string_pad - (MAKE_ENCRYPT(self->algorithm, - self->key->data, iv ? iv->data : NULL), - sexp_format(expr, SEXP_CANONICAL, 0), 1)), - -1), - -1), - -1)); -} - -/* Consumes the label and password arguments. */ -struct command * -make_pkcs5_encrypt(struct randomness *r, - struct lsh_string *label, - UINT32 prf_name, - struct mac_algorithm *prf, - int crypto_name, - struct crypto_algorithm *crypto, - UINT32 salt_length, - struct lsh_string *password, - UINT32 iterations) -{ - NEW(spki_password_encrypt, self); - - struct lsh_string *key; - struct lsh_string *salt; - - assert(crypto); - assert(prf); - - salt = lsh_string_alloc(salt_length); - RANDOM(r, salt->length, salt->data); - - key = lsh_string_alloc(crypto->key_size); - - pkcs5_derive_key(prf, - password->length, password->data, - salt->length, salt->data, - iterations, - key->length, key->data); - - lsh_string_free(password); - - self->super.call = do_spki_encrypt; - self->r = r; - self->label = label; - self->method = sexp_l(4, SA(XPKCS5V2), sexp_a(prf_name), - sexp_l(2, SA(ITERATIONS), sexp_uint32(iterations), -1), - sexp_l(2, SA(SALT), sexp_s(NULL, salt), -1), -1); - self->algorithm_name = crypto_name; - self->algorithm = crypto; - self->key = key; - - return &self->super; -} - -/* GABA: - (class - (name spki_password_decrypt) - (super command) - (vars - (mac_algorithms object alist) - (crypto_algorithms object alist) - (tty object interact))) -*/ - -static void -do_spki_decrypt(struct command *s, - struct lsh_object *a, - struct command_continuation *c, - struct exception_handler *e) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif -#if MACOS - UINT8 *key; -#endif - CAST(spki_password_decrypt, self, s); - CAST_SUBTYPE(sexp, expr, a); - - struct sexp_iterator *i; - - if (!sexp_check_type(expr, ATOM_PASSWORD_ENCRYPTED, &i)) - COMMAND_RETURN(c, expr); - - else - { - const struct lsh_string *label; - struct sexp *key_info; - struct sexp *payload; - - struct crypto_algorithm *crypto; - struct mac_algorithm *mac; - - const struct lsh_string *salt; - const struct lsh_string *iv; - const struct lsh_string *data; - UINT32 iterations; - - if (SEXP_LEFT(i) != 3) - { - SPKI_ERROR(e, "Invalid (password-encrypted ...) expression.", - expr); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - /* NOTE: This is a place where it might make sense to use a sexp - * display type, but we don't support that for now. */ - label = sexp2string(SEXP_GET(i)); - - if (!label) - { - SPKI_ERROR(e, "Invalid label in (password-encrypted ...) expression.", - expr); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - SEXP_NEXT(i); - key_info = SEXP_GET(i); - assert(key_info); - - SEXP_NEXT(i); - payload = SEXP_GET(i); - assert(payload); - - /* Examine the payload expression first, before asking for a - * pass phrase. */ - - { - int algorithm_name = spki_get_type(payload, &i); - CAST_SUBTYPE(crypto_algorithm, tmp, - ALIST_GET(self->crypto_algorithms, algorithm_name)); - crypto = tmp; - } - - if (!crypto) - { - SPKI_ERROR(e, "Unknown encryption algorithm for pkcs5v2.", payload); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - iv = sexp2string(sexp_assq(i, ATOM_IV)); - - if (crypto->iv_size) - { - if (!iv || (iv->length != crypto->iv_size)) - { - SPKI_ERROR(e, "Invalid IV for pkcs5v2.", payload); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - } - else if (iv) - { - if (iv->length) - { - SPKI_ERROR(e, "Unexpected iv provided for pkcs5v2.", payload); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - iv = NULL; - } - - data = sexp2string(sexp_assq(i, ATOM_DATA)); - - if (!data) - { - SPKI_ERROR(e, "Payload data missing for pkcs5v2.", payload); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - if (crypto->block_size && (data->length & crypto->block_size)) - { - SPKI_ERROR(e, "Payload data doesn't match block size for pkcs5v2.", payload); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - /* Get key */ - switch (spki_get_type(key_info, &i)) - { - default: - SPKI_ERROR(e, "Unknown key derivation mechanism.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - - case ATOM_XPKCS5V2: - if (SEXP_LEFT(i) != 3) - { - SPKI_ERROR(e, "Invalid pkcs5v2 parameters.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - { - int algorithm_name = sexp2atom(SEXP_GET(i)); - - CAST_SUBTYPE(mac_algorithm, tmp, - ALIST_GET(self->mac_algorithms, - algorithm_name)); - - mac = tmp; - } - - if (!mac) - { - SPKI_ERROR(e, "Unknown mac for pkcs5v2.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - SEXP_NEXT(i); - if (!sexp2uint32(sexp_assq(i, ATOM_ITERATIONS), &iterations) - || !iterations) - { - SPKI_ERROR(e, "Invalid iteration count for pkcs5v2.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - salt = sexp2string(sexp_assq(i, ATOM_SALT)); - - if (!salt) - { - SPKI_ERROR(e, "Invalid salt for pkcs5v2.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - /* Do the work */ - - - -#if MACOS - key = alloca(crypto->key_size); - while ( 1 ) -#endif - { - struct lsh_string *password - = INTERACT_READ_PASSWORD(self->tty, 500, label, 0); - struct lsh_string *clear; - struct sexp *res; -#if !MACOS - UINT8 *key; -#endif - - if (!password) - { - SPKI_ERROR(e, "No password provided for pkcs5v2.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - -#if !MACOS - key = alloca(crypto->key_size); -#endif - pkcs5_derive_key(mac, - password->length, password->data, - salt->length, salt->data, - iterations, - crypto->key_size, key); - - lsh_string_free(password); - - clear = crypt_string_unpad(MAKE_DECRYPT(crypto, - key, - iv ? iv->data : NULL), - data, 0); - - if (!clear) - { -#if MACOS - continue; -#endif - SPKI_ERROR(e, "Bad password for pkcs5v2.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } - - res = string_to_sexp(SEXP_CANONICAL, clear, 1); - - if (res) - COMMAND_RETURN(c, res); - else - { -#if MACOS - continue; -#endif - SPKI_ERROR(e, "Bad password for pkcs5v2.", key_info); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif - return; - } -#if MACOS - break; -#endif - } - } - } -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -struct command * -make_pkcs5_decrypt(struct alist *mac_algorithms, - struct alist *crypto_algorithms, - struct interact *tty) -{ - NEW(spki_password_decrypt, self); - self->super.call = do_spki_decrypt; - self->mac_algorithms = mac_algorithms; - self->crypto_algorithms = crypto_algorithms; - self->tty = tty; - - return &self->super; -} diff --git a/lsh/src/spki_commands.c.x b/lsh/src/spki_commands.c.x deleted file mode 100755 index 8f5a791..0000000 Binary files a/lsh/src/spki_commands.c.x and /dev/null differ diff --git a/lsh/src/spki_commands.h b/lsh/src/spki_commands.h deleted file mode 100755 index f9d375d..0000000 --- a/lsh/src/spki_commands.h +++ /dev/null @@ -1,78 +0,0 @@ -/* spki_commands.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SPKI_COMMANDS_H_INCLUDED -#define LSH_SPKI_COMMANDS_H_INCLUDED - -#include "command.h" -#include "interact.h" -#include "spki.h" - -extern struct command spki_signer2verifier; -#define SIGNER2VERIFIER (&spki_signer2verifier.super) - -extern struct command spki_verifier2public; -#define VERIFIER2PUBLIC (&spki_verifier2public.super) - -extern struct command spki_sexp2signer_command; -#define SEXP2SIGNER (&spki_sexp2signer_command.super) - -extern struct command spki_sexp2keypair_command; -#define SEXP2KEYPAIR (&spki_sexp2keypair_command.super) - -extern struct command spki_make_context_command; -#define SPKI_MAKE_CONTEXT (&spki_make_context_command.super) - -extern struct command spki_read_hostkeys_command; -#define SPKI_READ_HOSTKEYS (&spki_read_hostkeys_command.super) - -struct command * -make_spki_hash(int name, struct hash_algorithm *algorithm); - -struct command * -make_spki_read_acls(struct alist *algorithms); - -struct command * -make_spki_read_userkeys(struct alist *algorithms, - struct alist *signature_algorithms, - struct interact *tty); - - -/* Encryption of private data. */ -struct command * -make_pkcs5_encrypt(struct randomness *r, - struct lsh_string *label, - UINT32 prf_name, - struct mac_algorithm *prf, - int crypto_name, - struct crypto_algorithm *crypto, - UINT32 salt_length, - struct lsh_string *password, - UINT32 iterations); - -struct command * -make_pkcs5_decrypt(struct alist *mac_algorithms, - struct alist *crypto_algorithms, - struct interact *tty); - -#endif /* LSH_SPKI_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/srp-gen.c b/lsh/src/srp-gen.c deleted file mode 100755 index dc13cd3..0000000 --- a/lsh/src/srp-gen.c +++ /dev/null @@ -1,263 +0,0 @@ -/* srp-gen.c - * - * Create an SRP verifier - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "srp.h" - -#include "crypto.h" -#include "format.h" -#include "interact.h" -#include "io.h" -#include "randomness.h" -#include "sexp.h" -#include "srp.h" -#include "version.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#define BLOCK_SIZE 2000 -#define SALT_SIZE 20 - -#include "srp-gen.c.x" - -/* Option parsing */ - -const char *argp_program_version -= "srp-gen-" VERSION; - -const char *argp_program_bug_address = BUG_ADDRESS; - -/* GABA: - (class - (name srp_gen_options) - (vars - (backend object io_backend) - - (tty object interact) - - (e object exception_handler) - (G object abstract_group) - (H object hash_algorithm) - - (file string) - (dest object abstract_write) - - (style . sexp_argp_state) - - (name . "const char *") - (passwd string) - (r object randomness))) -*/ - -static struct srp_gen_options * -make_srp_gen_options(struct io_backend *backend, - struct exception_handler *e) -{ - NEW(srp_gen_options, self); - - self->backend = backend; - - /* We don't need window change tracking. */ - self->tty = make_unix_interact(NULL); - - self->e = e; - - self->G = make_ssh_ring_srp_1(); - self->H = &sha1_algorithm; - self->file = NULL; - self->dest = NULL; - - self->style = -1; - - self->name = getenv("LOGNAME"); - self->passwd = NULL; - - /* We use this only for generating the salt. */ - self->r = make_bad_random(); - - return self; -} - -static const struct argp_option -main_options[] = -{ - /* Name, key, arg-name, flags, doc, group */ - { "user", 'l', "User name", 0, NULL, 0 }, - { "password", 'p', "Password", 0, NULL, 0 }, - { "output-file", 'o', "Filename", 0, "Default is to write to stdout.", 0 }, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static const struct argp_child -main_argp_children[] = -{ - { &sexp_output_argp, 0, NULL, 0 }, - { &werror_argp, 0, "", 0 }, - { NULL, 0, NULL, 0} -}; - -static error_t -main_argp_parser(int key, char *arg, struct argp_state *state) -{ - CAST(srp_gen_options, self, state->input); - - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - - case ARGP_KEY_INIT: - state->child_inputs[0] = &self->style; - state->child_inputs[1] = NULL; - break; - - case ARGP_KEY_END: - if (!self->name) - argp_error(state, "No user name given. Use the -l option, or set LOGNAME in the environment."); - - { - struct lsh_fd *fd; - - if (self->file) - { - fd = io_write_file(self->backend, self->file->data, - O_CREAT | O_EXCL | O_WRONLY, - 0600, BLOCK_SIZE, - NULL, self->e); - if (!fd) - argp_failure(state, EXIT_FAILURE, errno, "Could not open '%s'.", self->file->data); - } - else - { - fd = io_write(make_lsh_fd(self->backend, - STDOUT_FILENO, "stdout", - self->e), - BLOCK_SIZE, NULL); - } - self->dest = &fd->write_buffer->super; - } - - while (!self->passwd) - { - struct lsh_string *pw; - struct lsh_string *again; - - pw = INTERACT_READ_PASSWORD(self->tty, 500, - ssh_format("Enter new SRP password: "), 1); - if (!pw) - argp_failure(state, EXIT_FAILURE, 0, "Aborted."); - - again = INTERACT_READ_PASSWORD(self->tty, 500, - ssh_format("Again: "), 1); - if (!again) - argp_failure(state, EXIT_FAILURE, 0, "Aborted."); - - if (lsh_string_eq(pw, again)) - self->passwd = pw; - else - lsh_string_free(pw); - - lsh_string_free(again); - } - if (self->style < 0) - self->style = self->file ? SEXP_CANONICAL : SEXP_TRANSPORT; - - break; - - case 'o': - self->file = make_string(arg); - break; - - case 'p': - self->passwd = ssh_format("%lz", arg); - break; - } - return 0; -} - -static const struct argp -main_argp = -{ main_options, main_argp_parser, - NULL, - "Generates a password verifier for the Secure Remote Password protocol.", - main_argp_children, - NULL, NULL -}; - -static struct sexp * -srp_gen(struct srp_gen_options *options) -{ - struct lsh_string *salt; - struct lsh_string *name; - struct sexp *e; - - salt = lsh_string_alloc(SALT_SIZE); - RANDOM(options->r, salt->length, salt->data); - name = ssh_format("%lz", options->name); - - e = srp_make_verifier(options->G, options->H, - salt, name, options->passwd); - lsh_string_free(name); - - return e; -} - -static void -do_srp_gen_handler(struct exception_handler *s UNUSED, - const struct exception *e) -{ - werror("lsh_writekey: %z\n", e->msg); - - exit(EXIT_FAILURE); -} - -static struct exception_handler exc_handler = -STATIC_EXCEPTION_HANDLER(do_srp_gen_handler, NULL); - -int main(int argc, char **argv) -{ - struct io_backend *backend = make_io_backend(); - struct srp_gen_options *options - = make_srp_gen_options(backend, &exc_handler); - - argp_parse(&main_argp, argc, argv, 0, NULL, options); - - A_WRITE(options->dest, - sexp_format(srp_gen(options), options->style, 0)); - - io_run(backend); - - return EXIT_SUCCESS; -} diff --git a/lsh/src/srp-gen.c.x b/lsh/src/srp-gen.c.x deleted file mode 100755 index e1ef0d8..0000000 Binary files a/lsh/src/srp-gen.c.x and /dev/null differ diff --git a/lsh/src/srp.h b/lsh/src/srp.h deleted file mode 100755 index 3580f25..0000000 --- a/lsh/src/srp.h +++ /dev/null @@ -1,92 +0,0 @@ -/* srp.h - * - * Declarations for Thomas Wu's Secure Remote Password Protocol - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef SRP_H_INCLUDED -#define SRP_H_INCLUDED - -#include "publickey_crypto.h" - -#define GABA_DECLARE -#include "srp.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name srp_entry) - (vars - (name string) - (salt string) - (verifier bignum))) -*/ - -/* Copies the name, rather than consuming it. */ -struct srp_entry * -make_srp_entry(struct lsh_string *name, struct sexp *e); - -/* Consumes the salt */ -struct sexp * -srp_make_verifier(struct abstract_group *G, - struct hash_algorithm *H, - struct lsh_string *salt, - struct lsh_string *name, - struct lsh_string *passwd); - -void -srp_hash_password(mpz_t x, - struct hash_algorithm *H, - struct lsh_string *salt, - struct lsh_string *name, - struct lsh_string *passwd); - -struct lsh_string * -srp_make_init_msg(struct dh_instance *dh, struct lsh_string *name); - -/* Returns the name */ -struct lsh_string * -srp_process_init_msg(struct dh_instance *self, struct lsh_string *packet); - -struct lsh_string * -srp_make_reply_msg(struct dh_instance *dh, struct srp_entry *entry); - -/* Returns the salt */ -struct lsh_string * -srp_process_reply_msg(struct dh_instance *dh, struct lsh_string *packet); - -struct lsh_string * -srp_make_client_proof(struct dh_instance *dh, - struct lsh_string **m2, - mpz_t x); - -struct lsh_string * -srp_process_client_proof(struct dh_instance *dh, struct lsh_string *packet); - -int -srp_process_server_proof(struct lsh_string *m2, - struct lsh_string *packet); - -struct dh_method * -make_srp1(struct randomness *r); - -#endif /* SRP_H_INCLUDED */ diff --git a/lsh/src/srp.h.x b/lsh/src/srp.h.x deleted file mode 100755 index ec147e4..0000000 Binary files a/lsh/src/srp.h.x and /dev/null differ diff --git a/lsh/src/srp_exchange.c b/lsh/src/srp_exchange.c deleted file mode 100755 index 0644165..0000000 --- a/lsh/src/srp_exchange.c +++ /dev/null @@ -1,426 +0,0 @@ -/* srp_exchange.c - * - * Thomas Wu's Secure Remote Password Protocol - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "srp.h" - -#include "crypto.h" -#include "format.h" -#include "sexp.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -#define GABA_DEFINE -#include "srp.h.x" -#undef GABA_DEFINE - -#if WITH_SRP - -/* We use the following syntax for verifiers: - * - * (srp-verifier ssh-group1 ) - * - * For now, the second element is the name of a group; we could also substitute - * ( (modulo ) (generator ) ) or something like that. - */ - -/* Copies the name, rather than consuming it. */ -struct srp_entry * -make_srp_entry(struct lsh_string *name, struct sexp *e) -{ - struct sexp_iterator *i; - - if (sexp_check_type(e, ATOM_SRP_VERIFIER, &i) - && (SEXP_LEFT(i) == 3) - && sexp_atom_eq(SEXP_GET(i), ATOM_SSH_RING1) ) - { - NEW(srp_entry, res); - const struct lsh_string *salt; - - mpz_init(res->verifier); - - SEXP_NEXT(i); - - salt = sexp2string(SEXP_GET(i)); - if (!salt) - { - KILL(res); - return NULL; - } - res->salt = lsh_string_dup(salt); - - SEXP_NEXT(i); - - /* FIXME: Pass a more restrictive limit to sexp2bignum_u. */ - if (!sexp2bignum_u(SEXP_GET(i), res->verifier, 0)) - { - KILL(res); - return NULL; - } - - res->name = lsh_string_dup(name); - - return res; - } - else - return NULL; -} - -/* Consumes the salt */ -struct sexp * -srp_make_verifier(struct abstract_group *G, - struct hash_algorithm *H, - struct lsh_string *salt, - struct lsh_string *name, - struct lsh_string *passwd) -{ - mpz_t x; - struct sexp *e; - - mpz_init(x); - - srp_hash_password(x, H, salt, name, passwd); - GROUP_POWER(G, x, G->generator, x); - - e = sexp_l(4, - sexp_a(ATOM_SRP_VERIFIER), sexp_a(ATOM_SSH_RING1), - sexp_s(NULL, salt), - sexp_un(x), - -1); - - mpz_clear(x); - - return e; -} - -/* Thomas Wu's Secure Remote Password Protocol, with a fixed group. */ - -void -srp_hash_password(mpz_t x, - struct hash_algorithm *H, - struct lsh_string *salt, - struct lsh_string *name, - struct lsh_string *passwd) -{ - struct lsh_string *h - = hash_string(H, ssh_format("%S%fS", salt, - hash_string(H, ssh_format("%S%S", name, passwd), 1)), - 1); - - bignum_parse_u(x, h->length, h->data); - lsh_string_free(h); -} - -static void -srp_format_proofs(struct dh_instance *dh, - struct lsh_string **m1, - struct lsh_string **m2) -{ - struct mac_algorithm *mac_algorithm - = make_hmac_algorithm(dh->method->H); - struct mac_instance *hmac - = MAKE_MAC(mac_algorithm, - dh->K->length, dh->K->data); - struct lsh_string *s; - - *m1 = lsh_string_alloc(hmac->hash_size); - *m2 = lsh_string_alloc(hmac->hash_size); - - HASH_UPDATE(hmac, - dh->exchange_hash->length, dh->exchange_hash->data); - HASH_DIGEST(hmac, (*m1)->data); - - s = ssh_format("%n%S%S", dh->e, *m1, dh->exchange_hash); - - HASH_UPDATE(hmac, s->length, s->data); - HASH_DIGEST(hmac, (*m2)->data); - - lsh_string_free(s); - KILL(hmac); -} - -/* dh_instance, name -> packet*/ -struct lsh_string * -srp_make_init_msg(struct dh_instance *dh, struct lsh_string *name) -{ - dh_generate_secret(dh->method, dh->secret, dh->e); - dh_hash_update(dh, ssh_format("%S", name), 1); - - debug("srp_make_init_msg: e = %xn\n", dh->e); - return ssh_format("%c%S%n", SSH_MSG_KEXSRP_INIT, name, dh->e); -} - -/* dh_instance, packet -> name */ -struct lsh_string * -srp_process_init_msg(struct dh_instance *self, struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - - struct lsh_string *name; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_KEXSRP_INIT) - && ( (name = parse_string_copy(&buffer) )) - /* FIXME: Pass a more restrictive limit to parse_bignum. */ - && parse_bignum(&buffer, self->e, 0) - && (mpz_cmp_ui(self->e, 1) > 0) - && GROUP_RANGE(self->method->G, self->e) - && parse_eod(&buffer) ) - { - debug("srp_process_init_msg: e = %xn\n", self->e); - return name; - } - else - { - werror("Invalid SSH_MSG_KEXSRP_INIT message.\n"); - return NULL; - } -} - -/* dh_instance -> u */ -static UINT32 -srp_select_u(struct dh_instance *dh) -{ - struct lsh_string *h; - UINT32 u; - - h = hash_string(dh->method->H, ssh_format("%ln", dh->f), 1); - - u = READ_UINT32(h->data); - lsh_string_free(h); - - debug("srp_select_u: u = %xi\n", u); - return u; -} - -/* dh_instance, v -> packet */ -struct lsh_string * -srp_make_reply_msg(struct dh_instance *dh, struct srp_entry *entry) -{ - UINT32 u; - mpz_t tmp; - - debug("srp_make_reply_msg: v = %xn\n", entry->verifier); - - for (;;) - { - /* Loop, in case f or u turns out to be zero */ - dh_generate_secret(dh->method, dh->secret, dh->f); - - debug("srp_make_reply_msg: f - v = %xn\n", dh->f); - - if (!GROUP_ADD(dh->method->G, dh->f, dh->f, entry->verifier)) - { - werror("srp_exchange.c: Found cleartext password by mistake!\n"); - continue; - } - - debug("srp_make_reply_msg: f = %xn\n", dh->f); - - u = srp_select_u(dh); - if (u) - break; - } - - /* Compute (e v^u) ^ b */ - mpz_init(tmp); - - GROUP_SMALL_POWER(dh->method->G, tmp, entry->verifier, u); - GROUP_COMBINE(dh->method->G, tmp, dh->e, tmp); - GROUP_POWER(dh->method->G, tmp, tmp, dh->secret); - - debug("srp_make_reply_msg: K = %xn\n", tmp); - - dh->K = ssh_format("%ln", tmp); - - mpz_clear(tmp); - - /* Update the exchange hash */ - - dh_hash_update(dh, ssh_format("%S%S", entry->name, entry->salt), 1); - dh_hash_digest(dh); - - return ssh_format("%c%S%n", SSH_MSG_KEXSRP_REPLY, entry->salt, dh->f); -} - -/* dh_instance, packet -> salt */ -struct lsh_string * -srp_process_reply_msg(struct dh_instance *dh, struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - struct lsh_string *salt; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_KEXSRP_REPLY) - && ( (salt = parse_string_copy(&buffer) )) - /* FIXME: Pass a more restrictive limit to parse_bignum. */ - && parse_bignum(&buffer, dh->f, 0) - && (mpz_cmp_ui(dh->f, 1) > 0) - && GROUP_RANGE(dh->method->G, dh->f) - && parse_eod(&buffer)) - { - debug("srp_process_reply_msg: f = %xn\n", dh->f); - - /* FIXME: It would be better to keep the u around. Now, we have - * to compute it again later. */ - if (!srp_select_u(dh)) - { - werror("Recived SSH_MSG_KEXSRP_REPLY messge with u = 0.\n"); - lsh_string_free(salt); - return NULL; - } - dh_hash_update(dh, ssh_format("%S", salt), 1); - return salt; - } - else - { - werror("Invalid SSH_MSG_KEXSRP_REPLY message.\n"); - return NULL; - } -} - -/* dh_instance, x -> packet, m2 - * - * x is derived from the password using srp_hash_password */ -struct lsh_string * -srp_make_client_proof(struct dh_instance *dh, - struct lsh_string **m2, - mpz_t x) -{ - UINT32 u = srp_select_u(dh); - mpz_t v; - mpz_t tmp; - struct lsh_string *m1; - - assert(u); - - mpz_init(v); - - /* Compute the verifier */ - GROUP_POWER(dh->method->G, v, dh->method->G->generator, x); - - debug("srp_make_client_proof: v = %xn\n", v); - - if (!GROUP_SUBTRACT(dh->method->G, v, dh->f, v)) - { - mpz_clear(v); - return NULL; - } - - debug("srp_make_client_proof: f - v = %xn\n", v); - - mpz_init(tmp); - - /* Compute the exponent */ - mpz_mul_ui(tmp, x, u); - mpz_add(tmp, tmp, dh->secret); - - GROUP_POWER(dh->method->G, v, v, tmp); - - debug("srp_make_client_proof: K = %xn\n", v); - dh->K = ssh_format("%ln", v); - - mpz_clear(v); - mpz_clear(tmp); - - dh_hash_digest(dh); - srp_format_proofs(dh, &m1, m2); - - return ssh_format("%c%fS", SSH_MSG_KEXSRP_PROOF, m1); -} - -struct lsh_string * -srp_process_client_proof(struct dh_instance *dh, struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - - UINT32 length; - const UINT8 *client_m1; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_KEXSRP_PROOF) - && parse_string(&buffer, &length, &client_m1) - && parse_eod(&buffer)) - { - struct lsh_string *m1; - struct lsh_string *m2; - - srp_format_proofs(dh, &m1, &m2); - - if (!lsh_string_eq_l(m1, length, client_m1)) - { - werror("SRP failed: Received invalid m1 from client.\n"); - lsh_string_free(m1); - lsh_string_free(m2); - - return NULL; - } - lsh_string_free(m1); - return ssh_format("%c%fS", SSH_MSG_KEXSRP_PROOF, - m2); - } - return NULL; -} - -int -srp_process_server_proof(struct lsh_string *m2, - struct lsh_string *packet) -{ - struct simple_buffer buffer; - unsigned msg_number; - - UINT32 length; - const UINT8 *server_m2; - - simple_buffer_init(&buffer, packet->length, packet->data); - - if (parse_uint8(&buffer, &msg_number) - && (msg_number == SSH_MSG_KEXSRP_PROOF) - && parse_string(&buffer, &length, &server_m2) - && parse_eod(&buffer)) - { - return lsh_string_eq_l(m2, length, server_m2); - } - return 0; -} - -struct dh_method * -make_srp1(struct randomness *r) -{ - return make_dh(make_ssh_ring_srp_1(), &sha1_algorithm, r); -} - -#endif /* WITH_SRP */ diff --git a/lsh/src/ssh-conv b/lsh/src/ssh-conv deleted file mode 100755 index 4644d7a..0000000 Binary files a/lsh/src/ssh-conv and /dev/null differ diff --git a/lsh/src/ssh.h b/lsh/src/ssh.h deleted file mode 100755 index 35108c0..0000000 --- a/lsh/src/ssh.h +++ /dev/null @@ -1,190 +0,0 @@ -/* ssh.h - * - */ - -#ifndef LSH_SSH_H_INCLUDED -#define LSH_SSH_H_INCLUDED - -/* 1-19 Transport layer generic (e.g. disconnect, ignore, debug, etc) */ - -#define SSH_MSG_DISCONNECT 1 -#define SSH_MSG_IGNORE 2 -#define SSH_MSG_UNIMPLEMENTED 3 -#define SSH_MSG_DEBUG 4 -#define SSH_MSG_SERVICE_REQUEST 5 -#define SSH_MSG_SERVICE_ACCEPT 6 - -/* 20-29 Algorithm negotiation */ - -#define SSH_MSG_KEXINIT 20 -#define SSH_MSG_NEWKEYS 21 - -/* 30-49 Key exchange method specific (numbers can be reused for - * different authentication methods) */ - -#define SSH_MSG_KEXDH_INIT 30 -#define SSH_MSG_KEXDH_REPLY 31 - -/* SRP based key exchange (experimental) */ - -#define SSH_MSG_KEXSRP_INIT 30 -#define SSH_MSG_KEXSRP_REPLY 31 -#define SSH_MSG_KEXSRP_PROOF 32 - -/* Diffie-hellman with group negotiation (experimental) */ - -#define SSH_MSG_KEX_DH_MOD_GROUPS 30 -#define SSH_MSG_KEX_DH_MOD_INIT 31 -#define SSH_MSG_KEX_DH_MOD_REPLY 32 - -/* 50-59 User authentication generic */ - -#define SSH_FIRST_USERAUTH_GENERIC 50 - -#define SSH_MSG_USERAUTH_REQUEST 50 -#define SSH_MSG_USERAUTH_FAILURE 51 -#define SSH_MSG_USERAUTH_SUCCESS 52 -#define SSH_MSG_USERAUTH_BANNER 53 - -/* 60-79 User authentication method specific (numbers can be reused - * for different authentication methods) */ - -#define SSH_FIRST_USERAUTH_SPECIFIC 60 - -#define SSH_MSG_USERAUTH_PK_OK 60 -#define SSH_MSG_USERAUTH_PASSWD_CHANGEREQ 60 - -/* 80-89 Connection protocol generic */ - -#define SSH_FIRST_CONNECTION_GENERIC 80 - -#define SSH_MSG_GLOBAL_REQUEST 80 -#define SSH_MSG_REQUEST_SUCCESS 81 -#define SSH_MSG_REQUEST_FAILURE 82 - -/* 90-127 Channel related messages */ - -#define SSH_FIRST_CONNECTION_CHANNELS 90 - -#define SSH_MSG_CHANNEL_OPEN 90 -#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION 91 -#define SSH_MSG_CHANNEL_OPEN_FAILURE 92 -#define SSH_MSG_CHANNEL_WINDOW_ADJUST 93 -#define SSH_MSG_CHANNEL_DATA 94 -#define SSH_MSG_CHANNEL_EXTENDED_DATA 95 -#define SSH_MSG_CHANNEL_EOF 96 -#define SSH_MSG_CHANNEL_CLOSE 97 -#define SSH_MSG_CHANNEL_REQUEST 98 -#define SSH_MSG_CHANNEL_SUCCESS 99 -#define SSH_MSG_CHANNEL_FAILURE 100 - -/* 128-191 Reserved */ - -#define SSH_FIRST_RESERVED 128 - -/* 192-255 Local extensions */ -#define SSH_FIRST_LOCAL 192 - -/* Disconnecting */ - -#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 -#define SSH_DISCONNECT_PROTOCOL_ERROR 2 -#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3 - -/* Formely known as SSH_DISCONNECT_HOST_AUTHENTICATION_FAILED */ -#define SSH_DISCONNECT_RESERVED 4 - -#define SSH_DISCONNECT_MAC_ERROR 5 -#define SSH_DISCONNECT_COMPRESSION_ERROR 6 -#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7 -#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 -#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 -#define SSH_DISCONNECT_CONNECTION_LOST 10 -#define SSH_DISCONNECT_BY_APPLICATION 11 -#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12 -#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13 -#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14 -#define SSH_DISCONNECT_ILLEGAL_USER_NAME 15 - -/* Channels */ -#define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 1 -#define SSH_OPEN_CONNECT_FAILED 2 -#define SSH_OPEN_UNKNOWN_CHANNEL_TYPE 3 -#define SSH_OPEN_RESOURCE_SHORTAGE 4 - -/* Extended data */ - -#define SSH_EXTENDED_DATA_STDERR 1 - -/* pty op.codes */ -#define SSH_TTY_OP_END 0 -#define SSH_VINTR 1 -#define SSH_VQUIT 2 -#define SSH_VERASE 3 -#define SSH_VKILL 4 -#define SSH_VEOF 5 -#define SSH_VEOL 6 -#define SSH_VEOL2 7 -#define SSH_VSTART 8 -#define SSH_VSTOP 9 -#define SSH_VSUSP 10 -#define SSH_VDSUSP 11 -#define SSH_VREPRINT 12 -#define SSH_VWERASE 13 -#define SSH_VLNEXT 14 -#define SSH_VFLUSH 15 -#define SSH_VSWTCH 16 -#define SSH_VSTATUS 17 -#define SSH_VDISCARD 18 -#define SSH_IGNPAR 30 -#define SSH_PARMRK 31 -#define SSH_INPCK 32 -#define SSH_ISTRIP 33 -#define SSH_INLCR 34 -#define SSH_IGNCR 35 -#define SSH_ICRNL 36 -#define SSH_IUCLC 37 -#define SSH_IXON 38 -#define SSH_IXANY 39 -#define SSH_IXOFF 40 -#define SSH_IMAXBEL 41 -#define SSH_ISIG 50 -#define SSH_ICANON 51 -#define SSH_XCASE 52 -#define SSH_ECHO 53 -#define SSH_ECHOE 54 -#define SSH_ECHOK 55 -#define SSH_ECHONL 56 -#define SSH_NOFLSH 57 -#define SSH_TOSTOP 58 -#define SSH_IEXTEN 59 -#define SSH_ECHOCTL 60 -#define SSH_ECHOKE 61 -#define SSH_PENDIN 62 -#define SSH_OPOST 70 -#define SSH_OLCUC 71 -#define SSH_ONLCR 72 -#define SSH_OCRNL 73 -#define SSH_ONOCR 74 -#define SSH_ONLRET 75 -#define SSH_CS7 90 -#define SSH_CS8 91 -#define SSH_PARENB 92 -#define SSH_PARODD 93 -#define SSH_TTY_OP_ISPEED 128 -#define SSH_TTY_OP_OSPEED 129 -#define SSH_TTY_OP_RESERVED 160 - -/* Limits */ - -/* Default max length of packet payload */ -#define SSH_MAX_PACKET 0x8000 - -/* Add this to get the maximum total length, including length, - * padding, MAC etc */ -#define SSH_MAX_PACKET_FUZZ (35000 - SSH_MAX_PACKET) - -/* Subtract this to get a reasonable max_packet value for a channel. */ -#define SSH_CHANNEL_MAX_PACKET_FUZZ 100 - -#endif /* LSH_SSH_H_INCLUDED */ diff --git a/lsh/src/ssh1_fallback.c b/lsh/src/ssh1_fallback.c deleted file mode 100755 index 9a47ad7..0000000 --- a/lsh/src/ssh1_fallback.c +++ /dev/null @@ -1,129 +0,0 @@ -/* ssh1_fallback.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "ssh1_fallback.h" - -#include "io.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#define GABA_DEFINE -#include "ssh1_fallback.h.x" -#undef GABA_DEFINE - -#include "ssh1_fallback.c.x" - -/* GABA: - (class - (name sshd1) - (super ssh1_fallback) - (vars - ; Full path to sshd1 - (sshd1 . "char *"))) -*/ - -static void -fall_back_to_ssh1(struct ssh1_fallback *c, - int fd, UINT32 length, const UINT8 *line, - struct exception_handler *e) -{ - CAST(sshd1, closure, c); - - /* We fork a SSH1 server to handle this connection. */ - - pid_t pid; - pid = fork(); - if (pid < 0) - { - werror("Forking to start fallback sshd1 failed with %z\n", - STRERROR(errno)); - - EXCEPTION_RAISE(e, make_protocol_exception(SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, - "Falling back to ssh1 failed.")); - } - else if (pid == 0) - { - /* Child process */ - - /* Create a NUL-terminated version string. */ - char *version = alloca(length + 1); - memcpy(version, line, length); - version[length] = '\0'; - - /* NOTE: All fds should have the close-on-exec flag set. - * So all we have to do is to dup the socket fd to stdin - * and stdout. */ - - /* Reset the fd to blocking mode. */ - io_set_blocking(fd); - - if (dup2(fd, STDIN_FILENO) < 0) - { - werror("lshd: fall_back_to_ssh1: Failed to dup socket to STDIN.\n"); - _exit(EXIT_FAILURE); - } - if (dup2(fd, STDOUT_FILENO) < 0) - { - werror("lshd: fall_back_to_ssh1: Failed to dup socket to STDOUT.\n"); - _exit(EXIT_FAILURE); - } - - /* What should we do about stderr? We can probably share it - * (that would be more difficult if we had put it into - * non-blocking mode, but we haven't). */ - - execl(closure->sshd1, closure->sshd1, - "-i", /* inetd mode */ - "-V" ,version, /* Compatibility mode */ - NULL); - werror("lshd: fall_back_to_ssh1: execl failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - else - { /* pid > 0 */ - /* Parent */ - static const struct exception delegate - = STATIC_EXCEPTION(EXC_FINISH_IO, - "Forked an ssh1 process to handle the connection."); - - /* This tells the backend to close our socket. */ - EXCEPTION_RAISE(e, &delegate); - } -} - -struct ssh1_fallback *make_ssh1_fallback(char *sshd1) -{ - NEW(sshd1, closure); - - closure->super.fallback = fall_back_to_ssh1; - closure->sshd1 = sshd1; - - return &closure->super; -} - diff --git a/lsh/src/ssh1_fallback.c.x b/lsh/src/ssh1_fallback.c.x deleted file mode 100755 index b9f4507..0000000 Binary files a/lsh/src/ssh1_fallback.c.x and /dev/null differ diff --git a/lsh/src/ssh1_fallback.h b/lsh/src/ssh1_fallback.h deleted file mode 100755 index b75e5c4..0000000 --- a/lsh/src/ssh1_fallback.h +++ /dev/null @@ -1,47 +0,0 @@ -/* ssh1_fallback.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SSH1_FALLBACK_H_INCLUDED -#define LSH_SSH1_FALLBACK_H_INCLUDED - -#include "exception.h" - -#define GABA_DECLARE -#include "ssh1_fallback.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name ssh1_fallback) - (vars - (fallback method void - "int fd" "UINT32 length" "const UINT8 *line" - "struct exception_handler *e"))) -*/ - -#define SSH1_FALLBACK(f, fd, length, line, e) \ -((f)->fallback((f), (fd), (length), (line), (e))) - -struct ssh1_fallback *make_ssh1_fallback(char *sshd1); - -#endif /* LSH_SSH1_FALLBACK_H_INCLUDED */ diff --git a/lsh/src/ssh1_fallback.h.x b/lsh/src/ssh1_fallback.h.x deleted file mode 100755 index f0b3460..0000000 Binary files a/lsh/src/ssh1_fallback.h.x and /dev/null differ diff --git a/lsh/src/string_buffer.c b/lsh/src/string_buffer.c deleted file mode 100755 index 5404658..0000000 --- a/lsh/src/string_buffer.c +++ /dev/null @@ -1,205 +0,0 @@ -/* string_buffer.c - * - * Functions for building strings whose lengths are not known from the - * start. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "string_buffer.h" - -#include "xalloc.h" - -#include -#include - -struct string_node -{ - struct string_node *prev; - struct lsh_string *s; -}; - -void string_buffer_init(struct string_buffer *buffer, - UINT32 guess) -{ - buffer->partial = lsh_string_alloc(guess); - buffer->left = guess; - buffer->current = buffer->partial->data; - - buffer->tail = NULL; - /* buffer->nlist = 0; */ - - buffer->total = 0; -} - -void string_buffer_clear(struct string_buffer *buffer) -{ - struct string_node *n; - - lsh_string_free(buffer->partial); - for (n = buffer->tail; n; ) - { - struct string_node *old = n; - n = old->prev; - - lsh_string_free(old->s); - lsh_space_free(old); - } -} - -/* Assumes that the buffer->partial string is full */ -void string_buffer_grow(struct string_buffer *buffer, UINT32 increment) -{ - struct string_node *n; - - NEW_SPACE(n); - - buffer->total += buffer->partial->length; - - n->s = buffer->partial; - n->prev = buffer->tail; - buffer->tail = n; - - buffer->partial = lsh_string_alloc(increment); - buffer->current = buffer->partial->data; - buffer->left = increment; -} - -#if 0 -void string_buffer_putc(struct string_buffer *buffer, UINT8 c) -{ - if (!buffer->left) - string_buffer_grow(buffer, buffer->increment); - - assert(buffer->left); - - *buffer->current++ = c; - buffer->left--; -} - -void string_buffer_write(struct string_buffer *buffer, - UINT32 length, const UINT8 *s) -{ - if (length > buffer->left) - { - memcpy(buffer->current, s, buffer->left); - s += buffer->left; - length -= buffer->left; - string_buffer_grow(MAX(length, buffer->increment)); - } - - assert(length <= buffer->left); - - memcpy(buffer->current, s, length); - buffer->current += length; - buffer->left -= length; -} - -struct lsh_string *string_buffer_final_write(struct string_buffer *buffer, - UINT32 length, const UINT8 *s) -{ - UINT32 final = buffer->total + length; - - if ( (length < left) && !buffer->tail) - { - /* This should be the usual case. */ - if (length) - memcpy(buffer->current, s, length); - - buffer->partial->length = final - return buffer->partial; - } - else - { - struct lsh_string *res = lsh_string_alloc(final); - UINT8 *p = res->data + final; - struct string_node *n; - - if (length) - { - p -= length; - memcpy(p, s, length); - } - - length = buffer->partial->length - buffer->left; - p -= length; - memcpy(p, buffer->partial->data, length); - lsh_string_free(buffer->partial); - - for (n = buffer->tail; n; ) - { - struct string_node *old = n; - n = n->next; - - p -= old->s->length; - memcpy(p, old->s->data, old->s->length); - - lsh_string_free(old->s); - lsh_space_free(old); - } - - assert(p == res->data); - - return res; - } -} -#endif - -struct lsh_string *string_buffer_final(struct string_buffer *buffer, - UINT32 left_over) -{ - UINT32 length = buffer->partial->length - left_over; - UINT32 final = buffer->total + length; - - if (!buffer->tail) - { - /* This should be the usual case. */ - - buffer->partial->length = final; - return buffer->partial; - } - else - { - struct lsh_string *res = lsh_string_alloc(final); - UINT8 *p = res->data + final; - struct string_node *n; - - p -= length; - memcpy(p, buffer->partial->data, length); - lsh_string_free(buffer->partial); - - for (n = buffer->tail; n; ) - { - struct string_node *old = n; - n = n->prev; - - p -= old->s->length; - memcpy(p, old->s->data, old->s->length); - - lsh_string_free(old->s); - lsh_space_free(old); - } - - assert(p == res->data); - - return res; - } -} diff --git a/lsh/src/string_buffer.h b/lsh/src/string_buffer.h deleted file mode 100755 index af84cc5..0000000 --- a/lsh/src/string_buffer.h +++ /dev/null @@ -1,78 +0,0 @@ -/* string_buffer.h - * - * Functions for building strings whose lengths are not known from the - * start. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_STRING_BUFFER_H_INCLUDED -#define LSH_STRING_BUFFER_H_INCLUDED - -/* We optimize for operations where we can guess an upper limit which - * is reasonable most of the time. */ - -#include "lsh.h" - -struct string_node; - -struct string_buffer -{ -#if 0 - /* Fail if the buffer grows larger than this value; zero means that - * there is no limit. */ - UINT32 max; - - /* Amount of space to allocate at a time */ - UINT32 increment; -#endif - - struct lsh_string *partial; /* Partial block. */ - - UINT32 left; - UINT8 *current; - - /* List of blocks beyond the first one */ - struct string_node *tail; -#if 0 - unsigned nlist; /* Number of nodes */ -#endif - UINT32 total; /* Total string length, in list (i.e. not including - * partial) */ -}; - -void string_buffer_init(struct string_buffer *buffer, UINT32 guess); - -#if 0 -int string_buffer_putc(struct string_buffer *buffer, UINT8 c); -int string_buffer_write(struct string_buffer *buffer, - UINT32 length, const UINT8 *s); -#endif - -void string_buffer_clear(struct string_buffer *buffer); - -/* Assumes that the buffer->partial string is full */ -void string_buffer_grow(struct string_buffer *buffer, UINT32 increment); - -struct lsh_string *string_buffer_final(struct string_buffer *buffer, - UINT32 left); - -#endif /* LSH_STRING_BUFFER_H_INCLUDED */ diff --git a/lsh/src/suspend.c b/lsh/src/suspend.c deleted file mode 100644 index 60ed2a8..0000000 --- a/lsh/src/suspend.c +++ /dev/null @@ -1,128 +0,0 @@ -/* suspend.c - * - * Handle process suspend for the client programs. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 - */ - -#include "suspend.h" - -#include "tty.h" -#include "werror.h" - -#include -#include -#include - -#include - -#if HAVE_UNISTD_H -# include -#endif - -#include -#include -#include - -static struct termios original_mode; - -static int tty_fd = -1; - -/* On SIGTSTP, we restore the tty mode to the origanal. - * On SIGCONT, we restore it, and the stdio fd flags, to what we hade before - * the suspend. */ -static void -stop_handler(int signum) -{ - struct termios mine; - int need_tty_reset; - int stdin_flags; - int stdout_flags; - int stderr_flags; - - assert(signum == SIGTSTP); - - stdin_flags = fcntl(STDIN_FILENO, F_GETFL); - stdout_flags = fcntl(STDOUT_FILENO, F_GETFL); - stderr_flags = fcntl(STDERR_FILENO, F_GETFL); - - need_tty_reset = (tty_fd > 0) ? tty_getattr(tty_fd, &mine) : 0; - - if (need_tty_reset) - tty_setattr(tty_fd, &original_mode); - -#ifndef MACOS - kill(getpid(), SIGSTOP); -#endif - - if (need_tty_reset) - tty_setattr(tty_fd, &mine); - - if (stdin_flags >= 0) - fcntl(STDIN_FILENO, F_SETFL, stdin_flags); - - if (stdout_flags >= 0) - fcntl(STDOUT_FILENO, F_SETFL, stdin_flags); - - if (stderr_flags >= 0) - fcntl(STDERR_FILENO, F_SETFL, stdin_flags); -} - -void -suspend_install_handler(void) -{ - struct sigaction stop; - - memset(&stop, 0, sizeof(stop)); - stop.sa_handler = stop_handler; - sigemptyset(&stop.sa_mask); - stop.sa_flags = 0; - - if (sigaction(SIGTSTP, &stop, NULL) < 0) - werror("Failed to install SIGTSTP handler (errno = %i): %z\n", - errno, STRERROR(errno)); -} - -void -suspend_handle_tty(int fd) -{ - tty_fd = fd; - - if (!tty_getattr(fd, &original_mode)) - werror("install_suspend_handler: tty_getattr failed (errno = %i): %z\n", - errno, STRERROR(errno)); -} - - -/* A callback that suspends the process. */ -static void -do_suspend(struct lsh_callback *self UNUSED) -{ -#ifndef MACOS - if (kill(getpid(), SIGTSTP) < 0) -#endif - werror("do_suspend: kill failed (errno = %i): %z\n", - errno, STRERROR(errno)); -} - -/* FIXME: Use const? */ -struct lsh_callback -suspend_callback = { STATIC_HEADER, do_suspend }; diff --git a/lsh/src/suspend.h b/lsh/src/suspend.h deleted file mode 100644 index 9774cf8..0000000 --- a/lsh/src/suspend.h +++ /dev/null @@ -1,40 +0,0 @@ -/* suspend.h - * - * Handle process suspend for the client programs. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_SUSPEND_H_INCLUDED -#define LSH_SUSPEND_H_INCLUDED - -#include "io.h" - -void -suspend_install_handler(void); - -void -suspend_handle_tty(int fd); - -extern struct lsh_callback -suspend_callback; - -#endif /* LSH_SUSPEND_H_INCLUDED */ diff --git a/lsh/src/tcpforward.c b/lsh/src/tcpforward.c deleted file mode 100755 index e8c8bf7..0000000 --- a/lsh/src/tcpforward.c +++ /dev/null @@ -1,535 +0,0 @@ -/* tcpforward.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "tcpforward.h" - -#include "channel_commands.h" -#include "channel_forward.h" -#include "format.h" -#include "io_commands.h" -#include "ssh.h" -#include "werror.h" - -#include -#include -#include - - -#define GABA_DEFINE -#include "tcpforward.h.x" -#undef GABA_DEFINE - -#include "tcpforward.c.x" - -/* Structures used to keep track of forwarded ports */ - -static struct local_port * -make_local_port(struct address_info *address, struct lsh_fd *socket) -{ - NEW(local_port, self); - - self->super.listen = address; - self->socket = socket; - return self; -} - -struct remote_port * -make_remote_port(struct address_info *listen, - struct command *callback) -{ - NEW(remote_port, self); - - self->super.listen = listen; - self->callback = callback; - - return self; -} - -static struct forwarded_port * -lookup_forward(struct object_queue *q, - UINT32 length, const UINT8 *ip, UINT32 port) -{ - FOR_OBJECT_QUEUE(q, n) - { - CAST_SUBTYPE(forwarded_port, f, n); - - if ( (port == f->listen->port) - && lsh_string_eq_l(f->listen->ip, length, ip) ) - return f; - } - return NULL; -} - -static struct local_port * -remove_forward(struct object_queue *q, int null_ok, - UINT32 length, const UINT8 *ip, UINT32 port) -{ - FOR_OBJECT_QUEUE(q, n) - { - CAST(local_port, f, n); - - if ( (port == f->super.listen->port) - && lsh_string_eq_l(f->super.listen->ip, length, ip) ) - { - if (null_ok || f->socket) - { - FOR_OBJECT_QUEUE_REMOVE(q, n); - return f; - } - else return NULL; - } - } - return NULL; -} - - -/* Handle channel open requests */ - -/* Exception handler that promotes connect and dns errors to - * CHANNEL_OPEN exceptions */ - -static void -do_exc_tcip_connect_handler(struct exception_handler *s, - const struct exception *e) -{ - switch(e->type) - { - case EXC_IO_CONNECT: - case EXC_RESOLVE: - EXCEPTION_RAISE(s->parent, - make_channel_open_exception(SSH_OPEN_CONNECT_FAILED, - e->msg)); - break; - default: - EXCEPTION_RAISE(s->parent, e); - } -} - -static struct exception_handler * -make_exc_tcpip_connect_handler(struct exception_handler *parent, - const char *context) -{ - return make_exception_handler(do_exc_tcip_connect_handler, parent, context); -} - -/* GABA: - (class - (name open_forwarded_tcpip_continuation) - (super command_continuation) - (vars - (up object command_continuation) - (connection object ssh_connection))) -*/ - -/* NOTE: This continuation should not duplicate the work done by - * channel_open_continuation. It must also not send any packets on the - * channel, because it is not yet completely initialized. */ -static void -do_open_forwarded_tcpip_continuation(struct command_continuation *s, - struct lsh_object *x) -{ - CAST(open_forwarded_tcpip_continuation, self, s); - CAST(channel_forward, channel, x); - - assert(channel); - - channel_forward_start_io(channel); - - COMMAND_RETURN(self->up, channel); -} - -static struct command_continuation * -make_open_forwarded_tcpip_continuation(struct ssh_connection *connection, - struct command_continuation *c) -{ - NEW(open_forwarded_tcpip_continuation, self); - self->super.c = do_open_forwarded_tcpip_continuation; - self->up = c; - self->connection = connection; - - return &self->super; -} - - -/* GABA: - (class - (name channel_open_direct_tcpip) - (super channel_open) - (vars - (callback object command))) -*/ - -static void -do_channel_open_direct_tcpip(struct channel_open *s, - struct ssh_connection *connection, - struct channel_open_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(channel_open_direct_tcpip, closure, s); - - struct lsh_string *dest_host; - UINT32 dest_port; - const UINT8 *orig_host; - UINT32 orig_host_length; - UINT32 orig_port; - - if ( (dest_host = parse_string_copy(args)) - && parse_uint32(args, &dest_port) - && parse_string(args, &orig_host_length, &orig_host) - && parse_uint32(args, &orig_port) - && parse_eod(args)) - { - verbose("direct-tcpip connection attempt\n"); - - COMMAND_CALL(closure->callback, - make_address_info(dest_host, dest_port), - make_open_forwarded_tcpip_continuation(connection, c), - /* NOTE: This exception handler will be associated with the - * fd for its entire lifetime. */ - make_exc_tcpip_connect_handler(e, HANDLER_CONTEXT)); - } - else - { - lsh_string_free(dest_host); - - werror("do_channel_open_direct_tcpip: Invalid message!\n"); - PROTOCOL_ERROR(connection->e, "Invalid CHANNEL_OPEN direct-tcp message."); - } -} - -struct channel_open * -make_channel_open_direct_tcpip(struct command *callback) -{ - NEW(channel_open_direct_tcpip, self); - - self->super.handler = do_channel_open_direct_tcpip; - self->callback = callback; - return &self->super; -} - - -/* Global requests for forwarding */ - -/* GABA: - (class - (name tcpip_forward_request_continuation) - (super command_continuation) - (vars - (forward object local_port) - (c object command_continuation))) -*/ - -static void -do_tcpip_forward_request_continuation(struct command_continuation *c, - struct lsh_object *x) -{ - CAST(tcpip_forward_request_continuation, self, c); - CAST(lsh_fd, fd, x); - - assert(self->forward); - assert(fd); - - self->forward->socket = fd; - - COMMAND_RETURN(self->c, &self->forward->super.super); -} - -static struct command_continuation * -make_tcpip_forward_request_continuation(struct local_port *forward, - struct command_continuation *c) -{ - NEW(tcpip_forward_request_continuation, self); - - self->forward = forward; - self->c = c; - - self->super.c = do_tcpip_forward_request_continuation; - - return &self->super; -} - -/* GABA: - (class - (name tcpip_forward_request_handler) - (super exception_handler) - (vars - (connection object ssh_connection) - (forward object local_port))) -*/ - -static void -do_tcpip_forward_request_exc(struct exception_handler *s, - const struct exception *e) -{ - CAST(tcpip_forward_request_handler, self, s); - - switch(e->type) - { - case EXC_IO_LISTEN: - case EXC_RESOLVE: - { - struct local_port *port - = remove_forward(&self->connection->table->local_ports, - 1, - self->forward->super.listen->ip->length, - self->forward->super.listen->ip->data, - self->forward->super.listen->port); - assert(port); - assert(port == self->forward); - EXCEPTION_RAISE(s->parent, - make_simple_exception(EXC_GLOBAL_REQUEST, - e->msg)); - break; - } - default: - if (e->type & EXC_IO) - { - werror("I/O error on forwarded connection: %z\n", - e->msg); - } - else - EXCEPTION_RAISE(self->super.parent, e); - } -} - -static struct exception_handler * -make_tcpip_forward_request_exc(struct ssh_connection *connection, - struct local_port *forward, - struct exception_handler *parent, - const char *context) -{ - NEW(tcpip_forward_request_handler, self); - self->super.raise = do_tcpip_forward_request_exc; - self->super.parent = parent; - self->super.context = context; - - self->connection = connection; - self->forward = forward; - - return &self->super; -} - -/* GABA: - (class - (name tcpip_forward_request) - (super global_request) - (vars - ; The callback is invoked for each request, with the port as - ; argument. If successful, it should return the fd object - ; associated with the listening port. It need not remember the port; - ; the continuation installed by do_tcpip_forward_request - ; takes care of that. - (callback object command))) -*/ - -static void -do_tcpip_forward_request(struct global_request *s, - struct ssh_connection *connection, - UINT32 type UNUSED, - int want_reply UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(tcpip_forward_request, self, s); - struct lsh_string *bind_host; - UINT32 bind_port; - - if ((bind_host = parse_string_copy(args)) - && parse_uint32(args, &bind_port) - && parse_eod(args)) - { - struct address_info *a = make_address_info(bind_host, bind_port); - struct local_port *forward; - - if (bind_port < 1024) - { - werror("Denying forwarding of privileged port %i.\n", bind_port); - COMMAND_RETURN(c, NULL); - return; - } - - if (lookup_forward(&connection->table->local_ports, - bind_host->length, bind_host->data, bind_port)) - { - static const struct exception again = - STATIC_EXCEPTION(EXC_GLOBAL_REQUEST, "An already requested tcp-forward requested again"); - - verbose("An already requested tcp-forward requested again\n"); - EXCEPTION_RAISE(e, &again); - return; - } - - verbose("Adding forward-tcpip\n"); - forward = make_local_port(a, NULL); - object_queue_add_head(&connection->table->local_ports, - &forward->super.super); - - { - COMMAND_CALL(self->callback, - a, - make_tcpip_forward_request_continuation(forward, c), - make_tcpip_forward_request_exc(connection, forward, - e, HANDLER_CONTEXT)); - - return; - } - } - else - { - werror("Incorrectly formatted tcpip-forward request\n"); - PROTOCOL_ERROR(e, "Invalid tcpip-forward message."); - } -} - -struct global_request *make_tcpip_forward_request(struct command *callback) -{ - NEW(tcpip_forward_request, self); - - self->super.handler = do_tcpip_forward_request; - self->callback = callback; - - return &self->super; -} - -static void -do_tcpip_cancel_forward(struct global_request *s UNUSED, - struct ssh_connection *connection, - UINT32 type UNUSED, - int want_reply UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - UINT32 bind_host_length; - const UINT8 *bind_host; - UINT32 bind_port; - - if (parse_string(args, &bind_host_length, &bind_host) && - parse_uint32(args, &bind_port) && - parse_eod(args)) - { - /* FIXME: Using null_ok == 0 is not quite right. If the - * tcpip_forward_hook doesn't return immediately, and we receive - * a cancel request before the forwarding is setup (which should - * be ok, if the forwarding was requested with want_reply == 0), - * cancelling fails and the client has to try again later. */ - - struct local_port *port - = remove_forward(&connection->table->local_ports, 0, - bind_host_length, - bind_host, - bind_port); - - if (port) - { - assert(port->socket); - verbose("Cancelling a requested tcpip-forward.\n"); - - close_fd(port->socket); - port->socket = NULL; - - COMMAND_RETURN(c, NULL); - return; - } - else - { - static const struct exception notfound = - STATIC_EXCEPTION(EXC_GLOBAL_REQUEST, "Could not find tcpip-forward to cancel"); - verbose("Could not find tcpip-forward to cancel\n"); - - EXCEPTION_RAISE(e, ¬found); - return; - } - } - else - { - werror("Incorrectly formatted cancel-tcpip-forward request\n"); - PROTOCOL_ERROR(connection->e, "Invalid cancel-tcpip-forward message."); - } -} - -struct global_request tcpip_cancel_forward = -{ STATIC_HEADER, do_tcpip_cancel_forward }; - - -/* Remote forwarding */ - -static void -do_channel_open_forwarded_tcpip(struct channel_open *s UNUSED, - struct ssh_connection *connection, - struct channel_open_info *info UNUSED, - struct simple_buffer *args, - struct command_continuation *c, - struct exception_handler *e) -{ - UINT32 listen_ip_length; - const UINT8 *listen_ip; - UINT32 listen_port; - struct lsh_string *peer_host = NULL; - UINT32 peer_port; - - if (parse_string(args, &listen_ip_length, &listen_ip) - && parse_uint32(args, &listen_port) - && (peer_host = parse_string_copy(args)) - && parse_uint32(args, &peer_port) - && parse_eod(args)) - { - CAST(remote_port, port, - lookup_forward(&connection->table->remote_ports, - listen_ip_length, listen_ip, listen_port)); - - if (port && port->callback) - { - COMMAND_CALL(port->callback, - make_address_info(peer_host, peer_port), - make_open_forwarded_tcpip_continuation(connection, c), - /* NOTE: This exception handler will be - * associated with the fd for its entire - * lifetime. */ - make_exc_tcpip_connect_handler(e, HANDLER_CONTEXT)); - return; - } - werror("Received a forwarded-tcpip request on a port for which we\n" - "haven't requested forwarding. Denying.\n"); - - lsh_string_free(peer_host); - EXCEPTION_RAISE(e, - make_channel_open_exception(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, - "Unexpected tcpip-forward request")); - return; - } - else - { - werror("do_channel_open_forwarded_tcpip: Invalid message!\n"); - - lsh_string_free(peer_host); - PROTOCOL_ERROR(e, "Invalid tcpip-forward message"); - } -} - -struct channel_open channel_open_forwarded_tcpip = -{ STATIC_HEADER, do_channel_open_forwarded_tcpip}; diff --git a/lsh/src/tcpforward.c.x b/lsh/src/tcpforward.c.x deleted file mode 100755 index d5a209f..0000000 Binary files a/lsh/src/tcpforward.c.x and /dev/null differ diff --git a/lsh/src/tcpforward.h b/lsh/src/tcpforward.h deleted file mode 100755 index 2c33a6c..0000000 --- a/lsh/src/tcpforward.h +++ /dev/null @@ -1,85 +0,0 @@ -/* tcpforward.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_TCPFORWARD_H_INCLUDED -#define LSH_TCPFORWARD_H_INCLUDED - -#include "channel.h" -#include "command.h" -#include "io.h" -#include "resource.h" -#include "xalloc.h" - -#define GABA_DECLARE -#include "tcpforward.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name forwarded_port) - (vars - ; this could store the type of this forward - ; tcp, udp etc. Or we could invent relevant methods - ; and subclasses. - ; (type . int) - - (listen object address_info))) -*/ - -/* GABA: - (class - (name local_port) - (super forwarded_port) - (vars - ; socket == NULL means that we are setting up a forward for this port, - ; but are not done yet. - (socket object lsh_fd))) -*/ - -/* Used by the client to keep track of remotely forwarded ports */ -/* GABA: - (class - (name remote_port) - (super forwarded_port) - (vars - ; Invoked when a forwarded_tcpip request is received. - ; Called with the struct address_info *peer as argument. - (callback object command))) -*/ - -struct remote_port * -make_remote_port(struct address_info *listen, - struct command *callback); - -struct channel_open * -make_channel_open_direct_tcpip(struct command *callback); - -extern struct channel_open channel_open_forwarded_tcpip; - -struct global_request * -make_tcpip_forward_request(struct command *callback); - -extern struct global_request tcpip_cancel_forward; - -#endif /* LSH_TCPFORWARD_H_INCLUDED */ diff --git a/lsh/src/tcpforward.h.x b/lsh/src/tcpforward.h.x deleted file mode 100755 index ea0e175..0000000 Binary files a/lsh/src/tcpforward.h.x and /dev/null differ diff --git a/lsh/src/tcpforward_commands.c b/lsh/src/tcpforward_commands.c deleted file mode 100755 index a494b8b..0000000 --- a/lsh/src/tcpforward_commands.c +++ /dev/null @@ -1,529 +0,0 @@ -/* tcpforward_commands.c - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "tcpforward_commands.h" - -#include "atoms.h" -#include "channel_commands.h" -#include "channel_forward.h" -#include "connection_commands.h" -#include "format.h" -#include "io_commands.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include - -/* Forward declarations */ - -extern struct command_2 open_direct_tcpip; -extern struct command_2 remote_listen_command; -extern struct command_2 open_forwarded_tcpip; -extern struct command tcpip_start_io; -extern struct command tcpip_connect_io; - -struct install_info install_direct_tcpip_handler; -struct install_info install_forwarded_tcpip_handler; - -/* FIXME: Should be static? */ -struct command make_direct_tcpip_handler; - -struct install_info install_tcpip_forward_handler; - -/* FIXME: Should be static? */ -struct command make_tcpip_forward_handler; - -#define OPEN_DIRECT_TCPIP (&open_direct_tcpip.super.super) -#define REMOTE_LISTEN (&remote_listen_command.super.super) -#define TCPIP_START_IO (&tcpip_start_io.super) -#define TCPIP_CONNECT_IO (&tcpip_connect_io.super) -#define OPEN_FORWARDED_TCPIP (&open_forwarded_tcpip.super.super) -#define DIRECT_TCPIP_HANDLER (&make_direct_tcpip_handler.super) -#define INSTALL_DIRECT_TCPIP (&install_direct_tcpip_handler.super.super.super) - -static struct catch_report_collect catch_channel_open; -#define CATCH_CHANNEL_OPEN (&catch_channel_open.super.super) - -#include "tcpforward_commands.c.x" - -static struct report_exception_info open_tcpip_report = -STATIC_REPORT_EXCEPTION_INFO(EXC_ALL, EXC_CHANNEL_OPEN, "Failed to open tcpip channel"); - -static struct catch_report_collect catch_channel_open -= STATIC_CATCH_REPORT(&open_tcpip_report); - -/* Takes a socket as argument, and returns a tcpip channel. Used by - * the party receiving a open-tcp request, when a channel to the - * target has been opened. */ - -#define TCPIP_WINDOW_SIZE 10000 - -/* NOTE: make_channel_forward adds the fd to the channel's resource list. */ -static void -do_tcpip_connect_io(struct command *ignored UNUSED, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(listen_value, lv, x); - - assert(lv); - assert(lv->fd); - - COMMAND_RETURN(c, make_channel_forward(lv->fd, TCPIP_WINDOW_SIZE)); -} - -struct command tcpip_connect_io = STATIC_COMMAND(do_tcpip_connect_io); - -/* Used by the party requesting tcp forwarding, i.e. when a socket is - * already open, and we have asked the other end to forward it. Takes - * a channel as argument, and connects it to the socket. Returns the - * channel. */ - -static void -do_tcpip_start_io(struct command *s UNUSED, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(channel_forward, channel, x); - - assert(channel); - - channel_forward_start_io(channel); - - COMMAND_RETURN(c, channel); -} - -struct command tcpip_start_io = -{ STATIC_HEADER, do_tcpip_start_io }; - - -/* Requesting the opening of a forwarded tcpip channel. */ - -/* Used for both forwarded-tcpip and direct-tcpip. Takes a listen - * value as argument, and returns a channel connected to some tcpip - * port at the other end. */ - -/* GABA: - (class - (name open_tcpip_command) - (super channel_open_command) - (vars - ; ATOM_FORWARDED_TCPIP or ATOM_DIRECT_TCPIP - (type . int) - - (initial_window . UINT32) - - ; For forwarded-tcpip, port is the port listened to. - ; For direct-tcpip, port is the port to connect to. - ; In both cases, it's a port used on the server end. - (port object address_info) - (peer object listen_value))) -*/ - -static struct ssh_channel * -new_tcpip_channel(struct channel_open_command *c, - struct ssh_connection *connection, - UINT32 local_channel_number, - struct lsh_string **request) -{ - CAST(open_tcpip_command, self, c); - struct ssh_channel *channel; - - /* NOTE: All accepted fd:s must end up in this function, so it - * should be ok to delay the REMEMBER call until here. It is done - * by make_channel_forward. */ - - debug("tcpforward_commands.c: new_tcpip_channel\n"); - - channel = &make_channel_forward(self->peer->fd, TCPIP_WINDOW_SIZE)->super; - channel->connection = connection; - - *request = format_channel_open(self->type, local_channel_number, - channel, - "%S%i%S%i", - self->port->ip, self->port->port, - self->peer->peer->ip, self->peer->peer->port); - - return channel; -} - -static struct command * -make_open_tcpip_command(int type, UINT32 initial_window, - struct address_info *port, - struct listen_value *peer) -{ - NEW(open_tcpip_command, self); - - debug("tcpforward_commands.c: make_open_tcpip_command\n"); - - self->super.super.call = do_channel_open_command; - self->super.new_channel = new_tcpip_channel; - - self->type = type; - self->initial_window = initial_window; - - self->port = port; - self->peer = peer; - - return &self->super.super; -} - -DEFINE_COMMAND2(open_forwarded_tcpip) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(address_info, local, a1); - CAST(listen_value, peer, a2); - - COMMAND_RETURN(c, - make_open_tcpip_command(ATOM_FORWARDED_TCPIP, - TCPIP_WINDOW_SIZE, - local, peer)); -} - -DEFINE_COMMAND2(open_direct_tcpip) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST(address_info, local, a1); - CAST(listen_value, peer, a2); - - COMMAND_RETURN(c, - make_open_tcpip_command(ATOM_DIRECT_TCPIP, - TCPIP_WINDOW_SIZE, - local, peer)); -} - - -/* Requesting remote forwarding of a port */ - -/* GABA: - (class - (name remote_port_install_continuation) - (super command_frame) - (vars - (port object remote_port) - (callback object command))) -*/ - -static void -do_remote_port_install_continuation(struct command_continuation *s, - struct lsh_object *x) -{ - CAST(remote_port_install_continuation, self, s); - CAST(ssh_connection, connection, x); - - assert(connection); - - debug("tcpforward_commands.c: do_remote_port_install_continuation, success.\n"); - self->port->callback = self->callback; - - COMMAND_RETURN(self->super.up, x); -} - -static struct command_continuation * -make_remote_port_install_continuation(struct remote_port *port, - struct command *callback, - struct command_continuation *c) -{ - NEW(remote_port_install_continuation, self); - - debug("tcpforward_commands.c: make_remote_port_install_continuation\n"); - - self->super.super.c = do_remote_port_install_continuation; - self->super.up = c; - - self->port = port; - self->callback = callback; - - return &self->super.super; -} - -/* Listening on a remote port - * - * (remote_listen callback port connection) - * - * Returns a remote_port or NULL. - * - * callback is invoked with a address_info peer as argument, and - * should return a channel or NULL. - */ - -/* GABA: - (class - (name request_tcpip_forward_command) - (super global_request_command) - (vars - ; Invoked when a forwarded_tcpip request is received. - ; Called with the struct address_info *peer as argument. - (callback object command) - (port object address_info))) */ - -static struct lsh_string * -do_format_request_tcpip_forward(struct global_request_command *s, - struct ssh_connection *connection, - struct command_continuation **c) -{ - CAST(request_tcpip_forward_command, self, s); - struct remote_port *port; - int want_reply; - - debug("tcpforward_commands.c: do_format_request_tcpip_forward\n"); - - if (CONTINUATION_USED_P(*c)) - { - /* FIXME: Use some exception handler to remove the port from the - * list if the request fails. */ - port = make_remote_port(self->port, NULL); - *c = make_remote_port_install_continuation(port, self->callback, *c); - want_reply = 1; - } - else - { - port = make_remote_port(self->port, self->callback); - want_reply = 0; - } - - object_queue_add_tail(&connection->table->remote_ports, - &port->super.super); - - return format_global_request(ATOM_TCPIP_FORWARD, want_reply, "%S%i", - self->port->ip, self->port->port); -} - - -DEFINE_COMMAND2(remote_listen_command) - (struct command_2 *s UNUSED, - struct lsh_object *a1, - struct lsh_object *a2, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - trace("remote_listen_command\n"); - - { - CAST_SUBTYPE(command, callback, a1); - CAST(address_info, port, a2); - - NEW(request_tcpip_forward_command, self); - - self->super.super.call = do_channel_global_command; - self->super.format_request = do_format_request_tcpip_forward; - - self->callback = callback; - self->port = port; - - COMMAND_RETURN(c, self); - } -} - - -/* Cancel a remotely forwarded port. - * FIXME: Not implemented */ - - - -/* GABA: - (expr - (name forward_local_port) - (params - (backend object io_backend) - (local object address_info) - (target object address_info)) - (expr - (lambda (connection) - (connection_remember connection - (listen_callback - (lambda (peer) - ;; Remembering is done by open_direct_tcpip - ;; and new_tcpip_channel. - (tcpip_start_io - (catch_channel_open - (open_direct_tcpip target peer) connection))) - backend - local))))) -*/ - -struct command * -make_forward_local_port(struct io_backend *backend, - struct address_info *local, - struct address_info *target) -{ - CAST_SUBTYPE(command, res, - forward_local_port(backend, local, target)); - - trace("tcpforward_commands.c: forward_local_port\n"); - - return res; -} - -/* GABA: - (expr - (name forward_remote_port) - (params - (connect object command) - (remote object address_info)) - (expr - (lambda (connection) - (remote_listen (lambda (peer) - (tcpip_connect_io - ; NOTE: The use of prog1 is needed to - ; delay the connect call until the - ; (otherwise ignored) peer argument is - ; available. - (connect (prog1 connection peer)))) - remote - connection)))) -*/ - -struct command * -make_forward_remote_port(struct io_backend *backend, - struct address_info *remote, - struct address_info *target) -{ - CAST_SUBTYPE(command, res, - forward_remote_port(make_connect_port(backend, target), remote)); - - debug("tcpforward_commands.c: forward_remote_port\n"); - - return res; -} - -/* Takes a callback function and returns a channel_open - * handler. */ -DEFINE_COMMAND(make_direct_tcpip_handler) - (struct command *s UNUSED, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command, callback, x); - - trace("tcpforward_commands.c: do_make_open_tcp_handler\n"); - - COMMAND_RETURN(c, - &make_channel_open_direct_tcpip(callback)->super); -} - -/* Takes a callback function and returns a global_request handler. */ -DEFINE_COMMAND(make_tcpip_forward_handler) - (struct command *s UNUSED, - struct lsh_object *x, - struct command_continuation *c, - struct exception_handler *e UNUSED) -{ - CAST_SUBTYPE(command, callback, x); - - debug("tcpforward_commands.c: make_tcpip_forward_handler\n"); - - COMMAND_RETURN(c, - &make_tcpip_forward_request(callback)->super); -} - - -/* Commands to install handlers */ -struct install_info install_direct_tcpip_handler = -STATIC_INSTALL_OPEN_HANDLER(ATOM_DIRECT_TCPIP); - -struct install_info install_forwarded_tcpip_handler = -STATIC_INSTALL_OPEN_HANDLER(ATOM_FORWARDED_TCPIP); - - -/* Server side callbacks */ - -/* Make this non-static? */ -/* GABA: - (expr - (name direct_tcpip_hook) - (params - (connect object command)) - (expr - (lambda (connection) - (install_direct_tcpip connection - (direct_tcpip_handler (lambda (port) - (tcpip_connect_io (connect connection port)))))))) -*/ - -struct command * -make_direct_tcpip_hook(struct io_backend *backend) -{ - CAST_SUBTYPE(command, res, - direct_tcpip_hook(make_connect_connection(backend))); - - debug("tcpforward_commands.c: make_direct_tcpip_hook\n"); - - return res; -} - -struct install_info install_tcpip_forward_handler = -STATIC_INSTALL_GLOBAL_HANDLER(ATOM_TCPIP_FORWARD); - - -/* GABA: - (expr - (name tcpip_forward_hook) - ; FIXME: Don't use globals. - (globals - (install "&install_tcpip_forward_handler.super.super.super") - (handler "&make_tcpip_forward_handler.super")) - (params - (backend object io_backend)) - (expr - (lambda (connection) - ;; Called when the ssh-connection is established - (install connection - (handler (lambda (port) - ;; Called when the client requests remote forwarding. - ;; It should return the fd associated with the port. - ;; NOTE: The caller, do_tcpip_forward_request, is responsible - ;; for handling I/O exceptions, and for remembering the port. - (listen_callback (lambda (peer) - ;; Called when someone connects to the - ;; forwarded port. - ;; Remembering is done by open_direct_tcpip - ;; and new_tcpip_channel. - (tcpip_start_io - (catch_channel_open - (open_forwarded_tcpip port peer) connection))) - backend port)))))))) -*/ - -struct command * -make_tcpip_forward_hook(struct io_backend *backend) -{ - CAST_SUBTYPE(command, res, tcpip_forward_hook(backend)); - - debug("tcpforward_commands.c: tcpip_forward_hook\n"); - - return res; -} diff --git a/lsh/src/tcpforward_commands.c.x b/lsh/src/tcpforward_commands.c.x deleted file mode 100755 index 4bfa950..0000000 Binary files a/lsh/src/tcpforward_commands.c.x and /dev/null differ diff --git a/lsh/src/tcpforward_commands.h b/lsh/src/tcpforward_commands.h deleted file mode 100755 index b1fd528..0000000 --- a/lsh/src/tcpforward_commands.h +++ /dev/null @@ -1,46 +0,0 @@ -/* tcpforward_commands.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_TCPFORWARD_COMMANDS_H_INCLUDED -#define LSH_TCPFORWARD_COMMANDS_H_INCLUDED - -#include "tcpforward.h" - -struct command * -make_forward_local_port(struct io_backend *backend, - struct address_info *local, - struct address_info *target); - -struct command * -make_forward_remote_port(struct io_backend *backend, - struct address_info *local, - struct address_info *target); - -struct command * -make_direct_tcpip_hook(struct io_backend *backend); - -struct command * -make_tcpip_forward_hook(struct io_backend *backend); - -#endif /* LSH_TCPFORWARD_COMMANDS_H_INCLUDED */ diff --git a/lsh/src/testsuite/Makefile.am b/lsh/src/testsuite/Makefile.am deleted file mode 100755 index 887f3a3..0000000 --- a/lsh/src/testsuite/Makefile.am +++ /dev/null @@ -1,51 +0,0 @@ -# Testsuite - -CFLAGS = @CFLAGS@ -O0 - -# Tests that can be used without any special setup. -TS_PROGS = arcfour-test des-test rijndael-test twofish-test \ - md5-test sha1-test rsa-test dsa-test spki-tag-test \ - string-test -TS_SH = conv-1-test conv-2-test export-1-test keygen-1-test keygen-2-test \ - write-key-1-test write-key-2-test - -TS_SOME = $(TS_PROGS) $(TS_SH) - -# Tests that require that lsh is set up for password-less login. -TS_MORE_SH = lsh-1-test lsh-2-test lsh-3-test lsh-4-test lsh-5-test \ - lsh-cat-test lshg-cat-test lshg-cat-2-test tcpip-local-test tcpip-remote-test \ - lshg-tcpip-local-test ssh1-fallback-test -TS_MORE_PROGS = - -TS_ALL = $(TS_PROGS) $(TS_SH) $(TS_MORE_PROGS) $(TS_MORE_SH) - -# Don't use automakes testsuite support -# TESTS = $(TS_PROGS) $(TS_SH) - -# SUFFIXES = .c .o -noinst_PROGRAMS = $(TS_PROGS) - -LDADD = ../liblsh.a ../nettle/libnettle.a $(addprefix ../,@LIBARGP@) - -EXTRA_DIST = macros.m4 $(SOURCES:.c=.m4) $(TS_SH) $(TS_MORE_SH) \ - functions.sh runtests key-1.private - -all: - @echo make check to build testprograms. - -M4FLAGS = -P #-s -%.c: macros.m4 %.m4 - $(M4) $(M4FLAGS) $^ > $@T - test -s $@T && mv -f $@T $@ - - -.PHONY: check-some check-more - -check: check-some - -check-some: $(TS_SOME) - srcdir=$(srcdir) $(srcdir)/runtests $(TS_SOME) - -check-more: $(TS_ALL) - srcdir=$(srcdir) $(srcdir)/runtests $(TS_ALL) - diff --git a/lsh/src/testsuite/Makefile.in b/lsh/src/testsuite/Makefile.in deleted file mode 100755 index 0dab9d1..0000000 --- a/lsh/src/testsuite/Makefile.in +++ /dev/null @@ -1,561 +0,0 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# Testsuite - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = ../.. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -BASH = @BASH@ -CC = @CC@ -GROFF = @GROFF@ -KRB_LIBS = @KRB_LIBS@ -KRB_PROGRAM = @KRB_PROGRAM@ -LIBARGP = @LIBARGP@ -M4 = @M4@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -RANLIB = @RANLIB@ -SCHEME_NAME = @SCHEME_NAME@ -SCHEME_PROGRAM = @SCHEME_PROGRAM@ -SRP_PROGRAM = @SRP_PROGRAM@ -VERSION = @VERSION@ - -CFLAGS = @CFLAGS@ -O0 - -# Tests that can be used without any special setup. -TS_PROGS = arcfour-test des-test rijndael-test twofish-test md5-test sha1-test rsa-test dsa-test spki-tag-test string-test - -TS_SH = conv-1-test conv-2-test export-1-test keygen-1-test keygen-2-test write-key-1-test write-key-2-test - - -TS_SOME = $(TS_PROGS) $(TS_SH) - -# Tests that require that lsh is set up for password-less login. -TS_MORE_SH = lsh-1-test lsh-2-test lsh-3-test lsh-4-test lsh-5-test lsh-cat-test lshg-cat-test lshg-cat-2-test tcpip-local-test tcpip-remote-test lshg-tcpip-local-test ssh1-fallback-test - -TS_MORE_PROGS = - -TS_ALL = $(TS_PROGS) $(TS_SH) $(TS_MORE_PROGS) $(TS_MORE_SH) - -# Don't use automakes testsuite support -# TESTS = $(TS_PROGS) $(TS_SH) - -# SUFFIXES = .c .o -noinst_PROGRAMS = $(TS_PROGS) - -LDADD = ../liblsh.a ../nettle/libnettle.a $(addprefix ../,@LIBARGP@) - -EXTRA_DIST = macros.m4 $(SOURCES:.c=.m4) $(TS_SH) $(TS_MORE_SH) functions.sh runtests key-1.private - - -M4FLAGS = -P #-s -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../../config.h -CONFIG_CLEAN_FILES = -PROGRAMS = $(noinst_PROGRAMS) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I../.. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -arcfour_test_SOURCES = arcfour-test.c -arcfour_test_OBJECTS = arcfour-test.o -arcfour_test_LDADD = $(LDADD) -arcfour_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a \ -$(addprefix ../,@LIBARGP@) -arcfour_test_LDFLAGS = -des_test_SOURCES = des-test.c -des_test_OBJECTS = des-test.o -des_test_LDADD = $(LDADD) -des_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a $(addprefix \ -../,@LIBARGP@) -des_test_LDFLAGS = -rijndael_test_SOURCES = rijndael-test.c -rijndael_test_OBJECTS = rijndael-test.o -rijndael_test_LDADD = $(LDADD) -rijndael_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a \ -$(addprefix ../,@LIBARGP@) -rijndael_test_LDFLAGS = -twofish_test_SOURCES = twofish-test.c -twofish_test_OBJECTS = twofish-test.o -twofish_test_LDADD = $(LDADD) -twofish_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a \ -$(addprefix ../,@LIBARGP@) -twofish_test_LDFLAGS = -md5_test_SOURCES = md5-test.c -md5_test_OBJECTS = md5-test.o -md5_test_LDADD = $(LDADD) -md5_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a $(addprefix \ -../,@LIBARGP@) -md5_test_LDFLAGS = -sha1_test_SOURCES = sha1-test.c -sha1_test_OBJECTS = sha1-test.o -sha1_test_LDADD = $(LDADD) -sha1_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a $(addprefix \ -../,@LIBARGP@) -sha1_test_LDFLAGS = -rsa_test_SOURCES = rsa-test.c -rsa_test_OBJECTS = rsa-test.o -rsa_test_LDADD = $(LDADD) -rsa_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a $(addprefix \ -../,@LIBARGP@) -rsa_test_LDFLAGS = -dsa_test_SOURCES = dsa-test.c -dsa_test_OBJECTS = dsa-test.o -dsa_test_LDADD = $(LDADD) -dsa_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a $(addprefix \ -../,@LIBARGP@) -dsa_test_LDFLAGS = -spki_tag_test_SOURCES = spki-tag-test.c -spki_tag_test_OBJECTS = spki-tag-test.o -spki_tag_test_LDADD = $(LDADD) -spki_tag_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a \ -$(addprefix ../,@LIBARGP@) -spki_tag_test_LDFLAGS = -string_test_SOURCES = string-test.c -string_test_OBJECTS = string-test.o -string_test_LDADD = $(LDADD) -string_test_DEPENDENCIES = ../liblsh.a ../nettle/libnettle.a \ -$(addprefix ../,@LIBARGP@) -string_test_LDFLAGS = -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = arcfour-test.c des-test.c rijndael-test.c twofish-test.c md5-test.c sha1-test.c rsa-test.c dsa-test.c spki-tag-test.c string-test.c -OBJECTS = arcfour-test.o des-test.o rijndael-test.o twofish-test.o md5-test.o sha1-test.o rsa-test.o dsa-test.o spki-tag-test.o string-test.o - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps src/testsuite/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -arcfour-test: $(arcfour_test_OBJECTS) $(arcfour_test_DEPENDENCIES) - @rm -f arcfour-test - $(LINK) $(arcfour_test_LDFLAGS) $(arcfour_test_OBJECTS) $(arcfour_test_LDADD) $(LIBS) - -des-test: $(des_test_OBJECTS) $(des_test_DEPENDENCIES) - @rm -f des-test - $(LINK) $(des_test_LDFLAGS) $(des_test_OBJECTS) $(des_test_LDADD) $(LIBS) - -rijndael-test: $(rijndael_test_OBJECTS) $(rijndael_test_DEPENDENCIES) - @rm -f rijndael-test - $(LINK) $(rijndael_test_LDFLAGS) $(rijndael_test_OBJECTS) $(rijndael_test_LDADD) $(LIBS) - -twofish-test: $(twofish_test_OBJECTS) $(twofish_test_DEPENDENCIES) - @rm -f twofish-test - $(LINK) $(twofish_test_LDFLAGS) $(twofish_test_OBJECTS) $(twofish_test_LDADD) $(LIBS) - -md5-test: $(md5_test_OBJECTS) $(md5_test_DEPENDENCIES) - @rm -f md5-test - $(LINK) $(md5_test_LDFLAGS) $(md5_test_OBJECTS) $(md5_test_LDADD) $(LIBS) - -sha1-test: $(sha1_test_OBJECTS) $(sha1_test_DEPENDENCIES) - @rm -f sha1-test - $(LINK) $(sha1_test_LDFLAGS) $(sha1_test_OBJECTS) $(sha1_test_LDADD) $(LIBS) - -rsa-test: $(rsa_test_OBJECTS) $(rsa_test_DEPENDENCIES) - @rm -f rsa-test - $(LINK) $(rsa_test_LDFLAGS) $(rsa_test_OBJECTS) $(rsa_test_LDADD) $(LIBS) - -dsa-test: $(dsa_test_OBJECTS) $(dsa_test_DEPENDENCIES) - @rm -f dsa-test - $(LINK) $(dsa_test_LDFLAGS) $(dsa_test_OBJECTS) $(dsa_test_LDADD) $(LIBS) - -spki-tag-test: $(spki_tag_test_OBJECTS) $(spki_tag_test_DEPENDENCIES) - @rm -f spki-tag-test - $(LINK) $(spki_tag_test_LDFLAGS) $(spki_tag_test_OBJECTS) $(spki_tag_test_LDADD) $(LIBS) - -string-test: $(string_test_OBJECTS) $(string_test_DEPENDENCIES) - @rm -f string-test - $(LINK) $(string_test_LDFLAGS) $(string_test_OBJECTS) $(string_test_LDADD) $(LIBS) - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = src/testsuite - -distdir: $(DISTFILES) - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done -arcfour-test.o: arcfour-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -des-test.o: des-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -dsa-test.o: dsa-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -md5-test.o: md5-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -rijndael-test.o: rijndael-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -rsa-test.o: rsa-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -sha1-test.o: sha1-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -spki-tag-test.o: spki-tag-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -string-test.o: string-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h -twofish-test.o: twofish-test.c ../../src/lsh.h ../../src/lsh_types.h \ - ../../config.h ../../src/algorithms.h \ - ../../src/abstract_compress.h ../../src/abstract_compress.h.x \ - ../../src/alist.h ../../src/alist.h.x ../../src/lsh_argp.h \ - ../../src/argp/argp.h ../../src/randomness.h \ - ../../src/abstract_crypto.h ../../src/list.h ../../src/list.h.x \ - ../../src/abstract_crypto.h.x ../../src/exception.h \ - ../../src/exception.h.x ../../src/randomness.h.x \ - ../../src/algorithms.h.x ../../src/crypto.h ../../src/digits.h \ - ../../src/format.h ../../src/atoms.h ../../src/atoms_defines.h \ - ../../src/bignum.h ../../src/sexp.h ../../src/command.h \ - ../../src/command.h.x ../../src/parse.h ../../src/sexp_table.h \ - ../../src/sexp.h.x ../../src/spki.h ../../src/dsa.h \ - ../../src/publickey_crypto.h ../../src/publickey_crypto.h.x \ - ../../src/spki.h.x ../../src/werror.h ../../src/xalloc.h \ - ../../src/gc.h - -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile $(PROGRAMS) -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \ - mostlyclean-tags mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-noinstPROGRAMS clean-compile clean-tags clean-generic \ - mostlyclean-am - -clean: clean-am - -distclean-am: distclean-noinstPROGRAMS distclean-compile distclean-tags \ - distclean-generic clean-am - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-noinstPROGRAMS \ - maintainer-clean-compile maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \ -clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ -check-am installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -all: - @echo make check to build testprograms. -%.c: macros.m4 %.m4 - $(M4) $(M4FLAGS) $^ > $@T - test -s $@T && mv -f $@T $@ - -.PHONY: check-some check-more - -check: check-some - -check-some: $(TS_SOME) - srcdir=$(srcdir) $(srcdir)/runtests $(TS_SOME) - -check-more: $(TS_ALL) - srcdir=$(srcdir) $(srcdir)/runtests $(TS_ALL) - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/lsh/src/testsuite/arcfour-test.c b/lsh/src/testsuite/arcfour-test.c deleted file mode 100755 index c1902dd..0000000 --- a/lsh/src/testsuite/arcfour-test.c +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - - { - struct crypto_algorithm *algorithm = &crypto_arcfour_algorithm; - struct lsh_string *key = simple_decode_hex("0123456789ABCDEF0000000000000000") ; - struct lsh_string *plain = simple_decode_hex("0123456789ABCDEF") ; - struct lsh_string *cipher = simple_decode_hex("697236591B5242B1") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with Arcfour ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with Arcfour ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - return 0; -} diff --git a/lsh/src/testsuite/arcfour-test.m4 b/lsh/src/testsuite/arcfour-test.m4 deleted file mode 100755 index 0001c53..0000000 Binary files a/lsh/src/testsuite/arcfour-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/conv-1-test b/lsh/src/testsuite/conv-1-test deleted file mode 100755 index bf20440..0000000 Binary files a/lsh/src/testsuite/conv-1-test and /dev/null differ diff --git a/lsh/src/testsuite/conv-2-test b/lsh/src/testsuite/conv-2-test deleted file mode 100755 index 1db2537..0000000 Binary files a/lsh/src/testsuite/conv-2-test and /dev/null differ diff --git a/lsh/src/testsuite/des-test.c b/lsh/src/testsuite/des-test.c deleted file mode 100755 index bb1dd95..0000000 --- a/lsh/src/testsuite/des-test.c +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); -/* From Applied Cryptography, 2:nd edition */ - - - { - struct crypto_algorithm *algorithm = &crypto_des_algorithm; - struct lsh_string *key = simple_decode_hex("0123456789ABCDEF") ; - struct lsh_string *plain = simple_decode_hex("0123456789ABCDE7") ; - struct lsh_string *cipher = simple_decode_hex("C95744256A5ED31D") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with DES AC ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with DES AC ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - -/* From Dana How's DEScore */ - - { - struct crypto_algorithm *algorithm = &crypto_des_algorithm; - struct lsh_string *key = simple_decode_hex("0101010101010180") ; - struct lsh_string *plain = simple_decode_hex("0000000000000000") ; - struct lsh_string *cipher = simple_decode_hex("9CC62DF43B6EED74") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with DES 1 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with DES 1 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &crypto_des_algorithm; - struct lsh_string *key = simple_decode_hex("8001010101010101") ; - struct lsh_string *plain = simple_decode_hex("0000000000000040") ; - struct lsh_string *cipher = simple_decode_hex("A380E02A6BE54696") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with DES 2 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with DES 2 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &crypto_des_algorithm; - struct lsh_string *key = simple_decode_hex("08192A3B4C5D6E7F") ; - struct lsh_string *plain = simple_decode_hex("0000000000000000") ; - struct lsh_string *cipher = simple_decode_hex("25DDAC3E96176467") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with DES 3 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with DES 3 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &crypto_des_algorithm; - struct lsh_string *key = simple_decode_hex("0123456789ABCDEF") ; - struct lsh_string *plain = ssh_format("%lz", "Now is t") ; - struct lsh_string *cipher = simple_decode_hex("3FA40E8A984D4815") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with DES 4 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with DES 4 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - return 0; -} diff --git a/lsh/src/testsuite/des-test.m4 b/lsh/src/testsuite/des-test.m4 deleted file mode 100755 index dfd7880..0000000 Binary files a/lsh/src/testsuite/des-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/dsa-test.c b/lsh/src/testsuite/dsa-test.c deleted file mode 100755 index 5ddab9f..0000000 --- a/lsh/src/testsuite/dsa-test.c +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - -{ - struct alist *algorithms = all_signature_algorithms(make_bad_random()); - struct sexp *key = string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "{KDM6ZHNhKDE6cDEyODqD2afCziqRefQ82zv/594PDu8m3V365E1TG8DeRWNN" - "LAfLkpsNvhDaWABw5qv7uEFcRL/1cLitd532U6rZfce964FdfogQPmFgbtPY" - "opX7/TQNLUniIIM+us5VEeIsTwKX7TUemUj6hI6cj623tHvMR970JVteHV4Q" - "IVs7VaC4XykoMTpxMjA6gmbg3q9GAgukjUEMpYDzqXhim10pKDE6ZzEyODow" - "00u583a+yUcVSv5Adrx9NZydMvVHHdu+jWqUHEf6ncTzJXMVHbtKpZ65ibdK" - "w2u2MQpei1gFAWVdkfOT2qGTrhMDBJuH/rsJPcBAS1O0xdokYzAPnFsVbXiM" - "Ss6Oy7ndAMGNmVN/JVrAJdB02JSmB8vjAjoSdu9VaRajP33lQykoMTp5MTI4" - "OmRAIEiyfzn0BKVGqEkJycDp4t0VOoSZRhBiiSWY0wryeuPO/CtwD7bQdzkK" - "g73K14oSmUh8liO7Yq8MhaPfnvHuLA1mZY4f0yg7VAf2zTDufmFU+tQaaosP" - "XIbFrMwRJ798ml1rrcsBIYDLYqVcXhfW01KM2+ACzO4THBuGhn96KSgxOngy" - "MDpWxu+vh40G7vIdwHD6tx2m7B4wpikp}") , 1); - struct lsh_string *msg = ssh_format("%lz", "Needs some randomness.") ; - struct sexp *sign; - struct signer *s = spki_make_signer(algorithms, key, NULL); - struct verifier *v; - - fputs("DSA signing ... ", stderr);; - if (!s) - /* Invalid key. */ - { fputs("failed.\n", stderr);; exit(1); }; - - sign = SIGN_SPKI(s, msg->length, msg->data); - - - v = SIGNER_GET_VERIFIER(s); - if (!v) - /* Can't create verifier */ - { fputs("failed.\n", stderr);; exit(1); } - - if (!VERIFY_SPKI(v, msg->length, msg->data, sign)) - /* Unexpected verification failure. */ - { fputs("failed.\n", stderr);; exit(1); }; - - /* Modify message slightly. */ - assert(msg->length > 10); - - msg->data[5] ^= 0x40; - - if (VERIFY_SPKI(v, msg->length, msg->data, sign)) - /* Unexpected verification success. */ - { fputs("failed.\n", stderr);; exit(1); }; - - fputs("ok.\n", stderr); -} - - return 0; -} diff --git a/lsh/src/testsuite/dsa-test.m4 b/lsh/src/testsuite/dsa-test.m4 deleted file mode 100755 index 9c06a3d..0000000 Binary files a/lsh/src/testsuite/dsa-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/export-1-test b/lsh/src/testsuite/export-1-test deleted file mode 100644 index a87f4dd..0000000 --- a/lsh/src/testsuite/export-1-test +++ /dev/null @@ -1,63 +0,0 @@ -#! /bin/sh - -# Tests the key export programs - -if [ -z "$srcdir" ] ; then - srcdir=`pwd` -fi - -. $srcdir/functions.sh - -# Keep silent unless -v is used. - -if [ x$1 != x-v ]; then - exec 2>/dev/null -fi - -# All output is diagnostic -exec 1>&2 - -echo "export-1-test: Testing lsh-export-key" - -(../lsh-export-key -s Test |tee test.out1) <test.out2 <" "`pwd`/test.out1" -cat ../lshd > test.out2 - -compare_output "lshg-cat-2-test" - - diff --git a/lsh/src/testsuite/lshg-cat-test b/lsh/src/testsuite/lshg-cat-test deleted file mode 100644 index c6b29c7..0000000 --- a/lsh/src/testsuite/lshg-cat-test +++ /dev/null @@ -1,22 +0,0 @@ -#! /bin/sh - -# Tests connecting with lsh. In order to use this, you must already -# have lsh set up so that you can login without password. - -# This restriction can be fixed if we add an option to lshd to use a -# custom passwd-file. - -echo lshg, cat test - -if [ -z "$srcdir" ] ; then - srcdir=`pwd` -fi - -. $srcdir/functions.sh - -spawn_lshd && spawn_lsh -G && sleep 20 && exec_lshg "cat `pwd`/../lshd" > test.out1 -cat ../lshd > test.out2 - -compare_output "lsh-cat-test" - - diff --git a/lsh/src/testsuite/lshg-tcpip-local-test b/lsh/src/testsuite/lshg-tcpip-local-test deleted file mode 100755 index fcdffe4..0000000 Binary files a/lsh/src/testsuite/lshg-tcpip-local-test and /dev/null differ diff --git a/lsh/src/testsuite/macros.m4 b/lsh/src/testsuite/macros.m4 deleted file mode 100755 index 7dc6560..0000000 Binary files a/lsh/src/testsuite/macros.m4 and /dev/null differ diff --git a/lsh/src/testsuite/md5-test.c b/lsh/src/testsuite/md5-test.c deleted file mode 100755 index 868a1a8..0000000 --- a/lsh/src/testsuite/md5-test.c +++ /dev/null @@ -1,311 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); -/* Test vectors from RFC 1321 */ - - { - struct lsh_string *a, *b; - fputs("MD5-1 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "") , 1); - b = simple_decode_hex("D41D8CD98F00B204E9800998ECF8427E") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - - - { - struct lsh_string *a, *b; - fputs("MD5-2 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "a") , 1); - b = simple_decode_hex("0CC175B9C0F1B6A831C399E269772661") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - - - { - struct lsh_string *a, *b; - fputs("MD5-3 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "abc") , 1); - b = simple_decode_hex("900150983cd24fb0D6963F7D28E17F72") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - - - { - struct lsh_string *a, *b; - fputs("MD5-4 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "message digest") , 1); - b = simple_decode_hex("F96B697D7CB7938D525A2F31AAF161D0") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - - - { - struct lsh_string *a, *b; - fputs("MD5-5 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "abcdefghijklmnopqrstuvwxyz") , 1); - b = simple_decode_hex("C3FCD3D76192E4007DFB496CCA67E13B") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - - - { - struct lsh_string *a, *b; - fputs("MD5-6 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") , 1); - b = simple_decode_hex("D174AB98D277D9F5A5611C2C9F419D9F") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - - - { - struct lsh_string *a, *b; - fputs("MD5-7 ... ", stderr); - a = hash_string(&md5_algorithm, ssh_format("%lz", "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890") , 1); - b = simple_decode_hex("57EDF4A22BE3C955AC49DA2E2107B67A") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - -/* Test vectors for md5 from RFC-2202 */ - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = simple_decode_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-1 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Hi There") , 1); - b = simple_decode_hex("9294727A3638BB1C13F48EF8158BFC9D") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = ssh_format("%lz", "Jefe") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-2 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "what do ya want for nothing?") , 1); - b = simple_decode_hex("750C783E6AB0B503EAA86E310A5DB738") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-3 ... ", stderr); - a = mac_string(hmac, key, 1, - simple_decode_hex("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD") , 1); - b = simple_decode_hex("56BE34521D144C88DBB8C733F0E8B3F6") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = simple_decode_hex("0102030405060708090A0B0C0D0E0F10111213141516171819") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-4 ... ", stderr); - a = mac_string(hmac, key, 1, - simple_decode_hex("CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD") , 1); - b = simple_decode_hex("697EAF0ACA3A3AEA3A75164746FFAA79") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = simple_decode_hex("0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-5 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Test With Truncation") , 1); - b = simple_decode_hex("56461EF2342EDC00F9BAB995690EFD4C") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-6 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Test Using Larger Than Block-Size Key - Hash Key First") , 1); - b = simple_decode_hex("6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&md5_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-MD5-7 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Test Using Larger Than Block-Size Key an" - "d Larger Than One Block-Size Data") , 1); - b = simple_decode_hex("6f630fad67cda0ee1fb1f562db3aa53e") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - return 0; -} diff --git a/lsh/src/testsuite/md5-test.m4 b/lsh/src/testsuite/md5-test.m4 deleted file mode 100755 index 18cf583..0000000 Binary files a/lsh/src/testsuite/md5-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/rijndael-test.c b/lsh/src/testsuite/rijndael-test.c deleted file mode 100755 index cdd9ab3..0000000 --- a/lsh/src/testsuite/rijndael-test.c +++ /dev/null @@ -1,626 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - - { - struct crypto_algorithm *algorithm = &rijndael128_algorithm; - struct lsh_string *key = simple_decode_hex("00010203050607080A0B0C0D0F101112") ; - struct lsh_string *plain = simple_decode_hex("506812A45F08C889B97F5980038B8359") ; - struct lsh_string *cipher = simple_decode_hex("D8F532538289EF7D06B506A4FD5BE9C9") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-128 1 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-128 1 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael128_algorithm; - struct lsh_string *key = simple_decode_hex("14151617191A1B1C1E1F202123242526") ; - struct lsh_string *plain = simple_decode_hex("5C6D71CA30DE8B8B00549984D2EC7D4B") ; - struct lsh_string *cipher = simple_decode_hex("59AB30F4D4EE6E4FF9907EF65B1FB68C") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-128 2 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-128 2 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael128_algorithm; - struct lsh_string *key = simple_decode_hex("28292A2B2D2E2F30323334353738393A") ; - struct lsh_string *plain = simple_decode_hex("53F3F4C64F8616E4E7C56199F48F21F6") ; - struct lsh_string *cipher = simple_decode_hex("BF1ED2FCB2AF3FD41443B56D85025CB1") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-128 3 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-128 3 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - -/* Skipped lots of tests */ - - - { - struct crypto_algorithm *algorithm = &rijndael128_algorithm; - struct lsh_string *key = simple_decode_hex("A0A1A2A3A5A6A7A8AAABACADAFB0B1B2") ; - struct lsh_string *plain = simple_decode_hex("F5F4F7F684878689A6A7A0A1D2CDCCCF") ; - struct lsh_string *cipher = simple_decode_hex("CE52AF650D088CA559425223F4D32694") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-128 128 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-128 128 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael192_algorithm; - struct lsh_string *key = simple_decode_hex("00010203050607080A0B0C0D0F10111214151617191A1B1C") ; - struct lsh_string *plain = simple_decode_hex("2D33EEF2C0430A8A9EBF45E809C40BB6") ; - struct lsh_string *cipher = simple_decode_hex("DFF4945E0336DF4C1C56BC700EFF837F") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-192 1 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-192 1 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael192_algorithm; - struct lsh_string *key = simple_decode_hex("1E1F20212324252628292A2B2D2E2F30323334353738393A") ; - struct lsh_string *plain = simple_decode_hex("6AA375D1FA155A61FB72353E0A5A8756") ; - struct lsh_string *cipher = simple_decode_hex("B6FDDEF4752765E347D5D2DC196D1252") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-192 2 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-192 2 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael192_algorithm; - struct lsh_string *key = simple_decode_hex("3C3D3E3F41424344464748494B4C4D4E5051525355565758") ; - struct lsh_string *plain = simple_decode_hex("BC3736518B9490DCB8ED60EB26758ED4") ; - struct lsh_string *cipher = simple_decode_hex("D23684E3D963B3AFCF1A114ACA90CBD6") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-192 3 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-192 3 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - -/* Skipped lots of tests */ - - - { - struct crypto_algorithm *algorithm = &rijndael192_algorithm; - struct lsh_string *key = simple_decode_hex("868788898B8C8D8E90919293959697989A9B9C9D9FA0A1A2") ; - struct lsh_string *plain = simple_decode_hex("D3D2DDDCAAADACAF9C9D9E9FE8EBEAE5") ; - struct lsh_string *cipher = simple_decode_hex("9ADB3D4CCA559BB98C3E2ED73DBF1154") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-192 128 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-192 128 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael256_algorithm; - struct lsh_string *key = simple_decode_hex("00010203050607080A0B0C0D0F10111214151617191A1B1C1E1F202123242526") ; - struct lsh_string *plain = simple_decode_hex("834EADFCCAC7E1B30664B1ABA44815AB") ; - struct lsh_string *cipher = simple_decode_hex("1946DABF6A03A2A2C3D0B05080AED6FC") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-256 1 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-256 1 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael256_algorithm; - struct lsh_string *key = simple_decode_hex("28292A2B2D2E2F30323334353738393A3C3D3E3F41424344464748494B4C4D4E") ; - struct lsh_string *plain = simple_decode_hex("D9DC4DBA3021B05D67C0518F72B62BF1") ; - struct lsh_string *cipher = simple_decode_hex("5ED301D747D3CC715445EBDEC62F2FB4") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-256 2 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-256 2 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = &rijndael256_algorithm; - struct lsh_string *key = simple_decode_hex("50515253555657585A5B5C5D5F60616264656667696A6B6C6E6F707173747576") ; - struct lsh_string *plain = simple_decode_hex("A291D86301A4A739F7392173AA3C604C") ; - struct lsh_string *cipher = simple_decode_hex("6585C8F43D13A6BEAB6419FC5935B9D0") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-256 3 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-256 3 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - -/* Skipped lots of tests */ - - - { - struct crypto_algorithm *algorithm = &rijndael256_algorithm; - struct lsh_string *key = simple_decode_hex("50515253555657585A5B5C5D5F60616264656667696A6B6C6E6F707173747576") ; - struct lsh_string *plain = simple_decode_hex("050407067477767956575051221D1C1F") ; - struct lsh_string *cipher = simple_decode_hex("7444527095838FE080FC2BCDD30847EB") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with rijndael-256 128 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with rijndael-256 128 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - return 0; -} diff --git a/lsh/src/testsuite/rijndael-test.m4 b/lsh/src/testsuite/rijndael-test.m4 deleted file mode 100755 index eac99c4..0000000 Binary files a/lsh/src/testsuite/rijndael-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/rsa-test.c b/lsh/src/testsuite/rsa-test.c deleted file mode 100755 index daada1a..0000000 --- a/lsh/src/testsuite/rsa-test.c +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - -{ - struct alist *algorithms = all_signature_algorithms(make_bad_random()); - struct sexp *key = string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "{KDE0OnJzYS1wa2NzMS1zaGExKDE6bjI1MzoBFRr6hWOxSyj4UOuRSv2TgnQT" - "RIbT+XhBCCuC0delL8hCt9SKN8QYGn9eSfJaMknWXZdbiATciNWXtC6BInC5" - "PiIyCwZP21u4x/UYNq7EpYRWfOr2GeFtgqAgjLCPiNcDmaje5RI6HltB1t69" - "gyRlgmTEGedjfCVUksR9HCa/YHO4Qj6nfGL43suz0qzbw90fo52pJQAFVsob" - "8uNXcIkKEIUF6iaCcFxz5chlmUDDuWZsu0CN2hwTVcNEODo2h4K9UZSJ1q5r" - "flh3Yd2hKeQDY4g1em/4faS43lvhkV+PqXNyaV5/9Oo5PfPhuVbppOvhV3fU" - "6GsPNH2rmaSnKSgxOmU0Og8eiqcpKDE6ZDI1MzoBALlbGgNWW/Iobv5Zm17I" - "lj8Vwg3DgYucIlNkKs4z+G5I1J5wSLlsSJp5mDixgy2meph8Zo7kRM8DXNbQ" - "FxPrx184sRHI+zQlcd61ldDSiy+U55cw99k+AW9xPGiSlIwfGFJb8+ihimFr" - "LD4bpJTjZmWFMza4W4EqovJZar2Lk8j1ahEClrVZxmClMwGViQf6sezat9eD" - "ccA3D1J7lbCqhhZ4/zO7M97VifRfcvzJCRsQUgf3fdsY6BFp0/jkx+7y0ZgC" - "IfBx7JJPPAe90wNIG7s+XXE4A0M3txusqFE3gpIZ+H84xD/as/h/CAkDnZDK" - "xTjaeL9KEMXaJDlXKSgxOnAxMjY6wOsl7emcAJwKRkNPGY2J+P/XTvCBSzKo" - "JfT3uwfCREpGfg4YliDVXyh1IgFeIZU70e8OoRkrBlDtyTzcgdq9okgSdPLu" - "+tIffBLfHrQ+ZAcg2Wp3cKckhIgqy8GdQutTw/z3aDGpOmoIS+mijVmdDNmp" - "g2IB/mSPjtOok3aXKSgxOnExMjc6AW+29CAmn3PY4n6MlE9jfE/ErXCTKZFh" - "IEASNJPF+zsKJSNDtx1ZeVmgX8/00ZFVASs2SScWlUQLYyHWqkjDjA3URL9n" - "nhdOCyGSJufb7C0OkPRWPmvlLdQi1rqIKff1IlsBRBK4y64suPmPAJ+rx39X" - "sFpTto7nzbji9wWUcSkoMTphMTI2OiIbnv4UD+cPiMag8ejks81LF5wWYLxi" - "UL2vQBPMQHfEVbqDupjxBjDaH/OZqtSo7kpBUPEfCT6QnbgEiozEPKoV2GOv" - "tzduDuNIG/cypIZ81a79rChDmt98o8Mo3xPNaOtQkdgpAGM4N/OZm65YCwd4" - "Rvi7sTgrx/c0uzXicykoMTpiMTI2Oi65so8tg+/ELd2PhaVfBGF9GAPYX8OT" - "ZPTR4TImy38sscW81Dwfn+IHUWZQZZVxkCF5g0WnZHM1Tb4yg6CyQoVAnipW" - "pf8D2Yf0FQuIRcwbUwLuEVPQ7/DZsUHPp0W2lvnSc987T0n8b4M43VOeg6Mj" - "EnREvLlSrjmPH288ZykoMTpjMTI2OrNtDOjzHIbPm3Tf4YlXcw9DxuXjhQQo" - "0dbVG80b4XAPc0Vtc3tKMw8hdWbqiKp6J4hzM+U5uz/bMCIqDTYK1srP0pNZ" - "8j3Q8Os5BI/JrVtkVMl2/BSvq4LRPVI08E49oGRLI/E4zxOVrmmoASntirUP" - "zrjLGBu2zAA3XTEb+Ckp}") , 1); - struct lsh_string *msg = ssh_format("%lz", "The magic words are squeamish ossifrage") ; - struct sexp *sign; - struct signer *s = spki_make_signer(algorithms, key, NULL); - struct verifier *v; - - fputs("RSA signing ... ", stderr);; - if (!s) - /* Invalid key. */ - { fputs("failed.\n", stderr);; exit(1); }; - - sign = SIGN_SPKI(s, msg->length, msg->data); - - - v = SIGNER_GET_VERIFIER(s); - if (!v) - /* Can't create verifier */ - { fputs("failed.\n", stderr);; exit(1); } - - if (!VERIFY_SPKI(v, msg->length, msg->data, sign)) - /* Unexpected verification failure. */ - { fputs("failed.\n", stderr);; exit(1); }; - - /* Modify message slightly. */ - assert(msg->length > 10); - - msg->data[5] ^= 0x40; - - if (VERIFY_SPKI(v, msg->length, msg->data, sign)) - /* Unexpected verification success. */ - { fputs("failed.\n", stderr);; exit(1); }; - - fputs("ok.\n", stderr); -} - - - - - return 0; -} diff --git a/lsh/src/testsuite/rsa-test.m4 b/lsh/src/testsuite/rsa-test.m4 deleted file mode 100755 index 477d8aa..0000000 Binary files a/lsh/src/testsuite/rsa-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/runtests b/lsh/src/testsuite/runtests deleted file mode 100755 index 58e3e54..0000000 Binary files a/lsh/src/testsuite/runtests and /dev/null differ diff --git a/lsh/src/testsuite/sha1-test.c b/lsh/src/testsuite/sha1-test.c deleted file mode 100755 index 57bd3e1..0000000 --- a/lsh/src/testsuite/sha1-test.c +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - - { - struct lsh_string *a, *b; - fputs("SHA1 ... ", stderr); - a = hash_string(&sha1_algorithm, ssh_format("%lz", "abc") , 1); - b = simple_decode_hex("A9993E364706816ABA3E25717850C26C9CD0D89D") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - -/* Test vectors for sha1 from RFC-2202, and some more */ - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-0 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Hi There") , 1); - b = simple_decode_hex("675B0B3A1B4DDF4E124872DA6C2F632BFED957E9") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-1 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Hi There") , 1); - b = simple_decode_hex("B617318655057264E28BC0B6FB378C8EF146BE00") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = ssh_format("%lz", "Jefe") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-2 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "what do ya want for nothing?") , 1); - b = simple_decode_hex("EFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-3a ... ", stderr); - a = mac_string(hmac, key, 1, - simple_decode_hex("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD") , 1); - b = simple_decode_hex("D730594D167E35D5956FD8003D0DB3D3F46DC7BB") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-3 ... ", stderr); - a = mac_string(hmac, key, 1, - simple_decode_hex("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD") , 1); - b = simple_decode_hex("125D7342B9AC11CD91A39AF48AA17B4F63F175D3") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("0102030405060708090A0B0C0D0E0F10111213141516171819") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-4 ... ", stderr); - a = mac_string(hmac, key, 1, - simple_decode_hex("CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD") , 1); - b = simple_decode_hex("4C9007F4026250C6BC8414F9BF50C86C2D7235DA") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-5 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Test With Truncation") , 1); - b = simple_decode_hex("4C1A03424B55E07FE7F27BE1D58BB9324A9A5A04") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-6 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Test Using Larger Than Block-Size Key - Hash Key First") , 1); - b = simple_decode_hex("AA4AE5E15272D00E95705637CE8A3B55ED402112") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - { - struct mac_algorithm *hmac = make_hmac_algorithm(&sha1_algorithm); - struct lsh_string *key = simple_decode_hex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ; - - - { - struct lsh_string *a, *b; - fputs("HMAC-SHA1-7 ... ", stderr); - a = mac_string(hmac, key, 1, - ssh_format("%lz", "Test Using Larger Than Block-Size Key an" - "d Larger Than One Block-Size Data") , 1); - b = simple_decode_hex("E8E99D0F45237D786D6BBAA7965C7808BBFF1A91") ; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } -; - } - - - - return 0; -} diff --git a/lsh/src/testsuite/sha1-test.m4 b/lsh/src/testsuite/sha1-test.m4 deleted file mode 100755 index 873dc7d..0000000 Binary files a/lsh/src/testsuite/sha1-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/spki-tag-test.c b/lsh/src/testsuite/spki-tag-test.c deleted file mode 100755 index 68b80b4..0000000 --- a/lsh/src/testsuite/spki-tag-test.c +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - -/* Examples taken from RFC-2693 */ - -{ - struct spki_tag *tag = spki_sexp_to_tag(string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "(3:ftp13:ftp.clark.net3:cme(1:*3:set4:read5:write))") , 1), 17); - struct sexp *access = string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "(3:ftp13:ftp.clark.net3:cme4:read)") , 1); - fputs("Granting access 1 ... ", stderr); - assert(tag); - assert(access); - - if (SPKI_TAG_MATCH(tag, access)) - fputs("ok.\n", stderr); - else - { fputs("failed.\n", stderr);; exit(1); } - KILL(tag); - KILL(access); -} - - -{ - struct spki_tag *tag = spki_sexp_to_tag(string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "(3:ftp13:ftp.clark.net3:cme(1:*3:set4:read5:write))") , 1), 17); - struct sexp *access = string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "(3:ftp13:ftp.clark.net3:cme6:delete)") , 1); - fputs("Denying access 2 ... ", stderr); - assert(tag); - assert(access); - - if (!SPKI_TAG_MATCH(tag, access)) - fputs("ok.\n", stderr); - else - { fputs("failed.\n", stderr);; exit(1); } - KILL(tag); - KILL(access); -} - - -{ - struct spki_tag *tag = spki_sexp_to_tag(string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "(3:ftp13:ftp.clark.net3:cme(1:*3:set4:read5:write))") , 1), 17); - struct sexp *access = string_to_sexp(SEXP_TRANSPORT, ssh_format("%lz", "(3:ftp13:ftp.clark.net3:cme)") , 1); - fputs("Denying access 3 ... ", stderr); - assert(tag); - assert(access); - - if (!SPKI_TAG_MATCH(tag, access)) - fputs("ok.\n", stderr); - else - { fputs("failed.\n", stderr);; exit(1); } - KILL(tag); - KILL(access); -} - - - return 0; -} diff --git a/lsh/src/testsuite/spki-tag-test.m4 b/lsh/src/testsuite/spki-tag-test.m4 deleted file mode 100755 index 9c16451..0000000 Binary files a/lsh/src/testsuite/spki-tag-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/ssh1-fallback-test b/lsh/src/testsuite/ssh1-fallback-test deleted file mode 100644 index 1dd7ac7..0000000 --- a/lsh/src/testsuite/ssh1-fallback-test +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/sh - -# Tests the ssh-1 fallback mechanism - -if [ -z "$srcdir" ] ; then - srcdir=`pwd` -fi - -. $srcdir/functions.sh - -spawn_lshd --ssh1-fallback=$srcdir/fake-sshd1 \ - && echo "SSH-1.5-ssh1-fallback-test" \ - | tcpconnect localhost $PORT \ - | grep -q a-packet && test_success diff --git a/lsh/src/testsuite/string-test.c b/lsh/src/testsuite/string-test.c deleted file mode 100644 index b64a409..0000000 --- a/lsh/src/testsuite/string-test.c +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); -fputs("lsh_get_cstring 1 ... ", stderr); -{ - struct lsh_string *s = ssh_format("%lz", "foo") ; - const char *p = lsh_get_cstring(s); - if (p && !strcmp(p, "foo")) fputs("ok.\n", stderr); else { fputs("failed.\n", stderr);; exit(1); } -} -fputs("lsh_get_cstring 2 ... ", stderr); -{ - struct lsh_string *s = simple_decode_hex("66006f") ; - if (!lsh_get_cstring(s)) fputs("ok.\n", stderr); else { fputs("failed.\n", stderr);; exit(1); } -} -fputs("lsh_get_cstring 3 ... ", stderr); -{ - struct lsh_string *s = simple_decode_hex("6600") ; - if (!lsh_get_cstring(s)) fputs("ok.\n", stderr); else { fputs("failed.\n", stderr);; exit(1); } -} -fputs("lsh_get_cstring 3 ... ", stderr); -{ - struct lsh_string *s = simple_decode_hex("") ; - const char *p = lsh_get_cstring(s); - if (p && !*p) fputs("ok.\n", stderr); else { fputs("failed.\n", stderr);; exit(1); } -} - - return 0; -} diff --git a/lsh/src/testsuite/string-test.m4 b/lsh/src/testsuite/string-test.m4 deleted file mode 100644 index d7ea6e8..0000000 --- a/lsh/src/testsuite/string-test.m4 +++ /dev/null @@ -1,22 +0,0 @@ -TS_MESSAGE(»lsh_get_cstring 1«) -{ - struct lsh_string *s = TS_STRING("foo"); - const char *p = lsh_get_cstring(s); - TS_CHECK(p && !strcmp(p, "foo")) -} -TS_MESSAGE(»lsh_get_cstring 2«) -{ - struct lsh_string *s = TS_STRING(#66006f#); - TS_CHECK(!lsh_get_cstring(s)) -} -TS_MESSAGE(»lsh_get_cstring 3«) -{ - struct lsh_string *s = TS_STRING(#6600#); - TS_CHECK(!lsh_get_cstring(s)) -} -TS_MESSAGE(»lsh_get_cstring 3«) -{ - struct lsh_string *s = TS_STRING(##); - const char *p = lsh_get_cstring(s); - TS_CHECK(p && !*p) -} diff --git a/lsh/src/testsuite/tcpip-local-test b/lsh/src/testsuite/tcpip-local-test deleted file mode 100755 index 90324ba..0000000 Binary files a/lsh/src/testsuite/tcpip-local-test and /dev/null differ diff --git a/lsh/src/testsuite/tcpip-remote-test b/lsh/src/testsuite/tcpip-remote-test deleted file mode 100755 index e0e7fc0..0000000 Binary files a/lsh/src/testsuite/tcpip-remote-test and /dev/null differ diff --git a/lsh/src/testsuite/twofish-test.c b/lsh/src/testsuite/twofish-test.c deleted file mode 100755 index 713c4b3..0000000 --- a/lsh/src/testsuite/twofish-test.c +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include "lsh.h" - -#include "algorithms.h" -#include "crypto.h" -#include "digits.h" -#include "format.h" -#include "randomness.h" -#include "sexp.h" -#include "spki.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -int main(int argc, char **argv) -{ - argp_parse(&werror_argp, argc, argv, 0, NULL, NULL); - - { - struct crypto_algorithm *algorithm = make_twofish_algorithm(16); - struct lsh_string *key = simple_decode_hex("00000000000000000000000000000000") ; - struct lsh_string *plain = simple_decode_hex("00000000000000000000000000000000") ; - struct lsh_string *cipher = simple_decode_hex("9F589F5CF6122C32B6BFEC2F2AE8C35A") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with Twofish 128 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with Twofish 128 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = make_twofish_algorithm(24); - struct lsh_string *key = simple_decode_hex("0123456789ABCDEFFEDCBA98765432100011223344556677") ; - struct lsh_string *plain = simple_decode_hex("00000000000000000000000000000000") ; - struct lsh_string *cipher = simple_decode_hex("CFD1D2E5A9BE9CDF501F13B892BD2248") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with Twofish 192 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with Twofish 192 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - { - struct crypto_algorithm *algorithm = make_twofish_algorithm(32); - struct lsh_string *key = simple_decode_hex("0123456789ABCDEFFEDCBA987654321000112233445566778899AABBCCDDEEFF") ; - struct lsh_string *plain = simple_decode_hex("00000000000000000000000000000000") ; - struct lsh_string *cipher = simple_decode_hex("37527BE0052334B89F0CFCCAE87CFA20") ; - struct crypto_instance *c; - - assert(key->length == algorithm->key_size); - assert(!algorithm->iv_size); - - c = MAKE_ENCRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Encrypting with Twofish 256 ... ", stderr); - a = crypt_string(c, plain, 0); - b = lsh_string_dup(cipher); - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - c = MAKE_DECRYPT(algorithm, key->data, NULL); - - { - struct lsh_string *a, *b; - fputs("Decrypting with Twofish 256 ... ", stderr); - a = crypt_string(c, cipher, 0); - b = plain; - if (!lsh_string_eq(a, b)) - { fputs("failed.\n", stderr);; exit(1); } - fputs("ok.\n", stderr); - lsh_string_free(a); - lsh_string_free(b); - } - - KILL(c); - - lsh_string_free(key); - lsh_string_free(cipher); - } - - - - - - - - - - return 0; -} diff --git a/lsh/src/testsuite/twofish-test.m4 b/lsh/src/testsuite/twofish-test.m4 deleted file mode 100755 index 4a4baec..0000000 Binary files a/lsh/src/testsuite/twofish-test.m4 and /dev/null differ diff --git a/lsh/src/testsuite/write-key-1-test b/lsh/src/testsuite/write-key-1-test deleted file mode 100755 index dfbd180..0000000 Binary files a/lsh/src/testsuite/write-key-1-test and /dev/null differ diff --git a/lsh/src/testsuite/write-key-2-test b/lsh/src/testsuite/write-key-2-test deleted file mode 100755 index 4c113a7..0000000 Binary files a/lsh/src/testsuite/write-key-2-test and /dev/null differ diff --git a/lsh/src/translate_signal.c b/lsh/src/translate_signal.c deleted file mode 100755 index ca95acd..0000000 --- a/lsh/src/translate_signal.c +++ /dev/null @@ -1,134 +0,0 @@ -/* translate_signal.c - * - * Translate local signal numbers to canonical numbers, and vice versa. - * The value of "canonical" is rather arbitrary. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "translate_signal.h" - -#include "atoms.h" - -#include - -struct signal_assoc -{ - int network; - int local; -}; - -/* IOT is the mnemonic for the PDP-11 instruction used by the abort function */ -#ifdef SIGIOT -# ifndef SIGABRT -# define SIGABRT SIGIOT -# endif -#endif - -/* The body is generated by - * - SIGNALS="ABRT ALRM FPE HUP ILL INT KILL PIPE QUIT SEGV TERM USR1 USR2" - for s in $SIGNALS; do - echo "#ifdef SIG""$s" - echo " { ATOM_""$s, SIG""$s"}, - echo "#endif" - done -*/ - -static const struct signal_assoc translate[] = -{ -#ifdef SIGABRT - { ATOM_ABRT, SIGABRT}, -#endif -#ifdef SIGALRM - { ATOM_ALRM, SIGALRM}, -#endif -#ifdef SIGFPE - { ATOM_FPE, SIGFPE}, -#endif -#ifdef SIGHUP - { ATOM_HUP, SIGHUP}, -#endif -#ifdef SIGILL - { ATOM_ILL, SIGILL}, -#endif -#ifdef SIGINT - { ATOM_INT, SIGINT}, -#endif -#ifdef SIGKILL - { ATOM_KILL, SIGKILL}, -#endif -#ifdef SIGPIPE - { ATOM_PIPE, SIGPIPE}, -#endif -#ifdef SIGQUIT - { ATOM_QUIT, SIGQUIT}, -#endif -#ifdef SIGSEGV - { ATOM_SEGV, SIGSEGV}, -#endif -#ifdef SIGTERM - { ATOM_TERM, SIGTERM}, -#endif -#ifdef SIGUSR1 - { ATOM_USR1, SIGUSR1}, -#endif -#ifdef SIGUSR2 - { ATOM_USR2, SIGUSR2}, -#endif - { -1, -1 } -}; - -/* Returns ATOM_SIGNAL_UNKNOWN_LOCAL if the signal has no network - * number */ -int signal_local_to_network(int signal) -{ - int i; - - if (!signal) - return 0; - - for (i = 0; ; i++) - { - if (translate[i].local < 0) - return ATOM_SIGNAL_UNKNOWN_LOCAL; - if (translate[i].local == signal) - return translate[i].network; - } -} - -/* Returns 0 if the signal has no local number */ -int signal_network_to_local(int signal) -{ - int i; - - if (!signal) - return 0; - - for (i = 0; ; i++) - { - if (translate[i].local < 0) - return 0; - if (translate[i].network == signal) - return translate[i].local; - } -} diff --git a/lsh/src/translate_signal.h b/lsh/src/translate_signal.h deleted file mode 100755 index f38101d..0000000 --- a/lsh/src/translate_signal.h +++ /dev/null @@ -1,34 +0,0 @@ -/* translate_signal.h - * - * Translate local signal numbers to canonical numbers, and vice versa. - * The value of "canonical" is rather arbitrary. - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_TRANSLATE_SIGNAL_H_INCLUDED -#define LSH_TRANSLATE_SIGNAL_H_INCLUDED - -int signal_local_to_network(int signal); -int signal_network_to_local(int signal); - -#endif /* LSH_TRANSLATE_SIGNAL_H_INCLUDED */ diff --git a/lsh/src/tty.c b/lsh/src/tty.c deleted file mode 100755 index 8d27ea0..0000000 --- a/lsh/src/tty.c +++ /dev/null @@ -1,517 +0,0 @@ -/* tty.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, Niels Möller, Balázs Scheidler - * - * 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 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 should 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 - */ - -#include "tty.h" - -#include "format.h" -#include "parse.h" -#include "ssh.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include - -#include -#include -#include - -#if WITH_PTY_SUPPORT - -int -tty_getattr(int fd, struct termios *ios) -{ - return tcgetattr(fd, ios) != -1 ? 1 : 0; -} - -int -tty_setattr(int fd, struct termios *ios) -{ - return tcsetattr(fd, TCSADRAIN, ios) != -1 ? 1 : 0; -} - -int -tty_getwinsize(int fd, struct terminal_dimensions *dims) -{ - struct winsize ws; - int rc; - - rc = ioctl(fd, TIOCGWINSZ, &ws); - if (rc != -1) - { - dims->char_width = ws.ws_col; - dims->char_height = ws.ws_row; - dims->pixel_width = ws.ws_xpixel; - dims->pixel_height = ws.ws_ypixel; - return 1; - } - return 0; -} - -int -tty_setwinsize(int fd, const struct terminal_dimensions *dims) -{ - struct winsize ws; - - ws.ws_row = dims->char_width; - ws.ws_col = dims->char_height; - ws.ws_xpixel = dims->pixel_width; - ws.ws_ypixel = dims->pixel_height; - - return ioctl(fd, TIOCSWINSZ, &ws) == -1 ? 0 : 1; -} - -static int cc_ndx[] = -{ -#ifdef VINTR - VINTR, -#else - -1, -#endif -#ifdef VQUIT - VQUIT, -#else - -1, -#endif -#ifdef VINTR - VERASE, -#else - -1, -#endif -#ifdef VKILL - VKILL, -#else - -1, -#endif -#ifdef VEOF - VEOF, -#else - -1, -#endif -#ifdef VEOL - VEOL, -#else - -1, -#endif -#ifdef VEOL2 - VEOL2, -#else - -1, -#endif -#ifdef VSTART - VSTART, -#else - -1, -#endif -#ifdef VSTOP - VSTOP, -#else - -1, -#endif -#ifdef VSUSP - VSUSP, -#else - -1, -#endif -#ifdef VDSUSP - VDSUSP, -#else - -1, -#endif -#ifdef VREPRINT - VREPRINT, -#else - -1, -#endif -#ifdef VWERASE - VWERASE, -#else - -1, -#endif -#ifdef VLNEXT - VLNEXT, -#else - -1, -#endif -#ifdef VFLUSH - VFLUSH, -#else - -1, -#endif -#ifdef VSWTCH - VSWTCH, -#else - -1, -#endif -#ifdef VSTATUS - VSTATUS, -#else - -1, -#endif -#ifdef VDISCARD - VDISCARD -#else - -1, -#endif -}; - -static int cc_iflags[] = { -#ifdef IGNPAR - IGNPAR, -#else - 0, -#endif -#ifdef PARMRK - PARMRK, -#else - 0, -#endif -#ifdef INPCK - INPCK, -#else - 0, -#endif -#ifdef ISTRIP - ISTRIP, -#else - 0, -#endif -#ifdef INLCR - INLCR, -#else - 0, -#endif -#ifdef IGNCR - IGNCR, -#else - 0, -#endif -#ifdef ICRNL - ICRNL, -#else - 0, -#endif -#ifdef IUCLC - IUCLC, -#else - 0, -#endif -#ifdef IXON - IXON, -#else - 0, -#endif -#ifdef IXANY - IXANY, -#else - 0, -#endif -#ifdef IXOFF - IXOFF, -#else - 0, -#endif -#ifdef IMAXBEL - IMAXBEL -#else - 0 -#endif -}; - -static int cc_oflags[] = { -#ifdef OPOST - OPOST, -#else - 0, -#endif -#ifdef OLCUC - OLCUC, -#else - 0, -#endif -#ifdef ONLCR - ONLCR, -#else - 0, -#endif -#ifdef OCRNL - OCRNL, -#else - 0, -#endif -#ifdef ONOCR - ONOCR, -#else - 0, -#endif -#ifdef ONLRET - ONLRET -#else - 0 -#endif -}; - -static int cc_cflags[] = { -#ifdef CS7 - CS7, -#else - 0, -#endif -#ifdef CS8 - CS8, -#else - 0, -#endif -#ifdef PARENB - PARENB, -#else - 0, -#endif -#ifdef PARODD - PARODD -#else - 0 -#endif -}; - -static int cc_lflags[] = { -#ifdef ISIG - ISIG, -#else - 0, -#endif -#ifdef ICANON - ICANON, -#else - 0, -#endif -#ifdef XCASE - XCASE, -#else - 0, -#endif -#ifdef ECHO - ECHO, -#else - 0, -#endif -#ifdef ECHOE - ECHOE, -#else - 0, -#endif -#ifdef ECHOK - ECHOK, -#else - 0, -#endif -#ifdef ECHONL - ECHONL, -#else - 0, -#endif -#ifdef NOFLSH - NOFLSH, -#else - 0, -#endif -#ifdef TOSTOP - TOSTOP, -#else - 0, -#endif -#ifdef IEXTEN - IEXTEN, -#else - 0, -#endif -#ifdef ECHOCTL - ECHOCTL, -#else - 0, -#endif -#ifdef ECHOKE - ECHOKE, -#else - 0, -#endif -#ifdef PENDIN - PENDIN -#else - 0, -#endif -}; - -#define SIZE(x) (sizeof((x)) / sizeof((x)[0])) - -/* FIXME: TTY_?SPEED not handled */ - -#define PARSE_FLAGS(cc, bits, offset) do { \ - debug("tty_encode_term_mode: termios bits %xi (offset %i)\n", \ - (bits), (offset)); \ - for (i=0; ilength - p) < 5) \ - goto fail; \ - \ - r = ((bits) & (cc)[i]) ? 1 : 0; \ - new->data[p++] = i + (offset); \ - WRITE_UINT32(new->data + p, r); \ - p += 4; \ - } \ -} while(0) - -struct lsh_string * -tty_encode_term_mode(struct termios *ios) -{ - unsigned int i; - struct lsh_string *new; - UINT32 p = 0; - - new = lsh_string_alloc(650); - - for (i=0; ilength - p) < 5) - goto fail; - - new->data[p++] = i + 1; - WRITE_UINT32(new->data + p, ios->c_cc[cc_ndx[i]]); - p += 4; - } - } - PARSE_FLAGS(cc_iflags, ios->c_iflag, 30); - PARSE_FLAGS(cc_lflags, ios->c_lflag, 50); - PARSE_FLAGS(cc_oflags, ios->c_oflag, 70); - PARSE_FLAGS(cc_cflags, ios->c_cflag, 90); - - if ( (new->length - p) < 1) - goto fail; - - new->data[p++] = 0; - new->length = p; - - return new; - -fail: - lsh_string_free(new); - return NULL; -} - -#define TTY_SET_VALUE(target, param, table, index) \ -do { \ - int _value; \ - if ((index) < (sizeof(table) / sizeof((table)[0])) \ - && ((_value = (table)[index]) >= 0)) \ - target[_value] = param; \ -} while(0) - -#define TTY_SET_FLAG(target, flag, table, index) \ -do { \ - int _mask; \ - if ((index) < (sizeof(table) / sizeof((table)[0])) \ - && ((_mask = (table)[index]) >= 0)) \ - { \ - if (flag) \ - (target) |= _mask; \ - else \ - (target) &= ~_mask; \ - } \ -} while(0) - -/* Interpret ssh:s terminal description */ -int -tty_decode_term_mode(struct termios *ios, UINT32 t_len, const UINT8 *t_modes) -{ - struct simple_buffer buffer; - - simple_buffer_init(&buffer, t_len, t_modes); - - for (;;) - { - unsigned opcode; - - if (!parse_uint8(&buffer, &opcode)) - return 0; - - { - UINT32 param; - - if ( (opcode == SSH_TTY_OP_END) - || (opcode > SSH_TTY_OP_RESERVED)) - break; - - if (!parse_uint32(&buffer, ¶m)) - return 0; - { - /* FIXME: This code might be simplified a little. I - * think some table lookups (mapping each opcode to some - * "action class", including ranges to check as well as - * further tables... Something like - - struct action = at[opcode]; - switch (action->type) - { - case ACTION_FLAG: - ... - */ - if (opcode < 30) - TTY_SET_VALUE(ios->c_cc, param, cc_ndx, opcode - 1); - else if (opcode < 50) - TTY_SET_FLAG(ios->c_iflag, param, cc_iflags, opcode - 30); - else if (opcode < 70) - TTY_SET_FLAG(ios->c_lflag, param, cc_lflags, opcode - 50); - else if (opcode < 90) - TTY_SET_FLAG(ios->c_oflag, param, cc_oflags, opcode - 70); - else if (opcode < 128) - TTY_SET_FLAG(ios->c_cflag, param, cc_cflags, opcode - 90); - else - { - switch(opcode) - { - case SSH_TTY_OP_ISPEED: - case SSH_TTY_OP_OSPEED: - /* FIXME: set input/output speed there's no point - * in setting the speed of a pseudo tty IMHO */ - /* The speed of the user's terminal could be - * useful for programs like emacs that try to - * optimize the redraw algorithm (slower - * terminals gets partial updates. But that is - * pretty useless as long as 9600 bps is - * considered fast... */ - break; - default: - werror("Unsupported terminal mode: %i\n", opcode); - } - } - } - } - } - return 1; -} - -#endif /* WITH_PTY_SUPPORT */ diff --git a/lsh/src/tty.h b/lsh/src/tty.h deleted file mode 100755 index 32a09ae..0000000 --- a/lsh/src/tty.h +++ /dev/null @@ -1,66 +0,0 @@ -/* tty.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998, 1999, Niels Möller, Balázs Scheidler - * - * 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 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 should 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 - */ - -#ifndef LSH_TTY_H_INCLUDED -#define LSH_TTY_H_INCLUDED - -#include "lsh_types.h" - -#include - -struct terminal_dimensions -{ - UINT32 char_width; - UINT32 char_height; - UINT32 pixel_width; - UINT32 pixel_height; -}; - -int tty_getattr(int fd, struct termios *ios); -int tty_setattr(int fd, struct termios *ios); - -int tty_getwinsize(int fd, struct terminal_dimensions *dims); -int tty_setwinsize(int fd, const struct terminal_dimensions *dims); - -struct lsh_string * -tty_encode_term_mode(struct termios *ios); -int -tty_decode_term_mode(struct termios *ios, UINT32 t_len, const UINT8 *t_modes); - -#if HAVE_CFMAKERAW -#define CFMAKERAW cfmakeraw -#else /* !HAVE_CFMAKERAW */ -/* The flags part definition is probably from the linux cfmakeraw man - * page. We also set the MIN and TIME attributes (note that these use - * the same fields as VEOF and VEOL). */ - -#define CFMAKERAW(ios) do { \ - (ios)->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); \ - (ios)->c_oflag &= ~OPOST; \ - (ios)->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); \ - (ios)->c_cflag &= ~(CSIZE|PARENB); (ios)->c_cflag |= CS8; \ - (ios)->c_cc[VMIN] = 3; (ios)->c_cc[VTIME] = 2; \ -} while(0) -#endif /* !HAVE_CFMAKERAW */ - -#endif /* LSH_TTY_H_INCLUDED */ diff --git a/lsh/src/twofish.c b/lsh/src/twofish.c deleted file mode 100755 index 4015cdb..0000000 --- a/lsh/src/twofish.c +++ /dev/null @@ -1,103 +0,0 @@ -/* twofish.c - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller, J.H.M. Dassen (Ray) - * - * 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 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 should 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 - */ - -#include "crypto.h" - -#include "werror.h" -#include "xalloc.h" - -#include "nettle/twofish.h" - -#include - -#include "twofish.c.x" - -/* Twofish */ -/* GABA: - (class - (name twofish_instance) - (super crypto_instance) - (vars - (ctx . "struct twofish_ctx"))) -*/ - -static void -do_twofish_encrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(twofish_instance, self, s); - - twofish_encrypt(&self->ctx, length, dst, src); -} - -static void -do_twofish_decrypt(struct crypto_instance *s, - UINT32 length, const UINT8 *src, UINT8 *dst) -{ - CAST(twofish_instance, self, s); - - twofish_decrypt(&self->ctx, length, dst, src); -} - -static struct crypto_instance * -make_twofish_instance(struct crypto_algorithm *algorithm, int mode, - const UINT8 *key, const UINT8 *iv UNUSED) -{ - NEW(twofish_instance, self); - - self->super.block_size = TWOFISH_BLOCK_SIZE; - self->super.crypt = ( (mode == CRYPTO_ENCRYPT) - ? do_twofish_encrypt - : do_twofish_decrypt); - - /* We don't have to deal with weak keys - being an AES candidate, Twofish was - * designed to have none. */ - twofish_set_key(&self->ctx, algorithm->key_size, key); - - return &self->super; -} - -struct crypto_algorithm * -make_twofish_algorithm(UINT32 key_size) -{ - NEW(crypto_algorithm, algorithm); - - assert(key_size <= TWOFISH_MAX_KEY_SIZE); - assert(key_size >= TWOFISH_MIN_KEY_SIZE); - - algorithm->block_size = TWOFISH_BLOCK_SIZE; - algorithm->key_size = key_size; - algorithm->iv_size = 0; - algorithm->make_crypt = make_twofish_instance; - - return algorithm; -} - -struct crypto_algorithm twofish128_algorithm = -{ STATIC_HEADER, TWOFISH_BLOCK_SIZE, 16, 0, make_twofish_instance}; - -struct crypto_algorithm twofish192_algorithm = -{ STATIC_HEADER, TWOFISH_BLOCK_SIZE, 24, 0, make_twofish_instance}; - -struct crypto_algorithm twofish256_algorithm = -{ STATIC_HEADER, TWOFISH_BLOCK_SIZE, 32, 0, make_twofish_instance}; diff --git a/lsh/src/twofish.c.x b/lsh/src/twofish.c.x deleted file mode 100755 index ba5cfbe..0000000 Binary files a/lsh/src/twofish.c.x and /dev/null differ diff --git a/lsh/src/unix_interact.c b/lsh/src/unix_interact.c deleted file mode 100755 index 04bd3df..0000000 --- a/lsh/src/unix_interact.c +++ /dev/null @@ -1,419 +0,0 @@ -/* unix_interact.c - * - * Interact with the user. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1999 Niels Möller - * - * 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 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 should 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 - */ - -#include "interact.h" - -#include "format.h" -#include "io.h" -#include "resource.h" -#include "suspend.h" -#include "tty.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include - -#include - -#if HAVE_UNISTD_H -# include -#endif - -#include -#include -#include - -#if MACOS -#include "lsh_context.h" -#endif - -#include "unix_interact.c.x" - -#if MACOS -extern int yes_or_no(const struct lsh_string *s, int def, int free); -#else -static volatile sig_atomic_t window_changed; -#endif - -static void winch_handler(int signum) -{ - assert(signum == SIGWINCH); - - window_changed = 1; -} - - -/* Depends on the tty being line buffered */ -static int -read_line(int fd, UINT32 size, UINT8 *buffer) -{ - UINT32 i = 0; - - while (i < size) - { - int res = read(fd, buffer + i, size - i); - if (!res) - /* User pressed EOF (^D) */ - return i; - else if (res < 0) - switch(errno) - { - case EAGAIN: - case EINTR: - break; - default: - /* I/O error */ - werror("unix_interact.c: read_line: %z (errno = %i)\n", - errno, STRERROR(errno)); - return 0; - } - else - { - UINT32 j; - for (j = 0; j < (unsigned) res; j++, i++) - if (buffer[i] == '\n') - return i; - } - } - /* We have filled our buffer already; continue reading until end of line */ -#define BUFSIZE 512 - for (;;) - { - UINT8 b[BUFSIZE]; - int res = read(fd, b, BUFSIZE); - if (!res) - /* EOF */ - return size; - else if (res < 0) - switch(errno) - { - case EAGAIN: - case EINTR: - break; - default: - /* I/O error */ - werror("tty_read_line: %z (errno = %i)\n", - errno, strerror(errno)); - return 0; - } - else - { - UINT32 j; - for (j = 0; j < (unsigned) res; j++) - if (b[j] == '\n') - return res; - } - } -#undef BUFSIZE -} - - -/* NOTE: If there are more than one instance of this class, window - * changes can be missed, as only one of them will have its signal - * handler installed properly. */ - -/* GABA: - (class - (name window_subscriber) - (super resource) - (vars - (next object window_subscriber) - (callback object window_change_callback))) -*/ - -/* GABA: - (class - (name unix_interact) - (super interact) - (vars - (tty_fd . int) - (subscribers object window_subscriber))) -*/ - -#define IS_TTY(self) ((self)->tty_fd >= 0) - -static int -unix_is_tty(struct interact *s) -{ - CAST(unix_interact, self, s); - - return IS_TTY(self); -} - -/* FIXME: Rewrite to operate on tty_fd. */ -static struct lsh_string * -unix_read_password(struct interact *s UNUSED, - UINT32 max_length UNUSED, - const struct lsh_string *prompt, int free) -{ - /* NOTE: Ignores max_length; instead getpass's limit applies. */ - - char *password; - const char *cprompt = lsh_get_cstring(prompt); - - if (!cprompt) - { - if (free) - lsh_string_free(prompt); - return NULL; - } - /* NOTE: This function uses a static buffer. */ - password = getpass(cprompt); - - if (free) - lsh_string_free(prompt); - - if (!password) - return NULL; - - return make_string(password); -} - - -static int -unix_yes_or_no(struct interact *s, - const struct lsh_string *prompt, - int def, int free) -{ -#define TTY_BUFSIZE 10 - - CAST(unix_interact, self, s); - if (!IS_TTY(self) || quiet_flag) - { - if (free) - lsh_string_free(prompt); - return def; - } - else - { -#if MACOS - return yes_or_no(prompt, def, free); -#else - UINT8 buffer[TTY_BUFSIZE]; - const struct exception *e; - - e = write_raw(self->tty_fd, prompt->length, prompt->data); - - if (free) - lsh_string_free(prompt); - - if (e) - return def; - - if (!read_line(self->tty_fd, TTY_BUFSIZE, buffer)) - return def; - - switch (buffer[0]) - { - case 'y': - case 'Y': - return 1; - default: - return 0; - } -#endif -#undef TTY_BUFSIZE - } -} - -/* GABA: - (class - (name unix_termios) - (super terminal_attributes) - (vars - (ios . "struct termios"))) -*/ - -static struct terminal_attributes * -do_make_raw(struct terminal_attributes *s) -{ - CAST(unix_termios, self, s); - CLONED(unix_termios, res, self); - - CFMAKERAW(&res->ios); - - return &res->super; -} - -static struct lsh_string * -do_encode(struct terminal_attributes *s) -{ - CAST(unix_termios, self, s); - return tty_encode_term_mode(&self->ios); -} - -static struct terminal_attributes * -unix_get_attributes(struct interact *s) -{ - CAST(unix_interact, self, s); - - if (!IS_TTY(self)) - return NULL; - else - { - NEW(unix_termios, res); - res->super.make_raw = do_make_raw; - res->super.encode = do_encode; - - if (!tty_getattr(self->tty_fd, &res->ios) < 0) - { - KILL(res); - return NULL; - } - return &res->super; - } -} - -static int -unix_set_attributes(struct interact *s, - struct terminal_attributes *a) -{ - CAST(unix_interact, self, s); - CAST(unix_termios, attr, a); - - return IS_TTY(self) - && tty_setattr(self->tty_fd, &attr->ios); -} - -static int -unix_window_size(struct interact *s, - struct terminal_dimensions *d) -{ - CAST(unix_interact, self, s); - - return IS_TTY(self) - && tty_getwinsize(self->tty_fd, d); -} - -static struct resource * -unix_window_change_subscribe(struct interact *s, - struct window_change_callback *callback) -{ - CAST(unix_interact, self, s); - - NEW(window_subscriber, subscriber); - init_resource(&subscriber->super, NULL); - - subscriber->next = self->subscribers; - subscriber->callback = callback; - - self->subscribers = subscriber; - - return &subscriber->super; -} - -/* GABA: - (class - (name winch_handler) - (super lsh_callback) - (vars - (interact object unix_interact))) -*/ - -static void -do_winch_handler(struct lsh_callback *s) -{ - CAST(winch_handler, self, s); - struct unix_interact *i = self->interact; - - if (i->subscribers) - { - struct window_subscriber *s; - struct window_subscriber **s_p; - - for (s_p = &i->subscribers; (s = *s_p) ;) - { - if (!s->super.alive) - *s_p = s->next; - else - { - WINDOW_CHANGE_CALLBACK(s->callback, &i->super); - s_p = &s->next; - } - } - } -} - -static struct lsh_callback * -make_winch_handler(struct unix_interact *i) -{ - NEW(winch_handler, self); - self->super.f = do_winch_handler; - self->interact = i; - - return &self->super; -} - -struct interact * -make_unix_interact(struct io_backend *backend) -{ - NEW(unix_interact, self); - - self->super.is_tty = unix_is_tty; - self->super.read_password = unix_read_password; - self->super.yes_or_no = unix_yes_or_no; - self->super.get_attributes = unix_get_attributes; - self->super.set_attributes = unix_set_attributes; - self->super.window_size = unix_window_size; - self->super.window_change_subscribe = unix_window_change_subscribe; - - window_changed = 0; - - self->tty_fd = -1; - -#if HAVE_STDTTY_FILENO - if (isatty(STDTTY_FILENO)) - self->tty_fd = STDTTY_FILENO; -#else /* ! HAVE_STDTTY_FILENO */ -#if MACOS - self->tty_fd = open("dev:tty", O_RDWR); -#else - self->tty_fd = open("/dev/tty", O_RDWR); -#endif -#endif - - if (backend && (self->tty_fd >= 0)) - { - /* Track window changes. */ - struct sigaction winch; - - memset(&winch, 0, sizeof(winch)); - winch.sa_handler = winch_handler; - sigemptyset(&winch.sa_mask); - winch.sa_flags = 0; - - if (sigaction(SIGWINCH, &winch, NULL) < 0) - werror("Failed to install SIGWINCH handler (errno = %i): %z\n", - errno, STRERROR(errno)); - - io_signal_handler(backend, &window_changed, - make_winch_handler(self)); - - suspend_handle_tty(self->tty_fd); - } - return &self->super; -} diff --git a/lsh/src/unix_interact.c.x b/lsh/src/unix_interact.c.x deleted file mode 100755 index 30798f3..0000000 Binary files a/lsh/src/unix_interact.c.x and /dev/null differ diff --git a/lsh/src/unix_random.c b/lsh/src/unix_random.c deleted file mode 100755 index 37c7e41..0000000 --- a/lsh/src/unix_random.c +++ /dev/null @@ -1,874 +0,0 @@ -/* unix_random.c - * - * $Id$ - * - * Randomness polling on unix, using ideas from Peter Gutmann's - * cryptlib. */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "randomness.h" - -#include "crypto.h" -#include "reaper.h" -#include "xalloc.h" -#include "werror.h" - -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include -#include -#include -#include -#include - -#ifdef HAVE_POLL -# if HAVE_POLL_H -# include -# elif HAVE_SYS_POLL_H -# include -# endif -#else -# include "jpoll.h" -#endif - -/* Workaround for some version of FreeBSD. */ -#ifdef POLLRDNORM -# define MY_POLLIN (POLLIN | POLLRDNORM) -#else /* !POLLRDNORM */ -# define MY_POLLIN POLLIN -#endif /* !POLLRDNORM */ - -#include -#include - -enum poll_status { POLL_NO_POLL, POLL_RUNNING, POLL_FINISHED, POLL_FAILED }; - -#include "unix_random.c.x" - -/* GABA: - (class - (name unix_random) - (super random_poll) - (vars - ; For the slow poll - (reaper object reap) - (poll_uid . uid_t) - (pid . pid_t) - (status . "enum poll_status") - ; NOTE: This fd is not known to the gc. - (fd . int) - - ; For the fast poll, count number of slow polls per second. - (previous_time . time_t) - (time_count . unsigned))) -*/ - -/* GABA: - (class - (name unix_random_callback) - (super exit_callback) - (vars - (ctx object unix_random))) -*/ - -static void -do_unix_random_callback(struct exit_callback *s, - int signalled, int core UNUSED, - int value) -{ - CAST(unix_random_callback, self, s); - - if (signalled || value) - { - self->ctx->status = POLL_FAILED; - trace("unix_random.c: do_unix_random_callback, background poll failed.\n"); - } - else - { - self->ctx->status = POLL_FINISHED; - trace("unix_random.c: do_unix_random_callback, background poll finished.\n"); - } -} - -static struct exit_callback * -make_unix_random_callback(struct unix_random *ctx) -{ - NEW(unix_random_callback, self); - self->super.exit = do_unix_random_callback; - self->ctx = ctx; - - return &self->super; -} - -#define UNIX_RANDOM_POLL_SIZE 20 - -/* This structure ought to fit in a pipe buffer (so that we can - * waitpid the process before reading its stdout). */ - -struct unix_random_poll_result -{ - UINT32 count; - UINT8 data[UNIX_RANDOM_POLL_SIZE]; -}; - -#define UNIX_RANDOM_SOURCE_SCALE 8192 -struct unix_random_source -{ - const char *path; - const char *arg; /* For now, use at most one argument. */ - int has_alternative; - - /* If non-zero, count quality bits of entropy if the amount of output - * exceeds this value. */ - unsigned small; - /* Bits of entropy per UNIX_RANDOM_SOURCE_SCALE bytes of output. */ - unsigned quality; -}; - -/* Lots of output expected; round downwards. */ -#define WLARGE(x) 0, x -/* Small but significant output expected; round upwards */ -#define WSMALL(x) 100, x - -static const struct unix_random_source random_sources[] = -{ - { "/bin/vmstat", "-s", 1, WSMALL(30) }, - { "/usr/bin/vmstat", "-s", 0, WSMALL(30) }, - { "/bin/vmstat", "-c", 1, WSMALL(30) }, - { "/usr/bin/vmstat", "-c", 0, WSMALL(30) }, - { "/usr/bin/pfstat", NULL, 0, WSMALL(20) }, - { "/bin/vmstat", "-i", 1, WSMALL(20) }, - { "/usr/bin/vmstat", "-i", 0, WSMALL(20) }, - { "/usr/ucb/netstat", "-s", 1, WLARGE(20) }, - { "/usr/bin/netstat", "-s", 1, WLARGE(20) }, - { "/usr/sbin/netstat", "-s", 1, WLARGE(20) }, - { "/bin/netstat", "-s", 1, WLARGE(20) }, - { "/usr/etc/netstat", "-s", 0, WLARGE(20) }, - { "/usr/bin/nfsstat", NULL, 0, WLARGE(20) }, - { "/usr/ucb/netstat", "-m", 1, WSMALL(10) }, - { "/usr/bin/netstat", "-m", 1, WSMALL(10) }, - { "/usr/sbin/netstat", "-m", 1, WSMALL(10) }, - { "/bin/netstat", "-m", 1, WSMALL(10) }, - { "/usr/etc/netstat", "-m", 0, WSMALL(10) }, - { "/usr/ucb/netstat", "-in", 1, WSMALL(10) }, - { "/usr/bin/netstat", "-in", 1, WSMALL(10) }, - { "/usr/sbin/netstat", "-in", 1, WSMALL(10) }, - { "/bin/netstat", "-in", 1, WSMALL(10) }, - { "/usr/etc/netstat", "-in", 0, WSMALL(10) }, -#if 0 - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.7.1.0", 0 WSMALL(10) }, /* UDP in */ - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.7.4.0", 0 WSMALL(10) }, /* UDP out */ - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.4.3.0", 0 WSMALL(10) }, /* IP ? */ - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.6.10.0", 0 WSMALL(10) }, /* TCP ? */ - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.6.11.0", 0 WSMALL(10) }, /* TCP ? */ - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.6.13.0", 0 WSMALL(10) }, /* TCP ? */ -#endif - { "/usr/bin/mpstat", NULL, 0, WLARGE(10) }, - { "/usr/bin/w", NULL, 1, WLARGE(10) }, - { "/usr/bsd/w", NULL, 0, WLARGE(10) }, - { "/usr/bin/df", NULL, 1, WLARGE(10) }, - { "/bin/df", NULL, 0, WLARGE(10) }, - { "/usr/sbin/portstat", NULL, 0, WLARGE(10) }, - { "/usr/bin/iostat", NULL, 0, WLARGE(0) }, - { "/usr/bin/uptime", NULL, 1, WLARGE(0) }, - { "/usr/bsd/uptime", NULL, 0, WLARGE(0) }, - { "/bin/vmstat", "-f", 1, WLARGE(0) }, - { "/usr/bin/vmstat", "-f", 0, WLARGE(0) }, - { "/bin/vmstat", NULL, 1, WLARGE(0) }, - { "/usr/bin/vmstat", NULL, 0, WLARGE(0) }, - { "/usr/ucb/netstat", "-n", 1, WLARGE(5) }, - { "/usr/bin/netstat", "-n", 1, WLARGE(5) }, - { "/usr/sbin/netstat", "-n", 1, WLARGE(5) }, - { "/bin/netstat", "-n", 1, WLARGE(5) }, - { "/usr/etc/netstat", "-n", 0, WLARGE(5) }, -#if defined( __sgi ) || defined( __hpux ) - { "/bin/ps", "-el", 1, WLARGE(3) }, -#endif /* __sgi || __hpux */ - { "/usr/ucb/ps", "aux", 1, WLARGE(3) }, - { "/usr/bin/ps", "aux", 1, WLARGE(3) }, - { "/bin/ps", "aux", 0, WLARGE(3) }, - { "/usr/bin/ipcs", "-a", 1, WLARGE(5) }, - { "/bin/ipcs", "-a", 0, WLARGE(5) }, - /* Unreliable source, depends on system usage */ - { "/etc/pstat", "-p", 1, WLARGE(5) }, - { "/bin/pstat", "-p", 0, WLARGE(5) }, - { "/etc/pstat", "-S", 1, WLARGE(2) }, - { "/bin/pstat", "-S", 0, WLARGE(2) }, - { "/etc/pstat", "-v", 1, WLARGE(2) }, - { "/bin/pstat", "-v", 0, WLARGE(2) }, - { "/etc/pstat", "-x", 1, WLARGE(2) }, - { "/bin/pstat", "-x", 0, WLARGE(2) }, - { "/etc/pstat", "-t", 1, WLARGE(1) }, - { "/bin/pstat", "-t", 0, WLARGE(1) }, - /* pstat is your friend */ - { "/usr/bin/last", "-n 50", 1, WLARGE(3) }, -#ifdef __sgi - { "/usr/bsd/last", "-50", 0, WLARGE(3) }, -#endif /* __sgi */ -#ifdef __hpux - { "/etc/last", "-50", 0, WLARGE(3) }, -#endif /* __hpux */ - { "/usr/bsd/last", "-n 50", 0, WLARGE(3) }, - { "/usr/local/bin/lsof", "-lnwP", 0, WLARGE(3) }, - /* Output is very system and version-dependent */ -#if 0 - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.5.1.0", 0, WLARGE(1) }, /* ICMP ? */ - { "/usr/sbin/snmp_request", "localhost public get 1.3.6.1.2.1.5.3.0", 0, WLARGE(1) }, /* ICMP ? */ -#endif - { "/etc/arp", "-a", 1, WLARGE(1) }, - { "/usr/etc/arp", "-a", 1, WLARGE(1) }, - { "/usr/bin/arp", "-a", 1, WLARGE(1) }, - { "/usr/sbin/arp", "-a", 0, WLARGE(1) }, - { "/usr/sbin/ripquery", "-nw 1 127.0.0.1", 0, WLARGE(1) }, - { "/bin/lpstat", "-t", 1, WLARGE(1) }, - { "/usr/bin/lpstat", "-t", 1, WLARGE(1) }, - { "/usr/ucb/lpstat", "-t", 0, WLARGE(1) }, -#if 0 - { "/usr/bin/tcpdump", "-c 5 -efvvx", 0, WLARGE(10) }, - /* This is very environment-dependant. If - network traffic is low, it'll probably time - out before delivering 5 packets, which is OK - because it'll probably be fixed stuff like - ARP anyway */ - { "/usr/sbin/advfsstat", "-b usr_domain", 0, WLARGE(0) }, - { "/usr/sbin/advfsstat", "-l 2 usr_domain", 0, WLARGE(5) }, - { "/usr/sbin/advfsstat", "-p usr_domain", 0, WLARGE(0) }, - /* This is a complex and screwball program. Some - systems have things like rX_dmn, x = integer, - for RAID systems, but the statistics are - pretty dodgy */ - - /* The following aren't enabled since they're somewhat slow and not very - unpredictable, however they give an indication of the sort of sources - you can use (for example the finger might be more useful on a - firewalled internal network) */ - { "/usr/bin/finger", "@ml.media.mit.edu", 0, WLARGE(9) }, - { "/usr/local/bin/wget", "-O - http://lavarand.sgi.com/block.html", 0, WLARGE(9) }, - { "/bin/cat", "/usr/spool/mqueue/syslog", 0, WLARGE(9) }, -#endif /* 0 */ - { NULL, NULL, 0, 0, 0 } -}; - -#undef WSMALL -#undef WLARGE - -struct unix_random_source_state -{ - const struct unix_random_source *source; - pid_t pid; /* Running process. */ - int fd; - unsigned length; /* Amount of data read so far. */ -}; - -static int -spawn_source_process(unsigned *index, - struct unix_random_source_state *state, - int null) -{ - unsigned i; - pid_t pid; - /* output[0] for reading, output[1] for writing. */ - int output[2]; - - for (i = *index; random_sources[i].path; ) - { - if (access(random_sources[i].path, X_OK) < 0) - { - debug("unix_random.c: spawn_source_process: Skipping '%z'; not executable: %z\n", - random_sources[i].path, STRERROR(errno)); - i++; - } - else - break; - } - - if (!random_sources[i].path) - { - *index = i; - return 0; - } - - if (!lsh_make_pipe(output)) - { - werror("unix_random.c: spawn_source_process: Can't create pipe (errno = %i): %z\n", - errno, STRERROR(errno)); - return 0; - } - - state->source = random_sources + i; - - if (!random_sources[i].has_alternative) - i++; - else - /* Skip alternatives */ - while (random_sources[i].has_alternative) - i++; - - *index = i; - - debug("unix_random.c: Trying source %z %z\n", - state->source->path, - state->source->arg ? state->source->arg : ""); - - pid = fork(); - switch(pid) - { - default: - /* Parent */ - close (output[1]); - state->fd = output[0]; - state->pid = pid; - io_set_close_on_exec(state->fd); - io_set_nonblocking(state->fd); - state->length = 0; - return 1; - - case -1: - /* Error */ - close(output[0]); - close(output[1]); - return 0; - case 0: - /* Child */ - if (dup2(output[1], STDOUT_FILENO) < 0) - { - werror("unix_random.c: spawn_source_process: dup2 for stdout failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - - /* Ignore stderr. */ - if (dup2(null, STDERR_FILENO) < 0) - { - werror("unix_random.c: spawn_source_process: dup2 for stderr failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - - close (output[0]); - close (output[1]); - - /* Works also if state->source->arg == NULL */ - execl(state->source->path, state->source->path, state->source->arg, NULL); - - werror("spawn_source_process: execl '%z' failed (errno = %i): %z\n", - state->source->path, errno, STRERROR(errno)); - - _exit(EXIT_FAILURE); - } -} - -static unsigned -use_dev_random(struct hash_instance *hash) -{ -#define DEVRANDOM_SIZE 40 - UINT8 buffer[DEVRANDOM_SIZE]; - unsigned count = 0; - int res; - - int fd = open("/dev/urandom", O_RDONLY); - if (fd < 0) - return 0; - - do - { res = read(fd, buffer, DEVRANDOM_SIZE); } - while ( (res < 0) && (errno == EINTR)); - - if (res < 0) - werror("unix_random.c: Reading from /dev/urandom failed (errno = %i): %z\n", - errno, STRERROR(errno)); - else if (res > 0) - { - HASH_UPDATE(hash, res, buffer); - /* Count 4 bits of entropy for each byte. */ - count = res * 4; - } - else - werror("unix_random.c: No data available on /dev/urandom!\n"); - - close(fd); - - return count; -} - -static unsigned -use_procfs(struct hash_instance *hash) -{ -#if 0 - /* Peter Gutmann's code uses the following sources. I'm not sure - * what quality to assign to them. */ - static const char *proc_sources[] = - { - "/proc/interrupts", "/proc/loadavg", "/proc/locks", - "/proc/meminfo", "/proc/stat", "/proc/net/tcp", "/proc/net/udp", - "/proc/net/dev", "/proc/net/ipx", NULL - }; -#endif - - /* Not implemented. */ - return 0; -} - -/* Spawn this number of processes. */ -#define UNIX_RANDOM_POLL_PROCESSES 10 -#define UNIX_RANDOM_THRESHOLD 200 - -static unsigned -background_poll(struct hash_instance *hash) -{ - struct unix_random_source_state state[UNIX_RANDOM_POLL_PROCESSES]; - unsigned count = 0; - unsigned running = 0; - unsigned i; - unsigned index = 0; - int null; - - trace("unix_random.c: background_poll\n"); - - null = open("/dev/null", O_WRONLY); - if (null < 0) - { - werror("unix_random.c: background_poll: Failed to open /dev/null (errno = %i): %z\n", - errno, STRERROR(errno)); - return count; - } - - count += use_dev_random(hash); - count += use_procfs(hash); - - for (i = 0; i < UNIX_RANDOM_POLL_PROCESSES; i++) - state[i].fd = -1; - - for (running = 0; running 0) - { - fds[nfds].fd = state[i].fd; - fds[nfds].events = MY_POLLIN; - nfds++; - } - - assert(nfds == running); - - debug("unix_random.c: calling poll, nfds = %i\n", nfds); - if (poll(fds, nfds, -1) < 0) - { - werror("unix_random.c: background_poll poll failed (errno = %i): %z\n", - errno, STRERROR(errno)); - return count; - } - - debug("unix_random.c: returned from poll.\n"); - - for (i = 0; ipath); - - res = read(fds[i].fd, buffer, BUFSIZE); -#undef BUFSIZE - - if (res < 0) - { - if (errno != EINTR) - { - werror("unix_random.c: background_poll read failed (errno = %i): %z\n", - errno, STRERROR(errno)); - return count; - } - } - else if (res > 0) - { - HASH_UPDATE(hash, res, buffer); - state[j].length += res; - } - else - { /* EOF */ - int status; - unsigned entropy; - - close(fds[i].fd); - - state[j].fd = -1; - - /* Estimate entropy */ - entropy = state[j].length * state[j].source->quality / UNIX_RANDOM_SOURCE_SCALE ; - - if (!entropy && state[j].source->small - && (state[j].length > state[j].source->small)) - entropy = state[j].source->quality; - - debug("unix_random.c: background_poll: Got %i bytes from %z %z,\n" - " estimating %i bits of entropy.\n", - state[j].length, - state[j].source->path, state[j].source->arg ? state[j].source->arg : "", - entropy); - - count += entropy; - - if (waitpid(state[j].pid, &status, 0) < 0) - { - werror("unix_random.c: background_poll waitpid failed (errno = %i): %z\n", - errno, STRERROR(errno)); - return count; - } - if (WIFEXITED(status)) - { - if (WEXITSTATUS(status)) - debug("unix_random.c: background_poll: %z exited unsuccessfully.\n", - state[j].source->path); - } - else if (WIFSIGNALED(status)) - { - werror("unix_random.c: background_poll: %z died from signal %i (%z).\n", - state[j].source->path, WTERMSIG(status), STRSIGNAL(WTERMSIG(status))); - } - - if (! ((count < UNIX_RANDOM_THRESHOLD) - && spawn_source_process(&index, state + j, null))) - running--; - } - } - } - } - return count; -} - -static void -start_background_poll(struct unix_random *self) -{ - pid_t pid; - int output[2]; - - assert(self->status == POLL_NO_POLL); - - trace("unix_random.c: start_background_poll\n"); - - if (!lsh_make_pipe(output)) - { - werror("Failed to create pipe for background randomness poll.\n"); - return; - } - - pid = fork(); - switch(pid) - { - default: - /* Parent */ - close(output[1]); - self->fd = output[0]; - io_set_close_on_exec(self->fd); - - if (self->reaper) - REAP(self->reaper, pid, make_unix_random_callback(self)); - - self->pid = pid; - self->status = POLL_RUNNING; - - verbose("unix_random.c: Started background poll. pid = %i.\n", - pid); - - return; - - case -1: - /* Error */ - werror("Failed to fork background randomness poll (errno = %i): %z\n", - errno, STRERROR(errno)); - return; - - case 0: - /* Child */ - { - struct unix_random_poll_result result; - struct hash_instance *hash = MAKE_HASH(&sha1_algorithm); - -#if 0 - int hang = 1; - while (hang) - sleep(1); -#endif - int null = open("/dev/null", O_RDONLY); - - if (null < 0) - { - werror("start_background_poll: Failed to open /dev/null (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - - if (dup2(null, STDIN_FILENO) < 0) - { - werror("start_background_poll: dup2 for stdin failed (errno = %i): %z\n", - errno, STRERROR(errno)); - - _exit(EXIT_FAILURE); - } - - close(null); - close(output[0]); - io_set_close_on_exec(output[1]); - - /* Change uid */ - if (!getuid()) - setuid(self->poll_uid); - - if (!getuid()) - _exit(EXIT_FAILURE); - - result.count = background_poll(hash); - - assert(hash->hash_size == sizeof(result.data)); - HASH_DIGEST(hash, result.data); - - if (!write_raw(output[1], sizeof(result), (UINT8 *) &result)) - _exit(EXIT_SUCCESS); - - _exit(EXIT_FAILURE); - } - } -} - -static void -wait_background_poll(struct unix_random *self) -{ - int status; - - assert(self->status == POLL_RUNNING); - trace("unix_random.c: wait_background_poll\n"); - self->status = POLL_FAILED; - - /* FIXME: Check error code. */ - if (waitpid(self->pid, &status, 0) == self->pid) - { - if (WIFEXITED(status) && !WEXITSTATUS(status)) - self->status = POLL_FINISHED; - } - - if (self->reaper) - REAP(self->reaper, self->pid, NULL); -} - - -static unsigned -finish_background_poll(struct unix_random *self, struct hash_instance *hash) -{ - unsigned count = 0; - - switch(self->status) - { - case POLL_FINISHED: - { - struct unix_random_poll_result result; - const struct exception *e; - - e = read_raw(self->fd, sizeof(result), (UINT8 *) &result); - - if (e) - werror("Failed to read result from background randomness poll.\n"); - else - { - HASH_UPDATE(hash, UNIX_RANDOM_POLL_SIZE, result.data); - count = result.count; - } - break; - } - case POLL_FAILED: - werror("Background randomness poll failed.\n"); - break; - - case POLL_NO_POLL: - return 0; - - default: - fatal("finish_background_poll: Internal error.\n"); - } - close(self->fd); - self->status = POLL_NO_POLL; - - return count; -} - -static unsigned -use_seed_file(struct hash_instance *hash) -{ - if (getuid()) - { - /* Lock and read seed file. */ - } - - return 0; -} - -#define HASH_OBJECT(h, x) HASH_UPDATE((h), sizeof(x), (UINT8 *) &(x)) - -static unsigned -do_unix_random_slow(struct random_poll *s, struct hash_instance *hash) -{ - CAST(unix_random, self, s); - unsigned count; - time_t now = time(NULL); - pid_t pid = getpid(); - - /* Make sure we don't start with the same state, if several - * instances are initializing at about the same time. */ - - HASH_OBJECT(hash, now); - HASH_OBJECT(hash, pid); - - if (self->status == POLL_NO_POLL) - start_background_poll(self); - - if (self->status == POLL_RUNNING) - wait_background_poll(self); - - count = finish_background_poll(self, hash); - - /* Do this in the main process, as the background process may run as - * different user. */ - count += use_seed_file(hash); - - return count; -} - -static unsigned -do_unix_random_fast(struct random_poll *s, struct hash_instance *hash) -{ - CAST(unix_random, self, s); - unsigned count = 0; - -#if HAVE_GETRUSAGE - { - struct rusage rusage; - if (getrusage(RUSAGE_SELF, &rusage) < 0) - fatal("do_unix_random_fast: getrusage failed: (errno = %i) %z\n", - errno, STRERROR(errno)); - - HASH_OBJECT(hash, rusage); - count += 1; - } -#endif /* HAVE_GETRUSAGE */ -#if HAVE_GETTIMEOFDAY - { - struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) - fatal("do_unix_random_fast: gettimeofday failed(errno = %i) %z\n", - errno, STRERROR(errno)); - - HASH_OBJECT(hash, tv); - } -#endif /* HAVE_GETTIMEOFDAY */ - - { - /* Fallback that is useful if nothing else works. Count the number - * of slow polls between time ticks, and count one bit of - * entropy if we have more than 2 calls or more than two seconds - * between calls. */ - - time_t now = time(NULL); - self->time_count++; - if (now != self->previous_time) - { - if ( (self->time_count > 2) || ((now - self->previous_time) > 2)) - count++; - - HASH_OBJECT(hash, now); - HASH_OBJECT(hash, self->time_count); - - self->time_count = 0; - self->previous_time = now; - } - } - - return count; -} - -static void do_unix_random_background(struct random_poll *s) -{ - CAST(unix_random, self, s); - - if (self->status == POLL_NO_POLL) - start_background_poll(self); -} - -/* Using a NULL reaper argument is ok. It must be supplied only if the - * application is using a reaper, as that may get to our child process - * before we can waitpid it. */ - -struct random_poll * -make_unix_random(struct reap *reaper) -{ - NEW(unix_random, self); - - struct passwd *pw = getpwnam("nobody"); - - self->super.slow = do_unix_random_slow; - self->super.fast = do_unix_random_fast; - self->super.background = do_unix_random_background; - - self->reaper = reaper; - - if (pw && pw->pw_uid) - self->poll_uid = pw->pw_uid; - else - self->poll_uid = (uid_t) -1; - - self->status = POLL_NO_POLL; - self->previous_time = time(NULL); - self->time_count = 0; - - return &self->super; -} diff --git a/lsh/src/unix_random.c.x b/lsh/src/unix_random.c.x deleted file mode 100755 index 601b4d5..0000000 Binary files a/lsh/src/unix_random.c.x and /dev/null differ diff --git a/lsh/src/unix_user.c b/lsh/src/unix_user.c deleted file mode 100755 index 7067339..0000000 --- a/lsh/src/unix_user.c +++ /dev/null @@ -1,1069 +0,0 @@ -/* unix_user.c - * - * User-related functions on UN*X - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2000 Niels Möller - * - * 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 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 should 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 - */ - -#include "server_userauth.h" - -#include "format.h" -#include "io.h" -#include "reaper.h" -#include "werror.h" -#include "xalloc.h" - -#include -#include -#include -#include - -#include -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include - -#include - -#if HAVE_CRYPT_H -# include -#endif -#include -#include - -#if HAVE_SHADOW_H -#include -#endif - -#if WITH_UTMP -# if HAVE_UTMP_H -# include -# endif - -# if HAVE_UTMPX_H -# include -# endif -#else /* !WITH_UTMP */ - struct utmp; -#endif - -#if HAVE_LIBUTIL_H -# include -#endif - -/* Forward declaration */ -struct unix_user_db; - -#include "unix_user.c.x" - - -/* GABA: - (class - (name logout_cleanup) - (super exit_callback) - (vars - (process object resource) - (log space "struct utmp") - (c object exit_callback))) -*/ - -static void -do_logout_cleanup(struct exit_callback *s, - int signaled, int core, int value) -{ - CAST(logout_cleanup, self, s); - - /* No need to signal the process. */ - self->process->alive = 0; - -#if defined(WITH_UTMP) && defined(HAVE_LOGWTMP) - if (self->log) - logwtmp(self->log->ut_line, - "", - self->log->ut_host); -#endif /* WITH_UTMP && HAVE_LOGWTMP */ - EXIT_CALLBACK(self->c, signaled, core, value); -} - -static struct exit_callback * -make_logout_cleanup(struct resource *process, - struct utmp *log, - struct exit_callback *c) -{ - NEW(logout_cleanup, self); - self->super.exit = do_logout_cleanup; - - self->process = process; - self->log = log; - self->c = c; - - return &self->super; -} - - -#if WITH_UTMP -static void -lsh_strncpy(char *dst, unsigned n, struct lsh_string *s) -{ - unsigned length = MIN(n - 1, s->length); - memcpy(dst, s->data, length); - dst[length] = '\0'; -} - -/* Strips the leading "/dev/" part of s. */ -static void -lsh_strncpy_tty(char *dst, unsigned n, struct lsh_string *s) -{ - /* "/dev/" is 5 characters */ - if (s->length <= 5) - lsh_strncpy(dst, n, s); - { - unsigned length = MIN(n - 1, s->length - 5); - memcpy(dst, s->data + 5, length); - dst[length] = '\0'; - } -} - -#define CP(dst, src) lsh_strncpy(dst, sizeof(dst), src); -#define CP_TTY(dst, src) lsh_strncpy_tty(dst, sizeof(dst), src); - -static struct utmp * -lsh_make_utmp(struct lsh_user *user, - struct address_info *peer, - struct lsh_string *ttyname) -{ - struct utmp *log; - NEW_SPACE(log); - -#if HAVE_STRUCT_UTMP_UT_NAME - CP(log->ut_name, user->name); -#elif HAVE_STRUCT_UTMP_UT_USER - CP(log->ut_user, user->name); -#endif - - CP_TTY(log->ut_line, ttyname); - -#if HAVE_STRUCT_UTMP_UT_HOST - CP(log->ut_host, peer->ip); -#endif - - return log; -} -#undef CP -#undef CP_TTY - -#endif /* WITH_UTMP */ - - -/* GABA: - (class - (name process_resource) - (super lsh_process) - (vars - (pid . pid_t) - ; Signal used for killing the process. - (signal . int))) -*/ - -static void -do_kill_process(struct resource *r) -{ - CAST(process_resource, self, r); - - if (self->super.super.alive) - { - self->super.super.alive = 0; - /* NOTE: This function only makes one attempt at killing the - * process. An improvement would be to install a callout handler - * which will kill -9 the process after a delay, if it hasn't died - * voluntarily. */ - - if (kill(self->pid, self->signal) < 0) - { - werror("do_kill_process: kill failed (errno = %i): %z\n", - errno, STRERROR(errno)); - } - } -} - -static int -do_signal_process(struct lsh_process *s, int signal) -{ - CAST(process_resource, self, s); - - return self->super.super.alive - && (kill(self->pid, signal) == 0); -} - - -static struct lsh_process * -make_process_resource(pid_t pid, int signal) -{ - NEW(process_resource, self); - init_resource(&self->super.super, do_kill_process); - self->super.signal = do_signal_process; - - self->pid = pid; - self->signal = signal; - - return &self->super; -} - - -/* GABA: - (class - (name unix_user) - (super lsh_user) - (vars - (gid . gid_t) - - ; Context needed for some methods. - (ctx object unix_user_db) - - ; These strings include a terminating NUL-character, for - ; compatibility with library and system calls. This applies also - ; to the inherited name attribute. - - (passwd string) ; Crypted passwd - (home string) - (shell string))) */ - -/* GABA: - (class - (name pwhelper_callback) - (super exit_callback) - (vars - (user object unix_user) - (c object command_continuation) - (e object exception_handler))) -*/ - -static void -do_pwhelper_callback(struct exit_callback *s, - int signaled, int core UNUSED, int value) -{ - CAST(pwhelper_callback, self, s); - - if (signaled || value) - { - static const struct exception invalid_password - = STATIC_EXCEPTION(EXC_USERAUTH, "Invalid password according to helper program."); - EXCEPTION_RAISE(self->e, &invalid_password); - } - else - COMMAND_RETURN(self->c, self->user); -} - -static struct exit_callback * -make_pwhelper_callback(struct unix_user *user, - struct command_continuation *c, - struct exception_handler *e) -{ - NEW(pwhelper_callback, self); - self->super.exit = do_pwhelper_callback; - self->user = user; - self->c = c; - self->e = e; - - return &self->super; -} - -/* NOTE: Consumes the pw string if successful. */ -static int -kerberos_check_pw(struct unix_user *user, struct lsh_string *pw, - struct command_continuation *c, - struct exception_handler *e) -{ - /* Because kerberos is big and complex, we fork a separate process - * to do the work. */ - - int in[2]; - pid_t child; - - /* First look if the helper program seems to exist. */ - if (access(user->ctx->pw_helper, X_OK) < 0) - { - /* No help available */ - werror("Password helper program '%z' not available (errno = %d): %z\n", - user->ctx->pw_helper, errno, STRERROR(errno)); - return 0; - } - - if (!lsh_make_pipe(in)) - { - werror("kerberos_check_pw: Failed to create pipe.\n"); - return 0; - } - - child = fork(); - - switch (child) - { - case -1: - werror("kerberos_check_pw: fork failed: %z\n", STRERROR(errno)); - return 0; - - case 0: - { /* Child */ - int null_fd; - - null_fd = open("/dev/null", O_RDWR); - if (null_fd < 0) - { - werror("kerberos_check_pw: Failed to open /dev/null.\n"); - _exit(EXIT_FAILURE); - } - if (dup2(in[0], STDIN_FILENO) < 0) - { - werror("kerberos_check_pw: Can't dup stdin!\n"); - _exit(EXIT_FAILURE); - } - - if (dup2(null_fd, STDOUT_FILENO) < 0) - { - werror("kerberos_check_pw: Can't dup stdout!\n"); - _exit(EXIT_FAILURE); - } - - if (dup2(null_fd, STDERR_FILENO) < 0) - { - _exit(EXIT_FAILURE); - } - - close(in[1]); - close(null_fd); - - execl(user->ctx->pw_helper, user->ctx->pw_helper, user->super.name->data, NULL); - _exit(EXIT_FAILURE); - } - default: - { - /* Parent */ - struct lsh_fd *fd; - - close(in[0]); - - fd = io_write(make_lsh_fd(user->ctx->backend, - in[1], "password helper stdin", - e), - pw->length, NULL); - - A_WRITE(&fd->write_buffer->super, pw); - - REAP(user->ctx->reaper, child, make_pwhelper_callback(user, c, e)); - - return 1; - } - } -} - -/* FIXME: This could be generalized to support some kind of list of - * password databases. The current code first checks for unix - * passwords, and if that fails, it optionally invokes a helper - * program to verify the password, typically used for kerberos. */ -static void -do_verify_password(struct lsh_user *s, - struct lsh_string *password, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(unix_user, user, s); - const struct exception *x = NULL; - - /* No supported password verification methods allows passwords - * containing NUL, so check that here. */ - - if (!lsh_get_cstring(password)) - { - static const struct exception invalid_passwd - = STATIC_EXCEPTION(EXC_USERAUTH, "NUL character in password."); - - EXCEPTION_RAISE(e, &invalid_passwd); - return; - } - - /* NOTE: Check for accounts with empty passwords. */ - if (!user->passwd || (user->passwd->length < 2) ) - { - static const struct exception no_passwd - = STATIC_EXCEPTION(EXC_USERAUTH, "No password in passwd db."); - - x = &no_passwd; - - /* NOTE: We attempt using kerberos passwords even if the - * passwd entry is totally bogus. */ - goto try_helper; - } - - /* Try password authentication against the ordinary unix database. */ - { - char *salt = user->passwd->data; - - /* NOTE: crypt uses the *ugly* convention of returning pointers - * to static buffers. */ - - if (strcmp(crypt(password->data, salt), user->passwd->data)) - { - /* Passwd doesn't match */ - static const struct exception invalid_passwd - = STATIC_EXCEPTION(EXC_USERAUTH, "Incorrect password."); - - x = &invalid_passwd; - - goto try_helper; - } - /* Unix style password authentication succeded. */ - lsh_string_free(password); - COMMAND_RETURN(c, user); - return; - } - - try_helper: - - /* We get here if checks against the ordinary passwd database failed. */ - assert(x); - - if (user->ctx->pw_helper && kerberos_check_pw(user, password, c, e)) - /* The helper program takes responsibility for password - * verification, and it also consumed the password string so that - * we don't need to free it here. */ - ; - else - { - lsh_string_free(password); - EXCEPTION_RAISE(e, x); - } -} - -/* NOTE: No arbitrary file names are passed to this function, so we don't have - * to check for things like "../../some/secret/file" */ -static int -do_file_exists(struct lsh_user *u, - struct lsh_string *name, - int free) -{ - CAST(unix_user, user, u); - struct lsh_string *path; - struct stat st; - const char *s; - - if (!user->home) - { - if (free) - lsh_string_free(name); - return 0; - } - - path = ssh_format(free ? "%lS/%lfS" : "%lS/%lS", - user->home, name); - s = lsh_get_cstring(path); - - if (s && (stat(s, &st) == 0)) - { - lsh_string_free(path); - return 1; - } - lsh_string_free(path); - return 0; -} - -static const struct exception * -check_user_permissions(struct stat *sbuf, const char *fname, - uid_t uid, int secret) -{ - mode_t bad = secret ? (S_IRWXG | S_IRWXO) : (S_IWGRP | S_IWOTH); - - if (!S_ISREG(sbuf->st_mode)) - { - werror("io.c: %z is not a regular file.\n", - fname); - return make_io_exception(EXC_IO_OPEN_READ, NULL, 0, "Not a regular file"); - } - if (sbuf->st_uid != uid) - { - werror("io.c: %z not owned by the right user (%i)\n", - fname, uid); - return make_io_exception(EXC_IO_OPEN_READ, NULL, 0, "Bad owner"); - } - - if (sbuf->st_mode & bad) - { - werror("io.c: Permissions on %z too loose.\n", - fname); - return make_io_exception(EXC_IO_OPEN_READ, NULL, 0, "Bad permissions"); - } - - return NULL; -} - -/* NOTE: No arbitrary file names are passed to this method, so we - * don't have to check for things like "../../some/secret/file", - * or for filenames containing NUL. */ - -static void -do_read_file(struct lsh_user *u, - const char *name, int secret, - struct command_continuation *c, - struct exception_handler *e) -{ - CAST(unix_user, user, u); - struct lsh_string *f; - struct stat sbuf; - const struct exception *x; - - pid_t child; - /* out[0] for reading, out[1] for writing */ - int out[2]; - - uid_t me = getuid(); - - /* There's no point trying to read other user's files unless we're - * root. */ - - if (me && (me != user->super.uid) ) - { - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, 0, "Access denied.")); - return; - } - - if (!user->home) - { - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, - ENOENT, "No home directory")); - return; - } - - f = ssh_format("%lS/.lsh/%lz", user->home, name); - - if (stat(lsh_get_cstring(f), &sbuf) < 0) - { - if (errno != ENOENT) - werror("io_read_user_file: Failed to stat %S (errno = %i): %z\n", - f, errno, STRERROR(errno)); - - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, errno, NULL)); - - lsh_string_free(f); - return; - } - - /* Perform a preliminary permissions check before forking, as errors - * detected by the child process are not reported as accurately. */ - - x = check_user_permissions(&sbuf, lsh_get_cstring(f), user->super.uid, secret); - if (x) - { - EXCEPTION_RAISE(e, x); - lsh_string_free(f); - return; - } - - if (!lsh_make_pipe(out)) - { - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, errno, NULL)); - lsh_string_free(f); - return; - } - - child = fork(); - - switch (child) - { - case -1: - /* Error */ - EXCEPTION_RAISE(e, make_io_exception(EXC_IO_OPEN_READ, NULL, errno, NULL)); - - close(out[0]); close(out[1]); - lsh_string_free(f); - return; - - default: - /* Parent */ - close(out[1]); - - /* NOTE: We could install an exit handler for the child process, - * but there's nothing useful for that to do. */ - COMMAND_RETURN(c, make_lsh_fd(user->ctx->backend, - out[0], "stdout, reading a user file", e)); - - lsh_string_free(f); - return; - - case 0: - /* Child */ - { - int fd; - close(out[0]); - - if ( (me != user->super.uid) && (setuid(user->super.uid) < 0) ) - { - werror("unix_user.c: do_read_file: setuid failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - assert(user->super.uid == getuid()); - - fd = open(lsh_get_cstring(f), O_RDONLY); - - /* Check permissions again, in case the file or some symlinks - * changed under our feet. */ - - if (fstat(fd, &sbuf) < 0) - { - werror("unix_user.c: do_read_file: fstat failed (errno = %i): %z\n", - errno, STRERROR(errno)); - _exit(EXIT_FAILURE); - } - - x = check_user_permissions(&sbuf, lsh_get_cstring(f), user->super.uid, secret); - - if (x) - { - werror("unix_user.c: do_read_file: %z\n", x->msg); - _exit(EXIT_FAILURE); - } - - if (lsh_copy_file(fd, out[1])) - _exit(EXIT_SUCCESS); - else - _exit(EXIT_FAILURE); - } - } -} - -/* Change to user's home directory. */ - -static int -do_chdir_home(struct lsh_user *u) -{ - CAST(unix_user, user, u); - - if (!user->home) - { - if (chdir("/") < 0) - { - werror("Strange: home directory was NULL, and chdir(\"/\") failed: %z\n", - STRERROR(errno)); - return 0; - } - } - else if (chdir(lsh_get_cstring(user->home)) < 0) - { - werror("chdir to %S failed (using / instead): %z\n", - user->home, - STRERROR(errno)); - if (chdir("/") < 0) - { - werror("chdir(\"/\") failed: %z\n", STRERROR(errno)); - return 0; - } - } - return 1; -} - -/* FIXME: initgroups in glibc (and possibly on other systems as well) - * is broken, and can't handle more than 32 groups. We need a - * workaround for that. */ -static int -change_uid(struct unix_user *user) -{ - /* NOTE: Error handling is crucial here. If we do something - * wrong, the server will think that the user is logged in - * under his or her user id, while in fact the process is - * still running as root. */ - if (initgroups(lsh_get_cstring(user->super.name), user->gid) < 0) - { - werror("initgroups failed: %z\n", STRERROR(errno)); - return 0; - } - if (setgid(user->gid) < 0) - { - werror("setgid failed: %z\n", STRERROR(errno)); - return 0; - } - if (setuid(user->super.uid) < 0) - { - werror("setuid failed: %z\n", STRERROR(errno)); - return 0; - } - return 1; -} - -static int -do_fork_process(struct lsh_user *u, - struct lsh_process **process, - struct exit_callback *c, - struct address_info *peer, struct lsh_string *tty) -{ - CAST(unix_user, user, u); - pid_t child; - - struct utmp *log = NULL; - - /* Don't start any processes unless the user has a login shell. */ - if (!user->shell) - return 0; - -#if WITH_UTMP - if (tty) - log = lsh_make_utmp(u, peer, tty); -#endif - - child = fork(); - - switch(child) - { - case -1: - werror("fork failed: %z\n", STRERROR(errno)); - return 0; - - case 0: /* Child */ - /* FIXME: Create utmp entry as well. */ -#if defined(WITH_UTMP) && defined(HAVE_LOGWTMP) - if (log) - /* FIXME: It should be safe to perform a blocking reverse dns lookup here, - * as we have forked. */ -#if HAVE_STRUCT_UTMP_UT_NAME - logwtmp(log->ut_line, log->ut_name, log->ut_host); -#elif HAVE_STRUCT_UTMP_UT_USER - logwtmp(log->ut_line, log->ut_user, log->ut_host); -#endif - -#endif /* WITH_UTMP && HAVE_LOGWTMP */ - - if (getuid() != user->super.uid) - if (!change_uid(user)) - { - werror("Changing uid failed!\n"); - _exit(EXIT_FAILURE); - } - - *process = NULL; - return 1; - - default: /* Parent */ - *process = make_process_resource(child, SIGHUP); - REAP(user->ctx->reaper, child, make_logout_cleanup(&(*process)->super, log, c)); - - return 1; - } -} - -#define USE_LOGIN_DASH_CONVENTION 1 - -static const char * -format_env_pair(const char *name, struct lsh_string *value) -{ - assert(lsh_get_cstring(value)); - return lsh_get_cstring(ssh_format("%lz=%lS", name, value)); -} - -static const char * -format_env_pair_c(const char *name, const char *value) -{ - return lsh_get_cstring(ssh_format("%lz=%lz", name, value)); -} - -static void -do_exec_shell(struct lsh_user *u, int login, - const char **argv, - unsigned env_length, - const struct env_value *env) -{ - CAST(unix_user, user, u); - const char **envp; - char *tz = getenv("TZ"); - unsigned i, j; - - assert(user->shell); - - /* Make up an initial environment */ - debug("do_exec_shell: Setting up environment.\n"); - - /* We need place for the caller's values, - * - * SHELL, HOME, USER, LOGNAME, TZ, PATH - * - * and a terminating NULL */ - -#define MAX_ENV 6 - - envp = alloca(sizeof(char *) * (env_length + MAX_ENV + 1)); - - i = 0; - envp[i++] = format_env_pair("SHELL", user->shell); - - if (user->home) - envp[i++] = format_env_pair("HOME", user->home); - - /* FIXME: The value of $PATH should not be hard-coded */ - envp[i++] = "PATH=/bin:/usr/bin"; - envp[i++] = format_env_pair("USER", user->super.name); - envp[i++] = format_env_pair("LOGNAME", user->super.name); - - if (tz) - envp[i++] = format_env_pair_c("TZ", tz); - - assert(i <= MAX_ENV); -#undef MAX_ENV - - for (j = 0; jshell); - char *loginshell; - - debug("do_exec_shell: fixing up name of shell...\n"); - - loginshell = alloca(user->shell->length + 2); - - /* Make sure that the shell's name begins with a -. */ - p = strrchr (shell, '/'); - if (!p) - p = shell; - else - p ++; - - loginshell[0] = '-'; - strncpy (loginshell + 1, p, user->shell->length); - - argv[0] = loginshell; - } - else -#endif /* USE_LOGIN_DASH_CONVENTION */ - argv[0] = lsh_get_cstring(user->shell); - - debug("do_exec_shell: argv[0] = '%z'.\n", argv[0]); - - /* FIXME: Is there a better way? The execve prototype uses char * - * const argv, and similarly for envp. */ - execve(lsh_get_cstring(user->shell), (char **) argv, (char **) envp); -} - -static struct lsh_user * -make_unix_user(struct lsh_string *name, - uid_t uid, gid_t gid, - struct unix_user_db *ctx, - const char *passwd, - const char *home, - const char *shell) -{ - NEW(unix_user, user); - - assert(lsh_get_cstring(name)); - - user->super.name = name; - user->super.verify_password = do_verify_password; - user->super.file_exists = do_file_exists; - user->super.read_file = do_read_file; - user->super.chdir_home = do_chdir_home; - user->super.fork_process = do_fork_process; - user->super.exec_shell = do_exec_shell; - - user->super.uid = uid; - user->gid = gid; - - user->ctx = ctx; - - /* Treat empty strings as NULL. */ - -#define STRING(s) (((s) && *(s)) ? make_string((s)) : NULL) - user->passwd = STRING(passwd); - user->home = STRING(home); - user->shell = STRING(shell); -#undef STRING - - return &user->super; -} - -/* GABA: - (class - (name unix_user_db) - (super user_db) - (vars - (backend object io_backend) - (reaper object reap) - - ; A program to use for verifying passwords. - (pw_helper . "const char *") - - ; Override the login shell for all users. - (login_shell . "const char *") - - (allow_root . int))) -*/ - - -/* NOTE: Calls functions using the disgusting convention of returning - * pointers to static buffers. */ - -/* This method filters out accounts that are known to be disabled - * (i.e. root, or shadow style expiration). However, it may still - * return some disabled accounts. - * - * An account that is disabled in /etc/passwd should have a value for - * the login shell that prevents login; replacing the passwd field - * only doesn't prevent login using publickey authentication. */ -static struct lsh_user * -do_lookup_user(struct user_db *s, - struct lsh_string *name, int free) -{ - CAST(unix_user_db, self, s); - - struct passwd *passwd; - const char *home; - const char *shell; - const char *cname = lsh_get_cstring(name); - - if (!cname) - { - if (free) - lsh_string_free(name); - return NULL; - } - - if ((passwd = getpwnam(cname)) - /* Check for root login */ - && (passwd->pw_uid || self->allow_root)) - { - char *crypted; - -#if HAVE_GETSPNAM - /* FIXME: What's the most portable way to test for shadow passwords? - * A single character in the passwd field should cover most variants. */ - if (passwd->pw_passwd && (strlen(passwd->pw_passwd) == 1)) - { - struct spwd *shadowpwd; - - /* Current day number since January 1, 1970. - * - * FIXME: Which timezone is used in the /etc/shadow file? */ - long now = time(NULL) / (3600 * 24); - - if (!(shadowpwd = getspnam(cname))) - goto fail; - - /* sp_expire == -1 means there is no account expiration date. - * although chage(1) claims that sp_expire == 0 does this */ - if ( (shadowpwd->sp_expire >= 0) - && (now > shadowpwd->sp_expire)) - { - werror("Access denied for user '%pS', account expired.\n", name); - goto fail; - } - - /* sp_inact == -1 means expired password doesn't disable account. - * - * During the time - * - * sp_lstchg + sp_max < now < sp_lstchg + sp_max + sp_inact - * - * the user is allowed to log in only by changing her - * password. As lsh doesn't support password change, this - * means that access is denied. */ - - if ( (shadowpwd->sp_inact >= 0) && - (now > (shadowpwd->sp_lstchg + shadowpwd->sp_max))) - { - werror("Access denied for user '%pS', password too old.\n", name); - goto fail; - } - - /* FIXME: We could look at sp_warn and figure out if it is - * appropriate to send a warning about passwords about to - * expire, and possibly also a - * SSH_MSG_USERAUTH_PASSWD_CHANGEREQ message. - * - * A warning is appropriate when - * - * sp_lstchg + sp_max - sp_warn < now < sp_lstchg + sp_max - * - */ - - crypted = shadowpwd->sp_pwdp; - } - else -#endif /* HAVE_GETSPNAM */ - crypted = passwd->pw_passwd; - - /* NOTE: If we are running as the uid of the user, it seems - * like a good idea to let the HOME environment variable - * override the passwd-database. */ - - if (! (passwd->pw_uid - && (passwd->pw_uid == getuid()) - && (home = getenv("HOME")))) - home = passwd->pw_dir; - - if (self->login_shell) - /* Override the passwd database */ - shell = self->login_shell; - else - shell = passwd->pw_shell; - - return make_unix_user(free ? name : lsh_string_dup(name), - passwd->pw_uid, passwd->pw_gid, - self, - crypted, - home, shell); - } - else - { - fail: - if (free) - lsh_string_free(name); - return NULL; - } -} - -struct user_db * -make_unix_user_db(struct io_backend *backend, struct reap *reaper, - const char *pw_helper, const char *login_shell, - int allow_root) -{ - NEW(unix_user_db, self); - - self->super.lookup = do_lookup_user; - self->backend = backend; - self->reaper = reaper; - self->pw_helper = pw_helper; - self->login_shell = login_shell; - self->allow_root = allow_root; - - return &self->super; -} diff --git a/lsh/src/unix_user.c.x b/lsh/src/unix_user.c.x deleted file mode 100755 index 9a776e0..0000000 Binary files a/lsh/src/unix_user.c.x and /dev/null differ diff --git a/lsh/src/unpad.c b/lsh/src/unpad.c deleted file mode 100755 index b66a8ec..0000000 --- a/lsh/src/unpad.c +++ /dev/null @@ -1,109 +0,0 @@ -/* unpad.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "unpad.h" - -#include "format.h" -#include "ssh.h" -#include "xalloc.h" - -#include "unpad.c.x" - -/* GABA: - (class - (name packet_unpad) - (super abstract_write_pipe) - (vars - ; Needed only for its exception_handler - (connection object ssh_connection))) -*/ - -static void -do_unpad(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(packet_unpad, closure, w); - - UINT8 padding_length; - UINT32 payload_length; - struct lsh_string *new; - - if (packet->length < 1) - { - lsh_string_free(packet); - - PROTOCOL_ERROR(closure->connection->e, - "Empty packet received."); - return; - } - - padding_length = packet->data[0]; - - if ( (padding_length < 4) - || (padding_length >= packet->length) ) - { - lsh_string_free(packet); - PROTOCOL_ERROR(closure->connection->e, - "Bogus padding length."); - return; - } - - payload_length = packet->length - 1 - padding_length; - - /* FIXME: This check seems redundant; fuzzy length check is done in - * read_packet.c, and a stricter check is done in connection.c. Some - * additional checking, using the SSH_MAX_PACKET constant, is also - * done in zlib.c */ - - if (payload_length > (closure->connection->rec_max_packet - + SSH_MAX_PACKET_FUZZ)) - { - lsh_string_free(packet); - PROTOCOL_ERROR(closure->connection->e, - "Max payload length exceeded."); - return; - } - new = ssh_format("%ls", payload_length, packet->data + 1); - - /* Keep sequence number */ - new->sequence_number = packet->sequence_number; - - lsh_string_free(packet); - - A_WRITE(closure->super.next, new); -} - -struct abstract_write * -make_packet_unpad(struct ssh_connection *connection, - struct abstract_write *next) -{ - NEW(packet_unpad, closure); - - closure->super.super.write = do_unpad; - closure->super.next = next; - closure->connection = connection; - - return &closure->super.super; -} diff --git a/lsh/src/unpad.c.x b/lsh/src/unpad.c.x deleted file mode 100755 index 15b2e1d..0000000 Binary files a/lsh/src/unpad.c.x and /dev/null differ diff --git a/lsh/src/unpad.h b/lsh/src/unpad.h deleted file mode 100755 index 2f0b57d..0000000 --- a/lsh/src/unpad.h +++ /dev/null @@ -1,36 +0,0 @@ -/* unpad.h - * - * Processor for unpadding packets. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_UNPAD_H_INCLUDED -#define LSH_UNPAD_H_INCLUDED - -#include "abstract_io.h" -#include "connection.h" - -struct abstract_write * -make_packet_unpad(struct ssh_connection *connection, - struct abstract_write *next); - -#endif /* LSH_UNPAD_H_INCLUDED */ diff --git a/lsh/src/userauth.c b/lsh/src/userauth.c deleted file mode 100755 index eb675d5..0000000 --- a/lsh/src/userauth.c +++ /dev/null @@ -1,44 +0,0 @@ -/* userauth.h - * - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "userauth.h" - -#include "format.h" -#include "ssh.h" -#include "xalloc.h" - -#define GABA_DEFINE -#include "userauth.h.x" -#undef GABA_DEFINE - -struct exception * -make_userauth_special_exception(struct lsh_string *reply, const char *msg) -{ - NEW(userauth_special_exception, self); - self->super.type = EXC_USERAUTH_SPECIAL; - self->super.msg = msg ? msg : "userauth special reply"; - self->reply = reply; - - return &self->super; -} - diff --git a/lsh/src/userauth.h b/lsh/src/userauth.h deleted file mode 100755 index fbab969..0000000 --- a/lsh/src/userauth.h +++ /dev/null @@ -1,133 +0,0 @@ -/* userauth.h - * - * $Id$ - */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_USERAUTH_H_INCLUDED -#define LSH_USERAUTH_H_INCLUDED - -#include "command.h" -#include "exception.h" -#include "resource.h" - -/* For uid_t */ -#include - -/* Forward declaration */ -struct env_value; - -#define GABA_DECLARE -#include "userauth.h.x" -#undef GABA_DECLARE - -/* GABA: - (class - (name userauth_special_exception) - (super exception) - (vars - (reply string))) -*/ - -/* FIXME: Perhaps it's better to use a const char * for the value? */ -struct env_value -{ - const char *name; - struct lsh_string *value; -}; - -struct exception * -make_userauth_special_exception(struct lsh_string *reply, - const char *msg); - -/* GABA: - (class - (name lsh_process) - (super resource) - (vars - (signal method int int))) -*/ - -#define SIGNAL_PROCESS(p, s) ((p)->signal((p), (s))) - -/* GABA: - (class - (name lsh_user) - (vars - ; This string include a terminating NUL-character, for - ; compatibility with library and system calls. - (name string) - (uid . uid_t) - - ; Verify a password. Consumes the password string. - (verify_password method void - "struct lsh_string *pw" - "struct command_continuation *c" - "struct exception_handler *e") - - ; Check if a file in the user's home directory exists. - ; Used by the current publickey userauth method. - (file_exists method int "struct lsh_string *name" "int free") - - ; Open a file in the user's "~/.lsh" directory. File must be - ; owned by the user and not writable for other users. If SECRET is 1, - ; it must also not be readable by other users. - (read_file method void - "const char *name" "int secret" - "struct command_continuation *c" "struct exception_handler *e") - - ; chdir to the user's home directory - (chdir_home method int) - - ; Fork a user process. - - ; FIXME: For non-UN*X-systems, we need a method - ; that combines fork() and exec(). It would have lots of - ; input arguments, perhaps a tag list, and return - ; an object containing the stdin file objects and perhaps some - ; other info. - - ; This function also returns the pid. - - ; The tty argument is for utmp/wtmp logging - (fork_process method int "struct lsh_process **child" - "struct exit_callback *c" - "struct address_info * peer" "struct lsh_string *tty") - - ; This modifies the argv vector, in particular its first - ; element. So the vector must have at least two elements, - ; (argv[0], NULL). - - (exec_shell method void "int login" - "const char **argv" - "unsigned env_length" - "const struct env_value *env"))) -*/ - -#define USER_VERIFY_PASSWORD(u, p, c, e) ((u)->verify_password((u), (p), (c), (e))) -#define USER_FILE_EXISTS(u, n, f) ((u)->file_exists((u), (n), (f))) -#define USER_READ_FILE(u, n, s, x, e) ((u)->read_file((u), (n), (s), (x), (e))) -#define USER_CHDIR_HOME(u) ((u)->chdir_home((u))) -#define USER_FORK(u, c, e, p, t) \ - ((u)->fork_process((u), (c), (e), (p), (t))) -#define USER_EXEC(u, m, a, l, e) ((u)->exec_shell((u), (m), (a), (l), (e))) - -#endif /* LSH_USERAUTH_H_INCLUDED */ diff --git a/lsh/src/userauth.h.x b/lsh/src/userauth.h.x deleted file mode 100755 index 39f929d..0000000 Binary files a/lsh/src/userauth.h.x and /dev/null differ diff --git a/lsh/src/version.h b/lsh/src/version.h deleted file mode 100755 index ce1cd9c..0000000 --- a/lsh/src/version.h +++ /dev/null @@ -1,42 +0,0 @@ -/* version.h - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_VERSION_H_INCLUDED -#define LSH_VERSION_H_INCLUDED - -#include "lsh_types.h" - -#define CLIENT_PROTOCOL_VERSION "2.0" -#define SERVER_PROTOCOL_VERSION "2.0" - -#if WITH_SSH1_FALLBACK -#define SSH1_SERVER_PROTOCOL_VERSION "1.99" -#endif - -#define SOFTWARE_CLIENT_VERSION ("lsh_" VERSION) -#define SOFTWARE_SERVER_VERSION ("lshd_" VERSION) - -/* Use "psst@net.lut.ac.uk" ? */ -#define BUG_ADDRESS "" - -#endif /* LSH_VERSION_H_INCLUDED */ diff --git a/lsh/src/werror.c b/lsh/src/werror.c deleted file mode 100755 index cd73cb0..0000000 --- a/lsh/src/werror.c +++ /dev/null @@ -1,685 +0,0 @@ -/* werror.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#if macintosh -#include "lshprefix.h" -#include "lsh_context.h" -#endif - -#include "werror.h" - -#include "charset.h" - -/* For format_size_in_decimal */ -#include "format.h" - -#include "gc.h" -#include "io.h" -#include "parse.h" -#include "xalloc.h" - -#include -#include -#include - -#if HAVE_UNISTD_H -#include -#endif - -#include -#include -#include - -#if HAVE_SYSLOG_H -#include -#endif - -#ifdef MACOS -extern void abort(); -#if !HAVE_SYSLOG_H -extern void openlog( const char *id, int flags, int type ); -extern void syslog( int priority, const char *format, ... ); -#define LOG_NOTICE 1 -#define LOG_PID 1 -#define LOG_CONS 2 -#define LOG_DAEMON 1 -#endif -#endif - -/* Global flags */ -#ifndef MACOS -int trace_flag = 0; -int debug_flag = 0; -int quiet_flag = 0; -int verbose_flag = 0; -#else -#include "lsh_context.h" -#endif -static const char *program_name = NULL; - -#define WERROR_TRACE -1 -#define WERROR_DEBUG -2 -#define WERROR_LOG -3 - -static const struct argp_option -werror_options[] = -{ - { "quiet", 'q', NULL, 0, "Suppress all warnings and diagnostic messages", 0 }, - { "verbose", 'v', NULL, 0, "Verbose diagnostic messages", 0}, - { "trace", WERROR_TRACE, NULL, 0, "Detailed trace", 0 }, - { "debug", WERROR_DEBUG, NULL, 0, "Print huge amounts of debug information", 0 }, - { "log-file", WERROR_LOG, "File name", 0, - "Append messages to this file.", 0}, - { NULL, 0, NULL, 0, NULL, 0 } -}; - -static error_t -werror_argp_parser(int key, char *arg, - struct argp_state *state) -{ - switch(key) - { - default: - return ARGP_ERR_UNKNOWN; - case ARGP_KEY_END: - case ARGP_KEY_INIT: - program_name = state->name; - break; - case 'q': - quiet_flag = 1; - break; - case 'v': - verbose_flag = 1; - break; - case WERROR_TRACE: - trace_flag = 1; - break; - case WERROR_DEBUG: - debug_flag = 1; - break; - case WERROR_LOG: - { - /* FIXME: For clients, this is right: We only get lsh-related - * messages to the log file, and child processes are not - * affected. But for the server, perhaps we should also dup - * the logfile over stderr? */ - - int fd = open(arg, O_WRONLY | O_CREAT | O_APPEND, 0666); - if (fd < 0) - argp_error(state, "Failed to open log file `%s'.", arg); - else - set_error_stream(fd); - } - } - return 0; -} - -const struct argp werror_argp = -{ - werror_options, - werror_argp_parser, - NULL, NULL, NULL, NULL, NULL -}; - -#ifndef MACOS -static int error_fd = STDERR_FILENO; - -#define BUF_SIZE 500 -static UINT8 error_buffer[BUF_SIZE]; -static UINT32 error_pos = 0; - -static const struct exception * -(*error_write)(int fd, UINT32 length, const UINT8 *data) = write_raw; -#else -#define BUF_SIZE ERROR_BUF_SIZE -#endif - -#if HAVE_SYSLOG -static const struct exception * -write_syslog(int fd UNUSED, UINT32 length, const UINT8 *data) -{ - struct lsh_string *s; - - /* Data must not contain any NUL:s */ - assert(!memchr(data, '\0', length)); - - /* NUL-terminate the string. */ - s = ssh_format("%ls", length, data); - - /* FIXME: Should we use different log levels for werror, verbose and - * debug? */ - - syslog(LOG_NOTICE, "%s", lsh_get_cstring(s)); - lsh_string_free(s); - - return NULL; -} - -/* FIXME: Delete argument and use program_name. */ -void -set_error_syslog(const char *id) -{ - openlog(id, LOG_PID | LOG_CONS, LOG_DAEMON); - error_write = write_syslog; - error_fd = -1; -} -#endif /* HAVE_SYSLOG */ - -static const struct exception * -write_ignore(int fd UNUSED, - UINT32 length UNUSED, const UINT8 *data UNUSED) -{ return NULL; } - -void -set_error_stream(int fd) -{ - error_fd = fd; - - error_write = write_raw; -} - -void -set_error_nonblocking(int fd) -{ - if (error_fd == fd) - error_write = write_raw_with_poll; -} - -int -dup_error_stream(void) -{ - if (error_fd < 0) - /* We're not writing error messages on any file; there's no - * problem. */ - return 1; - else - { - int fd = dup(error_fd); - - /* This function is used to get stderr away from the stdio fd - * range. In the unlikely event that dup returns an fd <= - * STDERR_FILENO, we treat that as an error. */ - if (fd > STDERR_FILENO) - { - io_set_close_on_exec(fd); - error_fd = fd; - return 1; - } - - if (fd >= 0) - close(fd); - - return 0; - } -} - -void -set_error_ignore(void) -{ - error_write = write_ignore; - error_fd = -1; -} - -#define WERROR(l, d) (error_write(error_fd, (l), (d))) - -static void -werror_flush(void) -{ - if (error_pos) - { - WERROR(error_pos, error_buffer); - error_pos = 0; - } -} - -static void -werror_putc(UINT8 c) -{ - if (error_pos == BUF_SIZE) - werror_flush(); - - error_buffer[error_pos++] = c; -} - -static void -werror_write(UINT32 length, const UINT8 *msg) -{ - if (error_pos + length <= BUF_SIZE) - { - memcpy(error_buffer + error_pos, msg, length); - error_pos += length; - } - else - { - werror_flush(); - WERROR(length, msg); - } -} - -static void -werror_cstring(char *s) { werror_write(strlen(s), s); } - -static void -werror_bignum(mpz_t n, int base) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - char *s = alloca(mpz_sizeinbase(n, base) + 2); - mpz_get_str(s, 16, n); - - werror_cstring(s); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static void -werror_decimal(UINT32 n) -{ -#if ALLOCA_68K_BUG - ALLOCA_START(alloca_ref); -#endif - unsigned length = format_size_in_decimal(n); - UINT8 *buffer = alloca(length); - - format_decimal(length, buffer, n); - - werror_write(length, buffer); -#if ALLOCA_68K_BUG - ALLOCA_FREE(alloca_ref); -#endif -} - -static unsigned format_size_in_hex(UINT32 n); - -static void -werror_hex_digit(unsigned digit) -{ - werror_putc("0123456789abcdef"[digit]); -} - -static void -werror_hex_putc(UINT8 c) -{ - werror_hex_digit(c / 16); - werror_hex_digit(c % 16); -} - -static void -werror_hex(UINT32 n) -{ - unsigned left = 8; - - while ( (left > 1) - && !(n & 0xf0000000UL)) - { - left --; - n <<= 4; - } - - while (left--) - { - werror_hex_digit((n >> 28) & 0xf); - n <<= 4; - } -} - -static void -werror_hexdump(UINT32 length, UINT8 *data) -{ - UINT32 i = 0; - - werror("(size %i = 0x%xi)\n", length, length); - - for (i = 0; i 16) - r = 16; - - for (j = 0; j 126) ) - c = '.'; - werror_putc(c); - } - - werror_cstring("\n"); - } -} - -static void -werror_paranoia_putc(UINT8 c) -{ - switch (c) - { - case '\\': - werror_cstring("\\\\"); - break; - case '\r': - /* Ignore */ - break; - default: - if (!isprint(c)) - { - werror_putc('\\'); - werror_hex_putc(c); - break; - } - /* Fall through */ - case '\n': - werror_putc(c); - break; - } -} - -void -werror_vformat(const char *f, va_list args) -{ - if (program_name) - { - werror_write(strlen(program_name), program_name); - werror_write(2, ": "); - } - - while (*f) - { - if (*f == '%') - { - int do_hex = 0; - int do_free = 0; - int do_paranoia = 0; - int do_utf8 = 0; - - while (*++f) - switch (*f) - { - case 'x': - do_hex = 1; - break; - case 'f': - do_free = 1; - break; - case 'p': - do_paranoia = 1; - break; - case 'u': - do_utf8 = 1; - break; - default: - goto end_options; - } - end_options: - switch(*f++) - { - case '%': - werror_putc(*f); - break; - case 'i': - (do_hex ? werror_hex : werror_decimal)(va_arg(args, UINT32)); - break; - case 'c': - (do_paranoia ? werror_paranoia_putc : werror_putc)(va_arg(args, int)); - break; - case 'n': - werror_bignum(va_arg(args, MP_INT *), do_hex ? 16 : 10); - break; - case 'a': - { - int atom = va_arg(args, int); - - assert(atom); - - werror_write(get_atom_length(atom), get_atom_name(atom)); - - break; - } - case 's': - { - UINT32 length = va_arg(args, UINT32); - UINT8 *s = va_arg(args, UINT8 *); - - struct lsh_string *u = NULL; - - if (do_utf8 && !local_is_utf8()) - { - u = low_utf8_to_local(length, s, 0); - if (!u) - { - werror_cstring(""); - break; - } - length = u->length; - s = u->data; - } - if (do_hex) - { - assert(!do_paranoia); - werror_hexdump(length, s); - } - else if (do_paranoia) - { - UINT32 i; - for (i=0; i"); - break; - } - do_free = 1; - } - if (do_hex) - { - assert(!do_paranoia); - werror_hexdump(s->length, s->data); - } - else if (do_paranoia) - { - UINT32 i; - for (i=0; ilength; i++) - werror_paranoia_putc(s->data[i]); - } - else - werror_write(s->length, s->data); - - if (do_free) - lsh_string_free(s); - - break; - } - case 't': - { - struct lsh_object *o = va_arg(args, struct lsh_object *); - const char *type; - - if (!o) - type = ""; - else if (o->isa) - type = o->isa->name; - else - type = ""; - - werror_write(strlen(type), type); - - break; - } - case 'z': - { - char *s = va_arg(args, char *); - - if (do_hex) - werror_hexdump(strlen(s), s); - - else if (do_paranoia) - while (*s) - werror_paranoia_putc(*s++); - else - werror_write(strlen(s), s); - - break; - } - default: - fatal("werror_vformat: bad format string!\n"); - break; - } - } - else - werror_putc(*f++); - } -} - -void -werror(const char *format, ...) -{ - va_list args; - - /* It is somewhat reasonable to use both -q and -v. In this case - * werror()-messages should be displayed. */ - if (verbose_flag || !quiet_flag) - { - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - } -} - -void -trace(const char *format, ...) -{ - va_list args; - - if (trace_flag) - { - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - } -} - -void -debug(const char *format, ...) -{ - va_list args; - - if (debug_flag) - { - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - } -} - -void -verbose(const char *format, ...) -{ - va_list args; - - if (verbose_flag) - { - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - } -} - -void -fatal(const char *format, ...) -{ - va_list args; - - va_start(args, format); - werror_vformat(format, args); - va_end(args); - werror_flush(); - -#if WITH_GCOV - exit(255); -#else - abort(); -#endif -} - -static unsigned -format_size_in_hex(UINT32 n) -{ - int i; - int e; - - /* Table of 16^(2^n) */ - static const UINT32 powers[] = { 0x10UL, 0x100UL, 0x10000UL }; - -#define SIZE (sizeof(powers) / sizeof(powers[0])) - - /* Determine the smallest e such that n < 16^e */ - for (i = SIZE - 1 , e = 0; i >= 0; i--) - { - if (n >= powers[i]) - { - e += 1UL << i; - n /= powers[i]; - } - } - -#undef SIZE - - return e+1; -} - diff --git a/lsh/src/werror.h b/lsh/src/werror.h deleted file mode 100755 index 5ad6007..0000000 --- a/lsh/src/werror.h +++ /dev/null @@ -1,86 +0,0 @@ -/* werror.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_ERROR_H_INCLUDED -#define LSH_ERROR_H_INCLUDED - -#include "bignum.h" -#include "lsh_argp.h" - -#include - -/* Global variables */ -#ifndef MACOS -extern int trace_flag; -extern int debug_flag; -extern int quiet_flag; -extern int verbose_flag; -#endif -extern const struct argp werror_argp; - -void set_error_stream(int fd); -void set_error_nonblocking(int fd); -void set_error_ignore(void); - -/* Tries to dup any error fd to something higher than STDERR_FILENO. - * Used to be able to print any error messages while forking a child - * process. */ -int dup_error_stream(void); - -#ifdef HAVE_SYSLOG -void set_error_syslog(const char *id); -#endif - -/* Format specifiers: - * - * %% %-character - * %i UINT32 - * %c int, interpreted as a single character to output - * %n mpz_t - * %z NUL-terminated string - * %a Insert a string containing one atom. - * %s UINT32 length, UINT8 *data - * %S lsh_string *s - * %t The type of an struct lsh_object * - * - * Modifiers: - * - * x hexadecimal output - * f Consume (and free) the input string - * p Filter out dangerous control characters - * u Input is in utf-8; convert to local charset - */ - - -void werror_vformat(const char *f, va_list args); - -void werror(const char *format, ...); -void trace(const char *format, ...); -void debug(const char *format, ...); -void verbose(const char *format, ...); - -void fatal(const char *format, ...) NORETURN; - -#endif /* LSH_ERROR_H_INCLUDED */ diff --git a/lsh/src/write_buffer.c b/lsh/src/write_buffer.c deleted file mode 100755 index 7258dba..0000000 --- a/lsh/src/write_buffer.c +++ /dev/null @@ -1,193 +0,0 @@ -/* write_buffer.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "write_buffer.h" - -#include "xalloc.h" -#include "werror.h" - -#include -#include - -#define GABA_DEFINE -#include "write_buffer.h.x" -#undef GABA_DEFINE - - -static void -do_write(struct abstract_write *w, - struct lsh_string *packet) -{ - CAST(write_buffer, closure, w); - - debug("write_buffer: do_write length = %i\n", - packet->length); - if (!packet->length) - { - lsh_string_free(packet); - return; - } - - if (closure->closed) - { - werror("write_buffer: Attempt to write data to closed buffer.\n"); - lsh_string_free(packet); - return; - } - - /* Enqueue packet */ - - string_queue_add_tail(&closure->q, packet); - -#if 0 - if (closure->try_write) - { - /* Attempt writing to the corresponding fd. */ - } -#endif - - closure->empty = 0; - closure->length += packet->length; - - debug("write_buffer: do_write closure->length = %i\n", - closure->length); -} - -/* Copy data as necessary, before writing. - * - * FIXME: Writing of large packets could probably be optimized by - * avoiding copying it into the buffer. - * - * Returns 1 if the buffer is non-empty. */ -int write_buffer_pre_write(struct write_buffer *buffer) -{ - UINT32 length = buffer->end - buffer->start; - - if (buffer->empty) - return 0; - - if (buffer->start > buffer->block_size) - { - /* Copy contents to the start of the buffer */ - memcpy(buffer->buffer, buffer->buffer + buffer->start, length); - buffer->start = 0; - buffer->end = length; - } - - while (length < buffer->block_size) - { - /* Copy more data into buffer */ - if (buffer->partial) - { - UINT32 partial_left = buffer->partial->length - buffer->pos; - UINT32 buffer_left = 2*buffer->block_size - buffer->end; - if (partial_left <= buffer_left) - { - /* The rest of the partial packet fits in the buffer */ - memcpy(buffer->buffer + buffer->end, - buffer->partial->data + buffer->pos, - partial_left); - - buffer->end += partial_left; - length += partial_left; - - lsh_string_free(buffer->partial); - buffer->partial = NULL; - } - else - { - memcpy(buffer->buffer + buffer->end, - buffer->partial->data + buffer->pos, - buffer_left); - - buffer->end += buffer_left; - length += buffer_left; - buffer->pos += buffer_left; - - assert(length >= buffer->block_size); - } - } - else - { - /* Dequeue a packet, if possible */ - if (!string_queue_is_empty(&buffer->q)) - { - buffer->partial = string_queue_remove_head(&buffer->q); - buffer->pos = 0; - } - else - break; - } - } - buffer->empty = !length; - return !buffer->empty; -} - -void write_buffer_consume(struct write_buffer *buffer, UINT32 size) -{ - buffer->start += size; - assert(buffer->start <= buffer->end); - buffer->length -= size; - - if (buffer->report) - FLOW_CONTROL_REPORT(buffer->report, size); -} - -void write_buffer_close(struct write_buffer *buffer) -{ - buffer->closed = 1; -} - -struct write_buffer * -make_write_buffer(UINT32 size) -{ - NEW(write_buffer, res); - - res->super.write = do_write; - - res->block_size = size; - - res->buffer = lsh_space_alloc(2 * size); - - res->empty = 1; - res->length = 0; - - res->closed = 0; - -#if 0 - res->try_write = try; -#endif - - string_queue_init(&res->q); - - res->pos = 0; - res->partial = NULL; - - res->start = res->end = 0; - - return res; -} - - diff --git a/lsh/src/write_buffer.h b/lsh/src/write_buffer.h deleted file mode 100755 index c269ab3..0000000 --- a/lsh/src/write_buffer.h +++ /dev/null @@ -1,81 +0,0 @@ -/* write_buffer.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_WRITE_BUFFER_H_INCLUDED -#define LSH_WRITE_BUFFER_H_INCLUDED - -#include "abstract_io.h" -#include "queue.h" - -#define GABA_DECLARE -#include "write_buffer.h.x" -#undef GABA_DECLARE - -/* For flow control, we use this callback to report that data - * has been flushed from a write_buffer. */ -/* GABA: - (class - (name flow_controlled) - (vars - (report method void UINT32))) -*/ - -#define FLOW_CONTROL_REPORT(o, written) ((o)->report((o), written)) - -/* GABA: - (class - (name write_buffer) - (super abstract_write) - (vars - (block_size . UINT32) - (buffer space UINT8) ; Size is twice the blocksize - (empty . int) - - ; Total amount of data currently in the buffer - (length . UINT32) - - (report object flow_controlled) - - ; If non-zero, don't accept any more data. The i/o-channel - ; should be closed once the current buffers are flushed. - (closed . int) - - ;; (try_write . int) - - (q struct string_queue) - - (pos . UINT32) ; Partial packet - (partial string) - - (start . UINT32) - (end . UINT32))) -*/ - -struct write_buffer *make_write_buffer(UINT32 size); -int write_buffer_pre_write(struct write_buffer *buffer); -void write_buffer_consume(struct write_buffer *buffer, UINT32 size); -void write_buffer_close(struct write_buffer *buffer); - -#endif /* LSH_WRITE_BUFFER_H_INCLUDED */ diff --git a/lsh/src/write_buffer.h.x b/lsh/src/write_buffer.h.x deleted file mode 100755 index b026aac..0000000 Binary files a/lsh/src/write_buffer.h.x and /dev/null differ diff --git a/lsh/src/xalloc.c b/lsh/src/xalloc.c deleted file mode 100755 index d076383..0000000 --- a/lsh/src/xalloc.c +++ /dev/null @@ -1,388 +0,0 @@ -/* xalloc.c - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#include "xalloc.h" - -#include "list.h" -#include "werror.h" - -#include -#include -#include - -#if DEBUG_ALLOC - -#define lsh_free debug_free -#define lsh_malloc debug_malloc - -/* There are two sets of allocation functions: Low level allocation * - * that can allocate memory for any purpose, and object allocators - * that assume that the allocated object begins with a type field. */ - -/* UNIT should be a type of a size that is a multiple of the alignment - * requirement of the machine. */ - -/* NOTE: The code breaks horribly if UNIT is of the wrong size. But it - * doesn't matter much if we guess wrong on some platforms, as this - * affects only optionalal debug code. */ - -#define UNIT unsigned long - -#define SIZE_IN_UNITS(x) (((x) + sizeof(UNIT)-1) / sizeof(UNIT)) - -static void *debug_malloc(size_t real_size) -{ - static int count = 4711; - UNIT *res; - UNIT size = SIZE_IN_UNITS(real_size); - - res = malloc((size + 3)*sizeof(UNIT)); - - if (!res) - return NULL; - - res += 2; - - res[-2] = count; - res[-1] = real_size; - res[size] = ~count; - count++; - - return (void *) res; -} - -static void -debug_free(const void *m) -{ - if (m) - { - UNIT *p = (UNIT *) m; - UNIT real_size = p[-1]; - UNIT size = SIZE_IN_UNITS(real_size); - - if (~p[-2] != p[size]) - fatal("Memory corrupted!\n"); - - p[-2] = p[size] = 0; - - free(p-2); - } -} - -#else /* !DEBUG_ALLOC */ - -/* ANSI-C free doesn't allow const pointers to be freed. (That is one - * of the few things that C++ gets right). */ -#define lsh_free(p) free((void *) (p)) -#define lsh_malloc malloc - -#endif /* !DEBUG_ALLOC */ - -static void *xalloc(size_t size) -{ - void *res = lsh_malloc(size); - if (!res) - fatal("Virtual memory exhausted"); - - /* FIXME: The gc can't handle uninitialized pointers. The simple way - * is to zero-fill all memory as it is allocated. But initialization - * is only necessary for objects, strings need no initialization. By - * moving initializing to some higher level, we could avoid - * unnecessary clearing, and also initialize mpz objects - * automatically. */ - memset(res, 0, size); - - return res; -} - -#if DEBUG_ALLOC -#undef lsh_string_alloc -static -#endif - -struct lsh_string * -lsh_string_alloc(UINT32 length) -{ - /* NOTE: The definition of the struct contains a char array of - * length 1, so the below includes space for a terminating NUL. */ - - struct lsh_string *s - = xalloc(sizeof(struct lsh_string) + length); - - s->length = length; - s->data[length] = '\0'; - s->sequence_number = 0; - - return s; -} - -#if DEBUG_ALLOC - -unsigned number_of_strings = 0; -struct lsh_string *all_strings = NULL; - -static void sanity_check_string_list(void) -{ - unsigned i = 0; - struct lsh_string *s; - - if (!all_strings) - { - assert(!number_of_strings); - return; - } - assert(!all_strings->header.prev); - - for(i = 0, s = all_strings; s; s = s->header.next, i++) - { - if (s->header.next) - { - assert(s->header.next->header.prev = s); - } - } - assert (i == number_of_strings); -} - -struct lsh_string * -lsh_string_alloc_clue(UINT32 length, const char *clue) -{ - struct lsh_string *s = lsh_string_alloc(length); - - sanity_check_string_list(); - - s->header.magic = -1717; - number_of_strings++; - - s->header.clue = clue; - s->header.next = all_strings; - s->header.prev = NULL; - if (s->header.next) - s->header.next->header.prev = s; - all_strings = s; - - sanity_check_string_list(); - - return s; -} -#endif - -void -lsh_string_free(const struct lsh_string *s) -{ - if (!s) - return; - -#if DEBUG_ALLOC - sanity_check_string_list(); - - assert(number_of_strings); - number_of_strings--; - - if (s->header.magic != -1717) - fatal("lsh_string_free: Not string!\n"); - if (s->data[s->length]) - fatal("lsh_string_free: String not NUL-terminated.\n"); - - if (s->header.next) - s->header.next->header.prev = s->header.prev; - - if (s->header.prev) - s->header.prev->header.next = s->header.next; - else - { - assert (all_strings == s); - all_strings = s->header.next; - } - - sanity_check_string_list(); -#endif - -#if 0 - debug("lsh_string_free: freeing %xi,\n", (UINT32) s); -#endif - - lsh_free(s); -} - -struct lsh_object * -lsh_object_alloc(struct lsh_class *class) -{ - struct lsh_object *instance = xalloc(class->size); - instance->isa = class; - instance->alloc_method = LSH_ALLOC_HEAP; - - gc_register(instance); - - return instance; -} - -struct lsh_object * -lsh_object_clone(struct lsh_object *o) -{ - struct lsh_object *i = xalloc(o->isa->size); - - /* Copy header and all instance variables. Note that the header is - * now invalid, as the next pointer can't be copied directly. This - * is fixed by the gc_register call below. */ - memcpy(i, o, o->isa->size); - - i->alloc_method = LSH_ALLOC_HEAP; - gc_register(i); - - return i; -} - -struct list_header * -lsh_list_alloc(struct lsh_class *class, - unsigned length, size_t element_size) -{ - struct list_header *list = xalloc(class->size - + element_size * length - - element_size); - - assert(element_size < 1024); - /* assert(length < 65536); */ - - list->super.isa = class; - list->super.alloc_method = LSH_ALLOC_HEAP; - - list->length = length; - - gc_register(&list->super); - - return list; -} - -/* Should be called *only* by the gc */ -void -lsh_object_free(struct lsh_object *o) -{ - if (!o) - return; - - if (o->alloc_method != LSH_ALLOC_HEAP) - fatal("lsh_object_free: Object not allocated on the heap!\n"); - -#if 0 - if (o->isa->free_instance) - o->isa->free_instance(o); -#endif - - lsh_free(o); -} - -#if DEBUG_ALLOC -struct lsh_object *lsh_object_check(struct lsh_class *class, - struct lsh_object *instance) -{ - if (!instance) - return instance; - - if (instance->marked) - fatal("lsh_object_check: Unexpected marked object!\n"); - - if (instance->dead) - fatal("lsh_object_check: Reference to dead object!\n"); - - if ( (instance->alloc_method == LSH_ALLOC_HEAP) - && (instance->isa != class)) - fatal("lsh_object_check: Type error!\n"); - - return instance; -} - -struct lsh_object *lsh_object_check_subtype(struct lsh_class *class, - struct lsh_object *instance) -{ - struct lsh_class *type; - - if (!instance) - return instance; - - if (instance->marked) - fatal("lsh_object_check: Unexpected marked object!\n"); - - if (instance->dead) - fatal("lsh_object_check: Reference to dead object!\n"); - - /* Only heap allocated objects have a valid isa-pointer */ - switch (instance->alloc_method) - { - case LSH_ALLOC_STATIC: - case LSH_ALLOC_STACK: - return instance; - case LSH_ALLOC_HEAP: - break; - default: - fatal("lsh_object_check_subtype: Memory corrupted!\n"); - } - - for (type = instance->isa; type; type=type->super_class) - if (type == class) - return instance; - - fatal("lsh_object_check_subtype: Type error!\n"); -} -#endif /* DEBUG_ALLOC */ - -#if DEBUG_ALLOC -void *lsh_space_alloc(size_t size) -{ - UNIT *p = xalloc(size + sizeof(UNIT)); - - *p = -1919; - - return (void *) (p + 1); -} - -void lsh_space_free(const void *p) -{ - UNIT *m; - - if (!p) - return; - - m = (UNIT *) p; - - if (m[-1] != (UNIT) -1919) - fatal("lsh_free_space: Type error!\n"); - - lsh_free(m-1); -} - -#else /* !DEBUG_ALLOC */ - -/* FIXME: Why not use macros for this? */ -void *lsh_space_alloc(size_t size) -{ - return lsh_malloc(size); -} - -void lsh_space_free(const void *p) -{ - lsh_free(p); -} - -#endif /* !DEBUG_ALLOC */ diff --git a/lsh/src/xalloc.h b/lsh/src/xalloc.h deleted file mode 100755 index 1cb1729..0000000 --- a/lsh/src/xalloc.h +++ /dev/null @@ -1,120 +0,0 @@ -/* xalloc.h - * - * - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_XALLOC_H_INCLUDED -#define LSH_XALLOC_H_INCLUDED - -#include "gc.h" - -#include - -/* Allocation */ - -/* The memory allocation model (for strings) is as follows: - * - * Packets are allocated when they are needed. A packet may be passed - * through a chain of processing functions, until it is finally - * discarded or transmitted, at which time it is deallocated. - * Processing functions may deallocate their input packets and - * allocate fresh packets to pass on; therefore, any data from a - * packet that is needed later must be copied into some other storage. - * - * At any time, each packet is own by a a particular processing - * function. Pointers into a packet are valid only while you own it. - * */ - -#if DEBUG_ALLOC -extern struct lsh_string *all_strings; - -struct lsh_string *lsh_string_alloc_clue(UINT32 size, const char *clue); - -#define lsh_string_alloc(size) \ - (lsh_string_alloc_clue((size), (__FILE__ ":" STRING_LINE ": " FUNCTION_NAME))) - -#else /* !DEBUG_ALLOC */ -struct lsh_string *lsh_string_alloc(UINT32 size); -#endif /* !DEBUG_ALLOC */ - -void -lsh_string_free(const struct lsh_string *packet); - -struct lsh_object *lsh_object_alloc(struct lsh_class *class); - -/* FIXME: Should take a const struct lsh_object. */ -void lsh_object_free(struct lsh_object *o); - -/* NOTE: This won't work for if there are strings or other instance - * variables that can't be shared. */ -struct lsh_object *lsh_object_clone(struct lsh_object *o); - -void *lsh_space_alloc(size_t size); -void lsh_space_free(const void *p); - -#if DEBUG_ALLOC - -struct lsh_object *lsh_object_check(struct lsh_class *class, - struct lsh_object *instance); -struct lsh_object *lsh_object_check_subtype(struct lsh_class *class, - struct lsh_object *instance); - -#define CHECK_TYPE(c, i) \ - lsh_object_check(&CLASS(c), (struct lsh_object *) (i)) -#define CHECK_SUBTYPE(c, i) \ - lsh_object_check_subtype(&CLASS(c), (struct lsh_object *) (i)) - -#define CAST(class, var, o) \ - struct class *(var) = (struct class *) CHECK_TYPE(class, o) - -#define CAST_SUBTYPE(class, var, o) \ - struct class *(var) = (struct class *) CHECK_SUBTYPE(class, o) - -extern unsigned number_of_strings; - -#else /* !DEBUG_ALLOC */ - -#define CHECK_TYPE(c, o) ((struct lsh_object *)(o)) -#define CHECK_SUBTYPE(c, o) ((struct lsh_object *)(o)) - -#define CAST(class, var, o) \ - struct class *(var) = (struct class *) (o) - -#define CAST_SUBTYPE(class, var, o) CAST(class, var, o) - - -#endif /* !DEBUG_ALLOC */ - -#define NEW(class, var) \ - struct class *(var) = (struct class *) lsh_object_alloc(&CLASS(class)) -#define NEW_SPACE(x) ((x) = lsh_space_alloc(sizeof(*(x)))) - -#define CLONE(class, i) \ - ((struct class *) lsh_object_clone(CHECK_TYPE(class, (i)))) - -#define CLONED(class, var, i) \ - struct class *(var) = CLONE(class, i) - -#define KILL(x) gc_kill((struct lsh_object *) (x)) - -#endif /* LSH_XALLOC_H_INCLUDED */ diff --git a/lsh/src/xauth.c b/lsh/src/xauth.c deleted file mode 100644 index 4ae48b6..0000000 --- a/lsh/src/xauth.c +++ /dev/null @@ -1,384 +0,0 @@ -/* xauth.c - * - * Xauth parsing. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 - */ - -#include "xauth.h" - -#include "format.h" -#include "werror.h" - -#if HAVE_X11_XAUTH_H -#include -#endif - -#include -#include - -#if HAVE_LIBXAU - -static int xauth_process(const char *filename, - unsigned family, - unsigned address_length, const char *address, - unsigned number_length, const char *number, - struct lsh_string **name, - struct lsh_string **data) -{ - FILE *f = fopen(filename, "rb"); - Xauth *xa; - - if (!f) - return 0; - - while ( (xa = XauReadAuth(f)) ) - { - debug("xauth: family: %i\n", xa->family); - debug(" address: %ps\n", xa->address_length, xa->address); - debug(" display: %s\n", xa->number_length, xa->number); - debug(" name: %s\n", xa->name_length, xa->name); - debug(" data length: %i\n", xa->data_length); - - if ( (xa->family == family) - && (xa->address_length == address_length) - && (xa->number_length == number_length) - && !memcmp(xa->address, address, address_length) - && !memcmp(xa->number, number, number_length) ) - { - *name = ssh_format("%ls", xa->name_length, xa->name); - *data = ssh_format("%ls", xa->data_length, xa->data); - - XauDisposeAuth(xa); - fclose(f); - - return 1; - } - } - XauDisposeAuth(xa); - fclose(f); - - return 0; -} - -int -xauth_lookup(struct sockaddr *sa, - unsigned number_length, - const char *number, - struct lsh_string **name, - struct lsh_string **data) -{ - int res = 0; - unsigned family; - - const char *address; - unsigned address_length; - - /* FIXME: Use xgethostbyname */ -#define HOST_MAX 200 - char host[HOST_MAX]; - - const char *filename = XauFileName(); - - if (!filename) - return 0; - - switch(sa->sa_family) - { - case AF_UNIX: - if (gethostname(host, sizeof(host) - 1) < 0) - return 0; - address = host; - address_length = strlen(host); - family = FamilyLocal; - break; - - case AF_INET: - { - struct sockaddr_in *s = (struct sockaddr_in *) sa; - - address = (char *) &s->sin_addr; - address_length = 4; - family = 0; - break; - } - -#if WITH_IPV6 - case AF_INET6: - { - struct sockaddr_in6 *s = (struct sockaddr_in6 *) sa; - - address = (char *) s->sin6_addr; - address_length = 16; - family = 0; - break; - } -#endif - default: - return 0; - } - - /* 5 retries, 1 second each */ - if (XauLockAuth(filename, 5, 1, 0) != LOCK_SUCCESS) - return 0; - - res = xauth_process(filename, - family, - address_length, address, - number_length, number, - name, data); - - XauUnlockAuth(filename); - - return res; -} -#else /* !HAVE_LIBXAU */ - -int -xauth_lookup(struct sockaddr *address UNUSED, - unsigned display_length UNUSED, - const char *display UNUSED, - struct lsh_string **name UNUSED, - struct lsh_string **auth UNUSED) -{ - return 0; -} -#endif /* !HAVE_LIBXAU */ - -#if 0 -#include "channel.h" - -#include "format.h" -#include "werror.h" -#include "xalloc.h" - -#include "xauth.c.x" - -#include -#include - -#include -#include - -/* FIXME: Should move somewhere else. */ -static struct lsh_string * -read_file(int fd, UINT32 limit) -{ - struct lsh_string *s = lsh_string_alloc(limit); - UINT32 i = 0; - - while ( i < s->length) - { - int res = read(fd, s->data + i, s->length - i); - if (res < 0) - { - lsh_string_free(s); - return NULL; - } - else if (!res) - break; - else i += res; - } - - s->length = i; - return s; -} - -/* Are the XAUTH file format and locking conventions documented anywhere? - * - * This file tryes to follow common practice. For locking the file - * ".Xauthority", create a file ".Xauthority-c" (using exclusive - * mode), and a hardlink ".Xauthority-l" to the same file. - * - * Fileformat: .Xauthority is a sequence of entries of the following format: - * - * uint16_t family - * uint16_t address_length - * uint8_t[address_length] address - * uint16_t display_length - * uint8_t[display_length] display (a number, formatted as ascii digits) - * uint16_t name_length - * uint8_t[name_length] name (e.g "MIT-MAGIC-COOKIE-1") - * uint16_t data_length - * uint8_t[data_length] data - * - * All lengths in network byte order. - * - * Valid values for family are - * - * 0 (address is an ip address) - * 252 FamilyLocalHost - * 253 FamilyKrb5Principal - * 254 FamilyNetname - * 256 FamilyLocal (e.g. host/unix) - * 65535 FamilyWild - */ - -/* xauth-style file locking */ -/* ;;GABA: - (class - (name xauth_lock) - (super resource) - (vars - (c_name string) - (l_name string))) -*/ - -static void -do_xauth_lock_kill(struct resource *s) -{ - CAST(xauth_lock, self, s); - if (self->super.alive) - { - self->super.alive = 0; - unlink (lsh_get_cstring(self->c_name)); - unlink (lsh_get_cstring(self->l_name)); - } -} - -static struct resource * -xauth_lock(const char *name) -{ - NEW(xauth_lock, self); - int f; - - init_resource(&self->super, do_xauth_lock_kill); - - self->c_name = ssh_format("%lz-c", name); - self->l_name = ssh_format("%lz-l", name); - - f = open(lsh_get_cstring(self->c_name), - O_CREAT | O_EXCL | O_WRONLY, 0666); - - if (f >= 0) - { - close(f); - if (link(lsh_get_cstring(self->c_name), - lsh_get_cstring(self->l_name)) == 0) - /* Success! */ - return &self->super; - } - - werror("locking xauth file `%S' failed.\n", name); - - self->super.alive = 0; - KILL(self); - return NULL; -} - -/* GABA: - (class - (name x11_forward) - (super channel_open) - (vars - ; NULL for local transport - (host string) - (display . UINT16) - - (auth_name string) - (auth_data string))) -*/ - - -#define XAUTH_MAX_SIZE 10000 - -int -xauth_lookup(struct sockaddr *address, - struct lsh_string **name, - struct lsh_string **auth) -{ - struct lsh_string *s = NULL; - struct resource *lock; - int fd; - - const char *fname = getenv("XAUTHORITY"); - if (!fname) - { - const char *home = getenv("HOME"); - if (!home) - return 0; - - s = ssh_format("%lz/.Xauthority", home); - fname = lsh_get_cstring(s); - } - assert(fname); - - lock = xauth_lock(fname); - if (!lock) - return 0; - - fd = open(fname, O_RDONLY); - - if (fd >= 0) - { - s = read_file(fd, XAUTH_MAX_SIZE); - close(fd); - } - - if (s) - { - struct simple_buffer buffer; - simple_buffer_init(&buffer, s->length, s->data); - - while (!parse_eod(&buffer)) - { - UINT32 family; - UINT32 address_length; - const UINT8 *address; - UINT32 display_length; - const UINT8 *display; - UINT32 name_length; - const UINT8 *name; - UINT32 data_length; - const UINT8 *data; - - if (parse_uint16(&buffer, &family) - && parse_string16(&buffer, &address_length, &address) - && parse_string16(&buffer, &display_length, &display) - && parse_string16(&buffer, &name_length, &name) - && parse_string16(&buffer, &data_length, &data)) - { - werror("xauth: family: %i\n", family); - werror(" address: %ps\n", address_length, address); - werror(" display: %s\n", display_length, display); - werror(" name: %s\n", name_length, name); - werror(" data length: %i\n", data_length); - -#if 0 - switch (family) - { - default: - continue; - case 0: - if (!self->host) - - - } -#endif - } - else break; - } - } - - KILL_RESOURCE(lock); - return 1; -} -#endif diff --git a/lsh/src/xauth.h b/lsh/src/xauth.h deleted file mode 100644 index 224acd9..0000000 --- a/lsh/src/xauth.h +++ /dev/null @@ -1,41 +0,0 @@ -/* xauth.h - * - * Xauth parsing. - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 2001 Niels Möller - * - * 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 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 should 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 - */ - -#ifndef LSH_XAUTH_H_INCLUDED -#define LSH_XAUTH_H_INCLUDED - -#include "lsh.h" - -#include -#include - -int -xauth_lookup(struct sockaddr *sa, - unsigned number_length, - const char *number, - struct lsh_string **name, - struct lsh_string **data); - -#endif /* LSH_XAUTH_H_INCLUDED */ diff --git a/lsh/src/zlib.c b/lsh/src/zlib.c deleted file mode 100755 index f4b9489..0000000 --- a/lsh/src/zlib.c +++ /dev/null @@ -1,356 +0,0 @@ -/* zlib.c - * - * zlib compression algorithm - * - * $Id$ */ - -/* lsh, an implementation of the ssh protocol - * - * Copyright (C) 1998 Balázs Scheidler, Niels Möller - * - * 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 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 should 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 - */ - -#include "compress.h" -#include "format.h" -#include "ssh.h" -#include "string_buffer.h" -#include "werror.h" -#include "xalloc.h" - -#if WITH_ZLIB - -#if HAVE_ZLIB_H -#include -#else -#warning zlib.h not present -#endif - -#include - -static void do_free_zstream(z_stream *z); - - -//#define verbose2 verbose -//#define werror2 werror -#define verbose2 debug -#define werror2 debug - -#include "zlib.c.x" - -/* GABA: - (class - (name zlib_instance) - (super compress_instance) - (vars - ; Fail before producing larger packets than this - (max . UINT32) - (rate . UINT32) - (f pointer (function int "z_stream *" int)) - (z indirect-special z_stream - #f do_free_zstream))) -*/ - -/* GABA: - (class - (name zlib_algorithm) - (super compress_algorithm) - (vars - (level . int))) -*/ - -/* Stored in the opaque pointer. */ -struct zlib_type -{ - int (*free_func)(z_stream *z); - const char *operation; -}; - -#define ZLIB_TYPE(z) ((struct zlib_type *)((z)->opaque)) - -static const struct zlib_type -zlib_inflate = { inflateEnd, "inflate" }; - -static const struct zlib_type -zlib_deflate = { deflateEnd, "deflate" }; - -/* zlib memory functions */ -void * -zlib_alloc(void *opaque UNUSED, unsigned int items, unsigned int size) -{ - return lsh_space_alloc(items * size); -} - -void -zlib_free(void *opaque UNUSED, void *address) -{ - lsh_space_free(address); -} - -static void -do_free_zstream(z_stream *z) -{ - /* We use the opaque pointer, as there's nothing else to help us - * figure if we should be calling inflateEnd or deflateEnd. */ - - const struct zlib_type *type = ZLIB_TYPE(z); - - int res = type->free_func(z); - - if (res != Z_OK) - debug("do_free_zstream (%z): Freeing failed: %z\n", - type->operation, z->msg ? z->msg : "No error"); -} - -/* Estimates of the resulting packet sizes. We use fixnum arithmetic, - * with one represented as 1<<10=1024. Only rates between 1/16 and 16 - * are used. This may be a little too conservative; I have observed - * compression ratios of about 50. */ - -#define RATE_UNIT 1024 -#define RATE_MAX (RATE_UNIT * 16) -#define RATE_MIN (RATE_UNIT / 16) -#define MARGIN 200 -#define INSIGNIFICANT 100 - -static UINT32 estimate_size(UINT32 rate, UINT32 input, UINT32 max) -{ - UINT32 guess = rate * input / RATE_UNIT + MARGIN; - return MIN(max, guess); -} - -/* Assumes that input is nonzero */ -static UINT32 estimate_update(UINT32 rate, UINT32 input, UINT32 output) -{ - /* Decay old estimate */ - rate = rate * 15 / 16; - - /* FIXME: Following the envelope is suboptimal for small inputs. We - * do it only for input packets of reasonable size. This method - * could be improved. - * - * Perhaps a linear combination k * rate + (1-k) estimate, where k - * depends on the size of the sample (i.e. input) would make sense? - * Or use different rate estimates for different lengths? */ - - if (input > INSIGNIFICANT) - { - UINT32 estimate = output * RATE_UNIT / input; - - if (estimate > RATE_MAX) - return RATE_MAX; - - /* Follow the "envelope" */ - rate = MAX(estimate, rate); - } - - return MAX(rate, RATE_MIN); -} - -/* Compress incoming data */ -static struct lsh_string * -do_zlib(struct compress_instance *c, - struct lsh_string *packet, - int free) -{ - CAST(zlib_instance, self, c); - struct string_buffer buffer; - - /* LIMIT keeps track of the amount of storage we may still need to - * allocate. To detect that a packet grows unexpectedly large, we - * need a little extra buffer space beyond the maximum size. */ - UINT32 limit = self->max + 1; - - UINT32 estimate; - - debug("do_zlib (%z): length in: %i\n", - ZLIB_TYPE(&self->z)->operation, packet->length); - - if (!packet->length) - { - werror("do_zlib (%z): Compressing empty packet.\n", - ZLIB_TYPE(&self->z)->operation); - return free ? packet : lsh_string_dup(packet); - } - - estimate = estimate_size(self->rate, packet->length, limit); - debug("do_zlib (%z): estimate: %i\n", - ZLIB_TYPE(&self->z)->operation, - estimate); - - string_buffer_init(&buffer, estimate); - - limit -= buffer.partial->length; - - self->z.next_in = packet->data; - self->z.avail_in = packet->length; - - for (;;) - { - int rc; - - self->z.next_out = buffer.current; - self->z.avail_out = buffer.left; - - assert(self->z.avail_out); - - rc = self->f(&self->z, Z_SYNC_FLUSH); - - switch (rc) - { - case Z_BUF_ERROR: - /* If avail_in is zero, this just means that all data have - * been flushed. */ - if (self->z.avail_in) - werror2("do_zlib (%z): Z_BUF_ERROR (probably harmless),\n" - " avail_in = %i, avail_out = %i\n", - ZLIB_TYPE(&self->z)->operation, - self->z.avail_in, self->z.avail_out); - /* Fall through */ - case Z_OK: - break; - default: - werror("do_zlib: %z failed: %z\n", - ZLIB_TYPE(&self->z)->operation, - self->z.msg ? self->z.msg : "No error(?)"); - if (free) - lsh_string_free(packet); - - return NULL; - } - - /* NOTE: It's not enough to check that avail_in is zero to - * determine that all data have been flushed. avail_in == 0 and - * avail_out > 0 implies that all data has been flushed, but if - * avail_in == avail_out == 0, we have to allocate more output - * space. */ - - if (!self->z.avail_in && !self->z.avail_out) - verbose2("do_zlib (%z): Both avail_in and avail_out are zero.\n", - ZLIB_TYPE(&self->z)->operation); - - if (!self->z.avail_out) - { /* All output space consumed */ - if (!limit) - { - werror("do_zlib (%z): Packet grew too large!\n", - ZLIB_TYPE(&self->z)->operation); - - if (free) - lsh_string_free(packet); - - string_buffer_clear(&buffer); - return NULL; - } - - /* Grow to about double size. */ - string_buffer_grow(&buffer, MIN(limit, buffer.partial->length + buffer.total + 100)); - limit -= buffer.partial->length; - } - else if (!self->z.avail_in) - { /* Compressed entire packet */ - UINT32 input = packet->length; - - if (free) - lsh_string_free(packet); - - packet = - string_buffer_final(&buffer, self->z.avail_out); - - assert(packet->length <= self->max); - - debug("do_zlib (%z): length out: %i\n", - ZLIB_TYPE(&self->z)->operation, - packet->length); - - if (packet->length > estimate) - verbose2("do_zlib (%z): Estimated size exceeded: input = %i, estimate = %i, output = %i\n", - ZLIB_TYPE(&self->z)->operation, - input, estimate, packet->length); - - self->rate = estimate_update(self->rate, input, packet->length); - - return packet; - } - } -} - -static struct compress_instance * -make_zlib_instance(struct compress_algorithm *c, int mode) -{ - CAST(zlib_algorithm, closure, c); - NEW(zlib_instance, res); - - res->z.zalloc = zlib_alloc; - res->z.zfree = zlib_free; - - switch (mode) - { - case COMPRESS_DEFLATE: - res->z.opaque = (void *) &zlib_deflate; - res->f = deflate; - res->super.codec = do_zlib; - - /* Maximum expansion is 0.1% + 12 bytes. We use 1% + 12, to be conservative. - * - * FIXME: These figures are documented for the entire stream, - * does they really apply to all segments, separated by - * Z_SYNC_FLUSH ? */ - - res->max = SSH_MAX_PACKET + SSH_MAX_PACKET / 100 + 12; - res->rate = RATE_UNIT; - - deflateInit(&res->z, closure->level); - break; - - case COMPRESS_INFLATE: - res->z.opaque = (void *) &zlib_inflate; - res->f = inflate; - res->super.codec = do_zlib; - - /* FIXME: Perhaps we ought to use the connection's - * rec_max_packet size? */ - res->max = SSH_MAX_PACKET; - res->rate = 2 * RATE_UNIT; - - inflateInit(&res->z); - break; - } - return &res->super; -} - -struct compress_algorithm *make_zlib_algorithm(int level) -{ - if ( (level != Z_DEFAULT_COMPRESSION) - && ( (level < Z_NO_COMPRESSION) - || (level > Z_BEST_COMPRESSION) )) - return NULL; - else - { - NEW(zlib_algorithm, closure); - - closure->super.make_compress = make_zlib_instance; - closure->level = level; - - return &closure->super; - } -} - -struct compress_algorithm *make_zlib(void) -{ - return make_zlib_algorithm(Z_DEFAULT_COMPRESSION); -} - -#endif /* WITH_ZLIB */ diff --git a/lsh/src/zlib.c.x b/lsh/src/zlib.c.x deleted file mode 100755 index 9262806..0000000 Binary files a/lsh/src/zlib.c.x and /dev/null differ diff --git a/lsh/stamp-h.in b/lsh/stamp-h.in deleted file mode 100755 index ebc4b62..0000000 Binary files a/lsh/stamp-h.in and /dev/null differ diff --git a/zlib/ChangeLog b/zlib/ChangeLog deleted file mode 100755 index bf2e3f9..0000000 --- a/zlib/ChangeLog +++ /dev/null @@ -1,481 +0,0 @@ - - ChangeLog file for zlib - -Changes in 1.1.4 (11 March 2002) -- ZFREE was repeated on same allocation on some error conditions. - This creates a security problem described in - http://www.zlib.org/advisory-2002-03-11.txt -- Returned incorrect error (Z_MEM_ERROR) on some invalid data -- Avoid accesses before window for invalid distances with inflate window - less than 32K. -- force windowBits > 8 to avoid a bug in the encoder for a window size - of 256 bytes. (A complete fix will be available in 1.1.5). - -Changes in 1.1.3 (9 July 1998) -- fix "an inflate input buffer bug that shows up on rare but persistent - occasions" (Mark) -- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) -- fix gzseek(..., SEEK_SET) in write mode -- fix crc check after a gzeek (Frank Faubert) -- fix miniunzip when the last entry in a zip file is itself a zip file - (J Lillge) -- add contrib/asm586 and contrib/asm686 (Brian Raiter) - See http://www.muppetlabs.com/~breadbox/software/assembly.html -- add support for Delphi 3 in contrib/delphi (Bob Dellaca) -- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) -- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) -- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) -- added a FAQ file - -- Support gzdopen on Mac with Metrowerks (Jason Linhart) -- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) -- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) -- avoid some warnings with Borland C (Tom Tanner) -- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) -- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) -- allow several arguments to configure (Tim Mooney, Frodo Looijaard) -- use libdir and includedir in Makefile.in (Tim Mooney) -- support shared libraries on OSF1 V4 (Tim Mooney) -- remove so_locations in "make clean" (Tim Mooney) -- fix maketree.c compilation error (Glenn, Mark) -- Python interface to zlib now in Python 1.5 (Jeremy Hylton) -- new Makefile.riscos (Rich Walker) -- initialize static descriptors in trees.c for embedded targets (Nick Smith) -- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) -- add the OS/2 files in Makefile.in too (Andrew Zabolotny) -- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) -- fix maketree.c to allow clean compilation of inffixed.h (Mark) -- fix parameter check in deflateCopy (Gunther Nikl) -- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) -- Many portability patches by Christian Spieler: - . zutil.c, zutil.h: added "const" for zmem* - . Make_vms.com: fixed some typos - . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists - . msdos/Makefile.msc: remove "default rtl link library" info from obj files - . msdos/Makefile.*: use model-dependent name for the built zlib library - . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: - new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) -- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) -- replace __far with _far for better portability (Christian Spieler, Tom Lane) -- fix test for errno.h in configure (Tim Newsham) - -Changes in 1.1.2 (19 March 98) -- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) - See http://www.winimage.com/zLibDll/unzip.html -- preinitialize the inflate tables for fixed codes, to make the code - completely thread safe (Mark) -- some simplifications and slight speed-up to the inflate code (Mark) -- fix gzeof on non-compressed files (Allan Schrum) -- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) -- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) -- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) -- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) -- do not wrap extern "C" around system includes (Tom Lane) -- mention zlib binding for TCL in README (Andreas Kupries) -- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) -- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) -- allow "configure --prefix $HOME" (Tim Mooney) -- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) -- move Makefile.sas to amiga/Makefile.sas - -Changes in 1.1.1 (27 Feb 98) -- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) -- remove block truncation heuristic which had very marginal effect for zlib - (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the - compression ratio on some files. This also allows inlining _tr_tally for - matches in deflate_slow. -- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) - -Changes in 1.1.0 (24 Feb 98) -- do not return STREAM_END prematurely in inflate (John Bowler) -- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) -- compile with -DFASTEST to get compression code optimized for speed only -- in minigzip, try mmap'ing the input file first (Miguel Albrecht) -- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain - on Sun but significant on HP) - -- add a pointer to experimental unzip library in README (Gilles Vollant) -- initialize variable gcc in configure (Chris Herborth) - -Changes in 1.0.9 (17 Feb 1998) -- added gzputs and gzgets functions -- do not clear eof flag in gzseek (Mark Diekhans) -- fix gzseek for files in transparent mode (Mark Diekhans) -- do not assume that vsprintf returns the number of bytes written (Jens Krinke) -- replace EXPORT with ZEXPORT to avoid conflict with other programs -- added compress2 in zconf.h, zlib.def, zlib.dnt -- new asm code from Gilles Vollant in contrib/asm386 -- simplify the inflate code (Mark): - . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() - . ZALLOC the length list in inflate_trees_fixed() instead of using stack - . ZALLOC the value area for huft_build() instead of using stack - . Simplify Z_FINISH check in inflate() - -- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 -- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) -- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with - the declaration of FAR (Gilles VOllant) -- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) -- read_buf buf parameter of type Bytef* instead of charf* -- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) -- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) -- fix check for presence of directories in "make install" (Ian Willis) - -Changes in 1.0.8 (27 Jan 1998) -- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) -- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) -- added compress2() to allow setting the compression level -- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) -- use constant arrays for the static trees in trees.c instead of computing - them at run time (thanks to Ken Raeburn for this suggestion). To create - trees.h, compile with GEN_TREES_H and run "make test". -- check return code of example in "make test" and display result -- pass minigzip command line options to file_compress -- simplifying code of inflateSync to avoid gcc 2.8 bug - -- support CC="gcc -Wall" in configure -s (QingLong) -- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) -- fix test for shared library support to avoid compiler warnings -- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) -- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) -- do not use fdopen for Metrowerks on Mac (Brad Pettit)) -- add checks for gzputc and gzputc in example.c -- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) -- use const for the CRC table (Ken Raeburn) -- fixed "make uninstall" for shared libraries -- use Tracev instead of Trace in infblock.c -- in example.c use correct compressed length for test_sync -- suppress +vnocompatwarnings in configure for HPUX (not always supported) - -Changes in 1.0.7 (20 Jan 1998) -- fix gzseek which was broken in write mode -- return error for gzseek to negative absolute position -- fix configure for Linux (Chun-Chung Chen) -- increase stack space for MSC (Tim Wegner) -- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) -- define EXPORTVA for gzprintf (Gilles Vollant) -- added man page zlib.3 (Rick Rodgers) -- for contrib/untgz, fix makedir() and improve Makefile - -- check gzseek in write mode in example.c -- allocate extra buffer for seeks only if gzseek is actually called -- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) -- add inflateSyncPoint in zconf.h -- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def - -Changes in 1.0.6 (19 Jan 1998) -- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and - gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) -- Fix a deflate bug occuring only with compression level 0 (thanks to - Andy Buckler for finding this one). -- In minigzip, pass transparently also the first byte for .Z files. -- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() -- check Z_FINISH in inflate (thanks to Marc Schluper) -- Implement deflateCopy (thanks to Adam Costello) -- make static libraries by default in configure, add --shared option. -- move MSDOS or Windows specific files to directory msdos -- suppress the notion of partial flush to simplify the interface - (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) -- suppress history buffer provided by application to simplify the interface - (this feature was not implemented anyway in 1.0.4) -- next_in and avail_in must be initialized before calling inflateInit or - inflateInit2 -- add EXPORT in all exported functions (for Windows DLL) -- added Makefile.nt (thanks to Stephen Williams) -- added the unsupported "contrib" directory: - contrib/asm386/ by Gilles Vollant - 386 asm code replacing longest_match(). - contrib/iostream/ by Kevin Ruland - A C++ I/O streams interface to the zlib gz* functions - contrib/iostream2/ by Tyge Løvset - Another C++ I/O streams interface - contrib/untgz/ by "Pedro A. Aranda Guti\irrez" - A very simple tar.gz file extractor using zlib - contrib/visual-basic.txt by Carlos Rios - How to use compress(), uncompress() and the gz* functions from VB. -- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression - level) in minigzip (thanks to Tom Lane) - -- use const for rommable constants in deflate -- added test for gzseek and gztell in example.c -- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) -- add undocumented function zError to convert error code to string - (for Tim Smithers) -- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. -- Use default memcpy for Symantec MSDOS compiler. -- Add EXPORT keyword for check_func (needed for Windows DLL) -- add current directory to LD_LIBRARY_PATH for "make test" -- create also a link for libz.so.1 -- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) -- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) -- added -soname for Linux in configure (Chun-Chung Chen, -- assign numbers to the exported functions in zlib.def (for Windows DLL) -- add advice in zlib.h for best usage of deflateSetDictionary -- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) -- allow compilation with ANSI keywords only enabled for TurboC in large model -- avoid "versionString"[0] (Borland bug) -- add NEED_DUMMY_RETURN for Borland -- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). -- allow compilation with CC -- defined STDC for OS/2 (David Charlap) -- limit external names to 8 chars for MVS (Thomas Lund) -- in minigzip.c, use static buffers only for 16-bit systems -- fix suffix check for "minigzip -d foo.gz" -- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) -- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) -- added makelcc.bat for lcc-win32 (Tom St Denis) -- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) -- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. -- check for unistd.h in configure (for off_t) -- remove useless check parameter in inflate_blocks_free -- avoid useless assignment of s->check to itself in inflate_blocks_new -- do not flush twice in gzclose (thanks to Ken Raeburn) -- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h -- use NO_ERRNO_H instead of enumeration of operating systems with errno.h -- work around buggy fclose on pipes for HP/UX -- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) -- fix configure if CC is already equal to gcc - -Changes in 1.0.5 (3 Jan 98) -- Fix inflate to terminate gracefully when fed corrupted or invalid data -- Use const for rommable constants in inflate -- Eliminate memory leaks on error conditions in inflate -- Removed some vestigial code in inflate -- Update web address in README - -Changes in 1.0.4 (24 Jul 96) -- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF - bit, so the decompressor could decompress all the correct data but went - on to attempt decompressing extra garbage data. This affected minigzip too. -- zlibVersion and gzerror return const char* (needed for DLL) -- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) -- use z_error only for DEBUG (avoid problem with DLLs) - -Changes in 1.0.3 (2 Jul 96) -- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS - small and medium models; this makes the library incompatible with previous - versions for these models. (No effect in large model or on other systems.) -- return OK instead of BUF_ERROR if previous deflate call returned with - avail_out as zero but there is nothing to do -- added memcmp for non STDC compilers -- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) -- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) -- better check for 16-bit mode MSC (avoids problem with Symantec) - -Changes in 1.0.2 (23 May 96) -- added Windows DLL support -- added a function zlibVersion (for the DLL support) -- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) -- Bytef is define's instead of typedef'd only for Borland C -- avoid reading uninitialized memory in example.c -- mention in README that the zlib format is now RFC1950 -- updated Makefile.dj2 -- added algorithm.doc - -Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] -- fix array overlay in deflate.c which sometimes caused bad compressed data -- fix inflate bug with empty stored block -- fix MSDOS medium model which was broken in 0.99 -- fix deflateParams() which could generated bad compressed data. -- Bytef is define'd instead of typedef'ed (work around Borland bug) -- added an INDEX file -- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), - Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) -- speed up adler32 for modern machines without auto-increment -- added -ansi for IRIX in configure -- static_init_done in trees.c is an int -- define unlink as delete for VMS -- fix configure for QNX -- add configure branch for SCO and HPUX -- avoid many warnings (unused variables, dead assignments, etc...) -- no fdopen for BeOS -- fix the Watcom fix for 32 bit mode (define FAR as empty) -- removed redefinition of Byte for MKWERKS -- work around an MWKERKS bug (incorrect merge of all .h files) - -Changes in 0.99 (27 Jan 96) -- allow preset dictionary shared between compressor and decompressor -- allow compression level 0 (no compression) -- add deflateParams in zlib.h: allow dynamic change of compression level - and compression strategy. -- test large buffers and deflateParams in example.c -- add optional "configure" to build zlib as a shared library -- suppress Makefile.qnx, use configure instead -- fixed deflate for 64-bit systems (detected on Cray) -- fixed inflate_blocks for 64-bit systems (detected on Alpha) -- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) -- always return Z_BUF_ERROR when deflate() has nothing to do -- deflateInit and inflateInit are now macros to allow version checking -- prefix all global functions and types with z_ with -DZ_PREFIX -- make falloc completely reentrant (inftrees.c) -- fixed very unlikely race condition in ct_static_init -- free in reverse order of allocation to help memory manager -- use zlib-1.0/* instead of zlib/* inside the tar.gz -- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith - -Wconversion -Wstrict-prototypes -Wmissing-prototypes" -- allow gzread on concatenated .gz files -- deflateEnd now returns Z_DATA_ERROR if it was premature -- deflate is finally (?) fully deterministic (no matches beyond end of input) -- Document Z_SYNC_FLUSH -- add uninstall in Makefile -- Check for __cpluplus in zlib.h -- Better test in ct_align for partial flush -- avoid harmless warnings for Borland C++ -- initialize hash_head in deflate.c -- avoid warning on fdopen (gzio.c) for HP cc -Aa -- include stdlib.h for STDC compilers -- include errno.h for Cray -- ignore error if ranlib doesn't exist -- call ranlib twice for NeXTSTEP -- use exec_prefix instead of prefix for libz.a -- renamed ct_* as _tr_* to avoid conflict with applications -- clear z->msg in inflateInit2 before any error return -- initialize opaque in example.c, gzio.c, deflate.c and inflate.c -- fixed typo in zconf.h (_GNUC__ => __GNUC__) -- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) -- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) -- in fcalloc, normalize pointer if size > 65520 bytes -- don't use special fcalloc for 32 bit Borland C++ -- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... -- use Z_BINARY instead of BINARY -- document that gzclose after gzdopen will close the file -- allow "a" as mode in gzopen. -- fix error checking in gzread -- allow skipping .gz extra-field on pipes -- added reference to Perl interface in README -- put the crc table in FAR data (I dislike more and more the medium model :) -- added get_crc_table -- added a dimension to all arrays (Borland C can't count). -- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast -- guard against multiple inclusion of *.h (for precompiled header on Mac) -- Watcom C pretends to be Microsoft C small model even in 32 bit mode. -- don't use unsized arrays to avoid silly warnings by Visual C++: - warning C4746: 'inflate_mask' : unsized array treated as '__far' - (what's wrong with far data in far model?). -- define enum out of inflate_blocks_state to allow compilation with C++ - -Changes in 0.95 (16 Aug 95) -- fix MSDOS small and medium model (now easier to adapt to any compiler) -- inlined send_bits -- fix the final (:-) bug for deflate with flush (output was correct but - not completely flushed in rare occasions). -- default window size is same for compression and decompression - (it's now sufficient to set MAX_WBITS in zconf.h). -- voidp -> voidpf and voidnp -> voidp (for consistency with other - typedefs and because voidnp was not near in large model). - -Changes in 0.94 (13 Aug 95) -- support MSDOS medium model -- fix deflate with flush (could sometimes generate bad output) -- fix deflateReset (zlib header was incorrectly suppressed) -- added support for VMS -- allow a compression level in gzopen() -- gzflush now calls fflush -- For deflate with flush, flush even if no more input is provided. -- rename libgz.a as libz.a -- avoid complex expression in infcodes.c triggering Turbo C bug -- work around a problem with gcc on Alpha (in INSERT_STRING) -- don't use inline functions (problem with some gcc versions) -- allow renaming of Byte, uInt, etc... with #define. -- avoid warning about (unused) pointer before start of array in deflate.c -- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c -- avoid reserved word 'new' in trees.c - -Changes in 0.93 (25 June 95) -- temporarily disable inline functions -- make deflate deterministic -- give enough lookahead for PARTIAL_FLUSH -- Set binary mode for stdin/stdout in minigzip.c for OS/2 -- don't even use signed char in inflate (not portable enough) -- fix inflate memory leak for segmented architectures - -Changes in 0.92 (3 May 95) -- don't assume that char is signed (problem on SGI) -- Clear bit buffer when starting a stored block -- no memcpy on Pyramid -- suppressed inftest.c -- optimized fill_window, put longest_match inline for gcc -- optimized inflate on stored blocks. -- untabify all sources to simplify patches - -Changes in 0.91 (2 May 95) -- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h -- Document the memory requirements in zconf.h -- added "make install" -- fix sync search logic in inflateSync -- deflate(Z_FULL_FLUSH) now works even if output buffer too short -- after inflateSync, don't scare people with just "lo world" -- added support for DJGPP - -Changes in 0.9 (1 May 95) -- don't assume that zalloc clears the allocated memory (the TurboC bug - was Mark's bug after all :) -- let again gzread copy uncompressed data unchanged (was working in 0.71) -- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented -- added a test of inflateSync in example.c -- moved MAX_WBITS to zconf.h because users might want to change that. -- document explicitly that zalloc(64K) on MSDOS must return a normalized - pointer (zero offset) -- added Makefiles for Microsoft C, Turbo C, Borland C++ -- faster crc32() - -Changes in 0.8 (29 April 95) -- added fast inflate (inffast.c) -- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this - is incompatible with previous versions of zlib which returned Z_OK. -- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) - (actually that was not a compiler bug, see 0.81 above) -- gzread no longer reads one extra byte in certain cases -- In gzio destroy(), don't reference a freed structure -- avoid many warnings for MSDOS -- avoid the ERROR symbol which is used by MS Windows - -Changes in 0.71 (14 April 95) -- Fixed more MSDOS compilation problems :( There is still a bug with - TurboC large model. - -Changes in 0.7 (14 April 95) -- Added full inflate support. -- Simplified the crc32() interface. The pre- and post-conditioning - (one's complement) is now done inside crc32(). WARNING: this is - incompatible with previous versions; see zlib.h for the new usage. - -Changes in 0.61 (12 April 95) -- workaround for a bug in TurboC. example and minigzip now work on MSDOS. - -Changes in 0.6 (11 April 95) -- added minigzip.c -- added gzdopen to reopen a file descriptor as gzFile -- added transparent reading of non-gziped files in gzread. -- fixed bug in gzread (don't read crc as data) -- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). -- don't allocate big arrays in the stack (for MSDOS) -- fix some MSDOS compilation problems - -Changes in 0.5: -- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but - not yet Z_FULL_FLUSH. -- support decompression but only in a single step (forced Z_FINISH) -- added opaque object for zalloc and zfree. -- added deflateReset and inflateReset -- added a variable zlib_version for consistency checking. -- renamed the 'filter' parameter of deflateInit2 as 'strategy'. - Added Z_FILTERED and Z_HUFFMAN_ONLY constants. - -Changes in 0.4: -- avoid "zip" everywhere, use zlib instead of ziplib. -- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush - if compression method == 8. -- added adler32 and crc32 -- renamed deflateOptions as deflateInit2, call one or the other but not both -- added the method parameter for deflateInit2. -- added inflateInit2 -- simplied considerably deflateInit and inflateInit by not supporting - user-provided history buffer. This is supported only in deflateInit2 - and inflateInit2. - -Changes in 0.3: -- prefix all macro names with Z_ -- use Z_FINISH instead of deflateEnd to finish compression. -- added Z_HUFFMAN_ONLY -- added gzerror() diff --git a/zlib/FAQ b/zlib/FAQ deleted file mode 100755 index 311f442..0000000 Binary files a/zlib/FAQ and /dev/null differ diff --git a/zlib/INDEX b/zlib/INDEX deleted file mode 100755 index cd39422..0000000 Binary files a/zlib/INDEX and /dev/null differ diff --git a/zlib/MacOS/.cvsignore b/zlib/MacOS/.cvsignore deleted file mode 100644 index b8b71e6..0000000 --- a/zlib/MacOS/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -*Data -zlib.ppc -zlib.carb diff --git a/zlib/MacOS/zlib.CWPro6.mcp b/zlib/MacOS/zlib.CWPro6.mcp deleted file mode 100644 index 5704434..0000000 Binary files a/zlib/MacOS/zlib.CWPro6.mcp and /dev/null differ diff --git a/zlib/MacOS/zlib.CWPro7.mcp b/zlib/MacOS/zlib.CWPro7.mcp deleted file mode 100644 index d45ba84..0000000 Binary files a/zlib/MacOS/zlib.CWPro7.mcp and /dev/null differ diff --git a/zlib/MacOS/zlib.mcp b/zlib/MacOS/zlib.mcp deleted file mode 100755 index cd961fc..0000000 Binary files a/zlib/MacOS/zlib.mcp and /dev/null differ diff --git a/zlib/Make_vms.com b/zlib/Make_vms.com deleted file mode 100755 index c512688..0000000 Binary files a/zlib/Make_vms.com and /dev/null differ diff --git a/zlib/Makefile.am b/zlib/Makefile.am deleted file mode 100755 index 3826e8b..0000000 Binary files a/zlib/Makefile.am and /dev/null differ diff --git a/zlib/Makefile.in b/zlib/Makefile.in deleted file mode 100755 index 4ee3102..0000000 --- a/zlib/Makefile.in +++ /dev/null @@ -1,175 +0,0 @@ -# Makefile for zlib -# Copyright (C) 1995-2002 Jean-loup Gailly. -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile and test, type: -# ./configure; make test -# The call of configure is optional if you don't have special requirements -# If you wish to build zlib as a shared library, use: ./configure -s - -# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: -# make install -# To install in $HOME instead of /usr/local, use: -# make install prefix=$HOME - -CC=cc - -CFLAGS=-O -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-g -DDEBUG -#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ -# -Wstrict-prototypes -Wmissing-prototypes - -LDFLAGS=-L. -lz -LDSHARED=$(CC) -CPP=$(CC) -E - -VER=1.1.4 -LIBS=libz.a -SHAREDLIB=libz.so - -AR=ar rc -RANLIB=ranlib -TAR=tar -SHELL=/bin/sh - -prefix = /usr/local -exec_prefix = ${prefix} -libdir = ${exec_prefix}/lib -includedir = ${prefix}/include - -OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ - zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o - -OBJA = -# to use the asm code: make OBJA=match.o - -TEST_OBJS = example.o minigzip.o - -DISTFILES = README FAQ INDEX ChangeLog configure Make*[a-z0-9] *.[ch] *.mms \ - algorithm.txt zlib.3 zlib.html \ - msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \ - nt/Make*[a-z0-9] nt/zlib.dnt amiga/Make*.??? os2/M*.os2 os2/zlib.def \ - contrib/RE*.contrib contrib/*.txt contrib/asm386/*.asm contrib/asm386/*.c \ - contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/asm[56]86/*.?86 \ - contrib/asm[56]86/*.S contrib/iostream/*.cpp \ - contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \ - contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 \ - contrib/minizip/[CM]*[pe] contrib/minizip/*.[ch] contrib/minizip/*.[td]?? \ - contrib/delphi*/*.??? - -all: example minigzip - -test: all - @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ - echo hello world | ./minigzip | ./minigzip -d || \ - echo ' *** minigzip test FAILED ***' ; \ - if ./example; then \ - echo ' *** zlib test OK ***'; \ - else \ - echo ' *** zlib test FAILED ***'; \ - fi - -libz.a: $(OBJS) $(OBJA) - $(AR) $@ $(OBJS) $(OBJA) - -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 - -match.o: match.S - $(CPP) match.S > _match.s - $(CC) -c _match.s - mv _match.o match.o - rm -f _match.s - -$(SHAREDLIB).$(VER): $(OBJS) - $(LDSHARED) -o $@ $(OBJS) - rm -f $(SHAREDLIB) $(SHAREDLIB).1 - ln -s $@ $(SHAREDLIB) - ln -s $@ $(SHAREDLIB).1 - -example: example.o $(LIBS) - $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) - -minigzip: minigzip.o $(LIBS) - $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) - -install: $(LIBS) - -@if [ ! -d $(includedir) ]; then mkdir $(includedir); fi - -@if [ ! -d $(libdir) ]; then mkdir $(libdir); fi - cp zlib.h zconf.h $(includedir) - chmod 644 $(includedir)/zlib.h $(includedir)/zconf.h - cp $(LIBS) $(libdir) - cd $(libdir); chmod 755 $(LIBS) - -@(cd $(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1 - cd $(libdir); if test -f $(SHAREDLIB).$(VER); then \ - rm -f $(SHAREDLIB) $(SHAREDLIB).1; \ - ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \ - ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \ - (ldconfig || true) >/dev/null 2>&1; \ - fi -# The ranlib in install is needed on NeXTSTEP which checks file times -# ldconfig is for Linux - -uninstall: - cd $(includedir); \ - v=$(VER); \ - if test -f zlib.h; then \ - v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`; \ - rm -f zlib.h zconf.h; \ - fi; \ - cd $(libdir); rm -f libz.a; \ - if test -f $(SHAREDLIB).$$v; then \ - rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \ - fi - -clean: - rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \ - _match.s maketree - -distclean: clean - -zip: - mv Makefile Makefile~; cp -p Makefile.in Makefile - rm -f test.c ztest*.c contrib/minizip/test.zip - v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ - zip -ul9 zlib$$v $(DISTFILES) - mv Makefile~ Makefile - -dist: - mv Makefile Makefile~; cp -p Makefile.in Makefile - rm -f test.c ztest*.c contrib/minizip/test.zip - d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ - rm -f $$d.tar.gz; \ - if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \ - files=""; \ - for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \ - cd ..; \ - GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \ - if test ! -d $$d; then rm -f $$d; fi - mv Makefile~ Makefile - -tags: - etags *.[ch] - -depend: - makedepend -- $(CFLAGS) -- *.[ch] - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -adler32.o: zlib.h zconf.h -compress.o: zlib.h zconf.h -crc32.o: zlib.h zconf.h -deflate.o: deflate.h zutil.h zlib.h zconf.h -example.o: zlib.h zconf.h -gzio.o: zutil.h zlib.h zconf.h -infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h -infcodes.o: zutil.h zlib.h zconf.h -infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h -inffast.o: zutil.h zlib.h zconf.h inftrees.h -inffast.o: infblock.h infcodes.h infutil.h inffast.h -inflate.o: zutil.h zlib.h zconf.h infblock.h -inftrees.o: zutil.h zlib.h zconf.h inftrees.h -infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h -minigzip.o: zlib.h zconf.h -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h -uncompr.o: zlib.h zconf.h -zutil.o: zutil.h zlib.h zconf.h diff --git a/zlib/Makefile.riscos b/zlib/Makefile.riscos deleted file mode 100755 index 2a28743..0000000 Binary files a/zlib/Makefile.riscos and /dev/null differ diff --git a/zlib/README b/zlib/README deleted file mode 100755 index 29d6714..0000000 --- a/zlib/README +++ /dev/null @@ -1,147 +0,0 @@ -zlib 1.1.4 is a general purpose data compression library. All the code -is thread safe. The data format used by the zlib library -is described by RFCs (Request for Comments) 1950 to 1952 in the files -http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate -format) and rfc1952.txt (gzip format). These documents are also available in -other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html - -All functions of the compression library are documented in the file zlib.h -(volunteer to write man pages welcome, contact jloup@gzip.org). A usage -example of the library is given in the file example.c which also tests that -the library is working correctly. Another example is given in the file -minigzip.c. The compression library itself is composed of all source files -except example.c and minigzip.c. - -To compile all files and run the test program, follow the instructions -given at the top of Makefile. In short "make test; make install" -should work for most machines. For Unix: "./configure; make test; make install" -For MSDOS, use one of the special makefiles such as Makefile.msc. -For VMS, use Make_vms.com or descrip.mms. - -Questions about zlib should be sent to , or to -Gilles Vollant for the Windows DLL version. -The zlib home page is http://www.zlib.org or http://www.gzip.org/zlib/ -Before reporting a problem, please check this site to verify that -you have the latest version of zlib; otherwise get the latest version and -check whether the problem still exists or not. - -PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html -before asking for help. - -Mark Nelson wrote an article about zlib for the Jan. 1997 -issue of Dr. Dobb's Journal; a copy of the article is available in -http://dogma.net/markn/articles/zlibtool/zlibtool.htm - -The changes made in version 1.1.4 are documented in the file ChangeLog. -The only changes made since 1.1.3 are bug corrections: - -- ZFREE was repeated on same allocation on some error conditions. - This creates a security problem described in - http://www.zlib.org/advisory-2002-03-11.txt -- Returned incorrect error (Z_MEM_ERROR) on some invalid data -- Avoid accesses before window for invalid distances with inflate window - less than 32K. -- force windowBits > 8 to avoid a bug in the encoder for a window size - of 256 bytes. (A complete fix will be available in 1.1.5). - -The beta version 1.1.5beta includes many more changes. A new official -version 1.1.5 will be released as soon as extensive testing has been -completed on it. - - -Unsupported third party contributions are provided in directory "contrib". - -A Java implementation of zlib is available in the Java Development Kit -http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html -See the zlib home page http://www.zlib.org for details. - -A Perl interface to zlib written by Paul Marquess -is in the CPAN (Comprehensive Perl Archive Network) sites -http://www.cpan.org/modules/by-module/Compress/ - -A Python interface to zlib written by A.M. Kuchling -is available in Python 1.5 and later versions, see -http://www.python.org/doc/lib/module-zlib.html - -A zlib binding for TCL written by Andreas Kupries -is availlable at http://www.westend.com/~kupries/doc/trf/man/man.html - -An experimental package to read and write files in .zip format, -written on top of zlib by Gilles Vollant , is -available at http://www.winimage.com/zLibDll/unzip.html -and also in the contrib/minizip directory of zlib. - - -Notes for some targets: - -- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc - and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL - The zlib DLL support was initially done by Alessandro Iacopetti and is - now maintained by Gilles Vollant . Check the zlib DLL - home page at http://www.winimage.com/zLibDll - - From Visual Basic, you can call the DLL functions which do not take - a structure as argument: compress, uncompress and all gz* functions. - See contrib/visual-basic.txt for more information, or get - http://www.tcfb.com/dowseware/cmp-z-it.zip - -- For 64-bit Irix, deflate.c must be compiled without any optimization. - With -O, one libpng test fails. The test works in 32 bit mode (with - the -n32 compiler flag). The compiler bug has been reported to SGI. - -- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 - it works when compiled with cc. - -- on Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 - is necessary to get gzprintf working correctly. This is done by configure. - -- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works - with other compilers. Use "make test" to check your compiler. - -- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers. - -- For Turbo C the small model is supported only with reduced performance to - avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 - -- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html - Per Harald Myrvang - - -Acknowledgments: - - The deflate format used by zlib was defined by Phil Katz. The deflate - and zlib specifications were written by L. Peter Deutsch. Thanks to all the - people who reported problems and suggested various improvements in zlib; - they are too numerous to cite here. - -Copyright notice: - - (C) 1995-2002 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - -If you use the zlib library in a product, we would appreciate *not* -receiving lengthy legal documents to sign. The sources are provided -for free but without warranty of any kind. The library has been -entirely written by Jean-loup Gailly and Mark Adler; it does not -include third-party code. - -If you redistribute modified sources, we would appreciate that you include -in the file ChangeLog history information documenting your changes. diff --git a/zlib/adler32.c b/zlib/adler32.c deleted file mode 100755 index fae88b6..0000000 --- a/zlib/adler32.c +++ /dev/null @@ -1,48 +0,0 @@ -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zlib.h" - -#define BASE 65521L /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {s1 += buf[i]; s2 += s1;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ - unsigned long s1 = adler & 0xffff; - unsigned long s2 = (adler >> 16) & 0xffff; - int k; - - if (buf == Z_NULL) return 1L; - - while (len > 0) { - k = len < NMAX ? len : NMAX; - len -= k; - while (k >= 16) { - DO16(buf); - buf += 16; - k -= 16; - } - if (k != 0) do { - s1 += *buf++; - s2 += s1; - } while (--k); - s1 %= BASE; - s2 %= BASE; - } - return (s2 << 16) | s1; -} diff --git a/zlib/algorithm.txt b/zlib/algorithm.txt deleted file mode 100755 index 9d46dc4..0000000 Binary files a/zlib/algorithm.txt and /dev/null differ diff --git a/zlib/amiga/Makefile.pup b/zlib/amiga/Makefile.pup deleted file mode 100755 index 572c958..0000000 Binary files a/zlib/amiga/Makefile.pup and /dev/null differ diff --git a/zlib/amiga/Makefile.sas b/zlib/amiga/Makefile.sas deleted file mode 100755 index 86afe4f..0000000 Binary files a/zlib/amiga/Makefile.sas and /dev/null differ diff --git a/zlib/compress.c b/zlib/compress.c deleted file mode 100755 index 814bd9d..0000000 --- a/zlib/compress.c +++ /dev/null @@ -1,68 +0,0 @@ -/* compress.c -- compress a memory buffer - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zlib.h" - -/* =========================================================================== - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ -int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; - int level; -{ - z_stream stream; - int err; - - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; -#ifdef MAXSEG_64K - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; -#endif - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - stream.opaque = (voidpf)0; - - err = deflateInit(&stream, level); - if (err != Z_OK) return err; - - err = deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = deflateEnd(&stream); - return err; -} - -/* =========================================================================== - */ -int ZEXPORT compress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); -} diff --git a/zlib/configure b/zlib/configure deleted file mode 100755 index f5b1fef..0000000 Binary files a/zlib/configure and /dev/null differ diff --git a/zlib/contrib/README.contrib b/zlib/contrib/README.contrib deleted file mode 100755 index 307170d..0000000 Binary files a/zlib/contrib/README.contrib and /dev/null differ diff --git a/zlib/contrib/asm386/gvmat32.asm b/zlib/contrib/asm386/gvmat32.asm deleted file mode 100755 index 8a39735..0000000 Binary files a/zlib/contrib/asm386/gvmat32.asm and /dev/null differ diff --git a/zlib/contrib/asm386/gvmat32c.c b/zlib/contrib/asm386/gvmat32c.c deleted file mode 100755 index d853bb7..0000000 --- a/zlib/contrib/asm386/gvmat32c.c +++ /dev/null @@ -1,200 +0,0 @@ -/* gvmat32.c -- C portion of the optimized longest_match for 32 bits x86 - * Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant. - * File written by Gilles Vollant, by modifiying the longest_match - * from Jean-loup Gailly in deflate.c - * it prepare all parameters and call the assembly longest_match_gvasm - * longest_match execute standard C code is wmask != 0x7fff - * (assembly code is faster with a fixed wmask) - * - */ - -#include "deflate.h" - -#undef FAR -#include - -#ifdef ASMV -#define NIL 0 - -#define UNALIGNED_OK - - -/* if your C compiler don't add underline before function name, - define ADD_UNDERLINE_ASMFUNC */ -#ifdef ADD_UNDERLINE_ASMFUNC -#define longest_match_7fff _longest_match_7fff -#endif - - - -void match_init() -{ -} - -unsigned long cpudetect32(); - -uInt longest_match_c( - deflate_state *s, - IPos cur_match); /* current match */ - - -uInt longest_match_7fff( - deflate_state *s, - IPos cur_match); /* current match */ - -uInt longest_match( - deflate_state *s, - IPos cur_match) /* current match */ -{ - static uInt iIsPPro=2; - - if ((s->w_mask == 0x7fff) && (iIsPPro==0)) - return longest_match_7fff(s,cur_match); - - if (iIsPPro==2) - iIsPPro = (((cpudetect32()/0x100)&0xf)>=6) ? 1 : 0; - - return longest_match_c(s,cur_match); -} - - - -uInt longest_match_c(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan+best_len-1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2: - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match+best_len-1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend-scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan+best_len-1); -#else - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} - -#endif /* ASMV */ diff --git a/zlib/contrib/asm386/mkgvmt32.bat b/zlib/contrib/asm386/mkgvmt32.bat deleted file mode 100755 index 7dc979c..0000000 Binary files a/zlib/contrib/asm386/mkgvmt32.bat and /dev/null differ diff --git a/zlib/contrib/asm386/zlibvc.def b/zlib/contrib/asm386/zlibvc.def deleted file mode 100755 index d559dfb..0000000 Binary files a/zlib/contrib/asm386/zlibvc.def and /dev/null differ diff --git a/zlib/contrib/asm386/zlibvc.dsp b/zlib/contrib/asm386/zlibvc.dsp deleted file mode 100755 index 750446d..0000000 Binary files a/zlib/contrib/asm386/zlibvc.dsp and /dev/null differ diff --git a/zlib/contrib/asm386/zlibvc.dsw b/zlib/contrib/asm386/zlibvc.dsw deleted file mode 100755 index bc4496c..0000000 Binary files a/zlib/contrib/asm386/zlibvc.dsw and /dev/null differ diff --git a/zlib/contrib/asm586/README.586 b/zlib/contrib/asm586/README.586 deleted file mode 100755 index 9c050f3..0000000 Binary files a/zlib/contrib/asm586/README.586 and /dev/null differ diff --git a/zlib/contrib/asm586/match.S b/zlib/contrib/asm586/match.S deleted file mode 100755 index 8180d2c..0000000 Binary files a/zlib/contrib/asm586/match.S and /dev/null differ diff --git a/zlib/contrib/asm686/README.686 b/zlib/contrib/asm686/README.686 deleted file mode 100755 index dbfbed6..0000000 Binary files a/zlib/contrib/asm686/README.686 and /dev/null differ diff --git a/zlib/contrib/asm686/match.S b/zlib/contrib/asm686/match.S deleted file mode 100755 index b1aaa6e..0000000 Binary files a/zlib/contrib/asm686/match.S and /dev/null differ diff --git a/zlib/contrib/delphi/zlib.mak b/zlib/contrib/delphi/zlib.mak deleted file mode 100755 index cfe09b7..0000000 Binary files a/zlib/contrib/delphi/zlib.mak and /dev/null differ diff --git a/zlib/contrib/delphi/zlibdef.pas b/zlib/contrib/delphi/zlibdef.pas deleted file mode 100755 index 2094f55..0000000 Binary files a/zlib/contrib/delphi/zlibdef.pas and /dev/null differ diff --git a/zlib/contrib/delphi2/d_zlib.bpr b/zlib/contrib/delphi2/d_zlib.bpr deleted file mode 100755 index b94e72c..0000000 Binary files a/zlib/contrib/delphi2/d_zlib.bpr and /dev/null differ diff --git a/zlib/contrib/delphi2/d_zlib.cpp b/zlib/contrib/delphi2/d_zlib.cpp deleted file mode 100755 index f5dea59..0000000 --- a/zlib/contrib/delphi2/d_zlib.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#pragma hdrstop -//--------------------------------------------------------------------------- -USEUNIT("adler32.c"); -USEUNIT("deflate.c"); -USEUNIT("infblock.c"); -USEUNIT("infcodes.c"); -USEUNIT("inffast.c"); -USEUNIT("inflate.c"); -USEUNIT("inftrees.c"); -USEUNIT("infutil.c"); -USEUNIT("trees.c"); -//--------------------------------------------------------------------------- -#define Library - -// To add a file to the library use the Project menu 'Add to Project'. - diff --git a/zlib/contrib/delphi2/readme.txt b/zlib/contrib/delphi2/readme.txt deleted file mode 100755 index d6de716..0000000 Binary files a/zlib/contrib/delphi2/readme.txt and /dev/null differ diff --git a/zlib/contrib/delphi2/zlib.bpg b/zlib/contrib/delphi2/zlib.bpg deleted file mode 100755 index 27a6106..0000000 Binary files a/zlib/contrib/delphi2/zlib.bpg and /dev/null differ diff --git a/zlib/contrib/delphi2/zlib.bpr b/zlib/contrib/delphi2/zlib.bpr deleted file mode 100755 index a2b5e2d..0000000 Binary files a/zlib/contrib/delphi2/zlib.bpr and /dev/null differ diff --git a/zlib/contrib/delphi2/zlib.cpp b/zlib/contrib/delphi2/zlib.cpp deleted file mode 100755 index bf6953b..0000000 --- a/zlib/contrib/delphi2/zlib.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#pragma hdrstop -//--------------------------------------------------------------------------- -USEUNIT("adler32.c"); -USEUNIT("compress.c"); -USEUNIT("crc32.c"); -USEUNIT("deflate.c"); -USEUNIT("gzio.c"); -USEUNIT("infblock.c"); -USEUNIT("infcodes.c"); -USEUNIT("inffast.c"); -USEUNIT("inflate.c"); -USEUNIT("inftrees.c"); -USEUNIT("infutil.c"); -USEUNIT("trees.c"); -USEUNIT("uncompr.c"); -USEUNIT("zutil.c"); -//--------------------------------------------------------------------------- -#define Library - -// To add a file to the library use the Project menu 'Add to Project'. - diff --git a/zlib/contrib/delphi2/zlib.pas b/zlib/contrib/delphi2/zlib.pas deleted file mode 100755 index ce35e89..0000000 Binary files a/zlib/contrib/delphi2/zlib.pas and /dev/null differ diff --git a/zlib/contrib/delphi2/zlib32.bpr b/zlib/contrib/delphi2/zlib32.bpr deleted file mode 100755 index 2c9afba..0000000 Binary files a/zlib/contrib/delphi2/zlib32.bpr and /dev/null differ diff --git a/zlib/contrib/delphi2/zlib32.cpp b/zlib/contrib/delphi2/zlib32.cpp deleted file mode 100755 index 7372f6b..0000000 --- a/zlib/contrib/delphi2/zlib32.cpp +++ /dev/null @@ -1,42 +0,0 @@ - -#include -#pragma hdrstop -#include - - -//--------------------------------------------------------------------------- -// Important note about DLL memory management in a VCL DLL: -// -// -// -// If your DLL uses VCL and exports any functions that pass VCL String objects -// (or structs/classes containing nested Strings) as parameter or function -// results, you will need to build both your DLL project and any EXE projects -// that use your DLL with the dynamic RTL (the RTL DLL). This will change your -// DLL and its calling EXE's to use BORLNDMM.DLL as their memory manager. In -// these cases, the file BORLNDMM.DLL should be deployed along with your DLL -// and the RTL DLL (CP3240MT.DLL). To avoid the requiring BORLNDMM.DLL in -// these situations, pass string information using "char *" or ShortString -// parameters and then link with the static RTL. -// -//--------------------------------------------------------------------------- -USEUNIT("adler32.c"); -USEUNIT("compress.c"); -USEUNIT("crc32.c"); -USEUNIT("deflate.c"); -USEUNIT("gzio.c"); -USEUNIT("infblock.c"); -USEUNIT("infcodes.c"); -USEUNIT("inffast.c"); -USEUNIT("inflate.c"); -USEUNIT("inftrees.c"); -USEUNIT("infutil.c"); -USEUNIT("trees.c"); -USEUNIT("uncompr.c"); -USEUNIT("zutil.c"); -//--------------------------------------------------------------------------- -#pragma argsused -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*) -{ - return 1; -} diff --git a/zlib/contrib/iostream/test.cpp b/zlib/contrib/iostream/test.cpp deleted file mode 100755 index 7d265b3..0000000 --- a/zlib/contrib/iostream/test.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include "zfstream.h" - -int main() { - - // Construct a stream object with this filebuffer. Anything sent - // to this stream will go to standard out. - gzofstream os( 1, ios::out ); - - // This text is getting compressed and sent to stdout. - // To prove this, run 'test | zcat'. - os << "Hello, Mommy" << endl; - - os << setcompressionlevel( Z_NO_COMPRESSION ); - os << "hello, hello, hi, ho!" << endl; - - setcompressionlevel( os, Z_DEFAULT_COMPRESSION ) - << "I'm compressing again" << endl; - - os.close(); - - return 0; - -} diff --git a/zlib/contrib/iostream/zfstream.cpp b/zlib/contrib/iostream/zfstream.cpp deleted file mode 100755 index a690bbe..0000000 --- a/zlib/contrib/iostream/zfstream.cpp +++ /dev/null @@ -1,329 +0,0 @@ - -#include -#include "zfstream.h" - -gzfilebuf::gzfilebuf() : - file(NULL), - mode(0), - own_file_descriptor(0) -{ } - -gzfilebuf::~gzfilebuf() { - - sync(); - if ( own_file_descriptor ) - close(); - -} - -gzfilebuf *gzfilebuf::open( const char *name, - int io_mode ) { - - if ( is_open() ) - return NULL; - - char char_mode[10]; - char *p; - memset(char_mode,'\0',10); - p = char_mode; - - if ( io_mode & ios::in ) { - mode = ios::in; - *p++ = 'r'; - } else if ( io_mode & ios::app ) { - mode = ios::app; - *p++ = 'a'; - } else { - mode = ios::out; - *p++ = 'w'; - } - - if ( io_mode & ios::binary ) { - mode |= ios::binary; - *p++ = 'b'; - } - - // Hard code the compression level - if ( io_mode & (ios::out|ios::app )) { - *p++ = '9'; - } - - if ( (file = gzopen(name, char_mode)) == NULL ) - return NULL; - - own_file_descriptor = 1; - - return this; - -} - -gzfilebuf *gzfilebuf::attach( int file_descriptor, - int io_mode ) { - - if ( is_open() ) - return NULL; - - char char_mode[10]; - char *p; - memset(char_mode,'\0',10); - p = char_mode; - - if ( io_mode & ios::in ) { - mode = ios::in; - *p++ = 'r'; - } else if ( io_mode & ios::app ) { - mode = ios::app; - *p++ = 'a'; - } else { - mode = ios::out; - *p++ = 'w'; - } - - if ( io_mode & ios::binary ) { - mode |= ios::binary; - *p++ = 'b'; - } - - // Hard code the compression level - if ( io_mode & (ios::out|ios::app )) { - *p++ = '9'; - } - - if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) - return NULL; - - own_file_descriptor = 0; - - return this; - -} - -gzfilebuf *gzfilebuf::close() { - - if ( is_open() ) { - - sync(); - gzclose( file ); - file = NULL; - - } - - return this; - -} - -int gzfilebuf::setcompressionlevel( short comp_level ) { - - return gzsetparams(file, comp_level, -2); - -} - -int gzfilebuf::setcompressionstrategy( short comp_strategy ) { - - return gzsetparams(file, -2, comp_strategy); - -} - - -streampos gzfilebuf::seekoff( streamoff off, ios::seek_dir dir, int which ) { - - return streampos(EOF); - -} - -int gzfilebuf::underflow() { - - // If the file hasn't been opened for reading, error. - if ( !is_open() || !(mode & ios::in) ) - return EOF; - - // if a buffer doesn't exists, allocate one. - if ( !base() ) { - - if ( (allocate()) == EOF ) - return EOF; - setp(0,0); - - } else { - - if ( in_avail() ) - return (unsigned char) *gptr(); - - if ( out_waiting() ) { - if ( flushbuf() == EOF ) - return EOF; - } - - } - - // Attempt to fill the buffer. - - int result = fillbuf(); - if ( result == EOF ) { - // disable get area - setg(0,0,0); - return EOF; - } - - return (unsigned char) *gptr(); - -} - -int gzfilebuf::overflow( int c ) { - - if ( !is_open() || !(mode & ios::out) ) - return EOF; - - if ( !base() ) { - if ( allocate() == EOF ) - return EOF; - setg(0,0,0); - } else { - if (in_avail()) { - return EOF; - } - if (out_waiting()) { - if (flushbuf() == EOF) - return EOF; - } - } - - int bl = blen(); - setp( base(), base() + bl); - - if ( c != EOF ) { - - *pptr() = c; - pbump(1); - - } - - return 0; - -} - -int gzfilebuf::sync() { - - if ( !is_open() ) - return EOF; - - if ( out_waiting() ) - return flushbuf(); - - return 0; - -} - -int gzfilebuf::flushbuf() { - - int n; - char *q; - - q = pbase(); - n = pptr() - q; - - if ( gzwrite( file, q, n) < n ) - return EOF; - - setp(0,0); - - return 0; - -} - -int gzfilebuf::fillbuf() { - - int required; - char *p; - - p = base(); - - required = blen(); - - int t = gzread( file, p, required ); - - if ( t <= 0) return EOF; - - setg( base(), base(), base()+t); - - return t; - -} - -gzfilestream_common::gzfilestream_common() : - ios( gzfilestream_common::rdbuf() ) -{ } - -gzfilestream_common::~gzfilestream_common() -{ } - -void gzfilestream_common::attach( int fd, int io_mode ) { - - if ( !buffer.attach( fd, io_mode) ) - clear( ios::failbit | ios::badbit ); - else - clear(); - -} - -void gzfilestream_common::open( const char *name, int io_mode ) { - - if ( !buffer.open( name, io_mode ) ) - clear( ios::failbit | ios::badbit ); - else - clear(); - -} - -void gzfilestream_common::close() { - - if ( !buffer.close() ) - clear( ios::failbit | ios::badbit ); - -} - -gzfilebuf *gzfilestream_common::rdbuf() { - - return &buffer; - -} - -gzifstream::gzifstream() : - ios( gzfilestream_common::rdbuf() ) -{ - clear( ios::badbit ); -} - -gzifstream::gzifstream( const char *name, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::open( name, io_mode ); -} - -gzifstream::gzifstream( int fd, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::attach( fd, io_mode ); -} - -gzifstream::~gzifstream() { } - -gzofstream::gzofstream() : - ios( gzfilestream_common::rdbuf() ) -{ - clear( ios::badbit ); -} - -gzofstream::gzofstream( const char *name, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::open( name, io_mode ); -} - -gzofstream::gzofstream( int fd, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::attach( fd, io_mode ); -} - -gzofstream::~gzofstream() { } diff --git a/zlib/contrib/iostream/zfstream.h b/zlib/contrib/iostream/zfstream.h deleted file mode 100755 index c87fa08..0000000 --- a/zlib/contrib/iostream/zfstream.h +++ /dev/null @@ -1,142 +0,0 @@ - -#ifndef _zfstream_h -#define _zfstream_h - -#include -#include "zlib.h" - -class gzfilebuf : public streambuf { - -public: - - gzfilebuf( ); - virtual ~gzfilebuf(); - - gzfilebuf *open( const char *name, int io_mode ); - gzfilebuf *attach( int file_descriptor, int io_mode ); - gzfilebuf *close(); - - int setcompressionlevel( short comp_level ); - int setcompressionstrategy( short comp_strategy ); - - inline int is_open() const { return (file !=NULL); } - - virtual streampos seekoff( streamoff, ios::seek_dir, int ); - - virtual int sync(); - -protected: - - virtual int underflow(); - virtual int overflow( int = EOF ); - -private: - - gzFile file; - short mode; - short own_file_descriptor; - - int flushbuf(); - int fillbuf(); - -}; - -class gzfilestream_common : virtual public ios { - - friend class gzifstream; - friend class gzofstream; - friend gzofstream &setcompressionlevel( gzofstream &, int ); - friend gzofstream &setcompressionstrategy( gzofstream &, int ); - -public: - virtual ~gzfilestream_common(); - - void attach( int fd, int io_mode ); - void open( const char *name, int io_mode ); - void close(); - -protected: - gzfilestream_common(); - -private: - gzfilebuf *rdbuf(); - - gzfilebuf buffer; - -}; - -class gzifstream : public gzfilestream_common, public istream { - -public: - - gzifstream(); - gzifstream( const char *name, int io_mode = ios::in ); - gzifstream( int fd, int io_mode = ios::in ); - - virtual ~gzifstream(); - -}; - -class gzofstream : public gzfilestream_common, public ostream { - -public: - - gzofstream(); - gzofstream( const char *name, int io_mode = ios::out ); - gzofstream( int fd, int io_mode = ios::out ); - - virtual ~gzofstream(); - -}; - -template class gzomanip { - friend gzofstream &operator<<(gzofstream &, const gzomanip &); -public: - gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { } -private: - gzofstream &(*func)(gzofstream &, T); - T val; -}; - -template gzofstream &operator<<(gzofstream &s, - const gzomanip &m) { - return (*m.func)(s, m.val); - -} - -inline gzofstream &setcompressionlevel( gzofstream &s, int l ) { - (s.rdbuf())->setcompressionlevel(l); - return s; -} - -inline gzofstream &setcompressionstrategy( gzofstream &s, int l ) { - (s.rdbuf())->setcompressionstrategy(l); - return s; -} - -inline gzomanip setcompressionlevel(int l) -{ - return gzomanip(&setcompressionlevel,l); -} - -inline gzomanip setcompressionstrategy(int l) -{ - return gzomanip(&setcompressionstrategy,l); -} - -#endif - - - - - - - - - - - - - - - diff --git a/zlib/contrib/iostream2/zstream.h b/zlib/contrib/iostream2/zstream.h deleted file mode 100755 index 861ef2b..0000000 --- a/zlib/contrib/iostream2/zstream.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - * - * Copyright (c) 1997 - * Christian Michelsen Research AS - * Advanced Computing - * Fantoftvegen 38, 5036 BERGEN, Norway - * http://www.cmr.no - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Christian Michelsen Research AS makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#ifndef ZSTREAM__H -#define ZSTREAM__H - -/* - * zstream.h - C++ interface to the 'zlib' general purpose compression library - * $Id$ - */ - -#include -#include -#include -#include "zlib.h" - -#if defined(_WIN32) -# include -# include -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif - -class zstringlen { -public: - zstringlen(class izstream&); - zstringlen(class ozstream&, const char*); - size_t value() const { return val.word; } -private: - struct Val { unsigned char byte; size_t word; } val; -}; - -// ----------------------------- izstream ----------------------------- - -class izstream -{ - public: - izstream() : m_fp(0) {} - izstream(FILE* fp) : m_fp(0) { open(fp); } - izstream(const char* name) : m_fp(0) { open(name); } - ~izstream() { close(); } - - /* Opens a gzip (.gz) file for reading. - * open() can be used to read a file which is not in gzip format; - * in this case read() will directly read from the file without - * decompression. errno can be checked to distinguish two error - * cases (if errno is zero, the zlib error is Z_MEM_ERROR). - */ - void open(const char* name) { - if (m_fp) close(); - m_fp = ::gzopen(name, "rb"); - } - - void open(FILE* fp) { - SET_BINARY_MODE(fp); - if (m_fp) close(); - m_fp = ::gzdopen(fileno(fp), "rb"); - } - - /* Flushes all pending input if necessary, closes the compressed file - * and deallocates all the (de)compression state. The return value is - * the zlib error number (see function error() below). - */ - int close() { - int r = ::gzclose(m_fp); - m_fp = 0; return r; - } - - /* Binary read the given number of bytes from the compressed file. - */ - int read(void* buf, size_t len) { - return ::gzread(m_fp, buf, len); - } - - /* Returns the error message for the last error which occurred on the - * given compressed file. errnum is set to zlib error number. If an - * error occurred in the file system and not in the compression library, - * errnum is set to Z_ERRNO and the application may consult errno - * to get the exact error code. - */ - const char* error(int* errnum) { - return ::gzerror(m_fp, errnum); - } - - gzFile fp() { return m_fp; } - - private: - gzFile m_fp; -}; - -/* - * Binary read the given (array of) object(s) from the compressed file. - * If the input file was not in gzip format, read() copies the objects number - * of bytes into the buffer. - * returns the number of uncompressed bytes actually read - * (0 for end of file, -1 for error). - */ -template -inline int read(izstream& zs, T* x, Items items) { - return ::gzread(zs.fp(), x, items*sizeof(T)); -} - -/* - * Binary input with the '>' operator. - */ -template -inline izstream& operator>(izstream& zs, T& x) { - ::gzread(zs.fp(), &x, sizeof(T)); - return zs; -} - - -inline zstringlen::zstringlen(izstream& zs) { - zs > val.byte; - if (val.byte == 255) zs > val.word; - else val.word = val.byte; -} - -/* - * Read length of string + the string with the '>' operator. - */ -inline izstream& operator>(izstream& zs, char* x) { - zstringlen len(zs); - ::gzread(zs.fp(), x, len.value()); - x[len.value()] = '\0'; - return zs; -} - -inline char* read_string(izstream& zs) { - zstringlen len(zs); - char* x = new char[len.value()+1]; - ::gzread(zs.fp(), x, len.value()); - x[len.value()] = '\0'; - return x; -} - -// ----------------------------- ozstream ----------------------------- - -class ozstream -{ - public: - ozstream() : m_fp(0), m_os(0) { - } - ozstream(FILE* fp, int level = Z_DEFAULT_COMPRESSION) - : m_fp(0), m_os(0) { - open(fp, level); - } - ozstream(const char* name, int level = Z_DEFAULT_COMPRESSION) - : m_fp(0), m_os(0) { - open(name, level); - } - ~ozstream() { - close(); - } - - /* Opens a gzip (.gz) file for writing. - * The compression level parameter should be in 0..9 - * errno can be checked to distinguish two error cases - * (if errno is zero, the zlib error is Z_MEM_ERROR). - */ - void open(const char* name, int level = Z_DEFAULT_COMPRESSION) { - char mode[4] = "wb\0"; - if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; - if (m_fp) close(); - m_fp = ::gzopen(name, mode); - } - - /* open from a FILE pointer. - */ - void open(FILE* fp, int level = Z_DEFAULT_COMPRESSION) { - SET_BINARY_MODE(fp); - char mode[4] = "wb\0"; - if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; - if (m_fp) close(); - m_fp = ::gzdopen(fileno(fp), mode); - } - - /* Flushes all pending output if necessary, closes the compressed file - * and deallocates all the (de)compression state. The return value is - * the zlib error number (see function error() below). - */ - int close() { - if (m_os) { - ::gzwrite(m_fp, m_os->str(), m_os->pcount()); - delete[] m_os->str(); delete m_os; m_os = 0; - } - int r = ::gzclose(m_fp); m_fp = 0; return r; - } - - /* Binary write the given number of bytes into the compressed file. - */ - int write(const void* buf, size_t len) { - return ::gzwrite(m_fp, (voidp) buf, len); - } - - /* Flushes all pending output into the compressed file. The parameter - * _flush is as in the deflate() function. The return value is the zlib - * error number (see function gzerror below). flush() returns Z_OK if - * the flush_ parameter is Z_FINISH and all output could be flushed. - * flush() should be called only when strictly necessary because it can - * degrade compression. - */ - int flush(int _flush) { - os_flush(); - return ::gzflush(m_fp, _flush); - } - - /* Returns the error message for the last error which occurred on the - * given compressed file. errnum is set to zlib error number. If an - * error occurred in the file system and not in the compression library, - * errnum is set to Z_ERRNO and the application may consult errno - * to get the exact error code. - */ - const char* error(int* errnum) { - return ::gzerror(m_fp, errnum); - } - - gzFile fp() { return m_fp; } - - ostream& os() { - if (m_os == 0) m_os = new ostrstream; - return *m_os; - } - - void os_flush() { - if (m_os && m_os->pcount()>0) { - ostrstream* oss = new ostrstream; - oss->fill(m_os->fill()); - oss->flags(m_os->flags()); - oss->precision(m_os->precision()); - oss->width(m_os->width()); - ::gzwrite(m_fp, m_os->str(), m_os->pcount()); - delete[] m_os->str(); delete m_os; m_os = oss; - } - } - - private: - gzFile m_fp; - ostrstream* m_os; -}; - -/* - * Binary write the given (array of) object(s) into the compressed file. - * returns the number of uncompressed bytes actually written - * (0 in case of error). - */ -template -inline int write(ozstream& zs, const T* x, Items items) { - return ::gzwrite(zs.fp(), (voidp) x, items*sizeof(T)); -} - -/* - * Binary output with the '<' operator. - */ -template -inline ozstream& operator<(ozstream& zs, const T& x) { - ::gzwrite(zs.fp(), (voidp) &x, sizeof(T)); - return zs; -} - -inline zstringlen::zstringlen(ozstream& zs, const char* x) { - val.byte = 255; val.word = ::strlen(x); - if (val.word < 255) zs < (val.byte = val.word); - else zs < val; -} - -/* - * Write length of string + the string with the '<' operator. - */ -inline ozstream& operator<(ozstream& zs, const char* x) { - zstringlen len(zs, x); - ::gzwrite(zs.fp(), (voidp) x, len.value()); - return zs; -} - -#ifdef _MSC_VER -inline ozstream& operator<(ozstream& zs, char* const& x) { - return zs < (const char*) x; -} -#endif - -/* - * Ascii write with the << operator; - */ -template -inline ostream& operator<<(ozstream& zs, const T& x) { - zs.os_flush(); - return zs.os() << x; -} - -#endif diff --git a/zlib/contrib/iostream2/zstream_test.cpp b/zlib/contrib/iostream2/zstream_test.cpp deleted file mode 100755 index 5bbd56c..0000000 --- a/zlib/contrib/iostream2/zstream_test.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "zstream.h" -#include -#include -#include - -void main() { - char h[256] = "Hello"; - char* g = "Goodbye"; - ozstream out("temp.gz"); - out < "This works well" < h < g; - out.close(); - - izstream in("temp.gz"); // read it back - char *x = read_string(in), *y = new char[256], z[256]; - in > y > z; - in.close(); - cout << x << endl << y << endl << z << endl; - - out.open("temp.gz"); // try ascii output; zcat temp.gz to see the results - out << setw(50) << setfill('#') << setprecision(20) << x << endl << y << endl << z << endl; - out << z << endl << y << endl << x << endl; - out << 1.1234567890123456789 << endl; - - delete[] x; delete[] y; -} diff --git a/zlib/contrib/minizip/ChangeLogUnzip b/zlib/contrib/minizip/ChangeLogUnzip deleted file mode 100755 index 5faee0b..0000000 Binary files a/zlib/contrib/minizip/ChangeLogUnzip and /dev/null differ diff --git a/zlib/contrib/minizip/Makefile b/zlib/contrib/minizip/Makefile deleted file mode 100755 index 5650e9e..0000000 Binary files a/zlib/contrib/minizip/Makefile and /dev/null differ diff --git a/zlib/contrib/minizip/miniunz.c b/zlib/contrib/minizip/miniunz.c deleted file mode 100755 index f3b7832..0000000 --- a/zlib/contrib/minizip/miniunz.c +++ /dev/null @@ -1,508 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#ifdef unix -# include -# include -#else -# include -# include -#endif - -#include "unzip.h" - -#define CASESENSITIVITY (0) -#define WRITEBUFFERSIZE (8192) - -/* - mini unzip, demo of unzip package - - usage : - Usage : miniunz [-exvlo] file.zip [file_to_extract] - - list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT - if it exists -*/ - - -/* change_file_date : change the date/time of a file - filename : the filename of the file where date/time must be modified - dosdate : the new date at the MSDos format (4 bytes) - tmu_date : the SAME new date at the tm_unz format */ -void change_file_date(filename,dosdate,tmu_date) - const char *filename; - uLong dosdate; - tm_unz tmu_date; -{ -#ifdef WIN32 - HANDLE hFile; - FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; - - hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, - 0,NULL,OPEN_EXISTING,0,NULL); - GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); - DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); - LocalFileTimeToFileTime(&ftLocal,&ftm); - SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); - CloseHandle(hFile); -#else -#ifdef unix - struct utimbuf ut; - struct tm newdate; - newdate.tm_sec = tmu_date.tm_sec; - newdate.tm_min=tmu_date.tm_min; - newdate.tm_hour=tmu_date.tm_hour; - newdate.tm_mday=tmu_date.tm_mday; - newdate.tm_mon=tmu_date.tm_mon; - if (tmu_date.tm_year > 1900) - newdate.tm_year=tmu_date.tm_year - 1900; - else - newdate.tm_year=tmu_date.tm_year ; - newdate.tm_isdst=-1; - - ut.actime=ut.modtime=mktime(&newdate); - utime(filename,&ut); -#endif -#endif -} - - -/* mymkdir and change_file_date are not 100 % portable - As I don't know well Unix, I wait feedback for the unix portion */ - -int mymkdir(dirname) - const char* dirname; -{ - int ret=0; -#ifdef WIN32 - ret = mkdir(dirname); -#else -#ifdef unix - ret = mkdir (dirname,0775); -#endif -#endif - return ret; -} - -int makedir (newdir) - char *newdir; -{ - char *buffer ; - char *p; - int len = strlen(newdir); - - if (len <= 0) - return 0; - - buffer = (char*)malloc(len+1); - strcpy(buffer,newdir); - - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mymkdir(buffer) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mymkdir(buffer) == -1) && (errno == ENOENT)) - { - printf("couldn't create directory %s\n",buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - -void do_banner() -{ - printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n"); - printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n"); -} - -void do_help() -{ - printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ; -} - - -int do_list(uf) - unzFile uf; -{ - uLong i; - unz_global_info gi; - int err; - - err = unzGetGlobalInfo (uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); - printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); - for (i=0;i0) - ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; - - if (file_info.compression_method==0) - string_method="Stored"; - else - if (file_info.compression_method==Z_DEFLATED) - { - uInt iLevel=(uInt)((file_info.flag & 0x6)/2); - if (iLevel==0) - string_method="Defl:N"; - else if (iLevel==1) - string_method="Defl:X"; - else if ((iLevel==2) || (iLevel==3)) - string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ - } - else - string_method="Unkn. "; - - printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", - file_info.uncompressed_size,string_method,file_info.compressed_size, - ratio, - (uLong)file_info.tmu_date.tm_mon + 1, - (uLong)file_info.tmu_date.tm_mday, - (uLong)file_info.tmu_date.tm_year % 100, - (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, - (uLong)file_info.crc,filename_inzip); - if ((i+1)='a') && (rep<='z')) - rep -= 0x20; - } - while ((rep!='Y') && (rep!='N') && (rep!='A')); - } - - if (rep == 'N') - skip = 1; - - if (rep == 'A') - *popt_overwrite=1; - } - - if ((skip==0) && (err==UNZ_OK)) - { - fout=fopen(write_filename,"wb"); - - /* some zipfile don't contain directory alone before file */ - if ((fout==NULL) && ((*popt_extract_without_path)==0) && - (filename_withoutpath!=(char*)filename_inzip)) - { - char c=*(filename_withoutpath-1); - *(filename_withoutpath-1)='\0'; - makedir(write_filename); - *(filename_withoutpath-1)=c; - fout=fopen(write_filename,"wb"); - } - - if (fout==NULL) - { - printf("error opening %s\n",write_filename); - } - } - - if (fout!=NULL) - { - printf(" extracting: %s\n",write_filename); - - do - { - err = unzReadCurrentFile(uf,buf,size_buf); - if (err<0) - { - printf("error %d with zipfile in unzReadCurrentFile\n",err); - break; - } - if (err>0) - if (fwrite(buf,err,1,fout)!=1) - { - printf("error in writing extracted file\n"); - err=UNZ_ERRNO; - break; - } - } - while (err>0); - fclose(fout); - if (err==0) - change_file_date(write_filename,file_info.dosDate, - file_info.tmu_date); - } - - if (err==UNZ_OK) - { - err = unzCloseCurrentFile (uf); - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzCloseCurrentFile\n",err); - } - } - else - unzCloseCurrentFile(uf); /* don't lose the error */ - } - - free(buf); - return err; -} - - -int do_extract(uf,opt_extract_without_path,opt_overwrite) - unzFile uf; - int opt_extract_without_path; - int opt_overwrite; -{ - uLong i; - unz_global_info gi; - int err; - FILE* fout=NULL; - - err = unzGetGlobalInfo (uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - - for (i=0;i -#include -#include -#include -#include -#include - -#ifdef unix -# include -# include -# include -# include -#else -# include -# include -#endif - -#include "zip.h" - - -#define WRITEBUFFERSIZE (16384) -#define MAXFILENAME (256) - -#ifdef WIN32 -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - int ret = 0; - { - FILETIME ftLocal; - HANDLE hFind; - WIN32_FIND_DATA ff32; - - hFind = FindFirstFile(f,&ff32); - if (hFind != INVALID_HANDLE_VALUE) - { - FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); - FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); - FindClose(hFind); - ret = 1; - } - } - return ret; -} -#else -#ifdef unix -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - int ret=0; - struct stat s; /* results of stat() */ - struct tm* filedate; - time_t tm_t=0; - - if (strcmp(f,"-")!=0) - { - char name[MAXFILENAME]; - int len = strlen(f); - strcpy(name, f); - if (name[len - 1] == '/') - name[len - 1] = '\0'; - /* not all systems allow stat'ing a file with / appended */ - if (stat(name,&s)==0) - { - tm_t = s.st_mtime; - ret = 1; - } - } - filedate = localtime(&tm_t); - - tmzip->tm_sec = filedate->tm_sec; - tmzip->tm_min = filedate->tm_min; - tmzip->tm_hour = filedate->tm_hour; - tmzip->tm_mday = filedate->tm_mday; - tmzip->tm_mon = filedate->tm_mon ; - tmzip->tm_year = filedate->tm_year; - - return ret; -} -#else -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - return 0; -} -#endif -#endif - - - - -int check_exist_file(filename) - const char* filename; -{ - FILE* ftestexist; - int ret = 1; - ftestexist = fopen(filename,"rb"); - if (ftestexist==NULL) - ret = 0; - else - fclose(ftestexist); - return ret; -} - -void do_banner() -{ - printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n"); - printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n"); -} - -void do_help() -{ - printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ; -} - -int main(argc,argv) - int argc; - char *argv[]; -{ - int i; - int opt_overwrite=0; - int opt_compress_level=Z_DEFAULT_COMPRESSION; - int zipfilenamearg = 0; - char filename_try[MAXFILENAME]; - int zipok; - int err=0; - int size_buf=0; - void* buf=NULL, - - - do_banner(); - if (argc==1) - { - do_help(); - exit(0); - return 0; - } - else - { - for (i=1;i='0') && (c<='9')) - opt_compress_level = c-'0'; - } - } - else - if (zipfilenamearg == 0) - zipfilenamearg = i ; - } - } - - size_buf = WRITEBUFFERSIZE; - buf = (void*)malloc(size_buf); - if (buf==NULL) - { - printf("Error allocating memory\n"); - return ZIP_INTERNALERROR; - } - - if (zipfilenamearg==0) - zipok=0; - else - { - int i,len; - int dot_found=0; - - zipok = 1 ; - strcpy(filename_try,argv[zipfilenamearg]); - len=strlen(filename_try); - for (i=0;i='a') && (rep<='z')) - rep -= 0x20; - } - while ((rep!='Y') && (rep!='N')); - if (rep=='N') - zipok = 0; - } - } - - if (zipok==1) - { - zipFile zf; - int errclose; - zf = zipOpen(filename_try,0); - if (zf == NULL) - { - printf("error opening %s\n",filename_try); - err= ZIP_ERRNO; - } - else - printf("creating %s\n",filename_try); - - for (i=zipfilenamearg+1;(i0) - { - err = zipWriteInFileInZip (zf,buf,size_read); - if (err<0) - { - printf("error in writing %s in the zipfile\n", - filenameinzip); - } - - } - } while ((err == ZIP_OK) && (size_read>0)); - - fclose(fin); - if (err<0) - err=ZIP_ERRNO; - else - { - err = zipCloseFileInZip(zf); - if (err!=ZIP_OK) - printf("error in closing %s in the zipfile\n", - filenameinzip); - } - } - } - errclose = zipClose(zf,NULL); - if (errclose != ZIP_OK) - printf("error in closing %s\n",filename_try); - } - - free(buf); - exit(0); - return 0; /* to avoid warning */ -} diff --git a/zlib/contrib/minizip/readme.txt b/zlib/contrib/minizip/readme.txt deleted file mode 100755 index 31975e8..0000000 Binary files a/zlib/contrib/minizip/readme.txt and /dev/null differ diff --git a/zlib/contrib/minizip/unzip.c b/zlib/contrib/minizip/unzip.c deleted file mode 100755 index ff71a47..0000000 --- a/zlib/contrib/minizip/unzip.c +++ /dev/null @@ -1,1294 +0,0 @@ -/* unzip.c -- IO on .zip files using zlib - Version 0.15 beta, Mar 19th, 1998, - - Read unzip.h for more info -*/ - - -#include -#include -#include -#include "zlib.h" -#include "unzip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - - - -#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ - !defined(CASESENSITIVITYDEFAULT_NO) -#define CASESENSITIVITYDEFAULT_NO -#endif - - -#ifndef UNZ_BUFSIZE -#define UNZ_BUFSIZE (16384) -#endif - -#ifndef UNZ_MAXFILENAMEINZIP -#define UNZ_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -const char unz_copyright[] = - " unzip 0.15 Copyright 1998 Gilles Vollant "; - -/* unz_file_info_interntal contain internal info about a file in zipfile*/ -typedef struct unz_file_info_internal_s -{ - uLong offset_curfile;/* relative offset of local header 4 bytes */ -} unz_file_info_internal; - - -/* file_in_zip_read_info_s contain internal information about a file in zipfile, - when reading and decompress it */ -typedef struct -{ - char *read_buffer; /* internal buffer for compressed data */ - z_stream stream; /* zLib stream structure for inflate */ - - uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialised*/ - - uLong offset_local_extrafield;/* offset of the local extra field */ - uInt size_local_extrafield;/* size of the local extra field */ - uLong pos_local_extrafield; /* position in the local extra field in read*/ - - uLong crc32; /* crc32 of all data uncompressed */ - uLong crc32_wait; /* crc32 we must obtain after decompress all */ - uLong rest_read_compressed; /* number of byte to be decompressed */ - uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ - FILE* file; /* io structore of the zipfile */ - uLong compression_method; /* compression method (0==store) */ - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ -} file_in_zip_read_info_s; - - -/* unz_s contain internal information about the zipfile -*/ -typedef struct -{ - FILE* file; /* io structore of the zipfile */ - unz_global_info gi; /* public global information */ - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - uLong num_file; /* number of the current file in the zipfile*/ - uLong pos_in_central_dir; /* pos of the current file in the central dir*/ - uLong current_file_ok; /* flag about the usability of the current file*/ - uLong central_pos; /* position of the beginning of the central dir*/ - - uLong size_central_dir; /* size of the central directory */ - uLong offset_central_dir; /* offset of start of central directory with - respect to the starting disk number */ - - unz_file_info cur_file_info; /* public info about the current file in zip*/ - unz_file_info_internal cur_file_info_internal; /* private info about it*/ - file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current - file if we are decompressing it */ -} unz_s; - - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ - - -local int unzlocal_getByte(fin,pi) - FILE *fin; - int *pi; -{ - unsigned char c; - int err = fread(&c, 1, 1, fin); - if (err==1) - { - *pi = (int)c; - return UNZ_OK; - } - else - { - if (ferror(fin)) - return UNZ_ERRNO; - else - return UNZ_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unzlocal_getShort (fin,pX) - FILE* fin; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = unzlocal_getByte(fin,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unzlocal_getLong (fin,pX) - FILE* fin; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = unzlocal_getByte(fin,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - - -/* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (fileName1,fileName2) - const char* fileName1; - const char* fileName2; -{ - for (;;) - { - char c1=*(fileName1++); - char c2=*(fileName2++); - if ((c1>='a') && (c1<='z')) - c1 -= 0x20; - if ((c2>='a') && (c2<='z')) - c2 -= 0x20; - if (c1=='\0') - return ((c2=='\0') ? 0 : -1); - if (c2=='\0') - return 1; - if (c1c2) - return 1; - } -} - - -#ifdef CASESENSITIVITYDEFAULT_NO -#define CASESENSITIVITYDEFAULTVALUE 2 -#else -#define CASESENSITIVITYDEFAULTVALUE 1 -#endif - -#ifndef STRCMPCASENOSENTIVEFUNCTION -#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal -#endif - -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) - -*/ -extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) - const char* fileName1; - const char* fileName2; - int iCaseSensitivity; -{ - if (iCaseSensitivity==0) - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; - - if (iCaseSensitivity==1) - return strcmp(fileName1,fileName2); - - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); -} - -#define BUFREADCOMMENT (0x400) - -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local uLong unzlocal_SearchCentralDir(fin) - FILE *fin; -{ - unsigned char* buf; - uLong uSizeFile; - uLong uBackRead; - uLong uMaxBack=0xffff; /* maximum size of global comment */ - uLong uPosFound=0; - - if (fseek(fin,0,SEEK_END) != 0) - return 0; - - - uSizeFile = ftell( fin ); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); - if (fseek(fin,uReadPos,SEEK_SET)!=0) - break; - - if (fread(buf,(uInt)uReadSize,1,fin)!=1) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer - "zlib/zlib109.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ -extern unzFile ZEXPORT unzOpen (path) - const char *path; -{ - unz_s us; - unz_s *s; - uLong central_pos,uL; - FILE * fin ; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - uLong number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - - int err=UNZ_OK; - - if (unz_copyright[0]!=' ') - return NULL; - - fin=fopen(path,"rb"); - if (fin==NULL) - return NULL; - - central_pos = unzlocal_SearchCentralDir(fin); - if (central_pos==0) - err=UNZ_ERRNO; - - if (fseek(fin,central_pos,SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unzlocal_getLong(fin,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir */ - if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* zipfile comment length */ - if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((central_pospfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); - - fclose(s->file); - TRYFREE(s); - return UNZ_OK; -} - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) - unzFile file; - unz_global_info *pglobal_info; -{ - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - *pglobal_info=s->gi; - return UNZ_OK; -} - - -/* - Translate date/time from Dos format to tm_unz (readable more easilty) -*/ -local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) - uLong ulDosDate; - tm_unz* ptm; -{ - uLong uDate; - uDate = (uLong)(ulDosDate>>16); - ptm->tm_mday = (uInt)(uDate&0x1f) ; - ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; - ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; - - ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; -} - -/* - Get Info about the current file in the zipfile, with internal only info -*/ -local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info *pfile_info, - unz_file_info_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unzlocal_GetCurrentFileInfoInternal (file, - pfile_info, - pfile_info_internal, - szFileName, fileNameBufferSize, - extraField, extraFieldBufferSize, - szComment, commentBufferSize) - unzFile file; - unz_file_info *pfile_info; - unz_file_info_internal *pfile_info_internal; - char *szFileName; - uLong fileNameBufferSize; - void *extraField; - uLong extraFieldBufferSize; - char *szComment; - uLong commentBufferSize; -{ - unz_s* s; - unz_file_info file_info; - unz_file_info_internal file_info_internal; - int err=UNZ_OK; - uLong uMagic; - long lSeek=0; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) - err=UNZ_ERRNO; - - - /* we check the magic */ - if (err==UNZ_OK) - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x02014b50) - err=UNZ_BADZIPFILE; - - if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) - err=UNZ_ERRNO; - - unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); - - if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - - lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_filename0) && (fileNameBufferSize>0)) - if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) - err=UNZ_ERRNO; - lSeek -= uSizeRead; - } - - - if ((err==UNZ_OK) && (extraField!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) - if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) - err=UNZ_ERRNO; - lSeek += file_info.size_file_extra - uSizeRead; - } - else - lSeek+=file_info.size_file_extra; - - - if ((err==UNZ_OK) && (szComment!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - if ((file_info.size_file_comment>0) && (commentBufferSize>0)) - if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) - err=UNZ_ERRNO; - lSeek+=file_info.size_file_comment - uSizeRead; - } - else - lSeek+=file_info.size_file_comment; - - if ((err==UNZ_OK) && (pfile_info!=NULL)) - *pfile_info=file_info; - - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) - *pfile_info_internal=file_info_internal; - - return err; -} - - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. -*/ -extern int ZEXPORT unzGetCurrentFileInfo (file, - pfile_info, - szFileName, fileNameBufferSize, - extraField, extraFieldBufferSize, - szComment, commentBufferSize) - unzFile file; - unz_file_info *pfile_info; - char *szFileName; - uLong fileNameBufferSize; - void *extraField; - uLong extraFieldBufferSize; - char *szComment; - uLong commentBufferSize; -{ - return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); -} - -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ -extern int ZEXPORT unzGoToFirstFile (file) - unzFile file; -{ - int err=UNZ_OK; - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - s->pos_in_central_dir=s->offset_central_dir; - s->num_file=0; - err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - - -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -extern int ZEXPORT unzGoToNextFile (file) - unzFile file; -{ - unz_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - if (s->num_file+1==s->gi.number_entry) - return UNZ_END_OF_LIST_OF_FILE; - - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; - s->num_file++; - err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - - -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzipStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ -extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) - unzFile file; - const char *szFileName; - int iCaseSensitivity; -{ - unz_s* s; - int err; - - - uLong num_fileSaved; - uLong pos_in_central_dirSaved; - - - if (file==NULL) - return UNZ_PARAMERROR; - - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; - - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - num_fileSaved = s->num_file; - pos_in_central_dirSaved = s->pos_in_central_dir; - - err = unzGoToFirstFile(file); - - while (err == UNZ_OK) - { - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - unzGetCurrentFileInfo(file,NULL, - szCurrentFileName,sizeof(szCurrentFileName)-1, - NULL,0,NULL,0); - if (unzStringFileNameCompare(szCurrentFileName, - szFileName,iCaseSensitivity)==0) - return UNZ_OK; - err = unzGoToNextFile(file); - } - - s->num_file = num_fileSaved ; - s->pos_in_central_dir = pos_in_central_dirSaved ; - return err; -} - - -/* - Read the local header of the current zipfile - Check the coherency of the local header and info in the end of central - directory about this file - store in *piSizeVar the size of extra info in local header - (filename and size of extra field data) -*/ -local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, - poffset_local_extrafield, - psize_local_extrafield) - unz_s* s; - uInt* piSizeVar; - uLong *poffset_local_extrafield; - uInt *psize_local_extrafield; -{ - uLong uMagic,uData,uFlags; - uLong size_filename; - uLong size_extra_field; - int err=UNZ_OK; - - *piSizeVar = 0; - *poffset_local_extrafield = 0; - *psize_local_extrafield = 0; - - if (fseek(s->file,s->cur_file_info_internal.offset_curfile + - s->byte_before_the_zipfile,SEEK_SET)!=0) - return UNZ_ERRNO; - - - if (err==UNZ_OK) - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x04034b50) - err=UNZ_BADZIPFILE; - - if (unzlocal_getShort(s->file,&uData) != UNZ_OK) - err=UNZ_ERRNO; -/* - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) - err=UNZ_BADZIPFILE; -*/ - if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&uData) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) - err=UNZ_BADZIPFILE; - - if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - - if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) - err=UNZ_BADZIPFILE; - - *piSizeVar += (uInt)size_filename; - - if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) - err=UNZ_ERRNO; - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + - SIZEZIPLOCALHEADER + size_filename; - *psize_local_extrafield = (uInt)size_extra_field; - - *piSizeVar += (uInt)size_extra_field; - - return err; -} - -/* - Open for reading data the current file in the zipfile. - If there is no error and the file is opened, the return value is UNZ_OK. -*/ -extern int ZEXPORT unzOpenCurrentFile (file) - unzFile file; -{ - int err=UNZ_OK; - int Store; - uInt iSizeVar; - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - uLong offset_local_extrafield; /* offset of the local extra field */ - uInt size_local_extrafield; /* size of the local extra field */ - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_PARAMERROR; - - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); - - if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, - &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) - return UNZ_BADZIPFILE; - - pfile_in_zip_read_info = (file_in_zip_read_info_s*) - ALLOC(sizeof(file_in_zip_read_info_s)); - if (pfile_in_zip_read_info==NULL) - return UNZ_INTERNALERROR; - - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; - pfile_in_zip_read_info->pos_local_extrafield=0; - - if (pfile_in_zip_read_info->read_buffer==NULL) - { - TRYFREE(pfile_in_zip_read_info); - return UNZ_INTERNALERROR; - } - - pfile_in_zip_read_info->stream_initialised=0; - - if ((s->cur_file_info.compression_method!=0) && - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - Store = s->cur_file_info.compression_method==0; - - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; - pfile_in_zip_read_info->crc32=0; - pfile_in_zip_read_info->compression_method = - s->cur_file_info.compression_method; - pfile_in_zip_read_info->file=s->file; - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; - - pfile_in_zip_read_info->stream.total_out = 0; - - if (!Store) - { - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=1; - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - * In unzip, i don't wait absolutely Z_STREAM_END because I known the - * size of both compressed and uncompressed data - */ - } - pfile_in_zip_read_info->rest_read_compressed = - s->cur_file_info.compressed_size ; - pfile_in_zip_read_info->rest_read_uncompressed = - s->cur_file_info.uncompressed_size ; - - - pfile_in_zip_read_info->pos_in_zipfile = - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + - iSizeVar; - - pfile_in_zip_read_info->stream.avail_in = (uInt)0; - - - s->pfile_in_zip_read = pfile_in_zip_read_info; - return UNZ_OK; -} - - -/* - Read bytes from the current file. - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ -extern int ZEXPORT unzReadCurrentFile (file, buf, len) - unzFile file; - voidp buf; - unsigned len; -{ - int err=UNZ_OK; - uInt iRead = 0; - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->read_buffer == NULL)) - return UNZ_END_OF_LIST_OF_FILE; - if (len==0) - return 0; - - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; - - pfile_in_zip_read_info->stream.avail_out = (uInt)len; - - if (len>pfile_in_zip_read_info->rest_read_uncompressed) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_uncompressed; - - while (pfile_in_zip_read_info->stream.avail_out>0) - { - if ((pfile_in_zip_read_info->stream.avail_in==0) && - (pfile_in_zip_read_info->rest_read_compressed>0)) - { - uInt uReadThis = UNZ_BUFSIZE; - if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; - if (uReadThis == 0) - return UNZ_EOF; - if (fseek(pfile_in_zip_read_info->file, - pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) - return UNZ_ERRNO; - if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, - pfile_in_zip_read_info->file)!=1) - return UNZ_ERRNO; - pfile_in_zip_read_info->pos_in_zipfile += uReadThis; - - pfile_in_zip_read_info->rest_read_compressed-=uReadThis; - - pfile_in_zip_read_info->stream.next_in = - (Bytef*)pfile_in_zip_read_info->read_buffer; - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; - } - - if (pfile_in_zip_read_info->compression_method==0) - { - uInt uDoCopy,i ; - if (pfile_in_zip_read_info->stream.avail_out < - pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; - else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; - - for (i=0;istream.next_out+i) = - *(pfile_in_zip_read_info->stream.next_in+i); - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, - pfile_in_zip_read_info->stream.next_out, - uDoCopy); - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; - pfile_in_zip_read_info->stream.avail_in -= uDoCopy; - pfile_in_zip_read_info->stream.avail_out -= uDoCopy; - pfile_in_zip_read_info->stream.next_out += uDoCopy; - pfile_in_zip_read_info->stream.next_in += uDoCopy; - pfile_in_zip_read_info->stream.total_out += uDoCopy; - iRead += uDoCopy; - } - else - { - uLong uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - uLong uOutThis; - int flush=Z_SYNC_FLUSH; - - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ - err=inflate(&pfile_in_zip_read_info->stream,flush); - - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->crc32 = - crc32(pfile_in_zip_read_info->crc32,bufBefore, - (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; - - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - if (err==Z_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=Z_OK) - break; - } - } - - if (err==Z_OK) - return iRead; - return err; -} - - -/* - Give the current position in uncompressed data -*/ -extern z_off_t ZEXPORT unztell (file) - unzFile file; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - return (z_off_t)pfile_in_zip_read_info->stream.total_out; -} - - -/* - return 1 if the end of file was reached, 0 elsewhere -*/ -extern int ZEXPORT unzeof (file) - unzFile file; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - return 1; - else - return 0; -} - - - -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field that can be read - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ -extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) - unzFile file; - voidp buf; - unsigned len; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - uInt read_now; - uLong size_to_read; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - size_to_read = (pfile_in_zip_read_info->size_local_extrafield - - pfile_in_zip_read_info->pos_local_extrafield); - - if (buf==NULL) - return (int)size_to_read; - - if (len>size_to_read) - read_now = (uInt)size_to_read; - else - read_now = (uInt)len ; - - if (read_now==0) - return 0; - - if (fseek(pfile_in_zip_read_info->file, - pfile_in_zip_read_info->offset_local_extrafield + - pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) - return UNZ_ERRNO; - - if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) - return UNZ_ERRNO; - - return (int)read_now; -} - -/* - Close the file in zip opened with unzipOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ -extern int ZEXPORT unzCloseCurrentFile (file) - unzFile file; -{ - int err=UNZ_OK; - - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - { - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) - err=UNZ_CRCERROR; - } - - - TRYFREE(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; - if (pfile_in_zip_read_info->stream_initialised) - inflateEnd(&pfile_in_zip_read_info->stream); - - pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); - - s->pfile_in_zip_read=NULL; - - return err; -} - - -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ -extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) - unzFile file; - char *szComment; - uLong uSizeBuf; -{ - int err=UNZ_OK; - unz_s* s; - uLong uReadThis ; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - - uReadThis = uSizeBuf; - if (uReadThis>s->gi.size_comment) - uReadThis = s->gi.size_comment; - - if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) - return UNZ_ERRNO; - - if (uReadThis>0) - { - *szComment='\0'; - if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) - return UNZ_ERRNO; - } - - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) - *(szComment+s->gi.size_comment)='\0'; - return (int)uReadThis; -} diff --git a/zlib/contrib/minizip/unzip.def b/zlib/contrib/minizip/unzip.def deleted file mode 100755 index 69475f2..0000000 Binary files a/zlib/contrib/minizip/unzip.def and /dev/null differ diff --git a/zlib/contrib/minizip/unzip.h b/zlib/contrib/minizip/unzip.h deleted file mode 100755 index 76692cb..0000000 --- a/zlib/contrib/minizip/unzip.h +++ /dev/null @@ -1,275 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 0.15 beta, Mar 19th, 1998, - - Copyright (C) 1998 Gilles Vollant - - This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Encryption and multi volume ZipFile (span) are not supported. - Old compressions used by old PKZip 1.x are not supported - - THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE - CAN CHANGE IN FUTURE VERSION !! - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -*/ -/* for more info about .ZIP format, see - ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip */ - -#ifndef _unz_H -#define _unz_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer - "zlib/zlib111.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _unz_H */ diff --git a/zlib/contrib/minizip/zip.c b/zlib/contrib/minizip/zip.c deleted file mode 100755 index 0cae64a..0000000 --- a/zlib/contrib/minizip/zip.c +++ /dev/null @@ -1,718 +0,0 @@ -/* zip.c -- IO on .zip files using zlib - Version 0.15 beta, Mar 19th, 1998, - - Read zip.h for more info -*/ - - -#include -#include -#include -#include "zlib.h" -#include "zip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -#ifndef VERSIONMADEBY -# define VERSIONMADEBY (0x0) /* platform depedent */ -#endif - -#ifndef Z_BUFSIZE -#define Z_BUFSIZE (16384) -#endif - -#ifndef Z_MAXFILENAMEINZIP -#define Z_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -/* -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) -*/ - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -const char zip_copyright[] = - " zip 0.15 Copyright 1998 Gilles Vollant "; - - -#define SIZEDATA_INDATABLOCK (4096-(4*4)) - -#define LOCALHEADERMAGIC (0x04034b50) -#define CENTRALHEADERMAGIC (0x02014b50) -#define ENDHEADERMAGIC (0x06054b50) - -#define FLAG_LOCALHEADER_OFFSET (0x06) -#define CRC_LOCALHEADER_OFFSET (0x0e) - -#define SIZECENTRALHEADER (0x2e) /* 46 */ - -typedef struct linkedlist_datablock_internal_s -{ - struct linkedlist_datablock_internal_s* next_datablock; - uLong avail_in_this_block; - uLong filled_in_this_block; - uLong unused; /* for future use and alignement */ - unsigned char data[SIZEDATA_INDATABLOCK]; -} linkedlist_datablock_internal; - -typedef struct linkedlist_data_s -{ - linkedlist_datablock_internal* first_block; - linkedlist_datablock_internal* last_block; -} linkedlist_data; - - -typedef struct -{ - z_stream stream; /* zLib stream structure for inflate */ - int stream_initialised; /* 1 is stream is initialised */ - uInt pos_in_buffered_data; /* last written byte in buffered_data */ - - uLong pos_local_header; /* offset of the local header of the file - currenty writing */ - char* central_header; /* central header data for the current file */ - uLong size_centralheader; /* size of the central header for cur file */ - uLong flag; /* flag of the file currently writing */ - - int method; /* compression method of file currenty wr.*/ - Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ - uLong dosDate; - uLong crc32; -} curfile_info; - -typedef struct -{ - FILE * filezip; - linkedlist_data central_dir;/* datablock with central dir in construction*/ - int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ - curfile_info ci; /* info on the file curretly writing */ - - uLong begin_pos; /* position of the beginning of the zipfile */ - uLong number_entry; -} zip_internal; - -local linkedlist_datablock_internal* allocate_new_datablock() -{ - linkedlist_datablock_internal* ldi; - ldi = (linkedlist_datablock_internal*) - ALLOC(sizeof(linkedlist_datablock_internal)); - if (ldi!=NULL) - { - ldi->next_datablock = NULL ; - ldi->filled_in_this_block = 0 ; - ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; - } - return ldi; -} - -local void free_datablock(ldi) - linkedlist_datablock_internal* ldi; -{ - while (ldi!=NULL) - { - linkedlist_datablock_internal* ldinext = ldi->next_datablock; - TRYFREE(ldi); - ldi = ldinext; - } -} - -local void init_linkedlist(ll) - linkedlist_data* ll; -{ - ll->first_block = ll->last_block = NULL; -} - -local void free_linkedlist(ll) - linkedlist_data* ll; -{ - free_datablock(ll->first_block); - ll->first_block = ll->last_block = NULL; -} - - -local int add_data_in_datablock(ll,buf,len) - linkedlist_data* ll; - const void* buf; - uLong len; -{ - linkedlist_datablock_internal* ldi; - const unsigned char* from_copy; - - if (ll==NULL) - return ZIP_INTERNALERROR; - - if (ll->last_block == NULL) - { - ll->first_block = ll->last_block = allocate_new_datablock(); - if (ll->first_block == NULL) - return ZIP_INTERNALERROR; - } - - ldi = ll->last_block; - from_copy = (unsigned char*)buf; - - while (len>0) - { - uInt copy_this; - uInt i; - unsigned char* to_copy; - - if (ldi->avail_in_this_block==0) - { - ldi->next_datablock = allocate_new_datablock(); - if (ldi->next_datablock == NULL) - return ZIP_INTERNALERROR; - ldi = ldi->next_datablock ; - ll->last_block = ldi; - } - - if (ldi->avail_in_this_block < len) - copy_this = (uInt)ldi->avail_in_this_block; - else - copy_this = (uInt)len; - - to_copy = &(ldi->data[ldi->filled_in_this_block]); - - for (i=0;ifilled_in_this_block += copy_this; - ldi->avail_in_this_block -= copy_this; - from_copy += copy_this ; - len -= copy_this; - } - return ZIP_OK; -} - - -local int write_datablock(fout,ll) - FILE * fout; - linkedlist_data* ll; -{ - linkedlist_datablock_internal* ldi; - ldi = ll->first_block; - while (ldi!=NULL) - { - if (ldi->filled_in_this_block > 0) - if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,1,fout)!=1) - return ZIP_ERRNO; - ldi = ldi->next_datablock; - } - return ZIP_OK; -} - -/****************************************************************************/ - -/* =========================================================================== - Outputs a long in LSB order to the given file - nbByte == 1, 2 or 4 (byte, short or long) -*/ - -local int ziplocal_putValue OF((FILE *file, uLong x, int nbByte)); -local int ziplocal_putValue (file, x, nbByte) - FILE *file; - uLong x; - int nbByte; -{ - unsigned char buf[4]; - int n; - for (n = 0; n < nbByte; n++) { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - if (fwrite(buf,nbByte,1,file)!=1) - return ZIP_ERRNO; - else - return ZIP_OK; -} - -local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); -local void ziplocal_putValue_inmemory (dest, x, nbByte) - void* dest; - uLong x; - int nbByte; -{ - unsigned char* buf=(unsigned char*)dest; - int n; - for (n = 0; n < nbByte; n++) { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } -} -/****************************************************************************/ - - -local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) - tm_zip* ptm; - uLong dosDate; -{ - uLong year = (uLong)ptm->tm_year; - if (year>1980) - year-=1980; - else if (year>80) - year-=80; - return - (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | - ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); -} - - -/****************************************************************************/ - -extern zipFile ZEXPORT zipOpen (pathname, append) - const char *pathname; - int append; -{ - zip_internal ziinit; - zip_internal* zi; - - ziinit.filezip = fopen(pathname,(append == 0) ? "wb" : "ab"); - if (ziinit.filezip == NULL) - return NULL; - ziinit.begin_pos = ftell(ziinit.filezip); - ziinit.in_opened_file_inzip = 0; - ziinit.ci.stream_initialised = 0; - ziinit.number_entry = 0; - init_linkedlist(&(ziinit.central_dir)); - - - zi = (zip_internal*)ALLOC(sizeof(zip_internal)); - if (zi==NULL) - { - fclose(ziinit.filezip); - return NULL; - } - - *zi = ziinit; - return (zipFile)zi; -} - -extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level) - zipFile file; - const char* filename; - const zip_fileinfo* zipfi; - const void* extrafield_local; - uInt size_extrafield_local; - const void* extrafield_global; - uInt size_extrafield_global; - const char* comment; - int method; - int level; -{ - zip_internal* zi; - uInt size_filename; - uInt size_comment; - uInt i; - int err = ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - if ((method!=0) && (method!=Z_DEFLATED)) - return ZIP_PARAMERROR; - - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - if (err != ZIP_OK) - return err; - } - - - if (filename==NULL) - filename="-"; - - if (comment==NULL) - size_comment = 0; - else - size_comment = strlen(comment); - - size_filename = strlen(filename); - - if (zipfi == NULL) - zi->ci.dosDate = 0; - else - { - if (zipfi->dosDate != 0) - zi->ci.dosDate = zipfi->dosDate; - else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); - } - - zi->ci.flag = 0; - if ((level==8) || (level==9)) - zi->ci.flag |= 2; - if ((level==2)) - zi->ci.flag |= 4; - if ((level==1)) - zi->ci.flag |= 6; - - zi->ci.crc32 = 0; - zi->ci.method = method; - zi->ci.stream_initialised = 0; - zi->ci.pos_in_buffered_data = 0; - zi->ci.pos_local_header = ftell(zi->filezip); - zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + - size_extrafield_global + size_comment; - zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); - - ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); - /* version info */ - ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); - ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); - ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); - ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); - ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); - ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ - ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); - ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); - ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); - ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ - - if (zipfi==NULL) - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); - else - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); - - if (zipfi==NULL) - ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); - else - ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); - - ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header,4); - - for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = - *(((const char*)extrafield_global)+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ - size_extrafield_global+i) = *(filename+i); - if (zi->ci.central_header == NULL) - return ZIP_INTERNALERROR; - - /* write the local header */ - err = ziplocal_putValue(zi->filezip,(uLong)LOCALHEADERMAGIC,4); - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)20,2);/* version needed to extract */ - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.flag,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.method,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.dosDate,4); - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* crc 32, unknown */ - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* compressed size, unknown */ - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* uncompressed size, unknown */ - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)size_extrafield_local,2); - - if ((err==ZIP_OK) && (size_filename>0)) - if (fwrite(filename,(uInt)size_filename,1,zi->filezip)!=1) - err = ZIP_ERRNO; - - if ((err==ZIP_OK) && (size_extrafield_local>0)) - if (fwrite(extrafield_local,(uInt)size_extrafield_local,1,zi->filezip) - !=1) - err = ZIP_ERRNO; - - zi->ci.stream.avail_in = (uInt)0; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - zi->ci.stream.total_in = 0; - zi->ci.stream.total_out = 0; - - if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED)) - { - zi->ci.stream.zalloc = (alloc_func)0; - zi->ci.stream.zfree = (free_func)0; - zi->ci.stream.opaque = (voidpf)0; - - err = deflateInit2(&zi->ci.stream, level, - Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0); - - if (err==Z_OK) - zi->ci.stream_initialised = 1; - } - - - if (err==Z_OK) - zi->in_opened_file_inzip = 1; - return err; -} - -extern int ZEXPORT zipWriteInFileInZip (file, buf, len) - zipFile file; - const voidp buf; - unsigned len; -{ - zip_internal* zi; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - - zi->ci.stream.next_in = buf; - zi->ci.stream.avail_in = len; - zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); - - while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) - { - if (zi->ci.stream.avail_out == 0) - { - if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip) - !=1) - err = ZIP_ERRNO; - zi->ci.pos_in_buffered_data = 0; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - - if (zi->ci.method == Z_DEFLATED) - { - uLong uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_NO_FLUSH); - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - - } - else - { - uInt copy_this,i; - if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) - copy_this = zi->ci.stream.avail_in; - else - copy_this = zi->ci.stream.avail_out; - for (i=0;ici.stream.next_out)+i) = - *(((const char*)zi->ci.stream.next_in)+i); - { - zi->ci.stream.avail_in -= copy_this; - zi->ci.stream.avail_out-= copy_this; - zi->ci.stream.next_in+= copy_this; - zi->ci.stream.next_out+= copy_this; - zi->ci.stream.total_in+= copy_this; - zi->ci.stream.total_out+= copy_this; - zi->ci.pos_in_buffered_data += copy_this; - } - } - } - - return 0; -} - -extern int ZEXPORT zipCloseFileInZip (file) - zipFile file; -{ - zip_internal* zi; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - zi->ci.stream.avail_in = 0; - - if (zi->ci.method == Z_DEFLATED) - while (err==ZIP_OK) - { - uLong uTotalOutBefore; - if (zi->ci.stream.avail_out == 0) - { - if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip) - !=1) - err = ZIP_ERRNO; - zi->ci.pos_in_buffered_data = 0; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_FINISH); - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - } - - if (err==Z_STREAM_END) - err=ZIP_OK; /* this is normal */ - - if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) - if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip) - !=1) - err = ZIP_ERRNO; - - if ((zi->ci.method == Z_DEFLATED) && (err==ZIP_OK)) - { - err=deflateEnd(&zi->ci.stream); - zi->ci.stream_initialised = 0; - } - - ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)zi->ci.crc32,4); /*crc*/ - ziplocal_putValue_inmemory(zi->ci.central_header+20, - (uLong)zi->ci.stream.total_out,4); /*compr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+24, - (uLong)zi->ci.stream.total_in,4); /*uncompr size*/ - - if (err==ZIP_OK) - err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, - (uLong)zi->ci.size_centralheader); - free(zi->ci.central_header); - - if (err==ZIP_OK) - { - long cur_pos_inzip = ftell(zi->filezip); - if (fseek(zi->filezip, - zi->ci.pos_local_header + 14,SEEK_SET)!=0) - err = ZIP_ERRNO; - - if (err==ZIP_OK) - err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */ - - if (err==ZIP_OK) /* compressed size, unknown */ - err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4); - - if (err==ZIP_OK) /* uncompressed size, unknown */ - err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4); - - if (fseek(zi->filezip, - cur_pos_inzip,SEEK_SET)!=0) - err = ZIP_ERRNO; - } - - zi->number_entry ++; - zi->in_opened_file_inzip = 0; - - return err; -} - -extern int ZEXPORT zipClose (file, global_comment) - zipFile file; - const char* global_comment; -{ - zip_internal* zi; - int err = 0; - uLong size_centraldir = 0; - uLong centraldir_pos_inzip ; - uInt size_global_comment; - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - } - - if (global_comment==NULL) - size_global_comment = 0; - else - size_global_comment = strlen(global_comment); - - - centraldir_pos_inzip = ftell(zi->filezip); - if (err==ZIP_OK) - { - linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; - while (ldi!=NULL) - { - if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) - if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block, - 1,zi->filezip) !=1 ) - err = ZIP_ERRNO; - - size_centraldir += ldi->filled_in_this_block; - ldi = ldi->next_datablock; - } - } - free_datablock(zi->central_dir.first_block); - - if (err==ZIP_OK) /* Magic End */ - err = ziplocal_putValue(zi->filezip,(uLong)ENDHEADERMAGIC,4); - - if (err==ZIP_OK) /* number of this disk */ - err = ziplocal_putValue(zi->filezip,(uLong)0,2); - - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = ziplocal_putValue(zi->filezip,(uLong)0,2); - - if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ - err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2); - - if (err==ZIP_OK) /* total number of entries in the central dir */ - err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2); - - if (err==ZIP_OK) /* size of the central directory */ - err = ziplocal_putValue(zi->filezip,(uLong)size_centraldir,4); - - if (err==ZIP_OK) /* offset of start of central directory with respect to the - starting disk number */ - err = ziplocal_putValue(zi->filezip,(uLong)centraldir_pos_inzip ,4); - - if (err==ZIP_OK) /* zipfile comment length */ - err = ziplocal_putValue(zi->filezip,(uLong)size_global_comment,2); - - if ((err==ZIP_OK) && (size_global_comment>0)) - if (fwrite(global_comment,(uInt)size_global_comment,1,zi->filezip) !=1 ) - err = ZIP_ERRNO; - fclose(zi->filezip); - TRYFREE(zi); - - return err; -} diff --git a/zlib/contrib/minizip/zip.def b/zlib/contrib/minizip/zip.def deleted file mode 100755 index eafe1cc..0000000 Binary files a/zlib/contrib/minizip/zip.def and /dev/null differ diff --git a/zlib/contrib/minizip/zip.h b/zlib/contrib/minizip/zip.h deleted file mode 100755 index 678260b..0000000 --- a/zlib/contrib/minizip/zip.h +++ /dev/null @@ -1,150 +0,0 @@ -/* zip.h -- IO for compress .zip files using zlib - Version 0.15 alpha, Mar 19th, 1998, - - Copyright (C) 1998 Gilles Vollant - - This unzip package allow creates .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Encryption and multi volume ZipFile (span) are not supported. - Old compressions used by old PKZip 1.x are not supported - - For uncompress .zip file, look at unzip.h - - THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE - CAN CHANGE IN FUTURE VERSION !! - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/zip.htm for evolution - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -*/ - -/* for more info about .ZIP format, see - ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip -*/ - -#ifndef _zip_H -#define _zip_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagzipFile__ { int unused; } zipFile__; -typedef zipFile__ *zipFile; -#else -typedef voidp zipFile; -#endif - -#define ZIP_OK (0) -#define ZIP_ERRNO (Z_ERRNO) -#define ZIP_PARAMERROR (-102) -#define ZIP_INTERNALERROR (-104) - -/* tm_zip contain date/time info */ -typedef struct tm_zip_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_zip; - -typedef struct -{ - tm_zip tmz_date; /* date in understandable format */ - uLong dosDate; /* if dos_date == 0, tmu_date is used */ -/* uLong flag; */ /* general purpose bit flag 2 bytes */ - - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ -} zip_fileinfo; - -extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); -/* - Create a zipfile. - pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on - an Unix computer "zlib/zlib111.zip". - if the file pathname exist and append=1, the zip will be created at the end - of the file. (useful if the file contain a self extractor code) - If the zipfile cannot be opened, the return value is NULL. - Else, the return value is a zipFile Handle, usable with other function - of this zip package. - - -*/ - -extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level)); -/* - Open a file in the ZIP for writing. - filename : the filename in zip (if NULL, '-' without quote will be used - *zipfi contain supplemental information - if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header - if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header - if comment != NULL, comment contain the comment string - method contain the compression method (0 for store, Z_DEFLATED for deflate) - level contain the level of compression (can be Z_DEFAULT_COMPRESSION) -*/ - -extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, - const voidp buf, - unsigned len)); -/* - Write data in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); -/* - Close the current file in the zipfile -*/ - -extern int ZEXPORT zipClose OF((zipFile file, - const char* global_comment)); -/* - Close the zipfile -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _zip_H */ diff --git a/zlib/contrib/minizip/zlibvc.def b/zlib/contrib/minizip/zlibvc.def deleted file mode 100755 index 430e86d..0000000 Binary files a/zlib/contrib/minizip/zlibvc.def and /dev/null differ diff --git a/zlib/contrib/minizip/zlibvc.dsp b/zlib/contrib/minizip/zlibvc.dsp deleted file mode 100755 index 52601e8..0000000 Binary files a/zlib/contrib/minizip/zlibvc.dsp and /dev/null differ diff --git a/zlib/contrib/minizip/zlibvc.dsw b/zlib/contrib/minizip/zlibvc.dsw deleted file mode 100755 index 4c5d753..0000000 Binary files a/zlib/contrib/minizip/zlibvc.dsw and /dev/null differ diff --git a/zlib/contrib/untgz/Makefile b/zlib/contrib/untgz/Makefile deleted file mode 100755 index 32760e3..0000000 Binary files a/zlib/contrib/untgz/Makefile and /dev/null differ diff --git a/zlib/contrib/untgz/makefile.w32 b/zlib/contrib/untgz/makefile.w32 deleted file mode 100755 index a93e3f2..0000000 Binary files a/zlib/contrib/untgz/makefile.w32 and /dev/null differ diff --git a/zlib/contrib/untgz/untgz.c b/zlib/contrib/untgz/untgz.c deleted file mode 100755 index 4a431ff..0000000 --- a/zlib/contrib/untgz/untgz.c +++ /dev/null @@ -1,522 +0,0 @@ -/* - * untgz.c -- Display contents and/or extract file from - * a gzip'd TAR file - * written by "Pedro A. Aranda Guti\irrez" - * adaptation to Unix by Jean-loup Gailly - */ - -#include -#include -#include -#include -#include -#include -#ifdef unix -# include -#else -# include -# include -#endif - -#include "zlib.h" - -#ifdef WIN32 -# ifndef F_OK -# define F_OK (0) -# endif -# ifdef _MSC_VER -# define mkdir(dirname,mode) _mkdir(dirname) -# define strdup(str) _strdup(str) -# define unlink(fn) _unlink(fn) -# define access(path,mode) _access(path,mode) -# else -# define mkdir(dirname,mode) _mkdir(dirname) -# endif -#else -# include -#endif - - -/* Values used in typeflag field. */ - -#define REGTYPE '0' /* regular file */ -#define AREGTYPE '\0' /* regular file */ -#define LNKTYPE '1' /* link */ -#define SYMTYPE '2' /* reserved */ -#define CHRTYPE '3' /* character special */ -#define BLKTYPE '4' /* block special */ -#define DIRTYPE '5' /* directory */ -#define FIFOTYPE '6' /* FIFO special */ -#define CONTTYPE '7' /* reserved */ - -#define BLOCKSIZE 512 - -struct tar_header -{ /* byte offset */ - char name[100]; /* 0 */ - char mode[8]; /* 100 */ - char uid[8]; /* 108 */ - char gid[8]; /* 116 */ - char size[12]; /* 124 */ - char mtime[12]; /* 136 */ - char chksum[8]; /* 148 */ - char typeflag; /* 156 */ - char linkname[100]; /* 157 */ - char magic[6]; /* 257 */ - char version[2]; /* 263 */ - char uname[32]; /* 265 */ - char gname[32]; /* 297 */ - char devmajor[8]; /* 329 */ - char devminor[8]; /* 337 */ - char prefix[155]; /* 345 */ - /* 500 */ -}; - -union tar_buffer { - char buffer[BLOCKSIZE]; - struct tar_header header; -}; - -enum { TGZ_EXTRACT = 0, TGZ_LIST }; - -static char *TGZfname OF((const char *)); -void TGZnotfound OF((const char *)); - -int getoct OF((char *, int)); -char *strtime OF((time_t *)); -int ExprMatch OF((char *,char *)); - -int makedir OF((char *)); -int matchname OF((int,int,char **,char *)); - -void error OF((const char *)); -int tar OF((gzFile, int, int, int, char **)); - -void help OF((int)); -int main OF((int, char **)); - -char *prog; - -/* This will give a benign warning */ - -static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", ".tar", NULL }; - -/* Return the real name of the TGZ archive */ -/* or NULL if it does not exist. */ - -static char *TGZfname OF((const char *fname)) -{ - static char buffer[1024]; - int origlen,i; - - strcpy(buffer,fname); - origlen = strlen(buffer); - - for (i=0; TGZprefix[i]; i++) - { - strcpy(buffer+origlen,TGZprefix[i]); - if (access(buffer,F_OK) == 0) - return buffer; - } - return NULL; -} - -/* error message for the filename */ - -void TGZnotfound OF((const char *fname)) -{ - int i; - - fprintf(stderr,"%s : couldn't find ",prog); - for (i=0;TGZprefix[i];i++) - fprintf(stderr,(TGZprefix[i+1]) ? "%s%s, " : "or %s%s\n", - fname, - TGZprefix[i]); - exit(1); -} - - -/* help functions */ - -int getoct(char *p,int width) -{ - int result = 0; - char c; - - while (width --) - { - c = *p++; - if (c == ' ') - continue; - if (c == 0) - break; - result = result * 8 + (c - '0'); - } - return result; -} - -char *strtime (time_t *t) -{ - struct tm *local; - static char result[32]; - - local = localtime(t); - sprintf(result,"%2d/%02d/%4d %02d:%02d:%02d", - local->tm_mday, local->tm_mon+1, local->tm_year+1900, - local->tm_hour, local->tm_min, local->tm_sec); - return result; -} - - -/* regular expression matching */ - -#define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) - -int ExprMatch(char *string,char *expr) -{ - while (1) - { - if (ISSPECIAL(*expr)) - { - if (*expr == '/') - { - if (*string != '\\' && *string != '/') - return 0; - string ++; expr++; - } - else if (*expr == '*') - { - if (*expr ++ == 0) - return 1; - while (*++string != *expr) - if (*string == 0) - return 0; - } - } - else - { - if (*string != *expr) - return 0; - if (*expr++ == 0) - return 1; - string++; - } - } -} - -/* recursive make directory */ -/* abort if you get an ENOENT errno somewhere in the middle */ -/* e.g. ignore error "mkdir on existing directory" */ -/* */ -/* return 1 if OK */ -/* 0 on error */ - -int makedir (char *newdir) -{ - char *buffer = strdup(newdir); - char *p; - int len = strlen(buffer); - - if (len <= 0) { - free(buffer); - return 0; - } - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mkdir(buffer, 0775) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT)) - { - fprintf(stderr,"%s: couldn't create directory %s\n",prog,buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - -int matchname (int arg,int argc,char **argv,char *fname) -{ - if (arg == argc) /* no arguments given (untgz tgzarchive) */ - return 1; - - while (arg < argc) - if (ExprMatch(fname,argv[arg++])) - return 1; - - return 0; /* ignore this for the moment being */ -} - - -/* Tar file list or extract */ - -int tar (gzFile in,int action,int arg,int argc,char **argv) -{ - union tar_buffer buffer; - int len; - int err; - int getheader = 1; - int remaining = 0; - FILE *outfile = NULL; - char fname[BLOCKSIZE]; - time_t tartime; - - if (action == TGZ_LIST) - printf(" day time size file\n" - " ---------- -------- --------- -------------------------------------\n"); - while (1) - { - len = gzread(in, &buffer, BLOCKSIZE); - if (len < 0) - error (gzerror(in, &err)); - /* - * Always expect complete blocks to process - * the tar information. - */ - if (len != BLOCKSIZE) - error("gzread: incomplete block read"); - - /* - * If we have to get a tar header - */ - if (getheader == 1) - { - /* - * if we met the end of the tar - * or the end-of-tar block, - * we are done - */ - if ((len == 0) || (buffer.header.name[0]== 0)) break; - - tartime = (time_t)getoct(buffer.header.mtime,12); - strcpy(fname,buffer.header.name); - - switch (buffer.header.typeflag) - { - case DIRTYPE: - if (action == TGZ_LIST) - printf(" %s %s\n",strtime(&tartime),fname); - if (action == TGZ_EXTRACT) - makedir(fname); - break; - case REGTYPE: - case AREGTYPE: - remaining = getoct(buffer.header.size,12); - if (action == TGZ_LIST) - printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); - if (action == TGZ_EXTRACT) - { - if ((remaining) && (matchname(arg,argc,argv,fname))) - { - outfile = fopen(fname,"wb"); - if (outfile == NULL) { - /* try creating directory */ - char *p = strrchr(fname, '/'); - if (p != NULL) { - *p = '\0'; - makedir(fname); - *p = '/'; - outfile = fopen(fname,"wb"); - } - } - fprintf(stderr, - "%s %s\n", - (outfile) ? "Extracting" : "Couldn't create", - fname); - } - else - outfile = NULL; - } - /* - * could have no contents - */ - getheader = (remaining) ? 0 : 1; - break; - default: - if (action == TGZ_LIST) - printf(" %s <---> %s\n",strtime(&tartime),fname); - break; - } - } - else - { - unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining; - - if ((action == TGZ_EXTRACT) && (outfile != NULL)) - { - if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) - { - fprintf(stderr,"%s : error writing %s skipping...\n",prog,fname); - fclose(outfile); - unlink(fname); - } - } - remaining -= bytes; - if (remaining == 0) - { - getheader = 1; - if ((action == TGZ_EXTRACT) && (outfile != NULL)) - { -#ifdef WIN32 - HANDLE hFile; - FILETIME ftm,ftLocal; - SYSTEMTIME st; - struct tm localt; - - fclose(outfile); - - localt = *localtime(&tartime); - - hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - - st.wYear = (WORD)localt.tm_year+1900; - st.wMonth = (WORD)localt.tm_mon; - st.wDayOfWeek = (WORD)localt.tm_wday; - st.wDay = (WORD)localt.tm_mday; - st.wHour = (WORD)localt.tm_hour; - st.wMinute = (WORD)localt.tm_min; - st.wSecond = (WORD)localt.tm_sec; - st.wMilliseconds = 0; - SystemTimeToFileTime(&st,&ftLocal); - LocalFileTimeToFileTime(&ftLocal,&ftm); - SetFileTime(hFile,&ftm,NULL,&ftm); - CloseHandle(hFile); - - outfile = NULL; -#else - struct utimbuf settime; - - settime.actime = settime.modtime = tartime; - - fclose(outfile); - outfile = NULL; - utime(fname,&settime); -#endif - } - } - } - } - - if (gzclose(in) != Z_OK) - error("failed gzclose"); - - return 0; -} - - -/* =========================================================== */ - -void help(int exitval) -{ - fprintf(stderr, - "untgz v 0.1\n" - " an sample application of zlib 1.0.4\n\n" - "Usage : untgz TGZfile to extract all files\n" - " untgz TGZfile fname ... to extract selected files\n" - " untgz -l TGZfile to list archive contents\n" - " untgz -h to display this help\n\n"); - exit(exitval); -} - -void error(const char *msg) -{ - fprintf(stderr, "%s: %s\n", prog, msg); - exit(1); -} - - -/* ====================================================================== */ - -int _CRT_glob = 0; /* disable globbing of the arguments */ - -int main(int argc,char **argv) -{ - int action = TGZ_EXTRACT; - int arg = 1; - char *TGZfile; - gzFile *f; - - - prog = strrchr(argv[0],'\\'); - if (prog == NULL) - { - prog = strrchr(argv[0],'/'); - if (prog == NULL) - { - prog = strrchr(argv[0],':'); - if (prog == NULL) - prog = argv[0]; - else - prog++; - } - else - prog++; - } - else - prog++; - - if (argc == 1) - help(0); - - if (strcmp(argv[arg],"-l") == 0) - { - action = TGZ_LIST; - if (argc == ++arg) - help(0); - } - else if (strcmp(argv[arg],"-h") == 0) - { - help(0); - } - - if ((TGZfile = TGZfname(argv[arg])) == NULL) - TGZnotfound(argv[arg]); - - ++arg; - if ((action == TGZ_LIST) && (arg != argc)) - help(1); - -/* - * Process the TGZ file - */ - switch(action) - { - case TGZ_LIST: - case TGZ_EXTRACT: - f = gzopen(TGZfile,"rb"); - if (f == NULL) - { - fprintf(stderr,"%s: Couldn't gzopen %s\n", - prog, - TGZfile); - return 1; - } - exit(tar(f, action, arg, argc, argv)); - break; - - default: - error("Unknown option!"); - exit(1); - } - - return 0; -} diff --git a/zlib/contrib/visual-basic.txt b/zlib/contrib/visual-basic.txt deleted file mode 100755 index 6bd5ef5..0000000 Binary files a/zlib/contrib/visual-basic.txt and /dev/null differ diff --git a/zlib/crc32.c b/zlib/crc32.c deleted file mode 100755 index 60deca2..0000000 --- a/zlib/crc32.c +++ /dev/null @@ -1,162 +0,0 @@ -/* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zlib.h" - -#define local static - -#ifdef DYNAMIC_CRC_TABLE - -local int crc_table_empty = 1; -local uLongf crc_table[256]; -local void make_crc_table OF((void)); - -/* - Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The table is simply the CRC of all possible eight bit values. This is all - the information needed to generate CRC's on data a byte at a time for all - combinations of CRC register values and incoming bytes. -*/ -local void make_crc_table() -{ - uLong c; - int n, k; - uLong poly; /* polynomial exclusive-or pattern */ - /* terms of polynomial defining this crc (except x^32): */ - static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - - /* make exclusive-or pattern from polynomial (0xedb88320L) */ - poly = 0L; - for (n = 0; n < sizeof(p)/sizeof(Byte); n++) - poly |= 1L << (31 - p[n]); - - for (n = 0; n < 256; n++) - { - c = (uLong)n; - for (k = 0; k < 8; k++) - c = c & 1 ? poly ^ (c >> 1) : c >> 1; - crc_table[n] = c; - } - crc_table_empty = 0; -} -#else -/* ======================================================================== - * Table of CRC-32's of all single-byte values (made by make_crc_table) - */ -local const uLongf crc_table[256] = { - 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, - 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, - 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, - 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, - 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, - 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, - 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, - 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, - 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, - 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, - 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, - 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, - 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, - 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, - 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, - 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, - 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, - 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, - 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, - 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, - 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, - 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, - 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, - 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, - 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, - 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, - 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, - 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, - 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, - 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, - 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, - 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, - 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, - 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, - 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, - 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, - 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, - 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, - 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, - 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, - 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, - 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, - 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, - 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, - 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, - 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, - 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, - 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, - 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, - 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, - 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, - 0x2d02ef8dL -}; -#endif - -/* ========================================================================= - * This function can be used by asm versions of crc32() - */ -const uLongf * ZEXPORT get_crc_table() -{ -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) make_crc_table(); -#endif - return (const uLongf *)crc_table; -} - -/* ========================================================================= */ -#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); -#define DO2(buf) DO1(buf); DO1(buf); -#define DO4(buf) DO2(buf); DO2(buf); -#define DO8(buf) DO4(buf); DO4(buf); - -/* ========================================================================= */ -uLong ZEXPORT crc32(crc, buf, len) - uLong crc; - const Bytef *buf; - uInt len; -{ - if (buf == Z_NULL) return 0L; -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif - crc = crc ^ 0xffffffffL; - while (len >= 8) - { - DO8(buf); - len -= 8; - } - if (len) do { - DO1(buf); - } while (--len); - return crc ^ 0xffffffffL; -} diff --git a/zlib/deflate.c b/zlib/deflate.c deleted file mode 100755 index 7e57dff..0000000 --- a/zlib/deflate.c +++ /dev/null @@ -1,1350 +0,0 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in ftp://ds.internic.net/rfc/rfc1951.txt - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id$ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* =========================================================================== - * Function prototypes. - */ -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); -/* Compression function. Returns the block state after the call. */ - -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); -local block_state deflate_slow OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifdef ASMV - void match_init OF((void)); /* asm code initialization */ - uInt longest_match OF((deflate_state *s, IPos cur_match)); -#else -local uInt longest_match OF((deflate_state *s, IPos cur_match)); -#endif - -#ifdef DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); -#endif - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */ - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to to UPDATE_HASH are made with consecutive - * input characters, so that a running hash key can be computed from the - * previous key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to to INSERT_STRING are made with consecutive - * input characters and the first MIN_MATCH bytes of str are valid - * (except for the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - s->head[s->hash_size-1] = NIL; \ - zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); - -/* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ - deflate_state *s; - int noheader = 0; - static const char* my_version = ZLIB_VERSION; - - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == Z_NULL) { - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; - } - if (strm->zfree == Z_NULL) strm->zfree = zcfree; - - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#ifdef FASTEST - level = 1; -#endif - - if (windowBits < 0) { /* undocumented feature: suppress zlib header */ - noheader = 1; - windowBits = -windowBits; - } - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_HUFFMAN_ONLY) { - return Z_STREAM_ERROR; - } - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - - s->noheader = noheader; - s->w_bits = windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ - deflate_state *s; - uInt length = dictLength; - uInt n; - IPos hash_head = 0; - - if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || - strm->state->status != INIT_STATE) return Z_STREAM_ERROR; - - s = strm->state; - strm->adler = adler32(strm->adler, dictionary, dictLength); - - if (length < MIN_MATCH) return Z_OK; - if (length > MAX_DIST(s)) { - length = MAX_DIST(s); -#ifndef USE_DICT_HEAD - dictionary += dictLength - length; /* use the tail of the dictionary */ -#endif - } - zmemcpy(s->window, dictionary, length); - s->strstart = length; - s->block_start = (long)length; - - /* Insert all strings in the hash table (except for the last two bytes). - * s->lookahead stays null, so s->ins_h will be recomputed at the next - * call of fill_window. - */ - s->ins_h = s->window[0]; - UPDATE_HASH(s, s->ins_h, s->window[1]); - for (n = 0; n <= length - MIN_MATCH; n++) { - INSERT_STRING(s, n, hash_head); - } - if (hash_head) hash_head = 0; /* to make compiler happy */ - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset (strm) - z_streamp strm; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR; - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->noheader < 0) { - s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ - } - s->status = s->noheader ? BUSY_STATE : INIT_STATE; - strm->adler = 1; - s->last_flush = Z_NO_FLUSH; - - _tr_init(s); - lm_init(s); - - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ - deflate_state *s; - compress_func func; - int err = Z_OK; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - - if (level == Z_DEFAULT_COMPRESSION) { - level = 6; - } - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if (func != configuration_table[level].func && strm->total_in != 0) { - /* Flush the last buffer: */ - err = deflate(strm, Z_PARTIAL_FLUSH); - } - if (s->level != level) { - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return err; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB (s, b) - deflate_state *s; - uInt b; -{ - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output goes - * through this function so some applications may wish to modify it - * to avoid allocating a large strm->next_out buffer and copying into it. - * (See also read_buf()). - */ -local void flush_pending(strm) - z_streamp strm; -{ - unsigned len = strm->state->pending; - - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, strm->state->pending_out, len); - strm->next_out += len; - strm->state->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - strm->state->pending -= len; - if (strm->state->pending == 0) { - strm->state->pending_out = strm->state->pending_buf; - } -} - -/* ========================================================================= */ -int ZEXPORT deflate (strm, flush) - z_streamp strm; - int flush; -{ - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - flush > Z_FINISH || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - s->strm = strm; /* just in case */ - old_flush = s->last_flush; - s->last_flush = flush; - - /* Write the zlib header */ - if (s->status == INIT_STATE) { - - uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; - uInt level_flags = (s->level-1) >> 1; - - if (level_flags > 3) level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - s->status = BUSY_STATE; - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = 1L; - } - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUFF_ERROR. - */ - } else if (strm->avail_in == 0 && flush <= old_flush && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = (*(configuration_table[s->level].func))(s, flush); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - Assert(strm->avail_out > 0, "bug2"); - - if (flush != Z_FINISH) return Z_OK; - if (s->noheader) return Z_STREAM_END; - - /* Write the zlib trailer (adler32) */ - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - s->noheader = -1; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd (strm) - z_streamp strm; -{ - int status; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - - status = strm->state->status; - if (status != INIT_STATE && status != BUSY_STATE && - status != FINISH_STATE) { - return Z_STREAM_ERROR; - } - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ -#ifdef MAXSEG_64K - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - ushf *overlay; - - - if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - *dest = *source; - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - *ds = *ss; - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local int read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - if (!strm->state->noheader) { - strm->adler = adler32(strm->adler, strm->next_in, len); - } - zmemcpy(buf, strm->next_in, len); - strm->next_in += len; - strm->total_in += len; - - return (int)len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init (s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -#ifdef ASMV - match_init(); /* initialize the asm code */ -#endif -} - -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -#ifndef ASMV -/* For 80x86 and 680x0, an optimized version will be provided in match.asm or - * match.S. The code will be functionally equivalent. - */ -#ifndef FASTEST -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan+best_len-1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2: - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match+best_len-1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend-scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan+best_len-1); -#else - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} - -#else /* FASTEST */ -/* --------------------------------------------------------------------------- - * Optimized version for level == 1 only - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return len <= s->lookahead ? len : s->lookahead; -} -#endif /* FASTEST */ -#endif /* ASMV */ - -#ifdef DEBUG -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ - /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); - do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start-match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - register unsigned n, m; - register Posf *p; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if strstart == 0 - * and lookahead == 1 (input done one byte at time) - */ - more--; - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - } else if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - - /* Slide the hash table (could be avoided with 32 bit values - at the expense of memory usage). We slide even when level == 0 - to keep the hash table consistent if we switch back to level > 0 - later. (Using level 0 permanently is not an optimal usage of - zlib, so we don't care about this pathological case.) - */ - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - } while (--n); - - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif - more += wsize; - } - if (s->strm->avail_in == 0) return; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead >= MIN_MATCH) { - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); -} - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, eof) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (eof)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, eof) { \ - FLUSH_BLOCK_ONLY(s, eof); \ - if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \ -} - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * This function does not insert new strings in the dictionary since - * uncompressible data is probably not useful. This function is used - * only for the level=0 compression option. - * NOTE: this function should be optimized to avoid extra copying from - * window to pending_buf. - */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ - /* Stored blocks are limited to 0xffff bytes, pending_buf is limited - * to pending_buf_size, and each stored block has a 5 byte header: - */ - ulg max_block_size = 0xffff; - ulg max_start; - - if (max_block_size > s->pending_buf_size - 5) { - max_block_size = s->pending_buf_size - 5; - } - - /* Copy as much as possible from input to output: */ - for (;;) { - /* Fill the window as much as possible: */ - if (s->lookahead <= 1) { - - Assert(s->strstart < s->w_size+MAX_DIST(s) || - s->block_start >= (long)s->w_size, "slide too late"); - - fill_window(s); - if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; - - if (s->lookahead == 0) break; /* flush the current block */ - } - Assert(s->block_start >= 0L, "block gone"); - - s->strstart += s->lookahead; - s->lookahead = 0; - - /* Emit a stored block if pending_buf will be full: */ - max_start = s->block_start + max_block_size; - if (s->strstart == 0 || (ulg)s->strstart >= max_start) { - /* strstart == 0 is possible when wraparound on 16-bit machine */ - s->lookahead = (uInt)(s->strstart - max_start); - s->strstart = (uInt)max_start; - FLUSH_BLOCK(s, 0); - } - /* Flush if we may have to slide, otherwise block_start may become - * negative and the data will be gone: - */ - if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { - FLUSH_BLOCK(s, 0); - } - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head = NIL; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - if (s->strategy != Z_HUFFMAN_ONLY) { - s->match_length = longest_match (s, hash_head); - } - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in hash table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} - -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head = NIL; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - if (s->strategy != Z_HUFFMAN_ONLY) { - s->match_length = longest_match (s, hash_head); - } - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED || - (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR))) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart-1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart -1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart-1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length-1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - s->match_available = 0; - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} diff --git a/zlib/deflate.h b/zlib/deflate.h deleted file mode 100755 index b99a48a..0000000 --- a/zlib/deflate.h +++ /dev/null @@ -1,318 +0,0 @@ -/* deflate.h -- internal compression state - * Copyright (C) 1995-2002 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef _DEFLATE_H -#define _DEFLATE_H - -#include "zutil.h" - -/* =========================================================================== - * Internal compression state. - */ - -#define LENGTH_CODES 29 -/* number of length codes, not counting the special END_BLOCK code */ - -#define LITERALS 256 -/* number of literal bytes 0..255 */ - -#define L_CODES (LITERALS+1+LENGTH_CODES) -/* number of Literal or Length codes, including the END_BLOCK code */ - -#define D_CODES 30 -/* number of distance codes */ - -#define BL_CODES 19 -/* number of codes used to transfer the bit lengths */ - -#define HEAP_SIZE (2*L_CODES+1) -/* maximum heap size */ - -#define MAX_BITS 15 -/* All codes must not exceed MAX_BITS bits */ - -#define INIT_STATE 42 -#define BUSY_STATE 113 -#define FINISH_STATE 666 -/* Stream status */ - - -/* Data structure describing a single value and its code string. */ -typedef struct ct_data_s { - union { - ush freq; /* frequency count */ - ush code; /* bit string */ - } fc; - union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ - } dl; -} FAR ct_data; - -#define Freq fc.freq -#define Code fc.code -#define Dad dl.dad -#define Len dl.len - -typedef struct static_tree_desc_s static_tree_desc; - -typedef struct tree_desc_s { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - static_tree_desc *stat_desc; /* the corresponding static tree */ -} FAR tree_desc; - -typedef ush Pos; -typedef Pos FAR Posf; -typedef unsigned IPos; - -/* A Pos is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - -typedef struct internal_state { - z_streamp strm; /* pointer back to this zlib stream */ - int status; /* as the name implies */ - Bytef *pending_buf; /* output still pending */ - ulg pending_buf_size; /* size of pending_buf */ - Bytef *pending_out; /* next pending byte to output to the stream */ - int pending; /* nb of bytes in the pending buffer */ - int noheader; /* suppress zlib header and adler32 */ - Byte data_type; /* UNKNOWN, BINARY or ASCII */ - Byte method; /* STORED (for zip only) or DEFLATED */ - int last_flush; /* value of flush param for previous deflate call */ - - /* used by deflate.c: */ - - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - uInt w_mask; /* w_size - 1 */ - - Bytef *window; - /* Sliding window. Input bytes are read into the second half of the window, - * and move to the first half later to keep a dictionary of at least wSize - * bytes. With this organization, matches are limited to a distance of - * wSize-MAX_MATCH bytes, but this ensures that IO is always - * performed with a length multiple of the block size. Also, it limits - * the window size to 64K, which is quite useful on MSDOS. - * To do: use the user input buffer as sliding window. - */ - - ulg window_size; - /* Actual size of window: 2*wSize, except when the user input buffer - * is directly used as sliding window. - */ - - Posf *prev; - /* Link to older string with same hash index. To limit the size of this - * array to 64K, this link is maintained only for the last 32K strings. - * An index in this array is thus a window index modulo 32K. - */ - - Posf *head; /* Heads of the hash chains or NIL. */ - - uInt ins_h; /* hash index of string to be inserted */ - uInt hash_size; /* number of elements in hash table */ - uInt hash_bits; /* log2(hash_size) */ - uInt hash_mask; /* hash_size-1 */ - - uInt hash_shift; - /* Number of bits by which ins_h must be shifted at each input - * step. It must be such that after MIN_MATCH steps, the oldest - * byte no longer takes part in the hash key, that is: - * hash_shift * MIN_MATCH >= hash_bits - */ - - long block_start; - /* Window position at the beginning of the current output block. Gets - * negative when the window is moved backwards. - */ - - uInt match_length; /* length of best match */ - IPos prev_match; /* previous match */ - int match_available; /* set if previous match exists */ - uInt strstart; /* start of string to insert */ - uInt match_start; /* start of matching string */ - uInt lookahead; /* number of valid bytes ahead in window */ - - uInt prev_length; - /* Length of the best match at previous step. Matches not greater than this - * are discarded. This is used in the lazy match evaluation. - */ - - uInt max_chain_length; - /* To speed up deflation, hash chains are never searched beyond this - * length. A higher limit improves compression ratio but degrades the - * speed. - */ - - uInt max_lazy_match; - /* Attempt to find a better match only when the current match is strictly - * smaller than this value. This mechanism is used only for compression - * levels >= 4. - */ -# define max_insert_length max_lazy_match - /* Insert new strings in the hash table only if the match length is not - * greater than this length. This saves time but degrades compression. - * max_insert_length is used only for compression levels <= 3. - */ - - int level; /* compression level (1..9) */ - int strategy; /* favor or force Huffman coding*/ - - uInt good_match; - /* Use a faster search when the previous match is longer than this */ - - int nice_match; /* Stop searching when current match exceeds this */ - - /* used by trees.c: */ - /* Didn't use ct_data typedef below to supress compiler warning */ - struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ - struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ - struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ - - struct tree_desc_s l_desc; /* desc. for literal tree */ - struct tree_desc_s d_desc; /* desc. for distance tree */ - struct tree_desc_s bl_desc; /* desc. for bit length tree */ - - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - int heap_len; /* number of elements in the heap */ - int heap_max; /* element of largest frequency */ - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. - * The same heap array is used to build all trees. - */ - - uch depth[2*L_CODES+1]; - /* Depth of each subtree used as tie breaker for trees of equal frequency - */ - - uchf *l_buf; /* buffer for literals or lengths */ - - uInt lit_bufsize; - /* Size of match buffer for literals/lengths. There are 4 reasons for - * limiting lit_bufsize to 64K: - * - frequencies can be kept in 16 bit counters - * - if compression is not successful for the first block, all input - * data is still in the window so we can still emit a stored block even - * when input comes from standard input. (This can also be done for - * all blocks if lit_bufsize is not greater than 32K.) - * - if compression is not successful for a file smaller than 64K, we can - * even emit a stored file instead of a stored block (saving 5 bytes). - * This is applicable only for zip (not gzip or zlib). - * - creating new Huffman trees less frequently may not provide fast - * adaptation to changes in the input data statistics. (Take for - * example a binary file with poorly compressible code followed by - * a highly compressible string table.) Smaller buffer sizes give - * fast adaptation but have of course the overhead of transmitting - * trees more frequently. - * - I can't count above 4 - */ - - uInt last_lit; /* running index in l_buf */ - - ushf *d_buf; - /* Buffer for distances. To simplify the code, d_buf and l_buf have - * the same number of elements. To use different lengths, an extra flag - * array would be necessary. - */ - - ulg opt_len; /* bit length of current block with optimal trees */ - ulg static_len; /* bit length of current block with static trees */ - uInt matches; /* number of string matches in current block */ - int last_eob_len; /* bit length of EOB code for last block */ - -#ifdef DEBUG - ulg compressed_len; /* total bit length of compressed file mod 2^32 */ - ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ -#endif - - ush bi_buf; - /* Output buffer. bits are inserted starting at the bottom (least - * significant bits). - */ - int bi_valid; - /* Number of valid bits in bi_buf. All bits above the last valid bit - * are always zero. - */ - -} FAR deflate_state; - -/* Output a byte on the stream. - * IN assertion: there is enough room in pending_buf. - */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} - - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) -/* In order to simplify the code, particularly on 16 bit machines, match - * distances are limited to MAX_DIST instead of WSIZE. - */ - - /* in trees.c */ -void _tr_init OF((deflate_state *s)); -int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, - int eof)); -void _tr_align OF((deflate_state *s)); -void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, - int eof)); - -#define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -/* Mapping from a distance to a distance code. dist is the distance - 1 and - * must not have side effects. _dist_code[256] and _dist_code[257] are never - * used. - */ - -#ifndef DEBUG -/* Inline versions of _tr_tally for speed: */ - -#if defined(GEN_TREES_H) || !defined(STDC) - extern uch _length_code[]; - extern uch _dist_code[]; -#else - extern const uch _length_code[]; - extern const uch _dist_code[]; -#endif - -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (length); \ - ush dist = (distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -#else -# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) -# define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) -#endif - -#endif diff --git a/zlib/descrip.mms b/zlib/descrip.mms deleted file mode 100755 index b7abb68..0000000 Binary files a/zlib/descrip.mms and /dev/null differ diff --git a/zlib/example.c b/zlib/example.c deleted file mode 100755 index e7e3673..0000000 --- a/zlib/example.c +++ /dev/null @@ -1,556 +0,0 @@ -/* example.c -- usage example of the zlib compression library - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include -#include "zlib.h" - -#ifdef STDC -# include -# include -#else - extern void exit OF((int)); -#endif - -#if defined(VMS) || defined(RISCOS) -# define TESTFILE "foo-gz" -#else -# define TESTFILE "foo.gz" -#endif - -#define CHECK_ERR(err, msg) { \ - if (err != Z_OK) { \ - fprintf(stderr, "%s error: %d\n", msg, err); \ - exit(1); \ - } \ -} - -const char hello[] = "hello, hello!"; -/* "hello world" would be more standard, but the repeated "hello" - * stresses the compression code better, sorry... - */ - -const char dictionary[] = "hello"; -uLong dictId; /* Adler32 value of the dictionary */ - -void test_compress OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_gzio OF((const char *out, const char *in, - Byte *uncompr, int uncomprLen)); -void test_deflate OF((Byte *compr, uLong comprLen)); -void test_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_large_deflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_large_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_flush OF((Byte *compr, uLong *comprLen)); -void test_sync OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_dict_deflate OF((Byte *compr, uLong comprLen)); -void test_dict_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -int main OF((int argc, char *argv[])); - -/* =========================================================================== - * Test compress() and uncompress() - */ -void test_compress(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - uLong len = strlen(hello)+1; - - err = compress(compr, &comprLen, (const Bytef*)hello, len); - CHECK_ERR(err, "compress"); - - strcpy((char*)uncompr, "garbage"); - - err = uncompress(uncompr, &uncomprLen, compr, comprLen); - CHECK_ERR(err, "uncompress"); - - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad uncompress\n"); - exit(1); - } else { - printf("uncompress(): %s\n", (char *)uncompr); - } -} - -/* =========================================================================== - * Test read/write of .gz files - */ -void test_gzio(out, in, uncompr, uncomprLen) - const char *out; /* compressed output file */ - const char *in; /* compressed input file */ - Byte *uncompr; - int uncomprLen; -{ - int err; - int len = strlen(hello)+1; - gzFile file; - z_off_t pos; - - file = gzopen(out, "wb"); - if (file == NULL) { - fprintf(stderr, "gzopen error\n"); - exit(1); - } - gzputc(file, 'h'); - if (gzputs(file, "ello") != 4) { - fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); - exit(1); - } - if (gzprintf(file, ", %s!", "hello") != 8) { - fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); - exit(1); - } - gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ - gzclose(file); - - file = gzopen(in, "rb"); - if (file == NULL) { - fprintf(stderr, "gzopen error\n"); - } - strcpy((char*)uncompr, "garbage"); - - uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); - if (uncomprLen != len) { - fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); - exit(1); - } - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); - exit(1); - } else { - printf("gzread(): %s\n", (char *)uncompr); - } - - pos = gzseek(file, -8L, SEEK_CUR); - if (pos != 6 || gztell(file) != pos) { - fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", - (long)pos, (long)gztell(file)); - exit(1); - } - - if (gzgetc(file) != ' ') { - fprintf(stderr, "gzgetc error\n"); - exit(1); - } - - gzgets(file, (char*)uncompr, uncomprLen); - uncomprLen = strlen((char*)uncompr); - if (uncomprLen != 6) { /* "hello!" */ - fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); - exit(1); - } - if (strcmp((char*)uncompr, hello+7)) { - fprintf(stderr, "bad gzgets after gzseek\n"); - exit(1); - } else { - printf("gzgets() after gzseek: %s\n", (char *)uncompr); - } - - gzclose(file); -} - -/* =========================================================================== - * Test deflate() with small buffers - */ -void test_deflate(compr, comprLen) - Byte *compr; - uLong comprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - int len = strlen(hello)+1; - - c_stream.zalloc = (alloc_func)0; - c_stream.zfree = (free_func)0; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); - CHECK_ERR(err, "deflateInit"); - - c_stream.next_in = (Bytef*)hello; - c_stream.next_out = compr; - - while (c_stream.total_in != (uLong)len && c_stream.total_out < comprLen) { - c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - } - /* Finish the stream, still forcing small buffers: */ - for (;;) { - c_stream.avail_out = 1; - err = deflate(&c_stream, Z_FINISH); - if (err == Z_STREAM_END) break; - CHECK_ERR(err, "deflate"); - } - - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); -} - -/* =========================================================================== - * Test inflate() with small buffers - */ -void test_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = (alloc_func)0; - d_stream.zfree = (free_func)0; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = 0; - d_stream.next_out = uncompr; - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { - d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ - err = inflate(&d_stream, Z_NO_FLUSH); - if (err == Z_STREAM_END) break; - CHECK_ERR(err, "inflate"); - } - - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad inflate\n"); - exit(1); - } else { - printf("inflate(): %s\n", (char *)uncompr); - } -} - -/* =========================================================================== - * Test deflate() with large buffers and dynamic change of compression level - */ -void test_large_deflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - - c_stream.zalloc = (alloc_func)0; - c_stream.zfree = (free_func)0; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_BEST_SPEED); - CHECK_ERR(err, "deflateInit"); - - c_stream.next_out = compr; - c_stream.avail_out = (uInt)comprLen; - - /* At this point, uncompr is still mostly zeroes, so it should compress - * very well: - */ - c_stream.next_in = uncompr; - c_stream.avail_in = (uInt)uncomprLen; - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - if (c_stream.avail_in != 0) { - fprintf(stderr, "deflate not greedy\n"); - exit(1); - } - - /* Feed in already compressed data and switch to no compression: */ - deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); - c_stream.next_in = compr; - c_stream.avail_in = (uInt)comprLen/2; - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - - /* Switch back to compressing mode: */ - deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED); - c_stream.next_in = uncompr; - c_stream.avail_in = (uInt)uncomprLen; - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - - err = deflate(&c_stream, Z_FINISH); - if (err != Z_STREAM_END) { - fprintf(stderr, "deflate should report Z_STREAM_END\n"); - exit(1); - } - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); -} - -/* =========================================================================== - * Test inflate() with large buffers - */ -void test_large_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = (alloc_func)0; - d_stream.zfree = (free_func)0; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = (uInt)comprLen; - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - for (;;) { - d_stream.next_out = uncompr; /* discard the output */ - d_stream.avail_out = (uInt)uncomprLen; - err = inflate(&d_stream, Z_NO_FLUSH); - if (err == Z_STREAM_END) break; - CHECK_ERR(err, "large inflate"); - } - - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - if (d_stream.total_out != 2*uncomprLen + comprLen/2) { - fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); - exit(1); - } else { - printf("large_inflate(): OK\n"); - } -} - -/* =========================================================================== - * Test deflate() with full flush - */ -void test_flush(compr, comprLen) - Byte *compr; - uLong *comprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - int len = strlen(hello)+1; - - c_stream.zalloc = (alloc_func)0; - c_stream.zfree = (free_func)0; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); - CHECK_ERR(err, "deflateInit"); - - c_stream.next_in = (Bytef*)hello; - c_stream.next_out = compr; - c_stream.avail_in = 3; - c_stream.avail_out = (uInt)*comprLen; - err = deflate(&c_stream, Z_FULL_FLUSH); - CHECK_ERR(err, "deflate"); - - compr[3]++; /* force an error in first compressed block */ - c_stream.avail_in = len - 3; - - err = deflate(&c_stream, Z_FINISH); - if (err != Z_STREAM_END) { - CHECK_ERR(err, "deflate"); - } - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); - - *comprLen = c_stream.total_out; -} - -/* =========================================================================== - * Test inflateSync() - */ -void test_sync(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = (alloc_func)0; - d_stream.zfree = (free_func)0; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = 2; /* just read the zlib header */ - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - d_stream.next_out = uncompr; - d_stream.avail_out = (uInt)uncomprLen; - - inflate(&d_stream, Z_NO_FLUSH); - CHECK_ERR(err, "inflate"); - - d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */ - err = inflateSync(&d_stream); /* but skip the damaged part */ - CHECK_ERR(err, "inflateSync"); - - err = inflate(&d_stream, Z_FINISH); - if (err != Z_DATA_ERROR) { - fprintf(stderr, "inflate should report DATA_ERROR\n"); - /* Because of incorrect adler32 */ - exit(1); - } - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - printf("after inflateSync(): hel%s\n", (char *)uncompr); -} - -/* =========================================================================== - * Test deflate() with preset dictionary - */ -void test_dict_deflate(compr, comprLen) - Byte *compr; - uLong comprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - - c_stream.zalloc = (alloc_func)0; - c_stream.zfree = (free_func)0; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_BEST_COMPRESSION); - CHECK_ERR(err, "deflateInit"); - - err = deflateSetDictionary(&c_stream, - (const Bytef*)dictionary, sizeof(dictionary)); - CHECK_ERR(err, "deflateSetDictionary"); - - dictId = c_stream.adler; - c_stream.next_out = compr; - c_stream.avail_out = (uInt)comprLen; - - c_stream.next_in = (Bytef*)hello; - c_stream.avail_in = (uInt)strlen(hello)+1; - - err = deflate(&c_stream, Z_FINISH); - if (err != Z_STREAM_END) { - fprintf(stderr, "deflate should report Z_STREAM_END\n"); - exit(1); - } - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); -} - -/* =========================================================================== - * Test inflate() with a preset dictionary - */ -void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = (alloc_func)0; - d_stream.zfree = (free_func)0; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = (uInt)comprLen; - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - d_stream.next_out = uncompr; - d_stream.avail_out = (uInt)uncomprLen; - - for (;;) { - err = inflate(&d_stream, Z_NO_FLUSH); - if (err == Z_STREAM_END) break; - if (err == Z_NEED_DICT) { - if (d_stream.adler != dictId) { - fprintf(stderr, "unexpected dictionary"); - exit(1); - } - err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, - sizeof(dictionary)); - } - CHECK_ERR(err, "inflate with dict"); - } - - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad inflate with dict\n"); - exit(1); - } else { - printf("inflate with dictionary: %s\n", (char *)uncompr); - } -} - -/* =========================================================================== - * Usage: example [output.gz [input.gz]] - */ - -int main(argc, argv) - int argc; - char *argv[]; -{ - Byte *compr, *uncompr; - uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ - uLong uncomprLen = comprLen; - static const char* myVersion = ZLIB_VERSION; - - if (zlibVersion()[0] != myVersion[0]) { - fprintf(stderr, "incompatible zlib version\n"); - exit(1); - - } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { - fprintf(stderr, "warning: different zlib version\n"); - } - - compr = (Byte*)calloc((uInt)comprLen, 1); - uncompr = (Byte*)calloc((uInt)uncomprLen, 1); - /* compr and uncompr are cleared to avoid reading uninitialized - * data and to ensure that uncompr compresses well. - */ - if (compr == Z_NULL || uncompr == Z_NULL) { - printf("out of memory\n"); - exit(1); - } - test_compress(compr, comprLen, uncompr, uncomprLen); - - test_gzio((argc > 1 ? argv[1] : TESTFILE), - (argc > 2 ? argv[2] : TESTFILE), - uncompr, (int)uncomprLen); - - test_deflate(compr, comprLen); - test_inflate(compr, comprLen, uncompr, uncomprLen); - - test_large_deflate(compr, comprLen, uncompr, uncomprLen); - test_large_inflate(compr, comprLen, uncompr, uncomprLen); - - test_flush(compr, &comprLen); - test_sync(compr, comprLen, uncompr, uncomprLen); - comprLen = uncomprLen; - - test_dict_deflate(compr, comprLen); - test_dict_inflate(compr, comprLen, uncompr, uncomprLen); - - exit(0); - return 0; /* to avoid warning */ -} diff --git a/zlib/gzio.c b/zlib/gzio.c deleted file mode 100755 index 09e0a20..0000000 --- a/zlib/gzio.c +++ /dev/null @@ -1,875 +0,0 @@ -/* gzio.c -- IO on .gz files - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Compile this file with -DNO_DEFLATE to avoid the compression code. - */ - -/* @(#) $Id$ */ - -#include - -#include "zutil.h" - -struct internal_state {int dummy;}; /* for buggy compilers */ - -#ifndef Z_BUFSIZE -# ifdef MAXSEG_64K -# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */ -# else -# define Z_BUFSIZE 16384 -# endif -#endif -#ifndef Z_PRINTF_BUFSIZE -# define Z_PRINTF_BUFSIZE 4096 -#endif - -#define ALLOC(size) malloc(size) -#define TRYFREE(p) {if (p) free(p);} - -static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ - -/* gzip flag byte */ -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ -#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define COMMENT 0x10 /* bit 4 set: file comment present */ -#define RESERVED 0xE0 /* bits 5..7: reserved */ - -typedef struct gz_stream { - z_stream stream; - int z_err; /* error code for last stream operation */ - int z_eof; /* set if end of input file */ - FILE *file; /* .gz file */ - Byte *inbuf; /* input buffer */ - Byte *outbuf; /* output buffer */ - uLong crc; /* crc32 of uncompressed data */ - char *msg; /* error message */ - char *path; /* path name for debugging only */ - int transparent; /* 1 if input file is not a .gz file */ - char mode; /* 'w' or 'r' */ - long startpos; /* start of compressed data in file (header skipped) */ -} gz_stream; - - -local gzFile gz_open OF((const char *path, const char *mode, int fd)); -local int do_flush OF((gzFile file, int flush)); -local int get_byte OF((gz_stream *s)); -local void check_header OF((gz_stream *s)); -local int destroy OF((gz_stream *s)); -local void putLong OF((FILE *file, uLong x)); -local uLong getLong OF((gz_stream *s)); - -/* =========================================================================== - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb"). The file is given either by file descriptor - or path name (if fd == -1). - gz_open return NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). -*/ -local gzFile gz_open (path, mode, fd) - const char *path; - const char *mode; - int fd; -{ - int err; - int level = Z_DEFAULT_COMPRESSION; /* compression level */ - int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ - char *p = (char*)mode; - gz_stream *s; - char fmode[80]; /* copy of mode, without the compression level */ - char *m = fmode; - - if (!path || !mode) return Z_NULL; - - s = (gz_stream *)ALLOC(sizeof(gz_stream)); - if (!s) return Z_NULL; - - s->stream.zalloc = (alloc_func)0; - s->stream.zfree = (free_func)0; - s->stream.opaque = (voidpf)0; - s->stream.next_in = s->inbuf = Z_NULL; - s->stream.next_out = s->outbuf = Z_NULL; - s->stream.avail_in = s->stream.avail_out = 0; - s->file = NULL; - s->z_err = Z_OK; - s->z_eof = 0; - s->crc = crc32(0L, Z_NULL, 0); - s->msg = NULL; - s->transparent = 0; - - s->path = (char*)ALLOC(strlen(path)+1); - if (s->path == NULL) { - return destroy(s), (gzFile)Z_NULL; - } - strcpy(s->path, path); /* do this early for debugging */ - - s->mode = '\0'; - do { - if (*p == 'r') s->mode = 'r'; - if (*p == 'w' || *p == 'a') s->mode = 'w'; - if (*p >= '0' && *p <= '9') { - level = *p - '0'; - } else if (*p == 'f') { - strategy = Z_FILTERED; - } else if (*p == 'h') { - strategy = Z_HUFFMAN_ONLY; - } else { - *m++ = *p; /* copy the mode */ - } - } while (*p++ && m != fmode + sizeof(fmode)); - if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; - - if (s->mode == 'w') { -#ifdef NO_DEFLATE - err = Z_STREAM_ERROR; -#else - err = deflateInit2(&(s->stream), level, - Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy); - /* windowBits is passed < 0 to suppress zlib header */ - - s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); -#endif - if (err != Z_OK || s->outbuf == Z_NULL) { - return destroy(s), (gzFile)Z_NULL; - } - } else { - s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); - - err = inflateInit2(&(s->stream), -MAX_WBITS); - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are - * present after the compressed stream. - */ - if (err != Z_OK || s->inbuf == Z_NULL) { - return destroy(s), (gzFile)Z_NULL; - } - } - s->stream.avail_out = Z_BUFSIZE; - - errno = 0; - s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); - - if (s->file == NULL) { - return destroy(s), (gzFile)Z_NULL; - } - if (s->mode == 'w') { - /* Write a very simple .gz header: - */ - fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], - Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); - s->startpos = 10L; - /* We use 10L instead of ftell(s->file) to because ftell causes an - * fflush on some systems. This version of the library doesn't use - * startpos anyway in write mode, so this initialization is not - * necessary. - */ - } else { - check_header(s); /* skip the .gz header */ - s->startpos = (ftell(s->file) - s->stream.avail_in); - } - - return (gzFile)s; -} - -/* =========================================================================== - Opens a gzip (.gz) file for reading or writing. -*/ -gzFile ZEXPORT gzopen (path, mode) - const char *path; - const char *mode; -{ - return gz_open (path, mode, -1); -} - -/* =========================================================================== - Associate a gzFile with the file descriptor fd. fd is not dup'ed here - to mimic the behavio(u)r of fdopen. -*/ -gzFile ZEXPORT gzdopen (fd, mode) - int fd; - const char *mode; -{ - char name[20]; - - if (fd < 0) return (gzFile)Z_NULL; - sprintf(name, "", fd); /* for debugging */ - - return gz_open (name, mode, fd); -} - -/* =========================================================================== - * Update the compression level and strategy - */ -int ZEXPORT gzsetparams (file, level, strategy) - gzFile file; - int level; - int strategy; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; - - /* Make room to allow flushing */ - if (s->stream.avail_out == 0) { - - s->stream.next_out = s->outbuf; - if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { - s->z_err = Z_ERRNO; - } - s->stream.avail_out = Z_BUFSIZE; - } - - return deflateParams (&(s->stream), level, strategy); -} - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ -local int get_byte(s) - gz_stream *s; -{ - if (s->z_eof) return EOF; - if (s->stream.avail_in == 0) { - errno = 0; - s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); - if (s->stream.avail_in == 0) { - s->z_eof = 1; - if (ferror(s->file)) s->z_err = Z_ERRNO; - return EOF; - } - s->stream.next_in = s->inbuf; - } - s->stream.avail_in--; - return *(s->stream.next_in)++; -} - -/* =========================================================================== - Check the gzip header of a gz_stream opened for reading. Set the stream - mode to transparent if the gzip magic header is not present; set s->err - to Z_DATA_ERROR if the magic header is present but the rest of the header - is incorrect. - IN assertion: the stream s has already been created sucessfully; - s->stream.avail_in is zero for the first time, but may be non-zero - for concatenated .gz files. -*/ -local void check_header(s) - gz_stream *s; -{ - int method; /* method byte */ - int flags; /* flags byte */ - uInt len; - int c; - - /* Check the gzip magic header */ - for (len = 0; len < 2; len++) { - c = get_byte(s); - if (c != gz_magic[len]) { - if (len != 0) s->stream.avail_in++, s->stream.next_in--; - if (c != EOF) { - s->stream.avail_in++, s->stream.next_in--; - s->transparent = 1; - } - s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END; - return; - } - } - method = get_byte(s); - flags = get_byte(s); - if (method != Z_DEFLATED || (flags & RESERVED) != 0) { - s->z_err = Z_DATA_ERROR; - return; - } - - /* Discard time, xflags and OS code: */ - for (len = 0; len < 6; len++) (void)get_byte(s); - - if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ - len = (uInt)get_byte(s); - len += ((uInt)get_byte(s))<<8; - /* len is garbage if EOF but the loop below will quit anyway */ - while (len-- != 0 && get_byte(s) != EOF) ; - } - if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ - while ((c = get_byte(s)) != 0 && c != EOF) ; - } - if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ - while ((c = get_byte(s)) != 0 && c != EOF) ; - } - if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ - for (len = 0; len < 2; len++) (void)get_byte(s); - } - s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; -} - - /* =========================================================================== - * Cleanup then free the given gz_stream. Return a zlib error code. - Try freeing in the reverse order of allocations. - */ -local int destroy (s) - gz_stream *s; -{ - int err = Z_OK; - - if (!s) return Z_STREAM_ERROR; - - TRYFREE(s->msg); - - if (s->stream.state != NULL) { - if (s->mode == 'w') { -#ifdef NO_DEFLATE - err = Z_STREAM_ERROR; -#else - err = deflateEnd(&(s->stream)); -#endif - } else if (s->mode == 'r') { - err = inflateEnd(&(s->stream)); - } - } - if (s->file != NULL && fclose(s->file)) { -#ifdef ESPIPE - if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ -#endif - err = Z_ERRNO; - } - if (s->z_err < 0) err = s->z_err; - - TRYFREE(s->inbuf); - TRYFREE(s->outbuf); - TRYFREE(s->path); - TRYFREE(s); - return err; -} - -/* =========================================================================== - Reads the given number of uncompressed bytes from the compressed file. - gzread returns the number of bytes actually read (0 for end of file). -*/ -int ZEXPORT gzread (file, buf, len) - gzFile file; - voidp buf; - unsigned len; -{ - gz_stream *s = (gz_stream*)file; - Bytef *start = (Bytef*)buf; /* starting point for crc computation */ - Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ - - if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; - - if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; - if (s->z_err == Z_STREAM_END) return 0; /* EOF */ - - next_out = (Byte*)buf; - s->stream.next_out = (Bytef*)buf; - s->stream.avail_out = len; - - while (s->stream.avail_out != 0) { - - if (s->transparent) { - /* Copy first the lookahead bytes: */ - uInt n = s->stream.avail_in; - if (n > s->stream.avail_out) n = s->stream.avail_out; - if (n > 0) { - zmemcpy(s->stream.next_out, s->stream.next_in, n); - next_out += n; - s->stream.next_out = next_out; - s->stream.next_in += n; - s->stream.avail_out -= n; - s->stream.avail_in -= n; - } - if (s->stream.avail_out > 0) { - s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out, - s->file); - } - len -= s->stream.avail_out; - s->stream.total_in += (uLong)len; - s->stream.total_out += (uLong)len; - if (len == 0) s->z_eof = 1; - return (int)len; - } - if (s->stream.avail_in == 0 && !s->z_eof) { - - errno = 0; - s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); - if (s->stream.avail_in == 0) { - s->z_eof = 1; - if (ferror(s->file)) { - s->z_err = Z_ERRNO; - break; - } - } - s->stream.next_in = s->inbuf; - } - s->z_err = inflate(&(s->stream), Z_NO_FLUSH); - - if (s->z_err == Z_STREAM_END) { - /* Check CRC and original size */ - s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); - start = s->stream.next_out; - - if (getLong(s) != s->crc) { - s->z_err = Z_DATA_ERROR; - } else { - (void)getLong(s); - /* The uncompressed length returned by above getlong() may - * be different from s->stream.total_out) in case of - * concatenated .gz files. Check for such files: - */ - check_header(s); - if (s->z_err == Z_OK) { - uLong total_in = s->stream.total_in; - uLong total_out = s->stream.total_out; - - inflateReset(&(s->stream)); - s->stream.total_in = total_in; - s->stream.total_out = total_out; - s->crc = crc32(0L, Z_NULL, 0); - } - } - } - if (s->z_err != Z_OK || s->z_eof) break; - } - s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); - - return (int)(len - s->stream.avail_out); -} - - -/* =========================================================================== - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ -int ZEXPORT gzgetc(file) - gzFile file; -{ - unsigned char c; - - return gzread(file, &c, 1) == 1 ? c : -1; -} - - -/* =========================================================================== - Reads bytes from the compressed file until len-1 characters are - read, or a newline character is read and transferred to buf, or an - end-of-file condition is encountered. The string is then terminated - with a null character. - gzgets returns buf, or Z_NULL in case of error. - - The current implementation is not optimized at all. -*/ -char * ZEXPORT gzgets(file, buf, len) - gzFile file; - char *buf; - int len; -{ - char *b = buf; - if (buf == Z_NULL || len <= 0) return Z_NULL; - - while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ; - *buf = '\0'; - return b == buf && len > 0 ? Z_NULL : b; -} - - -#ifndef NO_DEFLATE -/* =========================================================================== - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of bytes actually written (0 in case of error). -*/ -int ZEXPORT gzwrite (file, buf, len) - gzFile file; - const voidp buf; - unsigned len; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; - - s->stream.next_in = (Bytef*)buf; - s->stream.avail_in = len; - - while (s->stream.avail_in != 0) { - - if (s->stream.avail_out == 0) { - - s->stream.next_out = s->outbuf; - if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { - s->z_err = Z_ERRNO; - break; - } - s->stream.avail_out = Z_BUFSIZE; - } - s->z_err = deflate(&(s->stream), Z_NO_FLUSH); - if (s->z_err != Z_OK) break; - } - s->crc = crc32(s->crc, (const Bytef *)buf, len); - - return (int)(len - s->stream.avail_in); -} - -/* =========================================================================== - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). -*/ -#ifdef STDC -#include - -int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) -{ - char buf[Z_PRINTF_BUFSIZE]; - va_list va; - int len; - - va_start(va, format); -#ifdef HAS_vsnprintf - (void)vsnprintf(buf, sizeof(buf), format, va); -#else - (void)vsprintf(buf, format, va); -#endif - va_end(va); - len = strlen(buf); /* some *sprintf don't return the nb of bytes written */ - if (len <= 0) return 0; - - return gzwrite(file, buf, (unsigned)len); -} -#else /* not ANSI C */ - -int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) - gzFile file; - const char *format; - int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -{ - char buf[Z_PRINTF_BUFSIZE]; - int len; - -#ifdef HAS_snprintf - snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); -#else - sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); -#endif - len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */ - if (len <= 0) return 0; - - return gzwrite(file, buf, len); -} -#endif - -/* =========================================================================== - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ -int ZEXPORT gzputc(file, c) - gzFile file; - int c; -{ - unsigned char cc = (unsigned char) c; /* required for big endian systems */ - - return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1; -} - - -/* =========================================================================== - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ -int ZEXPORT gzputs(file, s) - gzFile file; - const char *s; -{ - return gzwrite(file, (char*)s, (unsigned)strlen(s)); -} - - -/* =========================================================================== - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. -*/ -local int do_flush (file, flush) - gzFile file; - int flush; -{ - uInt len; - int done = 0; - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; - - s->stream.avail_in = 0; /* should be zero already anyway */ - - for (;;) { - len = Z_BUFSIZE - s->stream.avail_out; - - if (len != 0) { - if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) { - s->z_err = Z_ERRNO; - return Z_ERRNO; - } - s->stream.next_out = s->outbuf; - s->stream.avail_out = Z_BUFSIZE; - } - if (done) break; - s->z_err = deflate(&(s->stream), flush); - - /* Ignore the second of two consecutive flushes: */ - if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; - - /* deflate has finished flushing only when it hasn't used up - * all the available space in the output buffer: - */ - done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END); - - if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; - } - return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; -} - -int ZEXPORT gzflush (file, flush) - gzFile file; - int flush; -{ - gz_stream *s = (gz_stream*)file; - int err = do_flush (file, flush); - - if (err) return err; - fflush(s->file); - return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; -} -#endif /* NO_DEFLATE */ - -/* =========================================================================== - Sets the starting position for the next gzread or gzwrite on the given - compressed file. The offset represents a number of bytes in the - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error. - SEEK_END is not implemented, returns error. - In this version of the library, gzseek can be extremely slow. -*/ -z_off_t ZEXPORT gzseek (file, offset, whence) - gzFile file; - z_off_t offset; - int whence; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || whence == SEEK_END || - s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) { - return -1L; - } - - if (s->mode == 'w') { -#ifdef NO_DEFLATE - return -1L; -#else - if (whence == SEEK_SET) { - offset -= s->stream.total_in; - } - if (offset < 0) return -1L; - - /* At this point, offset is the number of zero bytes to write. */ - if (s->inbuf == Z_NULL) { - s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ - zmemzero(s->inbuf, Z_BUFSIZE); - } - while (offset > 0) { - uInt size = Z_BUFSIZE; - if (offset < Z_BUFSIZE) size = (uInt)offset; - - size = gzwrite(file, s->inbuf, size); - if (size == 0) return -1L; - - offset -= size; - } - return (z_off_t)s->stream.total_in; -#endif - } - /* Rest of function is for reading only */ - - /* compute absolute position */ - if (whence == SEEK_CUR) { - offset += s->stream.total_out; - } - if (offset < 0) return -1L; - - if (s->transparent) { - /* map to fseek */ - s->stream.avail_in = 0; - s->stream.next_in = s->inbuf; - if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; - - s->stream.total_in = s->stream.total_out = (uLong)offset; - return offset; - } - - /* For a negative seek, rewind and use positive seek */ - if ((uLong)offset >= s->stream.total_out) { - offset -= s->stream.total_out; - } else if (gzrewind(file) < 0) { - return -1L; - } - /* offset is now the number of bytes to skip. */ - - if (offset != 0 && s->outbuf == Z_NULL) { - s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); - } - while (offset > 0) { - int size = Z_BUFSIZE; - if (offset < Z_BUFSIZE) size = (int)offset; - - size = gzread(file, s->outbuf, (uInt)size); - if (size <= 0) return -1L; - offset -= size; - } - return (z_off_t)s->stream.total_out; -} - -/* =========================================================================== - Rewinds input file. -*/ -int ZEXPORT gzrewind (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - if (s == NULL || s->mode != 'r') return -1; - - s->z_err = Z_OK; - s->z_eof = 0; - s->stream.avail_in = 0; - s->stream.next_in = s->inbuf; - s->crc = crc32(0L, Z_NULL, 0); - - if (s->startpos == 0) { /* not a compressed file */ - rewind(s->file); - return 0; - } - - (void) inflateReset(&s->stream); - return fseek(s->file, s->startpos, SEEK_SET); -} - -/* =========================================================================== - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. -*/ -z_off_t ZEXPORT gztell (file) - gzFile file; -{ - return gzseek(file, 0L, SEEK_CUR); -} - -/* =========================================================================== - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ -int ZEXPORT gzeof (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - return (s == NULL || s->mode != 'r') ? 0 : s->z_eof; -} - -/* =========================================================================== - Outputs a long in LSB order to the given file -*/ -local void putLong (file, x) - FILE *file; - uLong x; -{ - int n; - for (n = 0; n < 4; n++) { - fputc((int)(x & 0xff), file); - x >>= 8; - } -} - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets z_err in case - of error. -*/ -local uLong getLong (s) - gz_stream *s; -{ - uLong x = (uLong)get_byte(s); - int c; - - x += ((uLong)get_byte(s))<<8; - x += ((uLong)get_byte(s))<<16; - c = get_byte(s); - if (c == EOF) s->z_err = Z_DATA_ERROR; - x += ((uLong)c)<<24; - return x; -} - -/* =========================================================================== - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. -*/ -int ZEXPORT gzclose (file) - gzFile file; -{ - int err; - gz_stream *s = (gz_stream*)file; - - if (s == NULL) return Z_STREAM_ERROR; - - if (s->mode == 'w') { -#ifdef NO_DEFLATE - return Z_STREAM_ERROR; -#else - err = do_flush (file, Z_FINISH); - if (err != Z_OK) return destroy((gz_stream*)file); - - putLong (s->file, s->crc); - putLong (s->file, s->stream.total_in); -#endif - } - return destroy((gz_stream*)file); -} - -/* =========================================================================== - Returns the error message for the last error which occured on the - given compressed file. errnum is set to zlib error number. If an - error occured in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ -const char* ZEXPORT gzerror (file, errnum) - gzFile file; - int *errnum; -{ - char *m; - gz_stream *s = (gz_stream*)file; - - if (s == NULL) { - *errnum = Z_STREAM_ERROR; - return (const char*)ERR_MSG(Z_STREAM_ERROR); - } - *errnum = s->z_err; - if (*errnum == Z_OK) return (const char*)""; - - m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); - - if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); - - TRYFREE(s->msg); - s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); - strcpy(s->msg, s->path); - strcat(s->msg, ": "); - strcat(s->msg, m); - return (const char*)s->msg; -} diff --git a/zlib/infblock.c b/zlib/infblock.c deleted file mode 100755 index dd7a6d4..0000000 --- a/zlib/infblock.c +++ /dev/null @@ -1,403 +0,0 @@ -/* infblock.c -- interpret and process block types to last block - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infblock.h" -#include "inftrees.h" -#include "infcodes.h" -#include "infutil.h" - -struct inflate_codes_state {int dummy;}; /* for buggy compilers */ - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -/* Table for deflate from PKZIP's appnote.txt. */ -local const uInt border[] = { /* Order of the bit length code lengths */ - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - -/* - Notes beyond the 1.93a appnote.txt: - - 1. Distance pointers never point before the beginning of the output - stream. - 2. Distance pointers can point back across blocks, up to 32k away. - 3. There is an implied maximum of 7 bits for the bit length table and - 15 bits for the actual data. - 4. If only one code exists, then it is encoded using one bit. (Zero - would be more efficient, but perhaps a little confusing.) If two - codes exist, they are coded using one bit each (0 and 1). - 5. There is no way of sending zero distance codes--a dummy must be - sent if there are none. (History: a pre 2.0 version of PKZIP would - store blocks with no distance codes, but this was discovered to be - too harsh a criterion.) Valid only for 1.93a. 2.04c does allow - zero distance codes, which is sent as one code of zero bits in - length. - 6. There are up to 286 literal/length codes. Code 256 represents the - end-of-block. Note however that the static length tree defines - 288 codes just to fill out the Huffman codes. Codes 286 and 287 - cannot be used though, since there is no length base or extra bits - defined for them. Similarily, there are up to 30 distance codes. - However, static trees define 32 codes (all 5 bits) to fill out the - Huffman codes, but the last two had better not show up in the data. - 7. Unzip can check dynamic Huffman blocks for complete code sets. - The exception is that a single code would not be complete (see #4). - 8. The five bits following the block type is really the number of - literal codes sent minus 257. - 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits - (1+6+6). Therefore, to output three times the length, you output - three codes (1+1+1), whereas to output four times the same length, - you only need two codes (1+3). Hmm. - 10. In the tree reconstruction algorithm, Code = Code + Increment - only if BitLength(i) is not zero. (Pretty obvious.) - 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19) - 12. Note: length code 284 can represent 227-258, but length code 285 - really is 258. The last length deserves its own, short code - since it gets used a lot in very redundant files. The length - 258 is special since 258 - 3 (the min match length) is 255. - 13. The literal/length and distance code bit lengths are read as a - single stream of lengths. It is possible (and advantageous) for - a repeat code (16, 17, or 18) to go across the boundary between - the two sets of lengths. - */ - - -void inflate_blocks_reset(s, z, c) -inflate_blocks_statef *s; -z_streamp z; -uLongf *c; -{ - if (c != Z_NULL) - *c = s->check; - if (s->mode == BTREE || s->mode == DTREE) - ZFREE(z, s->sub.trees.blens); - if (s->mode == CODES) - inflate_codes_free(s->sub.decode.codes, z); - s->mode = TYPE; - s->bitk = 0; - s->bitb = 0; - s->read = s->write = s->window; - if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); - Tracev((stderr, "inflate: blocks reset\n")); -} - - -inflate_blocks_statef *inflate_blocks_new(z, c, w) -z_streamp z; -check_func c; -uInt w; -{ - inflate_blocks_statef *s; - - if ((s = (inflate_blocks_statef *)ZALLOC - (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) - return s; - if ((s->hufts = - (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL) - { - ZFREE(z, s); - return Z_NULL; - } - if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) - { - ZFREE(z, s->hufts); - ZFREE(z, s); - return Z_NULL; - } - s->end = s->window + w; - s->checkfn = c; - s->mode = TYPE; - Tracev((stderr, "inflate: blocks allocated\n")); - inflate_blocks_reset(s, z, Z_NULL); - return s; -} - - -int inflate_blocks(s, z, r) -inflate_blocks_statef *s; -z_streamp z; -int r; -{ - uInt t; /* temporary storage */ - uLong b; /* bit buffer */ - uInt k; /* bits in bit buffer */ - Bytef *p; /* input data pointer */ - uInt n; /* bytes available there */ - Bytef *q; /* output window write pointer */ - uInt m; /* bytes to end of window or read pointer */ - - /* copy input/output information to locals (UPDATE macro restores) */ - LOAD - - /* process input based on current state */ - while (1) switch (s->mode) - { - case TYPE: - NEEDBITS(3) - t = (uInt)b & 7; - s->last = t & 1; - switch (t >> 1) - { - case 0: /* stored */ - Tracev((stderr, "inflate: stored block%s\n", - s->last ? " (last)" : "")); - DUMPBITS(3) - t = k & 7; /* go to byte boundary */ - DUMPBITS(t) - s->mode = LENS; /* get length of stored block */ - break; - case 1: /* fixed */ - Tracev((stderr, "inflate: fixed codes block%s\n", - s->last ? " (last)" : "")); - { - uInt bl, bd; - inflate_huft *tl, *td; - - inflate_trees_fixed(&bl, &bd, &tl, &td, z); - s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z); - if (s->sub.decode.codes == Z_NULL) - { - r = Z_MEM_ERROR; - LEAVE - } - } - DUMPBITS(3) - s->mode = CODES; - break; - case 2: /* dynamic */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - s->last ? " (last)" : "")); - DUMPBITS(3) - s->mode = TABLE; - break; - case 3: /* illegal */ - DUMPBITS(3) - s->mode = BAD; - z->msg = (char*)"invalid block type"; - r = Z_DATA_ERROR; - LEAVE - } - break; - case LENS: - NEEDBITS(32) - if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) - { - s->mode = BAD; - z->msg = (char*)"invalid stored block lengths"; - r = Z_DATA_ERROR; - LEAVE - } - s->sub.left = (uInt)b & 0xffff; - b = k = 0; /* dump bits */ - Tracev((stderr, "inflate: stored length %u\n", s->sub.left)); - s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE); - break; - case STORED: - if (n == 0) - LEAVE - NEEDOUT - t = s->sub.left; - if (t > n) t = n; - if (t > m) t = m; - zmemcpy(q, p, t); - p += t; n -= t; - q += t; m -= t; - if ((s->sub.left -= t) != 0) - break; - Tracev((stderr, "inflate: stored end, %lu total out\n", - z->total_out + (q >= s->read ? q - s->read : - (s->end - s->read) + (q - s->window)))); - s->mode = s->last ? DRY : TYPE; - break; - case TABLE: - NEEDBITS(14) - s->sub.trees.table = t = (uInt)b & 0x3fff; -#ifndef PKZIP_BUG_WORKAROUND - if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) - { - s->mode = BAD; - z->msg = (char*)"too many length or distance symbols"; - r = Z_DATA_ERROR; - LEAVE - } -#endif - t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); - if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL) - { - r = Z_MEM_ERROR; - LEAVE - } - DUMPBITS(14) - s->sub.trees.index = 0; - Tracev((stderr, "inflate: table sizes ok\n")); - s->mode = BTREE; - case BTREE: - while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) - { - NEEDBITS(3) - s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7; - DUMPBITS(3) - } - while (s->sub.trees.index < 19) - s->sub.trees.blens[border[s->sub.trees.index++]] = 0; - s->sub.trees.bb = 7; - t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, - &s->sub.trees.tb, s->hufts, z); - if (t != Z_OK) - { - r = t; - if (r == Z_DATA_ERROR) - { - ZFREE(z, s->sub.trees.blens); - s->mode = BAD; - } - LEAVE - } - s->sub.trees.index = 0; - Tracev((stderr, "inflate: bits tree ok\n")); - s->mode = DTREE; - case DTREE: - while (t = s->sub.trees.table, - s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) - { - inflate_huft *h; - uInt i, j, c; - - t = s->sub.trees.bb; - NEEDBITS(t) - h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]); - t = h->bits; - c = h->base; - if (c < 16) - { - DUMPBITS(t) - s->sub.trees.blens[s->sub.trees.index++] = c; - } - else /* c == 16..18 */ - { - i = c == 18 ? 7 : c - 14; - j = c == 18 ? 11 : 3; - NEEDBITS(t + i) - DUMPBITS(t) - j += (uInt)b & inflate_mask[i]; - DUMPBITS(i) - i = s->sub.trees.index; - t = s->sub.trees.table; - if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || - (c == 16 && i < 1)) - { - ZFREE(z, s->sub.trees.blens); - s->mode = BAD; - z->msg = (char*)"invalid bit length repeat"; - r = Z_DATA_ERROR; - LEAVE - } - c = c == 16 ? s->sub.trees.blens[i - 1] : 0; - do { - s->sub.trees.blens[i++] = c; - } while (--j); - s->sub.trees.index = i; - } - } - s->sub.trees.tb = Z_NULL; - { - uInt bl, bd; - inflate_huft *tl, *td; - inflate_codes_statef *c; - - bl = 9; /* must be <= 9 for lookahead assumptions */ - bd = 6; /* must be <= 9 for lookahead assumptions */ - t = s->sub.trees.table; - t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), - s->sub.trees.blens, &bl, &bd, &tl, &td, - s->hufts, z); - if (t != Z_OK) - { - if (t == (uInt)Z_DATA_ERROR) - { - ZFREE(z, s->sub.trees.blens); - s->mode = BAD; - } - r = t; - LEAVE - } - Tracev((stderr, "inflate: trees ok\n")); - if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) - { - r = Z_MEM_ERROR; - LEAVE - } - s->sub.decode.codes = c; - } - ZFREE(z, s->sub.trees.blens); - s->mode = CODES; - case CODES: - UPDATE - if ((r = inflate_codes(s, z, r)) != Z_STREAM_END) - return inflate_flush(s, z, r); - r = Z_OK; - inflate_codes_free(s->sub.decode.codes, z); - LOAD - Tracev((stderr, "inflate: codes end, %lu total out\n", - z->total_out + (q >= s->read ? q - s->read : - (s->end - s->read) + (q - s->window)))); - if (!s->last) - { - s->mode = TYPE; - break; - } - s->mode = DRY; - case DRY: - FLUSH - if (s->read != s->write) - LEAVE - s->mode = DONE; - case DONE: - r = Z_STREAM_END; - LEAVE - case BAD: - r = Z_DATA_ERROR; - LEAVE - default: - r = Z_STREAM_ERROR; - LEAVE - } -} - - -int inflate_blocks_free(s, z) -inflate_blocks_statef *s; -z_streamp z; -{ - inflate_blocks_reset(s, z, Z_NULL); - ZFREE(z, s->window); - ZFREE(z, s->hufts); - ZFREE(z, s); - Tracev((stderr, "inflate: blocks freed\n")); - return Z_OK; -} - - -void inflate_set_dictionary(s, d, n) -inflate_blocks_statef *s; -const Bytef *d; -uInt n; -{ - zmemcpy(s->window, d, n); - s->read = s->write = s->window + n; -} - - -/* Returns true if inflate is currently at the end of a block generated - * by Z_SYNC_FLUSH or Z_FULL_FLUSH. - * IN assertion: s != Z_NULL - */ -int inflate_blocks_sync_point(s) -inflate_blocks_statef *s; -{ - return s->mode == LENS; -} diff --git a/zlib/infblock.h b/zlib/infblock.h deleted file mode 100755 index 173b226..0000000 --- a/zlib/infblock.h +++ /dev/null @@ -1,39 +0,0 @@ -/* infblock.h -- header to use infblock.c - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -struct inflate_blocks_state; -typedef struct inflate_blocks_state FAR inflate_blocks_statef; - -extern inflate_blocks_statef * inflate_blocks_new OF(( - z_streamp z, - check_func c, /* check function */ - uInt w)); /* window size */ - -extern int inflate_blocks OF(( - inflate_blocks_statef *, - z_streamp , - int)); /* initial return code */ - -extern void inflate_blocks_reset OF(( - inflate_blocks_statef *, - z_streamp , - uLongf *)); /* check value on output */ - -extern int inflate_blocks_free OF(( - inflate_blocks_statef *, - z_streamp)); - -extern void inflate_set_dictionary OF(( - inflate_blocks_statef *s, - const Bytef *d, /* dictionary */ - uInt n)); /* dictionary length */ - -extern int inflate_blocks_sync_point OF(( - inflate_blocks_statef *s)); diff --git a/zlib/infcodes.c b/zlib/infcodes.c deleted file mode 100755 index 9abe541..0000000 --- a/zlib/infcodes.c +++ /dev/null @@ -1,251 +0,0 @@ -/* infcodes.c -- process literals and length/distance pairs - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "infblock.h" -#include "infcodes.h" -#include "infutil.h" -#include "inffast.h" - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ - START, /* x: set up for LEN */ - LEN, /* i: get length/literal/eob next */ - LENEXT, /* i: getting length extra (have base) */ - DIST, /* i: get distance next */ - DISTEXT, /* i: getting distance extra */ - COPY, /* o: copying bytes in window, waiting for space */ - LIT, /* o: got literal, waiting for output space */ - WASH, /* o: got eob, possibly still output waiting */ - END, /* x: got eob and all data flushed */ - BADCODE} /* x: got error */ -inflate_codes_mode; - -/* inflate codes private state */ -struct inflate_codes_state { - - /* mode */ - inflate_codes_mode mode; /* current inflate_codes mode */ - - /* mode dependent information */ - uInt len; - union { - struct { - inflate_huft *tree; /* pointer into tree */ - uInt need; /* bits needed */ - } code; /* if LEN or DIST, where in tree */ - uInt lit; /* if LIT, literal */ - struct { - uInt get; /* bits to get for extra */ - uInt dist; /* distance back to copy from */ - } copy; /* if EXT or COPY, where and how much */ - } sub; /* submode */ - - /* mode independent information */ - Byte lbits; /* ltree bits decoded per branch */ - Byte dbits; /* dtree bits decoder per branch */ - inflate_huft *ltree; /* literal/length/eob tree */ - inflate_huft *dtree; /* distance tree */ - -}; - - -inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z) -uInt bl, bd; -inflate_huft *tl; -inflate_huft *td; /* need separate declaration for Borland C++ */ -z_streamp z; -{ - inflate_codes_statef *c; - - if ((c = (inflate_codes_statef *) - ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL) - { - c->mode = START; - c->lbits = (Byte)bl; - c->dbits = (Byte)bd; - c->ltree = tl; - c->dtree = td; - Tracev((stderr, "inflate: codes new\n")); - } - return c; -} - - -int inflate_codes(s, z, r) -inflate_blocks_statef *s; -z_streamp z; -int r; -{ - uInt j; /* temporary storage */ - inflate_huft *t; /* temporary pointer */ - uInt e; /* extra bits or operation */ - uLong b; /* bit buffer */ - uInt k; /* bits in bit buffer */ - Bytef *p; /* input data pointer */ - uInt n; /* bytes available there */ - Bytef *q; /* output window write pointer */ - uInt m; /* bytes to end of window or read pointer */ - Bytef *f; /* pointer to copy strings from */ - inflate_codes_statef *c = s->sub.decode.codes; /* codes state */ - - /* copy input/output information to locals (UPDATE macro restores) */ - LOAD - - /* process input and output based on current state */ - while (1) switch (c->mode) - { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ - case START: /* x: set up for LEN */ -#ifndef SLOW - if (m >= 258 && n >= 10) - { - UPDATE - r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z); - LOAD - if (r != Z_OK) - { - c->mode = r == Z_STREAM_END ? WASH : BADCODE; - break; - } - } -#endif /* !SLOW */ - c->sub.code.need = c->lbits; - c->sub.code.tree = c->ltree; - c->mode = LEN; - case LEN: /* i: get length/literal/eob next */ - j = c->sub.code.need; - NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); - DUMPBITS(t->bits) - e = (uInt)(t->exop); - if (e == 0) /* literal */ - { - c->sub.lit = t->base; - Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", t->base)); - c->mode = LIT; - break; - } - if (e & 16) /* length */ - { - c->sub.copy.get = e & 15; - c->len = t->base; - c->mode = LENEXT; - break; - } - if ((e & 64) == 0) /* next table */ - { - c->sub.code.need = e; - c->sub.code.tree = t + t->base; - break; - } - if (e & 32) /* end of block */ - { - Tracevv((stderr, "inflate: end of block\n")); - c->mode = WASH; - break; - } - c->mode = BADCODE; /* invalid code */ - z->msg = (char*)"invalid literal/length code"; - r = Z_DATA_ERROR; - LEAVE - case LENEXT: /* i: getting length extra (have base) */ - j = c->sub.copy.get; - NEEDBITS(j) - c->len += (uInt)b & inflate_mask[j]; - DUMPBITS(j) - c->sub.code.need = c->dbits; - c->sub.code.tree = c->dtree; - Tracevv((stderr, "inflate: length %u\n", c->len)); - c->mode = DIST; - case DIST: /* i: get distance next */ - j = c->sub.code.need; - NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); - DUMPBITS(t->bits) - e = (uInt)(t->exop); - if (e & 16) /* distance */ - { - c->sub.copy.get = e & 15; - c->sub.copy.dist = t->base; - c->mode = DISTEXT; - break; - } - if ((e & 64) == 0) /* next table */ - { - c->sub.code.need = e; - c->sub.code.tree = t + t->base; - break; - } - c->mode = BADCODE; /* invalid code */ - z->msg = (char*)"invalid distance code"; - r = Z_DATA_ERROR; - LEAVE - case DISTEXT: /* i: getting distance extra */ - j = c->sub.copy.get; - NEEDBITS(j) - c->sub.copy.dist += (uInt)b & inflate_mask[j]; - DUMPBITS(j) - Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); - c->mode = COPY; - case COPY: /* o: copying bytes in window, waiting for space */ - f = q - c->sub.copy.dist; - while (f < s->window) /* modulo window size-"while" instead */ - f += s->end - s->window; /* of "if" handles invalid distances */ - while (c->len) - { - NEEDOUT - OUTBYTE(*f++) - if (f == s->end) - f = s->window; - c->len--; - } - c->mode = START; - break; - case LIT: /* o: got literal, waiting for output space */ - NEEDOUT - OUTBYTE(c->sub.lit) - c->mode = START; - break; - case WASH: /* o: got eob, possibly more output */ - if (k > 7) /* return unused byte, if any */ - { - Assert(k < 16, "inflate_codes grabbed too many bytes") - k -= 8; - n++; - p--; /* can always return one */ - } - FLUSH - if (s->read != s->write) - LEAVE - c->mode = END; - case END: - r = Z_STREAM_END; - LEAVE - case BADCODE: /* x: got error */ - r = Z_DATA_ERROR; - LEAVE - default: - r = Z_STREAM_ERROR; - LEAVE - } -#ifdef NEED_DUMMY_RETURN - return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ -#endif -} - - -void inflate_codes_free(c, z) -inflate_codes_statef *c; -z_streamp z; -{ - ZFREE(z, c); - Tracev((stderr, "inflate: codes free\n")); -} diff --git a/zlib/infcodes.h b/zlib/infcodes.h deleted file mode 100755 index 46821a0..0000000 --- a/zlib/infcodes.h +++ /dev/null @@ -1,27 +0,0 @@ -/* infcodes.h -- header to use infcodes.c - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -struct inflate_codes_state; -typedef struct inflate_codes_state FAR inflate_codes_statef; - -extern inflate_codes_statef *inflate_codes_new OF(( - uInt, uInt, - inflate_huft *, inflate_huft *, - z_streamp )); - -extern int inflate_codes OF(( - inflate_blocks_statef *, - z_streamp , - int)); - -extern void inflate_codes_free OF(( - inflate_codes_statef *, - z_streamp )); - diff --git a/zlib/inffast.c b/zlib/inffast.c deleted file mode 100755 index b26b16e..0000000 --- a/zlib/inffast.c +++ /dev/null @@ -1,183 +0,0 @@ -/* inffast.c -- process literals and length/distance pairs fast - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "infblock.h" -#include "infcodes.h" -#include "infutil.h" -#include "inffast.h" - -struct inflate_codes_state {int dummy;}; /* for buggy compilers */ - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -/* macros for bit input with no checking and for returning unused bytes */ -#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3;} - -/* Called with number of bytes left to write in window at least 258 - (the maximum string length) and number of input bytes available - at least ten. The ten bytes are six bytes for the longest length/ - distance pair plus four bytes for overloading the bit buffer. */ - -int inflate_fast(bl, bd, tl, td, s, z) -uInt bl, bd; -inflate_huft *tl; -inflate_huft *td; /* need separate declaration for Borland C++ */ -inflate_blocks_statef *s; -z_streamp z; -{ - inflate_huft *t; /* temporary pointer */ - uInt e; /* extra bits or operation */ - uLong b; /* bit buffer */ - uInt k; /* bits in bit buffer */ - Bytef *p; /* input data pointer */ - uInt n; /* bytes available there */ - Bytef *q; /* output window write pointer */ - uInt m; /* bytes to end of window or read pointer */ - uInt ml; /* mask for literal/length tree */ - uInt md; /* mask for distance tree */ - uInt c; /* bytes to copy */ - uInt d; /* distance back to copy from */ - Bytef *r; /* copy source pointer */ - - /* load input, output, bit values */ - LOAD - - /* initialize masks */ - ml = inflate_mask[bl]; - md = inflate_mask[bd]; - - /* do until not enough input or output space for fast loop */ - do { /* assume called with m >= 258 && n >= 10 */ - /* get literal/length code */ - GRABBITS(20) /* max bits for literal/length code */ - if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) - { - DUMPBITS(t->bits) - Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? - "inflate: * literal '%c'\n" : - "inflate: * literal 0x%02x\n", t->base)); - *q++ = (Byte)t->base; - m--; - continue; - } - do { - DUMPBITS(t->bits) - if (e & 16) - { - /* get extra bits for length */ - e &= 15; - c = t->base + ((uInt)b & inflate_mask[e]); - DUMPBITS(e) - Tracevv((stderr, "inflate: * length %u\n", c)); - - /* decode distance base of block to copy */ - GRABBITS(15); /* max bits for distance code */ - e = (t = td + ((uInt)b & md))->exop; - do { - DUMPBITS(t->bits) - if (e & 16) - { - /* get extra bits to add to distance base */ - e &= 15; - GRABBITS(e) /* get extra bits (up to 13) */ - d = t->base + ((uInt)b & inflate_mask[e]); - DUMPBITS(e) - Tracevv((stderr, "inflate: * distance %u\n", d)); - - /* do the copy */ - m -= c; - r = q - d; - if (r < s->window) /* wrap if needed */ - { - do { - r += s->end - s->window; /* force pointer in window */ - } while (r < s->window); /* covers invalid distances */ - e = s->end - r; - if (c > e) - { - c -= e; /* wrapped copy */ - do { - *q++ = *r++; - } while (--e); - r = s->window; - do { - *q++ = *r++; - } while (--c); - } - else /* normal copy */ - { - *q++ = *r++; c--; - *q++ = *r++; c--; - do { - *q++ = *r++; - } while (--c); - } - } - else /* normal copy */ - { - *q++ = *r++; c--; - *q++ = *r++; c--; - do { - *q++ = *r++; - } while (--c); - } - break; - } - else if ((e & 64) == 0) - { - t += t->base; - e = (t += ((uInt)b & inflate_mask[e]))->exop; - } - else - { - z->msg = (char*)"invalid distance code"; - UNGRAB - UPDATE - return Z_DATA_ERROR; - } - } while (1); - break; - } - if ((e & 64) == 0) - { - t += t->base; - if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) - { - DUMPBITS(t->bits) - Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? - "inflate: * literal '%c'\n" : - "inflate: * literal 0x%02x\n", t->base)); - *q++ = (Byte)t->base; - m--; - break; - } - } - else if (e & 32) - { - Tracevv((stderr, "inflate: * end of block\n")); - UNGRAB - UPDATE - return Z_STREAM_END; - } - else - { - z->msg = (char*)"invalid literal/length code"; - UNGRAB - UPDATE - return Z_DATA_ERROR; - } - } while (1); - } while (m >= 258 && n >= 10); - - /* not enough input or output--restore pointers and return */ - UNGRAB - UPDATE - return Z_OK; -} diff --git a/zlib/inffast.h b/zlib/inffast.h deleted file mode 100755 index a31a4bb..0000000 --- a/zlib/inffast.h +++ /dev/null @@ -1,17 +0,0 @@ -/* inffast.h -- header to use inffast.c - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -extern int inflate_fast OF(( - uInt, - uInt, - inflate_huft *, - inflate_huft *, - inflate_blocks_statef *, - z_streamp )); diff --git a/zlib/inffixed.h b/zlib/inffixed.h deleted file mode 100755 index 77f7e76..0000000 --- a/zlib/inffixed.h +++ /dev/null @@ -1,151 +0,0 @@ -/* inffixed.h -- table for decoding fixed codes - * Generated automatically by the maketree.c program - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -local uInt fixed_bl = 9; -local uInt fixed_bd = 5; -local inflate_huft fixed_tl[] = { - {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115}, - {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192}, - {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160}, - {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224}, - {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144}, - {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208}, - {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176}, - {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240}, - {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227}, - {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200}, - {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168}, - {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232}, - {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152}, - {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216}, - {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184}, - {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248}, - {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163}, - {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196}, - {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164}, - {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228}, - {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148}, - {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212}, - {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180}, - {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244}, - {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0}, - {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204}, - {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172}, - {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236}, - {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156}, - {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220}, - {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188}, - {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252}, - {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131}, - {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194}, - {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162}, - {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226}, - {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146}, - {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210}, - {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178}, - {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242}, - {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258}, - {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202}, - {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170}, - {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234}, - {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154}, - {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218}, - {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186}, - {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250}, - {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195}, - {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198}, - {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166}, - {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230}, - {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150}, - {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214}, - {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182}, - {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246}, - {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0}, - {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206}, - {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174}, - {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238}, - {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158}, - {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222}, - {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190}, - {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254}, - {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115}, - {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193}, - {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161}, - {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225}, - {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145}, - {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209}, - {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177}, - {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241}, - {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227}, - {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201}, - {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169}, - {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233}, - {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153}, - {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217}, - {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185}, - {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249}, - {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163}, - {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197}, - {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165}, - {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229}, - {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149}, - {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213}, - {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181}, - {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245}, - {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0}, - {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205}, - {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173}, - {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237}, - {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157}, - {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221}, - {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189}, - {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253}, - {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131}, - {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195}, - {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163}, - {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227}, - {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147}, - {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211}, - {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179}, - {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243}, - {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258}, - {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203}, - {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171}, - {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235}, - {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155}, - {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219}, - {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187}, - {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251}, - {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195}, - {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199}, - {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167}, - {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231}, - {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151}, - {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215}, - {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183}, - {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247}, - {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0}, - {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207}, - {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175}, - {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239}, - {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159}, - {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223}, - {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191}, - {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255} - }; -local inflate_huft fixed_td[] = { - {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097}, - {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385}, - {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193}, - {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577}, - {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145}, - {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577}, - {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289}, - {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577} - }; diff --git a/zlib/inflate.c b/zlib/inflate.c deleted file mode 100755 index dfb2e86..0000000 --- a/zlib/inflate.c +++ /dev/null @@ -1,366 +0,0 @@ -/* inflate.c -- zlib interface to inflate modules - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infblock.h" - -struct inflate_blocks_state {int dummy;}; /* for buggy compilers */ - -typedef enum { - METHOD, /* waiting for method byte */ - FLAG, /* waiting for flag byte */ - DICT4, /* four dictionary check bytes to go */ - DICT3, /* three dictionary check bytes to go */ - DICT2, /* two dictionary check bytes to go */ - DICT1, /* one dictionary check byte to go */ - DICT0, /* waiting for inflateSetDictionary */ - BLOCKS, /* decompressing blocks */ - CHECK4, /* four check bytes to go */ - CHECK3, /* three check bytes to go */ - CHECK2, /* two check bytes to go */ - CHECK1, /* one check byte to go */ - DONE, /* finished check, done */ - BAD} /* got an error--stay here */ -inflate_mode; - -/* inflate private state */ -struct internal_state { - - /* mode */ - inflate_mode mode; /* current inflate mode */ - - /* mode dependent information */ - union { - uInt method; /* if FLAGS, method byte */ - struct { - uLong was; /* computed check value */ - uLong need; /* stream check value */ - } check; /* if CHECK, check values to compare */ - uInt marker; /* if BAD, inflateSync's marker bytes count */ - } sub; /* submode */ - - /* mode independent information */ - int nowrap; /* flag for no wrapper */ - uInt wbits; /* log2(window size) (8..15, defaults to 15) */ - inflate_blocks_statef - *blocks; /* current inflate_blocks state */ - -}; - - -int ZEXPORT inflateReset(z) -z_streamp z; -{ - if (z == Z_NULL || z->state == Z_NULL) - return Z_STREAM_ERROR; - z->total_in = z->total_out = 0; - z->msg = Z_NULL; - z->state->mode = z->state->nowrap ? BLOCKS : METHOD; - inflate_blocks_reset(z->state->blocks, z, Z_NULL); - Tracev((stderr, "inflate: reset\n")); - return Z_OK; -} - - -int ZEXPORT inflateEnd(z) -z_streamp z; -{ - if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) - return Z_STREAM_ERROR; - if (z->state->blocks != Z_NULL) - inflate_blocks_free(z->state->blocks, z); - ZFREE(z, z->state); - z->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} - - -int ZEXPORT inflateInit2_(z, w, version, stream_size) -z_streamp z; -int w; -const char *version; -int stream_size; -{ - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != sizeof(z_stream)) - return Z_VERSION_ERROR; - - /* initialize state */ - if (z == Z_NULL) - return Z_STREAM_ERROR; - z->msg = Z_NULL; - if (z->zalloc == Z_NULL) - { - z->zalloc = zcalloc; - z->opaque = (voidpf)0; - } - if (z->zfree == Z_NULL) z->zfree = zcfree; - if ((z->state = (struct internal_state FAR *) - ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) - return Z_MEM_ERROR; - z->state->blocks = Z_NULL; - - /* handle undocumented nowrap option (no zlib header or check) */ - z->state->nowrap = 0; - if (w < 0) - { - w = - w; - z->state->nowrap = 1; - } - - /* set window size */ - if (w < 8 || w > 15) - { - inflateEnd(z); - return Z_STREAM_ERROR; - } - z->state->wbits = (uInt)w; - - /* create inflate_blocks state */ - if ((z->state->blocks = - inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) - == Z_NULL) - { - inflateEnd(z); - return Z_MEM_ERROR; - } - Tracev((stderr, "inflate: allocated\n")); - - /* reset state */ - inflateReset(z); - return Z_OK; -} - - -int ZEXPORT inflateInit_(z, version, stream_size) -z_streamp z; -const char *version; -int stream_size; -{ - return inflateInit2_(z, DEF_WBITS, version, stream_size); -} - - -#define NEEDBYTE {if(z->avail_in==0)return r;r=f;} -#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) - -int ZEXPORT inflate(z, f) -z_streamp z; -int f; -{ - int r; - uInt b; - - if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL) - return Z_STREAM_ERROR; - f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; - r = Z_BUF_ERROR; - while (1) switch (z->state->mode) - { - case METHOD: - NEEDBYTE - if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) - { - z->state->mode = BAD; - z->msg = (char*)"unknown compression method"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - if ((z->state->sub.method >> 4) + 8 > z->state->wbits) - { - z->state->mode = BAD; - z->msg = (char*)"invalid window size"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - z->state->mode = FLAG; - case FLAG: - NEEDBYTE - b = NEXTBYTE; - if (((z->state->sub.method << 8) + b) % 31) - { - z->state->mode = BAD; - z->msg = (char*)"incorrect header check"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - Tracev((stderr, "inflate: zlib header ok\n")); - if (!(b & PRESET_DICT)) - { - z->state->mode = BLOCKS; - break; - } - z->state->mode = DICT4; - case DICT4: - NEEDBYTE - z->state->sub.check.need = (uLong)NEXTBYTE << 24; - z->state->mode = DICT3; - case DICT3: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 16; - z->state->mode = DICT2; - case DICT2: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 8; - z->state->mode = DICT1; - case DICT1: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE; - z->adler = z->state->sub.check.need; - z->state->mode = DICT0; - return Z_NEED_DICT; - case DICT0: - z->state->mode = BAD; - z->msg = (char*)"need dictionary"; - z->state->sub.marker = 0; /* can try inflateSync */ - return Z_STREAM_ERROR; - case BLOCKS: - r = inflate_blocks(z->state->blocks, z, r); - if (r == Z_DATA_ERROR) - { - z->state->mode = BAD; - z->state->sub.marker = 0; /* can try inflateSync */ - break; - } - if (r == Z_OK) - r = f; - if (r != Z_STREAM_END) - return r; - r = f; - inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); - if (z->state->nowrap) - { - z->state->mode = DONE; - break; - } - z->state->mode = CHECK4; - case CHECK4: - NEEDBYTE - z->state->sub.check.need = (uLong)NEXTBYTE << 24; - z->state->mode = CHECK3; - case CHECK3: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 16; - z->state->mode = CHECK2; - case CHECK2: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 8; - z->state->mode = CHECK1; - case CHECK1: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE; - - if (z->state->sub.check.was != z->state->sub.check.need) - { - z->state->mode = BAD; - z->msg = (char*)"incorrect data check"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - Tracev((stderr, "inflate: zlib check ok\n")); - z->state->mode = DONE; - case DONE: - return Z_STREAM_END; - case BAD: - return Z_DATA_ERROR; - default: - return Z_STREAM_ERROR; - } -#ifdef NEED_DUMMY_RETURN - return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ -#endif -} - - -int ZEXPORT inflateSetDictionary(z, dictionary, dictLength) -z_streamp z; -const Bytef *dictionary; -uInt dictLength; -{ - uInt length = dictLength; - - if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0) - return Z_STREAM_ERROR; - - if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; - z->adler = 1L; - - if (length >= ((uInt)1<state->wbits)) - { - length = (1<state->wbits)-1; - dictionary += dictLength - length; - } - inflate_set_dictionary(z->state->blocks, dictionary, length); - z->state->mode = BLOCKS; - return Z_OK; -} - - -int ZEXPORT inflateSync(z) -z_streamp z; -{ - uInt n; /* number of bytes to look at */ - Bytef *p; /* pointer to bytes */ - uInt m; /* number of marker bytes found in a row */ - uLong r, w; /* temporaries to save total_in and total_out */ - - /* set up */ - if (z == Z_NULL || z->state == Z_NULL) - return Z_STREAM_ERROR; - if (z->state->mode != BAD) - { - z->state->mode = BAD; - z->state->sub.marker = 0; - } - if ((n = z->avail_in) == 0) - return Z_BUF_ERROR; - p = z->next_in; - m = z->state->sub.marker; - - /* search */ - while (n && m < 4) - { - static const Byte mark[4] = {0, 0, 0xff, 0xff}; - if (*p == mark[m]) - m++; - else if (*p) - m = 0; - else - m = 4 - m; - p++, n--; - } - - /* restore */ - z->total_in += p - z->next_in; - z->next_in = p; - z->avail_in = n; - z->state->sub.marker = m; - - /* return no joy or set up to restart on a new block */ - if (m != 4) - return Z_DATA_ERROR; - r = z->total_in; w = z->total_out; - inflateReset(z); - z->total_in = r; z->total_out = w; - z->state->mode = BLOCKS; - return Z_OK; -} - - -/* Returns true if inflate is currently at the end of a block generated - * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP - * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH - * but removes the length bytes of the resulting empty stored block. When - * decompressing, PPP checks that at the end of input packet, inflate is - * waiting for these length bytes. - */ -int ZEXPORT inflateSyncPoint(z) -z_streamp z; -{ - if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL) - return Z_STREAM_ERROR; - return inflate_blocks_sync_point(z->state->blocks); -} diff --git a/zlib/inftrees.c b/zlib/inftrees.c deleted file mode 100755 index 4c32ca3..0000000 --- a/zlib/inftrees.c +++ /dev/null @@ -1,454 +0,0 @@ -/* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" - -#if !defined(BUILDFIXED) && !defined(STDC) -# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */ -#endif - -const char inflate_copyright[] = - " inflate 1.1.4 Copyright 1995-2002 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ -struct internal_state {int dummy;}; /* for buggy compilers */ - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - - -local int huft_build OF(( - uIntf *, /* code lengths in bits */ - uInt, /* number of codes */ - uInt, /* number of "simple" codes */ - const uIntf *, /* list of base values for non-simple codes */ - const uIntf *, /* list of extra bits for non-simple codes */ - inflate_huft * FAR*,/* result: starting table */ - uIntf *, /* maximum lookup bits (returns actual) */ - inflate_huft *, /* space for trees */ - uInt *, /* hufts used in space */ - uIntf * )); /* space for values */ - -/* Tables for deflate from PKZIP's appnote.txt. */ -local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - /* see note #13 above about 258 */ -local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */ -local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577}; -local const uInt cpdext[30] = { /* Extra bits for distance codes */ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13}; - -/* - Huffman code decoding is performed using a multi-level table lookup. - The fastest way to decode is to simply build a lookup table whose - size is determined by the longest code. However, the time it takes - to build this table can also be a factor if the data being decoded - is not very long. The most common codes are necessarily the - shortest codes, so those codes dominate the decoding time, and hence - the speed. The idea is you can have a shorter table that decodes the - shorter, more probable codes, and then point to subsidiary tables for - the longer codes. The time it costs to decode the longer codes is - then traded against the time it takes to make longer tables. - - This results of this trade are in the variables lbits and dbits - below. lbits is the number of bits the first level table for literal/ - length codes can decode in one step, and dbits is the same thing for - the distance codes. Subsequent tables are also less than or equal to - those sizes. These values may be adjusted either when all of the - codes are shorter than that, in which case the longest code length in - bits is used, or when the shortest code is *longer* than the requested - table size, in which case the length of the shortest code in bits is - used. - - There are two different values for the two tables, since they code a - different number of possibilities each. The literal/length table - codes 286 possible values, or in a flat code, a little over eight - bits. The distance table codes 30 possible values, or a little less - than five bits, flat. The optimum values for speed end up being - about one bit more than those, so lbits is 8+1 and dbits is 5+1. - The optimum values may differ though from machine to machine, and - possibly even between compilers. Your mileage may vary. - */ - - -/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */ -#define BMAX 15 /* maximum bit length of any code */ - -local int huft_build(b, n, s, d, e, t, m, hp, hn, v) -uIntf *b; /* code lengths in bits (all assumed <= BMAX) */ -uInt n; /* number of codes (assumed <= 288) */ -uInt s; /* number of simple-valued codes (0..s-1) */ -const uIntf *d; /* list of base values for non-simple codes */ -const uIntf *e; /* list of extra bits for non-simple codes */ -inflate_huft * FAR *t; /* result: starting table */ -uIntf *m; /* maximum lookup bits, returns actual */ -inflate_huft *hp; /* space for trees */ -uInt *hn; /* hufts used in space */ -uIntf *v; /* working area: values in order of bit length */ -/* Given a list of code lengths and a maximum table size, make a set of - tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR - if the given code set is incomplete (the tables are still built in this - case), or Z_DATA_ERROR if the input is invalid. */ -{ - - uInt a; /* counter for codes of length k */ - uInt c[BMAX+1]; /* bit length count table */ - uInt f; /* i repeats in table every f entries */ - int g; /* maximum code length */ - int h; /* table level */ - register uInt i; /* counter, current code */ - register uInt j; /* counter */ - register int k; /* number of bits in current code */ - int l; /* bits per table (returned in m) */ - uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */ - register uIntf *p; /* pointer into c[], b[], or v[] */ - inflate_huft *q; /* points to current table */ - struct inflate_huft_s r; /* table entry for structure assignment */ - inflate_huft *u[BMAX]; /* table stack */ - register int w; /* bits before this table == (l * h) */ - uInt x[BMAX+1]; /* bit offsets, then code stack */ - uIntf *xp; /* pointer into x */ - int y; /* number of dummy codes added */ - uInt z; /* number of entries in current table */ - - - /* Generate counts for each bit length */ - p = c; -#define C0 *p++ = 0; -#define C2 C0 C0 C0 C0 -#define C4 C2 C2 C2 C2 - C4 /* clear c[]--assume BMAX+1 is 16 */ - p = b; i = n; - do { - c[*p++]++; /* assume all entries <= BMAX */ - } while (--i); - if (c[0] == n) /* null input--all zero length codes */ - { - *t = (inflate_huft *)Z_NULL; - *m = 0; - return Z_OK; - } - - - /* Find minimum and maximum length, bound *m by those */ - l = *m; - for (j = 1; j <= BMAX; j++) - if (c[j]) - break; - k = j; /* minimum code length */ - if ((uInt)l < j) - l = j; - for (i = BMAX; i; i--) - if (c[i]) - break; - g = i; /* maximum code length */ - if ((uInt)l > i) - l = i; - *m = l; - - - /* Adjust last length count to fill out codes, if needed */ - for (y = 1 << j; j < i; j++, y <<= 1) - if ((y -= c[j]) < 0) - return Z_DATA_ERROR; - if ((y -= c[i]) < 0) - return Z_DATA_ERROR; - c[i] += y; - - - /* Generate starting offsets into the value table for each length */ - x[1] = j = 0; - p = c + 1; xp = x + 2; - while (--i) { /* note that i == g from above */ - *xp++ = (j += *p++); - } - - - /* Make a table of values in order of bit lengths */ - p = b; i = 0; - do { - if ((j = *p++) != 0) - v[x[j]++] = i; - } while (++i < n); - n = x[g]; /* set n to length of v */ - - - /* Generate the Huffman codes and for each, make the table entries */ - x[0] = i = 0; /* first Huffman code is zero */ - p = v; /* grab values in bit order */ - h = -1; /* no tables yet--level -1 */ - w = -l; /* bits decoded == (l * h) */ - u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */ - q = (inflate_huft *)Z_NULL; /* ditto */ - z = 0; /* ditto */ - - /* go through the bit lengths (k already is bits in shortest code) */ - for (; k <= g; k++) - { - a = c[k]; - while (a--) - { - /* here i is the Huffman code of length k bits for value *p */ - /* make tables up to required level */ - while (k > w + l) - { - h++; - w += l; /* previous table always l bits */ - - /* compute minimum size table less than or equal to l bits */ - z = g - w; - z = z > (uInt)l ? l : z; /* table size upper limit */ - if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ - { /* too few codes for k-w bit table */ - f -= a + 1; /* deduct codes from patterns left */ - xp = c + k; - if (j < z) - while (++j < z) /* try smaller tables up to z bits */ - { - if ((f <<= 1) <= *++xp) - break; /* enough codes to use up j bits */ - f -= *xp; /* else deduct codes from patterns */ - } - } - z = 1 << j; /* table entries for j-bit table */ - - /* allocate new table */ - if (*hn + z > MANY) /* (note: doesn't matter for fixed) */ - return Z_DATA_ERROR; /* overflow of MANY */ - u[h] = q = hp + *hn; - *hn += z; - - /* connect to last table, if there is one */ - if (h) - { - x[h] = i; /* save pattern for backing up */ - r.bits = (Byte)l; /* bits to dump before this table */ - r.exop = (Byte)j; /* bits in this table */ - j = i >> (w - l); - r.base = (uInt)(q - u[h-1] - j); /* offset to this table */ - u[h-1][j] = r; /* connect to last table */ - } - else - *t = q; /* first table is returned result */ - } - - /* set up table entry in r */ - r.bits = (Byte)(k - w); - if (p >= v + n) - r.exop = 128 + 64; /* out of values--invalid code */ - else if (*p < s) - { - r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ - r.base = *p++; /* simple code is just the value */ - } - else - { - r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */ - r.base = d[*p++ - s]; - } - - /* fill code-like entries with r */ - f = 1 << (k - w); - for (j = i >> w; j < z; j += f) - q[j] = r; - - /* backwards increment the k-bit code i */ - for (j = 1 << (k - 1); i & j; j >>= 1) - i ^= j; - i ^= j; - - /* backup over finished tables */ - mask = (1 << w) - 1; /* needed on HP, cc -O bug */ - while ((i & mask) != x[h]) - { - h--; /* don't need to update q */ - w -= l; - mask = (1 << w) - 1; - } - } - } - - - /* Return Z_BUF_ERROR if we were given an incomplete table */ - return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK; -} - - -int inflate_trees_bits(c, bb, tb, hp, z) -uIntf *c; /* 19 code lengths */ -uIntf *bb; /* bits tree desired/actual depth */ -inflate_huft * FAR *tb; /* bits tree result */ -inflate_huft *hp; /* space for trees */ -z_streamp z; /* for messages */ -{ - int r; - uInt hn = 0; /* hufts used in space */ - uIntf *v; /* work area for huft_build */ - - if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL) - return Z_MEM_ERROR; - r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, - tb, bb, hp, &hn, v); - if (r == Z_DATA_ERROR) - z->msg = (char*)"oversubscribed dynamic bit lengths tree"; - else if (r == Z_BUF_ERROR || *bb == 0) - { - z->msg = (char*)"incomplete dynamic bit lengths tree"; - r = Z_DATA_ERROR; - } - ZFREE(z, v); - return r; -} - - -int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z) -uInt nl; /* number of literal/length codes */ -uInt nd; /* number of distance codes */ -uIntf *c; /* that many (total) code lengths */ -uIntf *bl; /* literal desired/actual bit depth */ -uIntf *bd; /* distance desired/actual bit depth */ -inflate_huft * FAR *tl; /* literal/length tree result */ -inflate_huft * FAR *td; /* distance tree result */ -inflate_huft *hp; /* space for trees */ -z_streamp z; /* for messages */ -{ - int r; - uInt hn = 0; /* hufts used in space */ - uIntf *v; /* work area for huft_build */ - - /* allocate work area */ - if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) - return Z_MEM_ERROR; - - /* build literal/length tree */ - r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v); - if (r != Z_OK || *bl == 0) - { - if (r == Z_DATA_ERROR) - z->msg = (char*)"oversubscribed literal/length tree"; - else if (r != Z_MEM_ERROR) - { - z->msg = (char*)"incomplete literal/length tree"; - r = Z_DATA_ERROR; - } - ZFREE(z, v); - return r; - } - - /* build distance tree */ - r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v); - if (r != Z_OK || (*bd == 0 && nl > 257)) - { - if (r == Z_DATA_ERROR) - z->msg = (char*)"oversubscribed distance tree"; - else if (r == Z_BUF_ERROR) { -#ifdef PKZIP_BUG_WORKAROUND - r = Z_OK; - } -#else - z->msg = (char*)"incomplete distance tree"; - r = Z_DATA_ERROR; - } - else if (r != Z_MEM_ERROR) - { - z->msg = (char*)"empty distance tree with lengths"; - r = Z_DATA_ERROR; - } - ZFREE(z, v); - return r; -#endif - } - - /* done */ - ZFREE(z, v); - return Z_OK; -} - - -/* build fixed tables only once--keep them here */ -#ifdef BUILDFIXED -local int fixed_built = 0; -#define FIXEDH 544 /* number of hufts used by fixed tables */ -local inflate_huft fixed_mem[FIXEDH]; -local uInt fixed_bl; -local uInt fixed_bd; -local inflate_huft *fixed_tl; -local inflate_huft *fixed_td; -#else -#include "inffixed.h" -#endif - - -int inflate_trees_fixed(bl, bd, tl, td, z) -uIntf *bl; /* literal desired/actual bit depth */ -uIntf *bd; /* distance desired/actual bit depth */ -inflate_huft * FAR *tl; /* literal/length tree result */ -inflate_huft * FAR *td; /* distance tree result */ -z_streamp z; /* for memory allocation */ -{ -#ifdef BUILDFIXED - /* build fixed tables if not already */ - if (!fixed_built) - { - int k; /* temporary variable */ - uInt f = 0; /* number of hufts used in fixed_mem */ - uIntf *c; /* length list for huft_build */ - uIntf *v; /* work area for huft_build */ - - /* allocate memory */ - if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) - return Z_MEM_ERROR; - if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) - { - ZFREE(z, c); - return Z_MEM_ERROR; - } - - /* literal table */ - for (k = 0; k < 144; k++) - c[k] = 8; - for (; k < 256; k++) - c[k] = 9; - for (; k < 280; k++) - c[k] = 7; - for (; k < 288; k++) - c[k] = 8; - fixed_bl = 9; - huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, - fixed_mem, &f, v); - - /* distance table */ - for (k = 0; k < 30; k++) - c[k] = 5; - fixed_bd = 5; - huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, - fixed_mem, &f, v); - - /* done */ - ZFREE(z, v); - ZFREE(z, c); - fixed_built = 1; - } -#endif - *bl = fixed_bl; - *bd = fixed_bd; - *tl = fixed_tl; - *td = fixed_td; - return Z_OK; -} diff --git a/zlib/inftrees.h b/zlib/inftrees.h deleted file mode 100755 index 04b73b7..0000000 --- a/zlib/inftrees.h +++ /dev/null @@ -1,58 +0,0 @@ -/* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Huffman code lookup table entry--this entry is four bytes for machines - that have 16-bit pointers (e.g. PC's in the small or medium model). */ - -typedef struct inflate_huft_s FAR inflate_huft; - -struct inflate_huft_s { - union { - struct { - Byte Exop; /* number of extra bits or operation */ - Byte Bits; /* number of bits in this code or subcode */ - } what; - uInt pad; /* pad structure to a power of 2 (4 bytes for */ - } word; /* 16-bit, 8 bytes for 32-bit int's) */ - uInt base; /* literal, length base, distance base, - or table offset */ -}; - -/* Maximum size of dynamic tree. The maximum found in a long but non- - exhaustive search was 1004 huft structures (850 for length/literals - and 154 for distances, the latter actually the result of an - exhaustive search). The actual maximum is not known, but the - value below is more than safe. */ -#define MANY 1440 - -extern int inflate_trees_bits OF(( - uIntf *, /* 19 code lengths */ - uIntf *, /* bits tree desired/actual depth */ - inflate_huft * FAR *, /* bits tree result */ - inflate_huft *, /* space for trees */ - z_streamp)); /* for messages */ - -extern int inflate_trees_dynamic OF(( - uInt, /* number of literal/length codes */ - uInt, /* number of distance codes */ - uIntf *, /* that many (total) code lengths */ - uIntf *, /* literal desired/actual bit depth */ - uIntf *, /* distance desired/actual bit depth */ - inflate_huft * FAR *, /* literal/length tree result */ - inflate_huft * FAR *, /* distance tree result */ - inflate_huft *, /* space for trees */ - z_streamp)); /* for messages */ - -extern int inflate_trees_fixed OF(( - uIntf *, /* literal desired/actual bit depth */ - uIntf *, /* distance desired/actual bit depth */ - inflate_huft * FAR *, /* literal/length tree result */ - inflate_huft * FAR *, /* distance tree result */ - z_streamp)); /* for memory allocation */ diff --git a/zlib/infutil.c b/zlib/infutil.c deleted file mode 100755 index 9a07622..0000000 --- a/zlib/infutil.c +++ /dev/null @@ -1,87 +0,0 @@ -/* inflate_util.c -- data and routines common to blocks and codes - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infblock.h" -#include "inftrees.h" -#include "infcodes.h" -#include "infutil.h" - -struct inflate_codes_state {int dummy;}; /* for buggy compilers */ - -/* And'ing with mask[n] masks the lower n bits */ -uInt inflate_mask[17] = { - 0x0000, - 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, - 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff -}; - - -/* copy as much as possible from the sliding window to the output area */ -int inflate_flush(s, z, r) -inflate_blocks_statef *s; -z_streamp z; -int r; -{ - uInt n; - Bytef *p; - Bytef *q; - - /* local copies of source and destination pointers */ - p = z->next_out; - q = s->read; - - /* compute number of bytes to copy as far as end of window */ - n = (uInt)((q <= s->write ? s->write : s->end) - q); - if (n > z->avail_out) n = z->avail_out; - if (n && r == Z_BUF_ERROR) r = Z_OK; - - /* update counters */ - z->avail_out -= n; - z->total_out += n; - - /* update check information */ - if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(s->check, q, n); - - /* copy as far as end of window */ - zmemcpy(p, q, n); - p += n; - q += n; - - /* see if more to copy at beginning of window */ - if (q == s->end) - { - /* wrap pointers */ - q = s->window; - if (s->write == s->end) - s->write = s->window; - - /* compute bytes to copy */ - n = (uInt)(s->write - q); - if (n > z->avail_out) n = z->avail_out; - if (n && r == Z_BUF_ERROR) r = Z_OK; - - /* update counters */ - z->avail_out -= n; - z->total_out += n; - - /* update check information */ - if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(s->check, q, n); - - /* copy */ - zmemcpy(p, q, n); - p += n; - q += n; - } - - /* update pointers */ - z->next_out = p; - s->read = q; - - /* done */ - return r; -} diff --git a/zlib/infutil.h b/zlib/infutil.h deleted file mode 100755 index 4401df8..0000000 --- a/zlib/infutil.h +++ /dev/null @@ -1,98 +0,0 @@ -/* infutil.h -- types and macros common to blocks and codes - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -#ifndef _INFUTIL_H -#define _INFUTIL_H - -typedef enum { - TYPE, /* get type bits (3, including end bit) */ - LENS, /* get lengths for stored */ - STORED, /* processing stored block */ - TABLE, /* get table lengths */ - BTREE, /* get bit lengths tree for a dynamic block */ - DTREE, /* get length, distance trees for a dynamic block */ - CODES, /* processing fixed or dynamic block */ - DRY, /* output remaining window bytes */ - DONE, /* finished last block, done */ - BAD} /* got a data error--stuck here */ -inflate_block_mode; - -/* inflate blocks semi-private state */ -struct inflate_blocks_state { - - /* mode */ - inflate_block_mode mode; /* current inflate_block mode */ - - /* mode dependent information */ - union { - uInt left; /* if STORED, bytes left to copy */ - struct { - uInt table; /* table lengths (14 bits) */ - uInt index; /* index into blens (or border) */ - uIntf *blens; /* bit lengths of codes */ - uInt bb; /* bit length tree depth */ - inflate_huft *tb; /* bit length decoding tree */ - } trees; /* if DTREE, decoding info for trees */ - struct { - inflate_codes_statef - *codes; - } decode; /* if CODES, current state */ - } sub; /* submode */ - uInt last; /* true if this block is the last block */ - - /* mode independent information */ - uInt bitk; /* bits in bit buffer */ - uLong bitb; /* bit buffer */ - inflate_huft *hufts; /* single malloc for tree space */ - Bytef *window; /* sliding window */ - Bytef *end; /* one byte after sliding window */ - Bytef *read; /* window read pointer */ - Bytef *write; /* window write pointer */ - check_func checkfn; /* check function */ - uLong check; /* check on output */ - -}; - - -/* defines for inflate input/output */ -/* update pointers and return */ -#define UPDBITS {s->bitb=b;s->bitk=k;} -#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;} -#define UPDOUT {s->write=q;} -#define UPDATE {UPDBITS UPDIN UPDOUT} -#define LEAVE {UPDATE return inflate_flush(s,z,r);} -/* get bytes and bits */ -#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} -#define NEEDBYTE {if(n)r=Z_OK;else LEAVE} -#define NEXTBYTE (n--,*p++) -#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<>=(j);k-=(j);} -/* output bytes */ -#define WAVAIL (uInt)(qread?s->read-q-1:s->end-q) -#define LOADOUT {q=s->write;m=(uInt)WAVAIL;} -#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}} -#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} -#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} -#define OUTBYTE(a) {*q++=(Byte)(a);m--;} -/* load local pointers */ -#define LOAD {LOADIN LOADOUT} - -/* masks for lower bits (size given to avoid silly warnings with Visual C++) */ -extern uInt inflate_mask[17]; - -/* copy as much as possible from the sliding window to the output area */ -extern int inflate_flush OF(( - inflate_blocks_statef *, - z_streamp , - int)); - -struct internal_state {int dummy;}; /* for buggy compilers */ - -#endif diff --git a/zlib/maketree.c b/zlib/maketree.c deleted file mode 100755 index a16d4b1..0000000 --- a/zlib/maketree.c +++ /dev/null @@ -1,85 +0,0 @@ -/* maketree.c -- make inffixed.h table for decoding fixed codes - * Copyright (C) 1995-2002 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* This program is included in the distribution for completeness. - You do not need to compile or run this program since inffixed.h - is already included in the distribution. To use this program - you need to compile zlib with BUILDFIXED defined and then compile - and link this program with the zlib library. Then the output of - this program can be piped to inffixed.h. */ - -#include -#include -#include "zutil.h" -#include "inftrees.h" - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -/* generate initialization table for an inflate_huft structure array */ -void maketree(uInt b, inflate_huft *t) -{ - int i, e; - - i = 0; - while (1) - { - e = t[i].exop; - if (e && (e & (16+64)) == 0) /* table pointer */ - { - fprintf(stderr, "maketree: cannot initialize sub-tables!\n"); - exit(1); - } - if (i % 4 == 0) - printf("\n "); - printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base); - if (++i == (1< -#include "zlib.h" - -#ifdef STDC -# include -# include -#else - extern void exit OF((int)); -#endif - -#ifdef USE_MMAP -# include -# include -# include -#endif - -#if defined(MSDOS) || defined(OS2) || defined(WIN32) -# include -# include -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif - -#ifdef VMS -# define unlink delete -# define GZ_SUFFIX "-gz" -#endif -#ifdef RISCOS -# define unlink remove -# define GZ_SUFFIX "-gz" -# define fileno(file) file->__file -#endif -#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fileno */ -#endif - -#ifndef WIN32 /* unlink already in stdio.h for WIN32 */ - extern int unlink OF((const char *)); -#endif - -#ifndef GZ_SUFFIX -# define GZ_SUFFIX ".gz" -#endif -#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) - -#define BUFLEN 16384 -#define MAX_NAME_LEN 1024 - -#ifdef MAXSEG_64K -# define local static - /* Needed for systems with limitation on stack size. */ -#else -# define local -#endif - -char *prog; - -void error OF((const char *msg)); -void gz_compress OF((FILE *in, gzFile out)); -#ifdef USE_MMAP -int gz_compress_mmap OF((FILE *in, gzFile out)); -#endif -void gz_uncompress OF((gzFile in, FILE *out)); -void file_compress OF((char *file, char *mode)); -void file_uncompress OF((char *file)); -int main OF((int argc, char *argv[])); - -/* =========================================================================== - * Display error message and exit - */ -void error(msg) - const char *msg; -{ - fprintf(stderr, "%s: %s\n", prog, msg); - exit(1); -} - -/* =========================================================================== - * Compress input to output then close both files. - */ - -void gz_compress(in, out) - FILE *in; - gzFile out; -{ - local char buf[BUFLEN]; - int len; - int err; - -#ifdef USE_MMAP - /* Try first compressing with mmap. If mmap fails (minigzip used in a - * pipe), use the normal fread loop. - */ - if (gz_compress_mmap(in, out) == Z_OK) return; -#endif - for (;;) { - len = fread(buf, 1, sizeof(buf), in); - if (ferror(in)) { - perror("fread"); - exit(1); - } - if (len == 0) break; - - if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); - } - fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); -} - -#ifdef USE_MMAP /* MMAP version, Miguel Albrecht */ - -/* Try compressing the input file at once using mmap. Return Z_OK if - * if success, Z_ERRNO otherwise. - */ -int gz_compress_mmap(in, out) - FILE *in; - gzFile out; -{ - int len; - int err; - int ifd = fileno(in); - caddr_t buf; /* mmap'ed buffer for the entire input file */ - off_t buf_len; /* length of the input file */ - struct stat sb; - - /* Determine the size of the file, needed for mmap: */ - if (fstat(ifd, &sb) < 0) return Z_ERRNO; - buf_len = sb.st_size; - if (buf_len <= 0) return Z_ERRNO; - - /* Now do the actual mmap: */ - buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); - if (buf == (caddr_t)(-1)) return Z_ERRNO; - - /* Compress the whole file at once: */ - len = gzwrite(out, (char *)buf, (unsigned)buf_len); - - if (len != (int)buf_len) error(gzerror(out, &err)); - - munmap(buf, buf_len); - fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); - return Z_OK; -} -#endif /* USE_MMAP */ - -/* =========================================================================== - * Uncompress input to output then close both files. - */ -void gz_uncompress(in, out) - gzFile in; - FILE *out; -{ - local char buf[BUFLEN]; - int len; - int err; - - for (;;) { - len = gzread(in, buf, sizeof(buf)); - if (len < 0) error (gzerror(in, &err)); - if (len == 0) break; - - if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { - error("failed fwrite"); - } - } - if (fclose(out)) error("failed fclose"); - - if (gzclose(in) != Z_OK) error("failed gzclose"); -} - - -/* =========================================================================== - * Compress the given file: create a corresponding .gz file and remove the - * original. - */ -void file_compress(file, mode) - char *file; - char *mode; -{ - local char outfile[MAX_NAME_LEN]; - FILE *in; - gzFile out; - - strcpy(outfile, file); - strcat(outfile, GZ_SUFFIX); - - in = fopen(file, "rb"); - if (in == NULL) { - perror(file); - exit(1); - } - out = gzopen(outfile, mode); - if (out == NULL) { - fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); - exit(1); - } - gz_compress(in, out); - - unlink(file); -} - - -/* =========================================================================== - * Uncompress the given file and remove the original. - */ -void file_uncompress(file) - char *file; -{ - local char buf[MAX_NAME_LEN]; - char *infile, *outfile; - FILE *out; - gzFile in; - int len = strlen(file); - - strcpy(buf, file); - - if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { - infile = file; - outfile = buf; - outfile[len-3] = '\0'; - } else { - outfile = file; - infile = buf; - strcat(infile, GZ_SUFFIX); - } - in = gzopen(infile, "rb"); - if (in == NULL) { - fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); - exit(1); - } - out = fopen(outfile, "wb"); - if (out == NULL) { - perror(file); - exit(1); - } - - gz_uncompress(in, out); - - unlink(infile); -} - - -/* =========================================================================== - * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...] - * -d : decompress - * -f : compress with Z_FILTERED - * -h : compress with Z_HUFFMAN_ONLY - * -1 to -9 : compression level - */ - -int main(argc, argv) - int argc; - char *argv[]; -{ - int uncompr = 0; - gzFile file; - char outmode[20]; - - strcpy(outmode, "wb6 "); - - prog = argv[0]; - argc--, argv++; - - while (argc > 0) { - if (strcmp(*argv, "-d") == 0) - uncompr = 1; - else if (strcmp(*argv, "-f") == 0) - outmode[3] = 'f'; - else if (strcmp(*argv, "-h") == 0) - outmode[3] = 'h'; - else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && - (*argv)[2] == 0) - outmode[2] = (*argv)[1]; - else - break; - argc--, argv++; - } - if (argc == 0) { - SET_BINARY_MODE(stdin); - SET_BINARY_MODE(stdout); - if (uncompr) { - file = gzdopen(fileno(stdin), "rb"); - if (file == NULL) error("can't gzdopen stdin"); - gz_uncompress(file, stdout); - } else { - file = gzdopen(fileno(stdout), outmode); - if (file == NULL) error("can't gzdopen stdout"); - gz_compress(stdin, file); - } - } else { - do { - if (uncompr) { - file_uncompress(*argv); - } else { - file_compress(*argv, outmode); - } - } while (argv++, --argc); - } - exit(0); - return 0; /* to avoid warning */ -} diff --git a/zlib/msdos/Makefile.b32 b/zlib/msdos/Makefile.b32 deleted file mode 100755 index 0038da5..0000000 Binary files a/zlib/msdos/Makefile.b32 and /dev/null differ diff --git a/zlib/msdos/Makefile.bor b/zlib/msdos/Makefile.bor deleted file mode 100755 index c4aff5e..0000000 Binary files a/zlib/msdos/Makefile.bor and /dev/null differ diff --git a/zlib/msdos/Makefile.dj2 b/zlib/msdos/Makefile.dj2 deleted file mode 100755 index e0291b1..0000000 Binary files a/zlib/msdos/Makefile.dj2 and /dev/null differ diff --git a/zlib/msdos/Makefile.emx b/zlib/msdos/Makefile.emx deleted file mode 100755 index b1a9065..0000000 Binary files a/zlib/msdos/Makefile.emx and /dev/null differ diff --git a/zlib/msdos/Makefile.msc b/zlib/msdos/Makefile.msc deleted file mode 100755 index 9c3d8e2..0000000 Binary files a/zlib/msdos/Makefile.msc and /dev/null differ diff --git a/zlib/msdos/Makefile.tc b/zlib/msdos/Makefile.tc deleted file mode 100755 index 52e153e..0000000 Binary files a/zlib/msdos/Makefile.tc and /dev/null differ diff --git a/zlib/msdos/Makefile.w32 b/zlib/msdos/Makefile.w32 deleted file mode 100755 index 1cd425d..0000000 Binary files a/zlib/msdos/Makefile.w32 and /dev/null differ diff --git a/zlib/msdos/Makefile.wat b/zlib/msdos/Makefile.wat deleted file mode 100755 index 5f982eb..0000000 Binary files a/zlib/msdos/Makefile.wat and /dev/null differ diff --git a/zlib/msdos/zlib.def b/zlib/msdos/zlib.def deleted file mode 100755 index bfe810f..0000000 Binary files a/zlib/msdos/zlib.def and /dev/null differ diff --git a/zlib/msdos/zlib.rc b/zlib/msdos/zlib.rc deleted file mode 100755 index 462db72..0000000 Binary files a/zlib/msdos/zlib.rc and /dev/null differ diff --git a/zlib/nt/Makefile.emx b/zlib/nt/Makefile.emx deleted file mode 100755 index 9c48ff6..0000000 Binary files a/zlib/nt/Makefile.emx and /dev/null differ diff --git a/zlib/nt/Makefile.gcc b/zlib/nt/Makefile.gcc deleted file mode 100755 index 85dec92..0000000 Binary files a/zlib/nt/Makefile.gcc and /dev/null differ diff --git a/zlib/nt/Makefile.nt b/zlib/nt/Makefile.nt deleted file mode 100755 index a36292b..0000000 Binary files a/zlib/nt/Makefile.nt and /dev/null differ diff --git a/zlib/nt/zlib.dnt b/zlib/nt/zlib.dnt deleted file mode 100755 index 960064c..0000000 Binary files a/zlib/nt/zlib.dnt and /dev/null differ diff --git a/zlib/os2/Makefile.os2 b/zlib/os2/Makefile.os2 deleted file mode 100755 index b345f69..0000000 Binary files a/zlib/os2/Makefile.os2 and /dev/null differ diff --git a/zlib/os2/zlib.def b/zlib/os2/zlib.def deleted file mode 100755 index 1dde659..0000000 Binary files a/zlib/os2/zlib.def and /dev/null differ diff --git a/zlib/sshzlibrename.h b/zlib/sshzlibrename.h deleted file mode 100755 index 120f808..0000000 --- a/zlib/sshzlibrename.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Author: Tero Kivinen - * - * Copyright (c) 1999 SSH Communications Security Oy - */ -/* - * Program: zlib - * $Source$ - * $Author$ - * - * Creation : 13:56 Oct 20 1999 kivinen - * Last Modification : 13:58 Oct 20 1999 kivinen - * Last check in : $Date$ - * Revision number : $Revision$ - * State : $State$ - * Version : 1.4 - * - * Description : Renames all zlib functions to have ssh prefix - * - * - * $Log$ - * Revision 1.1.1.1 2001/03/03 00:11:04 chombier - * initial import - * - * $EndLog$ - */ - -#ifndef SSHZLIBRENAME_H -#define SSHZLIBRENAME_H - -/* Define zlib to have ssh prefix, so we will not care if there is another zlib - in the kernel */ -#define deflateInit_ ssh_z_deflateInit_ -#define deflate ssh_z_deflate -#define deflateEnd ssh_z_deflateEnd -#define inflateInit_ ssh_z_inflateInit_ -#define inflate ssh_z_inflate -#define inflateEnd ssh_z_inflateEnd -#define deflateInit2_ ssh_z_deflateInit2_ -#define deflateSetDictionary ssh_z_deflateSetDictionary -#define deflateCopy ssh_z_deflateCopy -#define deflateReset ssh_z_deflateReset -#define deflateParams ssh_z_deflateParams -#define inflateInit2_ ssh_z_inflateInit2_ -#define inflateSetDictionary ssh_z_inflateSetDictionary -#define inflateSync ssh_z_inflateSync -#define inflateSyncPoint ssh_z_inflateSyncPoint -#define inflateReset ssh_z_inflateReset -#define compress ssh_z_compress -#define compress2 ssh_z_compress2 -#define uncompress ssh_z_uncompress -#define adler32 ssh_z_adler32 -#define crc32 ssh_z_crc32 -#define get_crc_table ssh_z_get_crc_table - -/*#define Byte ssh_z_Byte*/ -#define uInt ssh_z_uInt -#define uLong ssh_z_uLong -#define Bytef ssh_z_Bytef -#define charf ssh_z_charf -#define intf ssh_z_intf -#define uIntf ssh_z_uIntf -#define uLongf ssh_z_uLongf -#define voidpf ssh_z_voidpf -#define voidp ssh_z_voidp -#define _tr_align ssh_z__tr_align -#define _tr_flush_block ssh_z__tr_flush_block -#define _tr_init ssh_z__tr_init -#define _tr_stored_block ssh_z__tr_stored_block -#define _tr_tally ssh_z__tr_tally -#define deflate_copyright ssh_z_deflate_copyright -#define inflate_blocks ssh_z_inflate_blocks -#define inflate_blocks_free ssh_z_inflate_blocks_free -#define inflate_blocks_new ssh_z_inflate_blocks_new -#define inflate_blocks_reset ssh_z_inflate_blocks_reset -#define inflate_codes ssh_z_inflate_codes -#define inflate_codes_free ssh_z_inflate_codes_free -#define inflate_codes_new ssh_z_inflate_codes_new -#define inflate_copyright ssh_z_inflate_copyright -#define inflate_fast ssh_z_inflate_fast -#define inflate_flush ssh_z_inflate_flush -#define inflate_mask ssh_z_inflate_mask -#define inflate_set_dictionary ssh_z_inflate_set_dictionary -#define inflate_trees_bits ssh_z_inflate_trees_bits -#define inflate_trees_dynamic ssh_z_inflate_trees_dynamic -#define inflate_trees_fixed ssh_z_inflate_trees_fixed -#define z_errmsg ssh_z_z_errmsg -#define zlibVersion ssh_z_zlibVersion - -#endif /* SSHZLIBRENAME_H */ diff --git a/zlib/trees.c b/zlib/trees.c deleted file mode 100755 index 19d0374..0000000 --- a/zlib/trees.c +++ /dev/null @@ -1,1214 +0,0 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2002 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id$ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -#define Buf_size (8 * 2*sizeof(char)) -/* Number of bits used within bi_buf. (bi_buf might be implemented on - * more than 16 bits on some systems.) - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -local static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Local (static) routines in this file. - */ - -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, ct_data *ltree, - ct_data *dtree)); -local void set_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned value, int length)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); -local void copy_block OF((deflate_state *s, charf *buf, unsigned len, - int header)); - -#ifdef GEN_TREES_H -local void gen_trees_header OF((void)); -#endif - -#ifndef DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (value << s->bi_valid); - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = value;\ - s->bi_buf |= (val << s->bi_valid);\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* DEBUG */ - - -#define MAX(a,b) (a >= b ? a : b) -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init() -{ -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1< dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256+dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Genererate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width)-1 ? ",\n" : ", ")) - -void gen_trees_header() -{ - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void _tr_init(s) - deflate_state *s; -{ - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; - s->last_eob_len = 8; /* enough lookahead for inflate */ -#ifdef DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->last_lit = s->matches = 0; -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max+1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n-base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (bits + xbits); - if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); - } - if (overflow == 0) return; - - Trace((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length-1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if (tree[m].Len != (unsigned) bits) { - Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((long)bits - (long)tree[m].Len) - *(long)tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes (tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - ush code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - next_code[bits] = code = (code + bl_count[bits-1]) << 1; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code+1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code+1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(s) - deflate_state *s; -{ - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*(max_blindex+1) + 5+5+4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5); - send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void _tr_stored_block(s, buf, stored_len, eof) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int eof; /* true if this is the last block for a file */ -{ - send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ -#ifdef DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; -#endif - copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - * The current inflate code requires 9 bits of lookahead. If the - * last two codes for the previous block (real code plus EOB) were coded - * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode - * the last real code. In this case we send two empty static blocks instead - * of one. (There are no problems if the previous block is stored or fixed.) - * To simplify the code, we assume the worst case of last real code encoded - * on one bit only. - */ -void _tr_align(s) - deflate_state *s; -{ - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); - /* Of the 10 bits for the empty block, we have already sent - * (10 - bi_valid) bits. The lookahead for the last real code (before - * the EOB of the previous block) was thus at least one plus the length - * of the EOB plus what we have just sent of the empty static block. - */ - if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; -#endif - bi_flush(s); - } - s->last_eob_len = 7; -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. - */ -void _tr_flush_block(s, buf, stored_len, eof) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int eof; /* true if this is the last block for a file */ -{ - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is ascii or binary */ - if (s->data_type == Z_UNKNOWN) set_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute first the block length in bytes*/ - opt_lenb = (s->opt_len+3+7)>>3; - static_lenb = (s->static_len+3+7)>>3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->last_lit)); - - if (static_lenb <= opt_lenb) opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len+4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, eof); - -#ifdef FORCE_STATIC - } else if (static_lenb >= 0) { /* force static trees */ -#else - } else if (static_lenb == opt_lenb) { -#endif - send_bits(s, (STATIC_TREES<<1)+eof, 3); - compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1)+eof, 3); - send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, - max_blindex+1); - compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (eof) { - bi_windup(s); -#ifdef DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*eof)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int _tr_tally (s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ -{ - s->d_buf[s->last_lit] = (ush)dist; - s->l_buf[s->last_lit++] = (uch)lc; - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - -#ifdef TRUNCATE_BLOCK - /* Try to guess if it is profitable to stop the current block here */ - if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { - /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; - ulg in_length = (ulg)((long)s->strstart - s->block_start); - int dcode; - for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); - } - out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", - s->last_lit, in_length, out_length, - 100L - out_length*100L/in_length)); - if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; - } -#endif - return (s->last_lit == s->lit_bufsize-1); - /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - ct_data *ltree; /* literal tree */ - ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->last_lit != 0) do { - dist = s->d_buf[lx]; - lc = s->l_buf[lx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); - - } while (lx < s->last_lit); - - send_code(s, END_BLOCK, ltree); - s->last_eob_len = ltree[END_BLOCK].Len; -} - -/* =========================================================================== - * Set the data type to ASCII or BINARY, using a crude approximation: - * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. - * IN assertion: the fields freq of dyn_ltree are set and the total of all - * frequencies does not exceed 64K (to fit in an int on 16 bit machines). - */ -local void set_data_type(s) - deflate_state *s; -{ - int n = 0; - unsigned ascii_freq = 0; - unsigned bin_freq = 0; - while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; - while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; - while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; - s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} - -/* =========================================================================== - * Copy a stored block, storing first the length and its - * one's complement if requested. - */ -local void copy_block(s, buf, len, header) - deflate_state *s; - charf *buf; /* the input data */ - unsigned len; /* its length */ - int header; /* true if block header must be written */ -{ - bi_windup(s); /* align on byte boundary */ - s->last_eob_len = 8; /* enough lookahead for inflate */ - - if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); -#ifdef DEBUG - s->bits_sent += 2*16; -#endif - } -#ifdef DEBUG - s->bits_sent += (ulg)len<<3; -#endif - while (len--) { - put_byte(s, *buf++); - } -} diff --git a/zlib/trees.h b/zlib/trees.h deleted file mode 100755 index 72facf9..0000000 --- a/zlib/trees.h +++ /dev/null @@ -1,128 +0,0 @@ -/* header created automatically with -DGEN_TREES_H */ - -local const ct_data static_ltree[L_CODES+2] = { -{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, -{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, -{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, -{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, -{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, -{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, -{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, -{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, -{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, -{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, -{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, -{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, -{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, -{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, -{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, -{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, -{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, -{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, -{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, -{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, -{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, -{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, -{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, -{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, -{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, -{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, -{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, -{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, -{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, -{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, -{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, -{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, -{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, -{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, -{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, -{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, -{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, -{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, -{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, -{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, -{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, -{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, -{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, -{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, -{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, -{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, -{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, -{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, -{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, -{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, -{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, -{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, -{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, -{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, -{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, -{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, -{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, -{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} -}; - -local const ct_data static_dtree[D_CODES] = { -{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, -{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, -{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, -{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, -{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, -{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} -}; - -const uch _dist_code[DIST_CODE_LEN] = { - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, -10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, -11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, -12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, -18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 -}; - -const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, -13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, -17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, -19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, -21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, -22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 -}; - -local const int base_length[LENGTH_CODES] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, -64, 80, 96, 112, 128, 160, 192, 224, 0 -}; - -local const int base_dist[D_CODES] = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, - 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, - 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 -}; - diff --git a/zlib/uncompr.c b/zlib/uncompr.c deleted file mode 100755 index a287714..0000000 --- a/zlib/uncompr.c +++ /dev/null @@ -1,58 +0,0 @@ -/* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zlib.h" - -/* =========================================================================== - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ -int ZEXPORT uncompress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - z_stream stream; - int err; - - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; - - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = inflateInit(&stream); - if (err != Z_OK) return err; - - err = inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = inflateEnd(&stream); - return err; -} diff --git a/zlib/zconf.h b/zlib/zconf.h deleted file mode 100755 index 61e90fd..0000000 --- a/zlib/zconf.h +++ /dev/null @@ -1,281 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef _ZCONF_H -#define _ZCONF_H - -#include "sshzlibrename.h" - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - */ -#ifdef Z_PREFIX -# define deflateInit_ z_deflateInit_ -# define deflate z_deflate -# define deflateEnd z_deflateEnd -# define inflateInit_ z_inflateInit_ -# define inflate z_inflate -# define inflateEnd z_inflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateSetDictionary z_deflateSetDictionary -# define deflateCopy z_deflateCopy -# define deflateReset z_deflateReset -# define deflateParams z_deflateParams -# define inflateInit2_ z_inflateInit2_ -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateReset z_inflateReset -# define compress z_compress -# define compress2 z_compress2 -# define uncompress z_uncompress -# define adler32 z_adler32 -# define crc32 z_crc32 -# define get_crc_table z_get_crc_table - -# define Byte z_Byte -# define uInt z_uInt -# define uLong z_uLong -# define Bytef z_Bytef -# define charf z_charf -# define intf z_intf -# define uIntf z_uIntf -# define uLongf z_uLongf -# define voidpf z_voidpf -# define voidp z_voidp -#endif - -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -# define WIN32 -#endif -#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) -# ifndef __32BIT__ -# define __32BIT__ -# endif -#endif -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#if defined(MSDOS) && !defined(__32BIT__) -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) -# define STDC -#endif -#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) -# ifndef STDC -# define STDC -# endif -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const -# endif -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Old Borland C incorrectly complains about missing returns: */ -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) -# define NEED_DUMMY_RETURN -#endif - - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -#endif -#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) -# ifndef __32BIT__ -# define SMALL_MEDIUM -# define FAR _far -# endif -#endif - -/* Compile with -DZLIB_DLL for Windows DLL support */ -#if defined(ZLIB_DLL) -# if defined(_WINDOWS) || defined(WINDOWS) -# ifdef FAR -# undef FAR -# endif -# include -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR _cdecl _export -# endif -# endif -# if defined (__BORLANDC__) -# if (__BORLANDC__ >= 0x0500) && defined (WIN32) -# include -# define ZEXPORT __declspec(dllexport) WINAPI -# define ZEXPORTRVA __declspec(dllexport) WINAPIV -# else -# if defined (_Windows) && defined (__DLL__) -# define ZEXPORT _export -# define ZEXPORTVA _export -# endif -# endif -# endif -#endif - -#if defined (__BEOS__) -# if defined (ZLIB_DLL) -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -#endif - -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif -#ifndef ZEXTERN -# define ZEXTERN extern -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(MACOS) && !defined(TARGET_OS_MAC) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#ifdef HAVE_UNISTD_H -# include /* for off_t */ -# include /* for SEEK_* and off_t */ -# define z_off_t off_t -#endif -#ifndef SEEK_SET -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif -#ifndef z_off_t -# define z_off_t long -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) -# pragma map(deflateInit_,"DEIN") -# pragma map(deflateInit2_,"DEIN2") -# pragma map(deflateEnd,"DEEND") -# pragma map(inflateInit_,"ININ") -# pragma map(inflateInit2_,"ININ2") -# pragma map(inflateEnd,"INEND") -# pragma map(inflateSync,"INSY") -# pragma map(inflateSetDictionary,"INSEDI") -# pragma map(inflate_blocks,"INBL") -# pragma map(inflate_blocks_new,"INBLNE") -# pragma map(inflate_blocks_free,"INBLFR") -# pragma map(inflate_blocks_reset,"INBLRE") -# pragma map(inflate_codes_free,"INCOFR") -# pragma map(inflate_codes,"INCO") -# pragma map(inflate_fast,"INFA") -# pragma map(inflate_flush,"INFLU") -# pragma map(inflate_mask,"INMA") -# pragma map(inflate_set_dictionary,"INSEDI2") -# pragma map(inflate_copyright,"INCOPY") -# pragma map(inflate_trees_bits,"INTRBI") -# pragma map(inflate_trees_dynamic,"INTRDY") -# pragma map(inflate_trees_fixed,"INTRFI") -# pragma map(inflate_trees_free,"INTRFR") -#endif - -#endif /* _ZCONF_H */ diff --git a/zlib/zlib.3 b/zlib/zlib.3 deleted file mode 100755 index 2a204e8..0000000 Binary files a/zlib/zlib.3 and /dev/null differ diff --git a/zlib/zlib.h b/zlib/zlib.h deleted file mode 100755 index 52cb529..0000000 --- a/zlib/zlib.h +++ /dev/null @@ -1,893 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.1.4, March 11th, 2002 - - Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ - -#ifndef _ZLIB_H -#define _ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.1.4" - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed - data. This version of the library supports only one compression method - (deflation) but other algorithms will be added later and will have the same - stream interface. - - Compression can be done in a single step if the buffers are large - enough (for example if an input file is mmap'ed), or can be done by - repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output - (providing more output space) before each call. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never - crash even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ - - char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: ascii or binary */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - The application must update next_in and avail_in when avail_in has - dropped to zero. It must update next_out and avail_out when avail_out - has dropped to zero. The application must initialize zalloc, zfree and - opaque before calling the init function. All other fields are set by the - compression library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - pointers returned by zalloc for objects of exactly 65536 bytes *must* - have their offset normalized to zero. The default allocation function - provided by this library ensures this (see zutil.c). To reduce memory - requirements and avoid any allocation of 64K objects, at the expense of - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or - progress reports. After compression, total_in holds the total size of - the uncompressed data and may be saved for use in the decompressor - (particularly if the decompressor wants to decompress everything in - a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -/* Allowed flush values; see deflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative - * values are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_ASCII 1 -#define Z_UNKNOWN 2 -/* Possible values of the data_type field */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is - not compatible with the zlib.h header file used by the application. - This check is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. - If zalloc and zfree are set to Z_NULL, deflateInit updates them to - use default allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at - all (the input data is simply copied a block at a time). - Z_DEFAULT_COMPRESSION requests a default compromise between speed and - compression (currently equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if level is not a valid compression level, - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). - msg is set to null if there is no error message. deflateInit does not - perform any compression: this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce some - output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating avail_in or avail_out accordingly; avail_out - should never be zero before the call. The application can consume the - compressed output when it wants, for example when the output buffer is full - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - and with zero avail_out, it must be called again after making room in the - output buffer because there might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In particular - avail_in is zero after the call if enough output space has been provided - before the call.) Flushing may degrade compression for some compression - algorithms and so it should be used only when necessary. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - the compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there - was enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the - stream are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least - 0.1% larger than avail_in plus 12 bytes. If deflate does not return - Z_STREAM_END, then it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update data_type if it can make a good guess about - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered - binary. This field is only for information purposes and does not affect - the compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, - msg may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact - value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller. msg is set to null if there is no error - message. inflateInit does not perform any decompression apart from reading - the zlib header if present: this will be done by inflate(). (So next_in and - avail_in may be modified, but next_out and avail_out are unchanged.) -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may some - introduce some output latency (reading input without producing any output) - except when forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing - will resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there - is no more input data or no more space in the output buffer (see below - about the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating the next_* and avail_* values accordingly. - The application can consume the uncompressed output when it wants, for - example when the output buffer is full (avail_out == 0), or after each - call of inflate(). If inflate returns Z_OK and with zero avail_out, it - must be called again after making room in the output buffer because there - might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much - output as possible to the output buffer. The flushing behavior of inflate is - not specified for values of the flush parameter other than Z_SYNC_FLUSH - and Z_FINISH, but the current implementation actually flushes as much output - as possible anyway. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step - (a single call of inflate), the parameter flush should be set to - Z_FINISH. In this case all pending input is processed and all pending - output is flushed; avail_out must be large enough to hold all the - uncompressed data. (The size of the uncompressed data may have been saved - by the compressor for this purpose.) The next operation on this stream must - be inflateEnd to deallocate the decompression state. The use of Z_FINISH - is never required, but can be used to inform inflate that a faster routine - may be used for the single inflate() call. - - If a preset dictionary is needed at this point (see inflateSetDictionary - below), inflate sets strm-adler to the adler32 checksum of the - dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise - it sets strm->adler to the adler32 checksum of all output produced - so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or - an error code as described below. At the end of the stream, inflate() - checks that its computed adler32 checksum is equal to that saved by the - compressor and returns Z_STREAM_END only if the checksum is correct. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect - adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent - (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if no progress is possible or if there was not - enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR - case, the application may then call inflateSync to look for a good - compression block. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by - the caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but - is slow and reduces compression ratio; memLevel=9 uses maximum memory - for optimal speed. The default value is 8. See zconf.h for total memory - usage as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match). Filtered data consists mostly of small values with a - somewhat random distribution. In this case, the compression algorithm is - tuned to compress them better. The effect of Z_FILTERED is to force more - Huffman coding and less string matching; it is somewhat intermediate - between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects - the compression ratio but not the correctness of the compressed output even - if it is not set appropriately. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid - method). msg is set to null if there is no error message. deflateInit2 does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any - call of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size in - deflate or deflate2. Thus the strings most likely to be useful should be - put at the end of the dictionary, not at the front. - - Upon return of this function, strm->adler is set to the Adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The Adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and - can consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. - The stream will keep the same compression level and any other attributes - that may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different - strategy. If the compression level is changed, the input available so far - is compressed with the old level (and may be flushed); the new level will - take effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to - be compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - if strm->avail_out was zero. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. If a compressed stream with a larger window size is given as - input, inflate() will return with the error code Z_DATA_ERROR instead of - trying to allocate a larger window. - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative - memLevel). msg is set to null if there is no error message. inflateInit2 - does not perform any decompression apart from reading the zlib header if - present: this will be done by inflate(). (So next_in and avail_in may be - modified, but next_out and avail_out are unchanged.) -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the Adler32 value returned by this call of - inflate. The compressor and decompressor must use exactly the same - dictionary (see deflateSetDictionary). - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect Adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been found, - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - case, the application may save the current current value of total_in which - indicates where valid compressed data was found. In the error case, the - application may repeatedly call inflateSync, providing more input each time, - until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. - The stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - - - /* utility functions */ - -/* - The following utility functions are implemented on top of the - basic stream-oriented functions. To simplify the interface, some - default options are assumed (compression level and memory usage, - standard memory allocation functions). The source code of these - utility functions can easily be modified if you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be at least 0.1% larger than - sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the - compressed buffer. - This function can be used to compress a whole file at once if the - input file is mmap'ed. - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ - - -typedef voidp gzFile; - -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); -/* - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb") but can also include a compression level - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - Huffman only compression as in "wb1h". (See the description - of deflateInit2 for more information about the strategy parameter.) - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. - - gzopen returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). */ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen() associates a gzFile with the file descriptor fd. File - descriptors are obtained from calls like open, dup, creat, pipe or - fileno (in the file has been previously opened with fopen). - The mode parameter is as in gzopen. - The next call of gzclose on the returned gzFile will also close the - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - gzdopen returns NULL if there was insufficient memory to allocate - the (de)compression state. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. - If the input file was not in gzip format, gzread copies the given number - of bytes into the buffer. - gzread returns the number of uncompressed bytes actually read (0 for - end of file, -1 for error). */ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - const voidp buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes actually written - (0 in case of error). -*/ - -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or - a newline character is read and transferred to buf, or an end-of-file - condition is encountered. The string is then terminated with a null - character. - gzgets returns buf, or Z_NULL in case of error. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. The return value is the zlib - error number (see function gzerror below). gzflush returns Z_OK if - the flush parameter is Z_FINISH and all output could be flushed. - gzflush should be called only when strictly necessary because it can - degrade compression. -*/ - -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); -/* - Sets the starting position for the next gzread or gzwrite on the - given compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); -/* - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. The return value is the zlib - error number (see function gzerror below). -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the - compression library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); - -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) - - -#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; /* hack for buggy compilers */ -#endif - -ZEXTERN const char * ZEXPORT zError OF((int err)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); - -#ifdef __cplusplus -} -#endif - -#endif /* _ZLIB_H */ diff --git a/zlib/zutil.c b/zlib/zutil.c deleted file mode 100755 index 7a6d2de..0000000 --- a/zlib/zutil.c +++ /dev/null @@ -1,228 +0,0 @@ -/* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" - -struct internal_state {int dummy;}; /* for buggy compilers */ - -#ifndef STDC -extern void exit OF((int)); -#endif - -const char *z_errmsg[10] = { -"need dictionary", /* Z_NEED_DICT 2 */ -"stream end", /* Z_STREAM_END 1 */ -"", /* Z_OK 0 */ -"file error", /* Z_ERRNO (-1) */ -"stream error", /* Z_STREAM_ERROR (-2) */ -"data error", /* Z_DATA_ERROR (-3) */ -"insufficient memory", /* Z_MEM_ERROR (-4) */ -"buffer error", /* Z_BUF_ERROR (-5) */ -"incompatible version",/* Z_VERSION_ERROR (-6) */ -""}; - - -const char * ZEXPORT zlibVersion() -{ - return ZLIB_VERSION; -} - -#ifdef DEBUG - -# ifndef verbose -# define verbose 0 -# endif -int z_verbose = verbose; - -void z_error (m) - char *m; -{ - fprintf(stderr, "%s\n", m); - exit(1); -} -#endif - -/* exported to allow conversion of error code to string for compress() and - * uncompress() - */ -const char * ZEXPORT zError(err) - int err; -{ - return ERR_MSG(err); -} - - -#ifndef HAVE_MEMCPY - -void zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); -} - -int zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; - } - return 0; -} - -void zmemzero(dest, len) - Bytef* dest; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); -} -#endif - -#ifdef __TURBOC__ -#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__) -/* Small and medium model in Turbo C are for now limited to near allocation - * with reduced MAX_WBITS and MAX_MEM_LEVEL - */ -# define MY_ZCALLOC - -/* Turbo C malloc() does not allow dynamic allocation of 64K bytes - * and farmalloc(64K) returns a pointer with an offset of 8, so we - * must fix the pointer. Warning: the pointer must be put back to its - * original form in order to free it, use zcfree(). - */ - -#define MAX_PTR 10 -/* 10*64K = 640K */ - -local int next_ptr = 0; - -typedef struct ptr_table_s { - voidpf org_ptr; - voidpf new_ptr; -} ptr_table; - -local ptr_table table[MAX_PTR]; -/* This table is used to remember the original form of pointers - * to large buffers (64K). Such pointers are normalized with a zero offset. - * Since MSDOS is not a preemptive multitasking OS, this table is not - * protected from concurrent access. This hack doesn't work anyway on - * a protected system like OS/2. Use Microsoft C instead. - */ - -voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) -{ - voidpf buf = opaque; /* just to make some compilers happy */ - ulg bsize = (ulg)items*size; - - /* If we allocate less than 65520 bytes, we assume that farmalloc - * will return a usable pointer which doesn't have to be normalized. - */ - if (bsize < 65520L) { - buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; - } else { - buf = farmalloc(bsize + 16L); - } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; - table[next_ptr].org_ptr = buf; - - /* Normalize the pointer to seg:0 */ - *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; - *(ush*)&buf = 0; - table[next_ptr++].new_ptr = buf; - return buf; -} - -void zcfree (voidpf opaque, voidpf ptr) -{ - int n; - if (*(ush*)&ptr != 0) { /* object < 64K */ - farfree(ptr); - return; - } - /* Find the original pointer */ - for (n = 0; n < next_ptr; n++) { - if (ptr != table[n].new_ptr) continue; - - farfree(table[n].org_ptr); - while (++n < next_ptr) { - table[n-1] = table[n]; - } - next_ptr--; - return; - } - ptr = opaque; /* just to make some compilers happy */ - Assert(0, "zcfree: ptr not found"); -} -#endif -#endif /* __TURBOC__ */ - - -#if defined(M_I86) && !defined(__32BIT__) -/* Microsoft C in 16-bit mode */ - -# define MY_ZCALLOC - -#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) -# define _halloc halloc -# define _hfree hfree -#endif - -voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - return _halloc((long)items, size); -} - -void zcfree (voidpf opaque, voidpf ptr) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - _hfree(ptr); -} - -#endif /* MSC */ - - -#ifndef MY_ZCALLOC /* Any system without a special alloc function */ - -#ifndef STDC -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); -#endif - -void *ssh_xcalloc(unsigned long nitems, unsigned long size); -void ssh_xfree(void *ptr); - -voidpf zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ - if (opaque) items += size - size; /* make compiler happy */ - return (voidpf)ssh_xcalloc(items, size); -} - -void zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; -{ - ssh_xfree(ptr); - if (opaque) return; /* make compiler happy */ -} - -#endif /* MY_ZCALLOC */ diff --git a/zlib/zutil.h b/zlib/zutil.h deleted file mode 100755 index e15f09e..0000000 --- a/zlib/zutil.h +++ /dev/null @@ -1,220 +0,0 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2002 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef _Z_UTIL_H -#define _Z_UTIL_H - -#include "zlib.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = (char*)ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#ifdef MSDOS -# define OS_CODE 0x00 -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -#endif - -#ifdef OS2 -# define OS_CODE 0x06 -#endif - -#ifdef WIN32 /* Window 95 & Windows NT */ -# define OS_CODE 0x0b -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 0x02 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#ifdef AMIGA -# define OS_CODE 0x01 -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 0x05 -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -# define OS_CODE 0x07 -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -# define OS_CODE 0x0F -#endif - -#ifdef TOPS20 -# define OS_CODE 0x0a -#endif - -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) -# define fdopen(fd,type) _fdopen(fd,type) -#endif - - - /* Common defaults */ - -#ifndef OS_CODE -# define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#ifdef HAVE_STRERROR - extern char *strerror OF((int)); -# define zstrerror(errnum) strerror(errnum) -#else -# define zstrerror(errnum) "" -#endif - -#if defined(pyr) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - extern void zmemzero OF((Bytef* dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -# include - extern int z_verbose; - extern void z_error OF((char *m)); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - - -typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, - uInt len)); -voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); -void zcfree OF((voidpf opaque, voidpf ptr)); - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -#endif /* _Z_UTIL_H */